WeaponFired

WeaponFired

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

WeaponFired

Post 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?
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: WeaponFired

Post 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.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: WeaponFired

Post 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
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: WeaponFired

Post 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?
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: WeaponFired

Post by lamer »

Dart and Sniper in ZK also generated WeaponFired (thats normal weapons).
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: WeaponFired

Post by Anarchid »

Sounds like it's a Java interface / Java wrapper problem, then.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: WeaponFired

Post 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).
Post Reply

Return to “AI”