fixed structures being farmable in a small area + started working on mining

This commit is contained in:
Alexandre 2024-07-16 22:59:19 +02:00
parent 17725892fe
commit 5e7a78be82
6 changed files with 126 additions and 4 deletions

BIN
a.out

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -37,9 +37,11 @@ let coin_magnet_dist = 1. ;;
(* -------------------------------------------------------------------------------------------------------- *)
let structure_1_frequency = 2000 ;;
let structure_1_frequency = 2500 ;;
(* avg number of chunk generation required before encountering a structure of type 1 *)
let structure_2_frequency = 2500 ;;
(* -------------------------------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------------------------------- *)
(* -------------------------------------------------------------------------------------------------------- *)
@ -57,6 +59,8 @@ ocamlfind ocamlopt -linkpkg -package unix -linkpkg -package graphics -thread -pa
*)
type chemical = Iron | Copper | Tungsten | Gold | Diamond | Carbon | Steel | Stackyte ;;
(* ------------------------------------------------------------- *)
(* ------------------------------------------------------------- *)
@ -1118,13 +1122,15 @@ let render_chunks hash mem camx camy camz ch_distance screen_wd screen_ht fov =
let structure_1_spawnable opt = match opt with
| None -> true
| Some k when k <= 0 && k <> -1 -> true
| Some k when k <= 0 && k > -1 -> true
| _ -> false ;;
let generate_structure_1 hash mem ch_x ch_y ch_z =
(* structure 1 is 5x5x5 chunks around the center *)
(* iterating on the edge of render distance field to prevent structure popping out of nowhere *)
let spawn_structure chx chy chz =
Stdlib.print_endline "1";
(*
par invariant global, Hashtbl.find_opt hash (chx, chy, chz) = None
*)
@ -1225,6 +1231,121 @@ let generate_structure_1 hash mem ch_x ch_y ch_z =
done
done ;;
let structure_2_spawnable opt = match opt with
| None -> true
| Some k when k <= 0 && k > -2 -> true
| _ -> false ;;
let generate_structure_2 hash mem ch_x ch_y ch_z =
(* structure 1 is 5x5x5 chunks around the center *)
(* iterating on the edge of render distance field to prevent structure popping out of nowhere *)
let spawn_structure chx chy chz =
Stdlib.print_endline "2";
(*
par invariant global, Hashtbl.find_opt hash (chx, chy, chz) = None
*)
let empty = dyn_create {flag = "struct_2" ; cube = create_cube 0 0 0 1; red = 33; green = 33; blue = 22} in
(*dyn_append dyna {cube = create_cube (chunk_size*chx) (chunk_size*chy) (chunk_size*chz) chunk_size; red = 250; green = 32; blue = 32};*)
for w = -2 to 2 do
for h = -2 to 2 do
for d = -2 to 2 do
if abs w = 2 || (abs h = 2 && w*d <> 0) || abs d = 2 then begin
let filled = dyn_create {flag = "struct_2" ; cube = create_cube 0 0 0 1; red = 33; green = 33; blue = 22} in
dyn_append filled {flag = "struct_2" ; cube = create_cube ((chx+w)*chunk_size) ((chy+h)*chunk_size) ((chz+d)*chunk_size) chunk_size; red = 128; green = 250; blue = 64};
Hashtbl.add hash (chx+w, chy+h, chz+d) filled;
end
else if w = 0 && h = 0 && d = 0 then begin
let filled = dyn_create {flag = "10" ; cube = create_cube 0 0 0 1; red = 33; green = 33; blue = 22} in
for i = 0 to chunk_size -1 do
for j = 0 to chunk_size -1 do
for k = 0 to chunk_size -1 do
dyn_append filled {flag = "10" ; cube = create_cube (chx*chunk_size+i) (chy*chunk_size+j) (chz*chunk_size+k) 1; red = 250; green = 250; blue = 64};
done
done
done;
Hashtbl.add hash (chx+w, chy+h, chz+d) filled;
end
else begin
Hashtbl.add hash (chx+w, chy+h, chz+d) empty;
end;
Hashtbl.add mem (chx+w, chy+h, chz+d) 3;
done
done
done;
(*Hashtbl.add mem (chx, chy, chz) 2;
Hashtbl.add hash (chx, chy, chz) dyna;*)
(*Printf.printf "Added S1 at (%d, %d, %d)\n" (chx*chunk_size) (chy*chunk_size) (chz*chunk_size);
Printf.printf "----------- (%d, %d, %d)" chx chy chz;
Stdlib.print_endline " "*)
in
for w = -(chunk_dist+3) to (chunk_dist+3) do
for h = -(chunk_dist+3) to (chunk_dist+3) do
if structure_2_spawnable (Hashtbl.find_opt mem (ch_x + w, ch_y + h, ch_z - (chunk_dist+3))) then begin (* if the chunk is valid *)
if (Random.int (structure_2_frequency-1)) = 0 then (* roll a dice *)
spawn_structure (ch_x + w) (ch_y + h) (ch_z - (chunk_dist+3))
else (* failed atempt *)
Hashtbl.add mem (ch_x + w, ch_y + h, ch_z - (chunk_dist+3)) (-2)
end;
done
done;
for w = -(chunk_dist+3) to (chunk_dist+3) do
for h = -(chunk_dist+3) to (chunk_dist+3) do
if structure_2_spawnable (Hashtbl.find_opt mem (ch_x + w, ch_y + h, ch_z + (chunk_dist+3))) then begin
if (Random.int (structure_2_frequency-1)) = 0 then
spawn_structure (ch_x + w) (ch_y + h) (ch_z + (chunk_dist+3))
else
Hashtbl.add mem (ch_x + w, ch_y + h, ch_z + (chunk_dist+3)) (-2)
end
done
done;
for w = -(chunk_dist+3) to (chunk_dist+3) do
for d = -(chunk_dist+3) to (chunk_dist+3) do
if structure_2_spawnable (Hashtbl.find_opt mem (ch_x + w, ch_y - (chunk_dist+3), ch_z + d)) then begin
if (Random.int (structure_2_frequency-1)) = 0 then
spawn_structure (ch_x + w) (ch_y - (chunk_dist+3)) (ch_z + d)
else
Hashtbl.add mem (ch_x + w, ch_y - (chunk_dist+3), ch_z + d) (-2)
end
done
done;
for w = -(chunk_dist+3) to (chunk_dist+3) do
for d = -(chunk_dist+3) to (chunk_dist+3) do
if structure_2_spawnable (Hashtbl.find_opt mem (ch_x + w, ch_y + (chunk_dist+3), ch_z + d)) then begin
if (Random.int (structure_2_frequency-1)) = 0 then
spawn_structure (ch_x + w) (ch_y + (chunk_dist+3)) (ch_z + d)
else
Hashtbl.add mem (ch_x + w, ch_y + (chunk_dist+3), ch_z + d) (-2)
end
done
done;
for h = -(chunk_dist+3) to (chunk_dist+3) do
for d = -(chunk_dist+3) to (chunk_dist+3) do
if structure_2_spawnable (Hashtbl.find_opt mem (ch_x - (chunk_dist+3), ch_y + h, ch_z + d)) then begin
if (Random.int (structure_2_frequency-1)) = 0 then
spawn_structure (ch_x - (chunk_dist+3)) (ch_y + h) (ch_z + d)
else
Hashtbl.add mem (ch_x - (chunk_dist+3), ch_y + h, ch_z + d) (-2)
end
done
done;
for h = -(chunk_dist+3) to (chunk_dist+3) do
for d = -(chunk_dist+3) to (chunk_dist+3) do
if structure_2_spawnable (Hashtbl.find_opt mem (ch_x + (chunk_dist+3), ch_y + h, ch_z + d)) then begin
if (Random.int (structure_2_frequency-1)) = 0 then
spawn_structure (ch_x + (chunk_dist+3)) (ch_y + h) (ch_z + d)
else
Hashtbl.add mem (ch_x + (chunk_dist+3), ch_y + h, ch_z + d) (-2)
end
done
done ;;
let generate_structures hash mem chx chy chz =
generate_structure_1 hash mem chx chy chz ;
generate_structure_2 hash mem chx chy chz ;;
let get1char_plus () =
if key_pressed () then
read_key ()
@ -1273,7 +1394,7 @@ let play_dos laby =
let (cx, cy, cz) = coords_to_chunk_f (-. camera_xyz.x) (-. camera_xyz.y) camera_xyz.z in
ch_x := cx ; ch_y := cy ; ch_z := cz;
generate_structure_1 hash memory !ch_x !ch_y !ch_z;
generate_structures hash memory !ch_x !ch_y !ch_z;
render_chunks hash memory !ch_x !ch_y !ch_z chunk_dist __width__ __height__ fov ;
set_color white;

BIN
display.o

Binary file not shown.

View File

@ -5,3 +5,4 @@
"spawn" : spawn chunk ; always has to be empty for the player to spawn
"struct_N" : solid block for structure N
"terrain" : regular terrain piece, usually white/gray
"<chemical_element>" : any material, quantity granted is always 1