diff options
author | Tycho Bickerstaff <work.tycho@gmail.com> | 2013-12-18 20:06:11 +0100 |
---|---|---|
committer | Tycho Bickerstaff <work.tycho@gmail.com> | 2013-12-18 20:06:11 +0100 |
commit | e627f2f98cb9a2ec7cddcaac779350abcbae414a (patch) | |
tree | 6101aa8aa5a0152c278e129a26ba7ca26172597c /src/Entities | |
parent | added zlib (diff) | |
parent | Merge pull request #440 from mc-server/repeaterfixes (diff) | |
download | cuberite-e627f2f98cb9a2ec7cddcaac779350abcbae414a.tar cuberite-e627f2f98cb9a2ec7cddcaac779350abcbae414a.tar.gz cuberite-e627f2f98cb9a2ec7cddcaac779350abcbae414a.tar.bz2 cuberite-e627f2f98cb9a2ec7cddcaac779350abcbae414a.tar.lz cuberite-e627f2f98cb9a2ec7cddcaac779350abcbae414a.tar.xz cuberite-e627f2f98cb9a2ec7cddcaac779350abcbae414a.tar.zst cuberite-e627f2f98cb9a2ec7cddcaac779350abcbae414a.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Entities/Boat.cpp | 33 | ||||
-rw-r--r-- | src/Entities/Boat.h | 3 | ||||
-rw-r--r-- | src/Entities/Effects.h | 30 | ||||
-rw-r--r-- | src/Entities/Entity.cpp | 18 | ||||
-rw-r--r-- | src/Entities/Entity.h | 1 | ||||
-rw-r--r-- | src/Entities/ExpOrb.cpp | 2 | ||||
-rw-r--r-- | src/Entities/Player.cpp | 78 | ||||
-rw-r--r-- | src/Entities/Player.h | 19 |
8 files changed, 149 insertions, 35 deletions
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); } ; diff --git a/src/Entities/Effects.h b/src/Entities/Effects.h new file mode 100644 index 000000000..e7611847d --- /dev/null +++ b/src/Entities/Effects.h @@ -0,0 +1,30 @@ +#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, +} ; +// tolua_end
\ No newline at end of file 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; } 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 ); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 85833f31d..7e7d77433 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) @@ -135,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); @@ -557,9 +537,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_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); SendHealth(); } + else + { + m_World->BroadcastEntityEffect(*this, E_EFFECT_HUNGER, 0, 400); // Give the player the "Hunger" effect for 20 seconds. + } } @@ -747,6 +731,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) @@ -1033,6 +1047,16 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const +void cPlayer::ForceSetSpeed(Vector3d a_Direction) +{ + SetSpeed(a_Direction); + m_ClientHandle->SendEntityVelocity(*this); +} + + + + + void cPlayer::MoveTo( const Vector3d & a_NewPos ) { if ((a_NewPos.y < -990) && (GetPosY() > -100)) @@ -1471,6 +1495,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()); @@ -1521,7 +1546,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()) { @@ -1704,6 +1730,10 @@ void cPlayer::HandleFood(void) m_FoodPoisonedTicksRemaining--; m_FoodExhaustionLevel += 0.025; // 0.5 per second = 0.025 per tick } + else + { + m_World->BroadcastRemoveEntityEffect(*this, E_EFFECT_HUNGER); // Remove the "Hunger" effect. + } // Apply food exhaustion that has accumulated: if (m_FoodExhaustionLevel >= 4) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 44cab7d74..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; @@ -167,6 +165,9 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); + /// 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 @@ -250,6 +251,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 +322,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 +426,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; |