Skip to content

Commit 272feb3

Browse files
committed
-
1 parent 6db6ea1 commit 272feb3

22 files changed

Lines changed: 208 additions & 53 deletions

gamedata/entities/weapons.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"base_hit_range": 1.1,
5656
"base_fire_rate": 15.0,
5757
"base_ammo_limit": 999,
58-
"base_damage": 3,
58+
"base_damage": 4,
5959

6060
"hud_sprite": 33
6161
},

src/Decoration.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ class Decoration final: public GameObject
66
{
77
friend class GameObjectsManager;
88

9-
// add runtime information support for gameobject
10-
decl_rtti(Decoration, GameObject)
11-
129
public:
1310
Decoration(GameObjectID id, GameObjectStyle* desc);
1411
~Decoration();

src/Explosion.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#include "Explosion.h"
33
#include "TimeManager.h"
44
#include "SpriteManager.h"
5+
#include "DebugRenderer.h"
6+
#include "PhysicsManager.h"
7+
#include "Pedestrian.h"
8+
#include "Vehicle.h"
59

610
Explosion::Explosion(GameObjectID id)
711
: GameObject(eGameObjectClass_Explosion, id)
@@ -25,6 +29,11 @@ void Explosion::UpdateFrame()
2529
mDrawSprite.SetOriginToCenter();
2630
}
2731

32+
if (!IsDamageDone())
33+
{
34+
ProcessDamage();
35+
}
36+
2837
if (!mAnimationState.IsAnimationActive())
2938
{
3039
MarkForDeletion();
@@ -33,6 +42,11 @@ void Explosion::UpdateFrame()
3342

3443
void Explosion::DrawDebug(DebugRenderer& debugRender)
3544
{
45+
float damageRadiusA = gGameParams.mExplosionPrimaryDamageDistance;
46+
float damageRadiusB = gGameParams.mExplosionSecondaryDamageDistance;
47+
48+
debugRender.DrawSphere(mExplosionEpicentre, damageRadiusA, Color32_Red, false);
49+
debugRender.DrawSphere(mExplosionEpicentre, damageRadiusB, Color32_Yellow, false);
3650
}
3751

3852
void Explosion::Spawn(const glm::vec3& startPosition)
@@ -53,4 +67,54 @@ void Explosion::Spawn(const glm::vec3& startPosition)
5367
debug_assert(false);
5468
}
5569
mDrawSprite.SetOriginToCenter();
56-
}
70+
71+
mExplosionEpicentre = startPosition;
72+
}
73+
74+
bool Explosion::IsDamageDone() const
75+
{
76+
return mDamageDone;
77+
}
78+
79+
void Explosion::ProcessDamage()
80+
{
81+
float maxImpactRadius = gGameParams.mExplosionPrimaryDamageDistance;
82+
float minImpactRadius = gGameParams.mExplosionSecondaryDamageDistance;
83+
84+
float impactRadius = std::max(maxImpactRadius, minImpactRadius);
85+
86+
glm::vec2 centerPoint (mExplosionEpicentre.x, mExplosionEpicentre.z);
87+
glm::vec2 extents (
88+
impactRadius,
89+
impactRadius
90+
);
91+
92+
// single shot
93+
mDamageDone = true;
94+
95+
// todo: fix distance to target
96+
PhysicsQueryResult queryResult;
97+
gPhysics.QueryObjectsWithinBox(centerPoint, extents, queryResult);
98+
99+
if (queryResult.IsNull())
100+
return;
101+
102+
for (int icurr = 0; icurr < queryResult.mElementsCount; ++icurr)
103+
{
104+
PhysicsQueryElement& currElement = queryResult.mElements[icurr];
105+
106+
if (CarPhysicsBody* carPhysics = currElement.mCarComponent)
107+
{
108+
// todo: temporary implementation
109+
carPhysics->mReferenceCar->ReceiveDamage(gGameParams.mExplosionPrimaryDamage);
110+
continue;
111+
}
112+
113+
if (PedPhysicsBody* pedPhysics = currElement.mPedComponent)
114+
{
115+
// todo: temporary implementation
116+
pedPhysics->mReferencePed->ReceiveDamageFromExplosion(this);
117+
continue;
118+
}
119+
}
120+
}

src/Explosion.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
class Explosion final: public GameObject
66
{
77
friend class GameObjectsManager;
8-
9-
// add runtime information support for gameobject
10-
decl_rtti(Explosion, GameObject)
11-
8+
129
public:
1310
Explosion(GameObjectID id);
1411
~Explosion();
@@ -21,6 +18,14 @@ class Explosion final: public GameObject
2118
// Setup initial state when spawned or respawned on level
2219
void Spawn(const glm::vec3& startPosition);
2320

21+
// Test whether explosion did its damage and can't hurt
22+
bool IsDamageDone() const;
23+
24+
private:
25+
void ProcessDamage();
26+
2427
private:
2528
SpriteAnimation mAnimationState;
29+
glm::vec3 mExplosionEpicentre;
30+
bool mDamageDone = false;
2631
};

src/GameObject.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class GameObject: public cxx::noncopyable
1010
friend class GameObjectsManager;
1111
friend class MapRenderer;
1212

