| 131 | } |
| 132 | |
| 133 | void pickupItem(MessageType msg) |
| 134 | { |
| 135 | Pickup* pickup = (Pickup*)s_msgTarget; |
| 136 | SecObject* entity = (SecObject*)s_msgEntity; |
| 137 | if (msg == MSG_DAMAGE || msg == MSG_EXPLOSION) |
| 138 | { |
| 139 | return; |
| 140 | } |
| 141 | // Only the player can pickup an item. |
| 142 | if (entity && !(entity->entityFlags & ETFLAG_PLAYER)) |
| 143 | { |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | JBool pickedUpItem = s_playerDying ? JFALSE : JTRUE; |
| 148 | // Cannot pickup items while dying! |
| 149 | if (!pickedUpItem) |
| 150 | { |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | // Handle pickup based on type. |
| 155 | if (pickup->type == ITYPE_WEAPON) |
| 156 | { |
| 157 | s32 maxAmount = pickup->maxAmount; |
| 158 | if (!(*pickup->playerItem) || *pickup->playerAmmo < maxAmount) |
| 159 | { |
| 160 | *pickup->playerAmmo = pickup_addToValue(*pickup->playerAmmo, pickup->amount, maxAmount); |
| 161 | if (*pickup->playerItem) |
| 162 | { |
| 163 | // Player already has the weapon, so show ammo message |
| 164 | hud_sendTextMessage(pickup->msgId[1]); |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | // Add the weapon |
| 169 | *pickup->playerItem = JTRUE; |
| 170 | hud_sendTextMessage(pickup->msgId[0]); |
| 171 | s_playerInfo.newWeapon = pickup->weaponIndex; |
| 172 | } |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | pickedUpItem = JFALSE; |
| 177 | } |
| 178 | } |
| 179 | else if (pickup->type == ITYPE_AMMO) |
| 180 | { |
| 181 | // Shield powerups cannot be picked up while invincibility is enabled even if shields are at less than maximum. |
| 182 | if (pickup->id == ITEM_SHIELD && s_invincibility) |
| 183 | { |
| 184 | pickedUpItem = JFALSE; |
| 185 | } |
| 186 | s32 curValue = *pickup->playerAmmo; |
| 187 | if (pickedUpItem && curValue < pickup->maxAmount) |
| 188 | { |
| 189 | *pickup->playerAmmo = pickup_addToValue(*pickup->playerAmmo, pickup->amount, pickup->maxAmount); |
| 190 | hud_sendTextMessage(pickup->msgId[0]); |
no test coverage detected