Cuberite
A lightweight, fast and extensible game server for Minecraft
Squid.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
3 
4 #include "Squid.h"
5 #include "../Chunk.h"
6 
7 
8 
9 
10 
12  Super("Squid", mtSquid, "entity.squid.hurt", "entity.squid.death", "entity.squid.ambient", 0.8f, 0.8f)
13 {
14 }
15 
16 
17 
18 
19 
20 void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer)
21 {
22  // Drops 0-3 Ink Sacs
23  unsigned int LootingLevel = 0;
24  if (a_Killer != nullptr)
25  {
27  }
28  AddRandomDropItem(a_Drops, 0, 3 + LootingLevel, E_ITEM_DYE, E_META_DYE_BLACK);
29 }
30 
31 
32 
33 
34 
35 void cSquid::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
36 {
37  m_PathfinderActivated = false; // Disable Pathfinding until it's fixed. TODO
38 
39  // We must first process current location, and only then tick, otherwise we risk processing a location in a chunk
40  // that is not where the entity currently resides (FS #411)
41  Vector3d Pos = GetPosition();
42 
43  // TODO: Not a real behavior, but cool :D
44  int RelY = FloorC(Pos.y);
45  if ((RelY < 0) || (RelY >= cChunkDef::Height))
46  {
47  return;
48  }
49 
50  if (!IsHeadInWater())
51  {
52  if (m_AirLevel <= 0)
53  {
54  // Runs the air tick timer to check whether the squid should be damaged
55  if (m_AirTickTimer <= 0)
56  {
57  // Damage squid
58  TakeDamage(dtSuffocating, nullptr, 1, 1, 0);
59  // Reset timer
61  }
62  else
63  {
65  }
66  }
67  else
68  {
69  // Reduce air supply
70  m_AirLevel--;
71  }
72  }
73  else
74  {
75  // Set the air back to maximum
78  }
79 
80  Super::Tick(a_Dt, a_Chunk);
81 }
@ E_ITEM_DYE
Definition: BlockType.h:396
@ E_META_DYE_BLACK
Definition: BlockType.h:1045
@ dtSuffocating
Definition: Defines.h:251
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
Definition: Globals.h:347
@ mtSquid
Definition: MonsterTypes.h:64
Definition: Chunk.h:36
static const int Height
Definition: ChunkDef.h:125
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
Definition: Entity.h:76
int m_AirLevel
Air level of a mobile.
Definition: Entity.h:660
virtual bool IsHeadInWater(void) const
Returns true if any part of the entity is in a water block.
Definition: Entity.h:504
int m_AirTickTimer
Definition: Entity.h:661
void TakeDamage(cEntity &a_Attacker)
Makes this pawn take damage from an attack by a_Attacker.
Definition: Entity.cpp:272
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:333
static const int DROWNING_TICKS
Number of ticks per heart of damage.
Definition: Entity.h:122
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
static const int MAX_AIR_LEVEL
Maximum air an entity can have.
Definition: Entity.h:121
cEnchantments m_Enchantments
Definition: Item.h:166
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
void AddRandomDropItem(cItems &a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth=0)
Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops.
Definition: Monster.cpp:1518
bool m_PathfinderActivated
Stores if pathfinder is being used - set when final destination is set, and unset when stopped moving...
Definition: Monster.h:258
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
cSquid()
Definition: Squid.cpp:11
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: Squid.cpp:20
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Squid.cpp:35
T y
Definition: Vector3.h:17