MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / getAutoreloadAmmoType

Function getAutoreloadAmmoType

game/state/shared/aequipment.cpp:291–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291static sp<AEquipment> getAutoreloadAmmoType(const AEquipment &weapon)
292{
293 LogAssert(weapon.type->type == AEquipmentType::Type::Weapon);
294 LogAssert(weapon.getPayloadType() != weapon.type);
295
296 // Check if the auto-reload option is disabled
297 if (!Options::optionAutoReload.get())
298 {
299 return nullptr;
300 }
301
302 // Prefer loading the same type of ammo again
303 if (weapon.lastLoadedAmmoType)
304 {
305 auto equippedAmmo = weapon.ownerAgent->getFirstItemByType(weapon.lastLoadedAmmoType);
306 if (equippedAmmo)
307 {
308 LogAssert(equippedAmmo->type->type == AEquipmentType::Type::Ammo);
309 return equippedAmmo;
310 }
311 }
312 // Otherwise find any possible ammo on the agent
313 for (const auto &ammoType : weapon.type->ammo_types)
314 {
315 auto equippedAmmo = weapon.ownerAgent->getFirstItemByType(ammoType);
316 if (equippedAmmo)
317 {
318 LogAssert(equippedAmmo->type->type == AEquipmentType::Type::Ammo);
319 return equippedAmmo;
320 }
321 }
322 // No ammo found
323 return nullptr;
324}
325
326void AEquipment::loadAmmo(GameState &state, sp<AEquipment> ammoItem)
327{

Callers 1

loadAmmoMethod · 0.85

Calls 3

getPayloadTypeMethod · 0.80
getFirstItemByTypeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected