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"
2014-02-23 13:44:58 -05:00
# include "../Enchantments.h"
2012-06-14 09:06:06 -04:00
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
{
2014-07-17 16:15:34 -04:00
mfHostile = 0 , // Spider, Zombies ...
mfPassive = 1 , // Cows, Pigs
mfAmbient = 2 , // Bats
mfWater = 3 , // Squid
2013-09-18 17:17:43 -04:00
2014-04-25 23:49:55 -04:00
mfNoSpawn ,
2014-07-17 16:15:34 -04:00
mfUnhandled , // 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 ;
2014-07-19 08:53:41 -04:00
enum MPersonality { PASSIVE , AGGRESSIVE , COWARDLY } m_EMPersonality ;
2013-10-20 07:25:56 -04:00
2012-12-22 04:39:13 -05:00
/** Creates the mob object.
2014-07-18 03:57:34 -04:00
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))
a_SoundHurt and a_SoundDeath are assigned into m_SoundHurt and m_SoundDeath , respectively
2012-12-22 04:39:13 -05:00
*/
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
2014-07-22 18:36:13 -04:00
CLASS_PROTODEF ( cMonster )
2012-12-21 07:21:20 -05:00
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
2014-04-25 18:32:30 -04:00
virtual bool DoTakeDamage ( TakeDamageInfo & a_TDI ) override ;
2012-12-21 06:04:08 -05:00
2014-07-04 05:55:09 -04:00
virtual void KilledBy ( TakeDamageInfo & a_TDI ) override ;
2012-06-14 09:06:06 -04:00
2014-07-17 16:15:34 -04:00
virtual void MoveToPosition ( const Vector3d & a_Position ) ; // tolua_export
2012-08-24 03:58:26 -04:00
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
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-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 ) ;
2014-06-08 21:44:20 -04:00
/** Returns whether this mob is undead (skeleton, zombie, etc.) */
2014-07-19 17:35:35 -04:00
virtual bool IsUndead ( void ) ;
2014-06-08 21:44:20 -04:00
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
2014-01-24 14:57:32 -05:00
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 ; }
2012-06-14 09:06:06 -04:00
2014-02-23 13:44:58 -05:00
float GetDropChanceWeapon ( ) { return m_DropChanceWeapon ; }
float GetDropChanceHelmet ( ) { return m_DropChanceHelmet ; }
float GetDropChanceChestplate ( ) { return m_DropChanceChestplate ; }
float GetDropChanceLeggings ( ) { return m_DropChanceLeggings ; }
float GetDropChanceBoots ( ) { return m_DropChanceBoots ; }
bool CanPickUpLoot ( ) { return m_CanPickUpLoot ; }
void SetDropChanceWeapon ( float a_DropChanceWeapon ) { m_DropChanceWeapon = a_DropChanceWeapon ; }
void SetDropChanceHelmet ( float a_DropChanceHelmet ) { m_DropChanceHelmet = a_DropChanceHelmet ; }
void SetDropChanceChestplate ( float a_DropChanceChestplate ) { m_DropChanceChestplate = a_DropChanceChestplate ; }
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 ; }
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 :
2014-01-24 14:57:32 -05:00
/* ======= PATHFINDING ======= */
/** A pointer to the entity this mobile is aiming to reach */
2012-12-21 06:04:08 -05:00
cEntity * m_Target ;
2014-01-24 14:57:32 -05:00
/** 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 ;
2014-06-08 21:44:20 -04:00
2014-01-24 14:57:32 -05:00
/** 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 ) ;
2014-01-25 09:42:26 -05:00
/** Returns if a monster can actually reach a given height by jumping or walking */
2014-01-24 16:55:04 -05:00
inline bool IsNextYPosReachable ( int a_PosY )
{
2014-01-25 09:42:26 -05:00
return (
2014-04-17 13:50:25 -04:00
( a_PosY < = POSY_TOINT ) | |
2014-01-25 09:42:26 -05:00
DoesPosYRequireJump ( a_PosY )
) ;
}
/** Returns if a monster can reach a given height by jumping */
inline bool DoesPosYRequireJump ( int a_PosY )
{
2014-04-17 13:50:25 -04:00
return ( ( a_PosY > POSY_TOINT ) & & ( a_PosY = = POSY_TOINT + 1 ) ) ;
2014-01-24 16:55:04 -05:00
}
2014-01-24 14:57:32 -05:00
/** 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 ) ;
2014-01-25 14:02:13 -05:00
/* =========================== */
/* ========= FALLING ========= */
2014-01-24 14:57:32 -05:00
2014-01-25 14:02:13 -05:00
virtual void HandleFalling ( void ) ;
int m_LastGroundHeight ;
/* =========================== */
2012-06-14 09:06:06 -04:00
2014-01-24 16:55:04 -05:00
float m_IdleInterval ;
2012-06-14 09:06:06 -04:00
float m_DestroyTimer ;
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 ;
2014-07-17 16:50:58 -04:00
float m_AttackRate ;
2014-01-24 14:57:32 -05:00
int m_AttackDamage ;
int m_AttackRange ;
2012-06-14 09:06:06 -04:00
float m_AttackInterval ;
2014-01-24 14:57:32 -05:00
int m_SightDistance ;
2013-09-05 16:40:08 -04:00
2014-02-23 13:44:58 -05:00
float m_DropChanceWeapon ;
float m_DropChanceHelmet ;
float m_DropChanceChestplate ;
float m_DropChanceLeggings ;
float m_DropChanceBoots ;
bool m_CanPickUpLoot ;
2014-01-24 16:55:04 -05:00
void HandleDaylightBurning ( cChunk & a_Chunk ) ;
2013-09-05 16:40:08 -04:00
bool m_BurnsInDaylight ;
2012-06-14 09:06:06 -04:00
2014-02-23 13:44:58 -05:00
/** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops*/
2014-07-17 16:50:58 -04:00
void AddRandomDropItem ( cItems & a_Drops , unsigned int a_Min , unsigned int a_Max , short a_Item , short a_ItemHealth = 0 ) ;
2014-02-23 13:44:58 -05:00
/** Adds a item a_Item with the chance of a_Chance (in percent) to itemdrops a_Drops*/
2014-07-17 16:50:58 -04:00
void AddRandomUncommonDropItem ( cItems & a_Drops , float a_Chance , short a_Item , short a_ItemHealth = 0 ) ;
2014-02-23 13:44:58 -05:00
/** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/
2014-07-17 16:50:58 -04:00
void AddRandomRareDropItem ( cItems & a_Drops , cItems & a_Items , short a_LootingLevel ) ;
2014-02-23 13:44:58 -05:00
2014-02-24 09:38:38 -05:00
/** Adds armor that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if piccked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop*/
2014-02-23 13:44:58 -05:00
void AddRandomArmorDropItem ( cItems & a_Drops , short a_LootingLevel ) ;
2014-02-24 09:38:38 -05:00
/** Adds weapon that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if piccked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop*/
2014-02-23 13:44:58 -05:00
void AddRandomWeaponDropItem ( cItems & a_Drops , short a_LootingLevel ) ;
2013-10-09 16:02:59 -04:00
2014-07-17 16:15:34 -04:00
} ; // tolua_export
2012-06-14 09:06:06 -04:00