2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/Pawn.h"
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "../Defines.h"
|
|
|
|
#include "../BlockID.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../Item.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Vector3f;
|
|
|
|
class cClientHandle;
|
2013-08-16 04:48:19 -04:00
|
|
|
class cWorld;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
// tolua_begin
|
|
|
|
class cMonster :
|
|
|
|
public cPawn
|
|
|
|
{
|
|
|
|
typedef cPawn super;
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2013-08-16 04:48:19 -04:00
|
|
|
/// This identifies individual monster type, as well as their network type-ID
|
|
|
|
enum eType
|
|
|
|
{
|
2013-10-20 04:23:30 -04:00
|
|
|
mtInvalidType = -1,
|
|
|
|
|
2013-09-18 17:17:43 -04:00
|
|
|
mtBat = E_META_SPAWN_EGG_BAT,
|
|
|
|
mtBlaze = E_META_SPAWN_EGG_BLAZE,
|
|
|
|
mtCaveSpider = E_META_SPAWN_EGG_CAVE_SPIDER,
|
|
|
|
mtChicken = E_META_SPAWN_EGG_CHICKEN,
|
|
|
|
mtCow = E_META_SPAWN_EGG_COW,
|
2013-08-16 04:48:19 -04:00
|
|
|
mtCreeper = E_META_SPAWN_EGG_CREEPER,
|
2013-09-18 17:17:43 -04:00
|
|
|
mtEnderDragon = E_META_SPAWN_EGG_ENDER_DRAGON,
|
2013-08-16 04:48:19 -04:00
|
|
|
mtEnderman = E_META_SPAWN_EGG_ENDERMAN,
|
2013-09-18 17:17:43 -04:00
|
|
|
mtGhast = E_META_SPAWN_EGG_GHAST,
|
|
|
|
mtGiant = E_META_SPAWN_EGG_GIANT,
|
|
|
|
mtHorse = E_META_SPAWN_EGG_HORSE,
|
|
|
|
mtIronGolem = E_META_SPAWN_EGG_IRON_GOLEM,
|
2013-08-16 04:48:19 -04:00
|
|
|
mtMagmaCube = E_META_SPAWN_EGG_MAGMA_CUBE,
|
2013-09-18 17:17:43 -04:00
|
|
|
mtMooshroom = E_META_SPAWN_EGG_MOOSHROOM,
|
|
|
|
mtOcelot = E_META_SPAWN_EGG_OCELOT,
|
2013-08-16 04:48:19 -04:00
|
|
|
mtPig = E_META_SPAWN_EGG_PIG,
|
|
|
|
mtSheep = E_META_SPAWN_EGG_SHEEP,
|
2013-09-18 17:17:43 -04:00
|
|
|
mtSilverfish = E_META_SPAWN_EGG_SILVERFISH,
|
|
|
|
mtSkeleton = E_META_SPAWN_EGG_SKELETON,
|
|
|
|
mtSlime = E_META_SPAWN_EGG_SLIME,
|
2013-08-16 04:48:19 -04:00
|
|
|
mtSnowGolem = E_META_SPAWN_EGG_SNOW_GOLEM,
|
2013-09-18 17:17:43 -04:00
|
|
|
mtSpider = E_META_SPAWN_EGG_SPIDER,
|
|
|
|
mtSquid = E_META_SPAWN_EGG_SQUID,
|
2013-08-16 04:48:19 -04:00
|
|
|
mtVillager = E_META_SPAWN_EGG_VILLAGER,
|
2013-09-18 17:17:43 -04:00
|
|
|
mtWitch = E_META_SPAWN_EGG_WITCH,
|
|
|
|
mtWither = E_META_SPAWN_EGG_WITHER,
|
|
|
|
mtWolf = E_META_SPAWN_EGG_WOLF,
|
|
|
|
mtZombie = E_META_SPAWN_EGG_ZOMBIE,
|
|
|
|
mtZombiePigman = E_META_SPAWN_EGG_ZOMBIE_PIGMAN,
|
2013-08-16 04:48:19 -04:00
|
|
|
} ;
|
2013-09-07 14:02:50 -04:00
|
|
|
|
|
|
|
enum eFamily
|
|
|
|
{
|
|
|
|
mfHostile = 0, // Spider, Zombies ...
|
|
|
|
mfPassive = 1, // Cows, Pigs
|
|
|
|
mfAmbient = 2, // Bats
|
|
|
|
mfWater = 3, // Squid
|
2013-09-18 17:17:43 -04:00
|
|
|
|
2013-09-07 19:21:43 -04:00
|
|
|
mfMaxplusone, // Nothing. Be sure this is the last and the others are in order
|
2013-08-16 04:48:19 -04:00
|
|
|
} ;
|
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
// tolua_end
|
2013-08-16 04:48:19 -04:00
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
enum MState{ATTACKING, IDLE, CHASING, ESCAPING} m_EMState;
|
|
|
|
enum MPersonality{PASSIVE,AGGRESSIVE,COWARDLY} m_EMPersonality;
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
float m_SightDistance;
|
2012-12-21 06:04:08 -05:00
|
|
|
|
2012-12-22 04:39:13 -05:00
|
|
|
/** Creates the mob object.
|
|
|
|
* If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig()
|
2013-10-20 04:23:30 -04:00
|
|
|
* a_MobType is the type of the mob (also used in the protocol ( http://wiki.vg/Entities#Mobs , 2012_12_22))
|
2012-12-22 04:39:13 -05:00
|
|
|
* a_SoundHurt and a_SoundDeath are assigned into m_SoundHurt and m_SoundDeath, respectively
|
|
|
|
*/
|
2013-10-20 04:23:30 -04:00
|
|
|
cMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-21 07:21:20 -05:00
|
|
|
CLASS_PROTODEF(cMonster);
|
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
|
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
virtual void KilledBy(cEntity * a_Killer) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
virtual void MoveToPosition(const Vector3f & a_Position);
|
|
|
|
virtual bool ReachedDestination(void);
|
|
|
|
|
2013-10-20 04:23:30 -04:00
|
|
|
// tolua_begin
|
|
|
|
eType GetMobType(void) const {return m_MobType; }
|
2013-09-10 09:09:45 -04:00
|
|
|
eFamily GetMobFamily(void) const;
|
2013-10-20 04:23:30 -04:00
|
|
|
// tolua_end
|
2013-09-10 09:09:45 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
const char * GetState();
|
2012-08-19 15:42:32 -04:00
|
|
|
void SetState(const AString & str);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
virtual void CheckEventSeePlayer(void);
|
|
|
|
virtual void EventSeePlayer(cEntity * a_Player);
|
2012-12-21 06:04:08 -05:00
|
|
|
virtual cPlayer * FindClosestPlayer(); // non static is easier. also virtual so other mobs can implement their own searching algo
|
2012-12-22 04:39:13 -05:00
|
|
|
|
|
|
|
/// Reads the monster configuration for the specified monster name and assigns it to this object.
|
|
|
|
void GetMonsterConfig(const AString & a_Name);
|
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
virtual void EventLosePlayer(void);
|
2013-04-13 17:02:10 -04:00
|
|
|
virtual void CheckEventLostPlayer(void);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
virtual void InStateIdle (float a_Dt);
|
|
|
|
virtual void InStateChasing (float a_Dt);
|
|
|
|
virtual void InStateEscaping(float a_Dt);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
virtual void Attack(float a_Dt);
|
2013-09-16 05:42:20 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
int GetAttackRate(){return (int)m_AttackRate;}
|
|
|
|
void SetAttackRate(int ar);
|
|
|
|
void SetAttackRange(float ar);
|
|
|
|
void SetAttackDamage(float ad);
|
|
|
|
void SetSightDistance(float sd);
|
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
/// Sets whether the mob burns in daylight. Only evaluated at next burn-decision tick
|
2013-09-17 15:57:35 -04:00
|
|
|
void SetBurnsInDaylight(bool a_BurnsInDaylight) { m_BurnsInDaylight = a_BurnsInDaylight; }
|
2013-10-09 16:02:59 -04:00
|
|
|
|
|
|
|
// Overridables to handle ageable mobs
|
|
|
|
virtual bool IsBaby (void) const { return false; }
|
|
|
|
virtual bool IsTame (void) const { return false; }
|
|
|
|
virtual bool IsSitting (void) const { return false; }
|
2013-09-05 16:40:08 -04:00
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
// tolua_begin
|
|
|
|
|
2013-10-25 04:41:19 -04:00
|
|
|
/// Translates MobType enum to a string, empty string if unknown
|
2013-10-20 07:25:56 -04:00
|
|
|
static AString MobTypeToString(eType a_MobType);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-10-25 04:41:19 -04:00
|
|
|
/// Translates MobType string to the enum, mtInvalidType if not recognized
|
2013-10-20 07:25:56 -04:00
|
|
|
static eType StringToMobType(const AString & a_MobTypeName);
|
|
|
|
|
|
|
|
/// Returns the mob family based on the type
|
|
|
|
static eFamily FamilyFromType(eType a_MobType);
|
2013-10-20 08:00:45 -04:00
|
|
|
|
2013-10-24 10:45:13 -04:00
|
|
|
/// Returns the spawn delay (number of game ticks between spawn attempts) for the given mob family
|
|
|
|
static int GetSpawnDelay(cMonster::eFamily a_MobFamily);
|
2013-10-20 07:25:56 -04:00
|
|
|
|
|
|
|
// tolua_end
|
|
|
|
|
|
|
|
/** Creates a new object of the specified mob.
|
|
|
|
a_MobType is the type of the mob to be created
|
2013-11-10 15:48:12 -05:00
|
|
|
Asserts and returns null if mob type is not specified
|
2013-10-20 07:25:56 -04:00
|
|
|
*/
|
2013-11-10 15:48:12 -05:00
|
|
|
static cMonster * NewMonsterFromType(eType a_MobType);
|
2013-10-20 07:25:56 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
protected:
|
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
cEntity * m_Target;
|
2012-06-14 09:06:06 -04:00
|
|
|
float m_AttackRate;
|
|
|
|
float idle_interval;
|
|
|
|
|
|
|
|
Vector3f m_Destination;
|
|
|
|
bool m_bMovingToDestination;
|
|
|
|
bool m_bPassiveAggressive;
|
|
|
|
|
|
|
|
float m_DestinationTime;
|
|
|
|
|
|
|
|
float m_DestroyTimer;
|
|
|
|
float m_Jump;
|
|
|
|
|
2013-10-20 04:23:30 -04:00
|
|
|
eType m_MobType;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-21 13:05:34 -05:00
|
|
|
AString m_SoundHurt;
|
|
|
|
AString m_SoundDeath;
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
float m_SeePlayerInterval;
|
|
|
|
float m_AttackDamage;
|
|
|
|
float m_AttackRange;
|
|
|
|
float m_AttackInterval;
|
2013-09-05 16:40:08 -04:00
|
|
|
|
|
|
|
bool m_BurnsInDaylight;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0);
|
2013-09-05 16:40:08 -04:00
|
|
|
|
|
|
|
void HandleDaylightBurning(cChunk & a_Chunk);
|
2013-10-09 16:02:59 -04:00
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
} ; // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|