From 4d2c810c64c38fd5530170d5c4d54956a5587fb2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Oct 2013 00:30:20 +0100 Subject: Pickups now have collection delay when vomited Implements FS#394. --- source/Entities/Pickup.cpp | 7 ++++--- source/Entities/Pickup.h | 7 ++++++- source/Entities/Player.cpp | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Pickup.cpp b/source/Entities/Pickup.cpp index 075f93449..50431f52e 100644 --- a/source/Entities/Pickup.cpp +++ b/source/Entities/Pickup.cpp @@ -24,11 +24,12 @@ -cPickup::cPickup(double a_X, double a_Y, double a_Z, const cItem & a_Item, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) +cPickup::cPickup(double a_X, double a_Y, double a_Z, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) : cEntity(etPickup, a_X, a_Y, a_Z, 0.2, 0.2) , m_Timer( 0.f ) , m_Item(a_Item) , m_bCollected( false ) + , m_bIsPlayerCreated( IsPlayerCreated ) { m_MaxHealth = 5; m_Health = 5; @@ -126,8 +127,8 @@ bool cPickup::CollectedBy(cPlayer * a_Dest) return false; // It's already collected! } - // 800 is to long - if (m_Timer < 500.f) + // Two seconds if player created the pickup (vomiting), half a second if anything else + if (m_Timer < (m_bIsPlayerCreated ? 2000.f : 500.f)) { // LOG("Pickup %d cannot be collected by \"%s\", because it is not old enough.", m_UniqueID, a_Dest->GetName().c_str()); return false; // Not old enough diff --git a/source/Entities/Pickup.h b/source/Entities/Pickup.h index 488f91fb2..e4154f1d4 100644 --- a/source/Entities/Pickup.h +++ b/source/Entities/Pickup.h @@ -24,7 +24,7 @@ class cPickup : public: CLASS_PROTODEF(cPickup); - cPickup(double a_X, double a_Y, double a_Z, const cItem & a_Item, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export + cPickup(double a_MicroPosX, double a_MicroPosY, double a_MicroPosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export cItem & GetItem(void) {return m_Item; } // tolua_export const cItem & GetItem(void) const {return m_Item; } @@ -40,6 +40,9 @@ public: /// Returns true if the pickup has already been collected bool IsCollected(void) const { return m_bCollected; } // tolua_export + + /// Returns true if created by player (i.e. vomiting), used for determining picking-up delay time + bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export private: Vector3d m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;) @@ -52,6 +55,8 @@ private: cItem m_Item; bool m_bCollected; + + bool m_bIsPlayerCreated; }; // tolua_export diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index d93b45614..e06281998 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -1183,7 +1183,7 @@ void cPlayer::TossItem( double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 3, vY * 3, vZ * 3); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player } -- cgit v1.2.3 From d359c5a2fe8a0e5af849916cbd225d31919f1826 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 11:05:43 +0200 Subject: Unified cPlayer's Heal() function with cEntity's. --- source/Entities/Player.cpp | 7 ++----- source/Entities/Player.h | 15 +++++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index e06281998..f92d42556 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -349,11 +349,8 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) void cPlayer::Heal(int a_Health) { - if (m_Health < GetMaxHealth()) - { - m_Health = (short)std::min((int)a_Health + m_Health, (int)GetMaxHealth()); - SendHealth(); - } + super::Heal(a_Health); + SendHealth(); } diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 82ff48954..067a996e5 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -167,13 +167,15 @@ public: StringList GetResolvedPermissions(); // >> EXPORTED IN MANUALBINDINGS << bool IsInGroup( const AString & a_Group ); // tolua_export - AString GetColor(void) const; // tolua_export + // tolua_begin + + /// Returns the full color code to use for this player, based on their primary group or set in m_Color + AString GetColor(void) const; - void TossItem(bool a_bDraggingItem, char a_Amount = 1, short a_CreateType = 0, short a_CreateHealth = 0); // tolua_export + void TossItem(bool a_bDraggingItem, char a_Amount = 1, short a_CreateType = 0, short a_CreateHealth = 0); - void Heal( int a_Health ); // tolua_export - - // tolua_begin + /// Heals the player by the specified amount of HPs (positive only); sends health update + void Heal(int a_Health); int GetFoodLevel (void) const { return m_FoodLevel; } double GetFoodSaturationLevel (void) const { return m_FoodSaturationLevel; } @@ -181,7 +183,7 @@ public: double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; } int GetFoodPoisonedTicksRemaining(void) const { return m_FoodPoisonedTicksRemaining; } - int GetAirLevel (void) const { return m_AirLevel; } + int GetAirLevel (void) const { return m_AirLevel; } /// 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); } @@ -302,6 +304,7 @@ protected: /// Player's air level (for swimming) int m_AirLevel; + /// used to time ticks between damage taken via drowning/suffocation int m_AirTickTimer; -- cgit v1.2.3 From eca6955a2dc4c8c444ad9e11ad4a8aa926969918 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 12:18:54 +0200 Subject: Cleanup in cPlayer. --- source/Entities/Player.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 067a996e5..449a63231 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -128,8 +128,8 @@ public: // 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 + /// Tries to move to a new position, with attachment-related checks (y == -999) + void MoveTo(const Vector3d & a_NewPos); // tolua_export cWindow * GetWindow(void) { return m_CurrentWindow; } // tolua_export const cWindow * GetWindow(void) const { return m_CurrentWindow; } @@ -159,8 +159,10 @@ public: /// Adds a player to existing group or creates a new group when it doesn't exist void AddToGroup( const AString & a_GroupName ); // tolua_export + /// Removes a player from the group, resolves permissions and group inheritance (case sensitive) void RemoveFromGroup( const AString & a_GroupName ); // tolua_export + bool CanUseCommand( const AString & a_Command ); // tolua_export bool HasPermission( const AString & a_Permission ); // tolua_export const GroupList & GetGroups() { return m_Groups; } // >> EXPORTED IN MANUALBINDINGS << -- cgit v1.2.3 From 625c5f86deb0649403994ae4bbcc4a4cd07853d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 15:05:23 +0200 Subject: Fixed cPickup's constructor's parameter naming. --- source/Entities/Pickup.cpp | 4 ++-- source/Entities/Pickup.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Pickup.cpp b/source/Entities/Pickup.cpp index 50431f52e..bc8abd204 100644 --- a/source/Entities/Pickup.cpp +++ b/source/Entities/Pickup.cpp @@ -24,8 +24,8 @@ -cPickup::cPickup(double a_X, double a_Y, double a_Z, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) - : cEntity(etPickup, a_X, a_Y, a_Z, 0.2, 0.2) +cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) + : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) , m_Timer( 0.f ) , m_Item(a_Item) , m_bCollected( false ) diff --git a/source/Entities/Pickup.h b/source/Entities/Pickup.h index e4154f1d4..cbd34a922 100644 --- a/source/Entities/Pickup.h +++ b/source/Entities/Pickup.h @@ -24,7 +24,7 @@ class cPickup : public: CLASS_PROTODEF(cPickup); - cPickup(double a_MicroPosX, double a_MicroPosY, double a_MicroPosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export + cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export cItem & GetItem(void) {return m_Item; } // tolua_export const cItem & GetItem(void) const {return m_Item; } -- cgit v1.2.3 From 99d369d83761e7ee27fa05061426cfdcd72f808b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 16:44:25 +0200 Subject: cPickup cleanup. --- source/Entities/Pickup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/Entities') diff --git a/source/Entities/Pickup.h b/source/Entities/Pickup.h index cbd34a922..d39eda298 100644 --- a/source/Entities/Pickup.h +++ b/source/Entities/Pickup.h @@ -31,7 +31,7 @@ public: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual bool CollectedBy(cPlayer * a_Dest); // tolua_export + bool CollectedBy(cPlayer * a_Dest); // tolua_export virtual void Tick(float a_Dt, cChunk & a_Chunk) override; -- cgit v1.2.3 From 9e9198e0907d3d6fd353c683478007f418d86dd8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 25 Oct 2013 11:15:44 +0200 Subject: cIniFile doesn't store filename internally anymore. --- source/Entities/Player.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index f92d42556..d94bc944c 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -1224,11 +1224,11 @@ void cPlayer::LoadPermissionsFromDisk() m_Groups.clear(); m_Permissions.clear(); - cIniFile IniFile("users.ini"); - if( IniFile.ReadFile() ) + cIniFile IniFile; + if (IniFile.ReadFile("users.ini")) { std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", ""); - if( Groups.size() > 0 ) + if (!Groups.empty()) { AStringVector Split = StringSplit( Groups, "," ); for( unsigned int i = 0; i < Split.size(); i++ ) @@ -1245,7 +1245,7 @@ void cPlayer::LoadPermissionsFromDisk() } else { - LOGWARN("WARNING: Failed to read ini file users.ini"); + LOGWARN("Failed to read the users.ini file. The player will be added only to the Default group."); AddToGroup("Default"); } ResolvePermissions(); -- cgit v1.2.3