JS API - eventAttacked() alternatives?

For AI and campaign script related discussions and questions
Post Reply
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

JS API - eventAttacked() alternatives?

Post by aubergine »

Hi,

I've been looking at the eventAttacked() event and it strikes me as being overkill. My understanding is that this event will get called every single time anything I own (structure or droid) is attacked. That means this event is going to get called *a lot*, and as its currently the only way to know if I've been attacked (and react to that situation) it's likely I'm going to have a fair chunk of code in the event handler = performance issues.

IMHO, it might be better to ditch eventAttacked() event (or at least have a strong health warning on its use) and instead have events such as:

eventStructureUnderAttack(victim,attacker) & eventDroidUnderAttack(victim,attacker)

This event would get triggered when a structure/droid that hasn't been attacked for the past 60? seconds is attacked. So it would get called at most once per minute for a given structure/droid.

This event will let me make decisions when new attacks occur, rather than repeatedly whilst under attack.

IMHO this event should be used in preference to eventAttacked() as it will significantly reduce the amount of attack event handling overhead in an AI.

eventStructureImcomingAttack(victim,attacker) & eventDroidIncomingAttack(victim,attacker)

EDIT: This event would be nice, but not vital - the others on the page are more important.

Similar to the previous events, but this gets called before a new attack starts, primarily when enemy droids (rather than artillery, etc) are about to attack (or are coming in to attack range of) my structure/droid.

eventStructureMediumDamage(victim,attacker) & eventDroidMediumDamage(victim,attacker)

I assume the game already has some mechanism to determine this point in time - especially for droids, as in-game I can set a droid to return for repair on medium damage. But I'd want this for structures too.

So, this event would trigger when a droid/structure damage level reaches medium damage.

This event will allow me to make decisions as to whether to repair/retreat something when it reaches medium damage level.

eventStructureHeavyDamage(victim,attacker) & eventDroidHeavyDamage(victim,attacker)

Same sort of thing as medium, but for heavy damage.

eventStructureDestroyed(victim,attacker) & eventDroidDestroyed(victim,attacker)

This will allow me to replenish attack groups, etc., or update build orders.

eventNewStructureDetected(structure,sensor) & eventNewDroidDetected(droid,sensor) & eventNewFeatureDetected(droid,sensor)

When my sensors detect something new on the map, trigger relevant event.

This will enable my AI to act proactively - eg. heading off an incoming invasion, or attacking a new enemy building, or start building defences, etc.

The 'sensor' param would be whatever detected the new structure/droid. Eg. a sensor, satellite uplink, or nearby structure/droid.

The ability to know when new features are detected is v. useful, for example I could expose a previously non-visible (in fog of war) oil resource and in the event choose to build a derrik on it. Or I could spot trees and decide to destroy them to make room for new buildings.

eventIncomingLaserSatelliteStrike(attacker,visible)

EDIT: This event would be nice, but not vital - the others on the page are more important.

Sort of obvious really - it won't tell me where the lsat will strike, but it will tell me which lsat structure initiated the attack.

The visible param tells me if that lsat structure is visible to my team - eg. it's not really fair for my AI to know where the lsat stucture is and attack it, if it can't see it on the map: a human player wouldn't be able to do that so why should AI?
Last edited by aubergine on 13 Jan 2012, 15:25, edited 3 times in total.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: JS API - eventAttacked() alternatives?

Post by NoQ »

I'd also like to have a way to figure out the object's health.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: JS API - eventAttacked() alternatives?

Post by aubergine »

I guess object health could be a property of base obejct (and thus inherited by droid/structure/feature objects)?

Also, it would be useful to have a "isVisible" param on base object, telling me whether the droid/struct/feature is visible to my team. Return values could be:

* VISIBLITY_FULL = the item is not in the fog of war, eg. it's fully visible on my radar and I can go look at it on the map
* VISIBLITY_ECHO = the item is in fog of war, but still detected (eg. a droid just after it's moved in to fog, or a building that was detected earlier but is now in fog)
* VISIBLITY_NONE = the player/alliance can't see it.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: JS API - eventAttacked() alternatives?

Post by aubergine »

An eventDroidIdle(droid) event would be mega useful as well - currently I have to set a timeout and keep checking all droids to see if they are idle in order to give next command. An event telling me that a droid is idle would remove the need for that costly/crufty timeout and allow me to set idle droids to work immediately.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: JS API - eventAttacked() alternatives?

Post by Per »

eventAttacked() is throttled, so do not worry too much about it being called too many times. (Not sure how exactly it works, but it is the same as in wzscript.)

eventDroidIdle() already exists. I'm not sure that it covers all the cases yet, so for now check regularly if anyone have fallen out of the loop.

All (or nearly all) functions that give you objects allow you to filter by visibility.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: JS API - eventAttacked() alternatives?

Post by aubergine »

If eventAttacked() is throttled does that mean that not all attacks trigger that event? I'd much rather have other events, that happen less frequently, but know that they will always be triggered as it would allow my AI to both take much more control over the situation and also do the minimum amount of processing in the event handler.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply