Page 1 of 1

What's reliable way to detect if unit has antiair weapon?

Posted: 14 Dec 2010, 11:30
by slogic
Current algo is:

Code: Select all

		if (weapon->def->tracks && !weapon->def->waterweapon 
		&& !weapon->def->stockpile && !weapon->def->canAttackGround)
			return true;
But flak weapons are skipped. I have no access to "toairweapon" tag of weapons.tdf file.

I was thinking about checking ballistic=1 & turret=1 but this is wrong.

Note that i won't parse text resources.

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 14 Dec 2010, 12:29
by slogic
Hm, i noticed all fbi files of anti-air units in BA have tags like these:

Code: Select all

  sightDistance=475;
  airSightDistance=900;
So, air sight distance of all anti-air units is 1.5x-2.x higher than usual sight distance. Can be used as additional trigger but also may give false positives.

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 14 Dec 2010, 13:22
by Forboding Angel
Dunno if you can do it this way, but you could check the target categories of the weapons for "VTOL". *Shrug*

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 14 Dec 2010, 13:56
by slogic
No, i can't: http://springrts.com/phpbb/viewtopic.php?f=15&t=22988

I just profiled (ud->airLosRadius / ud->losRadius) expression for all registered anti-air units and always get values < 1.0. Very strange. Looks like they are expressed in different items.

EDIT
From some lua widget:

Code: Select all

   unit->realLosRadius=(int) (ud->losRadius/(SQUARE_SIZE*2));
   unit->realAirLosRadius=(int) (ud->airLosRadius/(SQUARE_SIZE*4));
EDIT2
Actually more complicated :/

Code: Select all

	losRadius = udTable.GetFloat("sightDistance", 0.0f) * modInfo.losMul / (SQUARE_SIZE * (1 << modInfo.losMipLevel));
	airLosRadius = udTable.GetFloat("airSightDistance", -1.0f);
	if (airLosRadius == -1.0f) {
		airLosRadius = udTable.GetFloat("sightDistance", 0.0f) * modInfo.airLosMul * 1.5f / (SQUARE_SIZE * (1 << modInfo.airMipLevel));
	} else {
		airLosRadius = airLosRadius * modInfo.airLosMul / (SQUARE_SIZE * (1 << modInfo.airMipLevel));
	}

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 14 Dec 2010, 15:35
by slogic
Based on my tests (SQUARE_SIZE * (1 << modInfo.losMipLevel) / modInfo.losMul) = 32. I don't understand where modInfo.losMul & modInfo.losMipLevel are set by game developer? Or are they constants really?

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 14 Dec 2010, 15:40
by Kloot
modInfo(.lua) | modRules(.tdf)

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 14 Dec 2010, 15:54
by slogic
Thanx. Found at mod rules. Also found an outdated information that is was in sensors.tdf files long ago.

Well, i think i'm in a deadlock again like with Spring category tags because modInfo is not accessible via Legacy C++ API.

I see no way to 100% detect anti-air units.

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 15 Dec 2010, 00:57
by SpliFF
If you have have any persistence in your AI data you could train that stat by counting total air kills for each unitdef. Then pick a reasonable minimum threshold that avoids those occasional cases where a plane got caught on the ground.

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 22 Dec 2010, 12:15
by slogic
Training is bad for constantly modifying games.

Created mantis request #2264.

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 23 Dec 2010, 15:38
by Rafal99
In my ancient AI code I was detecting AA weapons using weaponDef->onlyTargetCategory.
It was before AI interface rewrite so no idea how the exact code would look like now.

Re: What's reliable way to detect if unit has antiair weapon?

Posted: 23 Dec 2010, 17:30
by slogic
I wanna use it too but it is of integer type (not string) & contains flags to which i have no access: they are not static.