summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-11-29 15:20:44 +0100
committerHowaner <franzi.moos@googlemail.com>2014-11-29 15:20:44 +0100
commit2478e290f9f7f6a74bba4ac885cfaef6327bc9ee (patch)
tree54d9f9d97e3a1ed850f63292e002938e3d8d3ff0 /src/Mobs
parentMerge branch 'master' into MobSpawner (diff)
downloadcuberite-2478e290f9f7f6a74bba4ac885cfaef6327bc9ee.tar
cuberite-2478e290f9f7f6a74bba4ac885cfaef6327bc9ee.tar.gz
cuberite-2478e290f9f7f6a74bba4ac885cfaef6327bc9ee.tar.bz2
cuberite-2478e290f9f7f6a74bba4ac885cfaef6327bc9ee.tar.lz
cuberite-2478e290f9f7f6a74bba4ac885cfaef6327bc9ee.tar.xz
cuberite-2478e290f9f7f6a74bba4ac885cfaef6327bc9ee.tar.zst
cuberite-2478e290f9f7f6a74bba4ac885cfaef6327bc9ee.zip
Diffstat (limited to 'src/Mobs')
-rw-r--r--src/Mobs/Monster.cpp113
-rw-r--r--src/Mobs/Monster.h11
2 files changed, 68 insertions, 56 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 5319bdf91..9937e6a95 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -26,36 +26,37 @@ static const struct
{
eMonsterType m_Type;
const char * m_lcName;
+ const char * m_VanillaName;
} g_MobTypeNames[] =
{
- {mtBat, "bat"},
- {mtBlaze, "blaze"},
- {mtCaveSpider, "cavespider"},
- {mtChicken, "chicken"},
- {mtCow, "cow"},
- {mtCreeper, "creeper"},
- {mtEnderman, "enderman"},
- {mtEnderDragon, "enderdragon"},
- {mtGhast, "ghast"},
- {mtHorse, "horse"},
- {mtIronGolem, "irongolem"},
- {mtMagmaCube, "magmacube"},
- {mtMooshroom, "mooshroom"},
- {mtOcelot, "ocelot"},
- {mtPig, "pig"},
- {mtSheep, "sheep"},
- {mtSilverfish, "silverfish"},
- {mtSkeleton, "skeleton"},
- {mtSlime, "slime"},
- {mtSnowGolem, "snowgolem"},
- {mtSpider, "spider"},
- {mtSquid, "squid"},
- {mtVillager, "villager"},
- {mtWitch, "witch"},
- {mtWither, "wither"},
- {mtWolf, "wolf"},
- {mtZombie, "zombie"},
- {mtZombiePigman, "zombiepigman"},
+ {mtBat, "bat", "Bat"},
+ {mtBlaze, "blaze", "Blaze"},
+ {mtCaveSpider, "cavespider", "CaveSpider"},
+ {mtChicken, "chicken", "Chicken"},
+ {mtCow, "cow", "Cow"},
+ {mtCreeper, "creeper", "Creeper"},
+ {mtEnderman, "enderman", "Enderman"},
+ {mtEnderDragon, "enderdragon", "EnderDragon"},
+ {mtGhast, "ghast", "Ghast"},
+ {mtHorse, "horse", "EntityHorse"},
+ {mtIronGolem, "irongolem", "VillagerGolem"},
+ {mtMagmaCube, "magmacube", "LavaSlime"},
+ {mtMooshroom, "mooshroom", "MushroomCow"},
+ {mtOcelot, "ocelot", "Ozelot"},
+ {mtPig, "pig", "Pig"},
+ {mtSheep, "sheep", "Sheep"},
+ {mtSilverfish, "silverfish", "Silverfish"},
+ {mtSkeleton, "skeleton", "Skeleton"},
+ {mtSlime, "slime", "Slime"},
+ {mtSnowGolem, "snowgolem", "SnowMan"},
+ {mtSpider, "spider", "Spider"},
+ {mtSquid, "squid", "Squid"},
+ {mtVillager, "villager", "Villager"},
+ {mtWitch, "witch", "Witch"},
+ {mtWither, "wither", "WitherBoss"},
+ {mtWolf, "wolf", "Wolf"},
+ {mtZombie, "zombie", "Zombie"},
+ {mtZombiePigman, "zombiepigman", "PigZombie"},
} ;
@@ -784,39 +785,47 @@ AString cMonster::MobTypeToString(eMonsterType a_MobType)
-eMonsterType cMonster::StringToMobType(const AString & a_Name)
+AString cMonster::MobTypeToVanillaName(eMonsterType a_MobType)
{
- AString lcName = StrToLower(a_Name);
-
- // Binary-search for the lowercase name:
- int lo = 0, hi = ARRAYCOUNT(g_MobTypeNames) - 1;
- while (hi - lo > 1)
+ // Mob types aren't sorted, so we need to search linearly:
+ for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
{
- 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)
- {
- lo = mid;
- }
- else
+ if (g_MobTypeNames[i].m_Type == a_MobType)
{
- hi = mid;
+ return g_MobTypeNames[i].m_VanillaName;
}
}
- // Range has collapsed to at most two elements, compare each:
- if (strcmp(g_MobTypeNames[lo].m_lcName, lcName.c_str()) == 0)
+
+ // Not found:
+ return "";
+}
+
+
+
+
+
+eMonsterType cMonster::StringToMobType(const AString & a_Name)
+{
+ AString lcName = StrToLower(a_Name);
+
+ // Search MCServer name:
+ for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
{
- return g_MobTypeNames[lo].m_Type;
+ if (strcmp(g_MobTypeNames[i].m_lcName, lcName.c_str()) == 0)
+ {
+ return g_MobTypeNames[i].m_Type;
+ }
}
- if ((lo != hi) && (strcmp(g_MobTypeNames[hi].m_lcName, lcName.c_str()) == 0))
+
+ // Not found. Search Vanilla name:
+ for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
{
- return g_MobTypeNames[hi].m_Type;
+ if (strcmp(StrToLower(g_MobTypeNames[i].m_VanillaName).c_str(), lcName.c_str()) == 0)
+ {
+ return g_MobTypeNames[i].m_Type;
+ }
}
-
+
// Not found:
return mtInvalidType;
}
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index fd4e8a659..4903c38ad 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -133,16 +133,19 @@ public:
If it's false, you only see the name when you sight the mob. If it's true, you always see the custom name. */
void SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible);
- /// Translates MobType enum to a string, empty string if unknown
+ /** Translates MobType enum to a string, empty string if unknown */
static AString MobTypeToString(eMonsterType a_MobType);
- /// Translates MobType string to the enum, mtInvalidType if not recognized
+ /** Translates MobType enum to the correct vanilla name of the mob, empty string if unknown. */
+ static AString MobTypeToVanillaName(eMonsterType a_MobType);
+
+ /** Translates MobType string to the enum, mtInvalidType if not recognized */
static eMonsterType StringToMobType(const AString & a_MobTypeName);
- /// Returns the mob family based on the type
+ /** Returns the mob family based on the type */
static eFamily FamilyFromType(eMonsterType a_MobType);
- /// Returns the spawn delay (number of game ticks between spawn attempts) for the given mob family
+ /** Returns the spawn delay (number of game ticks between spawn attempts) for the given mob family */
static int GetSpawnDelay(cMonster::eFamily a_MobFamily);
// tolua_end