From 37069288d5801acce0ad34878a78aa0daf004135 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 14 Dec 2013 18:03:00 +0100 Subject: Added SendEntityEffect and SendRemoveEntityEffect. Also a Player now gets the hunger effect when he has food poison. --- src/Entities/Player.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 85833f31d..20c4818b2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -557,9 +557,13 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - // TODO: Send the poisoning indication to the client - how? + m_ClientHandle->SendRemoveEntityEffect(*this, 17); SendHealth(); } + else + { + m_ClientHandle->SendEntityEffect(*this, 17, 0, 20); + } } @@ -1704,6 +1708,10 @@ void cPlayer::HandleFood(void) m_FoodPoisonedTicksRemaining--; m_FoodExhaustionLevel += 0.025; // 0.5 per second = 0.025 per tick } + else + { + m_ClientHandle->SendRemoveEntityEffect(*this, 17); // remove the "Hunger" effect. + } // Apply food exhaustion that has accumulated: if (m_FoodExhaustionLevel >= 4) -- cgit v1.2.3 From 71250b275f2c1b16ff81c74c6e3f5bc2794ebb97 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 14 Dec 2013 22:23:20 +0100 Subject: Added E_EFFECT_ --- src/Entities/Effects.h | 29 +++++++++++++++++++++++++++++ src/Entities/Player.cpp | 6 +++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/Entities/Effects.h (limited to 'src/Entities') diff --git a/src/Entities/Effects.h b/src/Entities/Effects.h new file mode 100644 index 000000000..4fb867e65 --- /dev/null +++ b/src/Entities/Effects.h @@ -0,0 +1,29 @@ +#pragma once + +// tolua_begin +enum ENUM_ENTITY_EFFECT +{ + E_EFFECT_SPEED = 1, + E_EFFECT_SLOWNESS = 2, + E_EFFECT_HASTE = 3, + E_EFFECT_MINING_FATIGUE = 4, + E_EFFECT_STENGTH = 5, + E_EFFECT_INSTANT_HEALTH = 6, + E_EFFECT_INSTANT_DAMAGE = 7, + E_EFFECT_JUMP_BOOST = 8, + E_EFFECT_NAUSEA = 9, + E_EFFECT_REGENERATION = 10, + E_EFFECT_RESISTANCE = 11, + E_EFFECT_FIRE_RESISTANCE = 12, + E_EFFECT_WATER_BREATHING = 13, + E_EFFECT_INVISIBILITY = 14, + E_EFFECT_BLINDNESS = 15, + E_EFFECT_NIGHT_VISION = 16, + E_EFFECT_HUNGER = 17, + E_EFFECT_WEAKNESS = 18, + E_EFFECT_POISON = 19, + E_EFFECT_WITHER = 20, + E_EFFECT_HEALTH_BOOST = 21, + E_EFFECT_ABSORPTION = 22, + E_EFFECT_SATURATION = 23, +} ; \ No newline at end of file diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 20c4818b2..b2485a8e2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -557,12 +557,12 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - m_ClientHandle->SendRemoveEntityEffect(*this, 17); + m_ClientHandle->SendRemoveEntityEffect(*this, E_EFFECT_HUNGER); SendHealth(); } else { - m_ClientHandle->SendEntityEffect(*this, 17, 0, 20); + m_ClientHandle->SendEntityEffect(*this, E_EFFECT_HUNGER, 0, 20); } } @@ -1710,7 +1710,7 @@ void cPlayer::HandleFood(void) } else { - m_ClientHandle->SendRemoveEntityEffect(*this, 17); // remove the "Hunger" effect. + m_ClientHandle->SendRemoveEntityEffect(*this, E_EFFECT_HUNGER); // remove the "Hunger" effect. } // Apply food exhaustion that has accumulated: -- cgit v1.2.3 From 8c04afe18a3420574942501a30e3151e89217acd Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 14 Dec 2013 22:34:49 +0100 Subject: Exported E_EFFECTS_ to lua. Forgot to commit Globals.h. --- src/Entities/Effects.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Effects.h b/src/Entities/Effects.h index 4fb867e65..e7611847d 100644 --- a/src/Entities/Effects.h +++ b/src/Entities/Effects.h @@ -26,4 +26,5 @@ enum ENUM_ENTITY_EFFECT E_EFFECT_HEALTH_BOOST = 21, E_EFFECT_ABSORPTION = 22, E_EFFECT_SATURATION = 23, -} ; \ No newline at end of file +} ; +// tolua_end \ No newline at end of file -- cgit v1.2.3 From 9c2089dc5a89acc2351fa089558d1e375c1d09f6 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 10:52:54 +0100 Subject: cPlayer is using the broadcast functions. --- src/Entities/Player.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index b2485a8e2..e057c25fe 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -557,12 +557,12 @@ void cPlayer::FoodPoison(int a_NumTicks) m_FoodPoisonedTicksRemaining = std::max(m_FoodPoisonedTicksRemaining, a_NumTicks); if (!HasBeenFoodPoisoned) { - m_ClientHandle->SendRemoveEntityEffect(*this, E_EFFECT_HUNGER); + m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); SendHealth(); } else { - m_ClientHandle->SendEntityEffect(*this, E_EFFECT_HUNGER, 0, 20); + m_World->BroadcastEntityEffect(*this, E_EFFECT_HUNGER, 0, 400); // Give the player the "Hunger" effect for 20 seconds. } } @@ -1710,7 +1710,7 @@ void cPlayer::HandleFood(void) } else { - m_ClientHandle->SendRemoveEntityEffect(*this, E_EFFECT_HUNGER); // remove the "Hunger" effect. + m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); // Remove the "Hunger" effect. } // Apply food exhaustion that has accumulated: -- cgit v1.2.3 From b10d0b95cbdce1d476f14415901c89bf324c0c18 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 14:48:17 +0100 Subject: Added m_IsFlying and m_CanFly. Both have a Get and Set function. Added cClientHandle::SendPlayerAbilities() function --- src/Entities/Player.cpp | 32 ++++++++++++++++++++++++++++++++ src/Entities/Player.h | 14 +++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index e057c25fe..c2a76342d 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -63,6 +63,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_IsSprinting(false) , m_IsSwimming(false) , m_IsSubmerged(false) + , m_IsFlying(false) + , m_CanFly(false) , m_EatingFinishTick(-1) , m_IsChargingBow(false) , m_BowCharge(0) @@ -751,6 +753,36 @@ void cPlayer::SetSprint(bool a_IsSprinting) +void cPlayer::SetCanFly(bool a_CanFly) +{ + if (a_CanFly == m_CanFly) + { + return; + } + + m_CanFly = a_CanFly; + m_ClientHandle->SendPlayerAbilities(); +} + + + + + +void cPlayer::SetFlying(bool a_IsFlying) +{ + if (a_IsFlying == m_IsFlying) + { + return; + } + + m_IsFlying = a_IsFlying; + m_ClientHandle->SendPlayerAbilities(); +} + + + + + void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if (a_TDI.DamageType != dtInVoid) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 44cab7d74..f3ee841e7 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -250,6 +250,8 @@ public: /// Returns true if the player is currently in the process of eating the currently equipped item bool IsEating(void) const { return (m_EatingFinishTick >= 0); } + /// Returns true if the player is currently flying. + bool IsFlying(void) const { return m_IsFlying; } // tolua_end /// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet @@ -319,12 +321,20 @@ public: /// Starts or stops sprinting, sends the max speed update to the client, if needed void SetSprint(bool a_IsSprinting); + /// Flags the player as flying + void SetFlying(bool a_IsFlying); + + /// If true the player can fly even when he's not in creative. + void SetCanFly(bool a_CanFly); + /// Returns whether the player is swimming or not virtual bool IsSwimming(void) const{ return m_IsSwimming; } /// Return whether the player is under water or not virtual bool IsSubmerged(void) const{ return m_IsSubmerged; } + /// Returns wheter the player can fly or not. + virtual bool CanFly(void) const { return m_CanFly; } // tolua_end // cEntity overrides: @@ -415,10 +425,12 @@ protected: bool m_IsCrouched; bool m_IsSprinting; - + bool m_IsFlying; bool m_IsSwimming; bool m_IsSubmerged; + bool m_CanFly; // If this is true the player can fly. Even if he is not in creative. + /// The world tick in which eating will be finished. -1 if not eating Int64 m_EatingFinishTick; -- cgit v1.2.3 From 368b7a40b5c86d5fcd37ac4672a8823cdfb48538 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 15 Dec 2013 15:57:38 +0100 Subject: Fixed indentation. --- src/Entities/ExpOrb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 248fb7278..04ee85823 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -54,7 +54,7 @@ void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk) Destroy(true); } a_Distance.Normalize(); - a_Distance *= ((float) (5.5 - Distance)); + a_Distance *= ((float) (5.5 - Distance)); SetSpeedX( a_Distance.x ); SetSpeedY( a_Distance.y ); SetSpeedZ( a_Distance.z ); -- cgit v1.2.3 From 0efd74f114dad98c4fadc0318718f2e0203bca8b Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 18:54:54 +0100 Subject: This adds a function that allows you to 'shoot' a player towards a direction. --- src/Entities/Player.cpp | 10 ++++++++++ src/Entities/Player.h | 3 +++ 2 files changed, 13 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c2a76342d..ab7075121 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1069,6 +1069,16 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const +void cPlayer::ShootTo(Vector3d a_Direction) +{ + SetSpeed(a_Direction); + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + void cPlayer::MoveTo( const Vector3d & a_NewPos ) { if ((a_NewPos.y < -990) && (GetPosY() > -100)) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index f3ee841e7..8dc6968ff 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -167,6 +167,9 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); + /// "Shoots" the player in the given direction. + void ShootTo(Vector3d a_Direction); // tolua_export + /// Tries to move to a new position, with attachment-related checks (y == -999) void MoveTo(const Vector3d & a_NewPos); // tolua_export -- cgit v1.2.3 From 5e75408b3becd5de0ef88223c789fa6f95ff6619 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 20:19:58 +0100 Subject: Renamed ShootTo function to ForceSetSpeed. --- src/Entities/Player.cpp | 2 +- src/Entities/Player.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ab7075121..38b911fd2 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1069,7 +1069,7 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const -void cPlayer::ShootTo(Vector3d a_Direction) +void cPlayer::ForceSetSpeed(Vector3d a_Direction) { SetSpeed(a_Direction); m_ClientHandle->SendEntityVelocity(*this); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 8dc6968ff..a09f7f489 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -167,8 +167,8 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); - /// "Shoots" the player in the given direction. - void ShootTo(Vector3d a_Direction); // tolua_export + /// Forces the player to move in the given direction. + void ForceSetSpeed(Vector3d a_Direction); // tolua_export /// Tries to move to a new position, with attachment-related checks (y == -999) void MoveTo(const Vector3d & a_NewPos); // tolua_export -- cgit v1.2.3 From 007d668c1bdd29bc6d28de0db2681f5c2f77ed5c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 21:25:13 +0100 Subject: Server saves if a player is flying. --- src/Entities/Player.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 38b911fd2..5165c2f8a 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1517,6 +1517,7 @@ bool cPlayer::LoadFromDisk() m_FoodExhaustionLevel = root.get("foodExhaustion", 0).asDouble(); m_LifetimeTotalXp = (short) root.get("xpTotal", 0).asInt(); m_CurrentXp = (short) root.get("xpCurrent", 0).asInt(); + m_IsFlying = root.get("isflying", 0).asBool(); //SetExperience(root.get("experience", 0).asInt()); @@ -1567,7 +1568,8 @@ bool cPlayer::SaveToDisk() root["foodSaturation"] = m_FoodSaturationLevel; root["foodTickTimer"] = m_FoodTickTimer; root["foodExhaustion"] = m_FoodExhaustionLevel; - root["world"] = GetWorld()->GetName(); + root["world"] = GetWorld()->GetName(); + root["isflying"] = IsFlying(); if (m_GameMode == GetWorld()->GetGameMode()) { -- cgit v1.2.3 From f521cbeb31e90e4c5c25edb6686544530ddbaf99 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 16 Dec 2013 10:41:35 +0100 Subject: Fixed cClientHandle::Tick() being called from two threads. When the player was initialized, the Tick() function continued to stream chunk, while the cWorld called Tick() from its tick thread. Final fix for #187. --- src/Entities/Player.cpp | 22 ---------------------- src/Entities/Player.h | 2 -- 2 files changed, 24 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 5165c2f8a..7e7d77433 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -137,28 +137,6 @@ cPlayer::~cPlayer(void) -bool cPlayer::Initialize(cWorld * a_World) -{ - ASSERT(a_World != NULL); - - if (super::Initialize(a_World)) - { - // Remove the client handle from the server, it will be ticked from this object from now on - if (m_ClientHandle != NULL) - { - cRoot::Get()->GetServer()->ClientMovedToWorld(m_ClientHandle); - } - - GetWorld()->AddPlayer(this); - return true; - } - return false; -} - - - - - void cPlayer::Destroyed() { CloseWindow(false); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index a09f7f489..59e941040 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -41,8 +41,6 @@ public: cPlayer(cClientHandle * a_Client, const AString & a_PlayerName); virtual ~cPlayer(); - virtual bool Initialize(cWorld * a_World) override; - virtual void SpawnOn(cClientHandle & a_Client) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; -- cgit v1.2.3 From 459d6369484107fbba93817469d038718ce41da2 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 18:02:33 +0100 Subject: Added HandleSpeedFromAttachee so an entity can override the function. --- src/Entities/Entity.cpp | 18 ++++++++++++++---- src/Entities/Entity.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 0a2145e81..7721d58b3 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1341,6 +1341,19 @@ void cEntity::AddSpeedZ(double a_AddSpeedZ) +void cEntity::HandleSpeedFromAttachee(float a_Forward, float a_Sideways) +{ + Vector3d LookVector = m_Attachee->GetLookVector(); + double AddSpeedX = LookVector.x * a_Forward + LookVector.z * a_Sideways; + double AddSpeedZ = LookVector.z * a_Forward - LookVector.x * a_Sideways; + SetSpeed(AddSpeedX, 0, AddSpeedZ); + BroadcastMovementUpdate(); +} + + + + + void cEntity::SteerVehicle(float a_Forward, float a_Sideways) { if (m_AttachedTo == NULL) @@ -1349,10 +1362,7 @@ void cEntity::SteerVehicle(float a_Forward, float a_Sideways) } if ((a_Forward != 0) || (a_Sideways != 0)) { - Vector3d LookVector = GetLookVector(); - double AddSpeedX = LookVector.x * a_Forward + LookVector.z * a_Sideways; - double AddSpeedZ = LookVector.z * a_Forward - LookVector.x * a_Sideways; - m_AttachedTo->AddSpeed(AddSpeedX, 0, AddSpeedZ); + m_AttachedTo->HandleSpeedFromAttachee(a_Forward, a_Sideways); } } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index de5f176ae..8d1692c98 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -197,6 +197,7 @@ public: void AddSpeedY (double a_AddSpeedY); void AddSpeedZ (double a_AddSpeedZ); + virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways); void SteerVehicle(float a_Forward, float a_Sideways); inline int GetUniqueID(void) const { return m_UniqueID; } -- cgit v1.2.3 From 199123d4f23aa6d1957b96382c96bd89cbcdf092 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 18:03:39 +0100 Subject: Boats drop a boat pickup when destroyed by hand. You can now actualy use boats. --- src/Entities/Boat.cpp | 33 +++++++++++++++++++++++++++++++-- src/Entities/Boat.h | 3 ++- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 56e766dd4..184aeeeeb 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -39,6 +39,15 @@ void cBoat::DoTakeDamage(TakeDamageInfo & TDI) if (GetHealth() == 0) { + if (TDI.Attacker != NULL) + { + if (TDI.Attacker->IsPlayer()) + { + cItems Pickups; + Pickups.Add(cItem(E_ITEM_BOAT)); + m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 0, 0, 0, true); + } + } Destroy(true); } } @@ -76,12 +85,32 @@ void cBoat::OnRightClicked(cPlayer & a_Player) -void cBoat::HandlePhysics(float a_Dt, cChunk & a_Chunk) +void cBoat::Tick(float a_Dt, cChunk & a_Chunk) { - super::HandlePhysics(a_Dt, a_Chunk); + super::Tick(a_Dt, a_Chunk); BroadcastMovementUpdate(); + SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed. + if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()))) + { + SetSpeedY(1); + } } + +void cBoat::HandleSpeedFromAttachee(float a_Forward, float a_Sideways) +{ + if (GetSpeed().Length() > 7) + { + return; + } + + Vector3d ToAddSpeed(m_Attachee->GetLookVector() * (a_Sideways * 1.5)); + ToAddSpeed.y = 0; + + AddSpeed(ToAddSpeed); +} + + \ No newline at end of file diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h index 8c51ab86c..c4c9afe7a 100644 --- a/src/Entities/Boat.h +++ b/src/Entities/Boat.h @@ -27,7 +27,8 @@ public: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void OnRightClicked(cPlayer & a_Player) override; virtual void DoTakeDamage(TakeDamageInfo & TDI) override; - virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override; cBoat(double a_X, double a_Y, double a_Z); } ; -- cgit v1.2.3