SWeaponFiredEvent question

SWeaponFiredEvent question

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

Moderators: hoijui, Moderators

Post Reply
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

SWeaponFiredEvent question

Post by ivand »

Hi!

Can you tell me when SWeaponFiredEvent and corresponding EventId are being signaled?

AI_Enemy and me gunning each over (in LOS), but no event comes. Isn't it a bug?

VBR,
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: SWeaponFiredEvent question

Post by hoijui »

have a look at rts/Sim/Units/CommandAI/CommandAI.cpp:1436

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();
	}
}
eoh sends stuff from the engine to AIs.
one event for each weapon fired would be bad for performance.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: SWeaponFiredEvent question

Post by ivand »

Hi!

I've seen that part of the code.
But if so many constraints applied, isn't the Event useless then?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: SWeaponFiredEvent question

Post by hoijui »

it is up to the AI dev to decide that. if it is useless for him, he can ignore it.

i extended documentation for the event now, will commit soon.
i am always happy if people do such stuff on a spring fork, i will merge it in then. some AI devs did that already.
i know that it is not nice to have to use an API which is not well documented. but keep in mind, that i did not write the API either (i just rewrote it). You already know how many functions there are in the AI callback, and then there are also events and commands. I already added a lot of docu, and some others helped too, but i will not go through all the functions, events and commands, and check all the code paths behind them and all stuff they depend on to find every little detail that could be of interest to an AI dev, and write it into nice comments. i guess you understand that ;-)
i do not use these functions myself, so i do not know which are unclear documented.
Whenever you investigate the inner functioning of a function, because it does not act according to its documentation, please document it right, and give it to me (as said, best through a git fork of spring).
so next time someone uses it, he does not have to go through the same process again.
also, besides the Lua interface maybe, this si already the most well documented part of the engine ;-)
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: SWeaponFiredEvent question

Post by yuritch »

Looks like this event will only trigger if the weapon is commandfire=1 (like dgun in TA-based mods and some other 'superweapons'). Not sure how useful this is to AI, maybe it can be used to dodge dgun shots?
Post Reply

Return to “AI”