Applies a default death to an object Parameters: objp - the object to destroy killer - the object who is killing it, or NULL damage - how much damage was applied in the death blow?
| 1034 | // killer - the object who is killing it, or NULL |
| 1035 | // damage - how much damage was applied in the death blow? |
| 1036 | void KillObject(object *objp, object *killer, float damage) { |
| 1037 | int death_flags = -1; |
| 1038 | float delay_time; |
| 1039 | |
| 1040 | // Make sure a valid type |
| 1041 | ASSERT(IS_GENERIC(objp->type) || (objp->type == OBJ_DOOR)); |
| 1042 | |
| 1043 | // Bail if already dying or exploding |
| 1044 | if ((objp->flags & OF_DYING) || (objp->flags & OF_DEAD)) |
| 1045 | return; |
| 1046 | |
| 1047 | // Get death info from the object page |
| 1048 | if (IS_GENERIC(objp->type)) { |
| 1049 | |
| 1050 | // Get random probability |
| 1051 | int r = (ps_rand() * 100 / (D3_RAND_MAX + 1)) + 1; // in range 1 to 100 |
| 1052 | |
| 1053 | // Loop through death types looking for chosen one |
| 1054 | for (int i = 0; i < MAX_DEATH_TYPES; i++) { |
| 1055 | int p = Object_info[objp->id].death_probabilities[i]; |
| 1056 | if (r <= p) { |
| 1057 | float delay_min, delay_max; |
| 1058 | |
| 1059 | death_flags = Object_info[objp->id].death_types[i].flags; |
| 1060 | |
| 1061 | delay_min = Object_info[objp->id].death_types[i].delay_min; |
| 1062 | delay_max = Object_info[objp->id].death_types[i].delay_max; |
| 1063 | |
| 1064 | delay_time = delay_min + (delay_max - delay_min) * ps_rand() / D3_RAND_MAX; |
| 1065 | |
| 1066 | mprintf(0, "Using %d\n", i); |
| 1067 | break; |
| 1068 | } |
| 1069 | r -= p; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | // If no death from page, generate default |
| 1074 | if (death_flags == -1) |
| 1075 | GenerateDefaultDeath(objp, &death_flags, &delay_time); |
| 1076 | |
| 1077 | // Now kill the object |
| 1078 | KillObject(objp, killer, damage, death_flags, delay_time); |
| 1079 | } |
| 1080 | |
| 1081 | // Sets the physics parameters for a falling object |
| 1082 | void SetFallingPhysics(object *objp) { |
no test coverage detected