1
0

Fixed loading allowed mobs in world.

This commit is contained in:
madmaxoft 2013-10-20 10:23:30 +02:00
parent 0258213d24
commit 34928378b8
43 changed files with 323 additions and 164 deletions

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 10/13/13 18:01:21.
** Generated automatically by tolua++-1.0.92 on 10/20/13 10:19:10.
*/
#ifndef __cplusplus
@ -19303,6 +19303,41 @@ static int tolua_AllToLua_cWebAdmin_GetBaseURL00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetHTMLEscapedString of class cWebAdmin */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWebAdmin_GetHTMLEscapedString00
static int tolua_AllToLua_cWebAdmin_GetHTMLEscapedString00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cWebAdmin",0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cWebAdmin* self = (cWebAdmin*) tolua_tousertype(tolua_S,1,0);
const AString a_Input = ((const AString) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetHTMLEscapedString'", NULL);
#endif
{
AString tolua_ret = (AString) self->GetHTMLEscapedString(a_Input);
tolua_pushcppstring(tolua_S,(const char*)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_Input);
}
}
return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetHTMLEscapedString'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetWebTitle of class cWebPlugin */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cWebPlugin_GetWebTitle00
static int tolua_AllToLua_cWebPlugin_GetWebTitle00(lua_State* tolua_S)
@ -29169,19 +29204,19 @@ static int tolua_AllToLua_cMonster_GetMobType00(lua_State* tolua_S)
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cMonster",0,&tolua_err) ||
!tolua_isusertype(tolua_S,1,"const cMonster",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cMonster* self = (cMonster*) tolua_tousertype(tolua_S,1,0);
const cMonster* self = (const cMonster*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMobType'", NULL);
#endif
{
int tolua_ret = (int) self->GetMobType();
cMonster::eType tolua_ret = (cMonster::eType) self->GetMobType();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
@ -29194,6 +29229,38 @@ static int tolua_AllToLua_cMonster_GetMobType00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: GetMobFamily of class cMonster */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cMonster_GetMobFamily00
static int tolua_AllToLua_cMonster_GetMobFamily00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const cMonster",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const cMonster* self = (const cMonster*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMobFamily'", NULL);
#endif
{
cMonster::eFamily tolua_ret = (cMonster::eFamily) self->GetMobFamily();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GetMobFamily'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* Open function */
TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
{
@ -30826,6 +30893,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetPage",tolua_AllToLua_cWebAdmin_GetPage00);
tolua_function(tolua_S,"GetDefaultPage",tolua_AllToLua_cWebAdmin_GetDefaultPage00);
tolua_function(tolua_S,"GetBaseURL",tolua_AllToLua_cWebAdmin_GetBaseURL00);
tolua_function(tolua_S,"GetHTMLEscapedString",tolua_AllToLua_cWebAdmin_GetHTMLEscapedString00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cWebPlugin","cWebPlugin","",NULL);
tolua_beginmodule(tolua_S,"cWebPlugin");
@ -31248,6 +31316,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cMonster","cMonster","cPawn",NULL);
tolua_beginmodule(tolua_S,"cMonster");
tolua_constant(tolua_S,"mtInvalidType",cMonster::mtInvalidType);
tolua_constant(tolua_S,"mtBat",cMonster::mtBat);
tolua_constant(tolua_S,"mtBlaze",cMonster::mtBlaze);
tolua_constant(tolua_S,"mtCaveSpider",cMonster::mtCaveSpider);
@ -31277,7 +31346,13 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"mtWolf",cMonster::mtWolf);
tolua_constant(tolua_S,"mtZombie",cMonster::mtZombie);
tolua_constant(tolua_S,"mtZombiePigman",cMonster::mtZombiePigman);
tolua_constant(tolua_S,"mfHostile",cMonster::mfHostile);
tolua_constant(tolua_S,"mfPassive",cMonster::mfPassive);
tolua_constant(tolua_S,"mfAmbient",cMonster::mfAmbient);
tolua_constant(tolua_S,"mfWater",cMonster::mfWater);
tolua_constant(tolua_S,"mfMaxplusone",cMonster::mfMaxplusone);
tolua_function(tolua_S,"GetMobType",tolua_AllToLua_cMonster_GetMobType00);
tolua_function(tolua_S,"GetMobFamily",tolua_AllToLua_cMonster_GetMobFamily00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cLineBlockTracer","cLineBlockTracer","",NULL);
tolua_beginmodule(tolua_S,"cLineBlockTracer");

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 10/13/13 18:01:22.
** Generated automatically by tolua++-1.0.92 on 10/20/13 10:19:10.
*/
/* Exported function */

View File

@ -47,6 +47,9 @@ cMobSpawner::tMobTypes cMobSpawner::initMobTypesBeforeCx11()
}
cMobSpawner::cMobSpawner(cMonster::eFamily a_MonsterFamily,const std::set<cMonster::eType>& a_AllowedTypes) :
m_MonsterFamily(a_MonsterFamily),
m_NewPack(true),
@ -54,13 +57,17 @@ cMobSpawner::cMobSpawner(cMonster::eFamily a_MonsterFamily,const std::set<cMonst
{
for (std::set<cMonster::eType>::const_iterator itr = a_AllowedTypes.begin(); itr != a_AllowedTypes.end(); itr++)
{
if (cMobTypesManager::getFamilyFromType(*itr) == a_MonsterFamily)
if (cMobTypesManager::FamilyFromType(*itr) == a_MonsterFamily)
{
m_AllowedTypes.insert(*itr);
}
}
}
bool cMobSpawner::CheckPackCenter(BLOCKTYPE a_BlockType)
{
// Packs of non-water mobs can only be centered on an air block

View File

@ -8,88 +8,115 @@
#include "FastRandom.h"
cMobTypesManager::tMobTypes2Names& cMobTypesManager::m_MobsTypes2Names()
cMobTypesManager::tMobTypes2Names & cMobTypesManager::m_MobsTypes2Names(void)
{
static std::map<cMonster::eType,std::string>* value = new std::map<cMonster::eType,std::string>(MobTypes2NamesInitializerBeforeCx11());
// TODO: This memory leaks
static std::map<cMonster::eType, AString> * value = new std::map<cMonster::eType, AString>(MobTypes2NamesInitializerBeforeCx11());
return *value;
}
cMobTypesManager::tMobTypes2Names cMobTypesManager::MobTypes2NamesInitializerBeforeCx11()
{
std::map<cMonster::eType,std::string> toReturn;
typedef std::map<cMonster::eType,std::string>::value_type ValueType;
toReturn.insert(ValueType(cMonster::mtMagmaCube,"Magmacube"));
toReturn.insert(ValueType(cMonster::mtSlime,"Slime"));
toReturn.insert(ValueType(cMonster::mtBat,"Bat"));
toReturn.insert(ValueType(cMonster::mtBlaze,"Blaze"));
toReturn.insert(ValueType(cMonster::mtCaveSpider,"Cavespider"));
toReturn.insert(ValueType(cMonster::mtChicken,"Chicken"));
toReturn.insert(ValueType(cMonster::mtCow,"Cow"));
toReturn.insert(ValueType(cMonster::mtCreeper,"Creeper"));
toReturn.insert(ValueType(cMonster::mtEnderman,"Enderman"));
toReturn.insert(ValueType(cMonster::mtGhast,"Ghast"));
toReturn.insert(ValueType(cMonster::mtMooshroom,"Mooshroom"));
toReturn.insert(ValueType(cMonster::mtOcelot,"Ocelot"));
toReturn.insert(ValueType(cMonster::mtPig,"Pig"));
toReturn.insert(ValueType(cMonster::mtSheep,"Sheep"));
toReturn.insert(ValueType(cMonster::mtSilverfish,"Silverfish"));
toReturn.insert(ValueType(cMonster::mtSkeleton,"Skeleton"));
toReturn.insert(ValueType(cMonster::mtSpider,"Spider"));
toReturn.insert(ValueType(cMonster::mtSquid,"Squid"));
toReturn.insert(ValueType(cMonster::mtVillager,"Villager"));
toReturn.insert(ValueType(cMonster::mtWitch,"Witch"));
toReturn.insert(ValueType(cMonster::mtWolf,"Wolf"));
toReturn.insert(ValueType(cMonster::mtZombie,"Zombie"));
toReturn.insert(ValueType(cMonster::mtZombiePigman,"Zombiepigman"));
std::map<cMonster::eType, AString> toReturn;
typedef std::map<cMonster::eType, AString>::value_type ValueType;
// The strings need to be lowercase (for more efficient comparisons in StringToMobType())
toReturn.insert(ValueType(cMonster::mtBat, "bat"));
toReturn.insert(ValueType(cMonster::mtBlaze, "blaze"));
toReturn.insert(ValueType(cMonster::mtCaveSpider, "cavespider"));
toReturn.insert(ValueType(cMonster::mtChicken, "chicken"));
toReturn.insert(ValueType(cMonster::mtCow, "cow"));
toReturn.insert(ValueType(cMonster::mtCreeper, "creeper"));
toReturn.insert(ValueType(cMonster::mtEnderman, "enderman"));
toReturn.insert(ValueType(cMonster::mtGhast, "ghast"));
toReturn.insert(ValueType(cMonster::mtHorse, "horse"));
toReturn.insert(ValueType(cMonster::mtMagmaCube, "magmacube"));
toReturn.insert(ValueType(cMonster::mtMooshroom, "mooshroom"));
toReturn.insert(ValueType(cMonster::mtOcelot, "ocelot"));
toReturn.insert(ValueType(cMonster::mtPig, "pig"));
toReturn.insert(ValueType(cMonster::mtSheep, "sheep"));
toReturn.insert(ValueType(cMonster::mtSilverfish, "silverfish"));
toReturn.insert(ValueType(cMonster::mtSkeleton, "skeleton"));
toReturn.insert(ValueType(cMonster::mtSlime, "slime"));
toReturn.insert(ValueType(cMonster::mtSpider, "spider"));
toReturn.insert(ValueType(cMonster::mtSquid, "squid"));
toReturn.insert(ValueType(cMonster::mtVillager, "villager"));
toReturn.insert(ValueType(cMonster::mtWitch, "witch"));
toReturn.insert(ValueType(cMonster::mtWolf, "wolf"));
toReturn.insert(ValueType(cMonster::mtZombie, "zombie"));
toReturn.insert(ValueType(cMonster::mtZombiePigman, "zombiepigman"));
return toReturn;
}
cMobTypesManager::tMobType2Family& cMobTypesManager::m_MobsType2Family()
cMobTypesManager::tMobType2Family & cMobTypesManager::m_MobsType2Family(void)
{
static std::map<cMonster::eType,cMonster::eFamily>* value = new std::map<cMonster::eType,cMonster::eFamily>(MobType2FamilyInitializerBeforeCx11());
// TODO: This memory is leaked:
static std::map<cMonster::eType,cMonster::eFamily> * value = new std::map<cMonster::eType,cMonster::eFamily>(MobType2FamilyInitializerBeforeCx11());
return *value;
}
cMobTypesManager::tMobType2Family cMobTypesManager::MobType2FamilyInitializerBeforeCx11()
{
std::map<cMonster::eType,cMonster::eFamily> toReturn;
typedef std::map<cMonster::eType,cMonster::eFamily>::value_type ValueType;
toReturn.insert(ValueType(cMonster::mtBat,cMonster::mfAmbient));
toReturn.insert(ValueType(cMonster::mtSquid,cMonster::mfWater));
toReturn.insert(ValueType(cMonster::mtCow,cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtPig,cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtSheep,cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtChicken,cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtVillager,cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtMagmaCube,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtSlime,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtBlaze,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtCaveSpider,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtCreeper,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtEnderman,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtGhast,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtMooshroom,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtOcelot,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtSilverfish,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtSkeleton,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtSpider,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtWitch,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtWolf,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtZombie,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtZombiePigman,cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtBat, cMonster::mfAmbient));
toReturn.insert(ValueType(cMonster::mtBlaze, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtCaveSpider, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtChicken, cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtCow, cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtCreeper, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtEnderman, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtGhast, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtHorse, cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtMagmaCube, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtMooshroom, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtOcelot, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtPig, cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtSheep, cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtSilverfish, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtSkeleton, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtSlime, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtSpider, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtSquid, cMonster::mfWater));
toReturn.insert(ValueType(cMonster::mtVillager, cMonster::mfPassive));
toReturn.insert(ValueType(cMonster::mtWitch, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtWolf, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtZombie, cMonster::mfHostile));
toReturn.insert(ValueType(cMonster::mtZombiePigman, cMonster::mfHostile));
return toReturn;
}
cFastRandom& cMobTypesManager::m_Random()
cFastRandom & cMobTypesManager::m_Random(void)
{
static cFastRandom* value = new cFastRandom();
// TODO: This memory is leaked:
static cFastRandom * value = new cFastRandom();
return *value;
}
cMonster* cMobTypesManager::NewMonsterFromType(cMonster::eType a_MobType, int a_Size)
cMonster * cMobTypesManager::NewMonsterFromType(cMonster::eType a_MobType, int a_Size)
{
cMonster * toReturn = NULL;
@ -98,20 +125,22 @@ cMonster* cMobTypesManager::NewMonsterFromType(cMonster::eType a_MobType, int a_
{
case cMonster::mtMagmaCube:
case cMonster::mtSlime:
{
if (a_Size == -1)
{
a_Size = m_Random().NextInt(2,a_MobType)+1;
a_Size = m_Random().NextInt(2, a_MobType) + 1;
}
if (a_Size <= 0 || a_Size >= 4)
if ((a_Size <= 0) || (a_Size >= 4))
{
ASSERT(!"Random for size was supposed to pick in [1..3] and picked outside");
a_Size = 1;
}
break;
default : break;
}
default: break;
} // switch (a_MobType)
// the big switch
// Create the mob entity
switch (a_MobType)
{
case cMonster::mtMagmaCube: toReturn = new cMagmaCube(a_Size); break;
@ -124,13 +153,15 @@ cMonster* cMobTypesManager::NewMonsterFromType(cMonster::eType a_MobType, int a_
case cMonster::mtCreeper: toReturn = new cCreeper(); break;
case cMonster::mtEnderman: toReturn = new cEnderman(); break;
case cMonster::mtGhast: toReturn = new cGhast(); break;
// TODO:
// case cMonster::mtHorse: toReturn = new cHorse(); break;
case cMonster::mtMooshroom: toReturn = new cMooshroom(); break;
case cMonster::mtOcelot: toReturn = new cOcelot(); break;
case cMonster::mtPig: toReturn = new cPig(); break;
// TODO: Implement sheep color
case cMonster::mtSheep: toReturn = new cSheep(0); break;
case cMonster::mtSilverfish: toReturn = new cSilverfish(); break;
// TODO: Implement wither geration
// TODO: Implement wither skeleton geration
case cMonster::mtSkeleton: toReturn = new cSkeleton(false); break;
case cMonster::mtSpider: toReturn = new cSpider(); break;
case cMonster::mtSquid: toReturn = new cSquid(); break;
@ -148,21 +179,28 @@ cMonster* cMobTypesManager::NewMonsterFromType(cMonster::eType a_MobType, int a_
}
const std::string& cMobTypesManager::fromMobTypeToString(cMonster::eType a_MobType)
AString cMobTypesManager::MobTypeToString(cMonster::eType a_MobType)
{
static std::string toReturnDefault = "";
std::string& toReturn = toReturnDefault;
std::map<cMonster::eType,std::string>::const_iterator itr = m_MobsTypes2Names().find(a_MobType);
std::map<cMonster::eType, AString>::const_iterator itr = m_MobsTypes2Names().find(a_MobType);
if (itr != m_MobsTypes2Names().end())
{
toReturn = itr->second;
return itr->second;
}
return toReturn;
return "";
}
cMonster::eType cMobTypesManager::fromStringToMobType(const std::string& a_Name)
cMonster::eType cMobTypesManager::StringToMobType(const AString & a_Name)
{
for(std::map<cMonster::eType,std::string>::const_iterator itr = m_MobsTypes2Names().begin(); itr != m_MobsTypes2Names().end(); itr++)
AString lcName(a_Name);
StrToLower(lcName);
for (std::map<cMonster::eType, AString>::const_iterator itr = m_MobsTypes2Names().begin(); itr != m_MobsTypes2Names().end(); itr++)
{
if (itr->second == a_Name)
{
@ -172,13 +210,21 @@ cMonster::eType cMobTypesManager::fromStringToMobType(const std::string& a_Name)
return cMonster::mtInvalidType;
}
cMonster::eFamily cMobTypesManager::getFamilyFromType(cMonster::eType a_Type)
cMonster::eFamily cMobTypesManager::FamilyFromType(cMonster::eType a_Type)
{
cMonster::eFamily toReturn = cMonster::mfMaxplusone;
std::map<cMonster::eType,cMonster::eFamily>::const_iterator itr = m_MobsType2Family().find(a_Type);
std::map<cMonster::eType, cMonster::eFamily>::const_iterator itr = m_MobsType2Family().find(a_Type);
if (itr != m_MobsType2Family().end())
{
toReturn = itr->second;
}
return toReturn;
}

View File

@ -1,44 +1,54 @@
#pragma once
#include <vector>
#include "Mobs/Monster.h" // this is a side effect of declaring cMonster::eType inside cMonster MG TODO : make a namespace
// fwd:
class cFastRandom;
// this aggregate static functionnalities about mob types (some could call it helper)
// functionnalities are (in the first version) :
// - create a mob from its type (as enum) (in that way it is a compiler-proxy for mobs)
// - can transform MobTypes from enums to string and reciprocal
// - return mob family from providen type
/**
This class aggregates static functions about mob types:
- create a mob from its type (as enum) (in that way it is a compiler-proxy for mobs)
- transform MobTypes from enums to string and vice versa
- return mob family from given type
*/
class cMobTypesManager
{
public:
static const std::string& fromMobTypeToString(cMonster::eType a_MobType);
static cMonster::eType fromStringToMobType(const std::string& a_MobTypeName);
static cMonster::eFamily getFamilyFromType(cMonster::eType a_MobType);
static AString MobTypeToString(cMonster::eType a_MobType);
static cMonster::eType StringToMobType(const AString& a_MobTypeName);
static cMonster::eFamily FamilyFromType(cMonster::eType a_MobType);
protected :
typedef const std::map<cMonster::eType,std::string> tMobTypes2Names;
static tMobTypes2Names& m_MobsTypes2Names();
static tMobTypes2Names MobTypes2NamesInitializerBeforeCx11();
typedef const std::map<cMonster::eType,cMonster::eFamily> tMobType2Family;
static tMobType2Family& m_MobsType2Family();
static tMobType2Family MobType2FamilyInitializerBeforeCx11();
static cFastRandom& m_Random();
public :
/** create a new object of the specified mob.
Warning, new without delete here;
a_MobType is the type of the mob to be created
a_Size is the size (for mobs with size)
if a_Size is let to -1 for entities that need size, size will be random
assert or return null if mob type is not specified
assert if size < 1 or > 3 for entities that need size
asserts and returns null if mob type is not specified
asserts if invalid size for mobs that need size
*/
static cMonster* NewMonsterFromType(cMonster::eType a_MobType, int a_Size=-1);
static cMonster * NewMonsterFromType(cMonster::eType a_MobType, int a_Size = -1);
protected :
typedef const std::map<cMonster::eType,std::string> tMobTypes2Names;
static tMobTypes2Names& m_MobsTypes2Names(void);
static tMobTypes2Names MobTypes2NamesInitializerBeforeCx11(void);
typedef const std::map<cMonster::eType,cMonster::eFamily> tMobType2Family;
static tMobType2Family& m_MobsType2Family(void);
static tMobType2Family MobType2FamilyInitializerBeforeCx11(void);
static cFastRandom & m_Random(void);
public :
} ;
}; // tolua_export

View File

@ -12,8 +12,8 @@
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
super(a_ConfigName, a_ProtocolMobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height),
cAggressiveMonster::cAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height),
m_ChaseTime(999999)
{
m_EMPersonality = AGGRESSIVE;

View File

@ -13,7 +13,7 @@ class cAggressiveMonster :
typedef cMonster super;
public:
cAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
cAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
virtual void Tick (float a_Dt, cChunk & a_Chunk) override;
virtual void InStateChasing(float a_Dt) override;

View File

@ -8,7 +8,7 @@
cBat::cBat(void) :
// TODO: The size is only a guesstimate, measure in vanilla and fix the size values here
super("Bat", 65, "mob.bat.hurt", "mob.bat.death", 0.7, 0.7)
super("Bat", mtBat, "mob.bat.hurt", "mob.bat.death", 0.7, 0.7)
{
}

View File

@ -9,7 +9,7 @@
cBlaze::cBlaze(void) :
// TODO: The size is only a guesstimate, measure in vanilla and fix the size values here
super("Blaze", 61, "mob.blaze.hit", "mob.blaze.death", 0.7, 1.8)
super("Blaze", mtBlaze, "mob.blaze.hit", "mob.blaze.death", 0.7, 1.8)
{
}

View File

@ -9,7 +9,7 @@
cCavespider::cCavespider(void) :
super("Cavespider", 59, "mob.spider.say", "mob.spider.death", 0.7, 0.5)
super("Cavespider", mtCaveSpider, "mob.spider.say", "mob.spider.death", 0.7, 0.5)
{
}

View File

@ -14,7 +14,7 @@
cChicken::cChicken(void) :
super("Chicken", 93, "mob.chicken.hurt", "mob.chicken.hurt", 0.3, 0.4)
super("Chicken", mtChicken, "mob.chicken.hurt", "mob.chicken.hurt", 0.3, 0.4)
{
}

View File

@ -11,7 +11,7 @@
cCow::cCow(void) :
super("Cow", 92, "mob.cow.hurt", "mob.cow.hurt", 0.9, 1.3)
super("Cow", mtCow, "mob.cow.hurt", "mob.cow.hurt", 0.9, 1.3)
{
}

View File

@ -9,7 +9,7 @@
cCreeper::cCreeper(void) :
super("Creeper", 50, "mob.creeper.say", "mob.creeper.say", 0.6, 1.8),
super("Creeper", mtCreeper, "mob.creeper.say", "mob.creeper.say", 0.6, 1.8),
m_bIsBlowing(false),
m_bIsCharged(false)
{

View File

@ -9,7 +9,7 @@
cEnderDragon::cEnderDragon(void) :
// TODO: Vanilla source says this, but is it right? Dragons fly, they don't stand
super("EnderDragon", 63, "mob.enderdragon.hit", "mob.enderdragon.end", 16.0, 8.0)
super("EnderDragon", mtEnderDragon, "mob.enderdragon.hit", "mob.enderdragon.end", 16.0, 8.0)
{
}

View File

@ -8,7 +8,7 @@
cEnderman::cEnderman(void) :
super("Enderman", 58, "mob.endermen.hit", "mob.endermen.death", 0.5, 2.9),
super("Enderman", mtEnderman, "mob.endermen.hit", "mob.endermen.death", 0.5, 2.9),
m_bIsScreaming(false),
CarriedBlock(E_BLOCK_AIR),
CarriedMeta(0)

View File

@ -8,7 +8,7 @@
cGhast::cGhast(void) :
super("Ghast", 56, "mob.ghast.scream", "mob.ghast.death", 4, 4)
super("Ghast", mtGhast, "mob.ghast.scream", "mob.ghast.death", 4, 4)
{
}

View File

@ -9,7 +9,7 @@
cGiant::cGiant(void) :
// TODO: The size is only a guesstimate, measure in vanilla and fix the size values here
super("Giant", 53, "mob.zombie.hurt", "mob.zombie.death", 2.0, 13.5)
super("Giant", mtGiant, "mob.zombie.hurt", "mob.zombie.death", 2.0, 13.5)
{
}

View File

@ -10,7 +10,7 @@
cHorse::cHorse(int Type, int Color, int Style, int TameTimes) :
super("Horse", 100, "mob.horse.hit", "mob.horse.death", 1.4, 1.6),
super("Horse", mtHorse, "mob.horse.hit", "mob.horse.death", 1.4, 1.6),
m_bHasChest(false),
m_bIsEating(false),
m_bIsRearing(false),

View File

@ -8,7 +8,7 @@
cIronGolem::cIronGolem(void) :
super("IronGolem", 99, "mob.IronGolem.hit", "mob.IronGolem.death", 1.4, 2.9)
super("IronGolem", mtIronGolem, "mob.IronGolem.hit", "mob.IronGolem.death", 1.4, 2.9)
{
}

View File

@ -8,7 +8,7 @@
cMagmaCube::cMagmaCube(int a_Size) :
super("MagmaCube", 62, "mob.MagmaCube.big", "mob.MagmaCube.big", 0.6 * a_Size, 0.6 * a_Size),
super("MagmaCube", mtMagmaCube, "mob.MagmaCube.big", "mob.MagmaCube.big", 0.6 * a_Size, 0.6 * a_Size),
m_Size(a_Size)
{
}

View File

@ -25,7 +25,7 @@
cMonster::cMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height)
cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height)
: super(etMonster, a_Width, a_Height)
, m_Target(NULL)
, m_AttackRate(3)
@ -34,7 +34,7 @@ cMonster::cMonster(const AString & a_ConfigName, char a_ProtocolMobType, const A
, m_DestinationTime( 0 )
, m_DestroyTimer( 0 )
, m_Jump(0)
, m_MobType(a_ProtocolMobType)
, m_MobType(a_MobType)
, m_SoundHurt(a_SoundHurt)
, m_SoundDeath(a_SoundDeath)
, m_EMState(IDLE)
@ -514,5 +514,9 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk)
cMonster::eFamily cMonster::GetMobFamily(void) const
{
return cMobTypesManager::getFamilyFromType(GetMobTypeAsEnum());
return cMobTypesManager::FamilyFromType(m_MobType);
}

View File

@ -26,6 +26,8 @@ public:
/// This identifies individual monster type, as well as their network type-ID
enum eType
{
mtInvalidType = -1,
mtBat = E_META_SPAWN_EGG_BAT,
mtBlaze = E_META_SPAWN_EGG_BLAZE,
mtCaveSpider = E_META_SPAWN_EGG_CAVE_SPIDER,
@ -55,7 +57,6 @@ public:
mtWolf = E_META_SPAWN_EGG_WOLF,
mtZombie = E_META_SPAWN_EGG_ZOMBIE,
mtZombiePigman = E_META_SPAWN_EGG_ZOMBIE_PIGMAN,
mtInvalidType
} ;
enum eFamily
@ -74,10 +75,10 @@ public:
/** Creates the mob object.
* If a_ConfigName is not empty, the configuration is loaded using GetMonsterConfig()
* a_ProtocolMobType is the ID of the mob used in the protocol ( http://wiki.vg/Entities#Mobs , 2012_12_22)
* 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
*/
cMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
cMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
CLASS_PROTODEF(cMonster);
@ -92,9 +93,10 @@ public:
virtual void MoveToPosition(const Vector3f & a_Position);
virtual bool ReachedDestination(void);
char GetMobType(void) const {return m_MobType; } // MG TODO : see if we can delete this one.
eType GetMobTypeAsEnum(void) const {return (eType)m_MobType; } // MG TODO : see if we should store m_MobType as enum instead of char.
// tolua_begin
eType GetMobType(void) const {return m_MobType; }
eFamily GetMobFamily(void) const;
// tolua_end
const char * GetState();
@ -116,8 +118,6 @@ public:
virtual void Attack(float a_Dt);
int GetMobType() { return m_MobType; } // tolua_export
int GetAttackRate(){return (int)m_AttackRate;}
void SetAttackRate(int ar);
void SetAttackRange(float ar);
@ -150,7 +150,7 @@ protected:
float m_DestroyTimer;
float m_Jump;
char m_MobType;
eType m_MobType;
AString m_SoundHurt;
AString m_SoundDeath;

View File

@ -14,7 +14,7 @@
cMooshroom::cMooshroom(void) :
super("Mooshroom", 96, "mob.cow.hurt", "mob.cow.hurt", 0.9, 1.3)
super("Mooshroom", mtMooshroom, "mob.cow.hurt", "mob.cow.hurt", 0.9, 1.3)
{
}

View File

@ -14,7 +14,7 @@ class cOcelot :
public:
cOcelot(void) :
super("Ocelot", 98, "mob.cat.hitt", "mob.cat.hitt", 0.6, 0.8)
super("Ocelot", mtOcelot, "mob.cat.hitt", "mob.cat.hitt", 0.6, 0.8)
{
}

View File

@ -9,8 +9,8 @@
cPassiveAggressiveMonster::cPassiveAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
super(a_ConfigName, a_ProtocolMobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
cPassiveAggressiveMonster::cPassiveAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
{
m_EMPersonality = PASSIVE;
}

View File

@ -13,7 +13,7 @@ class cPassiveAggressiveMonster :
typedef cAggressiveMonster super;
public:
cPassiveAggressiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
cPassiveAggressiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
} ;

View File

@ -9,8 +9,8 @@
cPassiveMonster::cPassiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
super(a_ConfigName, a_ProtocolMobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
cPassiveMonster::cPassiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) :
super(a_ConfigName, a_MobType, a_SoundHurt, a_SoundDeath, a_Width, a_Height)
{
m_EMPersonality = PASSIVE;
}

View File

@ -13,7 +13,7 @@ class cPassiveMonster :
typedef cMonster super;
public:
cPassiveMonster(const AString & a_ConfigName, char a_ProtocolMobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
cPassiveMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height);
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;

View File

@ -10,7 +10,7 @@
cPig::cPig(void) :
super("Pig", 90, "mob.pig.say", "mob.pig.death", 0.9, 0.9),
super("Pig", mtPig, "mob.pig.say", "mob.pig.death", 0.9, 0.9),
m_bIsSaddled(false)
{
}

View File

@ -11,7 +11,7 @@
cSheep::cSheep(int a_Color) :
super("Sheep", 91, "mob.sheep.say", "mob.sheep.say", 0.6, 1.3),
super("Sheep", mtSheep, "mob.sheep.say", "mob.sheep.say", 0.6, 1.3),
m_IsSheared(false),
m_WoolColor(a_Color)
{

View File

@ -14,7 +14,7 @@ class cSilverfish :
public:
cSilverfish(void) :
super("Silverfish", 60, "mob.silverfish.hit", "mob.silverfish.kill", 0.3, 0.7)
super("Silverfish", mtSilverfish, "mob.silverfish.hit", "mob.silverfish.kill", 0.3, 0.7)
{
}

View File

@ -9,7 +9,7 @@
cSkeleton::cSkeleton(bool IsWither) :
super("Skeleton", 51, "mob.skeleton.hurt", "mob.skeleton.death", 0.6, 1.8),
super("Skeleton", mtSkeleton, "mob.skeleton.hurt", "mob.skeleton.death", 0.6, 1.8),
m_bIsWither(IsWither)
{
SetBurnsInDaylight(true);

View File

@ -9,7 +9,7 @@
/// Creates a slime of the specified size; size is 1 .. 3, with 1 being the smallest
cSlime::cSlime(int a_Size) :
super("Slime", 55, "mob.slime.attack", "mob.slime.attack", 0.6 * a_Size, 0.6 * a_Size),
super("Slime", mtSlime, "mob.slime.attack", "mob.slime.attack", 0.6 * a_Size, 0.6 * a_Size),
m_Size(a_Size)
{
}

View File

@ -8,7 +8,7 @@
cSnowGolem::cSnowGolem(void) :
super("SnowGolem", 97, "", "", 0.4, 1.8)
super("SnowGolem", mtSnowGolem, "", "", 0.4, 1.8)
{
}

View File

@ -8,7 +8,7 @@
cSpider::cSpider(void) :
super("Spider", 52, "mob.spider.say", "mob.spider.death", 1.4, 0.9)
super("Spider", mtSpider, "mob.spider.say", "mob.spider.death", 1.4, 0.9)
{
}

View File

@ -10,7 +10,7 @@
cSquid::cSquid(void) :
super("Squid", 94, "", "", 0.95, 0.95)
super("Squid", mtSquid, "", "", 0.95, 0.95)
{
}

View File

@ -9,7 +9,7 @@
cVillager::cVillager(eVillagerType VillagerType) :
super("Villager", 120, "", "", 0.6, 1.8),
super("Villager", mtVillager, "", "", 0.6, 1.8),
m_Type(VillagerType)
{
}

View File

@ -8,7 +8,7 @@
cWitch::cWitch(void) :
super("Witch", 66, "", "", 0.6, 1.8)
super("Witch", mtWitch, "", "", 0.6, 1.8)
{
}

View File

@ -8,7 +8,7 @@
cWither::cWither(void) :
super("Wither", 64, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0)
super("Wither", mtWither, "mob.wither.hurt", "mob.wither.death", 0.9, 4.0)
{
}

View File

@ -10,7 +10,7 @@
cWolf::cWolf(void) :
super("Wolf", 95, "mob.wolf.hurt", "mob.wolf.death", 0.6, 0.8),
super("Wolf", mtWolf, "mob.wolf.hurt", "mob.wolf.death", 0.6, 0.8),
m_bIsAngry(false),
m_bIsTame(false),
m_bIsSitting(false),

View File

@ -9,7 +9,7 @@
cZombie::cZombie(bool IsVillagerZombie) :
super("Zombie", 54, "mob.zombie.hurt", "mob.zombie.death", 0.6, 1.8),
super("Zombie", mtZombie, "mob.zombie.hurt", "mob.zombie.death", 0.6, 1.8),
m_bIsConverting(false),
m_bIsVillagerZombie(IsVillagerZombie)
{

View File

@ -9,7 +9,7 @@
cZombiePigman::cZombiePigman(void) :
super("ZombiePigman", 57, "mob.zombiepig.zpighurt", "mob.zombiepig.zpigdeath", 0.6, 1.8)
super("ZombiePigman", mtZombiePigman, "mob.zombiepig.zpighurt", "mob.zombiepig.zpigdeath", 0.6, 1.8)
{
}

View File

@ -489,19 +489,36 @@ void cWorld::Start(void)
m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode);
m_bAnimals = IniFile.GetValueB("Monsters", "AnimalsOn", true);
AString sAllMonsters = IniFile.GetValue("Monsters", "Types");
AStringVector SplitList = StringSplit(sAllMonsters, ",");
for (unsigned int i = 0; i < SplitList.size(); ++i)
// Load allowed mobs:
const char * DefaultMonsters = "";
switch (m_Dimension)
{
cMonster::eType ToAdd = cMobTypesManager::fromStringToMobType(SplitList[i]);
case dimOverworld: DefaultMonsters = "bat, cavespider, chicken, cow, creeper, enderman, horse, mooshroom, ocelot, pig, sheep, silverfish, skeleton, slime, spider, squid, wolf, zombie"; break;
case dimNether: DefaultMonsters = "blaze, ghast, magmacube, skeleton, zombie, zombiepigman"; break;
case dimEnd: DefaultMonsters = "enderman"; break;
default:
{
ASSERT(!"Unhandled world dimension");
DefaultMonsters = "wither";
break;
}
}
m_bAnimals = IniFile.GetValueB("Monsters", "AnimalsOn", true);
AString AllMonsters = IniFile.GetValueSet("Monsters", "Types", DefaultMonsters);
AStringVector SplitList = StringSplitAndTrim(AllMonsters, ",");
for (AStringVector::const_iterator itr = SplitList.begin(), end = SplitList.end(); itr != end; ++itr)
{
cMonster::eType ToAdd = cMobTypesManager::StringToMobType(*itr);
if (ToAdd != cMonster::mtInvalidType)
{
m_AllowedMobs.insert(ToAdd);
LOGD("Allowed mob: %s",cMobTypesManager::fromMobTypeToString(ToAdd).c_str()); // a bit reverse working, but very few ressources wasted
LOGD("Allowed mob: %s", cMobTypesManager::MobTypeToString(ToAdd).c_str()); // a bit reverse working, but very few ressources wasted
}
else
{
LOG("World \"%s\": Unknown mob type: %s", m_WorldName.c_str(), itr->c_str());
}
}
};
m_ChunkMap = new cChunkMap(this);
@ -532,10 +549,10 @@ void cWorld::Start(void)
m_TickThread.Start();
// Init of the spawn monster time (as they are supposed to have different spawn rate)
m_LastSpawnMonster.insert(std::map<cMonster::eFamily,Int64>::value_type(cMonster::mfHostile,0));
m_LastSpawnMonster.insert(std::map<cMonster::eFamily,Int64>::value_type(cMonster::mfPassive,0));
m_LastSpawnMonster.insert(std::map<cMonster::eFamily,Int64>::value_type(cMonster::mfAmbient,0));
m_LastSpawnMonster.insert(std::map<cMonster::eFamily,Int64>::value_type(cMonster::mfWater,0));
m_LastSpawnMonster.insert(std::map<cMonster::eFamily, Int64>::value_type(cMonster::mfHostile, 0));
m_LastSpawnMonster.insert(std::map<cMonster::eFamily, Int64>::value_type(cMonster::mfPassive, 0));
m_LastSpawnMonster.insert(std::map<cMonster::eFamily, Int64>::value_type(cMonster::mfAmbient, 0));
m_LastSpawnMonster.insert(std::map<cMonster::eFamily, Int64>::value_type(cMonster::mfWater, 0));
// Save any changes that the defaults may have done to the ini file: