summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Monster.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-24 20:57:32 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-24 20:57:32 +0100
commit9c0e3615ce61dba0ae973b97807833bd6ddd5bda (patch)
treef19c645c9d41539064cb23b0448ed7794114c5d9 /src/Mobs/Monster.h
parentFixed mobs too close to player not ticking (diff)
downloadcuberite-9c0e3615ce61dba0ae973b97807833bd6ddd5bda.tar
cuberite-9c0e3615ce61dba0ae973b97807833bd6ddd5bda.tar.gz
cuberite-9c0e3615ce61dba0ae973b97807833bd6ddd5bda.tar.bz2
cuberite-9c0e3615ce61dba0ae973b97807833bd6ddd5bda.tar.lz
cuberite-9c0e3615ce61dba0ae973b97807833bd6ddd5bda.tar.xz
cuberite-9c0e3615ce61dba0ae973b97807833bd6ddd5bda.tar.zst
cuberite-9c0e3615ce61dba0ae973b97807833bd6ddd5bda.zip
Diffstat (limited to 'src/Mobs/Monster.h')
-rw-r--r--src/Mobs/Monster.h68
1 files changed, 49 insertions, 19 deletions
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index dafb33574..5f32650cf 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -10,7 +10,6 @@
-class Vector3f;
class cClientHandle;
class cWorld;
@@ -74,8 +73,6 @@ public:
enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState;
enum MPersonality{PASSIVE,AGGRESSIVE,COWARDLY} m_EMPersonality;
- float m_SightDistance;
-
/** Creates the mob object.
* If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig()
* a_MobType is the type of the mob (also used in the protocol ( http://wiki.vg/Entities#Mobs , 2012_12_22))
@@ -100,14 +97,9 @@ public:
eType GetMobType(void) const {return m_MobType; }
eFamily GetMobFamily(void) const;
// tolua_end
-
-
- const char * GetState();
- void SetState(const AString & str);
virtual void CheckEventSeePlayer(void);
virtual void EventSeePlayer(cEntity * a_Player);
- virtual cPlayer * FindClosestPlayer(); // non static is easier. also virtual so other mobs can implement their own searching algo
/// Reads the monster configuration for the specified monster name and assigns it to this object.
void GetMonsterConfig(const AString & a_Name);
@@ -121,11 +113,11 @@ public:
virtual void Attack(float a_Dt);
- int GetAttackRate(){return (int)m_AttackRate;}
- void SetAttackRate(int ar);
- void SetAttackRange(float ar);
- void SetAttackDamage(float ad);
- void SetSightDistance(float sd);
+ int GetAttackRate() { return (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; }
/// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick
void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; }
@@ -159,34 +151,72 @@ public:
protected:
+ /* ======= PATHFINDING ======= */
+
+ /** A pointer to the entity this mobile is aiming to reach */
cEntity * m_Target;
+ /** Coordinates of the next position that should be reached */
+ Vector3d m_Destination;
+ /** Coordinates for the ultimate, final destination. */
+ Vector3d m_FinalDestination;
+ /** Returns if the ultimate, final destination has been reached */
+ bool ReachedFinalDestination(void);
+
+ /** Stores if mobile is currently moving towards the ultimate, final destination */
+ bool m_bMovingToDestination;
+ /** Finds the first non-air block position (not the highest, as cWorld::GetHeight does)
+ If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1
+ If current Y is solid, goes up to find first nonsolid block, and returns that */
+ int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ);
+
+ /** A semi-temporary list to store the traversed coordinates during active pathfinding so we don't visit them again */
+ std::vector<Vector3i> m_TraversedCoordinates;
+ /** Returns if coordinate is in the traversed list */
+ bool IsCoordinateInTraversedList(Vector3i a_Coords);
+
+ /** Finds the next place to go
+ This is based on the ultimate, final destination and the current position, as well as the traversed coordinates, and any environmental hazards */
+ void TickPathFinding(void);
+ /** Finishes a pathfinding task, be it due to failure or something else */
+ inline void FinishPathFinding(void)
+ {
+ m_TraversedCoordinates.clear();
+ m_bMovingToDestination = false;
+ }
+ /** Sets the body yaw and head yaw/pitch based on next/ultimate destinations */
+ void SetPitchAndYawFromDestination(void);
+
+ /* ===========================*/
+
float m_AttackRate;
float m_IdleInterval;
- Vector3f m_Destination;
- bool m_bMovingToDestination;
+
bool m_bPassiveAggressive;
float m_DestinationTime;
float m_DestroyTimer;
- float m_Jump;
eType m_MobType;
AString m_SoundHurt;
AString m_SoundDeath;
- float m_SeePlayerInterval;
- float m_AttackDamage;
- float m_AttackRange;
+ int m_AttackDamage;
+ int m_AttackRange;
float m_AttackInterval;
+ int m_SightDistance;
bool m_BurnsInDaylight;
void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0);
void HandleDaylightBurning(cChunk & a_Chunk);
+ inline bool IsNextYPosReachable(int a_PosY)
+ {
+ return (a_PosY > (int)floor(GetPosY())) && (a_PosY == (int)floor(GetPosY()) + 1);
+ }
} ; // tolua_export