Page 1 of 1

WeaponFired

Posted: 27 Nov 2015, 12:11
by Anarchid
There seems to be something wrong with the WeaponFired event at least for Java AI's:

1) Listening to WeaponFired as a Java AI seems to never produce any results.

2) Documentation says that "This AI event is sent when certain weapons are fired. For performance reasons, it is not possible to send this event for all weapons. Therefore, it is currently only sent for manuall-fire weapons like for example the TA Commanders D-Gun or the Nuke.".

3) Code seems to say that WeaponFired is fired for every shot in a salvo, without checking for manualFire, and is sent to the AI which controls the team's units:

Code: Select all

Weapon.cpp:512 (in UpdateSalvo, unconditionally)
	owner->commandAI->WeaponFired(this, searchForNewTarget);

CommandAI.cpp:1544 (in WeaponFired, unconditionally)
	eoh->WeaponFired(*owner, *(weapon->weaponDef));
	
EngineOutHandler.cpp:477 (in WeaponFired, unconditionally)
	DO_FOR_TEAM_SKIRMISH_AIS(WeaponFired(unitId, defId), teamId);
None of those statements are pairwise compatible. HALP! Does anyone know anything? Should i mantis this? Do CPP or C bots suffer from this? Is something else wrong?

Re: WeaponFired

Posted: 27 Nov 2015, 13:48
by Kloot
This seems to be a case of ancient documentation getting overtaken by refactored/rewritten code.

At some point in the past the implementation of CCommandAI::WeaponFired looked like...

Code: Select all

void CCommandAI::WeaponFired(CWeapon* weapon)
{
   if(weapon->weaponDef->manualfire && !weapon->weaponDef->dropped && !commandQue.empty()
      && (commandQue.front().id==CMD_ATTACK || commandQue.front().id==CMD_DGUN) && inCommand)
   {
      owner->AttackUnit(0,true);
      eoh->WeaponFired(*owner, *(weapon->weaponDef));
      FinishCommand();
   }
}
... which matches the description better, but made no mention of performance.

The events do reach legacy C++ AI code so defer to your local Generated Interface Problem Solver.

Re: WeaponFired

Posted: 27 Nov 2015, 17:17
by lamer
Works in C++

Code: Select all

/cheat
/team <bot>
/give dante <bot>
Select dante and fire -> WeaponFired
Of course it is sent only for allied team

Re: WeaponFired

Posted: 27 Nov 2015, 17:47
by gajop
lamer wrote:Works in C++

Code: Select all

/cheat
/team <bot>
/give dante <bot>
Select dante and fire -> WeaponFired
Of course it is sent only for allied team
anything for normal (non dgun/manual) weapons?

Re: WeaponFired

Posted: 27 Nov 2015, 18:36
by lamer
Dart and Sniper in ZK also generated WeaponFired (thats normal weapons).

Re: WeaponFired

Posted: 27 Nov 2015, 22:33
by Anarchid
Sounds like it's a Java interface / Java wrapper problem, then.

Re: WeaponFired

Posted: 28 Nov 2015, 13:54
by lamer
I don't get what's the issue?
Try to add

Code: Select all

callback.getMap().getDrawer().addPoint(new AIFloat3(100, 0, 100), "weaponFired");
right after

Code: Select all

public int weaponFired(Unit unit, WeaponDef weaponDef) {
and you'll be surprised. (I mean it works in my experiments)

EDIT:
Of course it is sent only for allied team
My mistake. It is sent only for own team (as in several AIs controlling same units; not allies).