From f300ed54e5f53ed9e417d88eb63fd38e1979bacf Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 6 Sep 2013 00:04:49 +0200 Subject: Implemented SteerVehicle packet. --- source/Entities/Entity.cpp | 33 +++++++++++++++++++++++++++------ source/Entities/Entity.h | 2 ++ 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 56fd36a05..4066e81ab 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -546,22 +546,24 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } else { + // TODO: This condition belongs to minecarts, without it, they derails too much. + // But it shouldn't be here for other entities. We need a complete minecart physics overhaul. if ( - (BlockBelow != E_BLOCK_RAIL) && - (BlockBelow != E_BLOCK_DETECTOR_RAIL) && - (BlockBelow != E_BLOCK_POWERED_RAIL) && + (BlockBelow != E_BLOCK_RAIL) && + (BlockBelow != E_BLOCK_DETECTOR_RAIL) && + (BlockBelow != E_BLOCK_POWERED_RAIL) && (BlockBelow != E_BLOCK_ACTIVATOR_RAIL) - ) + ) { // Friction if (NextSpeed.SqrLength() > 0.0004f) { - NextSpeed.x *= 0.7f / (1 + a_Dt); + NextSpeed.x *= 0.6666; if (fabs(NextSpeed.x) < 0.05) { NextSpeed.x = 0; } - NextSpeed.z *= 0.7f / (1 + a_Dt); + NextSpeed.z *= 0.6666; if (fabs(NextSpeed.z) < 0.05) { NextSpeed.z = 0; @@ -1225,6 +1227,25 @@ void cEntity::AddSpeedZ(double a_AddSpeedZ) +void cEntity::SteerVehicle(float a_Forward, float a_Sideways) +{ + if (m_AttachedTo == NULL) + { + return; + } + 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); + } +} + + + + + ////////////////////////////////////////////////////////////////////////// // Get look vector (this is NOT a rotation!) Vector3d cEntity::GetLookVector(void) const diff --git a/source/Entities/Entity.h b/source/Entities/Entity.h index 2d058abae..b4777d249 100644 --- a/source/Entities/Entity.h +++ b/source/Entities/Entity.h @@ -185,6 +185,8 @@ public: void AddSpeedX (double a_AddSpeedX); void AddSpeedY (double a_AddSpeedY); void AddSpeedZ (double a_AddSpeedZ); + + void SteerVehicle(float a_Forward, float a_Sideways); inline int GetUniqueID(void) const { return m_UniqueID; } inline bool IsDestroyed(void) const { return !m_IsInitialized; } -- cgit v1.2.3 From c789a8ddf5840cf7861c73536279da8bbd9281c3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 8 Sep 2013 00:14:57 +0100 Subject: Initial boat support + Boats are saved + Boats have physics + Boats spawn --- source/Entities/Boat.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ source/Entities/Boat.h | 34 ++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 source/Entities/Boat.cpp create mode 100644 source/Entities/Boat.h (limited to 'source/Entities') diff --git a/source/Entities/Boat.cpp b/source/Entities/Boat.cpp new file mode 100644 index 000000000..f29766fc1 --- /dev/null +++ b/source/Entities/Boat.cpp @@ -0,0 +1,84 @@ + +// Minecart.cpp + +// Implements the cMinecart class representing a minecart in the world +// Indiana Jones! + +#include "Globals.h" +#include "Boat.h" +#include "../World.h" +#include "../ClientHandle.h" +#include "Player.h" + + + + + +cBoat::cBoat(double a_X, double a_Y, double a_Z) : + super(etBoat, a_X, a_Y, a_Z, 0.98, 0.7) +{ + SetMass(20.f); + SetMaxHealth(6); + SetHealth(6); +} + + + + +void cBoat::SpawnOn(cClientHandle & a_ClientHandle) +{ + a_ClientHandle.SendSpawnVehicle(*this, 1, 0); +} + + + + + +void cBoat::DoTakeDamage(TakeDamageInfo & TDI) +{ + super::DoTakeDamage(TDI); + + if (GetHealth() == 0) + { + Destroy(true); + } +} + + + + + +void cBoat::OnRightClicked(cPlayer & a_Player) +{ + if (m_Attachee != NULL) + { + if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID()) + { + // This player is already sitting in, they want out. + a_Player.Detach(); + return; + } + + if (m_Attachee->IsPlayer()) + { + // Another player is already sitting in here, cannot attach + return; + } + + // Detach whatever is sitting in this minecart now: + m_Attachee->Detach(); + } + + // Attach the player to this minecart + a_Player.AttachTo(this); +} + + + + + +void cBoat::HandlePhysics(float a_Dt, cChunk & a_Chunk) +{ + super::HandlePhysics(a_Dt, a_Chunk); + BroadcastMovementUpdate(); +} diff --git a/source/Entities/Boat.h b/source/Entities/Boat.h new file mode 100644 index 000000000..439b73a09 --- /dev/null +++ b/source/Entities/Boat.h @@ -0,0 +1,34 @@ + +// Boat.h + +// Declares the cBoat class representing a minecart in the world + + + + + +#pragma once + +#include "Entity.h" +#include "../Item.h" + + + + + +class cBoat : + public cEntity +{ + typedef cEntity super; + +public: + CLASS_PROTODEF(cBoat); + + // cEntity overrides: + 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; + + cBoat(double a_X, double a_Y, double a_Z); +} ; \ No newline at end of file -- cgit v1.2.3 From 50e24fb75fec614bb195e5a322e2ceff9cdd2b1a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 8 Sep 2013 16:56:16 +0100 Subject: Fixed a bunch of stuff * Fixed compilation * Made it less obvious I COPIED ALL THE CODE from Minecarts * Fixed alignment spaces to make xoft happy --- source/Entities/Boat.cpp | 6 +++--- source/Entities/Boat.h | 2 +- source/Entities/Entity.h | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'source/Entities') diff --git a/source/Entities/Boat.cpp b/source/Entities/Boat.cpp index f29766fc1..eebd3a373 100644 --- a/source/Entities/Boat.cpp +++ b/source/Entities/Boat.cpp @@ -1,8 +1,8 @@ -// Minecart.cpp +// Boat.cpp -// Implements the cMinecart class representing a minecart in the world -// Indiana Jones! +// Implements the cBoat class representing a boat in the world +// Pirates of the Carribean! #include "Globals.h" #include "Boat.h" diff --git a/source/Entities/Boat.h b/source/Entities/Boat.h index 439b73a09..e7a67958d 100644 --- a/source/Entities/Boat.h +++ b/source/Entities/Boat.h @@ -1,7 +1,7 @@ // Boat.h -// Declares the cBoat class representing a minecart in the world +// Declares the cBoat class representing a boat in the world diff --git a/source/Entities/Entity.h b/source/Entities/Entity.h index b4777d249..156f737a3 100644 --- a/source/Entities/Entity.h +++ b/source/Entities/Entity.h @@ -92,6 +92,7 @@ public: etMonster, etFallingBlock, etMinecart, + etBoat, etTNT, etProjectile, @@ -119,6 +120,7 @@ public: bool IsPickup (void) const { return (m_EntityType == etPickup); } bool IsMob (void) const { return (m_EntityType == etMob); } bool IsMinecart(void) const { return (m_EntityType == etMinecart); } + bool IsBoat (void) const { return (m_EntityType == etBoat); } bool IsTNT (void) const { return (m_EntityType == etTNT); } /// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true) -- cgit v1.2.3