]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mg_ore.cpp
Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282)
[dragonfireclient.git] / src / mg_ore.cpp
index c6c1c45a782bd2270d0e239bd9ea41b76c8c3bec..5f11dda92cb70d65781a4ca83d98dafd9a84d756 100644 (file)
@@ -1,6 +1,7 @@
 /*
 Minetest
-Copyright (C) 2010-2014 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2014-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2015-2017 paramat
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -22,11 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "noise.h"
 #include "map.h"
 #include "log.h"
+#include "util/numeric.h"
 #include <algorithm>
 
 
 FlagDesc flagdesc_ore[] = {
-       {"absheight",                 OREFLAG_ABSHEIGHT},
+       {"absheight",                 OREFLAG_ABSHEIGHT}, // Non-functional
        {"puff_cliffs",               OREFLAG_PUFF_CLIFFS},
        {"puff_additive_composition", OREFLAG_PUFF_ADDITIVE},
        {NULL,                        0}
@@ -42,7 +44,8 @@ OreManager::OreManager(IGameDef *gamedef) :
 }
 
 
-size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
+size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, s16 ore_zero_level)
 {
        size_t nplaced = 0;
 
@@ -51,7 +54,7 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nma
                if (!ore)
                        continue;
 
-               nplaced += ore->placeOre(mg, blockseed, nmin, nmax);
+               nplaced += ore->placeOre(mg, blockseed, nmin, nmax, ore_zero_level);
                blockseed++;
        }
 
@@ -61,8 +64,8 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nma
 
 void OreManager::clear()
 {
-       for (size_t i = 0; i < m_objects.size(); i++) {
-               Ore *ore = (Ore *)m_objects[i];
+       for (ObjDef *object : m_objects) {
+               Ore *ore = (Ore *) object;
                delete ore;
        }
        m_objects.clear();
@@ -71,14 +74,6 @@ void OreManager::clear()
 
 ///////////////////////////////////////////////////////////////////////////////
 
-
-Ore::Ore()
-{
-       flags = 0;
-       noise = NULL;
-}
-
-
 Ore::~Ore()
 {
        delete noise;
@@ -92,24 +87,23 @@ void Ore::resolveNodeNames()
 }
 
 
-size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
+size_t Ore::placeOre(Mapgen *mg, u32 blockseed,
+       v3s16 nmin, v3s16 nmax, s16 ore_zero_level)
 {
-       int in_range = 0;
+       // Ore y_min / y_max is displaced by ore_zero_level or remains unchanged.
+       // Any ore with a limit at +-MAX_MAP_GENERATION_LIMIT is considered to have
+       // that limit at +-infinity, so we do not alter that limit.
+       s32 y_min_disp = (y_min <= -MAX_MAP_GENERATION_LIMIT) ?
+               -MAX_MAP_GENERATION_LIMIT : y_min + ore_zero_level;
+
+       s32 y_max_disp = (y_max >= MAX_MAP_GENERATION_LIMIT) ?
+               MAX_MAP_GENERATION_LIMIT : y_max + ore_zero_level;
 
-       in_range |= (nmin.Y <= y_max && nmax.Y >= y_min);
-       if (flags & OREFLAG_ABSHEIGHT)
-               in_range |= (nmin.Y >= -y_max && nmax.Y <= -y_min) << 1;
-       if (!in_range)
+       if (nmin.Y > y_max_disp || nmax.Y < y_min_disp)
                return 0;
 
-       int actual_ymin, actual_ymax;
-       if (in_range & ORE_RANGE_MIRROR) {
-               actual_ymin = MYMAX(nmin.Y, -y_max);
-               actual_ymax = MYMIN(nmax.Y, -y_min);
-       } else {
-               actual_ymin = MYMAX(nmin.Y, y_min);
-               actual_ymax = MYMIN(nmax.Y, y_max);
-       }
+       int actual_ymin = MYMAX(nmin.Y, y_min_disp);
+       int actual_ymax = MYMIN(nmax.Y, y_max_disp);
        if (clust_size >= actual_ymax - actual_ymin + 1)
                return 0;
 
@@ -149,7 +143,7 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
                if (biomemap && !biomes.empty()) {
                        u32 index = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
-                       UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[index]);
+                       std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
                        if (it == biomes.end())
                                continue;
                }
@@ -203,7 +197,7 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
                        continue;
 
                if (biomemap && !biomes.empty()) {
-                       UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[index]);
+                       std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
                        if (it == biomes.end())
                                continue;
                }
@@ -227,15 +221,6 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
 
 ///////////////////////////////////////////////////////////////////////////////
-
-OrePuff::OrePuff() :
-       Ore()
-{
-       noise_puff_top    = NULL;
-       noise_puff_bottom = NULL;
-}
-
-
 OrePuff::~OrePuff()
 {
        delete noise_puff_top;
@@ -271,7 +256,7 @@ void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed,
                        continue;
 
                if (biomemap && !biomes.empty()) {
-                       UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[index]);
+                       std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[index]);
                        if (it == biomes.end())
                                continue;
                }
@@ -339,7 +324,7 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
                if (biomemap && !biomes.empty()) {
                        u32 bmapidx = sizex * (z0 - nmin.Z) + (x0 - nmin.X);
-                       UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[bmapidx]);
+                       std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[bmapidx]);
                        if (it == biomes.end())
                                continue;
                }
@@ -380,14 +365,6 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
 
 ///////////////////////////////////////////////////////////////////////////////
-
-OreVein::OreVein() :
-       Ore()
-{
-       noise2 = NULL;
-}
-
-
 OreVein::~OreVein()
 {
        delete noise2;
@@ -423,7 +400,7 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
 
                if (biomemap && !biomes.empty()) {
                        u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X);
-                       UNORDERED_SET<u8>::iterator it = biomes.find(biomemap[bmapidx]);
+                       std::unordered_set<u8>::const_iterator it = biomes.find(biomemap[bmapidx]);
                        if (it == biomes.end())
                                continue;
                }