From 2478e290f9f7f6a74bba4ac885cfaef6327bc9ee Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 29 Nov 2014 15:20:44 +0100 Subject: Many api fixes, add vanilla names to mob type -> string functions and mob spawner fixes. --- src/Mobs/Monster.cpp | 113 +++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 52 deletions(-) (limited to 'src/Mobs/Monster.cpp') 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; } -- cgit v1.2.3 From bcbd73f7d80b0a64b87c30840048f99613308ce0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Dec 2014 14:58:13 +0100 Subject: MobSpawner fixes. --- src/Mobs/Monster.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 3011acd85..b8926e31d 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -21,6 +21,7 @@ /** 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()) +m_VanillaName is the name that vanilla use for this mob. */ static const struct { -- cgit v1.2.3