|
| 1 | +#include "stdafx.h" |
| 2 | + |
| 3 | +#include "AmebaZone.h" |
| 4 | +#include "ZoneVisual.h" |
| 5 | +#include "CustomZone.h" |
| 6 | +#include "xrEngine/xr_collide_form.h" |
| 7 | +#include "Include/xrRender/Kinematics.h" |
| 8 | +#include "PhysicsShellHolder.h" |
| 9 | +#include "PHMovementControl.h" |
| 10 | +#include "CharacterPhysicsSupport.h" |
| 11 | +#include "entity_alive.h" |
| 12 | + |
| 13 | + |
| 14 | +CAmebaZone::CAmebaZone() : m_fVelocityLimit(1.f) {} |
| 15 | + |
| 16 | +CAmebaZone::~CAmebaZone() {} |
| 17 | + |
| 18 | +void CAmebaZone::Load(LPCSTR section) |
| 19 | +{ |
| 20 | + inherited::Load(section); |
| 21 | + m_fVelocityLimit = pSettings->r_float(section, "max_velocity_in_zone"); |
| 22 | +} |
| 23 | + |
| 24 | +bool CAmebaZone::BlowoutState() |
| 25 | +{ |
| 26 | + bool result = inherited::BlowoutState(); |
| 27 | + if (!result) |
| 28 | + UpdateBlowout(); |
| 29 | + |
| 30 | + // XXX: use range-based for |
| 31 | + for (OBJECT_INFO_VEC::iterator it = m_ObjectInfoMap.begin(); m_ObjectInfoMap.end() != it; ++it) |
| 32 | + Affect(&(*it)); |
| 33 | + |
| 34 | + return result; |
| 35 | +} |
| 36 | + |
| 37 | +void CAmebaZone::Affect(SZoneObjectInfo* O) |
| 38 | +{ |
| 39 | + CPhysicsShellHolder* pGameObject = smart_cast<CPhysicsShellHolder*>(O->object); |
| 40 | + if (!pGameObject) return; |
| 41 | + |
| 42 | + if (O->zone_ignore) return; |
| 43 | + |
| 44 | + Fvector hit_dir; |
| 45 | + hit_dir.set(Random.randF(-.5f, .5f), |
| 46 | + Random.randF(.0f, 1.f), |
| 47 | + Random.randF(-.5f, .5f)); |
| 48 | + hit_dir.normalize(); |
| 49 | + |
| 50 | + Fvector position_in_bone_space; |
| 51 | + |
| 52 | + float power = Power(distance_to_center(O->object), m_fEffectiveRadius); |
| 53 | + float power_critical = 0.0f; |
| 54 | + float impulse = m_fHitImpulseScale * power * pGameObject->GetMass(); |
| 55 | + |
| 56 | + if (power > 0.01f) |
| 57 | + { |
| 58 | + //m_dwDeltaTime = 0; |
| 59 | + position_in_bone_space.set(0.f, 0.f, 0.f); |
| 60 | + |
| 61 | + CreateHit(pGameObject->ID(), ID(), hit_dir, power, 0, position_in_bone_space, impulse, m_eHitTypeBlowout); |
| 62 | + |
| 63 | + PlayHitParticles(pGameObject); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +void CAmebaZone::PhTune(float step) |
| 68 | +{ |
| 69 | + // XXX: use range-based for |
| 70 | + for (OBJECT_INFO_VEC::iterator it = m_ObjectInfoMap.begin(); m_ObjectInfoMap.end() != it; ++it) |
| 71 | + { |
| 72 | + CEntityAlive* EA = smart_cast<CEntityAlive*>((*it).object); |
| 73 | + if (EA) |
| 74 | + { |
| 75 | + CPHMovementControl* mc = EA->character_physics_support()->movement(); |
| 76 | + if (mc) |
| 77 | + { |
| 78 | + if (distance_to_center(EA) < effective_radius(m_fEffectiveRadius)) |
| 79 | + mc->SetVelocityLimit(m_fVelocityLimit); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +void CAmebaZone::SwitchZoneState(EZoneState new_state) |
| 86 | +{ |
| 87 | + if (new_state == eZoneStateBlowout && m_eZoneState != eZoneStateBlowout) |
| 88 | + Activate(); |
| 89 | + |
| 90 | + if (new_state != eZoneStateBlowout && m_eZoneState == eZoneStateBlowout) |
| 91 | + Deactivate(); |
| 92 | + |
| 93 | + inherited::SwitchZoneState(new_state); |
| 94 | +} |
| 95 | + |
| 96 | +float CAmebaZone::distance_to_center(CGameObject* O) |
| 97 | +{ |
| 98 | + Fvector P; |
| 99 | + XFORM().transform_tiny(P, CForm->getSphere().P); |
| 100 | + Fvector OP; |
| 101 | + OP.set(O->Position()); |
| 102 | + return _sqrt((P.x - OP.x) * (P.x - OP.x) + (P.x - OP.x) * (P.x - OP.x)); |
| 103 | +} |
0 commit comments