massive target finding

Posted By: Random

massive target finding - 03/09/13 17:59

Hallo everybody.
I have two armies (10 vs 10) with are suppose to fight against another.
My problem is, I don`t know how to create a local targets for each AI. The target they search now is global.

So Team A looks for:
ENTITY* enemy_target;
While Team b looks for:
ENTITY* ally_target;

Team A searching code:
Code:
function AI_find_target()
{
	result = c_scan(my.x, my.pan, vector(360,180,2000), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);
	if(result > 0)
	{
		if(you.team != my.team)
		{
			while ((vec_dist (my.x, you.x)<2000) && (you.health>0))
			{
				enemy_target = you;
				wait(1);
			}
			enemy_target = NULL; 
		}
	}	
}



Team B searching code:
Code:
function AIfriendly_find_target()
{
	result = c_scan(my.x, my.pan, vector(360,180,2000), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);
	if(result > 0)
	{
		if(you.team != my.team)
		{
			while ((vec_dist (my.x, you.x)<2000) && (you.health>0))
			{
				ally_target = you;
				wait(1);
			}
			ally_target = NULL; 
		}
	}	
}



Obviously this can`t work as soon there are more AIs on each side...
Any ideas how to make this better?
Posted By: sivan

Re: massive target finding - 03/09/13 19:33

simply, each unit entity could store target entity's handle in a skill.
Posted By: Wjbender

Re: massive target finding - 03/09/13 19:55

yes what sivan said .

"as soon there are more AIs on each side..."

and also maby create an array for each team of entitys
and perhaps store an id also for each entity in the array
if you need it ..
Posted By: Random

Re: massive target finding - 03/09/13 21:00

Great it works!
I would never thought that you could mix entity with defines ^^

Fore those who are interested:

Code:
function AIfriendly_find_target()
{
	var closestTarget_dist;
	for(you=ent_next(NULL); you!=NULL; you=ent_next(you))
	{
		if ((you != my) && (you.team != my.team) && (you.health>0))
		{
			if(my.the_target ==NULL)
			{   
				my.the_target = you;
				ENTITY* enemy_target = my.the_target;
				closestTarget_dist = vec_dist(you.x, me.x);  
			}
			else
			{
				if(vec_dist(you.x, me.x) < closestTarget_dist)	
				{   
					my.the_target = you;
					ENTITY* enemy_target = my.the_target;
					closestTarget_dist = vec_dist(you.x, me.x); 
				}
			}
		}
	}
}



Thank you!
Posted By: Wjbender

Re: massive target finding - 03/09/13 21:45

nice now you only need to limit how many may choose the same target.. but
perhaps you would like to have them bunch up on the same target ?
Posted By: sivan

Re: massive target finding - 03/09/13 22:32

yes, and maybe some weighting of target dangerousness could be also fine, e.g. if there is a position important to defend.
Posted By: Abarudra

Re: massive target finding - 03/10/13 15:05

Maybe you can try something like this, i use it (currently in a very basic version) in my TD Game. I cant provide code at the moment sorry.

I have one scanning - entity that "knows" a list of ally forces nearby. I let it scan for enemys and i use event_detect to store their pointers in an array.
Currently i only look for the closest enemy and assign it as target to the allied forces. For the "communication" i use structs with entitypointerarrays.
This way i have more ways to assign targets to units.

Kind regards
Posted By: Random

Re: massive target finding - 03/10/13 16:15

Wouldn`t that effect the FPS quite much?
Posted By: Abarudra

Re: massive target finding - 03/10/13 16:36

Im sorry i dont know.
In my example i have currently only about 10 units on each side (1 scanner + several turrets vs a bunch of fighters. I don't have FPS Problems so far (i limit it to 60 and it never drops below).
When i have my system up and running again i will test it with more units.
My idea was to have one a bit more complex function and several "small" ones instead of a bunch of medium sized ones.
But my project is still in a prealpha version, so i dont have much experience in performance issues.
Posted By: sivan

Re: massive target finding - 03/11/13 07:57

if you have fps problems. let only a few units to use c_scan within one frame. e.g. one unit from each group. thus it must be fine, and within one second all the units has updated information.
© 2024 lite-C Forums