From d3801c0296dd32f430a4074932bfabf27a8ade03 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 28 Jul 2013 11:30:54 +0200 Subject: Added cPlayer::IsGameModeXXX() and cWorld::IsGameModeXXX() functions. These are the preferred way of determining the gamemode, you should use those instead of doing manual comparisons to the gamemode value. --- source/Player.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source/Player.h') diff --git a/source/Player.h b/source/Player.h index fed222157..69b0c3df1 100644 --- a/source/Player.h +++ b/source/Player.h @@ -73,7 +73,18 @@ public: virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override; - eGameMode GetGameMode(void) const { return m_GameMode; } // tolua_export + /// Returns the current gamemode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable + eGameMode GetGameMode(void) const { return m_GameMode; } // tolua_export + + /// Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world + bool IsGameModeCreative(void) const; + + /// Returns true if the player is in Survival mode, either explicitly, or by inheriting from current world + bool IsGameModeSurvival(void) const; + + /// Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world + bool IsGameModeAdventure(void) const; + std::string GetIP() { return m_IP; } // tolua_export float GetLastBlockActionTime() { return m_LastBlockActionTime; } // tolua_export int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } // tolua_export -- cgit v1.2.3 From 4746d2251c6204118e710c818d78b89c356a7427 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 28 Jul 2013 19:15:03 +0200 Subject: Implemented basic eating support. Food is now properly consumed and it takes 1.5 sec. --- source/Player.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/Player.h') diff --git a/source/Player.h b/source/Player.h index 69b0c3df1..093c35b44 100644 --- a/source/Player.h +++ b/source/Player.h @@ -28,6 +28,7 @@ public: { MAX_HEALTH = 20, MAX_FOOD_LEVEL = 20, + EATING_TICKS = 30, ///< Number of ticks it takes to eat an item } ; // tolua_end @@ -164,6 +165,15 @@ public: // tolua_end + /// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet + void StartEating(void); + + /// Finishes eating the currently equipped item. Consumes the item, updates health and broadcasts the packets + void FinishEating(void); + + /// Aborts the current eating operation + void AbortEating(void); + virtual void KilledBy(cEntity * a_Killer) override; void Respawn(void); // tolua_export @@ -296,6 +306,9 @@ protected: bool m_IsCrouched; bool m_IsSprinting; + /// The world tick in which eating will be finished. -1 if not eating + Int64 m_EatingFinishTick; + virtual void Destroyed(void); -- cgit v1.2.3 From 3bf4130e3fc05f84cf7be7e33656f3e29f0fe12c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 28 Jul 2013 22:55:09 +0200 Subject: Player eating is now properly broadcast to other players. Also fixed the API relating to food, determining player gamemode, and removed several unneeded API functions. --- source/Player.h | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'source/Player.h') diff --git a/source/Player.h b/source/Player.h index 093c35b44..eea8c1596 100644 --- a/source/Player.h +++ b/source/Player.h @@ -66,7 +66,7 @@ public: double GetEyeHeight(void) const; // tolua_export Vector3d GetEyePosition(void) const; // tolua_export inline bool IsOnGround(void) const {return m_bTouchGround; } // tolua_export - inline const double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc. + inline const double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc. inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export inline const cInventory & GetInventory(void) const { return m_Inventory; } @@ -74,9 +74,17 @@ public: virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override; + // tolua_begin + /// Returns the current gamemode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable - eGameMode GetGameMode(void) const { return m_GameMode; } // tolua_export + eGameMode GetGameMode(void) const { return m_GameMode; } + /** Sets the gamemode for the player. + The gamemode may be gmNotSet, in that case the player inherits the world's gamemode. + Updates the gamemode on the client (sends the packet) + */ + void SetGameMode(eGameMode a_GameMode); + /// Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world bool IsGameModeCreative(void) const; @@ -86,17 +94,22 @@ public: /// Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world bool IsGameModeAdventure(void) const; - std::string GetIP() { return m_IP; } // tolua_export - float GetLastBlockActionTime() { return m_LastBlockActionTime; } // tolua_export - int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } // tolua_export - void SetLastBlockActionCnt( int ); // tolua_export - void SetLastBlockActionTime(); // tolua_export - void SetGameMode( eGameMode a_GameMode ); // tolua_export - void LoginSetGameMode( eGameMode a_GameMode ); + AString GetIP(void) const { return m_IP; } // tolua_export + + // tolua_end + void SetIP(const AString & a_IP); + float GetLastBlockActionTime() { return m_LastBlockActionTime; } + int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } + void SetLastBlockActionCnt( int ); + void SetLastBlockActionTime(); + + // Sets the current gamemode, doesn't check validity, doesn't send update packets to client + void LoginSetGameMode(eGameMode a_GameMode); + /// Tries to move to a new position, with collision checks and stuff - virtual void MoveTo( const Vector3d & a_NewPos ); // tolua_export + virtual void MoveTo( const Vector3d & a_NewPos ); // tolua_export cWindow * GetWindow(void) { return m_CurrentWindow; } // tolua_export const cWindow * GetWindow(void) const { return m_CurrentWindow; } @@ -148,6 +161,9 @@ public: double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; } int GetFoodPoisonedTicksRemaining(void) const { return m_FoodPoisonedTicksRemaining; } + /// Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore + bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); } + void SetFoodLevel (int a_FoodLevel); void SetFoodSaturationLevel (double a_FoodSaturationLevel); void SetFoodTickTimer (int a_FoodTickTimer); @@ -163,6 +179,9 @@ public: /// Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two void FoodPoison(int a_NumTicks); + /// Returns true if the player is currently in the process of eating the currently equipped item + bool IsEating(void) const { return (m_EatingFinishTick >= 0); } + // tolua_end /// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet @@ -235,6 +254,7 @@ public: // cEntity overrides: virtual bool IsCrouched (void) const { return m_IsCrouched; } virtual bool IsSprinting(void) const { return m_IsSprinting; } + virtual bool IsRclking (void) const { return IsEating(); } protected: typedef std::map< std::string, bool > PermissionMap; -- cgit v1.2.3