13-
// add runtime information support for gameobject
14-
decl_rtti_base(GameObject)
15-
1613
public:
1714
const GameObjectID mObjectID; // its unique for all game objects except projectiles or effects, see GAMEOBJECT_ID_NULL
1815
const eGameObjectClass mObjectTypeID;

src/GameObjectsManager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ void GameObjectsManager::UpdateFrame()
4343

4444
// if is safe to add new objects during loop by adding them to the end of the list
4545

46-
const size_t allObjectsCount = mAllObjectsList.size();
47-
for (size_t iobject = 0; iobject < allObjectsCount; ++iobject)
46+
for (size_t i = 0, NumElements = mAllObjectsList.size(); i < NumElements; ++i)
4847
{
49-
GameObject* currentObject = mAllObjectsList[iobject];
48+
GameObject* currentObject = mAllObjectsList[i];
5049
currentObject->UpdateFrame();
5150
}
5251
}

src/GameParams.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ GameParams::GameParams()
1010

1111
void GameParams::SetToDefaults()
1212
{
13+
// todo: move to config
14+
15+
// pedestrians
1316
mPedestrianBoundsSphereRadius = Convert::MapUnitsToMeters(0.10f);
1417
mPedestrianTurnSpeed = 260.0f;
1518
mPedestrianTurnSpeedSlideOnCar = 120.0f;
@@ -20,4 +23,9 @@ void GameParams::SetToDefaults()
2023
mPedestrianKnockedDownTime = 3.0f;
2124
mPedestrianFallDeathHeight = Convert::MapUnitsToMeters(2.0f);
2225
mPedestrianDrowningTime = 0.05f;
26+
// etc
27+
mExplosionPrimaryDamageDistance = Convert::MapUnitsToMeters(0.7f);
28+
mExplosionSecondaryDamageDistance = Convert::MapUnitsToMeters(1.2f);
29+
mExplosionPrimaryDamage = 100;
30+
mExplosionSecondaryDamage = 20;
2331
}

src/GameParams.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class GameParams
2323
float mPedestrianSpotTheCarDistance; // max distance to detect the car, meters
2424
float mPedestrianFallDeathHeight; // falling distance which causes pedestrian death, meters
2525
float mPedestrianDrowningTime; // seconds
26+
27+
// etc
28+
float mExplosionPrimaryDamageDistance; // how far explosion can do maximum damage, meters
29+
float mExplosionSecondaryDamageDistance; // how far explosion can do significant damage, meters
30+
int mExplosionPrimaryDamage; // hit points to injure at Primary Damage Distance
31+
int mExplosionSecondaryDamage; // hit points to injure at Secondary Damage Distance
32+
2633
};
2734

2835
extern GameParams gGameParams;

src/Obstacle.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ class Obstacle final: public GameObject
66
{
77
friend class GameObjectsManager;
88

9-
// add runtime information support for gameobject
10-
decl_rtti(Obstacle, GameObject)
11-
129
public:
1310
Obstacle(GameObjectID id, GameObjectStyle* desc);
1411
~Obstacle();

src/Pedestrian.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ void Pedestrian::EnterCar(Vehicle* targetCar, eCarSeat targetSeat)
209209
debug_assert(targetSeat != eCarSeat_Any);
210210
debug_assert(targetCar);
211211

212+
if (targetCar->IsWrecked())
213+
return;
214+
212215
if (IsIdle())
213216
{
214217
PedestrianStateEvent evData { ePedestrianStateEvent_EnterCar };
@@ -227,11 +230,13 @@ void Pedestrian::ExitCar()
227230
}
228231
}
229232

230-
void Pedestrian::ReceiveDamage(eWeaponID weapon, Pedestrian* attacker)
233+
void Pedestrian::ReceiveDamage(WeaponInfo* weapon, Pedestrian* attacker)
231234
{
235+
debug_assert(weapon);
236+
232237
PedestrianStateEvent evData { ePedestrianStateEvent_DamageFromWeapon };
233238
evData.mAttacker = attacker;
234-
evData.mWeaponType = weapon;
239+
evData.mWeapon = weapon;
235240
mStatesManager.ProcessEvent(evData);
236241
}
237242

@@ -371,9 +376,11 @@ void Pedestrian::SetDead(ePedestrianDeathReason deathReason)
371376
}
372377
}
373378

374-
void Pedestrian::ReceiveHitByCar(Vehicle* targetCar, float impulse)
379+
void Pedestrian::ReceiveDamageFromCar(Vehicle* targetCar, float impulse)
375380
{
376-
debug_assert(targetCar);
381+
debug_assert(targetCar);
382+
383+
// todo: hit processing logic should be moved to states manager !
377384

378385
if (IsDead())
379386
return;
@@ -408,3 +415,13 @@ void Pedestrian::ReceiveHitByCar(Vehicle* targetCar, float impulse)
408415
}
409416
}
410417

418+
void Pedestrian::ReceiveDamageFromExplosion(Explosion* explosion)
419+
{
420+
// todo: hit processing logic should be moved to states manager !
421+
422+
if (IsDead())
423+
return;
424+
425+
Die(ePedestrianDeathReason_BlownUp, nullptr);
426+
}
427+

0 commit comments

Comments
 (0)