From 324fa55bf0c72f61ce8b5dfc3df7770d61a8e25f Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 18:01:33 +0100 Subject: You can spawn boats on water. --- src/Items/ItemBoat.h | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 6e3395f1d..c50171c0c 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -10,6 +10,7 @@ #pragma once #include "../Entities/Boat.h" +#include "../LineBlockTracer.h" @@ -30,23 +31,47 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override { - if (a_Dir < 0) + if (a_Dir > 0) { return false; } + + class cCallbacks : + public cBlockTracer::cCallbacks + { + public: + Vector3d Pos; + virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override + { + if (a_BlockType != E_BLOCK_AIR) + { + Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ); + return true; + } + return false; + } + } Callbacks; - double x = (double)a_BlockX + 0.5; - double y = (double)a_BlockY + 0.5; - double z = (double)a_BlockZ + 0.5; + cLineBlockTracer Tracer(*a_World, Callbacks); + Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); + Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); - cBoat * Boat = NULL; + Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); + + double x = Callbacks.Pos.x; + double y = Callbacks.Pos.y; + double z = Callbacks.Pos.z; + + if (x == 0 && y == 0 && z == 0) + { + return false; + } - Boat = new cBoat (x, y, z); + cBoat * Boat = new cBoat(x, y + 1, z); Boat->Initialize(a_World); return true; } - } ; -- cgit v1.2.3 From 459d6369484107fbba93817469d038718ce41da2 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 18:02:33 +0100 Subject: Added HandleSpeedFromAttachee so an entity can override the function. --- src/Entities/Entity.cpp | 18 ++++++++++++++---- src/Entities/Entity.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3 From 199123d4f23aa6d1957b96382c96bd89cbcdf092 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 18:03:39 +0100 Subject: Boats drop a boat pickup when destroyed by hand. You can now actualy use boats. --- src/Entities/Boat.cpp | 33 +++++++++++++++++++++++++++++++-- src/Entities/Boat.h | 3 ++- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'src') 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); } ; -- cgit v1.2.3 From 6b21dc6d11673f612d3ca6f3f4ced8809d61ef47 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 20:53:43 +0100 Subject: Using suggestions for Boat placing. --- src/Items/ItemBoat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index c50171c0c..0326b13b8 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -62,7 +62,7 @@ public: double y = Callbacks.Pos.y; double z = Callbacks.Pos.z; - if (x == 0 && y == 0 && z == 0) + if ((x == 0) && (y == 0) && (z == 0)) { return false; } -- cgit v1.2.3 From 59165dcba5df9fc30f4a9795b550364eb89e9c2b Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 16 Dec 2013 21:50:57 +0100 Subject: Boats spawn on top of a block. not between 4 blocks. --- src/Items/ItemBoat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h index 0326b13b8..79c8e9589 100644 --- a/src/Items/ItemBoat.h +++ b/src/Items/ItemBoat.h @@ -67,7 +67,7 @@ public: return false; } - cBoat * Boat = new cBoat(x, y + 1, z); + cBoat * Boat = new cBoat(x + 0.5, y + 1, z + 0.5); Boat->Initialize(a_World); return true; -- cgit v1.2.3