virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Activate: { IActor* pActor = GetAIActor(pActInfo); if (!pActor) break; IEntity* pEnt = pActor->GetEntity(); if (!pEnt) break; HSCRIPTFUNCTION func = 0; int ret = 0; IScriptTable* pTable = pEnt->GetScriptTable(); if (!pTable) break; if (IsPortActive(pActInfo, 1) && pTable->GetValue("GrabObject", func)) { IEntity* pObj = gEnv->pEntitySystem->GetEntity( GetPortEntityId(pActInfo, 0) ); if (pObj) { IScriptTable* pObjTable = pObj->GetScriptTable(); Script::CallReturn(gEnv->pScriptSystem, func, pTable, pObjTable, ret); } ActivateOutput(pActInfo, 0, ret); } else if (IsPortActive(pActInfo, 2) && pTable->GetValue("DropObject", func)) { bool bThrow = GetPortBool(pActInfo, 3); Script::CallReturn(gEnv->pScriptSystem, func, pTable, bThrow, ret); ActivateOutput(pActInfo, 0, ret); } if (pTable->GetValue("GetGrabbedObject", func)) { ScriptHandle sH(0); Script::CallReturn(gEnv->pScriptSystem, func, pTable, sH); ActivateOutput(pActInfo, 1, EntityId(sH.n)); } if(func) gEnv->pScriptSystem->ReleaseFunc(func); break; } } }
static bool GetTeamRadioTable(CGameRules *gr, const string &team_name, SmartScriptTable &out_table) { if(!gr) { return false; } IScriptTable *pTable = gr->GetEntity()->GetScriptTable(); if(!pTable) { return false; } SmartScriptTable pTeamRadio; if(!pTable->GetValue("teamRadio", pTeamRadio)) { return false; } if(!pTeamRadio->GetValue(team_name, out_table)) { return false; } return true; }
const char *CAnimatedCharacterSample::GetCharacterModelNameFromScriptTable() const { IEntity *pEntity = GetEntity(); IScriptTable *pScriptTable = pEntity->GetScriptTable(); if(pScriptTable == NULL) { return NULL; } SmartScriptTable propertiesTable; const bool hasPropertiesTable = pScriptTable->GetValue("Properties", propertiesTable); if(! hasPropertiesTable) { return NULL; } const char *modelName = NULL; const bool hasModelName = propertiesTable->GetValue("objModel", modelName); if(! hasModelName) { return NULL; } return modelName; }
bool CScriptRMI::SerializeScript( TSerialize ser, IEntity * pEntity ) { SSerializeFunctionParams p( ser, pEntity ); ScriptHandle hdl( &p ); IScriptTable * pTable = pEntity->GetScriptTable(); if (pTable) { SmartScriptTable serTable; SmartScriptTable synchedTable; pTable->GetValue( "synched", synchedTable ); if (synchedTable.GetPtr()) { synchedTable->GetValue( HIDDEN_FIELD, serTable ); if (serTable.GetPtr()) { IScriptSystem * pScriptSystem = pTable->GetScriptSystem(); pScriptSystem->BeginCall( serTable.GetPtr(), SERIALIZE_FUNCTION ); pScriptSystem->PushFuncParam( serTable ); pScriptSystem->PushFuncParam( hdl ); return pScriptSystem->EndCall(); } } } return true; }
void CBaseManagerEntitySink::OnSpawn(IEntity *pEntity, SEntitySpawnParams ¶ms) { // Check if it has a CNC Table. If it does, manually add it to the controller IScriptTable *pTable; if (NULL != pEntity && NULL != (pTable = pEntity->GetScriptTable())) { // Get property table SmartScriptTable props, cncbuilding; if (true == pTable->GetValue("Properties", props) && true == props->GetValue("CNCBuilding", cncbuilding)) { // Extract and build GUID char const* szTeam = 0; char const* szClass = 0; cncbuilding->GetValue("Team", szTeam); cncbuilding->GetValue("Class", szClass); BuildingGUID GUID = m_pManager->GenerateGUID(szTeam, szClass); if (GUID_INVALID != GUID) { // Get controller and manually add it IBuildingController *pController = m_pManager->FindBuildingController(GUID); if (NULL != pController) pController->AddInterface(pEntity); } } } }
void CBoidFish::SpawnParticleEffect( const Vec3 &pos,SBoidContext &bc,int nEffect ) { if (!bc.entity) return; IScriptTable *pEntityTable = bc.entity->GetScriptTable(); if (!pEntityTable) return; if (!m_pOnSpawnBubbleFunc) { pEntityTable->GetValue( "OnSpawnBubble",m_pOnSpawnBubbleFunc ); } if (!m_pOnSpawnSplashFunc) { pEntityTable->GetValue( "OnSpawnSplash",m_pOnSpawnSplashFunc ); } HSCRIPTFUNCTION pScriptFunc = NULL; switch (nEffect) { case SPAWN_BUBBLE: pScriptFunc = m_pOnSpawnBubbleFunc; break; case SPAWN_SPLASH: pScriptFunc = m_pOnSpawnSplashFunc; break; } if (pScriptFunc) { if (!vec_Bubble) { vec_Bubble = gEnv->pScriptSystem->CreateTable(); } { CScriptSetGetChain bubbleChain(vec_Bubble); bubbleChain.SetValue( "x",pos.x ); bubbleChain.SetValue( "y",pos.y ); bubbleChain.SetValue( "z",pos.z ); } Script::Call( gEnv->pScriptSystem,pScriptFunc,pEntityTable,pos ); } }
void CProceduralContextAim::InitialisePoseBlenderAim() { CRY_ASSERT( m_entity ); const int slot = 0; ICharacterInstance* pCharacterInstance = m_entity->GetCharacter( slot ); if ( pCharacterInstance == NULL ) { return; } ISkeletonPose* pSkeletonPose = pCharacterInstance->GetISkeletonPose(); if ( pSkeletonPose == NULL ) { return; } m_pPoseBlenderAim = pSkeletonPose->GetIPoseBlenderAim(); if ( m_pPoseBlenderAim ) { m_defaultPolarCoordinatesSmoothTimeSeconds = 0.1f; float polarCoordinatesMaxYawDegreesPerSecond = 360.f; float polarCoordinatesMaxPitchDegreesPerSecond = 360.f; float fadeInSeconds = 0.25f; float fadeOutSeconds = 0.25f; float fadeOutMinDistance = 0.f; IScriptTable* pScriptTable = m_entity->GetScriptTable(); if ( pScriptTable ) { SmartScriptTable pProceduralContextAimTable; pScriptTable->GetValue( "ProceduralContextAim", pProceduralContextAimTable ); if ( pProceduralContextAimTable ) { pProceduralContextAimTable->GetValue( "polarCoordinatesSmoothTimeSeconds", m_defaultPolarCoordinatesSmoothTimeSeconds ); pProceduralContextAimTable->GetValue( "polarCoordinatesMaxYawDegreesPerSecond", polarCoordinatesMaxYawDegreesPerSecond ); pProceduralContextAimTable->GetValue( "polarCoordinatesMaxPitchDegreesPerSecond", polarCoordinatesMaxPitchDegreesPerSecond ); pProceduralContextAimTable->GetValue( "fadeInSeconds", fadeInSeconds ); pProceduralContextAimTable->GetValue( "fadeOutSeconds", fadeOutSeconds ); pProceduralContextAimTable->GetValue( "fadeOutMinDistance", fadeOutMinDistance ); } } m_defaultPolarCoordinatesMaxSmoothRateRadiansPerSecond = Vec2( DEG2RAD( polarCoordinatesMaxYawDegreesPerSecond ), DEG2RAD( polarCoordinatesMaxPitchDegreesPerSecond ) ); m_pPoseBlenderAim->SetPolarCoordinatesSmoothTimeSeconds( m_defaultPolarCoordinatesSmoothTimeSeconds ); m_pPoseBlenderAim->SetPolarCoordinatesMaxRadiansPerSecond( m_defaultPolarCoordinatesMaxSmoothRateRadiansPerSecond ); m_pPoseBlenderAim->SetFadeInSpeed( fadeInSeconds ); m_pPoseBlenderAim->SetFadeOutSpeed( fadeOutSeconds ); m_pPoseBlenderAim->SetFadeOutMinDistance( fadeOutMinDistance ); m_pPoseBlenderAim->SetState( false ); } }
bool CTornado::Reset() { //Initialize default values before (in case ScriptTable fails) m_wanderSpeed = 10.0f; m_cloudHeight = 376.0f; m_radius = 300.0f; m_spinImpulse = 9.0f; m_attractionImpulse = 13.0f; m_upImpulse = 18.0f; const char* funnelEffect = 0; SmartScriptTable props; IScriptTable* pScriptTable = GetEntity()->GetScriptTable(); if(!pScriptTable || !pScriptTable->GetValue("Properties", props)) return false; props->GetValue("fWanderSpeed", m_wanderSpeed); props->GetValue("fCloudHeight", m_cloudHeight); props->GetValue("Radius", m_radius); props->GetValue("fSpinImpulse", m_spinImpulse); props->GetValue("fAttractionImpulse", m_attractionImpulse); props->GetValue("fUpImpulse", m_upImpulse); props->GetValue("FunnelEffect", funnelEffect); if (!UseFunnelEffect(funnelEffect)) return false; Matrix34 m = GetEntity()->GetWorldTM(); m_wanderDir = m.GetColumn(1)*0.414214f; m_isOnWater = false; m_isInAir = false; m_nextEntitiesCheck = 0; Vec3 pos = GetEntity()->GetWorldPos(); gEnv->pLog->Log("TORNADO INIT POS: %f %f %f", pos.x, pos.y, pos.z); m_points[0] = pos; m_points[1] = pos + Vec3(0,0,m_cloudHeight/8.0f); m_points[2] = pos + Vec3(0,0,m_cloudHeight/2.0f); m_points[3] = pos + Vec3(0,0,m_cloudHeight); for (int i=0; i<4; ++i) m_oldPoints[i] = m_points[i]; m_currentPos = GetEntity()->GetWorldPos(); CHANGED_NETWORK_STATE(this, POSITION_ASPECT); UpdateTornadoSpline(); return true; }
bool CSmartMine::ShouldStartTrackingEntity( const EntityId entityId ) const { // Always track player... if (entityId == g_pGame->GetIGameFramework()->GetClientActorId()) { return true; } // ... or any AI const SAutoaimTarget* pTargetInfo = g_pGame->GetAutoAimManager().GetTargetInfo( entityId ); if(pTargetInfo != NULL) { return (pTargetInfo->pActorWeak.lock() != NULL); } // Also track kickable and pickable objects IEntity* pEntity = gEnv->pEntitySystem->GetEntity( entityId ); IScriptTable* pScriptTable = (pEntity != NULL) ? pEntity->GetScriptTable() : NULL; if(pScriptTable != NULL) { SmartScriptTable propertiesTable; if(pScriptTable->GetValue("Properties", propertiesTable)) { int pickable = 0, kickable = 0; propertiesTable->GetValue("bPickable", pickable); propertiesTable->GetValue("bInteractLargeObject", kickable); if(pickable) { // Filter out items/weapons pickable = (g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(entityId) == NULL); } if (pickable || kickable) { //Check if object is moving IPhysicalEntity* pEntityPhysics = pEntity->GetPhysics(); if(pEntityPhysics != NULL) { pe_status_dynamics entityDynamics; if(pEntityPhysics->GetStatus(&entityDynamics)) { return (entityDynamics.v.len2() > 0.1f); } } } } } return false; }
//------------------------------------------------------------------------ void CVehicleDamageBehaviorBlowTire::OnVehicleEvent(EVehicleEvent event, const SVehicleEventParams& params) { assert(event == eVE_Timer); // notify AI passengers IScriptTable* pTable = m_pVehicle->GetEntity()->GetScriptTable(); HSCRIPTFUNCTION scriptFunction(NULL); if (pTable && pTable->GetValue("OnVehicleImmobilized", scriptFunction) && scriptFunction) { Script::Call(gEnv->pScriptSystem, scriptFunction, pTable); gEnv->pScriptSystem->ReleaseFunc(scriptFunction); } }
void CVicinityDependentObjectMover::SetupEntity() { const char* szModelName = VICINITYDEPENDENTOBJECTMOVER_MODEL_NORMAL; float fMoveToDistance = 10.0f; float fAreaTriggerRange = 10.0f; float fBackAreaTriggerRange = 10.0f; float fForceMoveCompleteDistance = 1.0f; IEntity* pEntity = GetEntity(); CRY_ASSERT( pEntity != NULL ); IScriptTable* pScriptTable = pEntity->GetScriptTable(); if ( pScriptTable != NULL ) { SmartScriptTable propertiesTable; if ( pScriptTable->GetValue( "Properties", propertiesTable) ) { propertiesTable->GetValue( "objModel", szModelName ); propertiesTable->GetValue( "fMoveToDistance", fMoveToDistance ); propertiesTable->GetValue( "fMoveToSpeed", m_fMoveToSpeed ); propertiesTable->GetValue( "fMoveBackSpeed", m_fMoveBackSpeed ); propertiesTable->GetValue( "fAreaTriggerRange", fAreaTriggerRange ); propertiesTable->GetValue( "fBackAreaTriggerRange", fBackAreaTriggerRange ); propertiesTable->GetValue( "fForceMoveCompleteDistance", fForceMoveCompleteDistance ); propertiesTable->GetValue( "bUseAreaTrigger", m_bUseAreaTrigger ); propertiesTable->GetValue( "bDisableAreaTriggerOnMoveComplete", m_bDisableAreaTriggerOnMoveComplete ); } } m_fMoveToDistance = fMoveToDistance; m_fMoveToDistanceSq = fMoveToDistance*fMoveToDistance; m_fAreaTriggerRange = fAreaTriggerRange; m_fAreaTriggerRangeSq = fAreaTriggerRange*fAreaTriggerRange; m_fBackAreaTriggerRange = fBackAreaTriggerRange; m_fBackAreaTriggerRangeSq = fBackAreaTriggerRange*fBackAreaTriggerRange; m_fForceMoveCompleteDistanceSq = fForceMoveCompleteDistance*fForceMoveCompleteDistance; // Load model pEntity->LoadGeometry( VICINITYDEPENDENTOBJECTMOVER_MODEL_NORMAL_SLOT, szModelName ); // Draw slot and physicalize it DrawSlot( VICINITYDEPENDENTOBJECTMOVER_MODEL_NORMAL_SLOT, true ); SEntityPhysicalizeParams physicalizeParams; physicalizeParams.nSlot = VICINITYDEPENDENTOBJECTMOVER_MODEL_NORMAL_SLOT; physicalizeParams.type = PE_RIGID; physicalizeParams.mass = 0; GetEntity()->Physicalize( physicalizeParams ); }
void CDangerousRigidBody::Reset() { IScriptTable* pTable = GetEntity()->GetScriptTable(); if (pTable != NULL) { SmartScriptTable propertiesTable; if (pTable->GetValue("Properties", propertiesTable)) { propertiesTable->GetValue("bCurrentlyDealingDamage", m_dangerous); propertiesTable->GetValue("bDoesFriendlyFireDamage", m_friendlyFireEnabled); propertiesTable->GetValue("fDamageToDeal", m_damageDealt); propertiesTable->GetValue("fTimeBetweenHits", m_timeBetweenHits); } } m_activatorTeam = 0; m_lastHitTime = 0; }
//------------------------------------------------------------------------ bool CShake::Init(IGameObject *pGameObject) { SetGameObject(pGameObject); //Initialize default values before (in case ScriptTable fails) m_radius = 30.0f; m_shake = 0.05f; SmartScriptTable props; IScriptTable* pScriptTable = GetEntity()->GetScriptTable(); if(!pScriptTable || !pScriptTable->GetValue("Properties", props)) return false; props->GetValue("Radius", m_radius); props->GetValue("Shake", m_shake); return true; }
const char* CDoorPanelBehavior::GetDestroyedExplosionType( IEntity* pEntity ) { CRY_ASSERT(pEntity != NULL); const char* szModelDestroyedName = DOOR_PANEL_MODEL_DESTROYED; IScriptTable* pScriptTable = pEntity->GetScriptTable(); if (pScriptTable != NULL) { SmartScriptTable propertiesTable; if (pScriptTable->GetValue("Properties", propertiesTable)) { propertiesTable->GetValue("DestroyedExplosionType", szModelDestroyedName); } } return szModelDestroyedName; }
void CAutoAimManager::RegisterCharacterTargetInfo(const CActor& targetActor, const SAutoaimTargetRegisterParams& registerParams) { SAutoaimTarget aimTarget; aimTarget.entityId = targetActor.GetEntityId(); aimTarget.pActorWeak = targetActor.GetWeakPtr(); aimTarget.fallbackOffset = registerParams.fallbackOffset; aimTarget.primaryBoneId = registerParams.primaryBoneId; aimTarget.physicsBoneId = registerParams.physicsBoneId; aimTarget.secondaryBoneId = registerParams.secondaryBoneId; aimTarget.innerRadius = registerParams.innerRadius; aimTarget.outerRadius = registerParams.outerRadius; aimTarget.snapRadius = registerParams.snapRadius; aimTarget.snapRadiusTagged = registerParams.snapRadiusTagged; if (!gEnv->bMultiplayer) { IEntity* pTargetEntity = targetActor.GetEntity(); aimTarget.aiFaction = IFactionMap::InvalidFactionID; //Instance properties, other stuff could be added here easily (grab enemy, sliding hit, etc) SmartScriptTable props; SmartScriptTable propsPlayerInteractions; IScriptTable* pScriptTable = pTargetEntity->GetScriptTable(); if (pScriptTable && pScriptTable->GetValue("Properties", props)) { if (props->GetValue("PlayerInteractions", propsPlayerInteractions)) { int stealhKill = 0; if (propsPlayerInteractions->GetValue("bStealthKill", stealhKill) && (stealhKill != 0)) { aimTarget.SetFlag(eAATF_StealthKillable); } int canBeGrabbed = 0; if (propsPlayerInteractions->GetValue("bCanBeGrabbed", canBeGrabbed) && (canBeGrabbed != 0)) { aimTarget.SetFlag(eAATF_CanBeGrabbed); } } } } m_autoaimTargets.push_back(aimTarget); }
void CFrogBoid::OnEnteringWater(const SBoidContext &bc) { if (!bc.entity) return; IScriptTable *pEntityTable = bc.entity->GetScriptTable(); if (!pEntityTable) return; // Calling script function if(!m_pOnWaterSplashFunc) { pEntityTable->GetValue( "OnWaterSplash",m_pOnWaterSplashFunc ); } if(m_pOnWaterSplashFunc) Script::Call( gEnv->pScriptSystem,m_pOnWaterSplashFunc,pEntityTable,m_pos ); }
void CAreaProxy::OnEnable(bool bIsEnable, bool bIsCallScript) { m_bIsEnable = bIsEnable; if(m_pArea->GetAreaType()==ENTITY_AREA_TYPE_GRAVITYVOLUME) { SEntityPhysicalizeParams physparams; if(bIsEnable && m_bIsEnableInternal) { physparams.pAreaDef = &m_areaDefinition; m_areaDefinition.areaType = SEntityPhysicalizeParams::AreaDefinition::AREA_SPLINE; m_bezierPointsTmp.resize(m_bezierPoints.size()); memcpy( &m_bezierPointsTmp[0],&m_bezierPoints[0],m_bezierPoints.size()*sizeof(Vec3) ); m_areaDefinition.pPoints = &m_bezierPointsTmp[0]; m_areaDefinition.nNumPoints = m_bezierPointsTmp.size(); m_areaDefinition.fRadius = m_fRadius; m_gravityParams.gravity = Vec3(0,0,m_fGravity); m_gravityParams.falloff0 = m_fFalloff; m_gravityParams.damping = m_fDamping; physparams.type = PE_AREA; m_areaDefinition.pGravityParams = &m_gravityParams; m_pEntity->SetTimer(0, 11000); } m_pEntity->Physicalize(physparams); if(bIsCallScript) { //call the OnEnable function in the script, to set game flags for this entity and such. IScriptTable *pScriptTable = m_pEntity->GetScriptTable(); if (pScriptTable) { HSCRIPTFUNCTION scriptFunc(NULL); pScriptTable->GetValue("OnEnable", scriptFunc); if (scriptFunc) Script::Call(gEnv->pScriptSystem,scriptFunc,pScriptTable,bIsEnable); gEnv->pScriptSystem->ReleaseFunc(scriptFunc); } } } }
bool CNetworkBuilding::GetSettings() { SmartScriptTable entityProperties; IScriptTable* pScriptTable = GetEntity()->GetScriptTable(); if(!pScriptTable || !pScriptTable->GetValue("Properties", entityProperties)) { CryLog("[Network Building] : Error read lua properties !"); return false; } //Physics properties SmartScriptTable physicProperties; if (entityProperties->GetValue("Physics", physicProperties)) { physicProperties->GetValue("iPhysType", phys_type); physicProperties->GetValue("fPhysMass", phys_mass); physicProperties->GetValue("fPhysDensity", phys_density); } //Building properties SmartScriptTable buildingProperties; if (entityProperties->GetValue("Building", buildingProperties)) { // Geometry buildingProperties->GetValue("sDefaultModel",default_model); buildingProperties->GetValue("sModel_1",model_1); buildingProperties->GetValue("sModel_2",model_2); buildingProperties->GetValue("sModel_3",model_3); buildingProperties->GetValue("sFinishModel",finish_model); // Materials buildingProperties->GetValue("sModel_1_material",Model_1_mat); buildingProperties->GetValue("sModel_2_material",Model_2_mat); buildingProperties->GetValue("sModel_3_material",Model_3_mat); buildingProperties->GetValue("sFinishMaterial",finishMat); // buildingProperties->GetValue("fBuildTime",build_time); } return true; }
void CBoundingContainer::SetupEntity() { IEntity* pEntity = GetEntity(); CRY_ASSERT(pEntity != NULL); IScriptTable* pScriptTable = pEntity->GetScriptTable(); if (pScriptTable != NULL) { SmartScriptTable propertiesTable; if (pScriptTable->GetValue("Properties", propertiesTable)) { Vec3 boundingDimensions(0.0f,0.0f,0.0f); propertiesTable->GetValue("DimX", boundingDimensions.x); propertiesTable->GetValue("DimY", boundingDimensions.y); propertiesTable->GetValue("DimZ", boundingDimensions.z); m_vBoundingMin = -boundingDimensions/2.0f; m_vBoundingMax = boundingDimensions/2.0f; } } }
void CCheckpointSystem::OnCheckpointLoaded(SCheckpointData metaData) { IEntity *pCheckpoint = gEnv->pEntitySystem->GetEntity(metaData.m_checkPointId); if(pCheckpoint) { //Trigger OnLoad IScriptTable *pScript = pCheckpoint->GetScriptTable(); if (pScript) { HSCRIPTFUNCTION hScriptFunc(NULL); pScript->GetValue("Event_OnLoadCheckpoint", hScriptFunc); if (hScriptFunc) //this will trigger the flowgraph output { IScriptSystem *pIScriptSystem = gEnv->pScriptSystem; Script::Call(pIScriptSystem,hScriptFunc,pScript); pIScriptSystem->ReleaseFunc(hScriptFunc); } } } }
// ============================================================================ // Query if the shield entity is dead. // // Returns: True if dead; otherwise false. // bool CDeflectorShield::IsDead() const { // In the future we could make this a call-back or something? assert(GetEntity() != NULL); IScriptTable* scriptTable = GetEntity()->GetScriptTable(); if (scriptTable == NULL) { assert(false); return true; } HSCRIPTFUNCTION scriptFunc(NULL); if (!(scriptTable->GetValue("IsDead", scriptFunc))) { assert(false); return true; } bool deadFlag = false; Script::CallReturn(gEnv->pScriptSystem, scriptFunc, scriptTable, deadFlag); gEnv->pScriptSystem->ReleaseFunc(scriptFunc); return deadFlag; }
//------------------------------------------------------------------------ void CVehicleDamageBehaviorBlowTire::OnVehicleEvent(EVehicleEvent event, const SVehicleEventParams& params) { switch (event) { case eVE_Timer: { if (params.iParam == m_aiImmobilizedTimer) { // notify AI passengers IScriptTable* pTable = m_pVehicle->GetEntity()->GetScriptTable(); HSCRIPTFUNCTION scriptFunction(NULL); if (pTable && pTable->GetValue("OnVehicleImmobilized", scriptFunction) && scriptFunction) { Script::Call(gEnv->pScriptSystem, scriptFunction, pTable); } m_aiImmobilizedTimer = -1; } } break; } }
// =========================================================================== // Query if an entity is resurrectable. // // In: Pointer to the target entity (NULL will abort!) // // Returns: True if resurrectable; otherwise false. // bool MastermindModuleDeathListener::IsEntityResurrectable(const IEntity* entity) const { // Do the cheap checks first. if (entity->IsHidden()) { return false; } // And then the more expensive ones. IScriptTable* scriptTable = entity->GetScriptTable(); if (scriptTable == NULL) { return false; } SmartScriptTable props; if (!(scriptTable->GetValue("Properties", props))) { return false; } SmartScriptTable propsResurrection; if (!(props->GetValue("Resurrection", propsResurrection))) { return false; } bool huskableByMastermind = false; if (propsResurrection->GetValue("bHuskableByMastermind", huskableByMastermind)) { if (!huskableByMastermind) { return false; } } return true; }
void SearchGroup::InitActors() { IVisionMap& visionMap = *gEnv->pAISystem->GetVisionMap(); SearchActors::iterator actorIt = m_actors.begin(); SearchActors::iterator actorEnd = m_actors.end(); for ( ; actorIt != actorEnd; ++actorIt) { SearchActor& actor = *actorIt; Agent agent(actor.entityID); assert(agent.IsValid()); if (agent.IsValid()) { actor.visionID = visionMap.CreateVisionID(agent.GetName()); ObserverParams observerParams; observerParams.entityId = actor.entityID; observerParams.factionsToObserveMask = 0xFFFFFFFF; observerParams.typeMask = ::SearchSpots; observerParams.eyePosition = agent.GetPos(); observerParams.eyeDirection = agent.GetViewDir(); observerParams.fovCos = cosf(120.0f); observerParams.sightRange = 8.0f; IScriptTable* entityTable = agent.GetScriptTable(); SmartScriptTable properties; if (entityTable->GetValue("SearchModule", properties)) properties->GetValue("sightRange", observerParams.sightRange); visionMap.RegisterObserver(actor.visionID, observerParams); } } }
//------------------------------------------------------------------------ void CGameRulesKingOfTheHillObjective::Update( float frameTime ) { BaseType::Update(frameTime); CGameRules *pGameRules = g_pGame->GetGameRules(); IGameRulesScoringModule *pScoringModule = pGameRules->GetScoringModule(); const int localTeamId = pGameRules->GetTeam(g_pGame->GetIGameFramework()->GetClientActorId()); for (int i = 0; i < HOLD_OBJECTIVE_MAX_ENTITIES; ++ i) { SHoldEntityDetails *pDetails = &m_entities[i]; if (!pDetails->m_id) { continue; } SKotHEntity *pKotHEntity = static_cast<SKotHEntity *>(pDetails->m_pAdditionalData); CRY_ASSERT(pKotHEntity); if (gEnv->bServer && pScoringModule) { #ifndef _RELEASE if (g_pGameCVars->g_KingOfTheHillObjective_watchLvl) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(pDetails->m_id); const char *pEntName = pEntity ? pEntity->GetName() : "<NULL>"; if (pDetails->m_controllingTeamId == CONTESTED_TEAM_ID) { CryWatch("KotH entity '%s' is contested", pEntName); } else if (pDetails->m_controllingTeamId == 0) { CryWatch("KotH entity '%s' has no players nearby", pEntName); } else { CryWatch("KotH entity '%s' controlled by team %i, scoreTimerLength='%.2f', timeSinceLastScore='%.2f'", pEntName, pDetails->m_controllingTeamId, pKotHEntity->m_scoreTimerLength, pKotHEntity->m_timeSinceLastScore); } } #endif if (pKotHEntity->m_scoringTeamId) { const int teamIndex = pKotHEntity->m_scoringTeamId - 1; CRY_ASSERT_MESSAGE(teamIndex >= 0 && teamIndex < NUM_TEAMS, "Update() scoringTeamId is out of range"); pKotHEntity->m_timeSinceLastScore += frameTime; if (pKotHEntity->m_timeSinceLastScore >= pKotHEntity->m_scoreTimerLength) { pScoringModule->OnTeamScoringEvent(teamIndex + 1, EGRST_KingOfTheHillObjectiveHeld); pKotHEntity->m_timeSinceLastScore = 0.f; AwardPlayerPoints(&pDetails->m_insideEntities[teamIndex], EGRST_KingOfTheHillObjectiveHeld); CCCPOINT_IF((pKotHEntity->m_scoringTeamId == 1), KingOfTheHillObjective_TeamMarinesScored); CCCPOINT_IF((pKotHEntity->m_scoringTeamId == 2), KingOfTheHillObjective_TeamCellScored); } } } if (gEnv->IsClient()) { if (m_useIcons && pKotHEntity->m_needsIconUpdate) { UpdateIcon(pDetails); } if (pGameRules->GetGameMode() == eGM_CrashSite) { if (pDetails->m_localPlayerIsWithinRange && pDetails->m_controllingTeamId != CONTESTED_TEAM_ID) { CPersistantStats::GetInstance()->IncrementClientStats(EFPS_CrashSiteHeldTime, frameTime); } } if (pKotHEntity->m_bPulseEnabled) { pKotHEntity->m_pulseTime -= frameTime; if (pKotHEntity->m_pulseTime < 0.f) { eRadiusPulseType pulseType = GetPulseType(pDetails); const float radiusEffectScale = pKotHEntity->m_radiusEffectScale * pDetails->m_controlRadius; RadiusEffectPulse(pDetails->m_id, pulseType, radiusEffectScale); pKotHEntity->m_pulseTime = m_pulseTimerLength; } } else { if (!m_shouldDoPulseEffectFunc.empty()) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(pDetails->m_id); if (pEntity) { IScriptTable *pEntityScript = pEntity->GetScriptTable(); HSCRIPTFUNCTION pulseCheckFunc; if (pEntityScript != NULL && pEntityScript->GetValue(m_shouldDoPulseEffectFunc.c_str(), pulseCheckFunc)) { IScriptSystem *pScriptSystem = gEnv->pScriptSystem; bool result = false; if (Script::CallReturn(pScriptSystem, pulseCheckFunc, pEntityScript, result)) { pKotHEntity->m_bPulseEnabled = result; } } } } } const float fOldScoringSFX = pKotHEntity->m_fScoringSFX; if(pKotHEntity->m_scoringTeamId) { pKotHEntity->m_fScoringSFX = min(pKotHEntity->m_fScoringSFX + (frameTime * 2.0f), 1.0f); } else { pKotHEntity->m_fScoringSFX = max(pKotHEntity->m_fScoringSFX - (frameTime * 1.0f), 0.0f); } if(pKotHEntity->m_fScoringSFX != fOldScoringSFX) UpdateEntityAudio(pDetails); } } }
// (jh) this function is called on any input dispatching it to a relevant method and eventually to Lua onAction method void CPlayerInput::OnAction( const ActionId& actionId, int activationMode, float value ) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); if (g_pGame->GetHostMigrationState() != CGame::eHMS_NotMigrating) { Reset(); return; } m_pPlayer->GetGameObject()->ChangedNetworkState( INPUT_ASPECT ); m_lastActions=m_actions; //this tell if OnAction have to be forwarded to scripts, now its true by default, only high framerate actions are ignored bool filterOut = true; m_checkZoom = false; const CGameActions& actions = g_pGame->Actions(); IVehicle* pVehicle = m_pPlayer->GetLinkedVehicle(); bool canMove = CanMove(); // disable movement while standing up if (!canMove) m_deltaMovement.zero(); // try to dispatch action to OnActionHandlers bool handled; { FRAME_PROFILER("New Action Processing", GetISystem(), PROFILE_GAME); handled = s_actionHandler.Dispatch(this, m_pPlayer->GetEntityId(), actionId, activationMode, value, filterOut); } { FRAME_PROFILER("Regular Action Processing", GetISystem(), PROFILE_GAME); if (!handled) { filterOut = true; if (!m_pPlayer->m_stats.spectatorMode) { if (actions.ulammo==actionId && m_pPlayer->m_pGameFramework->CanCheat() && gEnv->pSystem->IsDevMode()) { g_pGameCVars->i_unlimitedammo = 1; } else if (actions.debug_ag_step == actionId) { gEnv->pConsole->ExecuteString("ag_step"); } else if(actions.voice_chat_talk == actionId) { if(gEnv->bMultiplayer) { if(activationMode == eAAM_OnPress) g_pGame->GetIGameFramework()->EnableVoiceRecording(true); else if(activationMode == eAAM_OnRelease) g_pGame->GetIGameFramework()->EnableVoiceRecording(false); } } } } if (!m_pPlayer->m_stats.spectatorMode) { IInventory* pInventory = m_pPlayer->GetInventory(); if (!pInventory) return; bool scope = false; EntityId itemId = pInventory->GetCurrentItem(); CWeapon *pWeapon = 0; if (itemId) { pWeapon = m_pPlayer->GetWeapon(itemId); if (pWeapon) { scope = (pWeapon->IsZoomed() && pWeapon->GetMaxZoomSteps()>1); } } if (pVehicle) { if (m_pPlayer->m_pVehicleClient && !m_pPlayer->IsFrozen()) m_pPlayer->m_pVehicleClient->OnAction(pVehicle, m_pPlayer->GetEntityId(), actionId, activationMode, value); //FIXME:not really good m_actions = 0; m_deltaMovement.Set(0,0,0); } else if (m_pPlayer->GetHealth() > 0 && !m_pPlayer->m_stats.isFrozen.Value() && !m_pPlayer->m_stats.inFreefall.Value() && !m_pPlayer->m_stats.isOnLadder && !m_pPlayer->m_stats.isStandingUp && m_pPlayer->GetGameObject()->GetAspectProfile(eEA_Physics)!=eAP_Sleep) { m_pPlayer->CActor::OnAction(actionId, activationMode, value); if ((!scope || actionId == actions.use)) { COffHand* pOffHand = static_cast<COffHand*>(m_pPlayer->GetWeaponByClass(CItem::sOffHandClass)); if (pOffHand) { pOffHand->OnAction(m_pPlayer->GetEntityId(), actionId, activationMode, value); } if ((!pWeapon || !pWeapon->IsMounted())) { if ((actions.drop==actionId) && itemId) { float impulseScale=1.0f; if (activationMode==eAAM_OnPress) m_buttonPressure=2.5f; if (activationMode==eAAM_OnRelease) { m_buttonPressure=CLAMP(m_buttonPressure, 0.0f, 2.5f); impulseScale=1.0f+(1.0f-m_buttonPressure/2.5f)*15.0f; if (m_pPlayer->DropItem(itemId, impulseScale, true) && pOffHand && pOffHand->IsSelected()) { if (EntityId fistsId = pInventory->GetItemByClass(CItem::sFistsClass)) { m_pPlayer->SelectItem(fistsId, false); } pOffHand->PreExecuteAction(eOHA_REINIT_WEAPON, eAAM_OnPress); CItem* pItem = static_cast<CItem*>(m_pPlayer->GetCurrentItem()); if (pItem) { pItem->SetActionSuffix("akimbo_"); pItem->PlayAction(g_pItemStrings->idle); } } } } else if (actions.nextitem==actionId) m_pPlayer->SelectNextItem(1, true, 0); else if (actions.previtem==actionId) m_pPlayer->SelectNextItem(-1, true, 0); else if (actions.handgrenade==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.explosive==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.utility==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.small==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.medium==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.heavy==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.debug==actionId) { if (g_pGame) { if (!m_pPlayer->GetInventory()->GetItemByClass(CItem::sDebugGunClass)) g_pGame->GetWeaponSystem()->DebugGun(0); if (!m_pPlayer->GetInventory()->GetItemByClass(CItem::sRefWeaponClass)) g_pGame->GetWeaponSystem()->RefGun(0); } m_pPlayer->SelectNextItem(1, true, actionId.c_str()); } } } else { if (actions.handgrenade==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.explosive==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.utility==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.small==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.medium==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.heavy==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.drop==actionId && activationMode == eAAM_OnRelease && itemId) m_pPlayer->DropItem(itemId, 1.0f, true); } } if (m_checkZoom) { if (pWeapon) { IZoomMode *zm = pWeapon->GetZoomMode(pWeapon->GetCurrentZoomMode()); CScreenEffects* pScreenEffects = m_pPlayer->GetScreenEffects(); if (zm && !zm->IsZoomingInOrOut() && !zm->IsZoomed() && pScreenEffects != 0) { if (!m_moveButtonState && m_pPlayer->IsClient()) { IBlendedEffect *fovEffect = CBlendedEffect<CFOVEffect>::Create(CFOVEffect(m_pPlayer->GetEntityId(),1.0f)); IBlendType *blend = CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f)); pScreenEffects->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomIn, false); pScreenEffects->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomOut, false); pScreenEffects->StartBlend(fovEffect, blend, 1.0f/.25f, CScreenEffects::eSFX_GID_ZoomIn); } else { pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_ZoomIn); pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_ZoomOut); pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_HitReaction); } } } } } } bool hudFilterOut = true; // FIXME: temporary method to dispatch Actions to HUD (it's not yet possible to register) hudFilterOut = true; //Filter must take into account offHand too COffHand* pOffHand = static_cast<COffHand*>(m_pPlayer->GetWeaponByClass(CItem::sOffHandClass)); if(pOffHand && pOffHand->IsSelected()) filterOut = false; //send the onAction to scripts, after filter the range of actions. for now just use and hold if (filterOut && hudFilterOut) { FRAME_PROFILER("Script Processing", GetISystem(), PROFILE_GAME); HSCRIPTFUNCTION scriptOnAction(NULL); IScriptTable *scriptTbl = m_pPlayer->GetEntity()->GetScriptTable(); if (scriptTbl) { scriptTbl->GetValue("OnAction", scriptOnAction); if (scriptOnAction) { char *activation = 0; switch(activationMode) { case eAAM_OnHold: activation = "hold"; break; case eAAM_OnPress: activation = "press"; break; case eAAM_OnRelease: activation = "release"; break; default: activation = ""; break; } Script::Call(gEnv->pScriptSystem,scriptOnAction,scriptTbl,actionId.c_str(),activation, value); } } gEnv->pScriptSystem->ReleaseFunc(scriptOnAction); } }
//------------------------------------------------------------------------ void CGameRules::ServerSimpleHit(const SimpleHitInfo &simpleHitInfo) { switch (simpleHitInfo.type) { case 0: // tag { if (!simpleHitInfo.targetId) { return; } // tagged entities are temporary in MP, not in SP. bool temp = gEnv->bMultiplayer; AddTaggedEntity(simpleHitInfo.shooterId, simpleHitInfo.targetId, temp); } break; case 1: // tac { if (!simpleHitInfo.targetId) { return; } CActor *pActor = (CActor *)gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(simpleHitInfo.targetId); if (pActor && pActor->CanSleep()) { pActor->Fall(Vec3(0.0f, 0.0f, 0.0f), simpleHitInfo.value); } } break; case 0xe: // freeze { if (!simpleHitInfo.targetId) { return; } // call OnFreeze bool allow = true; if (m_serverStateScript.GetPtr() && m_serverStateScript->GetValueType("OnFreeze") == svtFunction) { HSCRIPTFUNCTION func = 0; m_serverStateScript->GetValue("OnFreeze", func); Script::CallReturn(m_serverStateScript->GetScriptSystem(), func, m_script, ScriptHandle(simpleHitInfo.targetId), ScriptHandle(simpleHitInfo.shooterId), ScriptHandle(simpleHitInfo.weaponId), simpleHitInfo.value, allow); gEnv->pScriptSystem->ReleaseFunc(func); } if (!allow) { return; } if (IEntity *pEntity = gEnv->pEntitySystem->GetEntity(simpleHitInfo.targetId)) { IScriptTable *pScriptTable = pEntity->GetScriptTable(); // call OnFrost if (pScriptTable && pScriptTable->GetValueType("OnFrost") == svtFunction) { HSCRIPTFUNCTION func = 0; pScriptTable->GetValue("OnFrost", func); Script::Call(pScriptTable->GetScriptSystem(), func, pScriptTable, ScriptHandle(simpleHitInfo.shooterId), ScriptHandle(simpleHitInfo.weaponId), simpleHitInfo.value); gEnv->pScriptSystem->ReleaseFunc(func); } FreezeEntity(simpleHitInfo.targetId, true, true, simpleHitInfo.value > 0.999f); } } break; default: assert(!"Unknown Simple Hit type!"); } }
//------------------------------------------------------------------------ void CGameRulesHoldObjectiveBase::DoAddEntityId(int type, EntityId entityId, int index, bool isNewEntity) { CRY_ASSERT(index < HOLD_OBJECTIVE_MAX_ENTITIES); CryLog("CGameRulesHoldObjectiveBase::DoAddEntityId() received objective, eid=%i, index=%i", entityId, index); SHoldEntityDetails *pDetails = &m_entities[index]; pDetails->m_id = entityId; if (m_spawnPOIType == eSPT_Avoid) { IGameRulesSpawningModule *pSpawningModule = g_pGame->GetGameRules()->GetSpawningModule(); if (pSpawningModule) { pSpawningModule->AddAvoidPOI(entityId, m_spawnPOIDistance, true, AreObjectivesStatic()); } } OnNewHoldEntity(pDetails, index); CCCPOINT(HoldObjective_AddEntity); gEnv->pEntitySystem->AddEntityEventListener(entityId, ENTITY_EVENT_ENTERAREA, this); gEnv->pEntitySystem->AddEntityEventListener(entityId, ENTITY_EVENT_LEAVEAREA, this); if (gEnv->bServer) { CHANGED_NETWORK_STATE(g_pGame->GetGameRules(), HOLD_OBJECTIVE_STATE_ASPECT); } if(isNewEntity) { //Not playing for the first time because it clashes with game start Announce("Incoming", k_announceType_CS_Incoming, m_shouldPlayIncomingAudio); m_shouldPlayIncomingAudio = true; } IEntity *pEntity = gEnv->pEntitySystem->GetEntity(entityId); if (pEntity) { IScriptTable *pScript = pEntity->GetScriptTable(); CRY_TODO(11, 02, 2009, "function name from xml?"); if (pScript) { if (pScript->GetValueType("ActivateCapturePoint") == svtFunction) { if (isNewEntity) { // Set flag to say we're expecting a trackview to start - so we can set the start position in the callback m_bExpectingMovieStart = true; if (!m_bAddedMovieListener) { if (gEnv->pMovieSystem) { CryLog("CGameRulesHoldObjectiveBase::CGameRulesHoldObjectiveBase() adding movie listener"); gEnv->pMovieSystem->AddMovieListener(NULL, this); m_bAddedMovieListener = true; } } } IScriptSystem *pScriptSystem = gEnv->pScriptSystem; pScriptSystem->BeginCall(pScript, "ActivateCapturePoint"); pScriptSystem->PushFuncParam(pScript); pScriptSystem->PushFuncParam(isNewEntity); pScriptSystem->EndCall(); } SmartScriptTable propertiesTable; if (pScript->GetValue("Properties", propertiesTable)) { pDetails->m_controlRadius = 5.f; propertiesTable->GetValue("ControlRadius", pDetails->m_controlRadius); pDetails->m_controlRadiusSqr = (pDetails->m_controlRadius * pDetails->m_controlRadius); pDetails->m_controlHeight = 5.f; propertiesTable->GetValue("ControlHeight", pDetails->m_controlHeight); pDetails->m_controlOffsetZ = 0.f; propertiesTable->GetValue("ControlOffsetZ", pDetails->m_controlOffsetZ); } } const IActor *pLocalPlayer = g_pGame->GetIGameFramework()->GetClientActor(); if (pLocalPlayer != NULL && IsActorEligible(pLocalPlayer)) { CheckLocalPlayerInside(pDetails, pEntity, pLocalPlayer->GetEntity()); } } }
//------------------------------------------------------------------------ EGameRulesMissionObjectives CGameRulesKingOfTheHillObjective::GetIcon( SHoldEntityDetails *pDetails, const char **ppOutName, const char **ppOutColour ) { SKotHEntity *pKotHEntity = static_cast<SKotHEntity*>(pDetails->m_pAdditionalData); CRY_ASSERT(pKotHEntity); EGameRulesMissionObjectives requestedIcon = EGRMO_Unknown; if (!pDetails->m_id) { requestedIcon = EGRMO_Unknown; } else { bool iconAllowed = true; if (!m_shouldShowIconFunc.empty()) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(pDetails->m_id); if (pEntity) { IScriptTable *pEntityScript = pEntity->GetScriptTable(); HSCRIPTFUNCTION iconCheckFunc; if (pEntityScript != NULL && pEntityScript->GetValue(m_shouldShowIconFunc.c_str(), iconCheckFunc)) { IScriptSystem *pScriptSystem = gEnv->pScriptSystem; bool result = false; if (Script::CallReturn(pScriptSystem, iconCheckFunc, pEntityScript, result)) { if (!result) { requestedIcon = EGRMO_Unknown; iconAllowed = false; } } } } } if (iconAllowed) { const char *pFriendlyColour = "#9AD5B7"; const char *pHostileColour = "#AC0000"; const char *pNeutralColour = "#666666"; CGameRules *pGameRules = g_pGame->GetGameRules(); int localTeamId = pGameRules->GetTeam(g_pGame->GetIGameFramework()->GetClientActorId()); if ( (pDetails->m_controllingTeamId == 0) ) { requestedIcon = m_neutralIcon; *ppOutName = m_iconTextCapture.c_str(); *ppOutColour = pNeutralColour; } else if( (pDetails->m_controllingTeamId == CONTESTED_TEAM_ID) ) { requestedIcon = m_contestedIcon; *ppOutName = m_iconTextClear.c_str(); *ppOutColour = pHostileColour; } else if (pDetails->m_controllingTeamId == localTeamId) { requestedIcon = m_friendlyIcon; *ppOutName = m_iconTextDefend.c_str(); *ppOutColour = pFriendlyColour; } else { requestedIcon = m_hostileIcon; *ppOutName = m_iconTextClear.c_str(); *ppOutColour = pHostileColour; } } } return requestedIcon; }
void CUIHUD3D::SpawnHudEntities() { RemoveHudEntities(); if (gEnv->IsEditor() && gEnv->IsEditing()) return; const char* hudprefab = NULL; IGameRules* pGameRules = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->GetCurrentGameRules(); if (pGameRules) { IScriptTable* pTable = pGameRules->GetEntity()->GetScriptTable(); if (pTable) { if (!pTable->GetValue("hud_prefab", hudprefab)) hudprefab = NULL; } } hudprefab = hudprefab ? hudprefab : HUD3D_PREFAB_LIB; XmlNodeRef node = gEnv->pSystem->LoadXmlFromFile(hudprefab); if (node) { // get the prefab with the name defined in HUD3D_PREFAB_NAME XmlNodeRef prefab = NULL; for (int i = 0; i < node->getChildCount(); ++i) { const char* name = node->getChild(i)->getAttr("Name"); if (name && strcmp(name, HUD3D_PREFAB_NAME) == 0) { prefab = node->getChild(i); prefab = prefab ? prefab->findChild("Objects") : XmlNodeRef(); break; } } if (prefab) { // get the PIVOT entity and collect childs XmlNodeRef pivotNode = NULL; std::vector<XmlNodeRef> childs; const int count = prefab->getChildCount(); childs.reserve(count-1); for (int i = 0; i < count; ++i) { const char* name = prefab->getChild(i)->getAttr("Name"); if (strcmp("PIVOT", name) == 0) { assert(pivotNode == NULL); pivotNode = prefab->getChild(i); } else { childs.push_back(prefab->getChild(i)); } } if (pivotNode) { // spawn pivot entity IEntityClass* pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( pivotNode->getAttr("EntityClass") ); if (pEntClass) { SEntitySpawnParams params; params.nFlags = ENTITY_FLAG_CLIENT_ONLY; params.pClass = pEntClass; m_pHUDRootEntity = gEnv->pEntitySystem->SpawnEntity(params); } if (!m_pHUDRootEntity) return; m_HUDRootEntityId = m_pHUDRootEntity->GetId(); // spawn the childs and link to the pivot enity for (std::vector<XmlNodeRef>::iterator it = childs.begin(); it != childs.end(); ++it) { XmlNodeRef child = *it; pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( child->getAttr("EntityClass") ); if (pEntClass) { const char* material = child->getAttr("Material"); Vec3 pos; Vec3 scale; Quat rot; child->getAttr("Pos", pos); child->getAttr("Rotate", rot); child->getAttr("Scale", scale); SEntitySpawnParams params; params.nFlags = ENTITY_FLAG_CLIENT_ONLY; params.pClass = pEntClass; params.vPosition = pos; params.qRotation = rot; params.vScale = scale; IEntity* pEntity = gEnv->pEntitySystem->SpawnEntity(params); if (pEntity) { IScriptTable* pScriptTable = pEntity->GetScriptTable(); if (pScriptTable) { SmartScriptTable probs; pScriptTable->GetValue("Properties", probs); XmlNodeRef properties = child->findChild("Properties"); if (probs && properties) { for (int k = 0; k < properties->getNumAttributes(); ++k) { const char* sKey; const char* sVal; properties->getAttributeByIndex(k, &sKey, &sVal); probs->SetValue(sKey, sVal); } } Script::CallMethod(pScriptTable,"OnPropertyChange"); } if (material) { IMaterial* pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(material); if (pMat) pEntity->SetMaterial(pMat); } m_pHUDRootEntity->AttachChild(pEntity); m_HUDEnties.push_back( pEntity->GetId() ); } } } } } } OnVisCVarChange( NULL ); }