MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ApplyDamageToGeneric

Function ApplyDamageToGeneric

Descent3/damage.cpp:1290–1418  ·  view source on GitHub ↗

Applies damage to robot objects. Handled differently than damage to players for obvious reasons.

Source from the content-addressed store, hash-verified

1288
1289// Applies damage to robot objects. Handled differently than damage to players for obvious reasons.
1290bool ApplyDamageToGeneric(object *hit_obj, object *killer, int damage_type, float damage, int server_says,
1291 int weapon_id) {
1292 ASSERT(hit_obj != NULL);
1293
1294 if (hit_obj->type == OBJ_DUMMY) {
1295 // as per ChrisP, dummies should be ignored here
1296 return false;
1297 }
1298
1299 if (hit_obj->flags & OF_AI_DEATH) {
1300 return false;
1301 }
1302
1303 // I don't think there's any problem with calling this function on an object that's not a generic
1304 // or a door, but I don't see why you would.
1305 ASSERT(IS_GENERIC(hit_obj->type) || (hit_obj->type == OBJ_DOOR));
1306
1307 object *weapon_obj = killer;
1308
1309 if (damage_type != GD_SCRIPTED &&
1310 !(IS_GENERIC(hit_obj->type) && (Object_info[hit_obj->id].flags & OIF_NO_DIFF_SCALE_DAMAGE)))
1311 damage *= Diff_robot_damage[DIFF_LEVEL];
1312
1313 if (killer != NULL && killer->type == OBJ_WEAPON) {
1314 killer = ObjGetUltimateParent(killer);
1315
1316 if (!(Game_mode & GM_MULTI) || (Game_mode & GM_MULTI && Netgame.local_role == LR_SERVER))
1317 weapon_id = weapon_obj->id;
1318 }
1319
1320 if (hit_obj->flags & OF_DESTROYABLE && (!(hit_obj->flags & OF_USE_DESTROYED_POLYMODEL))) {
1321 if ((Game_mode & GM_MULTI) && (hit_obj->flags & OF_DESTROYED)) {
1322 return false; // This object has already been sent to the server to be blown up!
1323 }
1324
1325 if (hit_obj->type == OBJ_POWERUP && (Game_mode & GM_MULTI))
1326 return false;
1327
1328 if ((!(Game_mode & GM_MULTI)) || server_says || ((Netgame.local_role == LR_SERVER) && (Game_mode & GM_MULTI))) {
1329 tOSIRISEventInfo ei;
1330 if (killer != NULL)
1331 ei.evt_damaged.it_handle = killer->handle;
1332 else
1333 ei.evt_damaged.it_handle = OBJECT_HANDLE_NONE;
1334
1335 if (weapon_obj)
1336 ei.evt_damaged.weapon_handle = weapon_obj->handle;
1337 else
1338 ei.evt_damaged.weapon_handle = OBJECT_HANDLE_NONE;
1339
1340 ei.evt_damaged.damage_type = damage_type;
1341 ei.evt_damaged.damage = damage;
1342 Osiris_CallEvent(hit_obj, EVT_DAMAGED, &ei);
1343
1344 // This statement allows a robot to have special resistances or vulerabilites to damage types
1345 damage = ei.evt_damaged.damage;
1346 if (damage == 0.0f) {
1347 return false;

Callers 8

collide_generic_and_wallFunction · 0.85
msafe_CallFunctionFunction · 0.85
MultiDoRobotDamageFunction · 0.85
DoConcussiveForceFunction · 0.85
do_melee_attackFunction · 0.85
ObjDoEffectsFunction · 0.85

Calls 8

ObjGetUltimateParentFunction · 0.85
Osiris_CallEventFunction · 0.85
CallGameDLLFunction · 0.85
MultiSendDamageObjectFunction · 0.85
KillObjectFunction · 0.85
SetDeformDamageEffectFunction · 0.85
SetNapalmDamageEffectFunction · 0.85
ApplyFreezeDamageEffectFunction · 0.85

Tested by

no test coverage detected