Game Development Community

Function Hierarchy -> Damage to DamageState

by Rutger Van Dijk · in RTS Starter Kit · 06/24/2005 (7:30 am) · 2 replies

Hi,

I was exploring how damage was dealt and updated to units, but i find the function calls confusing. To a point where I am not sure, exactly where it is checked if they are actually dead... From the beginning, if we presume that the user selected attack and clicked on the unit, we take onMouseDown in inputHandler.cs as our starting point.

inputHandler.cs
-> onMouseDown
	-> case RTSUnit 	-> calls onMouseDownUnit
-> onMouseDownUnit	
	-> case Attack	-> calls commandToServer('IssueAttack', ID)

commands.cs
-> serverCmdIssueAttack
	-> calls sendAttackEvent(%client.selection, %target) for every selected unit
	-> calls setAimObject(%target) for every selected unit

aiPlayer.cc 
-> SetAimObject	// just sets the private variable mAimObject - for processTick to handle later (?)
	-> mAimObject = targetObject;

rtsConnection.cc
-> sendAttackEvent
      -> RTSUnitAttackEvent* event = new RTSUnitAttackEvent;
      -> event->selection = attackSet;
      -> event->victim = victim;
      -> postNetEvent(event);

Now - processTick in RTSUnit.cc takes a look at if a unit is attacking or not. If it is at some point it calls:

->Con::executef(mDataBlock, 3, "onAttack", scriptThis(), mAimObject->getIdString());

I presume this calls the 'onAttack' of any UnitBaseBlock, which calls:
-> applyDamage(%target) 

The only file containing applyDamage is ShapeBase.cc, which calls
->updateDamageLevel     // confusing function, it sets stuff for the mDamageThread - i couldn't figure out what it was for. later it executes:
-> setDamageLevel(mDamage + amount)
	-> Con::executef(mDataBlock,3,"onDamage",scriptThis(),delta);

This does a callback to 'onDamage' of the UnitBaseBlock within player.cs. which calls
-> messageClient(%obj.client, 'MsgUnitAttacked', "", getWords(%obj.getPosition(), 0, 2));

But this skips any "damage dealing/checking if dead". I am confused how Torque jumps from code to code I presume... I have located some of this functionality in RTSUnit.cc and player.cc - but i just can't seem to get my head around how these are called. How exactly is the hierarchy like? How are ShapeBase/RTSUnit and Player related? Do they inherit each others functions / overwrite? Are they parents? - sorry to bother you guys with this, just need to get my head around it. So many functions and classes, it's hard to get your head around it.

Thanks,
Rutger :)

#1
06/24/2005 (3:12 pm)
No hierarchy, just different namespaces calling into one another. :)

IIRC, Unit A will attack Unit B. A will trigger (either directly or by means of a projectile) applyDamage on B. This causes a series of callbacks in B which ultimately result in B's health being decremented and, potentially, B runing out of health and entering a Damaged/Dead state.

You might want to try setting trace(1) so you can see what's happening on the script side here.
#2
06/27/2005 (7:24 am)
As another FYI on this, don't get the RTS SK model for damage confused with the original TGE 1.3 version--much of the damage state code was bypassed (not the call to applyDamage directly--the 1.3 code itself says this isn't a "good" thing to do. That applies to 1.3, but it was done in RTS SK due to a different game model).

I personally feel this should have been done better, and it's on the plate for future re-working, but right now we're still focusing on optimizing other, more directly important portions of the RTS SK, like vis manager, as well as possibly examples for collision avoidance and handling.