diff --git a/a.out b/a.out index a69a16b..6e356d8 100755 Binary files a/a.out and b/a.out differ diff --git a/display.cmi b/display.cmi index 9f7b53f..2c52df7 100644 Binary files a/display.cmi and b/display.cmi differ diff --git a/display.cmx b/display.cmx index 6149333..d3327c9 100644 Binary files a/display.cmx and b/display.cmx differ diff --git a/display.ml b/display.ml index 7b81979..8e0c657 100644 --- a/display.ml +++ b/display.ml @@ -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; diff --git a/display.o b/display.o index 6ae94b7..c34920e 100644 Binary files a/display.o and b/display.o differ diff --git a/flag_list.txt b/flag_list.txt index 000412e..0f435f7 100644 --- a/flag_list.txt +++ b/flag_list.txt @@ -4,4 +4,5 @@ "" : coin with its value "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 \ No newline at end of file +"terrain" : regular terrain piece, usually white/gray +"" : any material, quantity granted is always 1 \ No newline at end of file