BuildDistance in a groupai

BuildDistance in a groupai

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

BuildDistance in a groupai

Post by Bobcatben »

is the nanolathe range for a unit divided by something when you get it from aicb? cause i was working on a groupai the past couple days and i was having it search for units within its build range, and it wasn't working so i finally had it output the builddistance value when the unit was added and it keeps coming back as like 0.9 and 0.7, any ideas?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

hmmmm, odd can you show us the code you used? I use that value in ETA AI and it seems to be working fine.....
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

Code: Select all

bool CGroupAI::AddUnit(int unit)
{
	// * possibly do some stuff to check upon the suitability of unit for this group
	// * keep track of the unit by storing it in some array
	// * return true if the unit is accepted, false otherwise
	const UnitDef* ud=aicb->GetUnitDef(unit);
	UnitInfo* info=new UnitInfo;
	if(ud->buildSpeed==0){
		aicb->SendTextMsg("i only want builder units",0);
		return false;
	}
	char tmpstr[128];
	info->radius = ud->buildDistance;
	sprintf(tmpstr,"Unit Has %f Build Distance",info->radius);
	aicb->SendTextMsg(tmpstr,0);
	info->Status = idle;
	myUnits[unit] = info;
	return true;
}
it comes up with like 0.957465blahblahblah

im also having some weird bugs with VC++2003 itself, where after useing aicb->GetFeatures, it wont pop up any class definitions, like listing the methods in aicb, it thinks everythings "int max" after i use it.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

This should be in the AI forum

Code: Select all

bool CGroupAI::AddUnit(int unit) 
{ 
   // * possibly do some stuff to check upon the suitability of unit for this group 
   // * keep track of the unit by storing it in some array 
   // * return true if the unit is accepted, false otherwise 
   const UnitDef* ud=aicb->GetUnitDef(unit); 
   UnitInfo* info=new UnitInfo; 
   if(ud->buildSpeed==0){ 
      aicb->SendTextMsg("i only want builder units",0); 
      return false; 
   } 
   char tmpstr[128]; 
   info->radius = ud->buildDistance; 
   sprintf(tmpstr,"Unit Has %f Build Distance",info->radius); 
   aicb->SendTextMsg(tmpstr,0); 
   info->Status = idle; 
   myUnits[unit] = info; 
   return true; 
}
should be

Code: Select all

bool CGroupAI::AddUnit(int unit) 
{ 
   // * possibly do some stuff to check upon the suitability of unit for this group 
   // * keep track of the unit by storing it in some array 
   // * return true if the unit is accepted, false otherwise 
   const UnitDef* ud=aicb->GetUnitDef(unit);
   if(ud == 0) return false;
   // check if the engine gives an error to prevent crash

   UnitInfo* info = new UnitInfo();

   if(ud->builder){
      // if buildspeed < 0.5 then ti would give this error which we dont want
      // also this is the proper method.
      aicb->SendTextMsg("i only want builder units",0);
      return false;
   } 
   char tmpstr[128];
   info->radius = ud->buildDistance;
   sprintf(tmpstr,"Unit Has %f Build Distance",ud->buildDistance);
   // use the original value nto the value you assigned it to.
   aicb->SendTextMsg(tmpstr,0);
   info->Status = idle;
   myUnits[unit] = info;
   return true;
}
btw what are you making this groupAI for? If you're trying to make an estimated time groupAI I've beaten you to it....
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

a AI to manage nano towers/farks and junk, since nano towers cant seem to realize they cant move and patrol gets them stuck and totaly non functional after awhile.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

manage them how exactly? Just going around repairing stuff? nanotowers can do that already if you give the the fight command in 0.73b1, and they sorta do it if you give them patrol commands with repeat on
User avatar
Aun
Posts: 788
Joined: 31 Aug 2005, 13:00

Post by Aun »

AF wrote:manage them how exactly? Just going around repairing stuff? nanotowers can do that already if you give the the fight command in 0.73b1, and they sorta do it if you give them patrol commands with repeat on
The problem is that nano-towers are units, so they try to move to repair things outside of their range, ignoring everything else.
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

exactly, and to give them a priority of sorts, im having them repair hurt friendly s first, then reclaim enemy units, then reclaim wreckages then help build.

and iam trying to use the build distance in aicb->GetFriendlyUnits, to get all allied units within its build range, which since its returning 0.9blahblah isn't working unless the AI is right up next to the damaged unit
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

doesnt my code work?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

doesnt my code work?
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

same result with your code, 0.935something on a commander, and 0.973something on a nano tower
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

what about multiplying ti by the speed of the unti and logging that?
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

closer, but it ends up being half the actual build range on commanders, and 0 on nano towers since they cant move.
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

added combat units to the AI(which shouldn't even happen cause of the build speed check) and they all return the same 0.9blahblah build distance number... i never have gotten UnitDef stuff to work in my groupais, i tried to make a ai only accept planes before, same result, same number on can fly no matter what unit type.
User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben »

figured it out, and why ive never gotten unitdefs to work, i been compileing with svn version includes, and running it on 0.72b1
Post Reply

Return to “Engine”