From cb584a87bd8336d590941cec0c204cbf75ab53eb Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Mon, 1 Dec 2014 11:44:20 -0800 Subject: [PATCH 01/32] cacti no longer spawn outside of desert variants --- src/Generating/FinishGen.cpp | 14 +++++++++++++- src/Generating/FinishGen.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index b9d702429..e09646758 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -370,7 +370,8 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) (a_ChunkDesc.GetBlockType(x + 1, y, z) == E_BLOCK_AIR) && (a_ChunkDesc.GetBlockType(x - 1, y, z) == E_BLOCK_AIR) && (a_ChunkDesc.GetBlockType(x, y, z + 1) == E_BLOCK_AIR) && - (a_ChunkDesc.GetBlockType(x, y, z - 1) == E_BLOCK_AIR) + (a_ChunkDesc.GetBlockType(x, y, z - 1) == E_BLOCK_AIR) && + IsDesertVariant(a_ChunkDesc.GetBiome(x, z) ) { a_ChunkDesc.SetBlockType(x, ++Top, z, E_BLOCK_CACTUS); @@ -391,6 +392,17 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) +bool cFinishGenSprinkleFoliage::IsDesertVariant(EMCSBiome a_biome) +{ + return a_biome == biDesertHills || + a_biome == biDesert || + a_biome == biDesertM; +} + + + + + //////////////////////////////////////////////////////////////////////////////// // cFinishGenSoulsandRims diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index d45365683..16128efa5 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -149,6 +149,9 @@ protected: /// Tries to place sugarcane at the coords specified, returns true if successful bool TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ); + // Checks if biome is a desert to spawn cacti as opposed to just sand + bool IsDesertVariant(EMCSBiome a_biome); + // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; From 3bf111c69e11623947da70520063c57238d67bf0 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Mon, 1 Dec 2014 17:28:46 -0800 Subject: [PATCH 02/32] formatting and commenting fixes --- src/Generating/FinishGen.cpp | 8 ++++---- src/Generating/FinishGen.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index e09646758..cba45c0a1 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -392,11 +392,11 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) -bool cFinishGenSprinkleFoliage::IsDesertVariant(EMCSBiome a_biome) +bool cFinishGenSprinkleFoliage::IsDesertVariant(EMCSBiome a_Biome) { - return a_biome == biDesertHills || - a_biome == biDesert || - a_biome == biDesertM; + return (a_Biome == biDesertHills) || + (a_Biome == biDesert ) || + (a_Biome == biDesertM ); } diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index 16128efa5..dd6a09c6a 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -149,8 +149,8 @@ protected: /// Tries to place sugarcane at the coords specified, returns true if successful bool TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ); - // Checks if biome is a desert to spawn cacti as opposed to just sand - bool IsDesertVariant(EMCSBiome a_biome); + // Returns true is the specified biome is a desert or its variant + static bool IsDesertVariant(EMCSBiome a_biome); // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; From bb5a7d8f151bc7c2426f16becc5f7a0c70ca7fef Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Mon, 1 Dec 2014 17:47:36 -0800 Subject: [PATCH 03/32] reformat for lua and CI --- src/Generating/FinishGen.cpp | 13 ++++++++----- src/Generating/FinishGen.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index cba45c0a1..7ef658dc2 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -371,7 +371,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) (a_ChunkDesc.GetBlockType(x - 1, y, z) == E_BLOCK_AIR) && (a_ChunkDesc.GetBlockType(x, y, z + 1) == E_BLOCK_AIR) && (a_ChunkDesc.GetBlockType(x, y, z - 1) == E_BLOCK_AIR) && - IsDesertVariant(a_ChunkDesc.GetBiome(x, z) + IsDesertVariant(a_ChunkDesc.GetBiome(x, z)) ) { a_ChunkDesc.SetBlockType(x, ++Top, z, E_BLOCK_CACTUS); @@ -394,9 +394,12 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) bool cFinishGenSprinkleFoliage::IsDesertVariant(EMCSBiome a_Biome) { - return (a_Biome == biDesertHills) || - (a_Biome == biDesert ) || - (a_Biome == biDesertM ); + return + ( + (a_Biome == biDesertHills) || + (a_Biome == biDesert) || + (a_Biome == biDesertM) + ); } @@ -412,7 +415,7 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc) int ChunkZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; HEIGHTTYPE MaxHeight = a_ChunkDesc.GetMaxHeight(); - for (int x = 0; x < 16; x++) + for (int x = 0; x < 16; x++) { int xx = ChunkX + x; for (int z = 0; z < 16; z++) diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index dd6a09c6a..d8d67671d 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -121,7 +121,7 @@ class cFinishGenSoulsandRims : public cFinishGen { public: - cFinishGenSoulsandRims(int a_Seed) : + cFinishGenSoulsandRims(int a_Seed) : m_Noise(a_Seed) { } From 9831220a1cfc84804619e497f8b56853de98bf82 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 01:37:17 -0800 Subject: [PATCH 04/32] animal terrain finisher --- src/Generating/FinishGen.cpp | 212 +++++++++++++++++++++++++++++++++++ src/Generating/FinishGen.h | 29 +++++ 2 files changed, 241 insertions(+) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index b9d702429..b8575f4f8 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -26,6 +26,8 @@ #define DEF_OVERWORLD_LAVA_SPRINGS "0, 0; 10, 5; 11, 45; 48, 2; 64, 1; 255, 0" #define DEF_END_WATER_SPRINGS "0, 1; 255, 1" #define DEF_END_LAVA_SPRINGS "0, 1; 255, 1" +#define DEF_ANIMAL_SPAWN_PERCENT 10 +#define DEF_NO_ANIMALS 0 @@ -943,3 +945,213 @@ bool cFinishGenFluidSprings::TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int + +//////////////////////////////////////////////////////////////////////////////// +// cFinishGenPassiveMobs: + +cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension) : + m_Noise(a_Seed) +{ + AString SectionName = "Animals"; + int DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; + switch (a_Dimension) + { + case dimOverworld: + { + DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; + break; + } + case dimNether: + case dimEnd: // No nether or end animals (currently) + { + DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS; + break; + } + default: + { + ASSERT(!"Unhandled world dimension"); + break; + } + } // switch (dimension) + m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); + if (m_AnimalProbability < 0 || m_AnimalProbability > 100) + { + LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); + } +} + + + + + +void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) +{ + int ChanceRnd = m_Random.NextInt(100); + if (ChanceRnd > m_AnimalProbability) + { + return; + } + + eMonsterType RandomMob = GetRandomMob(a_ChunkDesc); + if (RandomMob == mtInvalidType) + { + LOGWARNING("Attempted to spawn invalid mob type."); + return; + } + + // Try spawning a pack center 10 times, should get roughly the same probability + for (int Tries = 0; Tries < 10; Tries++) + { + int PackCenterX = m_Random.NextInt(cChunkDef::Width - 1); + int PackCenterZ = m_Random.NextInt(cChunkDef::Width - 1); + if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob)) + { + for (int i = 0; i < 5; i++) + { + int OffsetX = m_Random.NextInt(cChunkDef::Width - 1); + int OffsetZ = m_Random.NextInt(cChunkDef::Width - 1); + TrySpawnAnimals(a_ChunkDesc, OffsetX, a_ChunkDesc.GetHeight(OffsetX, OffsetZ), OffsetZ, RandomMob); + } + + return; + + } // if pack center spawn successful + } // for tries +} + + + + + +bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, eMonsterType AnimalToSpawn) +{ + BLOCKTYPE BlockAtHead = a_ChunkDesc.GetBlockType(a_RelX, a_RelY + 1, a_RelZ); + BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY , a_RelZ); + BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ); + + // Check block below (opaque, grass, water), and above (air) + if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER) + { + return false; + } + if ( + (AnimalToSpawn != mtSquid) && + (BlockAtHead != E_BLOCK_AIR) && + (BlockAtFeet != E_BLOCK_AIR) && + (!cBlockInfo::IsTransparent(BlockUnderFeet)) + ) + { + return false; + } + if ( + (BlockUnderFeet != E_BLOCK_GRASS) && + ( + (AnimalToSpawn == mtSheep) || + (AnimalToSpawn == mtChicken) || + (AnimalToSpawn == mtPig) + ) + ) + { + return false; + } + + int AnimalX, AnimalY, AnimalZ; + AnimalX = (double)(a_ChunkDesc.GetChunkX()*cChunkDef::Width + a_RelX + 0.5); + AnimalY = a_RelY; + AnimalZ = (double)(a_ChunkDesc.GetChunkZ()*cChunkDef::Width + a_RelZ + 0.5); + + cEntityList ChunkEntities = a_ChunkDesc.GetEntities(); + cMonster * NewMob = cMonster::NewMonsterFromType(AnimalToSpawn); + NewMob->SetPosition(AnimalX, AnimalY, AnimalZ); + ChunkEntities.push_back(NewMob); + LOGD("Spawning %s #%i at {%d, %d, %d}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ); + + return true; +} + + + + + +eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) +{ + + std::set ListOfSpawnables; + std::set::iterator MobIter = ListOfSpawnables.begin(); + int x = m_Random.NextInt(cChunkDef::Width - 1); + int z = m_Random.NextInt(cChunkDef::Width - 1); + + // Check biomes first to get a list of animals + switch (a_ChunkDesc.GetBiome(x, z)) + { + // No animals + case biNether: + case biEnd: + return mtInvalidType; + + // Squid only + case biOcean: + case biFrozenOcean: + case biFrozenRiver: + case biRiver: + case biDeepOcean: + ListOfSpawnables.insert(MobIter, mtSquid); + break; + + // Mooshroom only + case biMushroomIsland: + case biMushroomShore: + ListOfSpawnables.insert(MobIter, mtMooshroom); + break; + + case biJungle: + case biJungleHills: + case biJungleEdge: + case biJungleM: + case biJungleEdgeM: + ListOfSpawnables.insert(MobIter, mtOcelot); + + case biPlains: + case biSunflowerPlains: + case biSavanna: + case biSavannaPlateau: + case biSavannaM: + case biSavannaPlateauM: + ListOfSpawnables.insert(MobIter, mtHorse); + // ListOfSpawnables.insert(mtDonkey); + + // Wolves only + case biForest: + case biTaiga: + case biMegaTaiga: + case biColdTaiga: + case biColdTaigaM: + ListOfSpawnables.insert(MobIter, mtWolf); + + // All other mobs + default: + ListOfSpawnables.insert(MobIter, mtChicken); + ListOfSpawnables.insert(MobIter, mtCow); + ListOfSpawnables.insert(MobIter, mtPig); + ListOfSpawnables.insert(MobIter, mtSheep); + } + + if (ListOfSpawnables.size() == 0) + { + LOGD("Tried to spawn an animal from an empty list."); + return mtInvalidType; + } + + int RandMob = m_Random.NextInt(ListOfSpawnables.size()); + MobIter=ListOfSpawnables.begin(); + for (int i = 0; i < RandMob; i++) + { + ++MobIter; + } + + return *MobIter; +} + + + + diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index d45365683..38bb93d2a 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -18,6 +18,8 @@ #include "ComposableGenerator.h" #include "../Noise/Noise.h" #include "../ProbabDistrib.h" +#include "../Mobs/Monster.h" +#include "FastRandom.h" @@ -315,3 +317,30 @@ protected: + +class cFinishGenPassiveMobs : + public cFinishGen +{ +public: + + cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension); + +protected: + + cNoise m_Noise; + int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk + cFastRandom m_Random; + + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; + + // Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more. + bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn); + + // Gets a random mob from biome-dependant list + eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc); +} ; + + + + From 2d93274a90a86829ff6edfa02dd575c8811a6cfd Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 01:58:30 -0800 Subject: [PATCH 05/32] animal terrain finisher --- src/Generating/FinishGen.cpp | 314 +++++++++++++++++------------------ src/Generating/FinishGen.h | 24 +-- 2 files changed, 169 insertions(+), 169 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index b8575f4f8..296e92139 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -402,7 +402,7 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc) int ChunkZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; HEIGHTTYPE MaxHeight = a_ChunkDesc.GetMaxHeight(); - for (int x = 0; x < 16; x++) + for (int x = 0; x < 16; x++) { int xx = ChunkX + x; for (int z = 0; z < 16; z++) @@ -950,34 +950,34 @@ bool cFinishGenFluidSprings::TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int // cFinishGenPassiveMobs: cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension) : - m_Noise(a_Seed) + m_Noise(a_Seed) { - AString SectionName = "Animals"; - int DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; - switch (a_Dimension) - { - case dimOverworld: - { - DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; - break; - } - case dimNether: - case dimEnd: // No nether or end animals (currently) - { - DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS; - break; - } - default: - { - ASSERT(!"Unhandled world dimension"); - break; - } - } // switch (dimension) - m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); - if (m_AnimalProbability < 0 || m_AnimalProbability > 100) - { - LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); - } + AString SectionName = "Animals"; + int DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; + switch (a_Dimension) + { + case dimOverworld: + { + DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; + break; + } + case dimNether: + case dimEnd:// No nether or end animals (currently) + { + DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS; + break; + } + default: + { + ASSERT(!"Unhandled world dimension"); + break; + } + }// switch (dimension) + m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); + if (m_AnimalProbability < 0 || m_AnimalProbability > 100) + { + LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); + } } @@ -986,37 +986,37 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) { - int ChanceRnd = m_Random.NextInt(100); - if (ChanceRnd > m_AnimalProbability) - { - return; - } + int ChanceRnd = m_Random.NextInt(100); + if (ChanceRnd > m_AnimalProbability) + { + return; + } - eMonsterType RandomMob = GetRandomMob(a_ChunkDesc); - if (RandomMob == mtInvalidType) - { - LOGWARNING("Attempted to spawn invalid mob type."); - return; - } + eMonsterType RandomMob = GetRandomMob(a_ChunkDesc); + if (RandomMob == mtInvalidType) + { + LOGWARNING("Attempted to spawn invalid mob type."); + return; + } - // Try spawning a pack center 10 times, should get roughly the same probability - for (int Tries = 0; Tries < 10; Tries++) - { - int PackCenterX = m_Random.NextInt(cChunkDef::Width - 1); - int PackCenterZ = m_Random.NextInt(cChunkDef::Width - 1); - if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob)) - { - for (int i = 0; i < 5; i++) - { - int OffsetX = m_Random.NextInt(cChunkDef::Width - 1); - int OffsetZ = m_Random.NextInt(cChunkDef::Width - 1); - TrySpawnAnimals(a_ChunkDesc, OffsetX, a_ChunkDesc.GetHeight(OffsetX, OffsetZ), OffsetZ, RandomMob); - } + // Try spawning a pack center 10 times, should get roughly the same probability + for (int Tries = 0; Tries < 10; Tries++) + { + int PackCenterX = m_Random.NextInt(cChunkDef::Width - 1); + int PackCenterZ = m_Random.NextInt(cChunkDef::Width - 1); + if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob)) + { + for (int i = 0; i < 5; i++) + { + int OffsetX = m_Random.NextInt(cChunkDef::Width - 1); + int OffsetZ = m_Random.NextInt(cChunkDef::Width - 1); + TrySpawnAnimals(a_ChunkDesc, OffsetX, a_ChunkDesc.GetHeight(OffsetX, OffsetZ), OffsetZ, RandomMob); + } - return; + return; - } // if pack center spawn successful - } // for tries + }// if pack center spawn successful + }// for tries } @@ -1025,48 +1025,48 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, eMonsterType AnimalToSpawn) { - BLOCKTYPE BlockAtHead = a_ChunkDesc.GetBlockType(a_RelX, a_RelY + 1, a_RelZ); - BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY , a_RelZ); - BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ); + BLOCKTYPE BlockAtHead = a_ChunkDesc.GetBlockType(a_RelX, a_RelY + 1, a_RelZ); + BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ); + BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ); - // Check block below (opaque, grass, water), and above (air) - if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER) - { - return false; - } - if ( - (AnimalToSpawn != mtSquid) && - (BlockAtHead != E_BLOCK_AIR) && - (BlockAtFeet != E_BLOCK_AIR) && - (!cBlockInfo::IsTransparent(BlockUnderFeet)) - ) - { - return false; - } - if ( - (BlockUnderFeet != E_BLOCK_GRASS) && - ( - (AnimalToSpawn == mtSheep) || - (AnimalToSpawn == mtChicken) || - (AnimalToSpawn == mtPig) - ) - ) - { - return false; - } + // Check block below (opaque, grass, water), and above (air) + if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER) + { + return false; + } + if ( + (AnimalToSpawn != mtSquid) && + (BlockAtHead != E_BLOCK_AIR) && + (BlockAtFeet != E_BLOCK_AIR) && + (!cBlockInfo::IsTransparent(BlockUnderFeet)) + ) + { + return false; + } + if ( + (BlockUnderFeet != E_BLOCK_GRASS) && + ( + (AnimalToSpawn == mtSheep) || + (AnimalToSpawn == mtChicken) || + (AnimalToSpawn == mtPig) + ) + ) + { + return false; + } - int AnimalX, AnimalY, AnimalZ; - AnimalX = (double)(a_ChunkDesc.GetChunkX()*cChunkDef::Width + a_RelX + 0.5); - AnimalY = a_RelY; - AnimalZ = (double)(a_ChunkDesc.GetChunkZ()*cChunkDef::Width + a_RelZ + 0.5); + int AnimalX, AnimalY, AnimalZ; + AnimalX = (double)(a_ChunkDesc.GetChunkX()*cChunkDef::Width + a_RelX + 0.5); + AnimalY = a_RelY; + AnimalZ = (double)(a_ChunkDesc.GetChunkZ()*cChunkDef::Width + a_RelZ + 0.5); - cEntityList ChunkEntities = a_ChunkDesc.GetEntities(); - cMonster * NewMob = cMonster::NewMonsterFromType(AnimalToSpawn); - NewMob->SetPosition(AnimalX, AnimalY, AnimalZ); - ChunkEntities.push_back(NewMob); - LOGD("Spawning %s #%i at {%d, %d, %d}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ); + cEntityList ChunkEntities = a_ChunkDesc.GetEntities(); + cMonster * NewMob = cMonster::NewMonsterFromType(AnimalToSpawn); + NewMob->SetPosition(AnimalX, AnimalY, AnimalZ); + ChunkEntities.push_back(NewMob); + LOGD("Spawning %s #%i at {%d, %d, %d}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ); - return true; + return true; } @@ -1076,80 +1076,80 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) { - std::set ListOfSpawnables; - std::set::iterator MobIter = ListOfSpawnables.begin(); - int x = m_Random.NextInt(cChunkDef::Width - 1); - int z = m_Random.NextInt(cChunkDef::Width - 1); + std::set ListOfSpawnables; + std::set::iterator MobIter = ListOfSpawnables.begin(); + int x = m_Random.NextInt(cChunkDef::Width - 1); + int z = m_Random.NextInt(cChunkDef::Width - 1); - // Check biomes first to get a list of animals - switch (a_ChunkDesc.GetBiome(x, z)) - { - // No animals - case biNether: - case biEnd: - return mtInvalidType; + // Check biomes first to get a list of animals + switch (a_ChunkDesc.GetBiome(x, z)) + { + // No animals + case biNether: + case biEnd: + return mtInvalidType; - // Squid only - case biOcean: - case biFrozenOcean: - case biFrozenRiver: - case biRiver: - case biDeepOcean: - ListOfSpawnables.insert(MobIter, mtSquid); - break; + // Squid only + case biOcean: + case biFrozenOcean: + case biFrozenRiver: + case biRiver: + case biDeepOcean: + ListOfSpawnables.insert(MobIter, mtSquid); + break; - // Mooshroom only - case biMushroomIsland: - case biMushroomShore: - ListOfSpawnables.insert(MobIter, mtMooshroom); - break; + // Mooshroom only + case biMushroomIsland: + case biMushroomShore: + ListOfSpawnables.insert(MobIter, mtMooshroom); + break; - case biJungle: - case biJungleHills: - case biJungleEdge: - case biJungleM: - case biJungleEdgeM: - ListOfSpawnables.insert(MobIter, mtOcelot); + case biJungle: + case biJungleHills: + case biJungleEdge: + case biJungleM: + case biJungleEdgeM: + ListOfSpawnables.insert(MobIter, mtOcelot); - case biPlains: - case biSunflowerPlains: - case biSavanna: - case biSavannaPlateau: - case biSavannaM: - case biSavannaPlateauM: - ListOfSpawnables.insert(MobIter, mtHorse); - // ListOfSpawnables.insert(mtDonkey); + case biPlains: + case biSunflowerPlains: + case biSavanna: + case biSavannaPlateau: + case biSavannaM: + case biSavannaPlateauM: + ListOfSpawnables.insert(MobIter, mtHorse); + // ListOfSpawnables.insert(mtDonkey); - // Wolves only - case biForest: - case biTaiga: - case biMegaTaiga: - case biColdTaiga: - case biColdTaigaM: - ListOfSpawnables.insert(MobIter, mtWolf); + // Wolves only + case biForest: + case biTaiga: + case biMegaTaiga: + case biColdTaiga: + case biColdTaigaM: + ListOfSpawnables.insert(MobIter, mtWolf); - // All other mobs - default: - ListOfSpawnables.insert(MobIter, mtChicken); - ListOfSpawnables.insert(MobIter, mtCow); - ListOfSpawnables.insert(MobIter, mtPig); - ListOfSpawnables.insert(MobIter, mtSheep); - } + // All other mobs + default: + ListOfSpawnables.insert(MobIter, mtChicken); + ListOfSpawnables.insert(MobIter, mtCow); + ListOfSpawnables.insert(MobIter, mtPig); + ListOfSpawnables.insert(MobIter, mtSheep); + } - if (ListOfSpawnables.size() == 0) - { - LOGD("Tried to spawn an animal from an empty list."); - return mtInvalidType; - } + if (ListOfSpawnables.size() == 0) + { + LOGD("Tried to spawn an animal from an empty list."); + return mtInvalidType; + } - int RandMob = m_Random.NextInt(ListOfSpawnables.size()); - MobIter=ListOfSpawnables.begin(); - for (int i = 0; i < RandMob; i++) - { - ++MobIter; - } + int RandMob = m_Random.NextInt(ListOfSpawnables.size()); + MobIter=ListOfSpawnables.begin(); + for (int i = 0; i < RandMob; i++) + { + ++MobIter; + } - return *MobIter; + return *MobIter; } diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index 38bb93d2a..c8575f4d1 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -123,7 +123,7 @@ class cFinishGenSoulsandRims : public cFinishGen { public: - cFinishGenSoulsandRims(int a_Seed) : + cFinishGenSoulsandRims(int a_Seed) : m_Noise(a_Seed) { } @@ -319,26 +319,26 @@ protected: class cFinishGenPassiveMobs : - public cFinishGen + public cFinishGen { public: - cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension); + cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension); protected: - cNoise m_Noise; - int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk - cFastRandom m_Random; + cNoise m_Noise; + int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk + cFastRandom m_Random; - // cFinishGen override: - virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; + // cFinishGen override: + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; - // Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more. - bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn); + // Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more. + bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn); - // Gets a random mob from biome-dependant list - eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc); + // Gets a random mob from biome-dependant list + eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc); } ; From 978c9967adb4dbafdb6ade3f05345d473fcef2e5 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 02:03:29 -0800 Subject: [PATCH 06/32] fix comments after replacing spaces with tabs --- src/Generating/FinishGen.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 296e92139..2b0194a27 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -962,7 +962,7 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e break; } case dimNether: - case dimEnd:// No nether or end animals (currently) + case dimEnd: // No nether or end animals (currently) { DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS; break; @@ -972,7 +972,7 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e ASSERT(!"Unhandled world dimension"); break; } - }// switch (dimension) + } // switch (dimension) m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); if (m_AnimalProbability < 0 || m_AnimalProbability > 100) { @@ -1015,8 +1015,8 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) return; - }// if pack center spawn successful - }// for tries + } // if pack center spawn successful + } // for tries } From 585662e63f33470a6c241340f0b527102fcf406a Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 11:21:51 -0800 Subject: [PATCH 07/32] indentation, repeatable random, small corrections --- src/Generating/FinishGen.cpp | 179 +++++++++++++++++------------------ 1 file changed, 87 insertions(+), 92 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 2b0194a27..3e5b24017 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -956,27 +956,27 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e int DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; switch (a_Dimension) { - case dimOverworld: - { - DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; - break; - } - case dimNether: - case dimEnd: // No nether or end animals (currently) - { - DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS; - break; - } - default: - { - ASSERT(!"Unhandled world dimension"); - break; - } + case dimOverworld: + { + DefaultAnimalSpawnChunkPercentage = DEF_ANIMAL_SPAWN_PERCENT; + break; + } + case dimNether: + case dimEnd: // No nether or end animals (currently) + { + DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS; + break; + } + default: + { + ASSERT(!"Unhandled world dimension"); + break; + } } // switch (dimension) m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); if (m_AnimalProbability < 0 || m_AnimalProbability > 100) { - LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); + LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); } } @@ -986,33 +986,32 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) { - int ChanceRnd = m_Random.NextInt(100); + int ChanceRnd = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % 100; if (ChanceRnd > m_AnimalProbability) { - return; + return; } eMonsterType RandomMob = GetRandomMob(a_ChunkDesc); if (RandomMob == mtInvalidType) { - LOGWARNING("Attempted to spawn invalid mob type."); - return; + LOGWARNING("Attempted to spawn invalid mob type."); + return; } // Try spawning a pack center 10 times, should get roughly the same probability for (int Tries = 0; Tries < 10; Tries++) { - int PackCenterX = m_Random.NextInt(cChunkDef::Width - 1); - int PackCenterZ = m_Random.NextInt(cChunkDef::Width - 1); + int PackCenterX = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; + int PackCenterZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob)) { for (int i = 0; i < 5; i++) { - int OffsetX = m_Random.NextInt(cChunkDef::Width - 1); - int OffsetZ = m_Random.NextInt(cChunkDef::Width - 1); + int OffsetX = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; + int OffsetZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; TrySpawnAnimals(a_ChunkDesc, OffsetX, a_ChunkDesc.GetHeight(OffsetX, OffsetZ), OffsetZ, RandomMob); } - return; } // if pack center spawn successful @@ -1032,27 +1031,24 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX // Check block below (opaque, grass, water), and above (air) if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER) { - return false; + return false; } - if ( - (AnimalToSpawn != mtSquid) && - (BlockAtHead != E_BLOCK_AIR) && - (BlockAtFeet != E_BLOCK_AIR) && - (!cBlockInfo::IsTransparent(BlockUnderFeet)) + if ((AnimalToSpawn != mtSquid) && + (BlockAtHead != E_BLOCK_AIR) && + (BlockAtFeet != E_BLOCK_AIR) && + (!cBlockInfo::IsTransparent(BlockUnderFeet)) ) { - return false; + return false; } - if ( - (BlockUnderFeet != E_BLOCK_GRASS) && - ( - (AnimalToSpawn == mtSheep) || - (AnimalToSpawn == mtChicken) || - (AnimalToSpawn == mtPig) - ) - ) + if ((BlockUnderFeet != E_BLOCK_GRASS) && + ((AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig))) { - return false; + return false; + } + if (AnimalToSpawn == mtMooshroom && BlockUnderFeet != E_BLOCK_MYCELIUM) + { + return false; } int AnimalX, AnimalY, AnimalZ; @@ -1078,75 +1074,74 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) std::set ListOfSpawnables; std::set::iterator MobIter = ListOfSpawnables.begin(); - int x = m_Random.NextInt(cChunkDef::Width - 1); - int z = m_Random.NextInt(cChunkDef::Width - 1); + int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; + int z = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; // Check biomes first to get a list of animals switch (a_ChunkDesc.GetBiome(x, z)) { - // No animals - case biNether: - case biEnd: - return mtInvalidType; + // No animals + case biNether: + case biEnd: + return mtInvalidType; - // Squid only - case biOcean: - case biFrozenOcean: - case biFrozenRiver: - case biRiver: - case biDeepOcean: - ListOfSpawnables.insert(MobIter, mtSquid); - break; + // Squid only + case biOcean: + case biFrozenOcean: + case biFrozenRiver: + case biRiver: + case biDeepOcean: + ListOfSpawnables.insert(MobIter, mtSquid); + break; - // Mooshroom only - case biMushroomIsland: - case biMushroomShore: - ListOfSpawnables.insert(MobIter, mtMooshroom); - break; + // Mooshroom only + case biMushroomIsland: + case biMushroomShore: + ListOfSpawnables.insert(MobIter, mtMooshroom); + break; - case biJungle: - case biJungleHills: - case biJungleEdge: - case biJungleM: - case biJungleEdgeM: - ListOfSpawnables.insert(MobIter, mtOcelot); + case biJungle: + case biJungleHills: + case biJungleEdge: + case biJungleM: + case biJungleEdgeM: + ListOfSpawnables.insert(MobIter, mtOcelot); - case biPlains: - case biSunflowerPlains: - case biSavanna: - case biSavannaPlateau: - case biSavannaM: - case biSavannaPlateauM: - ListOfSpawnables.insert(MobIter, mtHorse); - // ListOfSpawnables.insert(mtDonkey); + case biPlains: + case biSunflowerPlains: + case biSavanna: + case biSavannaPlateau: + case biSavannaM: + case biSavannaPlateauM: + ListOfSpawnables.insert(MobIter, mtHorse); + // ListOfSpawnables.insert(mtDonkey); - // Wolves only - case biForest: - case biTaiga: - case biMegaTaiga: - case biColdTaiga: - case biColdTaigaM: - ListOfSpawnables.insert(MobIter, mtWolf); + // Wolves only + case biForest: + case biTaiga: + case biMegaTaiga: + case biColdTaiga: + case biColdTaigaM: + ListOfSpawnables.insert(MobIter, mtWolf); - // All other mobs - default: - ListOfSpawnables.insert(MobIter, mtChicken); - ListOfSpawnables.insert(MobIter, mtCow); - ListOfSpawnables.insert(MobIter, mtPig); - ListOfSpawnables.insert(MobIter, mtSheep); + // All other mobs + default: + ListOfSpawnables.insert(MobIter, mtChicken); + ListOfSpawnables.insert(MobIter, mtCow); + ListOfSpawnables.insert(MobIter, mtPig); + ListOfSpawnables.insert(MobIter, mtSheep); } - if (ListOfSpawnables.size() == 0) + if (ListOfSpawnables.empty()) { - LOGD("Tried to spawn an animal from an empty list."); - return mtInvalidType; + return mtInvalidType; } int RandMob = m_Random.NextInt(ListOfSpawnables.size()); MobIter=ListOfSpawnables.begin(); for (int i = 0; i < RandMob; i++) { - ++MobIter; + ++MobIter; } return *MobIter; From 8d7c2d4b13c0a0903cc43d612dddcb10c12d7e21 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 11:26:37 -0800 Subject: [PATCH 08/32] fastRandom unused --- src/Generating/FinishGen.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index c8575f4d1..c4d2a0799 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -329,7 +329,6 @@ protected: cNoise m_Noise; int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk - cFastRandom m_Random; // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; From 6803df129f6e197e4f45294d46002f6dd8469655 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 11:32:53 -0800 Subject: [PATCH 09/32] typos and oversights for lua and CI --- src/Generating/FinishGen.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 3e5b24017..0844b01ab 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -986,6 +986,8 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) { + int chunkX = a_ChunkDesc.GetChunkX(); + int chunkZ = a_ChunkDesc.GetChunkZ(); int ChanceRnd = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % 100; if (ChanceRnd > m_AnimalProbability) { @@ -1074,6 +1076,8 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) std::set ListOfSpawnables; std::set::iterator MobIter = ListOfSpawnables.begin(); + int chunkX = a_ChunkDesc.GetChunkX(); + int chunkZ = a_ChunkDesc.GetChunkZ(); int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; int z = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; @@ -1137,7 +1141,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) return mtInvalidType; } - int RandMob = m_Random.NextInt(ListOfSpawnables.size()); + int RandMob = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % ListOfSpawnables.size(); MobIter=ListOfSpawnables.begin(); for (int i = 0; i < RandMob; i++) { From 2ea8a36df6bf0fd4d4eef21521ef0f07a87e895a Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 15:55:09 -0800 Subject: [PATCH 10/32] forgot initializer --- src/Generating/ComposableGenerator.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 6b8923955..bda45ad92 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -294,7 +294,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) for (AStringVector::const_iterator itr = Str.begin(); itr != Str.end(); ++itr) { // Finishers, alpha-sorted: - if (NoCaseCompare(*itr, "BottomLava") == 0) + if (NoCaseCompare(*itr, "Animals") == 0) + { + m_FinishGens.push_back(cFinishGenPtr(new cFinishGenPassiveMobs(Seed, a_IniFile, Dimension))); + } + else if (NoCaseCompare(*itr, "BottomLava") == 0) { int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10; int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel); From 7f8f2f1e704d77aed7a3406b88c3a93d61ae45a6 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 15:57:41 -0800 Subject: [PATCH 11/32] forgot generation defaul init --- src/World.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/World.cpp b/src/World.cpp index 00c8caf13..309be66b7 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -747,7 +747,7 @@ void cWorld::InitialiseGeneratorDefaults(cIniFile & a_IniFile) a_IniFile.GetValueSet("Generator", "BiomeGen", "Grown"); a_IniFile.GetValueSet("Generator", "ShapeGen", "BiomalNoise3D"); a_IniFile.GetValueSet("Generator", "CompositionGen", "Biomal"); - a_IniFile.GetValueSet("Generator", "Finishers", "Ravines, WormNestCaves, WaterLakes, WaterSprings, LavaLakes, LavaSprings, OreNests, Mineshafts, Trees, Villages, SprinkleFoliage, Ice, Snow, Lilypads, BottomLava, DeadBushes, PreSimulator"); + a_IniFile.GetValueSet("Generator", "Finishers", "Ravines, WormNestCaves, WaterLakes, WaterSprings, LavaLakes, LavaSprings, OreNests, Mineshafts, Trees, Villages, SprinkleFoliage, Ice, Snow, Lilypads, BottomLava, DeadBushes, PreSimulator, Animals"); break; } case dimNether: From d3484334064d950654bdf12ec0a81e1b860f627c Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Tue, 2 Dec 2014 22:35:34 -0800 Subject: [PATCH 12/32] doxy-commenting --- src/Generating/FinishGen.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index c4d2a0799..15dd70e15 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -310,7 +310,7 @@ protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; - /// Tries to place a spring at the specified coords, checks neighbors. Returns true if successful + // Tries to place a spring at the specified coords, checks neighbors. Returns true if successful bool TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int y, int z); } ; @@ -333,10 +333,10 @@ protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; - // Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more. + /** Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more. */ bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn); - // Gets a random mob from biome-dependant list + /** Gets a random mob from biome-dependant list */ eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc); } ; From 8c3b9ae15b8c590610fb05f32bd19d2d480f3fd6 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Wed, 3 Dec 2014 00:12:32 -0800 Subject: [PATCH 13/32] class description and doxy-commenting --- src/Generating/FinishGen.cpp | 6 +++--- src/Generating/FinishGen.h | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 0844b01ab..d938c34bd 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1001,7 +1001,7 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) return; } - // Try spawning a pack center 10 times, should get roughly the same probability + /** Try spawning a pack center 10 times, should get roughly the same probability */ for (int Tries = 0; Tries < 10; Tries++) { int PackCenterX = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; @@ -1030,7 +1030,7 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ); BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ); - // Check block below (opaque, grass, water), and above (air) + /** Check block below (opaque, grass, water), and above (air) */ if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER) { return false; @@ -1081,7 +1081,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; int z = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; - // Check biomes first to get a list of animals + /** Check biomes first to get a list of animals */ switch (a_ChunkDesc.GetBiome(x, z)) { // No animals diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index 15dd70e15..e11e6f414 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -318,6 +318,9 @@ protected: +/** This class populates generated chunks with packs of biome-dependant animals +Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots +*/ class cFinishGenPassiveMobs : public cFinishGen { @@ -328,9 +331,9 @@ public: protected: cNoise m_Noise; - int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk + int m_AnimalProbability; /** Chance, [0..100], that an animal pack will be generated in a chunk */ - // cFinishGen override: + /** cFinishGen override: */ virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; /** Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more. */ From 010546051e60856cfaeebbf60e1fc641d467c566 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 3 Dec 2014 16:14:26 +0100 Subject: [PATCH 14/32] Fixes socket leak in HTTP server. Fixes #1643. --- src/OSSupport/SocketThreads.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp index 7a3ef4274..153d6ed1d 100644 --- a/src/OSSupport/SocketThreads.cpp +++ b/src/OSSupport/SocketThreads.cpp @@ -86,7 +86,8 @@ void cSocketThreads::RemoveClient(const cCallback * a_Client) } } // for itr - m_Threads[] - ASSERT(!"Removing an unknown client"); + // This client wasn't found. + // It's not an error, because it may have been removed by a different thread in the meantime. } @@ -491,10 +492,17 @@ void cSocketThreads::cSocketThread::ReadFromSockets(fd_set * a_Read) { case sSlot::ssNormal: { - // Notify the callback that the remote has closed the socket; keep the slot - m_Slots[i].m_Client->SocketClosed(); + // Close the socket on our side: m_Slots[i].m_State = sSlot::ssRemoteClosed; m_Slots[i].m_Socket.CloseSocket(); + + // Notify the callback that the remote has closed the socket, *after* removing the socket: + cCallback * client = m_Slots[i].m_Client; + m_Slots[i] = m_Slots[--m_NumSlots]; + if (client != nullptr) + { + client->SocketClosed(); + } break; } case sSlot::ssWritingRestOut: From 34807248e269c9fae99ac63b3185f134c4c4fa56 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 4 Dec 2014 09:21:57 +0100 Subject: [PATCH 15/32] Fixed the CRAFTING_NO_RECIPE hook call. It used a pointer-to-pointer-to-cCraftingRecipe, which the Lua bindings didn't know how to handle, and emitted a warning message at runtime. Fixes #1641. --- src/Bindings/Plugin.h | 2 +- src/Bindings/PluginLua.cpp | 2 +- src/Bindings/PluginLua.h | 2 +- src/Bindings/PluginManager.cpp | 2 +- src/Bindings/PluginManager.h | 2 +- src/CraftingRecipes.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 8cc9ff0cd..08677553c 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -54,7 +54,7 @@ public: virtual bool OnChunkUnloaded (cWorld & a_World, int a_ChunkX, int a_ChunkZ) = 0; virtual bool OnChunkUnloading (cWorld & a_World, int a_ChunkX, int a_ChunkZ) = 0; virtual bool OnCollectingPickup (cPlayer & a_Player, cPickup & a_Pickup) = 0; - virtual bool OnCraftingNoRecipe (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe * a_Recipe) = 0; + virtual bool OnCraftingNoRecipe (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe) = 0; virtual bool OnDisconnect (cClientHandle & a_Client, const AString & a_Reason) = 0; virtual bool OnEntityAddEffect (cEntity & a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier) = 0; virtual bool OnExecuteCommand (cPlayer * a_Player, const AStringVector & a_Split) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 391d8bcbe..ea782ea3f 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -382,7 +382,7 @@ bool cPluginLua::OnCollectingPickup(cPlayer & a_Player, cPickup & a_Pickup) -bool cPluginLua::OnCraftingNoRecipe(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe * a_Recipe) +bool cPluginLua::OnCraftingNoRecipe(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe) { cCSLock Lock(m_CriticalSection); bool res = false; diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index 6bb134efc..7de5ffec4 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -78,7 +78,7 @@ public: virtual bool OnChunkUnloaded (cWorld & a_World, int a_ChunkX, int a_ChunkZ) override; virtual bool OnChunkUnloading (cWorld & a_World, int a_ChunkX, int a_ChunkZ) override; virtual bool OnCollectingPickup (cPlayer & a_Player, cPickup & a_Pickup) override; - virtual bool OnCraftingNoRecipe (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe * a_Recipe) override; + virtual bool OnCraftingNoRecipe (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe) override; virtual bool OnDisconnect (cClientHandle & a_Client, const AString & a_Reason) override; virtual bool OnEntityAddEffect (cEntity & a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier) override; virtual bool OnExecuteCommand (cPlayer * a_Player, const AStringVector & a_Split) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index f63578885..f951f6221 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -448,7 +448,7 @@ bool cPluginManager::CallHookCollectingPickup(cPlayer & a_Player, cPickup & a_Pi -bool cPluginManager::CallHookCraftingNoRecipe(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe * a_Recipe) +bool cPluginManager::CallHookCraftingNoRecipe(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe) { FIND_HOOK(HOOK_CRAFTING_NO_RECIPE); VERIFY_HOOK; diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index bc8c1f5e6..3a2aecc92 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -187,7 +187,7 @@ public: bool CallHookChunkUnloaded (cWorld & a_World, int a_ChunkX, int a_ChunkZ); bool CallHookChunkUnloading (cWorld & a_World, int a_ChunkX, int a_ChunkZ); bool CallHookCollectingPickup (cPlayer & a_Player, cPickup & a_Pickup); - bool CallHookCraftingNoRecipe (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe * a_Recipe); + bool CallHookCraftingNoRecipe (cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe); bool CallHookDisconnect (cClientHandle & a_Client, const AString & a_Reason); bool CallHookEntityAddEffect (cEntity & a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier); bool CallHookExecuteCommand (cPlayer * a_Player, const AStringVector & a_Split); // If a_Player == nullptr, it is a console cmd diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 2c2b02a69..202fb900e 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -294,7 +294,7 @@ void cCraftingRecipes::GetRecipe(cPlayer & a_Player, cCraftingGrid & a_CraftingG if (Recipe.get() == nullptr) { // Allow plugins to intercept a no-recipe-found situation: - cRoot::Get()->GetPluginManager()->CallHookCraftingNoRecipe(a_Player, a_CraftingGrid, &a_Recipe); + cRoot::Get()->GetPluginManager()->CallHookCraftingNoRecipe(a_Player, a_CraftingGrid, a_Recipe); return; } for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr) From 83d4bec369643c82c3f13e2e1c6d13009a2a0bd9 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Thu, 4 Dec 2014 01:08:17 -0800 Subject: [PATCH 16/32] awful comment fixing, randomizer fix --- src/Generating/FinishGen.cpp | 35 ++++++++++++++++++++++++----------- src/Generating/FinishGen.h | 16 ++++++++-------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index d938c34bd..e9cdfe91e 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -974,7 +974,7 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e } } // switch (dimension) m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); - if (m_AnimalProbability < 0 || m_AnimalProbability > 100) + if ((m_AnimalProbability < 0) || (m_AnimalProbability > 100)) { LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); } @@ -1001,7 +1001,7 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) return; } - /** Try spawning a pack center 10 times, should get roughly the same probability */ + // Try spawning a pack center 10 times, should get roughly the same probability for (int Tries = 0; Tries < 10; Tries++) { int PackCenterX = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; @@ -1010,8 +1010,8 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) { for (int i = 0; i < 5; i++) { - int OffsetX = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; - int OffsetZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; + int OffsetX = (m_Noise.IntNoise2DInt(chunkX + chunkZ, Tries) / 7) % cChunkDef::Width; + int OffsetZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ + Tries) / 7) % cChunkDef::Width; TrySpawnAnimals(a_ChunkDesc, OffsetX, a_ChunkDesc.GetHeight(OffsetX, OffsetZ), OffsetZ, RandomMob); } return; @@ -1026,11 +1026,16 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, eMonsterType AnimalToSpawn) { + if ((a_RelY >= cChunkDef::Height - 1) || (a_RelY <= 0)) + { + return false; + } + BLOCKTYPE BlockAtHead = a_ChunkDesc.GetBlockType(a_RelX, a_RelY + 1, a_RelZ); BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ); BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ); - /** Check block below (opaque, grass, water), and above (air) */ + // Check block below (opaque, grass, water), and above (air) if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER) { return false; @@ -1087,53 +1092,61 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) // No animals case biNether: case biEnd: + { return mtInvalidType; - + } // Squid only case biOcean: case biFrozenOcean: case biFrozenRiver: case biRiver: case biDeepOcean: + { ListOfSpawnables.insert(MobIter, mtSquid); break; - + } // Mooshroom only case biMushroomIsland: case biMushroomShore: + { ListOfSpawnables.insert(MobIter, mtMooshroom); break; - + } case biJungle: case biJungleHills: case biJungleEdge: case biJungleM: case biJungleEdgeM: + { ListOfSpawnables.insert(MobIter, mtOcelot); - + } case biPlains: case biSunflowerPlains: case biSavanna: case biSavannaPlateau: case biSavannaM: case biSavannaPlateauM: + { ListOfSpawnables.insert(MobIter, mtHorse); // ListOfSpawnables.insert(mtDonkey); - + } // Wolves only case biForest: case biTaiga: case biMegaTaiga: case biColdTaiga: case biColdTaigaM: + { ListOfSpawnables.insert(MobIter, mtWolf); - + } // All other mobs default: + { ListOfSpawnables.insert(MobIter, mtChicken); ListOfSpawnables.insert(MobIter, mtCow); ListOfSpawnables.insert(MobIter, mtPig); ListOfSpawnables.insert(MobIter, mtSheep); + } } if (ListOfSpawnables.empty()) diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index e11e6f414..1866d6133 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -318,28 +318,28 @@ protected: -/** This class populates generated chunks with packs of biome-dependant animals -Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots -*/ class cFinishGenPassiveMobs : public cFinishGen { public: - + + /** This class populates generated chunks with packs of biome-dependant animals + Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots + */ cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension); protected: cNoise m_Noise; - int m_AnimalProbability; /** Chance, [0..100], that an animal pack will be generated in a chunk */ + int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk - /** cFinishGen override: */ + // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; - /** Tries to spawn a mob in the center of the pack. If successful, spawns 0-5 more. */ + // Returns false if an animal cannot spawn at given coords, else adds it to the chunk's entity list and returns true bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn); - /** Gets a random mob from biome-dependant list */ + // Gets a random animal from biome-dependant list eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc); } ; From a36e7669a798d9756d7c13780aa017f60bc4ead5 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Thu, 4 Dec 2014 01:14:38 -0800 Subject: [PATCH 17/32] added p-mcgowan to contributors --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index fffc55b2a..9a0a675e7 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -18,6 +18,7 @@ mgueydan MikeHunsinger mtilden nesco +p-mcgowan rs2k SamJBarney Sofapriester From b7c4ef05ac320428cfa2fdeed562302f78d1a7ab Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Thu, 4 Dec 2014 01:18:55 -0800 Subject: [PATCH 18/32] last doxy fix --- src/Generating/FinishGen.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index 1866d6133..f2b59fa08 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -318,14 +318,14 @@ protected: +/** This class populates generated chunks with packs of biome-dependant animals + Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots + */ class cFinishGenPassiveMobs : public cFinishGen { public: - /** This class populates generated chunks with packs of biome-dependant animals - Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots - */ cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension); protected: From 99a5b38e27647e4535eed53b7b6d9cc6ea74c538 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Thu, 4 Dec 2014 13:28:27 -0800 Subject: [PATCH 19/32] format blocks and randomizing --- src/Generating/FinishGen.cpp | 17 +++++++++-------- src/Generating/FinishGen.h | 1 - 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index e9cdfe91e..e72e91c85 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1004,14 +1004,14 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) // Try spawning a pack center 10 times, should get roughly the same probability for (int Tries = 0; Tries < 10; Tries++) { - int PackCenterX = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; - int PackCenterZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; + int PackCenterX = (m_Noise.IntNoise2DInt(chunkX + chunkZ, Tries) / 7) % cChunkDef::Width; + int PackCenterZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ + Tries) / 7) % cChunkDef::Width; if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob)) { for (int i = 0; i < 5; i++) { - int OffsetX = (m_Noise.IntNoise2DInt(chunkX + chunkZ, Tries) / 7) % cChunkDef::Width; - int OffsetZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ + Tries) / 7) % cChunkDef::Width; + int OffsetX = (m_Noise.IntNoise2DInt(chunkX + chunkZ + i, Tries) / 7) % cChunkDef::Width; + int OffsetZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ + Tries + i) / 7) % cChunkDef::Width; TrySpawnAnimals(a_ChunkDesc, OffsetX, a_ChunkDesc.GetHeight(OffsetX, OffsetZ), OffsetZ, RandomMob); } return; @@ -1040,7 +1040,8 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX { return false; } - if ((AnimalToSpawn != mtSquid) && + if ( + (AnimalToSpawn != mtSquid) && (BlockAtHead != E_BLOCK_AIR) && (BlockAtFeet != E_BLOCK_AIR) && (!cBlockInfo::IsTransparent(BlockUnderFeet)) @@ -1083,8 +1084,8 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) std::set::iterator MobIter = ListOfSpawnables.begin(); int chunkX = a_ChunkDesc.GetChunkX(); int chunkZ = a_ChunkDesc.GetChunkZ(); - int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; - int z = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % cChunkDef::Width; + int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ + 10) / 7) % cChunkDef::Width; + int z = (m_Noise.IntNoise2DInt(chunkX + chunkZ, chunkZ) / 7) % cChunkDef::Width; /** Check biomes first to get a list of animals */ switch (a_ChunkDesc.GetBiome(x, z)) @@ -1154,7 +1155,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) return mtInvalidType; } - int RandMob = (m_Noise.IntNoise2DInt(chunkX, chunkZ) / 7) % ListOfSpawnables.size(); + int RandMob = (m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size(); MobIter=ListOfSpawnables.begin(); for (int i = 0; i < RandMob; i++) { diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index f2b59fa08..600a506bc 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -19,7 +19,6 @@ #include "../Noise/Noise.h" #include "../ProbabDistrib.h" #include "../Mobs/Monster.h" -#include "FastRandom.h" From 53a33595b7c53d3728cc38627a3d0601fce735aa Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Thu, 4 Dec 2014 16:44:18 -0800 Subject: [PATCH 20/32] formatting fixes --- src/Generating/FinishGen.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index e72e91c85..e50942073 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1049,12 +1049,14 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX { return false; } - if ((BlockUnderFeet != E_BLOCK_GRASS) && - ((AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig))) + if ( + (BlockUnderFeet != E_BLOCK_GRASS) && + ((AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig)) + ) { return false; } - if (AnimalToSpawn == mtMooshroom && BlockUnderFeet != E_BLOCK_MYCELIUM) + if ((AnimalToSpawn == mtMooshroom) && (BlockUnderFeet != E_BLOCK_MYCELIUM)) { return false; } @@ -1150,13 +1152,18 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) } } + ListOfSpawnables.insert(MobIter, mtChicken); + ListOfSpawnables.insert(MobIter, mtCow); + ListOfSpawnables.insert(MobIter, mtPig); + ListOfSpawnables.insert(MobIter, mtSheep); + if (ListOfSpawnables.empty()) { return mtInvalidType; } int RandMob = (m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size(); - MobIter=ListOfSpawnables.begin(); + MobIter = ListOfSpawnables.begin(); for (int i = 0; i < RandMob; i++) { ++MobIter; From 538991c973fc6839b16b48b40a22084fe1218f74 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Thu, 4 Dec 2014 16:59:45 -0800 Subject: [PATCH 21/32] handle non-vanilla dimensions --- src/Generating/FinishGen.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index e50942073..c83dfec67 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -835,6 +835,7 @@ cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cI default: { ASSERT(!"Unhandled world dimension"); + DefaultChance = 0; break; } } // switch (dimension) @@ -970,7 +971,7 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e default: { ASSERT(!"Unhandled world dimension"); - break; + return; } } // switch (dimension) m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); @@ -1156,7 +1157,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) ListOfSpawnables.insert(MobIter, mtCow); ListOfSpawnables.insert(MobIter, mtPig); ListOfSpawnables.insert(MobIter, mtSheep); - + if (ListOfSpawnables.empty()) { return mtInvalidType; From 78f0aebaf4bdef13d2cc61880111365297723517 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Thu, 4 Dec 2014 17:01:34 -0800 Subject: [PATCH 22/32] handle non-vanilla dimensions --- src/Generating/FinishGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index c83dfec67..a34f61fcf 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -835,7 +835,6 @@ cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cI default: { ASSERT(!"Unhandled world dimension"); - DefaultChance = 0; break; } } // switch (dimension) @@ -971,7 +970,8 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e default: { ASSERT(!"Unhandled world dimension"); - return; + DefaultChance = 0; + break; } } // switch (dimension) m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); From bd8c1850da9c80ae59334fd96da51c624893aac4 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Thu, 4 Dec 2014 17:20:19 -0800 Subject: [PATCH 23/32] restructured random animals, added check for desert (update as per wiki) --- src/Generating/FinishGen.cpp | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index a34f61fcf..97ee5a9f9 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -970,7 +970,7 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e default: { ASSERT(!"Unhandled world dimension"); - DefaultChance = 0; + DefaultAnimalSpawnChunkPercentage = DEF_NO_ANIMALS; break; } } // switch (dimension) @@ -1009,7 +1009,7 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) int PackCenterZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ + Tries) / 7) % cChunkDef::Width; if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob)) { - for (int i = 0; i < 5; i++) + for (int i = 0; i < 3; i++) { int OffsetX = (m_Noise.IntNoise2DInt(chunkX + chunkZ + i, Tries) / 7) % cChunkDef::Width; int OffsetZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ + Tries + i) / 7) % cChunkDef::Width; @@ -1093,13 +1093,23 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) /** Check biomes first to get a list of animals */ switch (a_ChunkDesc.GetBiome(x, z)) { - // No animals + // No animals in deserts or non-overworld dimensions case biNether: case biEnd: + case biDesertHills: + case biDesert: + case biDesertM: { return mtInvalidType; } - // Squid only + // Mooshroom only - no other mobs on mushroom islands + case biMushroomIsland: + case biMushroomShore: + { + ListOfSpawnables.insert(MobIter, mtMooshroom); + break; + } + // Add squid in ocean biomes case biOcean: case biFrozenOcean: case biFrozenRiver: @@ -1107,15 +1117,8 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biDeepOcean: { ListOfSpawnables.insert(MobIter, mtSquid); - break; - } - // Mooshroom only - case biMushroomIsland: - case biMushroomShore: - { - ListOfSpawnables.insert(MobIter, mtMooshroom); - break; } + // Add ocelots in jungle biomes case biJungle: case biJungleHills: case biJungleEdge: @@ -1134,7 +1137,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) ListOfSpawnables.insert(MobIter, mtHorse); // ListOfSpawnables.insert(mtDonkey); } - // Wolves only + // Add wolves in forest and spruce forests case biForest: case biTaiga: case biMegaTaiga: @@ -1143,7 +1146,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) { ListOfSpawnables.insert(MobIter, mtWolf); } - // All other mobs + // All other animals can be added to the list default: { ListOfSpawnables.insert(MobIter, mtChicken); @@ -1153,11 +1156,6 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) } } - ListOfSpawnables.insert(MobIter, mtChicken); - ListOfSpawnables.insert(MobIter, mtCow); - ListOfSpawnables.insert(MobIter, mtPig); - ListOfSpawnables.insert(MobIter, mtSheep); - if (ListOfSpawnables.empty()) { return mtInvalidType; From a1c6e89273ce9a46b49421c739e2205d957cfb17 Mon Sep 17 00:00:00 2001 From: Jonathan Fabian Date: Thu, 4 Dec 2014 23:25:46 -0500 Subject: [PATCH 24/32] Fix duplicate commands added to README.md --- MCServer/Plugins/InfoDump.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index de1d1f451..07a534b88 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -444,7 +444,18 @@ local function BuildPermissions(a_PluginInfo) Permissions[info.Permission] = Permission -- Add the command to the list of commands using this permission: Permission.CommandsAffected = Permission.CommandsAffected or {} - table.insert(Permission.CommandsAffected, CommandString) + -- First, make sure that we don't already have this command in the list, + -- it may have already been present in a_PluginInfo + local NewCommand = true + for _, existCmd in ipairs(Permission.CommandsAffected) do + if CommandString == existCmd then + NewCommand = false + break + end + end + if NewCommand then + table.insert(Permission.CommandsAffected, CommandString) + end end -- Process the command param combinations for permissions: From c655d97c9db9408dc178f436baa87d894363ecb3 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Fri, 5 Dec 2014 00:57:40 -0800 Subject: [PATCH 25/32] restructure, with logic this time --- src/Generating/FinishGen.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 97ee5a9f9..6788afca3 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1117,6 +1117,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biDeepOcean: { ListOfSpawnables.insert(MobIter, mtSquid); + break; } // Add ocelots in jungle biomes case biJungle: @@ -1126,6 +1127,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biJungleEdgeM: { ListOfSpawnables.insert(MobIter, mtOcelot); + break; } case biPlains: case biSunflowerPlains: @@ -1136,6 +1138,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) { ListOfSpawnables.insert(MobIter, mtHorse); // ListOfSpawnables.insert(mtDonkey); + break; } // Add wolves in forest and spruce forests case biForest: @@ -1145,16 +1148,21 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biColdTaigaM: { ListOfSpawnables.insert(MobIter, mtWolf); + break; } - // All other animals can be added to the list + // Nothing special about this biome default: { - ListOfSpawnables.insert(MobIter, mtChicken); - ListOfSpawnables.insert(MobIter, mtCow); - ListOfSpawnables.insert(MobIter, mtPig); - ListOfSpawnables.insert(MobIter, mtSheep); + break; } } + if ((a_ChunkDesc.GetBiome(x, z) != biMushroomIsland) && (a_ChunkDesc.GetBiome(x, z) != biMushroomShore)) + { + ListOfSpawnables.insert(MobIter, mtChicken); + ListOfSpawnables.insert(MobIter, mtCow); + ListOfSpawnables.insert(MobIter, mtPig); + ListOfSpawnables.insert(MobIter, mtSheep); + } if (ListOfSpawnables.empty()) { From 750b4a3eaadab231cd215cbc8557ad67a67742cc Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Fri, 5 Dec 2014 01:01:10 -0800 Subject: [PATCH 26/32] reformat --- src/Generating/FinishGen.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 6788afca3..358ed16a1 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1106,8 +1106,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biMushroomIsland: case biMushroomShore: { - ListOfSpawnables.insert(MobIter, mtMooshroom); - break; + return mtMooshroom; } // Add squid in ocean biomes case biOcean: @@ -1156,13 +1155,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) break; } } - if ((a_ChunkDesc.GetBiome(x, z) != biMushroomIsland) && (a_ChunkDesc.GetBiome(x, z) != biMushroomShore)) - { - ListOfSpawnables.insert(MobIter, mtChicken); - ListOfSpawnables.insert(MobIter, mtCow); - ListOfSpawnables.insert(MobIter, mtPig); - ListOfSpawnables.insert(MobIter, mtSheep); - } + ListOfSpawnables.insert(MobIter, mtChicken); + ListOfSpawnables.insert(MobIter, mtCow); + ListOfSpawnables.insert(MobIter, mtPig); + ListOfSpawnables.insert(MobIter, mtSheep); if (ListOfSpawnables.empty()) { From 44644ae0254bf3659c0995575041e2f656f20398 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Dec 2014 12:56:53 +0100 Subject: [PATCH 27/32] Fixed reported parentheses around comparisons. --- src/Entities/Entity.cpp | 2 +- src/Inventory.cpp | 8 ++- src/MobSpawner.cpp | 8 +-- src/Mobs/Blaze.cpp | 2 +- src/Mobs/Ghast.cpp | 2 +- src/Mobs/Skeleton.cpp | 2 +- src/Mobs/SnowGolem.cpp | 2 +- src/OSSupport/Socket.h | 2 +- src/Simulator/FluidSimulator.cpp | 4 +- src/StringUtils.cpp | 33 +++++----- src/Tracer.cpp | 105 ++++++++++++++++--------------- src/UI/SlotArea.cpp | 2 +- src/World.cpp | 4 +- src/XMLParser.h | 6 +- 14 files changed, 99 insertions(+), 83 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index afc61c73f..3b2fa9b4e 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1276,7 +1276,7 @@ bool cEntity::DetectPortal() return false; } - if (IsPlayer() && !((cPlayer *)this)->IsGameModeCreative() && m_PortalCooldownData.m_TicksDelayed != 80) + if (IsPlayer() && !((cPlayer *)this)->IsGameModeCreative() && (m_PortalCooldownData.m_TicksDelayed != 80)) { // Delay teleportation for four seconds if the entity is a non-creative player m_PortalCooldownData.m_TicksDelayed++; diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 51ac32da9..fba6f4aea 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -507,7 +507,11 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, int MaxStackSize = cItemHandler::GetItemHandler(a_Item.m_ItemType)->GetMaxStackSize(); for (int i = 0; i < a_Size; i++) { - if (m_Slots[i + a_Offset].m_ItemType == a_Item.m_ItemType && m_Slots[i + a_Offset].m_ItemCount < MaxStackSize && m_Slots[i + a_Offset].m_ItemDamage == a_Item.m_ItemDamage) + if ( + (m_Slots[i + a_Offset].m_ItemType == a_Item.m_ItemType) && + (m_Slots[i + a_Offset].m_ItemCount < MaxStackSize) && + (m_Slots[i + a_Offset].m_ItemDamage == a_Item.m_ItemDamage) + ) { int NumFree = MaxStackSize - m_Slots[i + a_Offset].m_ItemCount; if (NumFree >= a_Item.m_ItemCount) @@ -533,7 +537,7 @@ bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, if (a_Mode > 0) { // If we got more left, find first empty slot - for (int i = 0; i < a_Size && a_Item.m_ItemCount > 0; i++) + for (int i = 0; (i < a_Size) && (a_Item.m_ItemCount > 0); i++) { if (m_Slots[i + a_Offset].m_ItemType == -1) { diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index e477e2dac..ee9e569a7 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -61,7 +61,7 @@ eMonsterType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) { std::set allowedMobs; - if (a_Biome == biMushroomIsland || a_Biome == biMushroomShore) + if ((a_Biome == biMushroomIsland) || (a_Biome == biMushroomShore)) { addIfAllowed(mtMooshroom, allowedMobs); } @@ -84,7 +84,7 @@ eMonsterType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) addIfAllowed(mtCreeper, allowedMobs); addIfAllowed(mtSquid, allowedMobs); - if (a_Biome != biDesert && a_Biome != biBeach && a_Biome != biOcean) + if ((a_Biome != biDesert) && (a_Biome != biBeach) && (a_Biome != biOcean)) { addIfAllowed(mtSheep, allowedMobs); addIfAllowed(mtPig, allowedMobs); @@ -93,11 +93,11 @@ eMonsterType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) addIfAllowed(mtEnderman, allowedMobs); addIfAllowed(mtSlime, allowedMobs); // MG TODO : much more complicated rule - if (a_Biome == biForest || a_Biome == biForestHills || a_Biome == biTaiga || a_Biome == biTaigaHills) + if ((a_Biome == biForest) || (a_Biome == biForestHills) || (a_Biome == biTaiga) || (a_Biome == biTaigaHills)) { addIfAllowed(mtWolf, allowedMobs); } - else if (a_Biome == biJungle || a_Biome == biJungleHills) + else if ((a_Biome == biJungle) || (a_Biome == biJungleHills)) { addIfAllowed(mtOcelot, allowedMobs); } diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index 16869c79d..1fa9d2c37 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -34,7 +34,7 @@ void cBlaze::Attack(float a_Dt) { m_AttackInterval += a_Dt * m_AttackRate; - if (m_Target != nullptr && m_AttackInterval > 3.0) + if ((m_Target != nullptr) && (m_AttackInterval > 3.0)) { // Setting this higher gives us more wiggle room for attackrate Vector3d Speed = GetLookVector() * 20; diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index c65c0d29a..fc8de8362 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -36,7 +36,7 @@ void cGhast::Attack(float a_Dt) { m_AttackInterval += a_Dt * m_AttackRate; - if (m_Target != nullptr && m_AttackInterval > 3.0) + if ((m_Target != nullptr) && (m_AttackInterval > 3.0)) { // Setting this higher gives us more wiggle room for attackrate Vector3d Speed = GetLookVector() * 20; diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index f17bc307c..da5ddc670 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -71,7 +71,7 @@ void cSkeleton::Attack(float a_Dt) { m_AttackInterval += a_Dt * m_AttackRate; - if (m_Target != nullptr && m_AttackInterval > 3.0) + if ((m_Target != nullptr) && (m_AttackInterval > 3.0)) { // Setting this higher gives us more wiggle room for attackrate Vector3d Speed = GetLookVector() * 20; diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 76334d970..8c4178beb 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -38,7 +38,7 @@ void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk) { BLOCKTYPE BlockBelow = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()) - 1, (int) floor(GetPosZ())); BLOCKTYPE Block = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ())); - if (Block == E_BLOCK_AIR && cBlockInfo::IsSolid(BlockBelow)) + if ((Block == E_BLOCK_AIR) && cBlockInfo::IsSolid(BlockBelow)) { m_World->SetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()), E_BLOCK_SNOW, 0); } diff --git a/src/OSSupport/Socket.h b/src/OSSupport/Socket.h index e4ec895cb..9ec8c1111 100644 --- a/src/OSSupport/Socket.h +++ b/src/OSSupport/Socket.h @@ -74,7 +74,7 @@ public: inline static bool IsSocketError(int a_ReturnedValue) { #ifdef _WIN32 - return (a_ReturnedValue == SOCKET_ERROR || a_ReturnedValue == 0); + return ((a_ReturnedValue == SOCKET_ERROR) || (a_ReturnedValue == 0)); #else return (a_ReturnedValue <= 0); #endif diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp index 9c8453d04..a7551d9bc 100644 --- a/src/Simulator/FluidSimulator.cpp +++ b/src/Simulator/FluidSimulator.cpp @@ -133,8 +133,10 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a /* Disabled because of causing problems and being useless atm char BlockBelow = m_World.GetBlock(a_X, a_Y - 1, a_Z); // If there is nothing or fluid below it -> dominating flow is down :D - if (BlockBelow == E_BLOCK_AIR || IsAllowedBlock(BlockBelow)) + if ((BlockBelow == E_BLOCK_AIR) || IsAllowedBlock(BlockBelow)) + { return Y_MINUS; + } */ NIBBLETYPE LowestPoint = m_World.GetBlockMeta(a_X, a_Y, a_Z); // Current Block Meta so only lower points will be counted diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 34f2da682..fe145521f 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -416,24 +416,27 @@ static bool isLegalUTF8(const unsigned char * source, int length) { default: return false; // Everything else falls through when "true"... - case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; - case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; + case 4: if (((a = (*--srcptr)) < 0x80) || (a > 0xbf)) return false; + case 3: if (((a = (*--srcptr)) < 0x80) || (a > 0xbf)) return false; case 2: { - if ((a = (*--srcptr)) > 0xBF) return false; + if ((a = (*--srcptr)) > 0xbf) return false; switch (*source) { // no fall-through in this inner switch - case 0xE0: if (a < 0xA0) return false; break; - case 0xED: if (a > 0x9F) return false; break; - case 0xF0: if (a < 0x90) return false; break; - case 0xF4: if (a > 0x8F) return false; break; + case 0xe0: if (a < 0xa0) return false; break; + case 0xed: if (a > 0x9f) return false; break; + case 0xf0: if (a < 0x90) return false; break; + case 0xf4: if (a > 0x8f) return false; break; default: if (a < 0x80) return false; } } - case 1: if (*source >= 0x80 && *source < 0xC2) return false; + case 1: if ((*source >= 0x80) && (*source < 0xc2)) return false; + } + if (*source > 0xf4) + { + return false; } - if (*source > 0xF4) return false; return true; } @@ -446,11 +449,11 @@ AString UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length) AString UTF16; UTF16.reserve(a_UTF8Length * 3); - const unsigned char * source = (const unsigned char*)a_UTF8; + const unsigned char * source = (const unsigned char *)a_UTF8; const unsigned char * sourceEnd = source + a_UTF8Length; const int halfShift = 10; // used for shifting by 10 bits const unsigned int halfBase = 0x0010000UL; - const unsigned int halfMask = 0x3FFUL; + const unsigned int halfMask = 0x3ffUL; while (source < sourceEnd) { @@ -481,7 +484,7 @@ AString UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length) if (ch <= UNI_MAX_BMP) { // Target is a character <= 0xFFFF - if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) + if ((ch >= UNI_SUR_HIGH_START) && (ch <= UNI_SUR_LOW_END)) { // UTF-16 surrogate values are illegal in UTF-32 ch = ' '; @@ -723,15 +726,15 @@ AString ReplaceAllCharOccurrences(const AString & a_String, char a_From, char a_ /// Converts one Hex character in a Base64 encoding into the data value static inline int UnBase64(char c) { - if (c >='A' && c <= 'Z') + if ((c >='A') && (c <= 'Z')) { return c - 'A'; } - if (c >='a' && c <= 'z') + if ((c >='a') && (c <= 'z')) { return c - 'a' + 26; } - if (c >= '0' && c <= '9') + if ((c >= '0') && (c <= '9')) { return c - '0' + 52; } diff --git a/src/Tracer.cpp b/src/Tracer.cpp index e125c6aa4..53884dee8 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -14,15 +14,15 @@ -cTracer::cTracer(cWorld * a_World) - : m_World(a_World) +cTracer::cTracer(cWorld * a_World): + m_World(a_World) { - m_NormalTable[0].Set(-1, 0, 0); - m_NormalTable[1].Set( 0, 0, -1); - m_NormalTable[2].Set( 1, 0, 0); - m_NormalTable[3].Set( 0, 0, 1); - m_NormalTable[4].Set( 0, 1, 0); - m_NormalTable[5].Set( 0, -1, 0); + m_NormalTable[0].Set(-1, 0, 0); + m_NormalTable[1].Set( 0, 0, -1); + m_NormalTable[2].Set( 1, 0, 0); + m_NormalTable[3].Set( 0, 0, 1); + m_NormalTable[4].Set( 0, 1, 0); + m_NormalTable[5].Set( 0, -1, 0); } @@ -37,7 +37,7 @@ cTracer::~cTracer() -float cTracer::SigNum( float a_Num) +float cTracer::SigNum(float a_Num) { if (a_Num < 0.f) return -1.f; if (a_Num > 0.f) return 1.f; @@ -127,7 +127,7 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction) -bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight) +bool cTracer::Trace(const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight) { if ((a_Start.y < 0) || (a_Start.y >= cChunkDef::Height)) { @@ -249,35 +249,42 @@ int LinesCross(float x0, float y0, float x1, float y1, float x2, float y2, float { // float linx, liny; - float d=(x1-x0)*(y3-y2)-(y1-y0)*(x3-x2); - if (std::abs(d)<0.001) {return 0;} - float AB=((y0-y2)*(x3-x2)-(x0-x2)*(y3-y2))/d; - if (AB>=0.0 && AB<=1.0) + float d = (x1 - x0) * (y3 - y2) - (y1 - y0) * (x3 - x2); + if (std::abs(d) < 0.001) { - float CD=((y0-y2)*(x1-x0)-(x0-x2)*(y1-y0))/d; - if (CD>=0.0 && CD<=1.0) + return 0; + } + + float AB = ((y0 - y2) * (x3 - x2) - (x0 - x2) * (y3 - y2)) / d; + if ((AB >= 0.0) && (AB <= 1.0)) + { + float CD = ((y0 - y2) * (x1 - x0) - (x0 - x2) * (y1 - y0)) / d; + if ((CD >= 0.0) && (CD <= 1.0)) { - // linx=x0+AB*(x1-x0); - // liny=y0+AB*(y1-y0); + // linx = x0 + AB * (x1 - x0); + // liny = y0 + AB * (y1 - y0); return 1; } } return 0; } + + + // intersect3D_SegmentPlane(): intersect a segment and a plane // Input: a_Ray = a segment, and a_Plane = a plane = {Point V0; Vector n;} // Output: *I0 = the intersect point (when it exists) // Return: 0 = disjoint (no intersection) // 1 = intersection in the unique point *I0 // 2 = the segment lies in the plane -int cTracer::intersect3D_SegmentPlane( const Vector3f & a_Origin, const Vector3f & a_End, const Vector3f & a_PlanePos, const Vector3f & a_PlaneNormal) +int cTracer::intersect3D_SegmentPlane(const Vector3f & a_Origin, const Vector3f & a_End, const Vector3f & a_PlanePos, const Vector3f & a_PlaneNormal) { Vector3f u = a_End - a_Origin; // a_Ray.P1 - S.P0; Vector3f w = a_Origin - a_PlanePos; // S.P0 - Pn.V0; - float D = a_PlaneNormal.Dot( u); // dot(Pn.n, u); - float N = -(a_PlaneNormal.Dot( w)); // -dot(a_Plane.n, w); + float D = a_PlaneNormal.Dot(u); // dot(Pn.n, u); + float N = -(a_PlaneNormal.Dot(w)); // -dot(a_Plane.n, w); const float EPSILON = 0.0001f; if (fabs(D) < EPSILON) @@ -294,12 +301,12 @@ int cTracer::intersect3D_SegmentPlane( const Vector3f & a_Origin, const Vector3f // they are not parallel // compute intersect param float sI = N / D; - if (sI < 0 || sI > 1) + if ((sI < 0) || (sI > 1)) { return 0; // no intersection } - // Vector3f I ( a_Ray->GetOrigin() + sI * u);// S.P0 + sI * u; // compute segment intersect point + // Vector3f I (a_Ray->GetOrigin() + sI * u);// S.P0 + sI * u; // compute segment intersect point RealHit = a_Origin + u * sI; return 1; } @@ -311,9 +318,9 @@ int cTracer::intersect3D_SegmentPlane( const Vector3f & a_Origin, const Vector3f int cTracer::GetHitNormal(const Vector3f & start, const Vector3f & end, const Vector3i & a_BlockPos) { Vector3i SmallBlockPos = a_BlockPos; - char BlockID = m_World->GetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z); + char BlockID = m_World->GetBlock(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z); - if (BlockID == E_BLOCK_AIR || IsBlockWater(BlockID)) + if ((BlockID == E_BLOCK_AIR) || IsBlockWater(BlockID)) { return 0; } @@ -324,86 +331,86 @@ int cTracer::GetHitNormal(const Vector3f & start, const Vector3f & end, const Ve Vector3f Look = (end - start); Look.Normalize(); - float dot = Look.Dot( Vector3f(-1, 0, 0)); // first face normal is x -1 + float dot = Look.Dot(Vector3f(-1, 0, 0)); // first face normal is x -1 if (dot < 0) { - int Lines = LinesCross( start.x, start.y, end.x, end.y, BlockPos.x, BlockPos.y, BlockPos.x, BlockPos.y + 1); + int Lines = LinesCross(start.x, start.y, end.x, end.y, BlockPos.x, BlockPos.y, BlockPos.x, BlockPos.y + 1); if (Lines == 1) { - Lines = LinesCross( start.x, start.z, end.x, end.z, BlockPos.x, BlockPos.z, BlockPos.x, BlockPos.z + 1); + Lines = LinesCross(start.x, start.z, end.x, end.z, BlockPos.x, BlockPos.z, BlockPos.x, BlockPos.z + 1); if (Lines == 1) { - intersect3D_SegmentPlane( start, end, BlockPos, Vector3f(-1, 0, 0)); + intersect3D_SegmentPlane(start, end, BlockPos, Vector3f(-1, 0, 0)); return 1; } } } - dot = Look.Dot( Vector3f(0, 0, -1)); // second face normal is z -1 + dot = Look.Dot(Vector3f(0, 0, -1)); // second face normal is z -1 if (dot < 0) { - int Lines = LinesCross( start.z, start.y, end.z, end.y, BlockPos.z, BlockPos.y, BlockPos.z, BlockPos.y + 1); + int Lines = LinesCross(start.z, start.y, end.z, end.y, BlockPos.z, BlockPos.y, BlockPos.z, BlockPos.y + 1); if (Lines == 1) { - Lines = LinesCross( start.z, start.x, end.z, end.x, BlockPos.z, BlockPos.x, BlockPos.z, BlockPos.x + 1); + Lines = LinesCross(start.z, start.x, end.z, end.x, BlockPos.z, BlockPos.x, BlockPos.z, BlockPos.x + 1); if (Lines == 1) { - intersect3D_SegmentPlane( start, end, BlockPos, Vector3f(0, 0, -1)); + intersect3D_SegmentPlane(start, end, BlockPos, Vector3f(0, 0, -1)); return 2; } } } - dot = Look.Dot( Vector3f(1, 0, 0)); // third face normal is x 1 + dot = Look.Dot(Vector3f(1, 0, 0)); // third face normal is x 1 if (dot < 0) { - int Lines = LinesCross( start.x, start.y, end.x, end.y, BlockPos.x + 1, BlockPos.y, BlockPos.x + 1, BlockPos.y + 1); + int Lines = LinesCross(start.x, start.y, end.x, end.y, BlockPos.x + 1, BlockPos.y, BlockPos.x + 1, BlockPos.y + 1); if (Lines == 1) { - Lines = LinesCross( start.x, start.z, end.x, end.z, BlockPos.x + 1, BlockPos.z, BlockPos.x + 1, BlockPos.z + 1); + Lines = LinesCross(start.x, start.z, end.x, end.z, BlockPos.x + 1, BlockPos.z, BlockPos.x + 1, BlockPos.z + 1); if (Lines == 1) { - intersect3D_SegmentPlane( start, end, BlockPos + Vector3f(1, 0, 0), Vector3f(1, 0, 0)); + intersect3D_SegmentPlane(start, end, BlockPos + Vector3f(1, 0, 0), Vector3f(1, 0, 0)); return 3; } } } - dot = Look.Dot( Vector3f(0, 0, 1)); // fourth face normal is z 1 + dot = Look.Dot(Vector3f(0, 0, 1)); // fourth face normal is z 1 if (dot < 0) { - int Lines = LinesCross( start.z, start.y, end.z, end.y, BlockPos.z + 1, BlockPos.y, BlockPos.z + 1, BlockPos.y + 1); + int Lines = LinesCross(start.z, start.y, end.z, end.y, BlockPos.z + 1, BlockPos.y, BlockPos.z + 1, BlockPos.y + 1); if (Lines == 1) { - Lines = LinesCross( start.z, start.x, end.z, end.x, BlockPos.z + 1, BlockPos.x, BlockPos.z + 1, BlockPos.x + 1); + Lines = LinesCross(start.z, start.x, end.z, end.x, BlockPos.z + 1, BlockPos.x, BlockPos.z + 1, BlockPos.x + 1); if (Lines == 1) { - intersect3D_SegmentPlane( start, end, BlockPos + Vector3f(0, 0, 1), Vector3f(0, 0, 1)); + intersect3D_SegmentPlane(start, end, BlockPos + Vector3f(0, 0, 1), Vector3f(0, 0, 1)); return 4; } } } - dot = Look.Dot( Vector3f(0, 1, 0)); // fifth face normal is y 1 + dot = Look.Dot(Vector3f(0, 1, 0)); // fifth face normal is y 1 if (dot < 0) { - int Lines = LinesCross( start.y, start.x, end.y, end.x, BlockPos.y + 1, BlockPos.x, BlockPos.y + 1, BlockPos.x + 1); + int Lines = LinesCross(start.y, start.x, end.y, end.x, BlockPos.y + 1, BlockPos.x, BlockPos.y + 1, BlockPos.x + 1); if (Lines == 1) { - Lines = LinesCross( start.y, start.z, end.y, end.z, BlockPos.y + 1, BlockPos.z, BlockPos.y + 1, BlockPos.z + 1); + Lines = LinesCross(start.y, start.z, end.y, end.z, BlockPos.y + 1, BlockPos.z, BlockPos.y + 1, BlockPos.z + 1); if (Lines == 1) { - intersect3D_SegmentPlane( start, end, BlockPos + Vector3f(0, 1, 0), Vector3f(0, 1, 0)); + intersect3D_SegmentPlane(start, end, BlockPos + Vector3f(0, 1, 0), Vector3f(0, 1, 0)); return 5; } } } - dot = Look.Dot( Vector3f(0, -1, 0)); // sixth face normal is y -1 + dot = Look.Dot(Vector3f(0, -1, 0)); // sixth face normal is y -1 if (dot < 0) { - int Lines = LinesCross( start.y, start.x, end.y, end.x, BlockPos.y, BlockPos.x, BlockPos.y, BlockPos.x + 1); + int Lines = LinesCross(start.y, start.x, end.y, end.x, BlockPos.y, BlockPos.x, BlockPos.y, BlockPos.x + 1); if (Lines == 1) { - Lines = LinesCross( start.y, start.z, end.y, end.z, BlockPos.y, BlockPos.z, BlockPos.y, BlockPos.z + 1); + Lines = LinesCross(start.y, start.z, end.y, end.z, BlockPos.y, BlockPos.z, BlockPos.y, BlockPos.z + 1); if (Lines == 1) { - intersect3D_SegmentPlane( start, end, BlockPos, Vector3f(0, -1, 0)); + intersect3D_SegmentPlane(start, end, BlockPos, Vector3f(0, -1, 0)); return 6; } } diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 9113ec343..ff934c049 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1167,7 +1167,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) { m_MaximumCost = 39; } - if (m_MaximumCost >= 40 && !a_Player.IsGameModeCreative()) + if ((m_MaximumCost >= 40) && !a_Player.IsGameModeCreative()) { Input.Empty(); } diff --git a/src/World.cpp b/src/World.cpp index 9a6ef5c30..7518327b9 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1809,7 +1809,7 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_FlyAwaySpeed /= 100; // Pre-divide, so that we don't have to divide each time inside the loop for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { - if (!IsValidItem(itr->m_ItemType) || itr->m_ItemType == E_BLOCK_AIR) + if (!IsValidItem(itr->m_ItemType) || (itr->m_ItemType == E_BLOCK_AIR)) { // Don't spawn pickup if item isn't even valid; should prevent client crashing too continue; @@ -1835,7 +1835,7 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double { for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { - if (!IsValidItem(itr->m_ItemType) || itr->m_ItemType == E_BLOCK_AIR) + if (!IsValidItem(itr->m_ItemType) || (itr->m_ItemType == E_BLOCK_AIR)) { continue; } diff --git a/src/XMLParser.h b/src/XMLParser.h index 5b53e55cf..dab9699c9 100644 --- a/src/XMLParser.h +++ b/src/XMLParser.h @@ -105,11 +105,11 @@ public: Destroy (); // If the encoding or seperator are empty, then nullptr - if (pszEncoding != nullptr && pszEncoding [0] == 0) + if ((pszEncoding != nullptr) && (pszEncoding[0] == 0)) { pszEncoding = nullptr; } - if (pszSep != nullptr && pszSep [0] == 0) + if ((pszSep != nullptr) && (pszSep[0] == 0)) { pszSep = nullptr; } @@ -147,7 +147,7 @@ public: bool Parse (const char *pszBuffer, int nLength, bool fIsFinal = true) { assert (m_p != nullptr); - return XML_Parse (m_p, pszBuffer, nLength, fIsFinal) != 0; + return (XML_Parse (m_p, pszBuffer, nLength, fIsFinal) != 0); } // @cmember Parse internal buffer From 21d5374b979329aa04e0ee5af63becca08439d86 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Dec 2014 12:58:30 +0100 Subject: [PATCH 28/32] CheckBasicStyle: Added a check for parentheses around comparisons. The check is only rudimentary and tends to fall towards missed positived rather than false positives. --- src/CheckBasicStyle.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua index 76ae8c325..d703c3816 100644 --- a/src/CheckBasicStyle.lua +++ b/src/CheckBasicStyle.lua @@ -92,6 +92,25 @@ end local g_ViolationPatterns = { + -- Parenthesis around comparisons: + {"==[^)]+&&", "Add parenthesis around comparison"}, + {"&&[^(]+==", "Add parenthesis around comparison"}, + {"==[^)]+||", "Add parenthesis around comparison"}, + {"||[^(]+==", "Add parenthesis around comparison"}, + {"!=[^)]+&&", "Add parenthesis around comparison"}, + {"&&[^(]+!=", "Add parenthesis around comparison"}, + {"!=[^)]+||", "Add parenthesis around comparison"}, + {"||[^(]+!=", "Add parenthesis around comparison"}, + {"<[^)T][^)]*&&", "Add parenthesis around comparison"}, -- Must take special care of templates: "template fn(Args && ...)" + {"&&[^(]+<", "Add parenthesis around comparison"}, + {"<[^)T][^)]*||", "Add parenthesis around comparison"}, -- Must take special care of templates: "template fn(Args && ...)" + {"||[^(]+<", "Add parenthesis around comparison"}, + -- Cannot check ">" because of "obj->m_Flag &&". Check at least ">=": + {">=[^)]+&&", "Add parenthesis around comparison"}, + {"&&[^(]+>=", "Add parenthesis around comparison"}, + {">=[^)]+||", "Add parenthesis around comparison"}, + {"||[^(]+>=", "Add parenthesis around comparison"}, + -- Check against indenting using spaces: {"^\t* +", "Indenting with a space"}, @@ -227,6 +246,9 @@ end +-- Remove buffering from stdout, so that the output appears immediately in IDEs: +io.stdout:setvbuf("no") + -- Process all files in the AllFiles.lst file (generated by cmake): for fnam in io.lines("AllFiles.lst") do ProcessItem(fnam) From e2a04f580a0813206f527a61244cb3382248fd12 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Dec 2014 16:59:11 +0100 Subject: [PATCH 29/32] BasicStyle: Added missing braces to control statements. --- src/Bindings/DeprecatedBindings.cpp | 14 +++++ src/Bindings/PluginManager.cpp | 9 ++- src/Blocks/BlockBed.h | 5 +- src/Blocks/BlockDoor.cpp | 10 +++- src/Blocks/BlockRail.h | 88 +++++++++++++++++++++++------ src/ClientHandle.cpp | 4 ++ src/Entities/Entity.cpp | 20 +++++-- src/Entities/Minecart.cpp | 29 ++++++++-- src/Generating/Caves.cpp | 10 +++- src/Mobs/AggressiveMonster.cpp | 2 + src/Mobs/Monster.cpp | 27 +++++++-- src/OSSupport/Thread.cpp | 11 +++- src/Simulator/FluidSimulator.cpp | 2 + src/StringUtils.cpp | 10 +++- src/Tracer.cpp | 15 ++++- src/WorldStorage/WSSAnvil.cpp | 31 ++++++---- src/XMLParser.h | 8 +++ 17 files changed, 241 insertions(+), 54 deletions(-) diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index 95cd9c4f7..6dd6a4e59 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -52,7 +52,9 @@ static int tolua_get_AllToLua_g_BlockSpreadLightFalloff(lua_State* tolua_S) { tolua_Error tolua_err; if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err)) + { tolua_error(tolua_S, "#vinvalid type in array indexing.", &tolua_err); + } } #endif BlockType = (int)tolua_tonumber(tolua_S, 2, 0); @@ -78,7 +80,9 @@ static int tolua_get_AllToLua_g_BlockTransparent(lua_State* tolua_S) { tolua_Error tolua_err; if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err)) + { tolua_error(tolua_S, "#vinvalid type in array indexing.", &tolua_err); + } } #endif BlockType = (int)tolua_tonumber(tolua_S, 2, 0); @@ -104,7 +108,9 @@ static int tolua_get_AllToLua_g_BlockOneHitDig(lua_State* tolua_S) { tolua_Error tolua_err; if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err)) + { tolua_error(tolua_S, "#vinvalid type in array indexing.", &tolua_err); + } } #endif BlockType = (int)tolua_tonumber(tolua_S, 2, 0); @@ -130,7 +136,9 @@ static int tolua_get_AllToLua_g_BlockPistonBreakable(lua_State* tolua_S) { tolua_Error tolua_err; if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err)) + { tolua_error(tolua_S, "#vinvalid type in array indexing.", &tolua_err); + } } #endif BlockType = (int)tolua_tonumber(tolua_S, 2, 0); @@ -156,7 +164,9 @@ static int tolua_get_AllToLua_g_BlockIsSnowable(lua_State* tolua_S) { tolua_Error tolua_err; if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err)) + { tolua_error(tolua_S, "#vinvalid type in array indexing.", &tolua_err); + } } #endif BlockType = (int)tolua_tonumber(tolua_S, 2, 0); @@ -182,7 +192,9 @@ static int tolua_get_AllToLua_g_BlockIsSolid(lua_State* tolua_S) { tolua_Error tolua_err; if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err)) + { tolua_error(tolua_S, "#vinvalid type in array indexing.", &tolua_err); + } } #endif BlockType = (int)tolua_tonumber(tolua_S, 2, 0); @@ -208,7 +220,9 @@ static int tolua_get_AllToLua_g_BlockFullyOccupiesVoxel(lua_State* tolua_S) { tolua_Error tolua_err; if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err)) + { tolua_error(tolua_S, "#vinvalid type in array indexing.", &tolua_err); + } } #endif BlockType = (int)tolua_tonumber(tolua_S, 2, 0); diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index f951f6221..406a540f4 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1459,11 +1459,16 @@ cPluginManager::CommandResult cPluginManager::HandleCommand(cPlayer & a_Player, -cPlugin * cPluginManager::GetPlugin( const AString & a_Plugin) const +cPlugin * cPluginManager::GetPlugin(const AString & a_Plugin) const { for (PluginMap::const_iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr) { - if (itr->second == nullptr) continue; + if (itr->second == nullptr) + { + // The plugin is currently unloaded + continue; + } + if (itr->second->GetName().compare(a_Plugin) == 0) { return itr->second; diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 9fd45644b..a8b5be899 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -52,7 +52,10 @@ public: static NIBBLETYPE RotationToMetaData(double a_Rotation) { a_Rotation += 180 + (180 / 4); // So its not aligned with axis - if (a_Rotation > 360) a_Rotation -= 360; + if (a_Rotation > 360) + { + a_Rotation -= 360; + } a_Rotation = (a_Rotation / 360) * 4; diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index 96345a2df..90b7b15c2 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -145,7 +145,10 @@ NIBBLETYPE cBlockDoorHandler::MetaMirrorXY(NIBBLETYPE a_Meta) // in only the bottom tile while the hinge position is in the top tile. This function only operates on one tile at a time, // so the function can only see either the hinge position or orientation, but not both, at any given time. The class itself // needs extra datamembers. - if (a_Meta & 0x08) return a_Meta; + if (a_Meta & 0x08) + { + return a_Meta; + } // Holds open/closed meta data. 0x0C == 1100. NIBBLETYPE OtherMeta = a_Meta & 0x0C; @@ -173,7 +176,10 @@ NIBBLETYPE cBlockDoorHandler::MetaMirrorYZ(NIBBLETYPE a_Meta) // so the function can only see either the hinge position or orientation, but not both, at any given time.The class itself // needs extra datamembers. - if (a_Meta & 0x08) return a_Meta; + if (a_Meta & 0x08) + { + return a_Meta; + } // Holds open/closed meta data. 0x0C == 1100. NIBBLETYPE OtherMeta = a_Meta & 0x0C; diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 87ce069ab..21a34d8ce 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -151,13 +151,21 @@ public: Neighbors[6] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_NONE)); Neighbors[7] = (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ + 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_SOUTH, E_PURE_NONE)); if (IsUnstable(a_ChunkInterface, a_BlockX + 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_EAST)) + { Neighbors[0] = true; + } if (IsUnstable(a_ChunkInterface, a_BlockX - 1, a_BlockY - 1, a_BlockZ) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_WEST)) + { Neighbors[1] = true; + } if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ - 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_NORTH)) + { Neighbors[2] = true; + } if (IsUnstable(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ + 1) || !IsNotConnected(a_ChunkInterface, a_BlockX, a_BlockY - 1, a_BlockZ, BLOCK_FACE_SOUTH)) + { Neighbors[3] = true; + } for (int i = 0; i < 8; i++) { if (Neighbors[i]) @@ -167,12 +175,30 @@ public: } if (RailsCnt == 1) { - if (Neighbors[7]) return E_META_RAIL_ASCEND_ZP; - else if (Neighbors[6]) return E_META_RAIL_ASCEND_ZM; - else if (Neighbors[5]) return E_META_RAIL_ASCEND_XM; - else if (Neighbors[4]) return E_META_RAIL_ASCEND_XP; - else if (Neighbors[0] || Neighbors[1]) return E_META_RAIL_XM_XP; - else if (Neighbors[2] || Neighbors[3]) return E_META_RAIL_ZM_ZP; + if (Neighbors[7]) + { + return E_META_RAIL_ASCEND_ZP; + } + else if (Neighbors[6]) + { + return E_META_RAIL_ASCEND_ZM; + } + else if (Neighbors[5]) + { + return E_META_RAIL_ASCEND_XM; + } + else if (Neighbors[4]) + { + return E_META_RAIL_ASCEND_XP; + } + else if (Neighbors[0] || Neighbors[1]) + { + return E_META_RAIL_XM_XP; + } + else if (Neighbors[2] || Neighbors[3]) + { + return E_META_RAIL_ZM_ZP; + } ASSERT(!"Weird neighbor count"); return Meta; } @@ -185,16 +211,46 @@ public: } if (RailsCnt > 1) { - if (Neighbors[3] && Neighbors[0] && CanThisRailCurve()) return E_META_RAIL_CURVED_ZP_XP; - else if (Neighbors[3] && Neighbors[1] && CanThisRailCurve()) return E_META_RAIL_CURVED_ZP_XM; - else if (Neighbors[2] && Neighbors[0] && CanThisRailCurve()) return E_META_RAIL_CURVED_ZM_XP; - else if (Neighbors[2] && Neighbors[1] && CanThisRailCurve()) return E_META_RAIL_CURVED_ZM_XM; - else if (Neighbors[7] && Neighbors[2]) return E_META_RAIL_ASCEND_ZP; - else if (Neighbors[3] && Neighbors[6]) return E_META_RAIL_ASCEND_ZM; - else if (Neighbors[5] && Neighbors[0]) return E_META_RAIL_ASCEND_XM; - else if (Neighbors[4] && Neighbors[1]) return E_META_RAIL_ASCEND_XP; - else if (Neighbors[0] && Neighbors[1]) return E_META_RAIL_XM_XP; - else if (Neighbors[2] && Neighbors[3]) return E_META_RAIL_ZM_ZP; + if (Neighbors[3] && Neighbors[0] && CanThisRailCurve()) + { + return E_META_RAIL_CURVED_ZP_XP; + } + else if (Neighbors[3] && Neighbors[1] && CanThisRailCurve()) + { + return E_META_RAIL_CURVED_ZP_XM; + } + else if (Neighbors[2] && Neighbors[0] && CanThisRailCurve()) + { + return E_META_RAIL_CURVED_ZM_XP; + } + else if (Neighbors[2] && Neighbors[1] && CanThisRailCurve()) + { + return E_META_RAIL_CURVED_ZM_XM; + } + else if (Neighbors[7] && Neighbors[2]) + { + return E_META_RAIL_ASCEND_ZP; + } + else if (Neighbors[3] && Neighbors[6]) + { + return E_META_RAIL_ASCEND_ZM; + } + else if (Neighbors[5] && Neighbors[0]) + { + return E_META_RAIL_ASCEND_XM; + } + else if (Neighbors[4] && Neighbors[1]) + { + return E_META_RAIL_ASCEND_XP; + } + else if (Neighbors[0] && Neighbors[1]) + { + return E_META_RAIL_XM_XP; + } + else if (Neighbors[2] && Neighbors[3]) + { + return E_META_RAIL_ZM_ZP; + } if (CanThisRailCurve()) { diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a6cbad32a..366f20170 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -199,9 +199,13 @@ void cClientHandle::GenerateOfflineUUID(void) AString cClientHandle::FormatChatPrefix(bool ShouldAppendChatPrefixes, AString a_ChatPrefixS, AString m_Color1, AString m_Color2) { if (ShouldAppendChatPrefixes) + { return Printf("%s[%s] %s", m_Color1.c_str(), a_ChatPrefixS.c_str(), m_Color2.c_str()); + } else + { return Printf("%s", m_Color1.c_str()); + } } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 3b2fa9b4e..54b9f2a20 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -665,7 +665,10 @@ int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_Dama // Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover // Filter out damage types that are not protected by armor: - if (!ArmorCoversAgainst(a_DamageType)) return 0; + if (!ArmorCoversAgainst(a_DamageType)) + { + return 0; + } // Add up all armor points: // Ref.: http://www.minecraftwiki.net/wiki/Armor#Defense_points as of 2012_12_20 @@ -1011,9 +1014,18 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) // Block hit was within our projected path // Begin by stopping movement in the direction that we hit something. The Normal is the line perpendicular to a 2D face and in this case, stores what block face was hit through either -1 or 1. // For example: HitNormal.y = -1 : BLOCK_FACE_YM; HitNormal.y = 1 : BLOCK_FACE_YP - if (Tracer.HitNormal.x != 0.f) NextSpeed.x = 0.f; - if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f; - if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f; + if (Tracer.HitNormal.x != 0.f) + { + NextSpeed.x = 0.f; + } + if (Tracer.HitNormal.y != 0.f) + { + NextSpeed.y = 0.f; + } + if (Tracer.HitNormal.z != 0.f) + { + NextSpeed.z = 0.f; + } if (Tracer.HitNormal.y == 1.f) // Hit BLOCK_FACE_YP, we are on the ground { diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 22e046800..fac4f0714 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -142,8 +142,13 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) if (!IsBlockRail(InsideType)) { - Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); // When an descending minecart hits a flat rail, it goes through the ground; check for this - if (IsBlockRail(InsideType)) AddPosY(1); // Push cart upwards + // When a descending minecart hits a flat rail, it goes through the ground; check for this + Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); + if (IsBlockRail(InsideType)) + { + // Push cart upwards + AddPosY(1); + } } bool WasDetectorRail = false; @@ -218,7 +223,10 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) // Execute both the entity and block collision checks bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); - if (EntCol || BlckCol) return; + if (EntCol || BlckCol) + { + return; + } if (GetSpeedZ() != NO_SPEED) // Don't do anything if cart is stationary { @@ -243,7 +251,10 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) SetSpeedZ(NO_SPEED); bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); - if (EntCol || BlckCol) return; + if (EntCol || BlckCol) + { + return; + } if (GetSpeedX() != NO_SPEED) { @@ -422,7 +433,10 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) SetSpeedX(0); bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); - if (EntCol || BlckCol) return; + if (EntCol || BlckCol) + { + return; + } if (GetSpeedZ() != NO_SPEED) { @@ -445,7 +459,10 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) SetSpeedZ(NO_SPEED); bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); - if (EntCol || BlckCol) return; + if (EntCol || BlckCol) + { + return; + } if (GetSpeedX() != NO_SPEED) { diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index fc925a150..e4735cb83 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -692,8 +692,14 @@ static float GetMarbleNoise( float x, float y, float z, cNoise & a_Noise) float oct1 = (a_Noise.CubicNoise3D(x * 0.1f, y * 0.1f, z * 0.1f)) * 4; oct1 = oct1 * oct1 * oct1; - if (oct1 < 0.f) oct1 = PI_2; - if (oct1 > PI_2) oct1 = PI_2; + if (oct1 < 0.f) + { + oct1 = PI_2; + } + if (oct1 > PI_2) + { + oct1 = PI_2; + } return oct1; } diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 41ef26e2a..7ca7a9d66 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -75,7 +75,9 @@ void cAggressiveMonster::Tick(float a_Dt, cChunk & a_Chunk) } if (m_Target == nullptr) + { return; + } cTracer LineOfSight(GetWorld()); Vector3d AttackDirection(m_Target->GetPosition() - GetPosition()); diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index b8926e31d..c8b2ed774 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -267,7 +267,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) } if ((m_Target != nullptr) && m_Target->IsDestroyed()) + { m_Target = nullptr; + } // Burning in daylight HandleDaylightBurning(a_Chunk); @@ -1028,22 +1030,34 @@ 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 (!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 (!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 (!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()); + if (!GetEquippedBoots().IsEmpty()) + { + a_Drops.push_back(GetEquippedBoots()); + } } } @@ -1056,7 +1070,10 @@ 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()); + if (!GetEquippedWeapon().IsEmpty()) + { + a_Drops.push_back(GetEquippedWeapon()); + } } } diff --git a/src/OSSupport/Thread.cpp b/src/OSSupport/Thread.cpp index faaccce96..6188d5088 100644 --- a/src/OSSupport/Thread.cpp +++ b/src/OSSupport/Thread.cpp @@ -83,12 +83,16 @@ cThread::~cThread() void cThread::Start( bool a_bWaitOnDelete /* = true */) { if (a_bWaitOnDelete) + { m_StopEvent = new cEvent(); + } #ifndef _WIN32 pthread_t SndThread; if (pthread_create( &SndThread, NULL, MyThread, this)) + { LOGERROR("ERROR: Could not create thread!"); + } #else DWORD ThreadID = 0; HANDLE hThread = CreateThread(NULL // security @@ -132,6 +136,11 @@ void *cThread::MyThread( void *a_Param) ThreadFunction( ThreadParam); - if (StopEvent) StopEvent->Set(); + // If the thread was marked as wait-on-delete, signal the event being waited on: + if (StopEvent != nullptr) + { + StopEvent->Set(); + } + return 0; } diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp index a7551d9bc..ecd74ee52 100644 --- a/src/Simulator/FluidSimulator.cpp +++ b/src/Simulator/FluidSimulator.cpp @@ -184,7 +184,9 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a } if (LowestPoint == m_World.GetBlockMeta(a_X, a_Y, a_Z)) + { return NONE; + } if (a_X - X > 0) { diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index fe145521f..5febf5d6c 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -420,7 +420,10 @@ static bool isLegalUTF8(const unsigned char * source, int length) case 3: if (((a = (*--srcptr)) < 0x80) || (a > 0xbf)) return false; case 2: { - if ((a = (*--srcptr)) > 0xbf) return false; + if ((a = (*--srcptr)) > 0xbf) + { + return false; + } switch (*source) { // no fall-through in this inner switch @@ -523,7 +526,10 @@ are equivalent to the following loop: { ch += *source++; --tmpBytesToRead; - if (tmpBytesToRead) ch <<= 6; + if (tmpBytesToRead) + { + ch <<= 6; + } } while (tmpBytesToRead > 0); } --------------------------------------------------------------------- diff --git a/src/Tracer.cpp b/src/Tracer.cpp index 53884dee8..e604f4a5b 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -39,8 +39,14 @@ cTracer::~cTracer() float cTracer::SigNum(float a_Num) { - if (a_Num < 0.f) return -1.f; - if (a_Num > 0.f) return 1.f; + if (a_Num < 0.f) + { + return -1.f; + } + if (a_Num > 0.f) + { + return 1.f; + } return 0.f; } @@ -59,7 +65,10 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction) step.z = (int) SigNum(dir.z); // normalize the direction vector - if (dir.SqrLength() > 0.f) dir.Normalize(); + if (dir.SqrLength() > 0.f) + { + dir.Normalize(); + } // how far we must move in the ray direction before // we encounter a new voxel in x-direction diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index ddee5e514..26a9104bc 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1526,7 +1526,10 @@ void cWSSAnvil::LoadFallingBlockFromNBT(cEntityList & a_Entities, const cParsedN int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "TileID"); int MetaIdx = a_NBT.FindChildByName(a_TagIdx, "Data"); - if ((TypeIdx < 0) || (MetaIdx < 0)) { return; } + if ((TypeIdx < 0) || (MetaIdx < 0)) + { + return; + } int Type = a_NBT.GetInt(TypeIdx); NIBBLETYPE Meta = (NIBBLETYPE)a_NBT.GetByte(MetaIdx); @@ -2196,11 +2199,13 @@ void cWSSAnvil::LoadGiantFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { - int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "Type"); + int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "Type"); int ColorIdx = a_NBT.FindChildByName(a_TagIdx, "Color"); int StyleIdx = a_NBT.FindChildByName(a_TagIdx, "Style"); - - if ((TypeIdx < 0) || (ColorIdx < 0) || (StyleIdx < 0)) { return; } + if ((TypeIdx < 0) || (ColorIdx < 0) || (StyleIdx < 0)) + { + return; + } int Type = a_NBT.GetInt(TypeIdx); int Color = a_NBT.GetInt(ColorIdx); @@ -2390,8 +2395,10 @@ void cWSSAnvil::LoadSilverfishFromNBT(cEntityList & a_Entities, const cParsedNBT void cWSSAnvil::LoadSkeletonFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "SkeletonType"); - - if (TypeIdx < 0) { return; } + if (TypeIdx < 0) + { + return; + } bool Type = ((a_NBT.GetByte(TypeIdx) == 1) ? true : false); @@ -2505,8 +2512,10 @@ void cWSSAnvil::LoadSquidFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "Profession"); - - if (TypeIdx < 0) { return; } + if (TypeIdx < 0) + { + return; + } int Type = a_NBT.GetInt(TypeIdx); @@ -2630,8 +2639,10 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { int IsVillagerIdx = a_NBT.FindChildByName(a_TagIdx, "IsVillager"); - - if (IsVillagerIdx < 0) { return; } + if (IsVillagerIdx < 0) + { + return; + } bool IsVillagerZombie = ((a_NBT.GetByte(IsVillagerIdx) == 1) ? true : false); diff --git a/src/XMLParser.h b/src/XMLParser.h index dab9699c9..ea341bce6 100644 --- a/src/XMLParser.h +++ b/src/XMLParser.h @@ -254,7 +254,9 @@ protected: XML_SetDefaultHandlerExpand (m_p, fEnable ? DefaultHandler : nullptr); } else + { XML_SetDefaultHandler (m_p, fEnable ? DefaultHandler : nullptr); + } } // @cmember Enable/Disable external entity ref handler @@ -402,11 +404,17 @@ public: { XML_expat_version v = XML_ExpatVersionInfo (); if (pnMajor) + { *pnMajor = v .major; + } if (pnMinor) + { *pnMinor = v .minor; + } if (pnMicro) + { *pnMicro = v .micro; + } } // @cmember Get last error string From 8e56d7539d03e6d344f5e27f9be391c6cd1846bf Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Dec 2014 16:59:56 +0100 Subject: [PATCH 30/32] CheckBasicStyle: Check missing braces for control statements. Only single-line control statements are checked. --- src/CheckBasicStyle.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua index d703c3816..7914aedfd 100644 --- a/src/CheckBasicStyle.lua +++ b/src/CheckBasicStyle.lua @@ -181,6 +181,7 @@ local function ProcessFile(a_FileName) -- Ref.: http://stackoverflow.com/questions/10416869/iterate-over-possibly-empty-lines-in-a-way-that-matches-the-expectations-of-exis local lineCounter = 1 local lastIndentLevel = 0 + local isLastLineControl = false all:gsub("\r\n", "\n") -- normalize CRLF into LF-only string.gsub(all .. "\n", "[^\n]*\n", -- Iterate over each line, while preserving empty lines function(a_Line) @@ -217,6 +218,24 @@ local function ProcessFile(a_FileName) end lastIndentLevel = indentLevel end + + -- Check that control statements have braces on separate lines after them: + -- Note that if statements can be broken into multiple lines, in which case this test is not taken + if (isLastLineControl) then + if not(a_Line:find("^%s*{") or a_Line:find("^%s*#")) then + -- Not followed by a brace, not followed by a preprocessor + ReportViolation(a_FileName, lineCounter - 1, 1, 1, "Control statement needs a brace on separate line") + end + end + local lineWithSpace = " " .. a_Line + isLastLineControl = + lineWithSpace:find("^%s+if %b()") or + lineWithSpace:find("^%s+else if %b()") or + lineWithSpace:find("^%s+for %b()") or + lineWithSpace:find("^%s+switch %b()") or + lineWithSpace:find("^%s+else\n") or + lineWithSpace:find("^%s+else //") or + lineWithSpace:find("^%s+do %b()") lineCounter = lineCounter + 1 end From b25fcb0972554facbd4dfd79cb256a77a2cb6773 Mon Sep 17 00:00:00 2001 From: p-mcgowan Date: Fri, 5 Dec 2014 11:31:01 -0800 Subject: [PATCH 31/32] formatting and default spawn percentage --- src/Generating/FinishGen.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 41dbdca16..ad3dc5293 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -993,6 +993,7 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e if ((m_AnimalProbability < 0) || (m_AnimalProbability > 100)) { LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); + m_AnimalProbability = DefaultAnimalSpawnChunkPercentage; } } @@ -1052,7 +1053,7 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ); // Check block below (opaque, grass, water), and above (air) - if (AnimalToSpawn == mtSquid && BlockAtFeet != E_BLOCK_WATER) + if ((AnimalToSpawn == mtSquid) && (BlockAtFeet != E_BLOCK_WATER)) { return false; } From c5dc5ac45f19aac55f99629603cfaf81ac3d0b10 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Dec 2014 22:46:46 +0100 Subject: [PATCH 32/32] FinishGenPassiveMobs: Cosmetic changes. --- src/Generating/FinishGen.cpp | 45 ++++++++++++++++++------------------ src/Generating/FinishGen.h | 18 +++++++++------ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index ad3dc5293..e6732dbd5 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1078,16 +1078,14 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX return false; } - int AnimalX, AnimalY, AnimalZ; - AnimalX = (double)(a_ChunkDesc.GetChunkX()*cChunkDef::Width + a_RelX + 0.5); - AnimalY = a_RelY; - AnimalZ = (double)(a_ChunkDesc.GetChunkZ()*cChunkDef::Width + a_RelZ + 0.5); + double AnimalX = static_cast(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX + 0.5); + double AnimalY = a_RelY; + double AnimalZ = static_cast(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ + 0.5); - cEntityList ChunkEntities = a_ChunkDesc.GetEntities(); cMonster * NewMob = cMonster::NewMonsterFromType(AnimalToSpawn); NewMob->SetPosition(AnimalX, AnimalY, AnimalZ); - ChunkEntities.push_back(NewMob); - LOGD("Spawning %s #%i at {%d, %d, %d}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ); + a_ChunkDesc.GetEntities().push_back(NewMob); + LOGD("Spawning %s #%i at {%.02f, %.02f, %.02f}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ); return true; } @@ -1100,13 +1098,12 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) { std::set ListOfSpawnables; - std::set::iterator MobIter = ListOfSpawnables.begin(); int chunkX = a_ChunkDesc.GetChunkX(); int chunkZ = a_ChunkDesc.GetChunkZ(); int x = (m_Noise.IntNoise2DInt(chunkX, chunkZ + 10) / 7) % cChunkDef::Width; int z = (m_Noise.IntNoise2DInt(chunkX + chunkZ, chunkZ) / 7) % cChunkDef::Width; - /** Check biomes first to get a list of animals */ + // Check biomes first to get a list of animals switch (a_ChunkDesc.GetBiome(x, z)) { // No animals in deserts or non-overworld dimensions @@ -1118,12 +1115,14 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) { return mtInvalidType; } + // Mooshroom only - no other mobs on mushroom islands case biMushroomIsland: case biMushroomShore: { return mtMooshroom; } + // Add squid in ocean biomes case biOcean: case biFrozenOcean: @@ -1131,9 +1130,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biRiver: case biDeepOcean: { - ListOfSpawnables.insert(MobIter, mtSquid); + ListOfSpawnables.insert(mtSquid); break; } + // Add ocelots in jungle biomes case biJungle: case biJungleHills: @@ -1141,9 +1141,11 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biJungleM: case biJungleEdgeM: { - ListOfSpawnables.insert(MobIter, mtOcelot); + ListOfSpawnables.insert(mtOcelot); break; } + + // Add horses in plains-like biomes case biPlains: case biSunflowerPlains: case biSavanna: @@ -1151,10 +1153,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biSavannaM: case biSavannaPlateauM: { - ListOfSpawnables.insert(MobIter, mtHorse); - // ListOfSpawnables.insert(mtDonkey); + ListOfSpawnables.insert(mtHorse); break; } + // Add wolves in forest and spruce forests case biForest: case biTaiga: @@ -1162,7 +1164,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) case biColdTaiga: case biColdTaigaM: { - ListOfSpawnables.insert(MobIter, mtWolf); + ListOfSpawnables.insert(mtWolf); break; } // Nothing special about this biome @@ -1171,10 +1173,10 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) break; } } - ListOfSpawnables.insert(MobIter, mtChicken); - ListOfSpawnables.insert(MobIter, mtCow); - ListOfSpawnables.insert(MobIter, mtPig); - ListOfSpawnables.insert(MobIter, mtSheep); + ListOfSpawnables.insert(mtChicken); + ListOfSpawnables.insert(mtCow); + ListOfSpawnables.insert(mtPig); + ListOfSpawnables.insert(mtSheep); if (ListOfSpawnables.empty()) { @@ -1182,11 +1184,8 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) } int RandMob = (m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size(); - MobIter = ListOfSpawnables.begin(); - for (int i = 0; i < RandMob; i++) - { - ++MobIter; - } + auto MobIter = ListOfSpawnables.begin(); + std::advance(MobIter, RandMob); return *MobIter; } diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index 8305908c0..ae6dee590 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -312,7 +312,7 @@ protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; - // Tries to place a spring at the specified coords, checks neighbors. Returns true if successful + /** Tries to place a spring at the specified coords, checks neighbors. Returns true if successful. */ bool TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int y, int z); } ; @@ -321,8 +321,7 @@ protected: /** This class populates generated chunks with packs of biome-dependant animals - Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots - */ +Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots */ class cFinishGenPassiveMobs : public cFinishGen { @@ -332,16 +331,21 @@ public: protected: - cNoise m_Noise; - int m_AnimalProbability; // Chance, [0..100], that an animal pack will be generated in a chunk + /** The noise used as the source of randomness */ + cNoise m_Noise; + + /** Chance, [0..100], that an animal pack will be generated in a chunk */ + int m_AnimalProbability; + // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; - // Returns false if an animal cannot spawn at given coords, else adds it to the chunk's entity list and returns true + /** Returns false if an animal cannot spawn at given coords, else adds it to the chunk's entity list and returns true */ bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn); - // Gets a random animal from biome-dependant list + /** Picks a random animal from biome-dependant list for a random position in the chunk. + Returns the chosen mob type, or mtInvalid if no mob chosen. */ eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc); } ;