diff options
author | Mattes D <github@xoft.cz> | 2014-09-17 21:30:11 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-09-17 21:30:11 +0200 |
commit | 0625556c372462f48f13482866c0c12a6dcb51e2 (patch) | |
tree | d77b0dc3845b99911a8924449ef38d4cc47fcddf /src/Entities | |
parent | Added an explicit setting for allowing BungeeCord handshake. (diff) | |
parent | Implementing Spectator Mode (diff) | |
download | cuberite-0625556c372462f48f13482866c0c12a6dcb51e2.tar cuberite-0625556c372462f48f13482866c0c12a6dcb51e2.tar.gz cuberite-0625556c372462f48f13482866c0c12a6dcb51e2.tar.bz2 cuberite-0625556c372462f48f13482866c0c12a6dcb51e2.tar.lz cuberite-0625556c372462f48f13482866c0c12a6dcb51e2.tar.xz cuberite-0625556c372462f48f13482866c0c12a6dcb51e2.tar.zst cuberite-0625556c372462f48f13482866c0c12a6dcb51e2.zip |
Diffstat (limited to 'src/Entities')
-rw-r--r-- | src/Entities/Player.cpp | 29 | ||||
-rw-r--r-- | src/Entities/Player.h | 3 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ea795e346..3920bdb56 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -451,6 +451,11 @@ void cPlayer::CancelChargingBow(void) void cPlayer::SetTouchGround(bool a_bTouchGround) { + if (IsGameModeSpectator()) // You can fly through the ground in Spectator + { + return; + } + m_bTouchGround = a_bTouchGround; if (!m_bTouchGround) @@ -585,7 +590,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::AddFoodExhaustion(double a_Exhaustion) { - if (!IsGameModeCreative()) + if (!(IsGameModeCreative() || IsGameModeSpectator())) { m_FoodExhaustionLevel = std::min(m_FoodExhaustionLevel + a_Exhaustion, 40.0); } @@ -823,9 +828,9 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin)) { - if (IsGameModeCreative()) + if (IsGameModeCreative() || IsGameModeSpectator()) { - // No damage / health in creative mode if not void or plugin damage + // No damage / health in creative or spectator mode if not void or plugin damage return false; } } @@ -1043,6 +1048,14 @@ bool cPlayer::IsGameModeAdventure(void) const +bool cPlayer::IsGameModeSpectator(void) const +{ + return (m_GameMode == gmSpectator) || // Either the player is explicitly in Spectator + ((m_GameMode == gmNotSet) && m_World->IsGameModeSpectator()); // or they inherit from the world and the world is Adventure +} + + + void cPlayer::SetTeam(cTeam * a_Team) { @@ -1158,7 +1171,7 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) m_GameMode = a_GameMode; m_ClientHandle->SendGameMode(a_GameMode); - if (!IsGameModeCreative()) + if (!(IsGameModeCreative() || IsGameModeSpectator())) { SetFlying(false); SetCanFly(false); @@ -1340,6 +1353,7 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos) void cPlayer::SetVisible(bool a_bVisible) { + // Need to Check if the player or other players are in gamemode spectator, but will break compatibility if (a_bVisible && !m_bVisible) // Make visible { m_bVisible = true; @@ -1500,6 +1514,11 @@ void cPlayer::TossPickup(const cItem & a_Item) void cPlayer::TossItems(const cItems & a_Items) { + if (IsGameModeSpectator()) // Players can't toss items in spectator + { + return; + } + m_Stats.AddValue(statItemsDropped, (StatValue)a_Items.Size()); double vX = 0, vY = 0, vZ = 0; @@ -1786,7 +1805,7 @@ bool cPlayer::SaveToDisk() void cPlayer::UseEquippedItem(int a_Amount) { - if (IsGameModeCreative()) // No damage in creative + if (IsGameModeCreative() || IsGameModeSpectator()) // No damage in creative or spectator { return; } diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 9821cc6d9..d64dd6b99 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -171,6 +171,9 @@ public: /** Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world */ bool IsGameModeAdventure(void) const; + /** Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current world */ + bool IsGameModeSpectator(void) const; + AString GetIP(void) const { return m_IP; } // tolua_export /** Returns the associated team, NULL if none */ |