JS API - eventAttacked() alternatives?
Posted: 13 Jan 2012, 14:02
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?
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?