summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Monster.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs/Monster.h')
-rw-r--r--src/Mobs/Monster.h93
1 files changed, 56 insertions, 37 deletions
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 1f6bd6011..44497723c 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -4,12 +4,21 @@
#include "../Entities/Pawn.h"
#include "MonsterTypes.h"
#include "PathFinder.h"
-
+#include <vector>
class cItem;
class cClientHandle;
+//Behavior fwds
+class cPassiveMonster;
+class cBehaviorAggressive;
+class cBehaviorBreeder;
+class cBehaviorChaser;
+class cBehaviorStriker;
+class cBehaviorWanderer;
+class cBehaviorDayLightBurner;
+class cBehavior;
// tolua_begin
class cMonster :
@@ -31,7 +40,6 @@ public:
// tolua_end
- enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState;
enum MPersonality{PASSIVE, AGGRESSIVE, COWARDLY} m_EMPersonality;
/** Creates the mob object.
@@ -69,9 +77,6 @@ public:
eFamily GetMobFamily(void) const;
// tolua_end
- virtual void CheckEventSeePlayer(cChunk & a_Chunk);
- virtual void EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk);
-
// tolua_begin
/** Returns whether the mob can be leashed. */
@@ -109,18 +114,8 @@ public:
/** Returns whether this mob is undead (skeleton, zombie, etc.) */
virtual bool IsUndead(void);
- virtual void EventLosePlayer(void);
- virtual void CheckEventLostPlayer(void);
-
- virtual void InStateIdle (std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
- virtual void InStateChasing (std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
- virtual void InStateEscaping(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
-
- int GetAttackRate() { return static_cast<int>(m_AttackRate); }
- void SetAttackRate(float a_AttackRate) { m_AttackRate = a_AttackRate; }
- void SetAttackRange(int a_AttackRange) { m_AttackRange = a_AttackRange; }
- void SetAttackDamage(int a_AttackDamage) { m_AttackDamage = a_AttackDamage; }
void SetSightDistance(int a_SightDistance) { m_SightDistance = a_SightDistance; }
+ int GetSightDistance() { return m_SightDistance; }
float GetDropChanceWeapon() { return m_DropChanceWeapon; }
float GetDropChanceHelmet() { return m_DropChanceHelmet; }
@@ -134,10 +129,6 @@ public:
void SetDropChanceLeggings(float a_DropChanceLeggings) { m_DropChanceLeggings = a_DropChanceLeggings; }
void SetDropChanceBoots(float a_DropChanceBoots) { m_DropChanceBoots = a_DropChanceBoots; }
void SetCanPickUpLoot(bool a_CanPickUpLoot) { m_CanPickUpLoot = a_CanPickUpLoot; }
- void ResetAttackCooldown();
-
- /** Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick */
- void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; }
double GetRelativeWalkSpeed(void) const { return m_RelativeWalkSpeed; } // tolua_export
void SetRelativeWalkSpeed(double a_WalkSpeed) { m_RelativeWalkSpeed = a_WalkSpeed; } // tolua_export
@@ -211,7 +202,39 @@ public:
/** Returns if this mob last target was a player to avoid destruction on player quit */
bool WasLastTargetAPlayer() const { return m_WasLastTargetAPlayer; }
-protected:
+ bool IsPathFinderActivated() const;
+
+ // Behavior getters (most are probably not used. mobTodo - cleanup most of them)
+ virtual cBehaviorAggressive * GetBehaviorAggressive();
+ virtual cBehaviorBreeder * GetBehaviorBreeder();
+ virtual const cBehaviorBreeder * GetBehaviorBreeder() const;
+ virtual cBehaviorChaser * GetBehaviorChaser();
+ virtual cBehaviorStriker * GetBehaviorStriker();
+ virtual cBehaviorWanderer * GetBehaviorWanderer();
+ virtual cBehaviorDayLightBurner * GetBehaviorDayLightBurner();
+
+ // Polymorphic behavior functions ("Skin-specific")
+ virtual void InheritFromParents(cMonster * a_Parent1, cMonster * a_Parent2);
+ virtual void GetFollowedItems(cItems & a_Items);
+ virtual void GetBreedingItems(cItems & a_Items);
+
+ cPlayer * GetNearestPlayer();
+
+ // These should only be called from cBehavior::attachToMonster
+ void AttachPreTickBehavior(cBehavior * a_Behavior);
+ void AttachPostTickBehavior(cBehavior * a_Behavior);
+ void AttachTickBehavior(cBehavior * a_Behavior);
+ void AttachDestroyBehavior(cBehavior * a_Behavior);
+ void AttachRightClickBehavior(cBehavior * a_Behavior);
+ void AttachDoTakeDamageBehavior(cBehavior * a_Behavior);
+
+ protected:
+
+ /** Whether or not m_NearestPlayer is stale. Always true at the beginning of a tick.
+ When true, GetNearestPlayer() actually searches for a player, updates m_NearestPlayer, and sets it to false.
+ otherwise it returns m_NearestPlayer. This means we only perform 1 search per tick. */
+ bool m_NearestPlayerIsStale;
+ cPlayer * m_NearestPlayer;
/** The pathfinder instance handles pathfinding for this monster. */
cPathFinder m_PathFinder;
@@ -234,13 +257,6 @@ protected:
/** Returns if the ultimate, final destination has been reached. */
bool ReachedFinalDestination(void) { return ((m_FinalDestination - GetPosition()).SqrLength() < WAYPOINT_RADIUS * WAYPOINT_RADIUS); }
- /** Returns whether or not the target is close enough for attack. */
- bool TargetIsInRange(void)
- {
- ASSERT(GetTarget() != nullptr);
- return ((GetTarget()->GetPosition() - GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange));
- }
-
/** Returns whether the monster needs to jump to reach a given height. */
inline bool DoesPosYRequireJump(double a_PosY)
{
@@ -268,11 +284,7 @@ protected:
AString m_SoundHurt;
AString m_SoundDeath;
- float m_AttackRate;
- int m_AttackDamage;
- int m_AttackRange;
- int m_AttackCoolDownTicksLeft;
- int m_SightDistance;
+ int m_SightDistance; // mobTodo what to do with this?
float m_DropChanceWeapon;
float m_DropChanceHelmet;
@@ -280,11 +292,7 @@ protected:
float m_DropChanceLeggings;
float m_DropChanceBoots;
bool m_CanPickUpLoot;
- int m_TicksSinceLastDamaged; // How many ticks ago we were last damaged by a player?
- void HandleDaylightBurning(cChunk & a_Chunk, bool WouldBurn);
- bool WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk);
- bool m_BurnsInDaylight;
double m_RelativeWalkSpeed;
int m_Age;
@@ -328,4 +336,15 @@ private:
/** Leash calculations inside Tick function */
void CalcLeashActions();
+ std::vector<cBehavior*> m_AttachedPreTickBehaviors;
+ std::vector<cBehavior*> m_AttachedTickBehaviors;
+ std::vector<cBehavior*> m_AttachedPostTickBehaviors;
+ std::vector<cBehavior*> m_AttachedDestroyBehaviors;
+ std::vector<cBehavior*> m_AttachedOnRightClickBehaviors;
+ std::vector<cBehavior*> m_AttachedDoTakeDamageBehaviors;
+
+ cBehavior * m_CurrentTickControllingBehavior;
+ cBehavior * m_NewTickControllingBehavior;
+ enum TickState{NewControlStarting, OldControlEnding, Normal} m_TickControllingBehaviorState;
+
} ; // tolua_export