void CObjectActionReload::execute () { inherited::execute (); VERIFY (m_item); VERIFY (object().inventory().ActiveItem()); VERIFY (object().inventory().ActiveItem()->object().ID() == m_item->object().ID()); CWeapon *weapon = smart_cast<CWeapon*>(object().inventory().ActiveItem()); VERIFY (weapon); if (weapon->IsPending()) return; if (weapon->GetAmmoElapsed()) { VERIFY (weapon->GetSuitableAmmoTotal() >= weapon->GetAmmoElapsed()); if (weapon->GetSuitableAmmoTotal() == weapon->GetAmmoElapsed()) return; VERIFY (weapon->GetAmmoMagSize() >= weapon->GetAmmoElapsed()); if (weapon->GetAmmoMagSize() == weapon->GetAmmoElapsed()) return; } object().inventory().Action (kWPN_RELOAD,CMD_START); }
float CPersonalWeaponTypeFunction::ffGetTheBestWeapon() { u32 dwBestWeapon = 0; if (ef_storage().non_alife().member() && ef_storage().non_alife().member_item()) return (float(dwfGetWeaponType())); if (ef_storage().non_alife().member()) { const CInventoryOwner *tpInventoryOwner = smart_cast<const CInventoryOwner*>(ef_storage().non_alife().member()); if (tpInventoryOwner) { xr_vector<CInventorySlot>::const_iterator I = tpInventoryOwner->inventory().m_slots.begin(); xr_vector<CInventorySlot>::const_iterator E = tpInventoryOwner->inventory().m_slots.end(); for ( ; I != E; ++I) if ((*I).m_pIItem) { CWeapon *tpCustomWeapon = smart_cast<CWeapon*>((*I).m_pIItem); if (tpCustomWeapon && (tpCustomWeapon->GetSuitableAmmoTotal(true) > tpCustomWeapon->GetAmmoMagSize()/10)) { ef_storage().non_alife().member_item() = tpCustomWeapon; u32 dwCurrentBestWeapon = dwfGetWeaponType(); if (dwCurrentBestWeapon > dwBestWeapon) dwBestWeapon = dwCurrentBestWeapon; ef_storage().non_alife().member_item() = 0; } } } } else { if (!ef_storage().alife().member() || !ef_storage().alife().member()->m_tpCurrentBestWeapon) return(0); ef_storage().alife().member_item() = ef_storage().alife().member()->m_tpCurrentBestWeapon; dwBestWeapon = dwfGetWeaponType(); } return(float(dwBestWeapon)); }
bool CAI_Stalker::ready_to_detour () { if (!ready_to_kill()) return (false); CWeapon *weapon = smart_cast<CWeapon*>(m_best_item_to_kill); if (!weapon) return (false); return (weapon->GetAmmoElapsed() > weapon->GetAmmoMagSize()/2); }
void CUIWpnParams::SetInfo( CInventoryItem* slot_wpn, CInventoryItem& cur_wpn ) { if ( !g_lua_wpn_params ) { g_lua_wpn_params = xr_new<SLuaWpnParams>(); } LPCSTR cur_section = cur_wpn.object().cNameSect().c_str(); string2048 str_upgrades; str_upgrades[0] = 0; cur_wpn.get_upgrades_str( str_upgrades ); float cur_rpm = iFloor(g_lua_wpn_params->m_functorRPM( cur_section, str_upgrades )*53.0f)/53.0f; float cur_accur = iFloor(g_lua_wpn_params->m_functorAccuracy( cur_section, str_upgrades )*53.0f)/53.0f; float cur_hand = iFloor(g_lua_wpn_params->m_functorHandling( cur_section, str_upgrades )*53.0f)/53.0f; float cur_damage = ( GameID() == eGameIDSingle ) ? iFloor(g_lua_wpn_params->m_functorDamage( cur_section, str_upgrades )*53.0f)/53.0f : iFloor(g_lua_wpn_params->m_functorDamageMP( cur_section, str_upgrades )*53.0f)/53.0f; float slot_rpm = cur_rpm; float slot_accur = cur_accur; float slot_hand = cur_hand; float slot_damage = cur_damage; if ( slot_wpn && (slot_wpn != &cur_wpn) ) { LPCSTR slot_section = slot_wpn->object().cNameSect().c_str(); str_upgrades[0] = 0; slot_wpn->get_upgrades_str( str_upgrades ); slot_rpm = iFloor(g_lua_wpn_params->m_functorRPM( slot_section, str_upgrades )*53.0f)/53.0f; slot_accur = iFloor(g_lua_wpn_params->m_functorAccuracy( slot_section, str_upgrades )*53.0f)/53.0f; slot_hand = iFloor(g_lua_wpn_params->m_functorHandling( slot_section, str_upgrades )*53.0f)/53.0f; slot_damage = ( GameID() == eGameIDSingle ) ? iFloor(g_lua_wpn_params->m_functorDamage( slot_section, str_upgrades )*53.0f)/53.0f : iFloor(g_lua_wpn_params->m_functorDamageMP( slot_section, str_upgrades )*53.0f)/53.0f; } m_progressAccuracy.SetTwoPos( cur_accur, slot_accur ); m_progressDamage.SetTwoPos( cur_damage, slot_damage ); m_progressHandling.SetTwoPos( cur_hand, slot_hand ); m_progressRPM.SetTwoPos( cur_rpm, slot_rpm ); if(IsGameTypeSingle()) { xr_vector<shared_str> ammo_types; CWeapon* weapon = cur_wpn.cast_weapon(); if(!weapon) return; int ammo_count = weapon->GetAmmoMagSize(); int ammo_count2 = ammo_count; if(slot_wpn) { CWeapon* slot_weapon = slot_wpn->cast_weapon(); if(slot_weapon) ammo_count2 = slot_weapon->GetAmmoMagSize(); } if(ammo_count==ammo_count2) m_textAmmoCount2.SetTextColor(color_rgba(170,170,170,255)); else if(ammo_count<ammo_count2) m_textAmmoCount2.SetTextColor(color_rgba(255,0,0,255)); else m_textAmmoCount2.SetTextColor(color_rgba(0,255,0,255)); string128 str; xr_sprintf(str, sizeof(str), "%d", ammo_count); m_textAmmoCount2.SetText(str); ammo_types = weapon->m_ammoTypes; if(ammo_types.empty()) return; xr_sprintf(str, sizeof(str), "%s", pSettings->r_string(ammo_types[0].c_str(), "inv_name_short")); m_textAmmoUsedType.SetTextST(str); m_stAmmoType1.SetShader(InventoryUtilities::GetEquipmentIconsShader()); Frect tex_rect; tex_rect.x1 = float(pSettings->r_u32(ammo_types[0].c_str(), "inv_grid_x") * INV_GRID_WIDTH); tex_rect.y1 = float(pSettings->r_u32(ammo_types[0].c_str(), "inv_grid_y") * INV_GRID_HEIGHT); tex_rect.x2 = float(pSettings->r_u32(ammo_types[0].c_str(), "inv_grid_width") * INV_GRID_WIDTH ); tex_rect.y2 = float(pSettings->r_u32(ammo_types[0].c_str(), "inv_grid_height") * INV_GRID_HEIGHT); tex_rect.rb.add (tex_rect.lt); m_stAmmoType1.SetTextureRect(tex_rect); m_stAmmoType1.TextureOn(); m_stAmmoType1.SetStretchTexture(true); m_stAmmoType1.SetWndSize(Fvector2().set((tex_rect.x2-tex_rect.x1)*UI().get_current_kx(), tex_rect.y2-tex_rect.y1)); m_stAmmoType2.SetShader(InventoryUtilities::GetEquipmentIconsShader()); if(ammo_types.size()==1) { tex_rect.set(0,0,1,1); } else { tex_rect.x1 = float(pSettings->r_u32(ammo_types[1].c_str(), "inv_grid_x") * INV_GRID_WIDTH); tex_rect.y1 = float(pSettings->r_u32(ammo_types[1].c_str(), "inv_grid_y") * INV_GRID_HEIGHT); tex_rect.x2 = float(pSettings->r_u32(ammo_types[1].c_str(), "inv_grid_width") * INV_GRID_WIDTH ); tex_rect.y2 = float(pSettings->r_u32(ammo_types[1].c_str(), "inv_grid_height") * INV_GRID_HEIGHT); tex_rect.rb.add (tex_rect.lt); } m_stAmmoType2.SetTextureRect(tex_rect); m_stAmmoType2.TextureOn(); m_stAmmoType2.SetStretchTexture(true); m_stAmmoType2.SetWndSize(Fvector2().set((tex_rect.x2-tex_rect.x1)*UI().get_current_kx(), tex_rect.y2-tex_rect.y1)); } }