New spiffy table-based code
| 2570 | extern uint8_t AutomapVisMap[MAX_ROOMS]; |
| 2571 | // New spiffy table-based code |
| 2572 | bool HandleWeaponPowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup) { |
| 2573 | object *player = ObjGet(mstruct->ithandle); |
| 2574 | object *powerup = ObjGet(mstruct->objhandle); |
| 2575 | int p; |
| 2576 | if (!player || !powerup) |
| 2577 | return 0; |
| 2578 | bool handled = false; |
| 2579 | ASSERT(player->type == OBJ_PLAYER); |
| 2580 | ASSERT(powerup->control_type == CT_POWERUP); |
| 2581 | // Check the primaries |
| 2582 | for (p = 0; p < NUM_POWERUP_TYPES_PRIMARY; p++) { |
| 2583 | if (!stricmp(powerup_data_primary[p].name, pname)) { |
| 2584 | handled = true; |
| 2585 | int weapon_index = powerup_data_primary[p].weapon_index; |
| 2586 | if (!PlayerHasWeapon(player->id, weapon_index)) { |
| 2587 | *pickup = 1; |
| 2588 | if (player->id == Player_num) |
| 2589 | AddFilteredHUDMessage(TXT(powerup_data_primary[p].pickup_msg)); |
| 2590 | AddWeaponToPlayer(player->id, weapon_index, powerup->ctype.powerup_info.count); |
| 2591 | } else { // we already have this weapon |
| 2592 | // If multiplayer, don't do anything (except print the message), so only do stuff if not multiplayer |
| 2593 | if (!(Game_mode & GM_MULTI)) { |
| 2594 | // If this is an ammo weapon, give the player the ammo |
| 2595 | if (powerup->ctype.powerup_info.count > 0) { |
| 2596 | int old_ammo = Players[player->id].weapon_ammo[weapon_index]; |
| 2597 | int added = AddWeaponAmmo(player->id, weapon_index, powerup->ctype.powerup_info.count); |
| 2598 | if (added) { // got ammo, so remove powerup |
| 2599 | *pickup = 1; |
| 2600 | if (player->id == Player_num) { |
| 2601 | ShowAmmoAddedMessage(weapon_index, powerup_data_primary[p].ammo_msg, added); |
| 2602 | if (old_ammo == 0) |
| 2603 | CheckForWeaponSelect(player->id, weapon_index); |
| 2604 | } |
| 2605 | } else { // did not get ammo from powerup, so say full |
| 2606 | if (player->id == Player_num) |
| 2607 | AddFilteredHUDMessage(TXT(powerup_data_primary[p].full_msg)); |
| 2608 | } |
| 2609 | } else { // not an ammo weapon (or has no ammo) |
| 2610 | // Give the player energy & remove powerup, if energy not full, |
| 2611 | if (AddPowerupEnergyToPlayer(player->id)) |
| 2612 | *pickup = 1; |
| 2613 | } |
| 2614 | } else { |
| 2615 | if (player->id == Player_num) |
| 2616 | AddFilteredHUDMessage(TXT_ALREADY_HAVE_WEAPON); |
| 2617 | } |
| 2618 | } |
| 2619 | } |
| 2620 | } |
| 2621 | // Check the secondaries |
| 2622 | for (p = 0; p < NUM_POWERUP_TYPES_SECONDARY; p++) { |
| 2623 | if (!stricmp(powerup_data_secondary[p].name, pname)) { |
| 2624 | handled = true; |
| 2625 | int weapon_index = powerup_data_secondary[p].weapon_index; |
| 2626 | // Does the player have any now? |
| 2627 | bool has_weapon = PlayerHasWeapon(player->id, weapon_index); |
| 2628 | // Determine how much to add |
| 2629 | int added = AddWeaponAmmo(player->id, weapon_index, powerup->ctype.powerup_info.count); |
no test coverage detected