//передаче вещи из своего инвентаря в инвентарь партнера void CScriptGameObject::TransferItem(CScriptGameObject* pItem, CScriptGameObject* pForWho) { if (!pItem || !pForWho) { ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "cannot transfer NULL item"); return; } CInventoryItem* pIItem = smart_cast<CInventoryItem*>(&pItem->object()); if (!pIItem) { ai().script_engine().script_log(ScriptStorage::eLuaMessageTypeError, "Cannot transfer not CInventoryItem item"); return; } NET_Packet P; // выбросить у себя if (NULL != pItem->object().H_Parent() && this != pItem) // из скриптов часто подбираются "независимые" предметы { CGameObject::u_EventGen(P, GE_OWNERSHIP_REJECT, object().ID()); P.w_u16(pIItem->object().ID()); CGameObject::u_EventSend(P); } // отдать партнеру CGameObject::u_EventGen (P,GE_OWNERSHIP_TAKE, pForWho->object().ID()); P.w_u16 (pIItem->object().ID()); CGameObject::u_EventSend (P); }
CUIDragDropListEx* CUIMpTradeWnd::GetMatchedListForItem(const shared_str& sect_name) { CUIDragDropListEx* res = NULL; u8 list_idx = m_item_mngr->GetItemSlotIdx(sect_name); VERIFY (list_idx<e_total_lists && list_idx!=e_shop); res = m_list[list_idx]; //special case if(list_idx==e_pistol_ammo || list_idx==e_rifle_ammo) { CUICellItem* ci = (m_list[list_idx-1]->ItemsCount())?m_list[list_idx-1]->GetItemIdx(0):NULL; if(!ci) return m_list[e_player_bag]; CInventoryItem* ii = (CInventoryItem*)ci->m_pData; if(!ii->IsNecessaryItem(sect_name)) return m_list[e_player_bag]; } if(list_idx==e_pistol || list_idx==e_rifle || list_idx==e_outfit || list_idx==e_outfit) { if (m_list[list_idx]->ItemsCount() ) return m_list[e_player_bag]; } return res; }
void CUIBagWnd::ReloadItemsPrices () { string256 ItemCostStr = ""; string256 RankStr = ""; u32 sz = m_allItems.size(); for (u32 i = 0; i<sz; i++) { CUICellItem* itm = m_allItems[i]; CInventoryItem* iitm = (CInventoryItem*)itm->m_pData; const shared_str itm_name = iitm->object().cNameSect(); m_info[itm->m_index].price = pSettings->r_u32(m_sectionPrice, *itm_name); strconcat (sizeof(ItemCostStr),ItemCostStr, itm_name.c_str(), "_cost"); if (pSettings->line_exist (m_sectionPrice, ItemCostStr)) m_info[itm->m_index].price = pSettings->r_u32(m_sectionPrice, ItemCostStr); for (u32 i=1; i<=g_mp_restrictions.GetRank(); ++i) { sprintf_s (RankStr, "rank_%d", i); if (!pSettings->line_exist (RankStr, ItemCostStr)) continue; m_info[itm->m_index].price = pSettings->r_u32(RankStr, ItemCostStr); } } }
void CActor::PickupInfoDraw(CObject* object) { LPCSTR draw_str = NULL; CInventoryItem* item = smart_cast<CInventoryItem*>(object); if(!item) return; Fmatrix res; res.mul (Device.mFullTransform,object->XFORM()); Fvector4 v_res; Fvector shift; draw_str = item->NameItem(); shift.set(0,0,0); res.transform(v_res,shift); if (v_res.z < 0 || v_res.w < 0) return; if (v_res.x < -1.f || v_res.x > 1.f || v_res.y<-1.f || v_res.y>1.f) return; float x = (1.f + v_res.x)/2.f * (Device.dwWidth); float y = (1.f - v_res.y)/2.f * (Device.dwHeight); UI().Font().pFontLetterica16Russian->SetAligment (CGameFont::alCenter); UI().Font().pFontLetterica16Russian->SetColor (PICKUP_INFO_COLOR); UI().Font().pFontLetterica16Russian->Out (x,y,draw_str); }
//передаче вещи из своего инвентаря в инвентарь партнера void CScriptGameObject::TransferItem(CScriptGameObject* pItem, CScriptGameObject* pForWho) { if (!pItem || !pForWho) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"cannot transfer NULL item"); return; } CInventoryItem* pIItem = smart_cast<CInventoryItem*>(&pItem->object()); if (!pIItem) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"Cannot transfer not CInventoryItem item"); return ; } // выбросить у себя NET_Packet P; CGameObject::u_EventGen (P,GE_TRADE_SELL, object().ID()); P.w_u16 (pIItem->object().ID()); CGameObject::u_EventSend (P); // отдать партнеру CGameObject::u_EventGen (P,GE_TRADE_BUY, pForWho->object().ID()); P.w_u16 (pIItem->object().ID()); CGameObject::u_EventSend (P); }
CInventoryItem* CUIMpTradeWnd::CreateItem_internal(const shared_str& name_sect) { CLASS_ID class_id = pSettings->r_clsid(name_sect,"class"); DLL_Pure *dll_pure = xrFactory_Create(class_id); VERIFY (dll_pure); CInventoryItem* pIItem = smart_cast<CInventoryItem*>(dll_pure); pIItem->object().Load (name_sect.c_str()); VERIFY (pIItem); return (pIItem); }
CUICellItem* CUIBagWnd::CreateItem(const shared_str& name_sect) { counter++; CLASS_ID class_id = pSettings->r_clsid(name_sect,"class"); DLL_Pure *dll_pure = xrFactory_Create(class_id); VERIFY (dll_pure); CInventoryItem* pIItem = smart_cast<CInventoryItem*>(dll_pure); pIItem->object().Load (name_sect.c_str()); VERIFY (pIItem); return create_cell_item (pIItem); }
CUICellItem* CUIBagWnd::GetItemBySectoin(const shared_str& sectionName, bool bCreateOnFail){ u32 sz = m_allItems.size(); for (u32 i = 0; i < sz; i++) { CInventoryItem* iitem = (CInventoryItem*)m_allItems[i]->m_pData; if( iitem->object().cNameSect() == sectionName ) { if (IsInBag(m_allItems[i])) return m_allItems[i]; } } return NULL; }
CScriptGameObject *CScriptGameObject::item_in_slot (u32 slot_id) const { CInventoryOwner *inventory_owner = smart_cast<CInventoryOwner*>(&object()); if (!inventory_owner) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CInventoryOwner : cannot access class member item_in_slot!"); return (0); } if (inventory_owner->inventory().m_slots.size() <= slot_id) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CInventoryOwner : invalid slot id for class member item_in_slot : %d!",slot_id); return (0); } CInventoryItem *result = inventory_owner->inventory().m_slots[slot_id].m_pIItem; return (result ? result->object().lua_game_object() : 0); }
void CAI_Trader::feel_touch_new (CObject* O) { if (!g_Alive()) return; if (Remote()) return; // Now, test for game specific logical objects to minimize traffic CInventoryItem *I = smart_cast<CInventoryItem*> (O); if (I && I->useful_for_NPC()) { Msg("Taking item %s!",*I->object().cName()); NET_Packet P; u_EventGen (P,GE_OWNERSHIP_TAKE,ID()); P.w_u16 (u16(I->object().ID())); u_EventSend (P); } }
u8 CUIBagWnd::GetItemIndex(CUICellItem* pItem, u8 §ionNum){ sectionNum = 0; u8 ret = static_cast<u8>(-1); if (!pItem) return ret; ret = static_cast<u8>(m_info[pItem->m_index].pos_in_section); sectionNum = static_cast<u8>(m_info[pItem->m_index].section); CInventoryItem* iitem = (CInventoryItem*)pItem->m_pData; if (iitem->GetSlot() == PISTOL_SLOT || iitem->GetSlot() == RIFLE_SLOT) { CWeapon* pWeapon = (CWeapon*)pItem->m_pData; u8 addon = pWeapon->GetAddonsState(); if (addon & CSE_ALifeItemWeapon::eWeaponAddonScope) ret |= 1<<5; if (addon & CSE_ALifeItemWeapon::eWeaponAddonGrenadeLauncher) ret |= 1<<6; if (addon & CSE_ALifeItemWeapon::eWeaponAddonSilencer) ret |= 1<<7; } //returnID = static_cast<u8>(pDDItem->GetPosInSectionsGroup()); //sectionNum = static_cast<u8>(pDDItem->GetSectionGroupID()); //// Проверяем на наличие приаттаченых аддонов к оружию //if (pDDItem->bAddonsAvailable) //{ // u8 flags = 0; // for (int i = 0; i < 3; ++i) // { // if (1 == pDDItem->m_AddonInfo[i].iAttachStatus) // flags |= 1; // flags = flags << 1; // } // flags = flags << 4; // // В результате старшие 3 бита являются флагами признаков аддонов: // // FF - Scope, FE - Silencer, FD - Grenade Launcher // returnID |= flags; //} return ret; }
// KD // functions for CInventoryOwner class CScriptGameObject *CScriptGameObject::ItemOnBelt (u32 item_id) const { CInventoryOwner *inventory_owner = smart_cast<CInventoryOwner*>(&object()); if (!inventory_owner) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CInventoryOwner : cannot access class member item_on_belt!"); return (0); } TIItemContainer *belt = &(inventory_owner->inventory().m_belt); if (belt->size() < item_id) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"item_on_belt: item id outside belt!"); return (0); } CInventoryItem *result = belt->at(item_id); return (result ? result->object().lua_game_object() : 0); }
bool CActor::feel_touch_contact (CObject *O) { CInventoryItem *item = smart_cast<CInventoryItem*>(O); CInventoryOwner *inventory_owner = smart_cast<CInventoryOwner*>(O); if (item && item->Useful() && !item->object().H_Parent()) return true; if(inventory_owner && inventory_owner != smart_cast<CInventoryOwner*>(this)) { //CPhysicsShellHolder* sh=smart_cast<CPhysicsShellHolder*>(O); //if(sh&&sh->character_physics_support()) m_feel_touch_characters++; return true; } return (false); }
void CUIWpnParams::SetInfo( CInventoryItem const* slot_wpn, CInventoryItem const& cur_wpn ) { if ( !g_lua_wpn_params ) { g_lua_wpn_params = 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 = g_lua_wpn_params->m_functorRPM( cur_section, str_upgrades ); float cur_accur = g_lua_wpn_params->m_functorAccuracy( cur_section, str_upgrades ); float cur_hand = g_lua_wpn_params->m_functorHandling( cur_section, str_upgrades ); float cur_damage = ( GameID() == eGameIDSingle ) ? g_lua_wpn_params->m_functorDamage( cur_section, str_upgrades ) : g_lua_wpn_params->m_functorDamageMP( cur_section, str_upgrades ); 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 = g_lua_wpn_params->m_functorRPM( slot_section, str_upgrades ); slot_accur = g_lua_wpn_params->m_functorAccuracy( slot_section, str_upgrades ); slot_hand = g_lua_wpn_params->m_functorHandling( slot_section, str_upgrades ); slot_damage = ( GameID() == eGameIDSingle ) ? g_lua_wpn_params->m_functorDamage( slot_section, str_upgrades ) : g_lua_wpn_params->m_functorDamageMP( slot_section, str_upgrades ); } 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 ); }
bool CUIBagWnd::UpdateRank(CUICellItem* pItem) { CInventoryItem* pIItem; pIItem = (CInventoryItem*)pItem->m_pData; bool av = g_mp_restrictions.IsAvailable(*pIItem->object().cNameSect()); if (av || m_bIgnoreRank) { SET_NO_RESTR_COLOR (pItem); m_info[pItem->m_index].active = true; } else { SET_RANK_RESTR_COLOR (pItem); m_info[pItem->m_index].active = false; } return av; }
void CAI_Stalker::feel_touch_new (CObject* O) { // Msg ("FEEL_TOUCH::NEW : %s",*O->cName()); if (!g_Alive()) return; if (Remote()) return; if ((O->spatial.type | STYPE_VISIBLEFORAI) != O->spatial.type) return; // Now, test for game specific logical objects to minimize traffic CInventoryItem *I = smart_cast<CInventoryItem*> (O); if (!wounded() && !critically_wounded() && I && I->useful_for_NPC() && can_take(I)) { #ifndef SILENCE Msg("Taking item %s (%d)!",*I->cName(),I->ID()); #endif NET_Packet P; u_EventGen (P,GE_OWNERSHIP_TAKE,ID()); P.w_u16 (u16(I->object().ID())); u_EventSend (P); } }
void CUIConditionParams::SetInfo( CInventoryItem const* slot_item, CInventoryItem const& cur_item ) { float cur_value = cur_item.GetConditionToShow() * 100.0f + 1.0f - EPS; float slot_value = cur_value; if ( slot_item && (slot_item != &cur_item) /*&& (cur_item.object().cNameSect()._get() == slot_item->object().cNameSect()._get())*/ ) { slot_value = slot_item->GetConditionToShow() * 100.0f + 1.0f - EPS; } m_progress.SetTwoPos( cur_value, slot_value ); }
bool CCustomDetector::CheckCompatibilityInt(CHudItem* itm) { if(itm==NULL) return true; CInventoryItem iitm = itm->item(); u32 slot = iitm.GetSlot(); bool bres = (slot==PISTOL_SLOT || slot==KNIFE_SLOT || slot==BOLT_SLOT); if(itm->GetState()!=CHUDState::eShowing) bres = bres && !itm->IsPending(); if(bres) { CWeapon* W = smart_cast<CWeapon*>(itm); if(W) bres = bres && (W->GetState() != CHUDState::eBore) && (W->GetState() != CWeapon::eReload) && (W->GetState() != CWeapon::eSwitch) && !W->IsZoomed();//+ } return bres; }
bool CUIBagWnd::CanBuy(CUICellItem* itm) { VERIFY (itm); if (!IsInBag(itm)) return false; CInventoryItem* iitm = (CInventoryItem*)itm->m_pData; if (m_bIgnoreMoney) { if (m_bIgnoreRank) return true; else if (g_mp_restrictions.IsAvailable(iitm->object().cNameSect())) return true; } else if (m_bIgnoreRank) { if (m_info[itm->m_index].price < m_money) return true; } return m_info[itm->m_index].active && (!m_info[itm->m_index].bought); }
bool CUIBagWnd::IsBlueTeamItem(CUICellItem* itm) { if (GameID() == GAME_DEATHMATCH) return true; //in deathmath always blue CInventoryItem* iitm = (CInventoryItem*)itm->m_pData; LPCSTR item = *iitm->object().cNameSect(); bool blue = !strstr(m_sectionName.c_str(),"team1"); //is our team blue // string64 wpnSection; string1024 wpnNames, wpnSingleName; for (int i = 1; i < 20; ++i) { // Имя поля sprintf_s (wpnSection, "slot%i", i); if (!pSettings->line_exist(m_sectionName, wpnSection)) continue; strcpy (wpnNames, pSettings->r_string(m_sectionName, wpnSection)); u32 count = _GetItemCount(wpnNames); for (u32 j = 0; j < count; ++j) { _GetItem (wpnNames, j, wpnSingleName); if (0 == xr_strcmp(item,wpnSingleName)) return blue; } } return !blue; }
void CScriptGameObject::MakeItemActive(CScriptGameObject* pItem) { CInventoryOwner* owner = smart_cast<CInventoryOwner*>(&object()); CInventoryItem* item = smart_cast<CInventoryItem*>(&pItem->object()); u32 slot = item->GetSlot(); CInventoryItem* item_in_slot = owner->inventory().ItemFromSlot(slot); NET_Packet P; if(item_in_slot) { CGameObject::u_EventGen (P, GEG_PLAYER_ITEM2RUCK, owner->object_id()); P.w_u16 (item_in_slot->object().ID()); CGameObject::u_EventSend (P); } CGameObject::u_EventGen (P, GEG_PLAYER_ITEM2SLOT, owner->object_id()); P.w_u16 (item->object().ID()); CGameObject::u_EventSend (P); CGameObject::u_EventGen (P, GEG_PLAYER_ACTIVATE_SLOT, owner->object_id()); P.w_u32 (slot); CGameObject::u_EventSend (P); }
void CActor::Check_for_AutoPickUp() { // mp only if (!psActorFlags.test(AF_AUTOPICKUP)) return; if (IsGameTypeSingle()) return; if (Level().CurrentControlEntity() != this) return; if (!g_Alive()) return; Fvector bc; bc.add (Position(), m_AutoPickUp_AABB_Offset); Fbox APU_Box; APU_Box.set (Fvector().sub(bc, m_AutoPickUp_AABB), Fvector().add(bc, m_AutoPickUp_AABB)); xr_vector<ISpatial*> ISpatialResult; g_SpatialSpace->q_box (ISpatialResult, 0, STYPE_COLLIDEABLE, bc, m_AutoPickUp_AABB); // Determine visibility for dynamic part of scene for (u32 o_it=0; o_it<ISpatialResult.size(); o_it++) { ISpatial* spatial = ISpatialResult[o_it]; CInventoryItem* pIItem = smart_cast<CInventoryItem*> (spatial->dcast_CObject()); if (0 == pIItem) continue; if (!pIItem->CanTake()) continue; if (Level().m_feel_deny.is_object_denied(spatial->dcast_CObject()) ) continue; CGrenade* pGrenade = smart_cast<CGrenade*> (pIItem); if (pGrenade) continue; if (APU_Box.Pick(pIItem->object().Position(), pIItem->object().Position())) { if (GameID() == eGameIDDeathmatch || GameID() == eGameIDTeamDeathmatch) { if (pIItem->BaseSlot() == INV_SLOT_2 || pIItem->BaseSlot() == INV_SLOT_3 ) { if (inventory().ItemFromSlot(pIItem->BaseSlot())) continue; } } Game().SendPickUpEvent(ID(), pIItem->object().ID()); } } }
bool CInventory::Drop(CGameObject *pObj, bool call_drop) { CInventoryItem *pIItem = smart_cast<CInventoryItem*>(pObj); VERIFY (pIItem); if(pIItem->m_pInventory!=this) return false; VERIFY (pIItem->m_pInventory); VERIFY (pIItem->m_pInventory==this); VERIFY (pIItem->m_eItemPlace!=eItemPlaceUndefined); pIItem->object().processing_activate(); switch(pIItem->m_eItemPlace) { case eItemPlaceBelt: { VERIFY(InBelt(pIItem)); m_belt.erase(std::find(m_belt.begin(), m_belt.end(), pIItem)); pIItem->object().processing_deactivate(); } break; case eItemPlaceRuck: { VERIFY(InRuck(pIItem)); m_ruck.erase(std::find(m_ruck.begin(), m_ruck.end(), pIItem)); } break; case eItemPlaceSlot: { VERIFY(InSlot(pIItem)); if(m_iActiveSlot == pIItem->GetSlot()) Activate(NO_ACTIVE_SLOT); m_slots[pIItem->GetSlot()].m_pIItem = NULL; pIItem->object().processing_deactivate(); } break; default: NODEFAULT; }; TIItemContainer::iterator it = std::find(m_all.begin(), m_all.end(), pIItem); if(it!=m_all.end()) m_all.erase(std::find(m_all.begin(), m_all.end(), pIItem)); else Msg("! CInventory::Drop item not found in inventory!!!"); pIItem->m_pInventory = NULL; if (call_drop && smart_cast<CInventoryItem*>(pObj)) m_pOwner->OnItemDrop (smart_cast<CInventoryItem*>(pObj)); CalcTotalWeight (); InvalidateState (); m_drop_last_frame = true; return true; }
void UIInvUpgPropertiesWnd::set_item_info( CInventoryItem& item ) { set_info( item.upgardes() ); }
void CLevel::OnRender() { inherited::OnRender (); if (!game) return; Game().OnRender(); //отрисовать трассы пуль //Device.Statistic->TEST1.Begin(); BulletManager().Render(); //Device.Statistic->TEST1.End(); //отрисовать интерфейc пользователя HUD().RenderUI(); #ifdef DEBUG draw_wnds_rects(); ph_world->OnRender (); #endif // DEBUG #ifdef DEBUG if (ai().get_level_graph()) ai().level_graph().render(); #ifdef DEBUG_PRECISE_PATH test_precise_path (); #endif CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(Level().CurrentEntity()); if (stalker) stalker->OnRender (); if (bDebug) { for (u32 I=0; I < Level().Objects.o_count(); I++) { CObject* _O = Level().Objects.o_get_by_iterator(I); CAI_Stalker* stalker = smart_cast<CAI_Stalker*>(_O); if (stalker) stalker->OnRender (); CPhysicObject *physic_object = smart_cast<CPhysicObject*>(_O); if (physic_object) physic_object->OnRender(); CSpaceRestrictor *space_restrictor = smart_cast<CSpaceRestrictor*> (_O); if (space_restrictor) space_restrictor->OnRender(); CClimableObject *climable = smart_cast<CClimableObject*> (_O); if(climable) climable->OnRender(); CTeamBaseZone *team_base_zone = smart_cast<CTeamBaseZone*>(_O); if (team_base_zone) team_base_zone->OnRender(); if (GameID() != eGameIDSingle) { CInventoryItem* pIItem = smart_cast<CInventoryItem*>(_O); if (pIItem) pIItem->OnRender(); } if (dbg_net_Draw_Flags.test(dbg_draw_skeleton)) //draw skeleton { CGameObject* pGO = smart_cast<CGameObject*> (_O); if (pGO && pGO != Level().CurrentViewEntity() && !pGO->H_Parent()) { if (pGO->Position().distance_to_sqr(Device.vCameraPosition) < 400.0f) { pGO->dbg_DrawSkeleton(); } } }; } // [7/5/2005] if (Server && Server->game) Server->game->OnRender(); // [7/5/2005] ObjectSpace.dbgRender (); //--------------------------------------------------------------------- HUD().Font().pFontStat->OutSet (170,630); HUD().Font().pFontStat->SetHeight (16.0f); HUD().Font().pFontStat->SetColor (0xffff0000); if(Server)HUD().Font().pFontStat->OutNext ("Client Objects: [%d]",Server->GetEntitiesNum()); HUD().Font().pFontStat->OutNext ("Server Objects: [%d]",Objects.o_count()); HUD().Font().pFontStat->OutNext ("Interpolation Steps: [%d]", Level().GetInterpolationSteps()); HUD().Font().pFontStat->SetHeight (8.0f); //--------------------------------------------------------------------- } #endif #ifdef DEBUG if (bDebug) { DBG().draw_object_info (); DBG().draw_text (); DBG().draw_level_info (); } debug_renderer().render (); DBG().draw_debug_text(); if (psAI_Flags.is(aiVision)) { for (u32 I=0; I < Level().Objects.o_count(); I++) { CObject *object = Objects.o_get_by_iterator(I); CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(object); if (!stalker) continue; stalker->dbg_draw_vision (); } } if (psAI_Flags.test(aiDrawVisibilityRays)) { for (u32 I=0; I < Level().Objects.o_count(); I++) { CObject *object = Objects.o_get_by_iterator(I); CAI_Stalker *stalker = smart_cast<CAI_Stalker*>(object); if (!stalker) continue; stalker->dbg_draw_visibility_rays (); } } #endif }
void CActor::PickupModeUpdate_COD () { if (Level().CurrentViewEntity() != this || !g_b_COD_PickUpMode) return; if (!g_Alive() || eacFirstEye != cam_active) { CurrentGameUI()->UIMainIngameWnd->SetPickUpItem(NULL); return; }; CFrustum frustum; frustum.CreateFromMatrix (Device.mFullTransform, FRUSTUM_P_LRTB|FRUSTUM_P_FAR); ISpatialResult.clear_not_free (); g_SpatialSpace->q_frustum (ISpatialResult, 0, STYPE_COLLIDEABLE, frustum); float maxlen = 1000.0f; CInventoryItem* pNearestItem = NULL; for (u32 o_it=0; o_it<ISpatialResult.size(); o_it++) { ISpatial* spatial = ISpatialResult[o_it]; CInventoryItem* pIItem = smart_cast<CInventoryItem*> (spatial->dcast_CObject ()); if (0 == pIItem) continue; if (pIItem->object().H_Parent() != NULL) continue; if (!pIItem->CanTake()) continue; if ( smart_cast<CExplosiveRocket*>( &pIItem->object() ) ) continue; CGrenade* pGrenade = smart_cast<CGrenade*> (spatial->dcast_CObject ()); if (pGrenade && !pGrenade->Useful()) continue; CMissile* pMissile = smart_cast<CMissile*> (spatial->dcast_CObject ()); if (pMissile && !pMissile->Useful()) continue; Fvector A, B, tmp; pIItem->object().Center (A); if (A.distance_to_sqr(Position())>4) continue; tmp.sub(A, cam_Active()->vPosition); B.mad(cam_Active()->vPosition, cam_Active()->vDirection, tmp.dotproduct(cam_Active()->vDirection)); float len = B.distance_to_sqr(A); if (len > 1) continue; if (maxlen>len && !pIItem->object().getDestroy()) { maxlen = len; pNearestItem = pIItem; }; } if(pNearestItem) { CFrustum frustum; frustum.CreateFromMatrix (Device.mFullTransform,FRUSTUM_P_LRTB|FRUSTUM_P_FAR); if (!CanPickItem(frustum, Device.vCameraPosition, &pNearestItem->object())) pNearestItem = NULL; } if (pNearestItem && pNearestItem->cast_game_object()) { if (Level().m_feel_deny.is_object_denied(pNearestItem->cast_game_object())) pNearestItem = NULL; } if (pNearestItem && pNearestItem->cast_game_object()) { if(!pNearestItem->cast_game_object()->getVisible()) pNearestItem = NULL; } CurrentGameUI()->UIMainIngameWnd->SetPickUpItem(pNearestItem); if (pNearestItem && m_bPickupMode) { CUsableScriptObject* pUsableObject = smart_cast<CUsableScriptObject*>(pNearestItem); if(pUsableObject && (!m_pUsableObject)) pUsableObject->use(this); //подбирание объекта Game().SendPickUpEvent(ID(), pNearestItem->object().ID()); } };
bool CInventory::DropItem(CGameObject *pObj, bool just_before_destroy, bool dont_create_shell) { CInventoryItem *pIItem = smart_cast<CInventoryItem*>(pObj); VERIFY (pIItem); VERIFY (pIItem->m_pInventory); VERIFY (pIItem->m_pInventory==this); VERIFY (pIItem->m_ItemCurrPlace.type!=eItemPlaceUndefined); pIItem->object().processing_activate(); switch(pIItem->CurrPlace()) { case eItemPlaceBelt:{ VERIFY(InBelt(pIItem)); TIItemContainer::iterator temp_iter = std::find(m_belt.begin(), m_belt.end(), pIItem); if (temp_iter != m_belt.end()) { m_belt.erase(temp_iter); } else { Msg("! ERROR: CInventory::Drop item not found in belt..."); } pIItem->object().processing_deactivate(); }break; case eItemPlaceRuck:{ VERIFY(InRuck(pIItem)); TIItemContainer::iterator temp_iter = std::find(m_ruck.begin(), m_ruck.end(), pIItem); if (temp_iter != m_ruck.end()) { m_ruck.erase(temp_iter); } else { Msg("! ERROR: CInventory::Drop item not found in ruck..."); } }break; case eItemPlaceSlot:{ VERIFY (InSlot(pIItem)); if(m_iActiveSlot == pIItem->CurrSlot()) { CActor* pActor = smart_cast<CActor*>(m_pOwner); if (!pActor || pActor->g_Alive()) { if (just_before_destroy) { #ifdef DEBUG Msg("---DropItem activating slot [-1], forced, Frame[%d]", Device.dwFrame); #endif // #ifdef DEBUG Activate (NO_ACTIVE_SLOT, true); } else { #ifdef DEBUG Msg("---DropItem activating slot [-1], Frame[%d]", Device.dwFrame); #endif // #ifdef DEBUG Activate (NO_ACTIVE_SLOT); } } } m_slots[pIItem->CurrSlot()].m_pIItem = NULL; pIItem->object().processing_deactivate(); }break; default: NODEFAULT; }; TIItemContainer::iterator it = std::find(m_all.begin(), m_all.end(), pIItem); if(it!=m_all.end()) m_all.erase(std::find(m_all.begin(), m_all.end(), pIItem)); else Msg("! CInventory::Drop item not found in inventory!!!"); pIItem->m_pInventory = NULL; m_pOwner->OnItemDrop (smart_cast<CInventoryItem*>(pObj), just_before_destroy); CalcTotalWeight (); InvalidateState (); m_drop_last_frame = true; if( CurrentGameUI() ) { CObject* pActor_owner = smart_cast<CObject*>(m_pOwner); if (Level().CurrentViewEntity() == pActor_owner) CurrentGameUI()->OnInventoryAction(pIItem, GE_OWNERSHIP_REJECT); }; pObj->H_SetParent(0, dont_create_shell); return true; }
void CInventory::Take(CGameObject *pObj, bool bNotActivate, bool strict_placement) { CInventoryItem *pIItem = smart_cast<CInventoryItem*>(pObj); VERIFY (pIItem); VERIFY (pIItem->m_pInventory==NULL); VERIFY (CanTakeItem(pIItem)); pIItem->m_pInventory = this; pIItem->SetDropManual (FALSE); pIItem->AllowTrade (); //if net_Import for pObj arrived then the pObj will pushed to CrPr list (correction prediction) //usually net_Import arrived for objects that not has a parent object.. //for unknown reason net_Import arrived for object that has a parent, so correction prediction schema will crash Level().RemoveObject_From_4CrPr (pObj); m_all.push_back (pIItem); if(!strict_placement) pIItem->m_ItemCurrPlace.type = eItemPlaceUndefined; bool result = false; switch(pIItem->m_ItemCurrPlace.type) { case eItemPlaceBelt: result = Belt(pIItem, strict_placement); if(!result) pIItem->m_ItemCurrPlace.type = eItemPlaceUndefined; #ifdef DEBUG if(!result) Msg("cant put in belt item %s", *pIItem->object().cName()); #endif break; case eItemPlaceRuck: result = Ruck(pIItem, strict_placement); if(!result) pIItem->m_ItemCurrPlace.type = eItemPlaceUndefined; #ifdef DEBUG if(!result) Msg("cant put in ruck item %s", *pIItem->object().cName()); #endif break; case eItemPlaceSlot: result = Slot(pIItem->m_ItemCurrPlace.slot_id, pIItem, bNotActivate, strict_placement); if(!result) pIItem->m_ItemCurrPlace.type = eItemPlaceUndefined; #ifdef DEBUG if(!result) Msg("cant slot in slot item %s", *pIItem->object().cName()); #endif break; } if(pIItem->CurrPlace()==eItemPlaceUndefined) { if( !pIItem->RuckDefault() ) { if( CanPutInSlot(pIItem, pIItem->BaseSlot()) ) { result = Slot(pIItem->BaseSlot(), pIItem, bNotActivate,strict_placement); VERIFY(result); }else if (CanPutInBelt(pIItem)) { result = Belt(pIItem,strict_placement); VERIFY(result); }else { result = Ruck(pIItem,strict_placement); VERIFY(result); } }else { result = Ruck(pIItem,strict_placement); VERIFY(result); } } m_pOwner->OnItemTake (pIItem); CalcTotalWeight (); InvalidateState (); pIItem->object().processing_deactivate(); VERIFY (pIItem->CurrPlace() != eItemPlaceUndefined); if( CurrentGameUI() ) { CObject* pActor_owner = smart_cast<CObject*>(m_pOwner); if (Level().CurrentViewEntity() == pActor_owner) { CurrentGameUI()->OnInventoryAction(pIItem, GE_OWNERSHIP_TAKE); } else if(CurrentGameUI()->GetActorMenu().GetMenuMode()==mmDeadBodySearch) { if(m_pOwner==CurrentGameUI()->GetActorMenu().GetPartner()) CurrentGameUI()->OnInventoryAction(pIItem, GE_OWNERSHIP_TAKE); } }; }
SBuyItemInfo::~SBuyItemInfo() { CInventoryItem* iitem = (CInventoryItem*)m_cell_item->m_pData; xrFactory_Destroy (&iitem->object()); delete_data (m_cell_item); }
void CAI_Stalker::update_best_item_info () { ai().ef_storage().alife_evaluation(false); if ( m_item_actuality && m_best_item_to_kill && m_best_item_to_kill->can_kill() ) { if (!memory().enemy().selected()) return; ai().ef_storage().non_alife().member() = this; ai().ef_storage().non_alife().enemy() = memory().enemy().selected() ? memory().enemy().selected() : this; ai().ef_storage().non_alife().member_item() = &m_best_item_to_kill->object(); float value; value = ai().ef_storage().m_pfWeaponEffectiveness->ffGetValue(); if (fsimilar(value,m_best_item_value)) return; } // initialize parameters m_item_actuality = true; ai().ef_storage().non_alife().member() = this; ai().ef_storage().non_alife().enemy() = memory().enemy().selected() ? memory().enemy().selected() : this; m_best_item_to_kill = 0; m_best_ammo = 0; m_best_found_item_to_kill = 0; m_best_found_ammo = 0; m_best_item_value = 0.f; // try to find the best item which can kill { TIItemContainer::iterator I = inventory().m_all.begin(); TIItemContainer::iterator E = inventory().m_all.end(); for ( ; I != E; ++I) { if ((*I)->can_kill()) { ai().ef_storage().non_alife().member_item() = &(*I)->object(); float value; if (memory().enemy().selected()) value = ai().ef_storage().m_pfWeaponEffectiveness->ffGetValue(); else value = (float)(*I)->object().ef_weapon_type(); if (!fsimilar(value,m_best_item_value) && (value < m_best_item_value)) continue; if (!fsimilar(value,m_best_item_value) && (value > m_best_item_value)) { m_best_item_value = value; m_best_item_to_kill = *I; continue; } VERIFY (fsimilar(value,m_best_item_value)); if ((*I)->object().ef_weapon_type() <= m_best_item_to_kill->object().ef_weapon_type()) continue; m_best_item_value = value; m_best_item_to_kill = *I; } } } // check if we found if (m_best_item_to_kill) { m_best_ammo = m_best_item_to_kill; return; } // so we do not have such an item // check if we remember we saw item which can kill // or items which can make my item killing { xr_vector<const CGameObject*>::const_iterator I = memory().item().objects().begin(); xr_vector<const CGameObject*>::const_iterator E = memory().item().objects().end(); for ( ; I != E; ++I) { const CInventoryItem *inventory_item = smart_cast<const CInventoryItem*>(*I); if (!inventory_item || !memory().item().useful(&inventory_item->object())) continue; CInventoryItem *item = inventory_item->can_kill(&inventory()); if (item) { ai().ef_storage().non_alife().member_item() = &inventory_item->object(); float value = ai().ef_storage().m_pfWeaponEffectiveness->ffGetValue(); if (value > m_best_item_value) { m_best_item_value = value; m_best_found_item_to_kill = inventory_item; m_best_found_ammo = 0; m_best_ammo = item; } } else { item = inventory_item->can_make_killing(&inventory()); if (!item) continue; ai().ef_storage().non_alife().member_item() = &item->object(); float value = ai().ef_storage().m_pfWeaponEffectiveness->ffGetValue(); if (value > m_best_item_value) { m_best_item_value = value; m_best_item_to_kill = item; m_best_found_item_to_kill = 0; m_best_found_ammo = inventory_item; } } } } // check if we found such an item if (m_best_found_item_to_kill || m_best_found_ammo) return; // check if we remember we saw item to kill // and item which can make this item killing xr_vector<const CGameObject*>::const_iterator I = memory().item().objects().begin(); xr_vector<const CGameObject*>::const_iterator E = memory().item().objects().end(); for ( ; I != E; ++I) { const CInventoryItem *inventory_item = smart_cast<const CInventoryItem*>(*I); if (!inventory_item || !memory().item().useful(&inventory_item->object())) continue; const CInventoryItem *item = inventory_item->can_kill(memory().item().objects()); if (item) { ai().ef_storage().non_alife().member_item() = &inventory_item->object(); float value = ai().ef_storage().m_pfWeaponEffectiveness->ffGetValue(); if (value > m_best_item_value) { m_best_item_value = value; m_best_found_item_to_kill = inventory_item; m_best_found_ammo = item; } } } }