summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Monster.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Mobs/Monster.h120
1 files changed, 72 insertions, 48 deletions
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 1f6bd6011..760edb0e9 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -4,12 +4,23 @@
#include "../Entities/Pawn.h"
#include "MonsterTypes.h"
#include "PathFinder.h"
-
+#include "Behaviors/BehaviorWanderer.h"
+#include "MobPointer.h"
+#include <vector>
class cItem;
class cClientHandle;
+//Behavior fwds
+class cPassiveMonster;
+class cBehaviorAggressive;
+class cBehaviorBreeder;
+class cBehaviorAttacker;
+class cBehaviorStriker;
+class cBehaviorWanderer;
+class cBehaviorDayLightBurner;
+class cBehavior;
// tolua_begin
class cMonster :
@@ -31,7 +42,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 +79,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 +116,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 +131,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
@@ -193,14 +186,7 @@ public:
static AString MobTypeToVanillaNBT(eMonsterType a_MobType);
/** Sets the target that this mob will chase. Pass a nullptr to unset. */
- void SetTarget (cPawn * a_NewTarget);
-
- /** Unset the target without notifying the target entity. Do not use this, use SetTarget(nullptr) instead.
- This is only used by cPawn internally. */
- void UnsafeUnsetTarget();
-
- /** Returns the current target. */
- cPawn * GetTarget();
+ void SetLookingAt(cPawn * a_NewTarget);
/** Creates a new object of the specified mob.
a_MobType is the type of the mob to be created
@@ -211,8 +197,51 @@ public:
/** Returns if this mob last target was a player to avoid destruction on player quit */
bool WasLastTargetAPlayer() const { return m_WasLastTargetAPlayer; }
+ bool IsPathFinderActivated() const;
+
+ // Behavior getters (most are probably not used. mobTodo - cleanup most of them)
+ cBehaviorBreeder * GetBehaviorBreeder();
+ const cBehaviorBreeder * GetBehaviorBreeder() const;
+ cBehaviorAttacker * GetBehaviorAttacker();\
+ cBehaviorBreeder * m_BehaviorBreederPointer;
+ cBehaviorAttacker * m_BehaviorAttackerPointer;
+
+ // Polymorphic behavior functions
+ 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);
+
+ /** If a behavior calls this within its tick, it will be the only behavior
+ that gets to tick until UnpinBehavior is called. ControlDesired will no
+ longer be called for any tick until unpinning is done. MUST be called
+ from the tick function of a behavior. */
+ void PinBehavior(cBehavior * a_Behavior);
+
+ /** Unpins the behavior and ticking goes back to normal. MUST be called
+ on the same behavior pointer that called PinBehavior. */
+ void UnpinBehavior(cBehavior * a_Behavior);
+
+ /** Returns a reference to this mob's pathfinder. Typically used by behaviors
+ to tweak pathfinding behavior as they gain or release control of the mob. */
+ cPathFinder & GetPathFinder();
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 +263,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 +290,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 +298,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;
@@ -320,12 +334,22 @@ protected:
void AddRandomWeaponDropItem(cItems & a_Drops, unsigned int a_LootingLevel);
private:
- /** A pointer to the entity this mobile is aiming to reach.
- The validity of this pointer SHALL be guaranteed by the pointee;
- it MUST be reset when the pointee changes worlds or is destroyed. */
- cPawn * m_Target;
+ /** A pointer to the entity this mobile is lookingAt */
+ cMobPointer m_LookingAt;
/** 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;
+ cBehavior * m_PinnedBehavior;
+ enum TickState{NewControlStarting, OldControlEnding, Normal} m_TickControllingBehaviorState;
+
} ; // tolua_export