void CUITalkWnd::Update() { //остановить разговор, если нужно if (g_actor && m_pActor && !m_pActor->IsTalking() ) { StopTalk(); }else{ CGameObject* pOurGO = smart_cast<CGameObject*>(m_pOurInvOwner); CGameObject* pOtherGO = smart_cast<CGameObject*>(m_pOthersInvOwner); if( NULL==pOurGO || NULL==pOtherGO ) Game().StartStopMenu(this,true); } if(m_bNeedToUpdateQuestions) { UpdateQuestions (); } inherited::Update (); UpdateCameraDirection (smart_cast<CGameObject*>(m_pOthersInvOwner)); UITalkDialogWnd->UpdateButtonsLayout(b_disable_break, m_pOthersInvOwner->IsTradeEnabled()); if(playing_sound()) { CGameObject* pOtherGO = smart_cast<CGameObject*>(m_pOthersInvOwner); Fvector P = pOtherGO->Position(); P.y += 1.8f; m_sound.set_position (P); } }
bool CHistoryManager::doModify( SAction* action, bool redo ) { IDoc *pDoc = getIView()->getDocument(); CSerializable *pObject = &action->object1; if ( redo ) pObject = &action->object2; pObject->setCursorRecord(0); // get object id SSerializableRec *pObjectID = pObject->getProperty("objectID"); if ( pObjectID == NULL ) return false; long objID = -1; sscanf( pObjectID->data, "%ld", &objID ); CGameObject* pObj = pDoc->searchObject( objID ); if ( pObj == NULL ) return false; pObj->updateData( pObject ); return true; }
void CInventoryBox::OnEvent(NET_Packet& P, u16 type) { inherited::OnEvent (P, type); switch (type) { case GE_OWNERSHIP_TAKE: { u16 id; P.r_u16(id); CObject* itm = Level().Objects.net_Find(id); VERIFY(itm); m_items.push_back (id); itm->H_SetParent (this); itm->setVisible (FALSE); itm->setEnabled (FALSE); }break; case GE_OWNERSHIP_REJECT: { u16 id; P.r_u16(id); CObject* itm = Level().Objects.net_Find(id); VERIFY(itm); xr_vector<u16>::iterator it; it = std::find(m_items.begin(),m_items.end(),id); VERIFY(it!=m_items.end()); m_items.erase (it); itm->H_SetParent (NULL,!P.r_eof() && P.r_u8()); if( m_in_use ) { CGameObject* GO = smart_cast<CGameObject*>(itm); Actor()->callback(GameObject::eInvBoxItemTake)( this->lua_game_object(), GO->lua_game_object() ); } }break; }; }
void CRadioactiveZone::Affect(SZoneObjectInfo* O) { // вермя срабатывания не чаще, чем заданный период if(m_dwDeltaTime < m_dwPeriod) return; //. m_dwDeltaTime = 0; CGameObject *GO = O->object; if(GO) { Fvector pos; XFORM().transform_tiny(pos,CFORM()->getSphere().P); #ifdef DEBUG char pow[255]; sprintf(pow, "zone hit. %.3f", Power(GO->Position().distance_to(pos))); if(bDebug) Msg("%s %s", *GO->cName(), pow); #endif Fvector dir; dir.set(0,0,0); Fvector position_in_bone_space; float power = (GameID() == GAME_SINGLE) ? Power(GO->Position().distance_to(pos)) : 0.0f; float impulse = 0.f; if(power > EPS) { //. m_dwDeltaTime = 0; position_in_bone_space.set(0.f,0.f,0.f); CreateHit(GO->ID(),ID(),dir,power,BI_NONE,position_in_bone_space,impulse,ALife::eHitTypeRadiation); } } }
void CPurchaseList::process (const CGameObject &owner, const shared_str &name, const u32 &count, const float &probability) { VERIFY3 (count,"Invalid count for section in the purchase list",*name); VERIFY3 (!fis_zero(probability,EPS_S),"Invalid probability for section in the purchase list",*name); const Fvector &position = owner.Position(); const u32 &level_vertex_id = owner.ai_location().level_vertex_id(); const ALife::_OBJECT_ID &id = owner.ID(); CRandom random((u32)(CPU::QPC() & u32(-1))); u32 j = 0; for (u32 i=0; i<count; ++i) { if (random.randF() > probability) continue; ++j; Level().spawn_item (*name,position,level_vertex_id,id,false); } DEFICITS::const_iterator I = m_deficits.find(name); VERIFY3 (I == m_deficits.end(),"Duplicate section in the purchase list",*name); m_deficits.insert ( std::make_pair( name, (float)count*probability / _max((float)j,min_deficit_factor) ) ); }
CGameObject* CFactory::InstantiatePrototype(const string &AProtoName, const string &AName /*= ""*/) { CXMLNode *xml = GetPrototypeXML(AProtoName); if (!xml) { Log("ERROR", "Can't create prototype instance: no such prototype: '%s'", AProtoName.c_str()); return NULL; } CGameObject *result = New<CGameObject>(AName); if (AName.empty()) result->SetName(AProtoName + itos(result->GetID())); result->Prototype = true; result->Deserialize(xml); SetRecursionLimit(AProtoName, from_string<int>(xml->SafeGetAttribute("RecursionLimit", "-1"))); TraversePrototypeNode(xml, result, result); result->FinalizeCreation(); Log("INFO", "Prototype INSTANTIATED: '%s', instance name: '%s'", AProtoName.c_str(), result->GetName().c_str()); return result; }
bool CNoseHolder::FrameMsg(CFrameMsg *msg) { if (!_dragObject) { CGameObject *dragObj = getDraggingObject(); if (!dragObj) return false; if (!dragObj->isEquals("Feathers") || getView() != findView()) return false; _dragObject = dragObj; } if (_dragObject) { if (!checkPoint(Point(_dragObject->_bounds.left, _dragObject->_bounds.top))) { _field11C = false; } else if (!_field11C) { CActMsg actMsg("Sneeze"); actMsg.execute(this); _field11C = true; } } return true; }
CGameObject *CInputHandler::dragEnd(const Point &pt, CTreeItem *dragItem) { CViewItem *view = _gameManager->getView(); if (!view) return nullptr; // Scan through the view items to find the item being dropped on CGameObject *target = nullptr; for (CTreeItem *treeItem = view->scan(view); treeItem; treeItem = treeItem->scan(view)) { CGameObject *gameObject = dynamic_cast<CGameObject *>(treeItem); if (gameObject && gameObject != dragItem) { if (gameObject->checkPoint(pt)) target = gameObject; } } if (target) { // Check if the cursor is on the PET. If so, pass to the PET // to see what specific element the drag ended on CProjectItem *project = view->getRoot(); if (project) { CPetControl *petControl = project->getPetControl(); if (petControl && petControl->contains(pt)) { target = petControl->dragEnd(pt); if (!target) target = petControl; } } } return target; }
void CSniper::OnCollision(float deltaTime, std::vector<CGameObject*>* listObjectCollision) { float normalX = 0; float normalY = 0; float moveX = 0.0f; float moveY = 0.0f; float timeCollision; for (std::vector<CBullet*>::iterator it = CPoolingObject::GetInstance()->m_listBulletOfObject.begin(); it != CPoolingObject::GetInstance()->m_listBulletOfObject.end();) { CGameObject* obj = *it; timeCollision = CCollision::GetInstance()->Collision(obj, this, normalX, normalY, moveX, moveY, deltaTime); if((timeCollision > 0.0f && timeCollision < 1.0f) || timeCollision == 2.0f) { if(obj->IsAlive() && obj->GetLayer() == LAYER::PLAYER) { // Gan trang thai die cho doi tuong this->m_stateCurrent = SN_IS_DIE; // Xoa vien dan ra khoi d.s it = CPoolingObject::GetInstance()->m_listBulletOfObject.erase(it); //Load sound die ManageAudio::GetInstance()->playSound(TypeAudio::ENEMY_DEAD_SFX); // Tang diem cua contra len CContra::GetInstance()->IncreateScore(500); } else ++it; } else { ++it; } } }
bool CLemonDispensor::FrameMsg(CFrameMsg *msg) { if (_v2 || !_isSummer) return true; if (!_draggingObject) { CGameObject *obj = getDraggingObject(); if (obj && getView() == findView()) { if (obj->isEquals("Perch")) { petDisplayMessage(1, TOO_SHORT_TO_REACH_BRANCHES); return true; } if (obj->isEquals("LongStick")) _draggingObject = obj; } } if (_draggingObject) { Point pt(_origPt.x + _draggingObject->_bounds.left, _origPt.y + _draggingObject->_bounds.top); bool flag = checkPoint(pt, true); if (_fieldEC == 0) { if (flag && ++_v3 > 10) { CLemonFallsFromTreeMsg lemonMsg(pt); lemonMsg.execute("Lemon"); _v2 = 1; } } else if (_fieldEC == 1 && !flag) { _fieldEC = 0; } } return true; }
void game_cl_CaptureTheArtefact::OnBuyMenu_Ok() { #ifdef DEBUG Msg("* CTA: Buy menu OK..."); #endif // #ifdef DEBUG typedef CUIGameCTA::BuyMenuItemsCollection TBuyCol; VERIFY2(m_game_ui, "game ui not initialized"); CUIGameCTA::BuyMenuItemsCollection toBuyItemsCollection; s32 moneyDif = 0; m_game_ui->GetPurchaseItems(toBuyItemsCollection, moneyDif); R_ASSERT(local_player); if (local_player->testFlag(GAME_PLAYER_FLAG_VERY_VERY_DEAD)) { if (InWarmUp()) { buy_amount = 0; } else { buy_amount = moneyDif; } UpdateMoneyIndicator(); } CGameObject* pPlayer = smart_cast<CGameObject*>(Level().CurrentEntity()); VERIFY(pPlayer); NET_Packet P; pPlayer->u_EventGen(P, GE_GAME_EVENT, pPlayer->ID()); P.w_u16(GAME_EVENT_PLAYER_BUY_FINISHED); if (InWarmUp()) { P.w_s32(0); } else { P.w_s32(moneyDif); } P.w_u16(static_cast<u16>(toBuyItemsCollection.size())); TBuyCol::const_iterator bie = toBuyItemsCollection.end(); for (TBuyCol::const_iterator toBuyIter = toBuyItemsCollection.begin(); toBuyIter != bie; ++toBuyIter) { P.w_u8(toBuyIter->first); P.w_u8(toBuyIter->second); } pPlayer->u_EventSend(P); if (local_player->testFlag(GAME_PLAYER_FLAG_VERY_VERY_DEAD)) { u_EventGen(P, GE_GAME_EVENT, local_player->GameID); P.w_u16(GAME_EVENT_PLAYER_BUYMENU_CLOSE); u_EventSend(P); } set_buy_menu_not_ready(); }
void CPetGfxElement::draw(CScreenManager *screenManager, const Common::Point &destPos) { CGameObject *obj = getObject(); if (!obj) obj = _object0; if (obj) obj->draw(screenManager, destPos); }
CScriptGameObject *get_object_by_id(u16 id) { CGameObject* pGameObject = smart_cast<CGameObject*>(Level().Objects.net_Find(id)); if(!pGameObject) return NULL; return pGameObject->lua_game_object(); }
void CInventoryOwner::OnItemDrop (CInventoryItem *inventory_item) { CGameObject *object = smart_cast<CGameObject*>(this); VERIFY (object); object->callback(GameObject::eOnItemDrop)(inventory_item->object().lua_game_object()); detach (inventory_item); }
EContextEstablishTaskResult OnStep( SContextEstablishState& state ) { bool allowPlayers = (m_what & eFS_Players) != 0; bool allowGameRules = (m_what & eFS_GameRules) != 0; bool allowOthers = (m_what & eFS_Others) != 0; EntityId gameRulesId = 0; if (IEntity * pGameRules = CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRulesEntity()) gameRulesId = pGameRules->GetId(); // we are in the editor, and that means that there have been entities spawned already // that are not bound to the network context... so lets bind them! IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator(); while (IEntity * pEntity = pIt->Next()) { bool isOther = true; bool isPlayer = false; IActor* pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(pEntity->GetId()); if (pActor && pActor->IsPlayer()) { isPlayer = true; isOther = false; } if (isPlayer && !allowPlayers) continue; bool isGameRules = false; if (pEntity->GetId() == gameRulesId) { isGameRules = true; isOther = false; } if (isGameRules && !allowGameRules) continue; if (isOther && !allowOthers) continue; CGameObject * pGO = (CGameObject *) pEntity->GetProxy( ENTITY_PROXY_USER ); if (pGO) { if (pGO->IsBoundToNetwork()) pGO->BindToNetwork(eBTNM_Force); // force rebinding } SEntitySpawnParams fakeParams; fakeParams.id = pEntity->GetId(); fakeParams.nFlags = pEntity->GetFlags(); fakeParams.pClass = pEntity->GetClass(); fakeParams.qRotation = pEntity->GetRotation(); fakeParams.sName = pEntity->GetName(); fakeParams.vPosition = pEntity->GetPos(); fakeParams.vScale = pEntity->GetScale(); CCryAction::GetCryAction()->GetGameContext()->OnSpawn( pEntity, fakeParams ); } return eCETR_Ok; }
void CAddObjectController::cancelController() { IView *pView = getIView(); wchar_t *currentTemplate = pView->getCurrentObjectTemplate(); CGameObject *p = CObjTemplateFactory::getGameObject( currentTemplate ); if ( p ) p->setVisible( false ); }
bool CUsableScriptObject::use(CGameObject* who_use) { VERIFY(who_use); CGameObject* pThis = smart_cast<CGameObject*>(this); VERIFY(pThis); pThis->callback(GameObject::eUseObject)(pThis->lua_game_object(),who_use->lua_game_object()); return true; }
void DebugLayout() { float y_offset = 100; CPlayer* LocalPlayer; if (NetworkManager) { LocalPlayer = NetworkManager->GetLocalPlayer(); Render::DrawText(20, y_offset, color_white, DT_LEFT, "R3DNetwork: %x", NetworkManager); y_offset += 15; } CObjectManager* ObjectManager = CObjectManager::Get(); if (ObjectManager) { Render::DrawText(20, y_offset, color_white, DT_LEFT, "ObjectManager: %x", ObjectManager); y_offset += 15; //Finds LocalPlayer in the main menu (For the shooting range) if (!LocalPlayer) { CGameObject* Object = ObjectManager->GetFirst(); for (CGameObject* Object = ObjectManager->GetFirst(); Object && Object->GetNext(); Object = Object->GetNext()) { if (Object->GetObjectInfo()->m_id == OBJECT_AI_PLAYER) { LocalPlayer = (CPlayer*)Object; break; } } } } if (LocalPlayer) { Render::DrawText(20, y_offset, color_white, DT_LEFT, "LocalPlayer: %x [0x%x]", LocalPlayer, LocalPlayer->GetObjectInfo()); y_offset += 15; for (int slot = 0; slot < SLOT_MAX; slot++) { Weapon* pWeapon = LocalPlayer->m_weaponSlots[slot]; if (!pWeapon) continue; Render::DrawText(40, y_offset, color_white, DT_LEFT, "Slot Weapon %i: %x (CWeaponConfig: %x)", slot, pWeapon, pWeapon->GetWeaponConfig()); y_offset += 15; } Render::DrawTextA(20, y_offset, color_white, DT_LEFT, "Health: %f", LocalPlayer->GetHealth()); } }
// selectObject // detect list objs at rect void CDocument::selectObject( int x, int y, int w, int h, bool isControlHold ) { IView *pView = getIView(); ISceneManager *smgr = pView->getSceneMgr(); ICameraSceneNode *camera = smgr->getActiveCamera(); // if no camera if ( camera == NULL ) return; const SViewFrustum* viewFrustum = camera->getViewFrustum(); ISceneCollisionManager *collMan = smgr->getSceneCollisionManager(); int screenX = -1, screenY = -1; ArrayZoneIter iZone = m_zones.begin(), iEnd = m_zones.end(); while ( iZone != iEnd ) { ArrayGameObject* listObj = (*iZone)->getChilds(); ArrayGameObjectIter iObj = listObj->begin(), objEnd = listObj->end(); ISceneNode *pNode = NULL; while ( iObj != objEnd ) { CGameObject *pGameObj = (CGameObject*)(*iObj); pNode = pGameObj->getSceneNode(); if ( pNode != NULL && pGameObj->isVisible() ) { core::vector3df center = pGameObj->getPosition(); // check object is in frustum if ( viewFrustum->getBoundingBox().isPointInside( center ) ) { if ( pView->getScreenCoordinatesFrom3DPosition( center, &screenX, &screenY ) ) { if ( x <= screenX && screenX <= x + w && y <= screenY && screenY <= y + h ) { if ( isControlHold == false || pGameObj->getObjectState() == CGameObject::Normal ) m_selectObjects.push_back( pGameObj ); } // inselect } // getScreenCoordinatesFrom3DPosition } // frustum } iObj++; } iZone++; } }
Rect CPetGfxElement::getBounds() const { CGameObject *obj = getObject(); if (!obj) obj = _object0; if (obj && obj->surfaceHasFrame()) return _bounds; else return Rect(); }
void game_cl_ArtefactHunt::OnBuySpawnMenu_Ok () { CObject* curr = Level().CurrentEntity(); if (!curr) return; CGameObject* GO = smart_cast<CGameObject*>(curr); NET_Packet P; GO->u_EventGen (P,GE_GAME_EVENT,GO->ID() ); P.w_u16(GAME_EVENT_PLAYER_BUY_SPAWN); GO->u_EventSend (P); };
CPlayerComponent::~CPlayerComponent() { // unregister collide obj CGameObject *zone = (CGameObject*)m_gameObject->getParent(); if ( zone && zone->getObjectType() == CGameObject::ZoneObject ) ((CZone*)zone)->unRegisterCollideObj( m_gameObject); // unregister event getIView()->unRegisterEvent( this ); }
CScriptGameObject *CScriptGameObject::GetMedikit() const { CAI_Stalker *l_tpStalker = smart_cast<CAI_Stalker*>(&object()); if (!l_tpStalker) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CAI_Stalker : cannot access class member GetCurrentWeapon!"); return (0); } CGameObject *medikit = l_tpStalker->GetMedikit() ? &l_tpStalker->GetMedikit()->object() : 0; return (medikit ? medikit->lua_game_object() : 0); }
CScriptGameObject *CScriptGameObject::GetFood() const { CAI_Stalker *l_tpStalker = smart_cast<CAI_Stalker*>(&object()); if (!l_tpStalker) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"CAI_Stalker : cannot access class member GetFood!"); return (0); } CGameObject *food = l_tpStalker->GetFood() ? &l_tpStalker->GetFood()->object() : 0; return (food ? food->lua_game_object() : 0); }
bool CSpeechDispensor::FrameMsg(CFrameMsg *msg) { if (_fieldEC || _seasonNum == SEASON_SUMMER || _seasonNum == SEASON_SPRING) return true; CGameObject *dragObject = getDraggingObject(); if (!_dragItem && dragObject && getView() == findView()) { if (dragObject->isEquals("Perch")) { petDisplayMessage(1, TOO_SHORT_TO_REACH_BRANCHES); return true; } if (dragObject->isEquals("LongStick")) _dragItem = dragObject; } if (_dragItem) { Point pt(_itemPos.x + _dragItem->_bounds.left, _itemPos.y + _dragItem->_bounds.top); if (!checkPoint(pt, true)) return true; switch (_state) { case 0: playSound("z#93.wav"); if (_seasonNum == SEASON_WINTER) { petDisplayMessage(1, FROZEN_TO_BRANCH); _fieldE0 = false; _state = 1; } else { if (++_fieldE0 >= 5) { CActMsg actMsg("PlayerGetsSpeechCentre"); actMsg.execute("SeasonalAdjust"); CSpeechFallsFromTreeMsg fallMsg(pt); fallMsg.execute("SpeechCentre"); _fieldEC = true; _fieldE0 = false; } _state = 1; } break; case 2: _state = 0; ++_fieldE0; break; default: break; } } return true; }
//call this after CGameObject::net_Spawn BOOL CInventoryOwner::net_Spawn (CSE_Abstract* DC) { if (!m_pTrade) m_pTrade = xr_new<CTrade>(this); if (m_trade_parameters) xr_delete (m_trade_parameters); m_trade_parameters = xr_new<CTradeParameters>(trade_section()); //получить указатель на объект, InventoryOwner //m_inventory->setSlotsBlocked(false); CGameObject *pThis = smart_cast<CGameObject*>(this); if(!pThis) return FALSE; CSE_Abstract* E = (CSE_Abstract*)(DC); if ( IsGameTypeSingle() ) { CSE_ALifeTraderAbstract* pTrader = NULL; if(E) pTrader = smart_cast<CSE_ALifeTraderAbstract*>(E); if(!pTrader) return FALSE; R_ASSERT( pTrader->character_profile().size() ); //синхронизируем параметры персонажа с серверным объектом CharacterInfo().Init(pTrader); //------------------------------------- m_known_info_registry->registry().init(E->ID); //------------------------------------- CAI_PhraseDialogManager* dialog_manager = smart_cast<CAI_PhraseDialogManager*>(this); if( dialog_manager && !dialog_manager->GetStartDialog().size() ) { dialog_manager->SetStartDialog(CharacterInfo().StartDialog()); dialog_manager->SetDefaultStartDialog(CharacterInfo().StartDialog()); } m_game_name = pTrader->m_character_name; } else { CharacterInfo().m_SpecificCharacter.Load ("mp_actor"); CharacterInfo().InitSpecificCharacter ("mp_actor"); CharacterInfo().m_SpecificCharacter.data()->m_sGameName = (E->name_replace()[0]) ? E->name_replace() : *pThis->cName(); m_game_name = (E->name_replace()[0]) ? E->name_replace() : *pThis->cName(); } if(!pThis->Local()) return TRUE; return TRUE; }
// reloadActiveWeapon // reload weapon void CWeaponComponent::reloadActiveWeapon(bool b) { if ( m_activeWeapon ) { CGameObject *pObj = m_activeWeapon->m_obj; CGunComponent* gun = (CGunComponent*)pObj->getComponent(CGameComponent::GunComponent); if ( gun ) gun->reload(b); } }
int CScriptBind_Action::IsGameObjectProbablyVisible( IFunctionHandler *pH, ScriptHandle gameObject ) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity((EntityId)gameObject.n); if (pEntity) { CGameObject *pGameObject = static_cast<CGameObject *>(pEntity->GetProxy(ENTITY_PROXY_USER)); if (pGameObject && pGameObject->IsProbablyVisible()) return pH->EndFunction(1); } return pH->EndFunction(); }
void CInventoryOwner::OnItemSlot (CInventoryItem *inventory_item, EItemPlace previous_place) { /************************************************** added by Ray Twitty (aka Shadows) START **************************************************/ // Колбек перемещения предмета в слот CGameObject *object = smart_cast<CGameObject*>(this); VERIFY (object); object->callback(GameObject::eOnItemSlot)(inventory_item->object().lua_game_object()); /*************************************************** added by Ray Twitty (aka Shadows) END ***************************************************/ attach (inventory_item); }
void CGameObject::OnH_B_Independent(bool just_before_destroy) { inherited::OnH_B_Independent(just_before_destroy); setup_parent_ai_locations (false); CGameObject *parent = smart_cast<CGameObject*>(H_Parent()); VERIFY (parent); if (ai().get_level_graph() && ai().level_graph().valid_vertex_id(parent->ai_location().level_vertex_id())) validate_ai_locations (false); }