void CSpammer::UpdateLoadIn(float frameTime) { const int currentAmmoCount = GetAmmoCount(); const bool infiniteAmmo = (GetClipSize() < 0); if ((!infiniteAmmo) && (m_numLoadedRockets >= currentAmmoCount)) { GetWeapon()->PlayAction(GetFragmentIds().empty_clip); StopFire(); return; } const SSpammerParams& params = GetShared()->spammerParams; const float loadInTime = 1.0f / (params.loadInRate / 60.0f); m_timer -= frameTime; while (m_timer < 0.0f && m_numLoadedRockets < params.maxNumRockets) { m_timer += loadInTime; AddTarget(); GetWeapon()->PlayAction(GetFragmentIds().c**k); } if (m_numLoadedRockets != m_targetsAssigned.GetNumLockOns()) { EntityId nextTarget = GetNextLockOnTarget(); if (nextTarget != 0) m_targetsAssigned.LockOn(nextTarget); } }
GDALDataset* GDALProxyPoolDataset::RefUnderlyingDataset() { /* We pretend that the current thread is responsiblePID, that is */ /* to say the thread that created that GDALProxyPoolDataset object. */ /* This is for the case when a GDALProxyPoolDataset is created by a */ /* thread and used by other threads. These other threads, when doing actual */ /* IO, will come there and potentially open the underlying dataset. */ /* By doing this, they can indirectly call GDALOpenShared() on .aux file */ /* for example. So this call to GDALOpenShared() must occur as if it */ /* was done by the creating thread, otherwise it will not be correctly closed afterwards... */ /* To make a long story short : this is necessary when warping with ChunkAndWarpMulti */ /* a VRT of GeoTIFFs that have associated .aux files */ GIntBig curResponsiblePID = GDALGetResponsiblePIDForCurrentThread(); GDALSetResponsiblePIDForCurrentThread(responsiblePID); cacheEntry = GDALDatasetPool::RefDataset(GetDescription(), eAccess, papszOpenOptions, GetShared()); GDALSetResponsiblePIDForCurrentThread(curResponsiblePID); if (cacheEntry != NULL) { if (cacheEntry->poDS != NULL) return cacheEntry->poDS; else GDALDatasetPool::UnrefDataset(cacheEntry); } return NULL; }
NetworkID GameFactory::DestroyInstance(FactoryObject& reference) { Reference* _reference = reference.reference; if (!_reference) throw VaultException("GameFactory::DestroyInstance Reference is NULL"); NetworkID id = _reference->GetNetworkID(); #ifdef VAULTMP_DEBUG if (debug) debug->PrintFormat("Reference %08X with base %08X and NetworkID %llu (type: %s) to be destructed", true, _reference->GetReference(), _reference->GetBase(), _reference->GetNetworkID(), typeid(*_reference).name()); #endif cs.StartSession(); ReferenceList::iterator it = GetShared(_reference); --typecount[it->second]; _reference->Finalize(); instances.erase(it); cs.EndSession(); reference.reference = nullptr; reference.type = 0x00; return id; }
void CAutomaticShotgun::StartFire() { if (!m_firing && !m_firePending && GetShared()->shotgunparams.fully_automated) { m_rapidFireCountdown = m_next_shot_dt; m_firing = true; } CShotgun::StartFire(); }
void CSpammer::StartLoadingIn() { m_state = EState_LoadingIn; m_timer = 0.0f; m_targetsAssigned.Clear(); m_numLoadedRockets = 0; const SFireModeParams& params = *GetShared(); m_nextFireTimer = 1.0f / (params.fireparams.rate / 60.0f); }
void EntityComponent::OnRemove() { FunctionObject *pFunc = GetShared()->GetFunctionIfExists("OnDelete"); if (pFunc) { //looks like someone wanted notification VariantList vList(this); pFunc->m_sig_function(&vList); } }
void InterpolateComponent::SetEndValue() { if (m_pVar) { Variant *pV = GetShared()->GetVarIfExists("set_value_on_finish"); if (pV) { m_pVar->Set(*pV); } } }
void CBurst::NetStartFire() { IEntityClass* ammo = GetShared()->fireparams.ammo_type_class; int ammoCount = m_pWeapon->GetAmmoCount(ammo); m_pWeapon->PlayAction( GetFragmentIds().burst_fire, 0, false, CItem::eIPAF_Default, -1.0f, GetFireAnimationWeight(), GetFireFFeedbackWeight()); }
//------------------------------------------------------------------------ void CBurst::StartFire() { if (!m_bursting && !m_fireTriggerDown) { m_fireTriggerDown = true; if (m_next_burst <= 0.0f) { CSingle::StartFire(); if(m_fired) //Only set if first shot was successful { IEntityClass* ammo = GetShared()->fireparams.ammo_type_class; // We need to add 1, because Single decreased one the ammo count already int ammoCount = (m_pWeapon->GetAmmoCount(ammo) + 1); const CTagDefinition* pTagDefinition = NULL; int fragmentID = m_pWeapon->GetFragmentID("burst_fire", &pTagDefinition); if (fragmentID != FRAGMENT_ID_INVALID) { TagState actionTags = TAG_STATE_EMPTY; if(pTagDefinition) { CTagState fragTags(*pTagDefinition); m_pWeapon->SetAmmoCountFragmentTags(fragTags, ammoCount); actionTags = fragTags.GetMask(); } CBurstFireAction* pAction = new CBurstFireAction(PP_PlayerAction, fragmentID, this, actionTags); if(m_fireParams->burstparams.useBurstSoundParam) { float param = 0.f; int burstLength = m_fireParams->burstparams.nshots; param = (float)min(burstLength, ammoCount); pAction->SetParam(CItem::sActionParamCRCs.burstFire, param); } m_pWeapon->PlayFragment(pAction, -1.f, -1.f, GetFireAnimationWeight(), GetFireFFeedbackWeight(), false); } m_next_burst = m_next_burst_dt; m_bursting = true; m_pWeapon->SetItemFlag(CItem::eIF_BlockActions, true); } } } }
unsigned char GameFactory::GetType(const Reference* reference) noexcept { ReferenceList::iterator it; cs.StartSession(); unsigned char type; it = GetShared(reference); type = (it != instances.end() ? it->second : 0x00); cs.EndSession(); return type; }
void CSpammer::UpdateBurst(float frameTime) { const SSpammerParams& params = GetShared()->spammerParams; const float burstTime = 1.0f / (params.burstRate / 60.0f); m_timer -= frameTime; while (m_timer < 0.0f && m_numLoadedRockets != 0) { m_timer += burstTime; --m_numLoadedRockets; ShootNextTarget(); } if (m_numLoadedRockets == 0) m_state = EState_None; }
FactoryObject GameFactory::GetObject(NetworkID id) { Reference* reference; unsigned char type; cs.StartSession(); reference = Network::Manager()->GET_OBJECT_FROM_ID<Reference*>(id); if (reference) type = GetShared(reference)->second; cs.EndSession(); if (!reference) throw VaultException("Unknown object with NetworkID %llu", id); return FactoryObject(reference, type); }
void InterpolateComponent::OnAdd(Entity *pEnt) { EntityComponent::OnAdd(pEnt); //if game is currently paused, assuming we should use a system timer so we don't pause with it m_pTimingSystem = &GetVarWithDefault("timingSystem", Variant(uint32(GetBaseApp()->GetActiveTimingSystem())))->GetUINT32(); m_pVarName = &GetVar("var_name")->GetString(); //local to us m_pDuration = &GetVar("duration_ms")->GetUINT32(); m_pDeleteAfterPlayCount = &GetVar("deleteAfterPlayCount")->GetUINT32(); m_pPlayCount = &GetVar("playCount")->GetUINT32(); m_pOnFinish = &GetVarWithDefault("on_finish", Variant( uint32(ON_FINISH_DIE)))->GetUINT32(); m_pInterpolateType = &GetVarWithDefault("interpolation", Variant( uint32(INTERPOLATE_LINEAR)))->GetUINT32(); m_pVarTarget = GetVar("target"); m_pComponentName = &GetShared()->GetVar("component_name")->GetString(); GetVar("var_name")->GetSigOnChanged()->connect(1, boost::bind(&InterpolateComponent::OnVarNameChanged, this, _1)); GetVar("duration_ms")->GetSigOnChanged()->connect(1, boost::bind(&InterpolateComponent::OnDurationChanged, this, _1)); //register to get updated every frame, assuming our entity gets an OnUpdate call GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&InterpolateComponent::OnUpdate, this, _1)); }
vector<FactoryObject> GameFactory::GetMultiple(const vector<NetworkID>& objects) { vector<FactoryObject> result(objects.size()); multimap<ReferenceList::value_type, unsigned int> sort; cs.StartSession(); try { unsigned int i = 0; for (const auto& id : objects) { Reference* reference = Network::Manager()->GET_OBJECT_FROM_ID<Reference*>(id); if (!reference) throw VaultException("Unknown object with NetworkID %llu", id); // emplace sort.insert(make_pair(*GetShared(reference), i)); ++i; } } catch (...) { cs.EndSession(); throw; } cs.EndSession(); for (const auto& reference : sort) result[reference.second] = FactoryObject(reference.first.first.get(), reference.first.second); return result; }
//Note: this is here for compatibility. All damage by explosions is // handled server-side float CPlant::GetDamageAmountAtXMeters(float x) { return (float)GetShared()->plantparams.damage; }
void CSpammer::StartBursting() { const SSpammerParams& params = GetShared()->spammerParams; m_timer = 1.0f / (params.burstRate / 60.0f); m_state = EState_Bursting; }
bool CShotgun::Shoot(bool resetAnimation, bool autoreload/* =true */, bool isRemote) { CCCPOINT(Shotgun_TryShoot); m_firePending = false; m_shotIndex++; IEntityClass* ammo = m_fireParams->fireparams.ammo_type_class; int ammoCount = m_pWeapon->GetAmmoCount(ammo); int clipSize = GetClipSize(); if (clipSize == 0) ammoCount = m_pWeapon->GetInventoryAmmoCount(ammo); CActor *pActor = m_pWeapon->GetOwnerActor(); bool playerIsShooter = pActor ? pActor->IsPlayer() : false; bool shooterIsClient = pActor ? pActor->IsClient() : false; if (!CanFire(true)) { if ((ammoCount <= 0) && (!m_reloading)) { m_pWeapon->PlayAction(GetFragmentIds().empty_clip); m_pWeapon->OnFireWhenOutOfAmmo(); CCCPOINT(Shotgun_TryShootWhileOutOfAmmo); } else { CCCPOINT(Shotgun_TryShootWhileCannotBeFired); } return false; } if (m_reloading) { if(m_pWeapon->IsBusy()) m_pWeapon->SetBusy(false); if(CanFire(true) && !m_break_reload) { m_break_reload = true; m_pWeapon->RequestCancelReload(); } CCCPOINT(Shotgun_TryShootWhileReloading); return false; } uint32 flags = CItem::eIPAF_Default; if (IsProceduralRecoilEnabled() && pActor) { pActor->ProceduralRecoil(m_fireParams->proceduralRecoilParams.duration, m_fireParams->proceduralRecoilParams.strength, m_fireParams->proceduralRecoilParams.kickIn, m_fireParams->proceduralRecoilParams.arms); } float speedOverride = -1.f; m_pWeapon->PlayAction(GetFragmentIds().fire, 0, false, flags, speedOverride); Vec3 hit = GetProbableHit(WEAPON_HIT_RANGE); Vec3 pos = GetFiringPos(hit); Vec3 fdir = GetFiringDir(hit, pos); Vec3 vel = GetFiringVelocity(fdir); Vec3 dir; const float hitDist = hit.GetDistance(pos); CheckNearMisses(hit, pos, fdir, WEAPON_HIT_RANGE, m_fireParams->shotgunparams.spread); CRY_ASSERT_MESSAGE(m_fireParams->fireparams.hitTypeId, string().Format("Invalid hit type '%s' in fire params for '%s'", m_fireParams->fireparams.hit_type.c_str(), m_pWeapon->GetEntity()->GetName())); CRY_ASSERT_MESSAGE(m_fireParams->fireparams.hitTypeId == g_pGame->GetGameRules()->GetHitTypeId(m_fireParams->fireparams.hit_type.c_str()), "Sanity Check Failed: Stored hit type id does not match the type string, possibly CacheResources wasn't called on this weapon type"); int quad = cry_random(0, 3); const int numPellets = m_fireParams->shotgunparams.pellets; std::vector<CProjectile*> projList; projList.reserve(numPellets); int ammoCost = (m_fireParams->fireparams.fake_fire_rate && playerIsShooter) ? m_fireParams->fireparams.fake_fire_rate : 1; ammoCost = min(ammoCost, ammoCount); EntityId firstAmmoId = 0; // SHOT HERE for (int i = 0; i < numPellets; i++) { CProjectile *pAmmo = m_pWeapon->SpawnAmmo(m_fireParams->fireparams.spawn_ammo_class, false); if (pAmmo) { if(!firstAmmoId) { firstAmmoId = pAmmo->GetEntityId(); } projList.push_back(pAmmo); dir = ApplySpread(fdir, m_fireParams->shotgunparams.spread, quad); quad = (quad+1)%4; int pelletDamage = m_fireParams->shotgunparams.pelletdamage; if (!playerIsShooter) pelletDamage += m_fireParams->shotgunparams.npc_additional_damage; const bool canOvercharge = m_pWeapon->GetSharedItemParams()->params.can_overcharge; const float overchargeModifier = pActor ? pActor->GetOverchargeDamageScale() : 1.0f; if (canOvercharge) { pelletDamage = int(pelletDamage * overchargeModifier); } CProjectile::SProjectileDesc projectileDesc( m_pWeapon->GetOwnerId(), m_pWeapon->GetHostId(), m_pWeapon->GetEntityId(), pelletDamage, m_fireParams->fireparams.damage_drop_min_distance, m_fireParams->fireparams.damage_drop_per_meter, m_fireParams->fireparams.damage_drop_min_damage, m_fireParams->fireparams.hitTypeId, m_fireParams->fireparams.bullet_pierceability_modifier, m_pWeapon->IsZoomed()); projectileDesc.pointBlankAmount = m_fireParams->fireparams.point_blank_amount; projectileDesc.pointBlankDistance = m_fireParams->fireparams.point_blank_distance; projectileDesc.pointBlankFalloffDistance = m_fireParams->fireparams.point_blank_falloff_distance; if (m_fireParams->fireparams.ignore_damage_falloff) projectileDesc.damageFallOffAmount = 0.0f; const Vec3 pelletDestination = pos + (dir * hitDist); pAmmo->SetParams(projectileDesc); pAmmo->SetDestination(m_pWeapon->GetDestination()); pAmmo->Launch(pos, dir, vel); pAmmo->CreateBulletTrail( pelletDestination ); pAmmo->SetKnocksTargetInfo( GetShared() ); if ((!m_fireParams->tracerparams.geometry.empty() || !m_fireParams->tracerparams.effect.empty()) && ((ammoCount == clipSize) || (ammoCount%m_fireParams->tracerparams.frequency==0))) { EmitTracer(pos, pelletDestination, &m_fireParams->tracerparams, pAmmo); } if(shooterIsClient) { pAmmo->RegisterLinkedProjectile(m_shotIndex); if(gEnv->bMultiplayer) { float damageCap = g_pGameCVars->pl_shotgunDamageCap; pAmmo->SetDamageCap(damageCap); } } m_projectileId = pAmmo->GetEntity()->GetId(); pAmmo->SetAmmoCost(ammoCost); } } if (m_pWeapon->IsServer()) { const char *ammoName = ammo != NULL ? ammo->GetName() : NULL; g_pGame->GetIGameFramework()->GetIGameplayRecorder()->Event(m_pWeapon->GetOwner(), GameplayEvent(eGE_WeaponShot, ammoName, m_fireParams->shotgunparams.pellets, (void *)(EXPAND_PTR)m_pWeapon->GetEntityId())); } m_muzzleEffect.Shoot(this, hit, m_barrelId); m_fired = true; SetNextShotTime(m_next_shot + m_next_shot_dt); ammoCount -= ammoCost; if (ammoCount < m_fireParams->fireparams.minimum_ammo_count) ammoCount = 0; if (clipSize != -1) { if (clipSize != 0) m_pWeapon->SetAmmoCount(ammo, ammoCount); else m_pWeapon->SetInventoryAmmoCount(ammo, ammoCount); } OnShoot(m_pWeapon->GetOwnerId(), firstAmmoId, ammo, pos, dir, vel); const SThermalVisionParams& thermalParams = m_fireParams->thermalVisionParams; m_pWeapon->AddShootHeatPulse(pActor, thermalParams.weapon_shootHeatPulse, thermalParams.weapon_shootHeatPulseTime, thermalParams.owner_shootHeatPulse, thermalParams.owner_shootHeatPulseTime); if (OutOfAmmo()) { m_pWeapon->OnOutOfAmmo(ammo); if (autoreload) { uint32 scheduleTime = max(m_pWeapon->GetCurrentAnimationTime(eIGS_Owner), (uint)(m_next_shot*1000)); m_pWeapon->GetScheduler()->TimerAction(scheduleTime, CSchedulerAction<ScheduleReload>::Create(ScheduleReload(this, m_pWeapon)), false); m_autoReloading = true; } } m_pWeapon->RequestShoot(ammo, pos, dir, vel, hit, 1.0f, 0, false); #if defined(ANTI_CHEAT) const int numProjectiles = projList.size(); uint32 shotId = m_pWeapon->GetLastShotId(); for(int i = 0; i < numProjectiles; i++) { CProjectile * pAmmo = projList[i]; pAmmo->SetShotId(shotId); shotId -= (1 << CWeapon::GetShotIdCountOffset()); } #endif CCCPOINT(Shotgun_Fired); return true; }