void CVTOLVehicleManager::RespawnVTOL(IVehicle* pVehicle, SVTOLInfo& info) { CryLog("CVTOLVehicleManager::RespawnVTOL()"); //Reset parts and component damage int numComponents = pVehicle->GetComponentCount(); for(int c = 0; c < numComponents; ++c) { IVehicleComponent* pComponent = pVehicle->GetComponent(c); int numParts = pComponent->GetPartCount(); for(int p = 0; p < numParts; ++p) { pComponent->GetPart(p)->Reset(); } pComponent->SetDamageRatio(0.f); } if (IVehicleMovement* pMovement = pVehicle->GetMovement()) { pMovement->Reset(); } SVehicleStatus& status = const_cast<SVehicleStatus&>(pVehicle->GetStatus()); status.Reset(); //Activate flowgraph Respawn output IScriptTable* pScriptTable = pVehicle->GetEntity()->GetScriptTable(); Script::CallMethod(pScriptTable, "Respawn", pScriptTable, 0); info.state = EVS_Normal; info.stateTime = 0.f; pVehicle->GetEntity()->Hide(false); LockSeats(pVehicle, false); SetupMovement(info.entityId); //Add to HUD Radar SHUDEvent hudEvent(eHUDEvent_AddEntity); hudEvent.AddData((int)info.entityId); CHUDEventDispatcher::CallEvent(hudEvent); }
//------------------------------------------------------------------------ void CVehiclePartLight::PostInit() { m_pHelper = m_pVehicle->GetHelper(m_pSharedParameters->m_helperPosName.c_str()); // get Components this Part belongs to. // currently that's only needed for Lights. for (int i=0,nComps=m_pVehicle->GetComponentCount(); i<nComps; ++i) { IVehicleComponent* pComponent = m_pVehicle->GetComponent(i); for (int j=0,nParts=pComponent->GetPartCount(); j<nParts; ++j) { if (pComponent->GetPart(j) == this) { m_components.push_back(pComponent); break; } } } if (VehicleCVars().v_lights_enable_always) ToggleLight(true); }
//------------------------------------------------------------------------ void CVehicleDamageBehaviorBlowTire::Activate(bool activate) { if (activate == m_isActive) return; if (activate && m_pVehicle->IsDestroyed()) return; if (activate) { // NOTE: stance and physics position when getting into vehicles is set wrong if (!gEnv->pSystem->IsSerializingFile()) DamagePlayers(); } IVehicleComponent* pComponent = m_pVehicle->GetComponent(m_component.c_str()); if (!pComponent) return; IVehiclePart* pPart = pComponent->GetPart(0); if (!pPart) return; // if IVehicleWheel available, execute full damage behavior. if null, only apply effects IVehicleWheel* pWheel = pPart->GetIWheel(); if (activate) { IEntity* pEntity = m_pVehicle->GetEntity(); IPhysicalEntity* pPhysics = pEntity->GetPhysics(); const Matrix34& wheelTM = pPart->GetLocalTM(false); const SVehicleStatus& status = m_pVehicle->GetStatus(); if (pWheel) { const pe_cargeomparams* pParams = pWheel->GetCarGeomParams(); // handle destroyed wheel pe_params_wheel wheelParams; wheelParams.iWheel = pWheel->GetWheelIndex(); wheelParams.minFriction = wheelParams.maxFriction = 0.5f * pParams->maxFriction; pPhysics->SetParams(&wheelParams); if (IVehicleMovement* pMovement = m_pVehicle->GetMovement()) { SVehicleMovementEventParams params; params.pComponent = pComponent; params.iValue = pWheel->GetWheelIndex(); pMovement->OnEvent(IVehicleMovement::eVME_TireBlown, params); } if (status.speed > 0.1f) { // add angular impulse pe_action_impulse angImp; float amount = m_pVehicle->GetMass() * status.speed * Random(0.25f, 0.45f) * -sgn(wheelTM.GetTranslation().x); angImp.angImpulse = pEntity->GetWorldTM().TransformVector(Vec3(0,0,amount)); pPhysics->Action(&angImp); } m_aiImmobilizedTimer = m_pVehicle->SetTimer(-1, AI_IMMOBILIZED_TIME*1000, this); } if (!gEnv->pSystem->IsSerializingFile()) { // add linear impulse pe_action_impulse imp; imp.point = pPart->GetWorldTM().GetTranslation(); float amount = m_pVehicle->GetMass() * Random(0.1f, 0.15f); if (pWheel) { amount *= max(0.5f, min(10.f, status.speed)); if (status.speed < 0.1f) amount = -0.5f*amount; } else amount *= 0.5f; imp.impulse = pEntity->GetWorldTM().TransformVector(Vec3(0,0,amount)); pPhysics->Action(&imp); // effect IParticleEffect* pEffect = gEnv->pParticleManager->FindEffect(TIRE_BLOW_EFFECT); if (pEffect) { int slot = pEntity->LoadParticleEmitter(-1, pEffect); if (slot > -1) { float rotation = pWheel ? 0.5f * gf_PI * -sgn(wheelTM.GetTranslation().x) : gf_PI; Matrix34 tm = Matrix34::CreateRotationZ(rotation); tm.SetTranslation(wheelTM.GetTranslation()); pEntity->SetSlotLocalTM(slot, tm); } } // remove affected decals { Vec3 pos = pPart->GetWorldTM().GetTranslation(); AABB aabb = pPart->GetLocalBounds(); float radius = aabb.GetRadius(); Vec3 vRadius(radius,radius,radius); AABB areaBox(pos-vRadius, pos+vRadius); IRenderNode * pRenderNode = NULL; if (IEntityRenderProxy *pRenderProxy = (IEntityRenderProxy*)pEntity->GetProxy(ENTITY_PROXY_RENDER)) pRenderNode = pRenderProxy->GetRenderNode(); gEnv->p3DEngine->DeleteDecalsInRange(&areaBox, pRenderNode); } } } else { if (pWheel) { // restore wheel properties IPhysicalEntity* pPhysics = m_pVehicle->GetEntity()->GetPhysics(); pe_params_wheel wheelParams; for (int i=0; i<m_pVehicle->GetWheelCount(); ++i) { const pe_cargeomparams* pParams = m_pVehicle->GetWheelPart(i)->GetIWheel()->GetCarGeomParams(); wheelParams.iWheel = i; wheelParams.bBlocked = 0; wheelParams.suspLenMax = pParams->lenMax; wheelParams.bDriving = pParams->bDriving; wheelParams.minFriction = pParams->minFriction; wheelParams.maxFriction = pParams->maxFriction; pPhysics->SetParams(&wheelParams); } if (IVehicleMovement* pMovement = m_pVehicle->GetMovement()) { SVehicleMovementEventParams params; params.pComponent = pComponent; params.iValue = pWheel->GetWheelIndex(); // reset the particle status pMovement->OnEvent(IVehicleMovement::eVME_TireRestored, params); } } m_aiImmobilizedTimer = -1; } m_isActive = activate; }
virtual void ProcessEvent( EFlowEvent event,SActivationInfo *pActInfo ) { IVehicleSystem * pVehicleSystem = NULL; IVehicle * pVehicle = NULL; switch(event) { case eFE_Initialize: { pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false); break; } case eFE_Activate: { if (!pActInfo->pEntity) return; pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem(); pVehicle = pVehicleSystem->GetVehicle(pActInfo->pEntity->GetId()); if (!pVehicleSystem || !pVehicle) return; string givenString = GetPortString(pActInfo, IN_PARTS); currentParam = givenString.substr(0,givenString.find_first_of(":")); currentSetting = givenString.substr(givenString.find_first_of(":")+1,(givenString.length()-givenString.find_first_of(":"))); column1 = 10.f; column2 = 100.f; if (IsPortActive(pActInfo,IN_SHOW)) pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true); break; } case eFE_Update: { IRenderer * pRenderer = gEnv->pRenderer; pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem(); pVehicle = pVehicleSystem->GetVehicle(pActInfo->pEntity->GetId()); if(!pVehicleSystem || !pActInfo->pEntity || !pVehicle) return; pRenderer->Draw2dLabel(column1,10,GetPortFloat(pActInfo,IN_SIZE)+2.f,Col_Cyan,false,pActInfo->pEntity->GetName()); if(currentParam=="Seats") { loops = 0; for(uint32 i=0;i<pVehicle->GetSeatCount();i++) { IVehicleSeat * currentSeat; if(currentSetting=="All") { currentSeat = pVehicle->GetSeatById(i+1); } else { currentSeat = pVehicle->GetSeatById(pVehicle->GetSeatId(currentSetting)); i = pVehicle->GetSeatCount()-1; } loops += 1; // column 1 string pMessage = ("%s:", currentSeat->GetSeatName()); if (column2<pMessage.size()*8*GetPortFloat(pActInfo, IN_SIZE)) column2=pMessage.size()*8*GetPortFloat(pActInfo, IN_SIZE); pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessage); // column 2 if(currentSeat->GetPassenger(true)) { pMessage = ("- %s", gEnv->pEntitySystem->GetEntity(currentSeat->GetPassenger(true))->GetName()); pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessage); } } } else if(currentParam=="Wheels") { pRenderer->Draw2dLabel(column1,50.f,GetPortFloat(pActInfo,IN_SIZE)+1.f,Col_Red,false,"!"); } else if(currentParam=="Weapons") { loops = 0; for(int i=0;i<pVehicle->GetWeaponCount();i++) { IItemSystem * pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); IWeapon * currentWeapon; EntityId currentEntityId; IItem * pItem; if(currentSetting=="All") { currentEntityId = pVehicle->GetWeaponId(i+1); } else { currentEntityId = gEnv->pEntitySystem->FindEntityByName(currentSetting)->GetId(); i = pVehicle->GetWeaponCount()-1; } if(!pItemSystem->GetItem(currentEntityId)) return; pItem = pItemSystem->GetItem(currentEntityId); currentWeapon = pItem->GetIWeapon(); loops += 1; // column 1 string pMessageName = string().Format("%s", gEnv->pEntitySystem->GetEntity(currentEntityId)->GetName()); pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessageName); if (column2<pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE)) column2=pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE); // column 2 string pMessageValue = string().Format("seat: %s firemode: %i", pVehicle->GetWeaponParentSeat(currentEntityId)->GetSeatName(), currentWeapon->GetCurrentFireMode()).c_str(); pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessageValue); } } else if(currentParam=="Components") { loops = 0; for(int i=0;i<pVehicle->GetComponentCount();i++) { IVehicleComponent * currentComponent; if(currentSetting=="All") { currentComponent = pVehicle->GetComponent(i); } else { currentComponent = pVehicle->GetComponent(currentSetting); i = pVehicle->GetComponentCount()-1; } loops += 1; ColorF labelColor; labelColor = ColorF(currentComponent->GetDamageRatio(),(1.f-currentComponent->GetDamageRatio()),0.f); // column 1 string pMessageName = string().Format("%s", currentComponent->GetComponentName()).c_str(); pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),labelColor,false,pMessageName); if (column2<pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE)) column2=pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE); // column 2 string pMessageValue = string().Format("%5.2f (%3.2f)", currentComponent->GetDamageRatio()*currentComponent->GetMaxDamage(), currentComponent->GetDamageRatio()).c_str(); pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),labelColor,false,pMessageValue); } } else { pRenderer->Draw2dLabel(column1,50.f,GetPortFloat(pActInfo,IN_SIZE)+1.f,Col_Red,false,"no component selected!"); } break; } } };