2014-04-10 10:52:00 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
#include "IncludeAllMonsters.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../Root.h"
|
|
|
|
#include "../Server.h"
|
|
|
|
#include "../ClientHandle.h"
|
|
|
|
#include "../World.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/Player.h"
|
2013-11-25 14:04:39 -05:00
|
|
|
#include "../Entities/ExpOrb.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../MonsterConfig.h"
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "../MersenneTwister.h"
|
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
#include "../Chunk.h"
|
2013-10-20 07:25:56 -04:00
|
|
|
#include "../FastRandom.h"
|
2013-04-22 03:18:03 -04:00
|
|
|
|
2013-09-10 09:09:45 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
/** Map for eType <-> string
|
|
|
|
Needs to be alpha-sorted by the strings, because binary search is used in StringToMobType()
|
|
|
|
The strings need to be lowercase (for more efficient comparisons in StringToMobType())
|
|
|
|
*/
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
cMonster::eType m_Type;
|
|
|
|
const char * m_lcName;
|
|
|
|
} g_MobTypeNames[] =
|
|
|
|
{
|
|
|
|
{cMonster::mtBat, "bat"},
|
|
|
|
{cMonster::mtBlaze, "blaze"},
|
|
|
|
{cMonster::mtCaveSpider, "cavespider"},
|
|
|
|
{cMonster::mtChicken, "chicken"},
|
|
|
|
{cMonster::mtCow, "cow"},
|
|
|
|
{cMonster::mtCreeper, "creeper"},
|
|
|
|
{cMonster::mtEnderman, "enderman"},
|
2013-12-23 04:32:49 -05:00
|
|
|
{cMonster::mtEnderDragon, "enderdragon"},
|
2013-10-20 07:25:56 -04:00
|
|
|
{cMonster::mtGhast, "ghast"},
|
|
|
|
{cMonster::mtHorse, "horse"},
|
2013-12-23 04:32:49 -05:00
|
|
|
{cMonster::mtIronGolem, "irongolem"},
|
2013-10-20 07:25:56 -04:00
|
|
|
{cMonster::mtMagmaCube, "magmacube"},
|
|
|
|
{cMonster::mtMooshroom, "mooshroom"},
|
|
|
|
{cMonster::mtOcelot, "ocelot"},
|
|
|
|
{cMonster::mtPig, "pig"},
|
|
|
|
{cMonster::mtSheep, "sheep"},
|
|
|
|
{cMonster::mtSilverfish, "silverfish"},
|
|
|
|
{cMonster::mtSkeleton, "skeleton"},
|
2013-12-23 04:32:49 -05:00
|
|
|
{cMonster::mtSnowGolem, "snowgolem"},
|
2013-10-20 07:25:56 -04:00
|
|
|
{cMonster::mtSlime, "slime"},
|
|
|
|
{cMonster::mtSpider, "spider"},
|
|
|
|
{cMonster::mtSquid, "squid"},
|
|
|
|
{cMonster::mtVillager, "villager"},
|
|
|
|
{cMonster::mtWitch, "witch"},
|
2013-12-23 04:32:49 -05:00
|
|
|
{cMonster::mtWither, "wither"},
|
2013-10-20 07:25:56 -04:00
|
|
|
{cMonster::mtWolf, "wolf"},
|
|
|
|
{cMonster::mtZombie, "zombie"},
|
|
|
|
{cMonster::mtZombiePigman, "zombiepigman"},
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cMonster:
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-10-20 04:23:30 -04:00
|
|
|
cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height)
|
2013-10-13 07:47:55 -04:00
|
|
|
: super(etMonster, a_Width, a_Height)
|
2013-12-20 10:39:20 -05:00
|
|
|
, m_EMState(IDLE)
|
|
|
|
, m_EMPersonality(AGGRESSIVE)
|
2012-12-21 07:52:14 -05:00
|
|
|
, m_Target(NULL)
|
2012-06-14 09:06:06 -04:00
|
|
|
, m_bMovingToDestination(false)
|
2014-02-05 12:43:49 -05:00
|
|
|
, m_LastGroundHeight(POSY_TOINT)
|
|
|
|
, m_IdleInterval(0)
|
2014-01-24 16:55:04 -05:00
|
|
|
, m_DestroyTimer(0)
|
2013-10-20 04:23:30 -04:00
|
|
|
, m_MobType(a_MobType)
|
2012-12-22 04:39:13 -05:00
|
|
|
, m_SoundHurt(a_SoundHurt)
|
|
|
|
, m_SoundDeath(a_SoundDeath)
|
2014-02-05 12:43:49 -05:00
|
|
|
, m_AttackRate(3)
|
2014-01-24 16:55:04 -05:00
|
|
|
, m_AttackDamage(1)
|
|
|
|
, m_AttackRange(2)
|
2012-06-14 09:06:06 -04:00
|
|
|
, m_AttackInterval(0)
|
2014-02-24 09:38:38 -05:00
|
|
|
, m_SightDistance(25)
|
2014-03-16 17:00:28 -04:00
|
|
|
, m_DropChanceWeapon(0.085f)
|
|
|
|
, m_DropChanceHelmet(0.085f)
|
|
|
|
, m_DropChanceChestplate(0.085f)
|
|
|
|
, m_DropChanceLeggings(0.085f)
|
|
|
|
, m_DropChanceBoots(0.085f)
|
2014-02-23 13:44:58 -05:00
|
|
|
, m_CanPickUpLoot(true)
|
2013-09-07 10:42:34 -04:00
|
|
|
, m_BurnsInDaylight(false)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-22 04:39:13 -05:00
|
|
|
if (!a_ConfigName.empty())
|
|
|
|
{
|
|
|
|
GetMonsterConfig(a_ConfigName);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
void cMonster::SpawnOn(cClientHandle & a_Client)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-24 03:58:26 -04:00
|
|
|
a_Client.SendSpawnMob(*this);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
void cMonster::TickPathFinding()
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-04-17 13:50:25 -04:00
|
|
|
const int PosX = POSX_TOINT;
|
|
|
|
const int PosY = POSY_TOINT;
|
|
|
|
const int PosZ = POSZ_TOINT;
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
m_FinalDestination.y = (double)FindFirstNonAirBlockPosition(m_FinalDestination.x, m_FinalDestination.z);
|
|
|
|
|
|
|
|
std::vector<Vector3d> m_PotentialCoordinates;
|
|
|
|
m_TraversedCoordinates.push_back(Vector3i(PosX, PosY, PosZ));
|
|
|
|
|
2014-01-25 14:02:13 -05:00
|
|
|
static const struct // Define which directions to try to move to
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
|
|
|
int x, z;
|
|
|
|
} gCrossCoords[] =
|
|
|
|
{
|
|
|
|
{ 1, 0},
|
|
|
|
{-1, 0},
|
|
|
|
{ 0, 1},
|
|
|
|
{ 0,-1},
|
|
|
|
} ;
|
2014-03-31 17:37:05 -04:00
|
|
|
|
|
|
|
if ((PosY - 1 < 0) || (PosY + 2 > cChunkDef::Height) /* PosY + 1 will never be true if PosY + 2 is not */)
|
|
|
|
{
|
|
|
|
// Too low/high, can't really do anything
|
|
|
|
FinishPathFinding();
|
|
|
|
return;
|
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
|
|
|
|
{
|
|
|
|
if (IsCoordinateInTraversedList(Vector3i(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ)))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLOCKTYPE BlockAtY = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY, gCrossCoords[i].z + PosZ);
|
|
|
|
BLOCKTYPE BlockAtYP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 1, gCrossCoords[i].z + PosZ);
|
|
|
|
BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ);
|
2014-04-17 13:50:25 -04:00
|
|
|
int LowestY = FindFirstNonAirBlockPosition(gCrossCoords[i].x + PosX, gCrossCoords[i].z + PosZ);
|
|
|
|
BLOCKTYPE BlockAtLowestY = m_World->GetBlock(gCrossCoords[i].x + PosX, LowestY, gCrossCoords[i].z + PosZ);
|
|
|
|
|
|
|
|
if (
|
|
|
|
(!cBlockInfo::IsSolid(BlockAtY)) &&
|
|
|
|
(!cBlockInfo::IsSolid(BlockAtYP)) &&
|
|
|
|
(!IsBlockLava(BlockAtLowestY)) &&
|
|
|
|
(BlockAtLowestY != E_BLOCK_CACTUS) &&
|
|
|
|
(PosY - LowestY < FALL_DAMAGE_HEIGHT)
|
|
|
|
)
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
|
|
|
m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ));
|
|
|
|
}
|
2014-04-17 13:50:25 -04:00
|
|
|
else if (
|
|
|
|
(cBlockInfo::IsSolid(BlockAtY)) &&
|
|
|
|
(BlockAtY != E_BLOCK_CACTUS) &&
|
|
|
|
(!cBlockInfo::IsSolid(BlockAtYP)) &&
|
|
|
|
(!cBlockInfo::IsSolid(BlockAtYPP)) &&
|
|
|
|
(BlockAtY != E_BLOCK_FENCE) &&
|
|
|
|
(BlockAtY != E_BLOCK_FENCE_GATE)
|
|
|
|
)
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
|
|
|
m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_PotentialCoordinates.empty())
|
|
|
|
{
|
|
|
|
Vector3f ShortestCoords = m_PotentialCoordinates.front();
|
|
|
|
for (std::vector<Vector3d>::const_iterator itr = m_PotentialCoordinates.begin(); itr != m_PotentialCoordinates.end(); ++itr)
|
|
|
|
{
|
|
|
|
Vector3f Distance = m_FinalDestination - ShortestCoords;
|
|
|
|
Vector3f Distance2 = m_FinalDestination - *itr;
|
|
|
|
if (Distance.SqrLength() > Distance2.SqrLength())
|
|
|
|
{
|
|
|
|
ShortestCoords = *itr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Destination = ShortestCoords;
|
|
|
|
m_Destination.z += 0.5f;
|
|
|
|
m_Destination.x += 0.5f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FinishPathFinding();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::MoveToPosition(const Vector3f & a_Position)
|
|
|
|
{
|
|
|
|
FinishPathFinding();
|
|
|
|
|
|
|
|
m_FinalDestination = a_Position;
|
2012-06-14 09:06:06 -04:00
|
|
|
m_bMovingToDestination = true;
|
2014-01-24 14:57:32 -05:00
|
|
|
TickPathFinding();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-04 11:29:36 -05:00
|
|
|
|
2014-02-03 14:52:11 -05:00
|
|
|
void cMonster::MoveToPosition(const Vector3d & a_Position)
|
|
|
|
{
|
|
|
|
FinishPathFinding();
|
|
|
|
|
|
|
|
m_FinalDestination = a_Position;
|
|
|
|
m_bMovingToDestination = true;
|
|
|
|
TickPathFinding();
|
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cMonster::IsCoordinateInTraversedList(Vector3i a_Coords)
|
|
|
|
{
|
|
|
|
for (std::vector<Vector3i>::const_iterator itr = m_TraversedCoordinates.begin(); itr != m_TraversedCoordinates.end(); ++itr)
|
|
|
|
{
|
|
|
|
if (itr->Equals(a_Coords))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
bool cMonster::ReachedDestination()
|
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
if ((m_Destination - GetPosition()).Length() < 0.5f)
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return true;
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
bool cMonster::ReachedFinalDestination()
|
|
|
|
{
|
|
|
|
if ((GetPosition() - m_FinalDestination).Length() <= m_AttackRange)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
super::Tick(a_Dt, a_Chunk);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
if (m_Health <= 0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
// The mob is dead, but we're still animating the "puff" they leave when they die
|
|
|
|
m_DestroyTimer += a_Dt / 1000;
|
|
|
|
if (m_DestroyTimer > 1)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-06-25 02:36:59 -04:00
|
|
|
Destroy(true);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-24 18:56:19 -05:00
|
|
|
if ((m_Target != NULL) && m_Target->IsDestroyed())
|
|
|
|
m_Target = NULL;
|
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
// Burning in daylight
|
|
|
|
HandleDaylightBurning(a_Chunk);
|
2013-04-22 03:18:03 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
a_Dt /= 1000;
|
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
if (m_bMovingToDestination)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-01-25 09:42:26 -05:00
|
|
|
if (m_bOnGround)
|
|
|
|
{
|
2014-01-25 14:02:13 -05:00
|
|
|
m_Destination.y = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z);
|
2014-01-25 09:42:26 -05:00
|
|
|
|
2014-02-04 18:07:22 -05:00
|
|
|
if (DoesPosYRequireJump((int)floor(m_Destination.y)))
|
2014-01-25 09:42:26 -05:00
|
|
|
{
|
|
|
|
m_bOnGround = false;
|
|
|
|
AddPosY(1.5); // Jump!!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
Vector3f Distance = m_Destination - GetPosition();
|
|
|
|
if(!ReachedDestination() && !ReachedFinalDestination()) // If we haven't reached any sort of destination, move
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
Distance.y = 0;
|
|
|
|
Distance.Normalize();
|
2014-02-01 11:38:53 -05:00
|
|
|
Distance *= 5;
|
2014-01-24 14:57:32 -05:00
|
|
|
SetSpeedX(Distance.x);
|
|
|
|
SetSpeedZ(Distance.z);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
if (m_EMState == ESCAPING)
|
|
|
|
{ //Runs Faster when escaping :D otherwise they just walk away
|
2013-03-22 02:33:10 -04:00
|
|
|
SetSpeedX (GetSpeedX() * 2.f);
|
|
|
|
SetSpeedZ (GetSpeedZ() * 2.f);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
if (ReachedFinalDestination()) // If we have reached the ultimate, final destination, stop pathfinding and attack if appropriate
|
|
|
|
{
|
|
|
|
FinishPathFinding();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TickPathFinding(); // We have reached the next point in our path, calculate another point
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-03-23 00:33:47 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
SetPitchAndYawFromDestination();
|
2014-01-25 14:02:13 -05:00
|
|
|
HandleFalling();
|
2013-03-22 02:33:10 -04:00
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
switch (m_EMState)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
case IDLE:
|
|
|
|
{
|
|
|
|
// If enemy passive we ignore checks for player visibility
|
2013-04-13 17:02:10 -04:00
|
|
|
InStateIdle(a_Dt);
|
2012-12-22 05:15:53 -05:00
|
|
|
break;
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
2012-12-22 05:15:53 -05:00
|
|
|
case CHASING:
|
|
|
|
{
|
|
|
|
// If we do not see a player anymore skip chasing action
|
2013-04-13 17:02:10 -04:00
|
|
|
InStateChasing(a_Dt);
|
2012-12-22 05:15:53 -05:00
|
|
|
break;
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
2012-12-22 05:15:53 -05:00
|
|
|
case ESCAPING:
|
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
InStateEscaping(a_Dt);
|
2012-12-22 05:15:53 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // switch (m_EMState)
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
BroadcastMovementUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::SetPitchAndYawFromDestination()
|
|
|
|
{
|
|
|
|
Vector3d FinalDestination = m_FinalDestination;
|
|
|
|
if (m_Target != NULL)
|
|
|
|
{
|
|
|
|
if (m_Target->IsPlayer())
|
|
|
|
{
|
|
|
|
FinalDestination.y = ((cPlayer *)m_Target)->GetStance();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FinalDestination.y = GetHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3d Distance = FinalDestination - GetPosition();
|
|
|
|
if (Distance.SqrLength() > 0.1f)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
double Rotation, Pitch;
|
|
|
|
Distance.Normalize();
|
|
|
|
VectorToEuler(Distance.x, Distance.y, Distance.z, Rotation, Pitch);
|
|
|
|
SetHeadYaw(Rotation);
|
|
|
|
SetPitch(-Pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Vector3d BodyDistance = m_Destination - GetPosition();
|
|
|
|
double Rotation, Pitch;
|
|
|
|
Distance.Normalize();
|
|
|
|
VectorToEuler(BodyDistance.x, BodyDistance.y, BodyDistance.z, Rotation, Pitch);
|
|
|
|
SetYaw(Rotation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-25 14:02:13 -05:00
|
|
|
void cMonster::HandleFalling()
|
|
|
|
{
|
|
|
|
if (m_bOnGround)
|
|
|
|
{
|
|
|
|
int Damage = (m_LastGroundHeight - POSY_TOINT) - 3;
|
|
|
|
|
|
|
|
if (Damage > 0)
|
|
|
|
{
|
|
|
|
TakeDamage(dtFalling, NULL, Damage, Damage, 0);
|
|
|
|
|
|
|
|
// Fall particles
|
|
|
|
GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */);
|
|
|
|
}
|
|
|
|
|
2014-04-17 13:50:25 -04:00
|
|
|
m_LastGroundHeight = POSY_TOINT;
|
2014-01-25 14:02:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
|
|
|
|
{
|
2014-04-17 13:50:25 -04:00
|
|
|
int PosY = POSY_TOINT;
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2014-01-25 09:42:26 -05:00
|
|
|
if (PosY < 0)
|
|
|
|
PosY = 0;
|
|
|
|
else if (PosY > cChunkDef::Height)
|
|
|
|
PosY = cChunkDef::Height;
|
|
|
|
|
2014-03-01 14:34:19 -05:00
|
|
|
if (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))))
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2014-03-01 14:34:19 -05:00
|
|
|
while (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY > 0))
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
|
|
|
PosY--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PosY + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-01 14:34:19 -05:00
|
|
|
while (cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY < cChunkDef::Height))
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
|
|
|
PosY++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PosY;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
void cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-21 06:04:08 -05:00
|
|
|
super::DoTakeDamage(a_TDI);
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
if((m_SoundHurt != "") && (m_Health > 0))
|
|
|
|
m_World->BroadcastSoundEffect(m_SoundHurt, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
|
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
if (a_TDI.Attacker != NULL)
|
|
|
|
{
|
|
|
|
m_Target = a_TDI.Attacker;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
void cMonster::KilledBy(cEntity * a_Killer)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-21 06:04:08 -05:00
|
|
|
super::KilledBy(a_Killer);
|
2013-07-01 06:39:56 -04:00
|
|
|
if (m_SoundHurt != "")
|
|
|
|
{
|
|
|
|
m_World->BroadcastSoundEffect(m_SoundDeath, (int)(GetPosX() * 8), (int)(GetPosY() * 8), (int)(GetPosZ() * 8), 1.0f, 0.8f);
|
|
|
|
}
|
2013-11-25 15:43:43 -05:00
|
|
|
int Reward;
|
2013-11-25 15:03:26 -05:00
|
|
|
switch (m_MobType)
|
|
|
|
{
|
|
|
|
// Animals
|
|
|
|
case cMonster::mtChicken:
|
|
|
|
case cMonster::mtCow:
|
|
|
|
case cMonster::mtHorse:
|
|
|
|
case cMonster::mtPig:
|
|
|
|
case cMonster::mtSheep:
|
|
|
|
case cMonster::mtSquid:
|
|
|
|
case cMonster::mtMooshroom:
|
|
|
|
case cMonster::mtOcelot:
|
|
|
|
case cMonster::mtWolf:
|
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
Reward = m_World->GetTickRandomNumber(2) + 1;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Monsters
|
|
|
|
case cMonster::mtCaveSpider:
|
|
|
|
case cMonster::mtCreeper:
|
|
|
|
case cMonster::mtEnderman:
|
|
|
|
case cMonster::mtGhast:
|
|
|
|
case cMonster::mtSilverfish:
|
|
|
|
case cMonster::mtSkeleton:
|
|
|
|
case cMonster::mtSpider:
|
|
|
|
case cMonster::mtWitch:
|
|
|
|
case cMonster::mtZombie:
|
|
|
|
case cMonster::mtZombiePigman:
|
|
|
|
case cMonster::mtSlime:
|
|
|
|
case cMonster::mtMagmaCube:
|
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
Reward = 6 + (m_World->GetTickRandomNumber(2));
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:43:43 -05:00
|
|
|
}
|
|
|
|
case cMonster::mtBlaze:
|
|
|
|
{
|
|
|
|
Reward = 10;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bosses
|
|
|
|
case cMonster::mtEnderDragon:
|
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
Reward = 12000;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
case cMonster::mtWither:
|
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
Reward = 50;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
Reward = 0;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
}
|
2014-04-18 15:20:00 -04:00
|
|
|
if ((a_Killer != NULL) && (!IsBaby()))
|
2014-04-10 10:50:43 -04:00
|
|
|
{
|
|
|
|
m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
m_DestroyTimer = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
//Checks to see if EventSeePlayer should be fired
|
|
|
|
//monster sez: Do I see the player
|
2013-04-13 17:02:10 -04:00
|
|
|
void cMonster::CheckEventSeePlayer(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
// TODO: Rewrite this to use cWorld's DoWithPlayers()
|
2014-01-25 09:42:26 -05:00
|
|
|
cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance, false);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
if (Closest != NULL)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
EventSeePlayer(Closest);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
void cMonster::CheckEventLostPlayer(void)
|
2014-01-24 15:46:22 -05:00
|
|
|
{
|
2012-08-19 15:42:32 -04:00
|
|
|
if (m_Target != NULL)
|
|
|
|
{
|
2014-01-24 15:46:22 -05:00
|
|
|
if ((m_Target->GetPosition() - GetPosition()).Length() > m_SightDistance)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
EventLosePlayer();
|
|
|
|
}
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
EventLosePlayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if player is seen
|
|
|
|
// default to change state to chasing
|
2013-04-13 17:02:10 -04:00
|
|
|
void cMonster::EventSeePlayer(cEntity * a_SeenPlayer)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
m_Target = a_SeenPlayer;
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
void cMonster::EventLosePlayer(void)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
m_Target = NULL;
|
2012-06-14 09:06:06 -04:00
|
|
|
m_EMState = IDLE;
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
void cMonster::InStateIdle(float a_Dt)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2014-01-25 09:42:26 -05:00
|
|
|
if (m_bMovingToDestination)
|
|
|
|
{
|
|
|
|
return; // Still getting there
|
|
|
|
}
|
|
|
|
|
2013-12-20 10:39:20 -05:00
|
|
|
m_IdleInterval += a_Dt;
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2013-12-20 10:39:20 -05:00
|
|
|
if (m_IdleInterval > 1)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
// At this interval the results are predictable
|
2013-04-13 17:02:10 -04:00
|
|
|
int rem = m_World->GetTickRandomNumber(6) + 1;
|
2014-01-24 14:57:32 -05:00
|
|
|
m_IdleInterval -= 1; // So nothing gets dropped when the server hangs for a few seconds
|
|
|
|
|
|
|
|
Vector3d Dist;
|
2014-01-25 09:42:26 -05:00
|
|
|
Dist.x = (double)m_World->GetTickRandomNumber(10) - 5;
|
|
|
|
Dist.z = (double)m_World->GetTickRandomNumber(10) - 5;
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
if ((Dist.SqrLength() > 2) && (rem >= 3))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-01-25 09:42:26 -05:00
|
|
|
Vector3d Destination(GetPosX() + Dist.x, 0, GetPosZ() + Dist.z);
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2014-01-25 09:42:26 -05:00
|
|
|
int NextHeight = FindFirstNonAirBlockPosition(Destination.x, Destination.z);
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2014-01-25 09:42:26 -05:00
|
|
|
if (IsNextYPosReachable(NextHeight))
|
2013-04-13 17:02:10 -04:00
|
|
|
{
|
2014-01-25 09:42:26 -05:00
|
|
|
Destination.y = NextHeight;
|
|
|
|
MoveToPosition(Destination);
|
2013-04-13 17:02:10 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if in Chasing State
|
|
|
|
// This state should always be defined in each child class
|
2013-04-13 17:02:10 -04:00
|
|
|
void cMonster::InStateChasing(float a_Dt)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_Dt);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if in Escaping State
|
2013-04-13 17:02:10 -04:00
|
|
|
void cMonster::InStateEscaping(float a_Dt)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
UNUSED(a_Dt);
|
|
|
|
|
|
|
|
if (m_Target != NULL)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-03-22 02:33:10 -04:00
|
|
|
Vector3d newloc = GetPosition();
|
2012-06-14 09:06:06 -04:00
|
|
|
newloc.x = (m_Target->GetPosition().x < newloc.x)? (newloc.x + m_SightDistance): (newloc.x - m_SightDistance);
|
|
|
|
newloc.z = (m_Target->GetPosition().z < newloc.z)? (newloc.z + m_SightDistance): (newloc.z - m_SightDistance);
|
|
|
|
MoveToPosition(newloc);
|
|
|
|
}
|
2012-08-19 15:42:32 -04:00
|
|
|
else
|
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
m_EMState = IDLE; // This shouldnt be required but just to be safe
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 04:39:13 -05:00
|
|
|
void cMonster::GetMonsterConfig(const AString & a_Name)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-22 04:39:13 -05:00
|
|
|
cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
AString cMonster::MobTypeToString(cMonster::eType a_MobType)
|
|
|
|
{
|
|
|
|
// Mob types aren't sorted, so we need to search linearly:
|
2013-12-20 10:01:34 -05:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
|
|
|
if (g_MobTypeNames[i].m_Type == a_MobType)
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[i].m_lcName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not found:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cMonster::eType cMonster::StringToMobType(const AString & a_Name)
|
|
|
|
{
|
|
|
|
AString lcName(a_Name);
|
|
|
|
StrToLower(lcName);
|
|
|
|
|
|
|
|
// Binary-search for the lowercase name:
|
2013-10-20 07:42:59 -04:00
|
|
|
int lo = 0, hi = ARRAYCOUNT(g_MobTypeNames) - 1;
|
2013-10-20 07:25:56 -04:00
|
|
|
while (hi - lo > 1)
|
|
|
|
{
|
|
|
|
int mid = (lo + hi) / 2;
|
|
|
|
int res = strcmp(g_MobTypeNames[mid].m_lcName, lcName.c_str());
|
|
|
|
if (res == 0)
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[mid].m_Type;
|
|
|
|
}
|
|
|
|
if (res < 0)
|
|
|
|
{
|
2013-10-20 07:42:59 -04:00
|
|
|
lo = mid;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-20 07:42:59 -04:00
|
|
|
hi = mid;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Range has collapsed to at most two elements, compare each:
|
|
|
|
if (strcmp(g_MobTypeNames[lo].m_lcName, lcName.c_str()) == 0)
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[lo].m_Type;
|
|
|
|
}
|
|
|
|
if ((lo != hi) && (strcmp(g_MobTypeNames[hi].m_lcName, lcName.c_str()) == 0))
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[hi].m_Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not found:
|
|
|
|
return mtInvalidType;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cMonster::eFamily cMonster::FamilyFromType(eType a_Type)
|
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
// Passive-agressive mobs are counted in mob spawning code as passive
|
|
|
|
|
2013-10-20 08:15:55 -04:00
|
|
|
switch (a_Type)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtBat: return mfAmbient;
|
|
|
|
case mtBlaze: return mfHostile;
|
|
|
|
case mtCaveSpider: return mfHostile;
|
|
|
|
case mtChicken: return mfPassive;
|
|
|
|
case mtCow: return mfPassive;
|
|
|
|
case mtCreeper: return mfHostile;
|
|
|
|
case mtEnderman: return mfHostile;
|
|
|
|
case mtGhast: return mfHostile;
|
|
|
|
case mtHorse: return mfPassive;
|
2013-12-25 11:07:52 -05:00
|
|
|
case mtIronGolem: return mfPassive;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtMagmaCube: return mfHostile;
|
|
|
|
case mtMooshroom: return mfHostile;
|
2013-12-25 11:07:52 -05:00
|
|
|
case mtOcelot: return mfPassive;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtPig: return mfPassive;
|
|
|
|
case mtSheep: return mfPassive;
|
|
|
|
case mtSilverfish: return mfHostile;
|
|
|
|
case mtSkeleton: return mfHostile;
|
|
|
|
case mtSlime: return mfHostile;
|
|
|
|
case mtSpider: return mfHostile;
|
|
|
|
case mtSquid: return mfWater;
|
|
|
|
case mtVillager: return mfPassive;
|
|
|
|
case mtWitch: return mfHostile;
|
2014-03-24 06:29:19 -04:00
|
|
|
case mtWither: return mfHostile;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtWolf: return mfHostile;
|
|
|
|
case mtZombie: return mfHostile;
|
|
|
|
case mtZombiePigman: return mfHostile;
|
2013-10-20 07:25:56 -04:00
|
|
|
} ;
|
2013-10-20 08:15:55 -04:00
|
|
|
ASSERT(!"Unhandled mob type");
|
2013-10-20 07:25:56 -04:00
|
|
|
return mfMaxplusone;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 10:45:13 -04:00
|
|
|
int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily)
|
2013-10-20 08:00:45 -04:00
|
|
|
{
|
|
|
|
switch (a_MobFamily)
|
|
|
|
{
|
2013-11-02 15:47:43 -04:00
|
|
|
case mfHostile: return 40;
|
|
|
|
case mfPassive: return 40;
|
|
|
|
case mfAmbient: return 40;
|
2013-10-20 08:00:45 -04:00
|
|
|
case mfWater: return 400;
|
|
|
|
}
|
|
|
|
ASSERT(!"Unhandled mob family");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-10 15:48:12 -05:00
|
|
|
cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
|
|
|
cFastRandom Random;
|
|
|
|
cMonster * toReturn = NULL;
|
|
|
|
|
2013-11-10 15:48:12 -05:00
|
|
|
// Create the mob entity
|
2013-10-20 07:25:56 -04:00
|
|
|
switch (a_MobType)
|
|
|
|
{
|
|
|
|
case mtMagmaCube:
|
|
|
|
case mtSlime:
|
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
toReturn = new cSlime(Random.NextInt(2) + 1);
|
2013-11-13 05:08:51 -05:00
|
|
|
break;
|
|
|
|
}
|
2013-11-10 17:20:25 -05:00
|
|
|
case mtSkeleton:
|
|
|
|
{
|
|
|
|
// TODO: Actual detection of spawning in Nether
|
2013-11-13 05:08:51 -05:00
|
|
|
toReturn = new cSkeleton(Random.NextInt(1) == 0 ? false : true);
|
2013-11-10 17:20:25 -05:00
|
|
|
break;
|
|
|
|
}
|
2013-11-10 15:48:12 -05:00
|
|
|
case mtVillager:
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2013-11-13 05:08:51 -05:00
|
|
|
int VillagerType = Random.NextInt(6);
|
|
|
|
if (VillagerType == 6)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2013-11-13 05:08:51 -05:00
|
|
|
// Give farmers a better chance of spawning
|
|
|
|
VillagerType = 0;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
2013-11-10 15:48:12 -05:00
|
|
|
|
2013-11-13 05:08:51 -05:00
|
|
|
toReturn = new cVillager((cVillager::eVillagerType)VillagerType);
|
2013-11-10 15:48:12 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case mtHorse:
|
|
|
|
{
|
|
|
|
// Horses take a type (species), a colour, and a style (dots, stripes, etc.)
|
2013-11-13 05:08:51 -05:00
|
|
|
int HorseType = Random.NextInt(7);
|
|
|
|
int HorseColor = Random.NextInt(6);
|
|
|
|
int HorseStyle = Random.NextInt(6);
|
|
|
|
int HorseTameTimes = Random.NextInt(6) + 1;
|
2013-11-10 15:48:12 -05:00
|
|
|
|
2013-11-13 05:08:51 -05:00
|
|
|
if ((HorseType == 5) || (HorseType == 6) || (HorseType == 7))
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2013-11-13 05:08:51 -05:00
|
|
|
// Increase chances of normal horse (zero)
|
|
|
|
HorseType = 0;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
2013-11-10 15:48:12 -05:00
|
|
|
|
2013-11-13 05:08:51 -05:00
|
|
|
toReturn = new cHorse(HorseType, HorseColor, HorseStyle, HorseTameTimes);
|
2013-10-20 07:25:56 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-13 05:08:51 -05:00
|
|
|
case mtBat: toReturn = new cBat(); break;
|
|
|
|
case mtBlaze: toReturn = new cBlaze(); break;
|
|
|
|
case mtCaveSpider: toReturn = new cCavespider(); break;
|
|
|
|
case mtChicken: toReturn = new cChicken(); break;
|
|
|
|
case mtCow: toReturn = new cCow(); break;
|
|
|
|
case mtCreeper: toReturn = new cCreeper(); break;
|
2013-12-22 14:15:09 -05:00
|
|
|
case mtEnderDragon: toReturn = new cEnderDragon(); break;
|
2013-11-13 05:08:51 -05:00
|
|
|
case mtEnderman: toReturn = new cEnderman(); break;
|
|
|
|
case mtGhast: toReturn = new cGhast(); break;
|
2013-12-23 04:32:49 -05:00
|
|
|
case mtIronGolem: toReturn = new cIronGolem(); break;
|
2013-11-13 05:08:51 -05:00
|
|
|
case mtMooshroom: toReturn = new cMooshroom(); break;
|
|
|
|
case mtOcelot: toReturn = new cOcelot(); break;
|
|
|
|
case mtPig: toReturn = new cPig(); break;
|
|
|
|
case mtSheep: toReturn = new cSheep (Random.NextInt(15)); break; // Colour parameter
|
|
|
|
case mtSilverfish: toReturn = new cSilverfish(); break;
|
2013-12-22 14:15:09 -05:00
|
|
|
case mtSnowGolem: toReturn = new cSnowGolem(); break;
|
2013-11-13 05:08:51 -05:00
|
|
|
case mtSpider: toReturn = new cSpider(); break;
|
|
|
|
case mtSquid: toReturn = new cSquid(); break;
|
|
|
|
case mtWitch: toReturn = new cWitch(); break;
|
2013-12-23 04:32:49 -05:00
|
|
|
case mtWither: toReturn = new cWither(); break;
|
2013-11-13 05:08:51 -05:00
|
|
|
case mtWolf: toReturn = new cWolf(); break;
|
|
|
|
case mtZombie: toReturn = new cZombie(false); break; // TODO: Infected zombie parameter
|
|
|
|
case mtZombiePigman: toReturn = new cZombiePigman(); break;
|
2013-10-20 07:25:56 -04:00
|
|
|
default:
|
|
|
|
{
|
2013-11-10 15:48:12 -05:00
|
|
|
ASSERT(!"Unhandled mob type whilst trying to spawn mob!");
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
MTRand r1;
|
|
|
|
int Count = r1.randInt() % (a_Max + 1 - a_Min) + a_Min;
|
|
|
|
if (Count > 0)
|
|
|
|
{
|
|
|
|
a_Drops.push_back(cItem(a_Item, Count, a_ItemHealth));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
|
2014-02-23 13:44:58 -05:00
|
|
|
void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth)
|
|
|
|
{
|
|
|
|
MTRand r1;
|
|
|
|
int Count = r1.randInt() % 1000;
|
|
|
|
if (Count < (a_Chance * 10))
|
|
|
|
{
|
|
|
|
a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel)
|
|
|
|
{
|
|
|
|
MTRand r1;
|
|
|
|
int Count = r1.randInt() % 200;
|
|
|
|
if (Count < (5 + a_LootingLevel))
|
|
|
|
{
|
|
|
|
int Rare = r1.randInt() % a_Items.Size();
|
|
|
|
a_Drops.push_back(a_Items.at(Rare));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel)
|
|
|
|
{
|
|
|
|
MTRand r1;
|
|
|
|
if (r1.randInt() % 200 < ((m_DropChanceHelmet * 200) + (a_LootingLevel * 2)))
|
|
|
|
{
|
|
|
|
if (!GetEquippedHelmet().IsEmpty()) a_Drops.push_back(GetEquippedHelmet());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r1.randInt() % 200 < ((m_DropChanceChestplate * 200) + (a_LootingLevel * 2)))
|
|
|
|
{
|
|
|
|
if (!GetEquippedChestplate().IsEmpty()) a_Drops.push_back(GetEquippedChestplate());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r1.randInt() % 200 < ((m_DropChanceLeggings * 200) + (a_LootingLevel * 2)))
|
|
|
|
{
|
|
|
|
if (!GetEquippedLeggings().IsEmpty()) a_Drops.push_back(GetEquippedLeggings());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r1.randInt() % 200 < ((m_DropChanceBoots * 200) + (a_LootingLevel * 2)))
|
|
|
|
{
|
|
|
|
if (!GetEquippedBoots().IsEmpty()) a_Drops.push_back(GetEquippedBoots());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel)
|
|
|
|
{
|
|
|
|
MTRand r1;
|
|
|
|
if (r1.randInt() % 200 < ((m_DropChanceWeapon * 200) + (a_LootingLevel * 2)))
|
|
|
|
{
|
|
|
|
if (!GetEquippedWeapon().IsEmpty()) a_Drops.push_back(GetEquippedWeapon());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
void cMonster::HandleDaylightBurning(cChunk & a_Chunk)
|
|
|
|
{
|
|
|
|
if (!m_BurnsInDaylight)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-17 13:50:25 -04:00
|
|
|
int RelY = POSY_TOINT;
|
2013-09-05 16:40:08 -04:00
|
|
|
if ((RelY < 0) || (RelY >= cChunkDef::Height))
|
|
|
|
{
|
|
|
|
// Outside the world
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-17 13:50:25 -04:00
|
|
|
int RelX = POSX_TOINT - GetChunkX() * cChunkDef::Width;
|
|
|
|
int RelZ = POSZ_TOINT - GetChunkZ() * cChunkDef::Width;
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
if (!a_Chunk.IsLightValid())
|
|
|
|
{
|
|
|
|
m_World->QueueLightChunk(GetChunkX(), GetChunkZ());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
if (
|
|
|
|
(a_Chunk.GetSkyLight(RelX, RelY, RelZ) == 15) && // In the daylight
|
|
|
|
(a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand
|
|
|
|
(GetWorld()->GetTimeOfDay() < (12000 + 1000)) && // It is nighttime
|
2014-04-18 07:59:14 -04:00
|
|
|
!IsOnFire() && // Not already burning
|
|
|
|
(GetWorld()->GetWeather() != eWeather_Rain) // Not raining
|
2013-09-05 16:40:08 -04:00
|
|
|
)
|
|
|
|
{
|
|
|
|
// Burn for 100 ticks, then decide again
|
|
|
|
StartBurning(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-10 09:09:45 -04:00
|
|
|
cMonster::eFamily cMonster::GetMobFamily(void) const
|
|
|
|
{
|
2013-10-20 07:25:56 -04:00
|
|
|
return FamilyFromType(m_MobType);
|
2013-09-10 09:09:45 -04:00
|
|
|
}
|
2013-10-20 04:23:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|