From e8f7b72f1b20b6b3861ab8c7f247501618bb1df7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 20 Aug 2013 21:17:33 +0200 Subject: Hotfix for #83. Do not tick the player while their chunk is invalid. --- source/Entities/Player.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/Entities/Player.cpp') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 3ccb4ca1d..119afbafc 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -200,6 +200,12 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) } } + if (!a_Chunk.IsValid()) + { + // This may happen if the cPlayer is created before the chunks have the chance of being loaded / generated (#83) + return; + } + super::Tick(a_Dt, a_Chunk); // Set player swimming state -- cgit v1.2.3 From 17ad4c2610f2c33d5b4a8b42b7d4b8fbda9ade32 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 Aug 2013 14:24:03 +0200 Subject: Shooting a bow kinda works. The arrow is released, but sometimes hits wrong blocks or disappears completely. --- source/Entities/Player.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'source/Entities/Player.cpp') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 119afbafc..0cb047933 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -64,6 +64,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_IsSwimming(false) , m_IsSubmerged(false) , m_EatingFinishTick(-1) + , m_IsChargingBow(false) + , m_BowCharge(0) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", a_PlayerName.c_str(), a_Client->GetIPString().c_str(), @@ -213,6 +215,13 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) // Handle air drowning stuff HandleAir(); + + // Handle charging the bow: + if (m_IsChargingBow) + { + m_BowCharge += 1; + LOGD("Player \"%s\" charging bow: %d", m_PlayerName.c_str(), m_BowCharge); + } if (m_bDirtyPosition) { @@ -253,6 +262,41 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) +void cPlayer::StartChargingBow(void) +{ + LOGD("Player \"%s\" started charging their bow", m_PlayerName.c_str()); + m_IsChargingBow = true; + m_BowCharge = 0; +} + + + + + +int cPlayer::FinishChargingBow(void) +{ + LOGD("Player \"%s\" finished charging their bow at a charge of %d", m_PlayerName.c_str(), m_BowCharge); + int res = m_BowCharge; + m_IsChargingBow = false; + m_BowCharge = 0; + return res; +} + + + + + +void cPlayer::CancelChargingBow(void) +{ + LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", m_PlayerName.c_str(), m_BowCharge); + m_IsChargingBow = false; + m_BowCharge = 0; +} + + + + + void cPlayer::SetTouchGround(bool a_bTouchGround) { // If just -- cgit v1.2.3 From 88f3fe7f000992fe7a3c47d4e235f725e9b77b69 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 Aug 2013 17:29:46 +0200 Subject: Moved throw pos and speed calculation from cProjectileEntity into cPlayer. --- source/Entities/Player.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source/Entities/Player.cpp') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index 0cb047933..0943f61ff 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -857,6 +857,36 @@ void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) +Vector3d cPlayer::GetThrowStartPos(void) const +{ + Vector3d res = GetEyePosition(); + + // Adjust the position to be just outside the player's bounding box: + res.x += 0.16 * cos(GetPitch()); + res.y += -0.1; + res.z += 0.16 * sin(GetPitch()); + + return res; +} + + + + + +Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const +{ + Vector3d res = GetLookVector(); + res.Normalize(); + + // TODO: Add a slight random change (+-0.0075 in each direction) + + return res * a_SpeedCoeff; +} + + + + + void cPlayer::MoveTo( const Vector3d & a_NewPos ) { if ((a_NewPos.y < -990) && (GetPosY() > -100)) -- cgit v1.2.3