summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Boat.cpp38
-rw-r--r--src/Entities/Boat.h23
-rw-r--r--src/Entities/Entity.cpp22
-rw-r--r--src/Entities/Entity.h3
4 files changed, 83 insertions, 3 deletions
diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp
index e81e57529..330e54740 100644
--- a/src/Entities/Boat.cpp
+++ b/src/Entities/Boat.cpp
@@ -14,7 +14,10 @@
cBoat::cBoat(double a_X, double a_Y, double a_Z) :
- super(etBoat, a_X, a_Y, a_Z, 0.98, 0.7)
+ super(etBoat, a_X, a_Y, a_Z, 0.98, 0.7),
+ m_LastDamage(0), m_ForwardDirection(0),
+ m_DamageTaken(0.0f), m_Type(0),
+ m_RightPaddleUsed(false), m_LeftPaddleUsed(false)
{
SetMass(20.0f);
SetGravity(-16.0f);
@@ -37,12 +40,15 @@ void cBoat::SpawnOn(cClientHandle & a_ClientHandle)
bool cBoat::DoTakeDamage(TakeDamageInfo & TDI)
{
+ m_LastDamage = 10;
if (!super::DoTakeDamage(TDI))
{
return false;
}
- if (GetHealth() == 0)
+ m_World->BroadcastEntityMetadata(*this);
+
+ if (GetHealth() <= 0)
{
if (TDI.Attacker != nullptr)
{
@@ -112,6 +118,14 @@ void cBoat::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
AddSpeedY(0.2);
}
}
+
+ if (GetLastDamage() > 0)
+ {
+ SetLastDamage(GetLastDamage() - 1);
+ }
+
+ // Broadcast any changes in position
+ m_World->BroadcastEntityMetadata(*this);
}
@@ -130,3 +144,23 @@ void cBoat::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
AddSpeed(ToAddSpeed);
}
+
+
+
+
+void cBoat::SetLastDamage(int TimeSinceLastHit)
+{
+ m_LastDamage = TimeSinceLastHit;
+}
+
+
+
+
+
+void cBoat::UpdatePaddles(bool a_RightPaddleUsed, bool a_LeftPaddleUsed)
+{
+ m_RightPaddleUsed = a_RightPaddleUsed;
+ m_LeftPaddleUsed = a_LeftPaddleUsed;
+
+ m_World->BroadcastEntityMetadata(*this);
+}
diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h
index d168f5072..5815ff88c 100644
--- a/src/Entities/Boat.h
+++ b/src/Entities/Boat.h
@@ -31,8 +31,29 @@ public:
virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override;
cBoat(double a_X, double a_Y, double a_Z);
-} ;
+ int GetLastDamage(void) const { return m_LastDamage; }
+ int GetForwardDirection(void) const { return m_ForwardDirection; }
+
+ float GetDamageTaken(void) const { return m_DamageTaken; }
+
+ int GetType(void) const { return m_Type; }
+
+ bool IsRightPaddleUsed(void) const { return m_RightPaddleUsed; }
+ bool IsLeftPaddleUsed(void) const { return m_LeftPaddleUsed; }
+ void SetLastDamage(int TimeSinceLastHit);
+ void UpdatePaddles(bool rightPaddleUsed, bool leftPaddleUsed);
+private:
+ int m_LastDamage;
+ int m_ForwardDirection;
+
+ float m_DamageTaken;
+
+ int m_Type;
+
+ bool m_RightPaddleUsed;
+ bool m_LeftPaddleUsed;
+} ;
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 6e1dec957..98be99a27 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1038,6 +1038,20 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
NextSpeed -= NextSpeed * (m_AirDrag * 20.0f) * DtSec.count();
}
NextSpeed.y += static_cast<float>(fallspeed);
+
+ // A real boat floats
+ if (IsBoat())
+ {
+ // Find top water block and sit there
+ int NextBlockY = BlockY;
+ BLOCKTYPE NextBlock = NextChunk->GetBlock(RelBlockX, NextBlockY, RelBlockZ);
+ while (IsBlockWater(NextBlock))
+ {
+ NextBlock = NextChunk->GetBlock(RelBlockX, ++NextBlockY, RelBlockZ);
+ }
+ NextPos.y = NextBlockY - 0.5;
+ NextSpeed.y = 0;
+ }
}
else
{
@@ -1913,6 +1927,14 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
+cEntity * cEntity::GetAttached()
+{
+ return m_AttachedTo;
+}
+
+
+
+
void cEntity::AttachTo(cEntity * a_AttachTo)
{
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index b00201f3a..6923795db 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -421,6 +421,9 @@ public:
/** Updates clients of changes in the entity. */
virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr);
+ /** Gets entity (vehicle) attached to this entity */
+ cEntity * GetAttached();
+
/** Attaches to the specified entity; detaches from any previous one first */
void AttachTo(cEntity * a_AttachTo);