bool CBitmapUi::CanDrawCrosshair() const { assert( m_pGameFramework != NULL ); if ( ! g_pGameCVars->g_show_crosshair ) { return false; } IActor* pPlayer = m_pGameFramework->GetClientActor(); if ( pPlayer == NULL ) { return false; } bool isPlayerDead = pPlayer->IsDead(); if ( isPlayerDead ) { return false; } bool thirdPersonMode = pPlayer->IsThirdPerson(); bool crosshairEnabledInThirdPerson = ( g_pGameCVars->g_show_crosshair_tp != 0 ); if ( thirdPersonMode && ! crosshairEnabledInThirdPerson ) { return false; } IItem* pItem = pPlayer->GetCurrentItem(); if ( pItem == NULL ) { return false; } IWeapon* pWeapon = pItem->GetIWeapon(); if ( pWeapon == NULL ) { return false; } bool carryingMeleeWeapon = pWeapon->CanMeleeAttack(); if ( carryingMeleeWeapon ) { return false; } bool isWeaponZoomed = pWeapon->IsZoomed(); bool usingWeaponSightForAiming = ( ! thirdPersonMode && isWeaponZoomed ); if ( usingWeaponSightForAiming ) { return false; } return true; }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case (eFE_Activate): { if (!IsPortActive(pActInfo, 0)) return; IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem(); // get actor IActor* pActor = CCryAction::GetCryAction()->GetClientActor(); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(GetPortString(pActInfo,1)); IItem* pItem = pItemSys->GetItem(pInventory->GetItemByClass(pClass)); if (!pItem || !pItem->GetIWeapon()) { pItem = pActor->GetCurrentItem(); if (!pItem || pItem->GetEntity()->GetClass() != pClass || !pItem->GetIWeapon()) { GameWarning("[flow] CFlowNode_WeaponAmmo: No item/weapon %s!", GetPortString(pActInfo,1).c_str()); return; } } IWeapon *pWeapon = pItem->GetIWeapon(); const string& ammoType = GetPortString(pActInfo,2); IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str()); CRY_ASSERT(pAmmoClass); IFireMode* pCurrentFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()); if (pCurrentFireMode) { int clipSize = pCurrentFireMode->GetClipSize(); int ammo = pWeapon->GetAmmoCount(pAmmoClass) + GetPortInt(pActInfo,3); ammo = CLAMP(ammo, 0, clipSize); pWeapon->SetAmmoCount(pAmmoClass, ammo); } ActivateOutput(pActInfo, 0, pWeapon->GetAmmoCount(pAmmoClass)); } break; } }
void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo) { if (event == eFE_Activate && (IsPortActive(pActInfo, IN_GET) || IsPortActive(pActInfo, IN_SET))) { IActor* pActor = GetInputActor(pActInfo); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (pInventory) { const string& ammoType = GetPortString(pActInfo, IN_AMMOTYPE); IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str()); if (pAmmoClass) { if (IsPortActive(pActInfo, IN_SET)) { const bool bAdd = GetPortBool(pActInfo, IN_ADD); const int ammoAmount = GetPortInt(pActInfo, IN_AMMOCOUNT); pInventory->SetAmmoCount(pAmmoClass, bAdd ? (ammoAmount + pInventory->GetAmmoCount(pAmmoClass)) : (ammoAmount)); } int magazineAmmo = 0; int inventoryAmmo = pInventory->GetAmmoCount(pAmmoClass); if (IItem* pItem = pActor->GetCurrentItem()) { IWeapon* pCurrentWeapon = GetWeapon(pItem->GetEntityId()); if (pCurrentWeapon) { magazineAmmo = pCurrentWeapon->GetAmmoCount(pAmmoClass); } } ActivateOutput(pActInfo, OUT_MAGAZINE, magazineAmmo); ActivateOutput(pActInfo, OUT_INVENTORY, inventoryAmmo); ActivateOutput(pActInfo, OUT_TOTAL, (magazineAmmo + inventoryAmmo)); } } } }
int CFlowConvoyNode::GetCoachIndexPlayerIsOn() { IPhysicalEntity *pGroundCollider=NULL; IActor *pPlayerActor = gEnv->pGame->GetIGameFramework()->GetClientActor(); // if player use a mounted weapon on the train, the GroundCollider check not good if(m_coachIndex>=0) {//player can catch mounted weapon on the train if he were on it before CItem *pCurrentItem=static_cast<CItem *>(pPlayerActor->GetCurrentItem()); if ( pCurrentItem != NULL && pCurrentItem->IsMounted()) return m_coachIndex; // give back the last m_coachIndex, it should be valid } IPhysicalEntity *pPhysicalEntity=pPlayerActor->GetEntity()->GetPhysics(); if (pPhysicalEntity) { pe_status_living livStat; if(pPhysicalEntity->GetStatus(&livStat)) pGroundCollider=livStat.pGroundCollider; } if(!pGroundCollider) return -1; for (size_t i = 0; i < m_coaches.size(); ++i) { if(m_coaches[i].m_pEntity->GetPhysics()==pGroundCollider) return i; else {//attached objects IEntity *pCoachEntity=m_coaches[i].m_pEntity; for (int j = 0; j < pCoachEntity->GetChildCount(); ++j) { if(pCoachEntity->GetChild(j)->GetPhysics()==pGroundCollider) return i; } } } return -1; }
//------------------------------------------------------------------------ void CInventory::SerializeInventoryForLevelChange( TSerialize ser ) { IActor *pActor = GetActor(); if(!pActor) return; if(ser.IsReading()) { m_stats.ammoInfo.clear(); } m_bSerializeLTL = true; //Items by class (accessories) ser.BeginGroup("accessorySlots"); int exSize = m_stats.accessorySlots.size(); ser.Value("Size", exSize); if(ser.IsReading()) { m_stats.accessorySlots.resize(0); if(exSize>0) m_stats.accessorySlots.reserve(exSize); } for(int i = 0; i<exSize; ++i) { string accessoryName; if(ser.IsWriting()) accessoryName = m_stats.accessorySlots[i]->GetName(); ser.BeginGroup("Class"); ser.Value("AccessoryName", accessoryName); ser.EndGroup(); if(ser.IsReading()) { IEntityClass* pAccessoryClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(accessoryName); CRY_ASSERT(pAccessoryClass); if (pAccessoryClass) { m_stats.accessorySlots.push_back(pAccessoryClass); } } } ser.EndGroup();//"accessorySlots" if(ser.IsReading()) { for(int r = 0; r < m_stats.slots.size(); ++r) { IItem *pItem = m_pGameFrameWork->GetIItemSystem()->GetItem(m_stats.slots[r]); if(pItem) { pItem->Drop(); pItem->GetEntity()->SetFlags(pItem->GetEntity()->GetFlags()|ENTITY_FLAG_UPDATE_HIDDEN); pItem->GetEntity()->Hide(true); gEnv->pEntitySystem->RemoveEntity(m_stats.slots[r]); } } } int numItems = 0; string currentItemNameOnReading; if(ser.IsReading()) { m_stats.slots.clear(); m_stats.currentItemId = 0; m_stats.holsteredItemId = 0; m_stats.lastItemId = 0; string itemName; ser.Value("numOfItems", numItems); for(int i = 0; i < numItems; ++i) { ser.BeginGroup("Items"); bool nextItemExists = false; ser.Value("nextItemExists", nextItemExists); if(nextItemExists) { ser.Value("ItemName", itemName); EntityId id = m_pGameFrameWork->GetIItemSystem()->GiveItem(pActor, itemName.c_str(), false, false, false); IItem *pItem = m_pGameFrameWork->GetIItemSystem()->GetItem(id); if(pItem) { //actual serialization pItem->SerializeLTL(ser); } else CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Couldn't spawn inventory item %s, got id %i.", itemName.c_str(), id); } ser.EndGroup(); } ser.Value("CurrentItemName", itemName); if(stricmp(itemName.c_str(), "none")) { currentItemNameOnReading = itemName; IEntityClass *pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(itemName.c_str()); if(pClass) { if(IItem* pItem = m_pGameFrameWork->GetIItemSystem()->GetItem(GetItemByClass(pClass))) { if (pActor->GetCurrentItem() && pActor->GetCurrentItem() != pItem) pActor->GetCurrentItem()->Select(false); pItem->Select(true); m_stats.currentItemId = pItem->GetEntityId(); } else m_stats.currentItemId = m_pGameFrameWork->GetIItemSystem()->GiveItem(pActor, itemName.c_str(), false, true, false); } } } else { numItems = m_stats.slots.size(); ser.Value("numOfItems", numItems); for(int i = 0; i < numItems; ++i) { ser.BeginGroup("Items"); IItem *pItem = m_pGameFrameWork->GetIItemSystem()->GetItem(m_stats.slots[i]); bool nextItem = true; if(pItem) { ser.Value("nextItemExists", nextItem); ser.Value("ItemName", pItem->GetEntity()->GetClass()->GetName()); pItem->SerializeLTL(ser); } else { nextItem = false; ser.Value("nextItemExists", nextItem); } ser.EndGroup(); } bool currentItemIsInInventory = stl::find(m_stats.slots, m_stats.currentItemId); IItem* pCurrentItem = NULL; if (currentItemIsInInventory) { pCurrentItem = m_pGameFrameWork->GetIItemSystem()->GetItem(m_stats.currentItemId); } else { pCurrentItem = m_pGameFrameWork->GetIItemSystem()->GetItem(GetHolsteredItem()); //Fallback to last selected one... if (!pCurrentItem) { pCurrentItem = m_pGameFrameWork->GetIItemSystem()->GetItem(GetLastItem()); // desperate fallback to any weapon... // this fallback should never be needed. However, right now it happens if the player loads a savegame where a heavyweapon is being used, right before the end of the mission. // that is a bug, but at this point is safer to just do this bruteforce fallback instead of fixing it // TODO: to fix that and remove this fallback... if (!pCurrentItem) { for(int i = 0; i < numItems; ++i) { IItem *pItem = m_pGameFrameWork->GetIItemSystem()->GetItem( m_stats.slots[i] ); if (pItem) { const char* pCategoryName = m_pGameFrameWork->GetIItemSystem()->GetItemCategory( pItem->GetEntity()->GetClass()->GetName() ); if (pCategoryName) { EInventorySlots slotType = GetSlotForItemCategory( pCategoryName ); if (slotType==eInventorySlot_Weapon) { pCurrentItem = pItem; break; } } } } } } } if (pCurrentItem) { ser.Value("CurrentItemName", pCurrentItem->GetEntity()->GetClass()->GetName()); } else { string name("none"); ser.Value("CurrentItemName", name); } } //**************************************AMMO ser.BeginGroup("Ammo"); TAmmoInfoMap::iterator ammoInfoIt = m_stats.ammoInfo.begin(); int ammoAmount = m_stats.ammoInfo.size(); ser.Value("AmmoAmount", ammoAmount); for(int i = 0; i < ammoAmount; ++i) { string name; int amount = 0; int users = 0; int capacity = 0; if(ser.IsWriting()) { IEntityClass* pAmmoClass = ammoInfoIt->first; CRY_ASSERT(pAmmoClass); name = (pAmmoClass) ? pAmmoClass->GetName() : ""; const SAmmoInfo& ammoInfo = ammoInfoIt->second;; amount = ammoInfo.GetCount(); capacity = ammoInfo.GetCapacity(); ++ammoInfoIt; } ser.BeginGroup("Ammo"); ser.Value("AmmoName", name); ser.Value("Bullets", amount); ser.Value("Capacity", capacity); ser.EndGroup(); if(ser.IsReading()) { IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(name); CRY_ASSERT(pClass); TAmmoInfoMap::iterator it = m_stats.ammoInfo.find(pClass); if (it == m_stats.ammoInfo.end()) { m_stats.ammoInfo[pClass] = SAmmoInfo(amount, capacity); } else { it->second.SetCount(amount); it->second.SetCapacity(capacity); } } } ser.EndGroup(); m_bSerializeLTL = false; }
// // Extract the various modifiers out into their own function. // // Aim is to make the code easier to understand and modify, as // well as to ease the addition of new modifiers. // void CPlayerView::ViewFirstPerson(SViewParams &viewParams) { //headbob Ang3 angOffset(0,0,0); Vec3 weaponOffset(0,0,0); Ang3 weaponAngleOffset(0,0,0); // jump/land spring effect. Adjust the eye and weapon pos as required. FirstPersonJump(viewParams,weaponOffset,weaponAngleOffset); //float standSpeed(GetStanceMaxSpeed(STANCE_STAND)); Vec3 vSpeed(0,0,0); if (m_in.standSpeed>0.001f) vSpeed = (m_in.stats_velocity / m_in.standSpeed); float vSpeedLen(vSpeed.len()); if (vSpeedLen>1.5f) vSpeed = vSpeed / vSpeedLen * 1.5f; float speedMul(0); if (m_in.standSpeed>0.001f) speedMul=(m_in.stats_flatSpeed / m_in.standSpeed * 1.1f); speedMul = min(1.5f,speedMul); bool crawling(m_in.stance==STANCE_PRONE /*&& m_in.stats_flatSpeed>0.1f*/ && m_in.stats_onGround>0.1f); bool weaponZoomed = false; bool weaponZomming = false; //Not crawling while in zoom mode IActor *owner = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.entityId); if(owner && owner->IsPlayer()) { IItem *pItem = owner->GetCurrentItem(); if(pItem) { CWeapon *pWeapon = static_cast<CWeapon*>(pItem->GetIWeapon()); if(pWeapon) { weaponZoomed = pWeapon->IsZoomed(); weaponZomming = pWeapon->IsZooming(); if(weaponZoomed||weaponZomming||pWeapon->IsModifying()) crawling = false; } } } // On the ground. if (m_in.stats_inAir < 0.1f /*&& m_in.stats_inWater < 0.1f*/) { //--- Bobbing. // bobCycle is a speed varying time step running (looping) from 0 to 1 // this feeds into a sin eqn creating a double horizontal figure of 8. // ( a lissajous figure with the vertical freq twice the horz freq ). // To tweak the total speed of the curve: // To tweak the effect speed has on the curve: float kSpeedToBobFactor=1.15f;//0.9f // To tweak the width of the bob: float kBobWidth=0.1f; // To tweak the height of the bob: float kBobHeight=0.05f; // To tweak the scale of strafing lag: (may need to manually adjust the strafing angle offsets as well.) const float kStrafeHorzScale=0.05f; kBobWidth = 0.15f; kBobHeight = 0.06f; m_io.stats_bobCycle += m_in.frameTime * kSpeedToBobFactor * speedMul;// * (m_in.bSprinting?1.25f:1.0f); //if player is standing set the bob to rest. (bobCycle reaches 1.0f within 1 second) if (speedMul < 0.1f) m_io.stats_bobCycle = min(m_io.stats_bobCycle + m_in.frameTime * 1.0f,1.0f); // bobCycle loops between 0 and 1 if (m_io.stats_bobCycle>1.0f) m_io.stats_bobCycle = m_io.stats_bobCycle - 1.0f; if (crawling) kBobWidth *= 2.0f * speedMul; else if (m_in.bSprinting) kBobWidth *= 1.25f * speedMul; //set the bob offset Vec3 bobDir(cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f)*kBobWidth*speedMul,0,cry_sinf(m_io.stats_bobCycle*gf_PI*4.0f)*kBobHeight*speedMul); //not the bob offset for the weapon bobDir *= 0.25f; //if player is strafing shift a bit the weapon on left/right if (speedMul > 0.01f) { // right vector dot speed vector float dot(m_io.viewQuatFinal.GetColumn0() * vSpeed); bobDir.x -= dot * kStrafeHorzScale; // the faster we move right, the more the gun lags to the left and vice versa //tweak the right strafe for weapon laser if (dot>0.0f) weaponAngleOffset.z += dot * 1.5f; // kStrafeHorzScale else weaponAngleOffset.z -= dot * 2.0f; // kStrafeHorzScale weaponAngleOffset.y += dot * 5.0f; // kStrafeHorzScale } //CryLogAlways("bobDir.z: %f", bobDir.z); if (bobDir.z < 0.0f) { bobDir.x *= 1.0f; bobDir.y *= 1.0f; bobDir.z *= 0.35f; speedMul *= 0.65f; } else bobDir.z *= 1.85f; //CryLogAlways("bobDir.z: %f after", bobDir.z); weaponOffset += m_io.viewQuatFinal * bobDir; weaponOffset -= m_io.baseQuat.GetColumn2() * 0.035f * speedMul; weaponAngleOffset.y += cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f) * speedMul * -1.5f; if (crawling) weaponAngleOffset.y *= 3.0f; weaponAngleOffset.x += speedMul * 1.5f; if (crawling) weaponAngleOffset.z += cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f) * speedMul * 3.0f; //FIXME: viewAngles must include all the view offsets, otherwise aiming wont be precise. angOffset.x += cry_sinf(m_io.stats_bobCycle*gf_PI*4.0f)*0.7f*speedMul; if (crawling) { angOffset.x *= 2.5f; angOffset.y += cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f)*1.25f*speedMul; angOffset.z -= cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f)*2.5f*speedMul; } else if (m_in.bSprinting) { angOffset.x *= 2.5f; angOffset.y += cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f)*1.0f*speedMul; angOffset.z -= cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f)*2.25f*speedMul; } else if(m_in.stance==STANCE_CROUCH && !weaponZoomed && !weaponZomming) { weaponOffset.z += 0.035f; weaponOffset.y -= m_io.viewQuatFinal.GetColumn1().y * 0.03f; } else if(m_in.stance==STANCE_CROUCH && weaponZomming) { weaponOffset.z -= 0.07f; weaponOffset.y += m_io.viewQuatFinal.GetColumn1().y * 0.06f; } else { //angOffset.x *= 2.25f; //angOffset.y += cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f)*0.5f*speedMul; //angOffset.z -= cry_sinf(m_io.stats_bobCycle*gf_PI*2.0f)*1.125f*speedMul; } } else { m_io.stats_bobCycle = 0; //while flying offset a bit the weapon model by the player speed if (m_in.stats_velocity.len2()>0.001f) { float dotFwd(m_io.viewQuatFinal.GetColumn1() * vSpeed); float dotSide(m_io.viewQuatFinal.GetColumn0() * vSpeed); float dotUp(m_io.viewQuatFinal.GetColumn2() * vSpeed); weaponOffset += m_io.viewQuatFinal * Vec3(dotSide * -0.05f,dotFwd * -0.035f,dotUp * -0.05f); weaponAngleOffset.x += dotUp * 2.0f; weaponAngleOffset.y += dotSide * 5.0f; weaponAngleOffset.z -= dotSide * 2.0f; } } //add some inertia to weapon due view direction change. float deltaDotSide(m_io.vFPWeaponLastDirVec * m_io.viewQuatFinal.GetColumn0()); float deltaDotUp(m_io.vFPWeaponLastDirVec * m_io.viewQuatFinal.GetColumn2()); weaponOffset += m_io.viewQuatFinal * Vec3(deltaDotSide * 0.1f + m_in.stats_leanAmount * 0.05f,0,deltaDotUp * 0.1f - fabs(m_in.stats_leanAmount) * 0.05f) * m_in.params_weaponInertiaMultiplier; weaponAngleOffset.x -= deltaDotUp * 5.0f * m_in.params_weaponInertiaMultiplier; weaponAngleOffset.z += deltaDotSide * 5.0f * m_in.params_weaponInertiaMultiplier; weaponAngleOffset.y += deltaDotSide * 5.0f * m_in.params_weaponInertiaMultiplier; if(m_in.stats_leanAmount<0.0f) weaponAngleOffset.y += m_in.stats_leanAmount * 5.0f; //the weapon model tries to stay parallel to the terrain when the player is freefalling/parachuting if (m_in.stats_inWater > 0.0f) weaponOffset -= m_io.viewQuat.GetColumn2() * 0.15f; if (m_in.stats_inWater>0.1f && !m_in.stats_headUnderWater) { Ang3 offset(m_io.viewQuatFinal); offset.z = 0; if (offset.x<0.0f) offset.x = 0; weaponAngleOffset -= offset*(180.0f/gf_PI)*0.75f; } else if (m_io.stats_inFreefall) { Ang3 offset(m_io.viewQuatFinal); offset.z = 0; weaponAngleOffset -= offset*(180.0f/gf_PI)*0.5f; } //same thing with crawling else if (crawling) { //FIXME:to optimize, looks like a bit too expensive Vec3 forward(m_io.viewQuatFinal.GetColumn1()); Vec3 up(m_io.baseQuat.GetColumn2()); Vec3 right(-(up % forward)); Matrix33 mat; mat.SetFromVectors(right,up%right,up); mat.OrthonormalizeFast(); Ang3 offset(m_io.viewQuatFinal.GetInverted() * Quat(mat)); weaponAngleOffset += offset*(180.0f/gf_PI)*0.5f; float lookDown(m_io.viewQuatFinal.GetColumn1() * m_io.baseQuat.GetColumn2()); weaponOffset += m_io.baseQuat * Vec3(0,-0.5f*max(-lookDown,0.0f),-0.05f); float scale = 0.5f;; if(weaponAngleOffset.x>0.0f) { scale = min(0.5f,weaponAngleOffset.x/15.0f); weaponAngleOffset.x *= scale; } else { scale = min(0.5f,-weaponAngleOffset.x/20.0f); weaponAngleOffset *= (1.0f-scale); weaponOffset *= scale; } //if(vSpeedLen>0.1f) //weaponAngleOffset += Ang3(-8.0f,0,-12.5f); } else if (m_in.bSprinting && vSpeedLen>0.5f) { weaponAngleOffset += Ang3(-20.0f,0,10.0f); weaponOffset += m_io.viewQuatFinal * Vec3(0.0f, -.01f, .1f); } else if (m_in.bLookingAtFriendlyAI && !weaponZomming && !weaponZoomed) { weaponAngleOffset += Ang3(-15.0f,0,8.0f); weaponOffset += m_io.viewQuatFinal * Vec3(0.0f, -.01f, .05f); } //apply some multipliers weaponOffset *= m_in.params_weaponBobbingMultiplier; angOffset *= m_io.bobMul * 0.25f; if (m_io.bobMul*m_io.bobMul!=1.0f) { weaponOffset *= m_io.bobMul; weaponAngleOffset *= m_io.bobMul; } float bobSpeedMult(1.0f); if(m_in.stats_inWater>0.1) bobSpeedMult = 0.75f; // m_io.viewQuatForWeapon *= Quat::CreateRotationXYZ(Ang3(rx,ry,rz)); Interpolate(m_io.vFPWeaponOffset,weaponOffset,3.95f*bobSpeedMult,m_in.frameTime); Interpolate(m_io.vFPWeaponAngleOffset,weaponAngleOffset,10.0f*bobSpeedMult,m_in.frameTime); Interpolate(m_io.vFPWeaponLastDirVec,m_io.viewQuatFinal.GetColumn1(),5.0f*bobSpeedMult,m_in.frameTime); Interpolate(m_io.angleOffset,angOffset,10.0f,m_in.frameTime,0.002f); if(weaponZomming) { m_io.vFPWeaponLastDirVec = m_io.viewQuatFinal.GetColumn1(); m_io.vFPWeaponOffset.Set(0.0f,0.0f,0.0f); m_io.vFPWeaponAngleOffset.Set(0.0f,0.0f,0.0f); m_io.bobOffset.Set(0.0f,0.0f,0.0f); } if (m_in.bSprinting) { float headBobScale = (m_in.stats_flatSpeed / m_in.standSpeed); headBobScale = min(1.0f, headBobScale); m_io.bobOffset = m_io.vFPWeaponOffset * 2.5f * g_pGameCVars->cl_headBob * headBobScale; float bobLenSq = m_io.bobOffset.GetLengthSquared(); float bobLenLimit = g_pGameCVars->cl_headBobLimit; if (bobLenSq > bobLenLimit*bobLenLimit) { float bobLen = sqrt_tpl(bobLenSq); m_io.bobOffset *= bobLenLimit/bobLen; } viewParams.position += m_io.bobOffset; } }
void CPlayerView::ViewThirdPerson(SViewParams &viewParams) { if (m_in.thirdPersonYaw>0.001f) { viewParams.rotation *= Quat::CreateRotationXYZ(Ang3(0,0,m_in.thirdPersonYaw * gf_PI/180.0f)); m_io.viewQuatFinal = viewParams.rotation; } if (g_pGameCVars->goc_enable) { Vec3 target(g_pGameCVars->goc_targetx, g_pGameCVars->goc_targety, g_pGameCVars->goc_targetz); static Vec3 current(target); Interpolate(current, target, 5.0f, m_in.frameTime); // make sure we don't clip through stuff that much Vec3 offsetX(0,0,0); Vec3 offsetY(0,0,0); Vec3 offsetZ(0,0,0); offsetX = m_io.viewQuatFinal.GetColumn0() * current.x; offsetY = m_io.viewQuatFinal.GetColumn1() * current.y; offsetZ = m_io.viewQuatFinal.GetColumn2() * current.z; IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.entityId); if (pActor) { static ray_hit hit; IPhysicalEntity* pSkipEntities[10]; int nSkip = 0; IItem* pItem = pActor->GetCurrentItem(); if (pItem) { CWeapon* pWeapon = (CWeapon*)pItem->GetIWeapon(); if (pWeapon) nSkip = CSingle::GetSkipEntities(pWeapon, pSkipEntities, 10); } float oldLen = offsetY.len(); Vec3 start = m_io.baseQuat * m_io.eyeOffsetView + viewParams.position+offsetX+offsetZ; if (gEnv->pPhysicalWorld->RayWorldIntersection(start, offsetY, ent_static|ent_terrain|ent_rigid, rwi_ignore_noncolliding | rwi_stop_at_pierceable, &hit, 1, pSkipEntities, nSkip)) { offsetY = hit.pt - start; if (offsetY.len()> 0.25f) { offsetY -= offsetY.GetNormalized()*0.25f; } current.y = current.y * (hit.dist/oldLen); } } //viewParams.position += m_io.viewQuatFinal.GetColumn0() * current.x; // right //viewParams.position += m_io.viewQuatFinal.GetColumn1() * current.y; // back //viewParams.position += m_io.viewQuatFinal.GetColumn2() * current.z; // up viewParams.position += offsetX + offsetY + offsetZ; } else { if (m_io.bUsePivot) viewParams.position += m_io.viewQuatFinal.GetColumn1() * m_in.params_viewDistance + m_io.viewQuatFinal.GetColumn2() * (0.25f + m_in.params_viewHeightOffset); else { viewParams.position += m_io.viewQuatFinal.GetColumn1() * -m_in.thirdPersonDistance + m_io.viewQuatFinal.GetColumn2() * (0.25f + m_in.params_viewHeightOffset); } } }
void CPlayerView::ViewDeathCamTarget(SViewParams &viewParams) { CActor* pTarget = (CActor*)g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.stats_spectatorTarget); if(!pTarget) return; Matrix34 targetWorldTM = pTarget->GetEntity()->GetWorldTM(); Vec3 camPos = viewParams.position; static float offset = 1.5f; camPos.z += offset; float heightOffset = 1.5f; const SStanceInfo* pSI = pTarget->GetStanceInfo(pTarget->GetStance()); if(pSI) { heightOffset = pSI->viewOffset.z; } Vec3 targetPos = targetWorldTM.GetTranslation(); targetPos.z += heightOffset; int thisFrameId = gEnv->pRenderer->GetFrameID(); static int frameNo(thisFrameId); static Vec3 oldCamPos(camPos); static Vec3 oldTargetPos(targetPos); static EntityId lastSpectatorTarget(m_in.stats_spectatorTarget); static float oldFOVScale(1.0f); // if more than a few frames have passed since our last update, invalidate the positions if(thisFrameId - frameNo > 5) { oldCamPos = viewParams.position; // interpolate from current camera pos oldTargetPos = targetPos; oldFOVScale = 1.0f; } // if target changed, reset positions if(lastSpectatorTarget != m_in.stats_spectatorTarget) { oldCamPos = camPos; oldTargetPos = targetPos; lastSpectatorTarget = m_in.stats_spectatorTarget; oldFOVScale = 1.0f; } frameNo = thisFrameId; // slight zoom after 2s float timeNow = gEnv->pTimer->GetCurrTime(); float distSq = (targetPos - camPos).GetLengthSquared(); float scale = 1.0f; if(timeNow - m_in.deathTime > 1.0f && distSq > 2500.0f) { // 1.0f at 50m, 0.3f at 100m+ scale = 1.0f - (distSq - 2500.0f)/25000.0f; scale = CLAMP(scale, 0.3f, 1.0f); } Interpolate(oldCamPos, camPos, 5.0f, viewParams.frameTime); Interpolate(oldTargetPos, targetPos, 5.0f, viewParams.frameTime); Interpolate(oldFOVScale, scale, 0.5f, viewParams.frameTime); viewParams.position = oldCamPos; Vec3 dir = (oldTargetPos - oldCamPos).GetNormalizedSafe(); Matrix33 rotation = Matrix33::CreateRotationVDir(dir); dir.z = 0.0f; // quick ray check to make sure there's not a wall in the way... IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_in.entityId); if (pActor) { static ray_hit hit; IPhysicalEntity* pSkipEntities[10]; int nSkip = 0; IItem* pItem = pActor->GetCurrentItem(); if (pItem) { CWeapon* pWeapon = (CWeapon*)pItem->GetIWeapon(); if (pWeapon) nSkip = CSingle::GetSkipEntities(pWeapon, pSkipEntities, 10); } if (gEnv->pPhysicalWorld->RayWorldIntersection(viewParams.position, -dir, ent_static|ent_terrain|ent_rigid, rwi_ignore_noncolliding | rwi_stop_at_pierceable, &hit, 1, pSkipEntities, nSkip)) { dir.zero(); } } viewParams.position -= dir; viewParams.fov = m_in.defaultFov*oldFOVScale*(gf_PI/180.0f);; viewParams.rotation = GetQuatFromMat33(rotation); m_io.bUsePivot = true; m_io.stats_bobCycle = 0.0; }
//------------------------------------------------------------------------ bool CGameRules::OnPromoteToServer(SHostMigrationInfo& hostMigrationInfo, uint32& state) { if (!g_pGame->GetIGameFramework()->ShouldMigrateNub(hostMigrationInfo.m_session)) { return true; } CryLogAlways("[Host Migration]: CGameRules::OnPromoteToServer() started"); // Server time will change after we migrate (change from old server time to new server time) m_gameStartedTime.SetValue(m_gameStartedTime.GetValue() - m_cachedServerTime.GetValue()); m_gameStartTime.SetValue(m_gameStartTime.GetValue() - m_cachedServerTime.GetValue()); // If this migration has reset (we're not the original anticipated host, remove any entities from the first attempt if (!m_hostMigrationCachedEntities.empty()) { HostMigrationRemoveDuplicateDynamicEntities(); } // Now we know we're the server, remove the actors for anyone we know isn't going to migrate CGameLobby *pGameLobby = g_pGame->GetGameLobby(); CRY_ASSERT(pGameLobby); if (pGameLobby) { TPlayers playersToRemove; IActorSystem *pActorSystem = g_pGame->GetIGameFramework()->GetIActorSystem(); playersToRemove.reserve(pActorSystem->GetActorCount()); IActorIteratorPtr actorIt = pActorSystem->CreateActorIterator(); IActor *pActor; while (pActor = actorIt->Next()) { if (pActor->IsPlayer()) { CRY_ASSERT(pActor->GetChannelId()); SCryMatchMakingConnectionUID conId = pGameLobby->GetConnectionUIDFromChannelID((int) pActor->GetChannelId()); if (pGameLobby->GetSessionNames().Find(conId) == SSessionNames::k_unableToFind) { CryLog(" player '%s' has not got a corresponding CGameLobby entry, removing actor", pActor->GetEntity()->GetName()); playersToRemove.push_back(pActor->GetEntityId()); } } } const int numPlayersToRemove = playersToRemove.size(); for (int i = 0; i < numPlayersToRemove; ++ i) { FakeDisconnectPlayer(playersToRemove[i]); } } for (uint32 i = 0; i < MAX_PLAYERS; ++ i) { m_migratedPlayerChannels[i] = 0; } IItemSystem *pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); IEntityItPtr it = gEnv->pEntitySystem->GetEntityIterator(); it->MoveFirst(); for (uint32 i = 0; i < m_hostMigrationItemMaxCount; ++ i) { m_pHostMigrationItemInfo[i].Reset(); } uint32 itemIndex = 0; IEntity *pEntity = NULL; while (pEntity = it->Next()) { IItem *pItem = pItemSystem->GetItem(pEntity->GetId()); if (pItem) { if (pItem->GetOwnerId()) { IEntity *pOwner = gEnv->pEntitySystem->GetEntity(pItem->GetOwnerId()); if (pOwner) { EntityId currentItemId = 0; IActor *pOwnerActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pOwner->GetId()); if (pOwnerActor) { IItem *pCurrentItem = pOwnerActor->GetCurrentItem(); currentItemId = pCurrentItem ? pCurrentItem->GetEntityId() : 0; } CryLog("[CG] Item '%s' is owned by '%s'", pEntity->GetName(), pOwner->GetName()); //m_pHostMigrationItemInfo[itemIndex].Set(pEntity->GetId(), pOwner->GetId(), pItem->IsUsed(), (pItem->GetEntityId() == currentItemId)); itemIndex ++; if (itemIndex >= m_hostMigrationItemMaxCount) { CRY_ASSERT(itemIndex < m_hostMigrationItemMaxCount); break; } } } } // Tell entities that we're host migrating // - Currently only used by ForbiddenArea but may well be needed for other entities later // - Currently only called on the new server, add to OnDemoteToClient if we need to use this on a client IScriptTable *pScript = pEntity->GetScriptTable(); if (pScript != NULL && pScript->GetValueType("OnHostMigration") == svtFunction) { m_pScriptSystem->BeginCall(pScript, "OnHostMigration"); m_pScriptSystem->PushFuncParam(pScript); m_pScriptSystem->PushFuncParam(true); m_pScriptSystem->EndCall(); } } // This needs initialising on the new server otherwise the respawn timer will be counting down // from uninitialised data. Likewise for the pre-round timer. ResetReviveCycleTime(); const int numRespawnParams = m_respawndata.size(); for (int i = 0; i < numRespawnParams; ++ i) { SEntityRespawnData *pData = &m_respawndata[i]; pEntity = gEnv->pEntitySystem->GetEntity(pData->m_currentEntityId); if (pEntity == NULL) { CryLog(" detected respawn entity (id=%u) is not present, scheduling for respawn", pData->m_currentEntityId); ScheduleEntityRespawn(pData->m_currentEntityId, false, g_pGameCVars->g_defaultItemRespawnTimer); } } CryLog("[Host Migration]: CGameRules::OnPromoteToServer() finished"); CCCPOINT(HostMigration_OnPromoteToServer); return true; }
void CHUDCrosshair::UpdateCrosshair() { IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor(); if(!pClientActor) return; int iNewFriendly = 0; if(pClientActor->GetLinkedVehicle()) { // JanM/MichaelR: // Get status from the VehicleWeapon, which raycasts considering the necessary SkipEntities (in contrast to WorldQuery) // Julien: this is now done in MP as well iNewFriendly = g_pHUD->GetVehicleInterface()->GetFriendlyFire(); } else { if(!gEnv->bMultiplayer) { CWeapon *pWeapon = g_pHUD->GetCurrentWeapon(); if(pWeapon) { iNewFriendly = pWeapon->IsWeaponLowered() && pWeapon->IsPendingFireRequest(); if(iNewFriendly && pWeapon->GetEntity()->GetClass() == CItem::sTACGunFleetClass) iNewFriendly = 0; } else{ //Two handed pickups need the red X as well CPlayer *pPlayer= static_cast<CPlayer*>(pClientActor); if(CWeapon *pOffHand = static_cast<CWeapon*>(pPlayer->GetItemByClass(CItem::sOffHandClass))) iNewFriendly = pOffHand->IsWeaponLowered(); } } else { EntityId uiCenterId = pClientActor->GetGameObject()->GetWorldQuery()->GetLookAtEntityId(); if(uiCenterId) { iNewFriendly = IsFriendlyEntity(gEnv->pEntitySystem->GetEntity(uiCenterId)); } } } // SNH: if player is carrying a claymore or mine, ask the weapon whether it is possible to place it currently // (takes into account player speed / stance / aim direction). // So 'friendly' is a bit of a misnomer here, but we want the "don't/can't fire" crosshair... if(iNewFriendly != 1 && g_pHUD) { CWeapon *pWeapon = g_pHUD->GetCurrentWeapon(); if(pWeapon) { static IEntityClass* pClaymoreClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("Claymore"); static IEntityClass* pAVMineClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("AVMine"); IEntityClass* pClass = pWeapon->GetEntity()->GetClass(); if(pClass == pClaymoreClass || pClass == pAVMineClass) { if(IFireMode* pfm = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode())) { if(!pfm->IsFiring()) iNewFriendly = pWeapon->CanFire() ? 0 : 1; } } } } if(iNewFriendly != m_iFriendlyTarget) { m_iFriendlyTarget = iNewFriendly; //m_animCrossHair.Invoke("setFriendly", m_iFriendlyTarget); if(iNewFriendly) m_animFriendCross.SetVisible(true); else m_animFriendCross.SetVisible(false); } if(m_animInterActiveIcons.GetVisible()) { m_bHideUseIconTemp = false; CItem *pItem = static_cast<CItem*>(pClientActor->GetCurrentItem()); if(pItem) { IWeapon *pWeapon = pItem->GetIWeapon(); if(pWeapon) { CItem::SStats stats = pItem->GetStats(); if(stats.mounted && stats.used) m_bHideUseIconTemp = true; } } if(!m_bHideUseIconTemp) { EntityId offHandId = pClientActor->GetInventory()->GetItemByClass(CItem::sOffHandClass); IItem *pOffHandItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(offHandId); if(pOffHandItem) { COffHand *pOffHand = static_cast<COffHand*>(pOffHandItem); uint32 offHandState = pOffHand->GetOffHandState(); if(offHandState == eOHS_HOLDING_OBJECT || offHandState == eOHS_THROWING_OBJECT || offHandState == eOHS_HOLDING_NPC || offHandState == eOHS_THROWING_NPC) m_bHideUseIconTemp = true; } } } }