Advertisement
Guest User

Untitled

a guest
Mar 27th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. commit 357c8453be32c5e6261c6a5a8946907ae024fd86
  2. Author: kwolekr <kwolekr@minetest.net>
  3. Date:   Wed Mar 27 15:08:34 2013 -0400
  4.  
  5.     Vary ore density by height
  6.  
  7. diff --git a/src/mapgen.cpp b/src/mapgen.cpp
  8. index b5deaae..20e8a89 100644
  9. --- a/src/mapgen.cpp
  10. +++ b/src/mapgen.cpp
  11. @@ -86,6 +86,20 @@ void Ore::resolveNodeNames(INodeDefManager *ndef) {
  12.  }
  13.  
  14.  
  15. +s16 Ore::getScarcity(s16 y) {
  16. +   s16 smin  = clust_scarcity_min;
  17. +   s16 smax  = clust_scarcity_max;
  18. +   s16 sramp = clust_scarcity_ramp;
  19. +
  20. +   if (y <= sramp)
  21. +       return smin;
  22. +      
  23. +   float factor = (float)(sramp - y) / (float)(sramp - height_max);
  24. +   s16 scarcity = smin + factor * (smax - smin);
  25. +   return scarcity;
  26. +}
  27. +
  28. +
  29.  void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
  30.     if (nmin.Y > height_max || nmax.Y < height_min)
  31.         return;
  32. @@ -106,8 +120,8 @@ void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
  33.                  (nmax.Z - nmin.Z + 1);
  34.     int csize     = clust_size;
  35.     int orechance = (csize * csize * csize) / clust_num_ores;
  36. -   int nclusters = volume / clust_scarcity;
  37. -
  38. +   int nclusters = volume / getScarcity(nmin.Y);
  39. +  
  40.     for (int i = 0; i != nclusters; i++) {
  41.         int x0 = pr.range(nmin.X, nmax.X - csize + 1);
  42.         int y0 = pr.range(ymin,   ymax   - csize + 1);
  43. diff --git a/src/mapgen.h b/src/mapgen.h
  44. index a900985..31aef8c 100644
  45. --- a/src/mapgen.h
  46. +++ b/src/mapgen.h
  47. @@ -110,7 +110,9 @@ class Ore {
  48.  
  49.     content_t ore;
  50.     content_t wherein;  // the node to be replaced
  51. -   s16 clust_scarcity; //
  52. +   s16 clust_scarcity_min;
  53. +   s16 clust_scarcity_ramp;
  54. +   s16 clust_scarcity_max;
  55.     s16 clust_num_ores; // how many ore nodes are in a chunk
  56.     s16 clust_size;     // how large (in nodes) a chunk of ore is
  57.     s16 height_min;
  58. @@ -127,6 +129,7 @@ class Ore {
  59.     }
  60.    
  61.     void resolveNodeNames(INodeDefManager *ndef);
  62. +   s16 getScarcity(s16 y);
  63.     virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
  64.  };
  65.  
  66. diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
  67. index 80abffa..5f213d8 100644
  68. --- a/src/scriptapi.cpp
  69. +++ b/src/scriptapi.cpp
  70. @@ -712,7 +712,9 @@ static int l_register_ore(lua_State *L)
  71.    
  72.     ore->ore_name       = getstringfield_default(L, index, "ore", "");
  73.     ore->wherein_name   = getstringfield_default(L, index, "wherein", "");
  74. -   ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
  75. +   ore->clust_scarcity_min  = getintfield_default(L, index, "clust_scarcity_min", 100);
  76. +   ore->clust_scarcity_ramp = getintfield_default(L, index, "clust_scarcity_ramp", 0);
  77. +   ore->clust_scarcity_max  = getintfield_default(L, index, "clust_scarcity_max", 100);
  78.     ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1);
  79.     ore->clust_size     = getintfield_default(L, index, "clust_size", 0);
  80.     ore->height_min     = getintfield_default(L, index, "height_min", 0);
  81. @@ -725,7 +727,7 @@ static int l_register_ore(lua_State *L)
  82.    
  83.     ore->noise = NULL;
  84.    
  85. -   if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) {
  86. +   if (ore->clust_num_ores <= 0) {
  87.         errorstream << "register_ore: clust_scarcity and clust_num_ores"
  88.             "must be greater than 0";
  89.         delete ore;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement