• Welcome to Freedom Reborn Archive.
 

regDamage for Buildings

Started by GogglesPizanno, August 18, 2007, 05:40:33 PM

Previous topic - Next topic

GogglesPizanno

Ok here is a weird one directed at some of the scripting gurus.
I am working on a script that tracks how much total health damage is done to a map (based on the amount of health damage objects recieve).

I set up a regDamage event sink for all inanimate objects on a map.
for obj in js.Mission_GetObjects():
        oclass = js.Object_GetClass(obj)
        if ((oclass&(js.OC_CONTROLLABLE|js.OC_CHARACTER|js.OC_VILLIAN|js.OC_MINION))==0 ):
           cshelper.regDamage(obj, 'PublicDestruction')



def PublicDestruction(event):
    desObj = event.object
    healthchange = event.data   # IF BUILDING this returns '0'
    print js.Object_GetTemplate(desObj)
    print 'health: %s'%js.Object_GetAttr(desObj, 'health')
    print 'damage: %s'%healthchange
    cshelper.regDamage(desObj, 'PublicDestruction')


This works fine. Each time an object gets damaged, it returns the change in health (event.data)...EXCEPT for buildings.
The change in health always returns "0" for buildings.
Is there some quirk with buildings that anyone knows about (I'm apparently having universal building issues this week)

stumpy

I haven't looked at how building damage works in a while, and I recall there have been some improvements to regDamage() since the first game (e.g. I think previously it didn't return anything useful in event.data). But, I would speculate that what's likely different about buildings is that they take damage in sections so that the game can trigger the progressive collapses. I don't know that any other objects work that way, where the object we can access as the building is really a reflection of the section objects that compose it.

For buildings, it seems like the game looks at whatever damage would be done by an attack, but actually applies some other damage (presumably a fraction of the total) to the individual sections. My guess would be that that process mucks with (neglects) how the event fields are supposed to be set for the damage sink. For instance, since internally the sections themselves aren't really the same object that we have access to as the building, the game may apply damage to them, but not trigger the sink because it was for the whole object which was never directly damaged and we can't register a sink for the section objects.

If you need to track damage to buildings on a per damage basis (as opposed to total damage which you could get by comparing current health to maxHealth), you may have to set a check for their object class and get the damage from each attack by updating an 'oldHealth' or similar object variable.