summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Boat.cpp109
-rw-r--r--src/Entities/Boat.h43
2 files changed, 143 insertions, 9 deletions
diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp
index f9b83eee5..cdb12123c 100644
--- a/src/Entities/Boat.cpp
+++ b/src/Entities/Boat.cpp
@@ -13,10 +13,10 @@
-cBoat::cBoat(double a_X, double a_Y, double a_Z) :
+cBoat::cBoat(double a_X, double a_Y, double a_Z, eMaterial a_Material) :
super(etBoat, a_X, a_Y, a_Z, 0.98, 0.7),
m_LastDamage(0), m_ForwardDirection(0),
- m_DamageTaken(0.0f), m_Type(0),
+ m_DamageTaken(0.0f), m_Material(a_Material),
m_RightPaddleUsed(false), m_LeftPaddleUsed(false)
{
SetMass(20.0f);
@@ -55,7 +55,7 @@ bool cBoat::DoTakeDamage(TakeDamageInfo & TDI)
if (TDI.Attacker->IsPlayer())
{
cItems Pickups;
- Pickups.Add(cItem(E_ITEM_BOAT));
+ Pickups.Add(MaterialToItem(m_Material));
m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 0, 0, 0, true);
}
}
@@ -169,3 +169,106 @@ void cBoat::UpdatePaddles(bool a_RightPaddleUsed, bool a_LeftPaddleUsed)
m_World->BroadcastEntityMetadata(*this);
}
+
+
+
+
+
+cBoat::eMaterial cBoat::ItemToMaterial(const cItem & a_Item)
+{
+ switch (a_Item.m_ItemType)
+ {
+ case E_ITEM_BOAT: return bmOak;
+ case E_ITEM_SPRUCE_BOAT: return bmSpruce;
+ case E_ITEM_BIRCH_BOAT: return bmBirch;
+ case E_ITEM_JUNGLE_BOAT: return bmJungle;
+ case E_ITEM_ACACIA_BOAT: return bmAcacia;
+ case E_ITEM_DARK_OAK_BOAT: return bmDarkOak;
+ default:
+ {
+ LOGWARNING("%s: Item type not handled %d.", __FUNCTION__, a_Item.m_ItemType);
+ return cBoat::bmOak;
+ }
+ }
+}
+
+
+
+
+
+AString cBoat::MaterialToString(eMaterial a_Material)
+{
+ switch (a_Material)
+ {
+ case bmOak: return "oak";
+ case bmSpruce: return "spruce";
+ case bmBirch: return "birch";
+ case bmJungle: return "jungle";
+ case bmAcacia: return "acacia";
+ case bmDarkOak: return "dark_oak";
+ }
+ ASSERT(!"Unhandled boat material");
+ #ifndef __clang__
+ return "oak";
+ #endif
+}
+
+
+
+
+
+cBoat::eMaterial cBoat::StringToMaterial(const AString & a_Material)
+{
+ if (a_Material == "oak")
+ {
+ return bmOak;
+ }
+ else if (a_Material == "spruce")
+ {
+ return bmSpruce;
+ }
+ else if (a_Material == "birch")
+ {
+ return bmBirch;
+ }
+ else if (a_Material == "jungle")
+ {
+ return bmJungle;
+ }
+ else if (a_Material == "acacia")
+ {
+ return bmAcacia;
+ }
+ else if (a_Material == "dark_oak")
+ {
+ return bmDarkOak;
+ }
+ else
+ {
+ return bmOak;
+ }
+}
+
+
+
+
+
+cItem cBoat::MaterialToItem(eMaterial a_Material)
+{
+ switch (a_Material)
+ {
+ case bmOak: return cItem(E_ITEM_BOAT);
+ case bmSpruce: return cItem(E_ITEM_SPRUCE_BOAT);
+ case bmBirch: return cItem(E_ITEM_BIRCH_BOAT);
+ case bmJungle: return cItem(E_ITEM_JUNGLE_BOAT);
+ case bmAcacia: return cItem(E_ITEM_ACACIA_BOAT);
+ case bmDarkOak: return cItem(E_ITEM_DARK_OAK_BOAT);
+ }
+ #ifndef __clang__
+ return cItem(E_ITEM_BOAT);
+ #endif
+}
+
+
+
+
diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h
index 5815ff88c..a6a99d683 100644
--- a/src/Entities/Boat.h
+++ b/src/Entities/Boat.h
@@ -13,7 +13,7 @@
-
+// tolua_begin
class cBoat :
public cEntity
@@ -21,6 +21,18 @@ class cBoat :
typedef cEntity super;
public:
+ enum eMaterial
+ {
+ bmOak,
+ bmSpruce,
+ bmBirch,
+ bmJungle,
+ bmAcacia,
+ bmDarkOak
+ };
+
+ // tolua_end
+
CLASS_PROTODEF(cBoat)
// cEntity overrides:
@@ -30,14 +42,34 @@ public:
virtual void Tick(std::chrono::milliseconds 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);
+ cBoat(double a_X, double a_Y, double a_Z, eMaterial a_Material);
int GetLastDamage(void) const { return m_LastDamage; }
int GetForwardDirection(void) const { return m_ForwardDirection; }
float GetDamageTaken(void) const { return m_DamageTaken; }
- int GetType(void) const { return m_Type; }
+ // tolua_begin
+
+ /** Returns the eMaterial of the boat */
+ eMaterial GetMaterial(void) const { return m_Material; }
+
+ /** Sets the eMaterial of the boat */
+ void SetMaterial(cBoat::eMaterial a_Material) { m_Material = a_Material; }
+
+ /** Returns the eMaterial that should be used for a boat created from the specified item. Returns bmOak if not a boat item */
+ static eMaterial ItemToMaterial(const cItem & a_Item);
+
+ /** Returns the boat item of the boat material */
+ static cItem MaterialToItem(eMaterial a_Material);
+
+ /** Returns the eMaterial as string */
+ static AString MaterialToString(const eMaterial a_Material);
+
+ /** Returns the boat material for the passed string. Returns oak if not valid */
+ static eMaterial StringToMaterial(const AString & a_Material);
+
+ // tolua_end
bool IsRightPaddleUsed(void) const { return m_RightPaddleUsed; }
bool IsLeftPaddleUsed(void) const { return m_LeftPaddleUsed; }
@@ -45,15 +77,14 @@ public:
void SetLastDamage(int TimeSinceLastHit);
void UpdatePaddles(bool rightPaddleUsed, bool leftPaddleUsed);
-
private:
int m_LastDamage;
int m_ForwardDirection;
float m_DamageTaken;
- int m_Type;
+ eMaterial m_Material;
bool m_RightPaddleUsed;
bool m_LeftPaddleUsed;
-} ;
+} ; // tolua_export