DEADSOFTWARE

Rewrite ore generation
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 8 Mar 2017 21:35:20 +0000 (00:35 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 8 Mar 2017 21:35:20 +0000 (00:35 +0300)
BUGS
src/randoms.mpsrc
src/worldgen.mpsrc

diff --git a/BUGS b/BUGS
index 932bedc3c350f403be0a1d2da9112db1c9a8b065..d0d381ed420f3dce4bee71a1fe738f9a4e3f2aef 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -20,7 +20,7 @@
 Иногда вместо травы генерируется грязь.
 Перепроверить генерацию предметов в вокровищницах
 Починить спавнеры
-Уголь встречается на поверхности реже чем железо
+Уголь встречается на поверхности реже чем железо
 Починит установку блока при прыжке
 Перепроверить рост деревьев
 + Печь не светится когда работает
index 47208986a7c3ec5ee5961b0963535515e0d27b8e..d4e8dea8279b2fe7c23650b1a5ada694d81c3198 100644 (file)
@@ -6,6 +6,9 @@ interface
  function rnd(max:integer):integer;//Возвращает число от 0 до max\r
  function rnd_pr(pr,p1,p2:integer):integer;\r
 \r
+ (* Возвращает true с вероятностью x/y *)\r
+ function RandomBoolean(x, y : Integer) : Boolean;\r
+\r
 implementation\r
  var\r
   next:integer;\r
@@ -34,4 +37,9 @@ implementation
    if pr>=rnd(101) then rnd_pr:=p1; else rnd_pr:=p2;\r
   end;\r
 \r
-end.
\ No newline at end of file
+ function RandomBoolean(x, y : Integer) : Boolean;\r
+   begin\r
+     RandomBoolean := rnd(y) <= x;\r
+   end;\r
+\r
+end.\r
index ca522107373f7ae63dccc066994cebef4b34d858..d49159a2428d1f9293956bc1a2aefd0c86cab6a3 100644 (file)
@@ -407,104 +407,42 @@ procedure create_bonus_chest(chx,chy:integer);
     end;\r
   end;\r
 \r
+ // Генерирует чанки руды в камне типа block с максимальной вероятность percent процентов\r
+ // Начиная с уровня starty и размером не более maxsize*maxsize\r
+ // С ростом глубины вероятность растёт\r
+ procedure GenOreChunks(block, percent, starty, maxsize : Integer);\r
+   const\r
+     preq = 100000;\r
+   var\r
+     x, y, i, j : Integer;\r
+   begin\r
+     for x := 0 to MAP_W do\r
+     for y := starty to MAP_H do\r
+       if RandomBoolean(y * percent * preq / MAP_H, 100 * preq) then\r
+         for i := 0 to rnd(maxsize) - 1 do\r
+         for j := 0 to rnd(maxsize) - 1 do\r
+           if RandomBoolean(50, 100) and (GetMap(x + i, y + j) = 3) then\r
+             SetMap(block, x + i, y + j);\r
+   end;\r
+\r
  procedure genallrudes;\r
-  var\r
-   ix,iy,iu,iv:integer;\r
   begin\r
-   //алмазы\r
-   for ix:=0 to 255 do\r
-   for iy:=111 to 127 do\r
-    if (rnd_pr(1,1,0)=1) then\r
-     begin\r
-      for iu:=0 to 2 do\r
-      for iv:=0 to 2 do\r
-       if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(10,19,getmap(ix+iu,iy+iv)),ix+iu,iy+iv);\r
-      ix:=ix+3;\r
-     end;\r
-\r
-   //золото\r
-   for ix:=0 to 255 do\r
-   for iy:=95 to 127 do\r
-    if (rnd_pr(3,1,0)=1) then\r
-     begin\r
-      for iu:=0 to 2 do\r
-      for iv:=0 to 2 do\r
-       if (ix+iu<255) and (iy+iv<126) then\r
-        if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(20,16,getmap(ix+iu,iy+iv)),ix+iu,iy+iv);\r
-      ix:=ix+3;\r
-     end;\r
-\r
-   //лазурит\r
-   for ix:=0 to 255 do\r
-   for iy:=107 to 127 do\r
-    if (rnd_pr(2,1,0)=1) then\r
-     begin\r
-      for iu:=0 to 2 do\r
-      for iv:=0 to 2 do\r
-       if (ix+iu<255) and (iy+iv<126) then\r
-        if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(40,54,getmap(ix+iu,iy+iv)),ix+iu,iy+iv);\r
-      ix:=ix+3;\r
-     end;\r
-\r
-   //редстоун\r
-   for ix:=0 to 255 do\r
-   for iy:=107 to 127 do\r
-    if (rnd_pr(2,1,0)=1) then\r
-     begin\r
-      for iu:=0 to 2 do\r
-      for iv:=0 to 2 do\r
-       if (ix+iu<255) and (iy+iv<126) then\r
-        if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(40,20,getmap(ix+iu,iy+iv)),ix+iu,iy+iv);\r
-      ix:=ix+3;\r
-     end;\r
-\r
-   //железо\r
-   for ix:=0 to 255 do\r
-   for iy:=63 to 127 do\r
-    if (rnd_pr(4,1,0)=1) then\r
-     begin\r
-      for iu:=0 to 2 do\r
-      for iv:=0 to 2 do\r
-       if (ix+iu<255) and (iy+iv<126) then\r
-        if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(40,17,getmap(ix+iu,iy+iv)),ix+iu,iy+iv);\r
-      ix:=ix+3;\r
-     end;\r
-\r
-   //уголь\r
-   for ix:=0 to 255 do\r
-   for iy:=0 to 127 do\r
-    if (rnd_pr(6,1,0)=1) then\r
-     begin\r
-      for iu:=0 to 2 do\r
-      for iv:=0 to 2 do\r
-       if (ix+iu<255) and (iy+iv<126) then\r
-        if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(50,18,getmap(ix+iu,iy+iv)),ix+iu,iy+iv);\r
-      ix:=ix+3;\r
-     end;\r
-\r
-   //гравий\r
-   for ix:=0 to 255 do\r
-   for iy:=63 to 126 do\r
-    if (rnd_pr(2,1,0)=1) then\r
-     begin\r
-      for iu:=0 to rnd(5) do\r
-      for iv:=0 to rnd(5) do\r
-       if (ix+iu<255) and (iy+iv<126) then\r
-        if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(90,8,getmap(ix+iu,iy+iv)),ix+iu,iy+iv);\r
-      ix:=ix+3;\r
-     end;\r
-\r
-   //земля на камне\r
-   for ix:=0 to 255 do\r
-   for iy:=63 to 127 do\r
-    if (rnd_pr(1,1,0)=1) then\r
-     begin\r
-      for iu:=0 to rnd(5) do\r
-      for iv:=0 to rnd(5) do\r
-       if (ix+iu<255) and (iy+iv<126) then\r
-        if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(90,1,getmap(ix+iu,iy+iv)),ix+iu,iy+iv);\r
-      ix:=ix+3;\r
-     end;\r
+   (* Алмазная руда *)\r
+   GenOreChunks(19, 1, 111, 3);\r
+   (* Золотая руда *)\r
+   GenOreChunks(16, 2, 95, 3);\r
+   (* Лазуритовая руда *)\r
+   GenOreChunks(54, 2, 107, 3);\r
+   (* Красная руда *)\r
+   GenOreChunks(20, 2, 107, 3);\r
+   (* Железная руда *)\r
+   GenOreChunks(17, 3, 63, 3);\r
+   (* Угольная руда *)\r
+   GenOreChunks(18, 4, 0, 6);\r
+   (* Гравий *)\r
+   GenOreChunks(8, 2, 0, 6);\r
+   (* Грязь *)\r
+   GenOreChunks(8, 2, 0, 6);\r
   end;\r
 \r
  procedure dec_0(ix,iy:integer);\r