From 210cd4eb50bd9470611e772dfb1ae20997996710 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Mon, 14 Oct 2013 11:12:12 -0600 Subject: General fixes to get the new Monster spawning code working. Also wrote in some code to use the default settings for monsters located in settings.ini --- source/World.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/World.cpp b/source/World.cpp index 7a9bf46af..3a4469c99 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -444,6 +444,12 @@ void cWorld::Start(void) m_SpawnY = cChunkDef::Height; m_SpawnZ = (double)((m_TickRand.randInt() % 1000) - 500); m_GameMode = eGameMode_Creative; + static AString SettingsName = "settings.ini"; + cIniFile Settings(SettingsName); + if (!Settings.ReadFile()) + { + LOGWARNING("Cannot read world settings from \"%s\", defaults will be used.", SettingsName.c_str()); + } cIniFile IniFile(m_IniFileName); if (!IniFile.ReadFile()) @@ -489,8 +495,11 @@ void cWorld::Start(void) m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode); - m_bAnimals = IniFile.GetValueB("Monsters", "AnimalsOn", true); + m_bAnimals = Settings.GetValueB("Monsters", "AnimalsOn", true); + m_bAnimals = IniFile.GetValueB("Monsters", "AnimalsOn", m_bAnimals); AString sAllMonsters = IniFile.GetValue("Monsters", "Types"); + if (!sAllMonsters.size()) + sAllMonsters = Settings.GetValue("Monsters", "Types"); AStringVector SplitList = StringSplit(sAllMonsters, ","); for (unsigned int i = 0; i < SplitList.size(); ++i) { @@ -728,7 +737,6 @@ void cWorld::TickMobs(float a_Dt) // before every Mob action, we have to "counts" them depending on the distance to players, on their megatype ... cMobCensus MobCensus; m_ChunkMap->CollectMobCensus(MobCensus); - for(cMobFamilyCollecter::tMobFamilyList::const_iterator itr = cMobFamilyCollecter::m_AllFamilies().begin(); itr != cMobFamilyCollecter::m_AllFamilies().end(); itr++) { cMobCensus::tMobSpawnRate::const_iterator spawnrate = cMobCensus::m_SpawnRate().find(*itr); @@ -741,6 +749,7 @@ void cWorld::TickMobs(float a_Dt) { if (m_bAnimals) { + cMobSpawner Spawner(*itr,m_AllowedMobs); if (Spawner.CanSpawnSomething()) { @@ -2511,11 +2520,11 @@ int cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eTyp int SlSize = GetTickRandomNumber(2) + 1; // 1 .. 3 - Slime int ShColor = GetTickRandomNumber(15); // 0 .. 15 - Sheep - bool SkType = GetDimension() == biNether; // Skeleton - - cMobTypesManager::NewMonsterFromType(a_MonsterType); - Monster->SetPosition(a_PosX, a_PosY, a_PosZ); + bool SkType = GetDimension() == dimNether ; // Skeleton + Monster = cMobTypesManager::NewMonsterFromType(a_MonsterType); + if (Monster) + Monster->SetPosition(a_PosX, a_PosY, a_PosZ); return SpawnMobFinalize(Monster); } @@ -2524,6 +2533,8 @@ int cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eTyp int cWorld::SpawnMobFinalize(cMonster* a_Monster) { + if (!a_Monster) + return -1; a_Monster->SetHealth(a_Monster->GetMaxHealth()); if (cPluginManager::Get()->CallHookSpawningMonster(*this, *a_Monster)) { -- cgit v1.2.3