// Function for callbacks added by Cribbledirge. void CWeaponMagazined::StateSwitchCallback(GameObject::ECallbackType actor_type, GameObject::ECallbackType npc_type) { xr_string ammo_type; if (GetAmmoElapsed() == 0 || m_magazine.empty()) { ammo_type = *m_ammoTypes[m_ammoType]; } else { ammo_type = *m_ammoTypes[m_magazine.back().m_LocalAmmoType]; } if (g_actor) { if (smart_cast<CActor*>(H_Parent())) // This is an actor. { Actor()->callback(actor_type)( lua_game_object(), // The weapon as a game object. ammo_type.c_str() // The caliber of the weapon. ); } else if (smart_cast<CEntityAlive*>(H_Parent())) // This is an NPC. { Actor()->callback(npc_type)( smart_cast<CEntityAlive*>(H_Parent())->lua_game_object(), // The owner of the weapon. lua_game_object(), // The weapon itself. ammo_type.c_str() // The caliber of the weapon. ); } } }
void CWeaponMagazined::GetBriefInfo(xr_string& str_name, xr_string& icon_sect_name, xr_string& str_count) { int AE = GetAmmoElapsed(); int AC = GetAmmoCurrent(); if (AE == 0 || 0 == m_magazine.size()) icon_sect_name = *m_ammoTypes[m_ammoType]; else icon_sect_name = *m_ammoTypes[m_magazine.back().m_LocalAmmoType]; string256 sItemName; strcpy_s(sItemName, *CStringTable().translate(pSettings->r_string(icon_sect_name.c_str(), "inv_name_short"))); if (HasFireModes()) strcat_s(sItemName, GetCurrentFireModeStr()); str_name = sItemName; { if (!unlimited_ammo()) sprintf_s(sItemName, "%d/%d", AE, AC - AE); else sprintf_s(sItemName, "%d/--", AE); str_count = sItemName; } }
bool CWeapon::ready_to_kill () const { return ( !IsMisfire() && ((GetState() == eIdle) || (GetState() == eFire) || (GetState() == eFire2)) && GetAmmoElapsed() ); }
CInventoryItem *CWeapon::can_kill (CInventory *inventory) const { if (GetAmmoElapsed() || m_ammoTypes.empty()) return (const_cast<CWeapon*>(this)); TIItemContainer::iterator I = inventory->m_all.begin(); TIItemContainer::iterator E = inventory->m_all.end(); for ( ; I != E; ++I) { CInventoryItem *inventory_item = smart_cast<CInventoryItem*>(*I); if (!inventory_item) continue; xr_vector<shared_str>::const_iterator i = std::find(m_ammoTypes.begin(),m_ammoTypes.end(),inventory_item->object().cNameSect()); if (i != m_ammoTypes.end()) return (inventory_item); } return (0); }