| 1138 | } |
| 1139 | } |
| 1140 | void DoDeathSpew(object *parent) { |
| 1141 | ASSERT(IS_GENERIC(parent->type)); |
| 1142 | int i, j; |
| 1143 | int num_last_type = 0; |
| 1144 | uint8_t f_dspew = Object_info[parent->id].f_dspew; |
| 1145 | |
| 1146 | if (!parent) |
| 1147 | return; |
| 1148 | for (i = 0; i < MAX_DSPEW_TYPES; i++) { |
| 1149 | int type; |
| 1150 | int id; |
| 1151 | id = Object_info[parent->id].dspew[i]; |
| 1152 | if (id == -1) |
| 1153 | continue; // spew type set to none |
| 1154 | type = Object_info[id].type; |
| 1155 | int max_spewed = Object_info[parent->id].dspew_number[i]; |
| 1156 | int rand_val = (int)((float)D3_RAND_MAX * Object_info[parent->id].dspew_percent[i]); |
| 1157 | // Skip it if the player has that weapon battery enabled |
| 1158 | // If multiplayer, it will spew type 2 if no type 1 is spewed |
| 1159 | if (i == 0 && (f_dspew & DSF_ONLY_IF_PLAYER_HAS_OBJ_1)) { |
| 1160 | bool f_skip = false; |
| 1161 | |
| 1162 | if (Game_mode & GM_MULTI) { |
| 1163 | f_dspew &= ~DSF_ONLY_IF_PLAYER_HAS_OBJ_1; |
| 1164 | f_dspew |= DSF_ONLY_IF_NO_1; |
| 1165 | } else if (type == OBJ_POWERUP) { |
| 1166 | player *playp = &Players[0]; |
| 1167 | for (j = 0; j < MAX_PLAYER_WEAPONS; j++) { |
| 1168 | if (playp->weapon_flags & HAS_FLAG(j)) { |
| 1169 | int p_id = Ships[playp->ship_index].spew_powerup[j]; |
| 1170 | if (p_id == id) { |
| 1171 | f_skip = true; |
| 1172 | break; |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | if (f_skip) |
| 1177 | continue; |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | if (i == 1 && (f_dspew & DSF_ONLY_IF_NO_1) && num_last_type != 0) |
| 1182 | continue; |
| 1183 | num_last_type = 0; |
| 1184 | for (j = 0; j < max_spewed; j++) { |
| 1185 | if (ps_rand() <= rand_val) { |
| 1186 | int objnum = ObjCreate(type, id, parent->roomnum, &parent->pos, NULL); |
| 1187 | num_last_type++; |
| 1188 | if (objnum < 0) { |
| 1189 | mprintf(0, "Couldn't spew object!\n"); |
| 1190 | return; |
| 1191 | } |
| 1192 | object *obj = &Objects[objnum]; |
| 1193 | |
| 1194 | // Set random velocity for powerups |
| 1195 | obj->mtype.phys_info.velocity.x = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 35.0; |
| 1196 | obj->mtype.phys_info.velocity.z = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 35.0; |
| 1197 | obj->mtype.phys_info.velocity.y = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 35.0; |
no test coverage detected