From 45d5263c1b7b20f5fd555c485b1f83237e978241 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Thu, 9 Mar 2017 00:35:20 +0300 Subject: [PATCH] Rewrite ore generation --- BUGS | 2 +- src/randoms.mpsrc | 10 +++- src/worldgen.mpsrc | 130 ++++++++++++--------------------------------- 3 files changed, 44 insertions(+), 98 deletions(-) diff --git a/BUGS b/BUGS index 932bedc..d0d381e 100644 --- a/BUGS +++ b/BUGS @@ -20,7 +20,7 @@ Иногда вместо травы генерируется грязь. Перепроверить генерацию предметов в вокровищницах Починить спавнеры -Уголь встречается на поверхности реже чем железо ++ Уголь встречается на поверхности реже чем железо Починит установку блока при прыжке Перепроверить рост деревьев + Печь не светится когда работает diff --git a/src/randoms.mpsrc b/src/randoms.mpsrc index 4720898..d4e8dea 100644 --- a/src/randoms.mpsrc +++ b/src/randoms.mpsrc @@ -6,6 +6,9 @@ interface function rnd(max:integer):integer;//Возвращает число от 0 до max function rnd_pr(pr,p1,p2:integer):integer; + (* Возвращает true с вероятностью x/y *) + function RandomBoolean(x, y : Integer) : Boolean; + implementation var next:integer; @@ -34,4 +37,9 @@ implementation if pr>=rnd(101) then rnd_pr:=p1; else rnd_pr:=p2; end; -end. \ No newline at end of file + function RandomBoolean(x, y : Integer) : Boolean; + begin + RandomBoolean := rnd(y) <= x; + end; + +end. diff --git a/src/worldgen.mpsrc b/src/worldgen.mpsrc index ca52210..d49159a 100644 --- a/src/worldgen.mpsrc +++ b/src/worldgen.mpsrc @@ -407,104 +407,42 @@ procedure create_bonus_chest(chx,chy:integer); end; end; + // Генерирует чанки руды в камне типа block с максимальной вероятность percent процентов + // Начиная с уровня starty и размером не более maxsize*maxsize + // С ростом глубины вероятность растёт + procedure GenOreChunks(block, percent, starty, maxsize : Integer); + const + preq = 100000; + var + x, y, i, j : Integer; + begin + for x := 0 to MAP_W do + for y := starty to MAP_H do + if RandomBoolean(y * percent * preq / MAP_H, 100 * preq) then + for i := 0 to rnd(maxsize) - 1 do + for j := 0 to rnd(maxsize) - 1 do + if RandomBoolean(50, 100) and (GetMap(x + i, y + j) = 3) then + SetMap(block, x + i, y + j); + end; + procedure genallrudes; - var - ix,iy,iu,iv:integer; begin - //алмазы - for ix:=0 to 255 do - for iy:=111 to 127 do - if (rnd_pr(1,1,0)=1) then - begin - for iu:=0 to 2 do - for iv:=0 to 2 do - if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(10,19,getmap(ix+iu,iy+iv)),ix+iu,iy+iv); - ix:=ix+3; - end; - - //золото - for ix:=0 to 255 do - for iy:=95 to 127 do - if (rnd_pr(3,1,0)=1) then - begin - for iu:=0 to 2 do - for iv:=0 to 2 do - if (ix+iu<255) and (iy+iv<126) then - if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(20,16,getmap(ix+iu,iy+iv)),ix+iu,iy+iv); - ix:=ix+3; - end; - - //лазурит - for ix:=0 to 255 do - for iy:=107 to 127 do - if (rnd_pr(2,1,0)=1) then - begin - for iu:=0 to 2 do - for iv:=0 to 2 do - if (ix+iu<255) and (iy+iv<126) then - if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(40,54,getmap(ix+iu,iy+iv)),ix+iu,iy+iv); - ix:=ix+3; - end; - - //редстоун - for ix:=0 to 255 do - for iy:=107 to 127 do - if (rnd_pr(2,1,0)=1) then - begin - for iu:=0 to 2 do - for iv:=0 to 2 do - if (ix+iu<255) and (iy+iv<126) then - if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(40,20,getmap(ix+iu,iy+iv)),ix+iu,iy+iv); - ix:=ix+3; - end; - - //железо - for ix:=0 to 255 do - for iy:=63 to 127 do - if (rnd_pr(4,1,0)=1) then - begin - for iu:=0 to 2 do - for iv:=0 to 2 do - if (ix+iu<255) and (iy+iv<126) then - if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(40,17,getmap(ix+iu,iy+iv)),ix+iu,iy+iv); - ix:=ix+3; - end; - - //уголь - for ix:=0 to 255 do - for iy:=0 to 127 do - if (rnd_pr(6,1,0)=1) then - begin - for iu:=0 to 2 do - for iv:=0 to 2 do - if (ix+iu<255) and (iy+iv<126) then - if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(50,18,getmap(ix+iu,iy+iv)),ix+iu,iy+iv); - ix:=ix+3; - end; - - //гравий - for ix:=0 to 255 do - for iy:=63 to 126 do - if (rnd_pr(2,1,0)=1) then - begin - for iu:=0 to rnd(5) do - for iv:=0 to rnd(5) do - if (ix+iu<255) and (iy+iv<126) then - if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(90,8,getmap(ix+iu,iy+iv)),ix+iu,iy+iv); - ix:=ix+3; - end; - - //земля на камне - for ix:=0 to 255 do - for iy:=63 to 127 do - if (rnd_pr(1,1,0)=1) then - begin - for iu:=0 to rnd(5) do - for iv:=0 to rnd(5) do - if (ix+iu<255) and (iy+iv<126) then - if getmap(ix+iu,iy+iv)=3 then setmap(rnd_pr(90,1,getmap(ix+iu,iy+iv)),ix+iu,iy+iv); - ix:=ix+3; - end; + (* Алмазная руда *) + GenOreChunks(19, 1, 111, 3); + (* Золотая руда *) + GenOreChunks(16, 2, 95, 3); + (* Лазуритовая руда *) + GenOreChunks(54, 2, 107, 3); + (* Красная руда *) + GenOreChunks(20, 2, 107, 3); + (* Железная руда *) + GenOreChunks(17, 3, 63, 3); + (* Угольная руда *) + GenOreChunks(18, 4, 0, 6); + (* Гравий *) + GenOreChunks(8, 2, 0, 6); + (* Грязь *) + GenOreChunks(8, 2, 0, 6); end; procedure dec_0(ix,iy:integer); -- 2.29.2