-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic -- -- GNU General Public Licence (version 3 or later) with core, ui, resource, equipment, unit, construction, chad, effect; package body world is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ view_reach : constant integer := 96; landmark_limit : constant integer := 360; location_limit : constant integer := 60; construction_limit : constant natural := 120; equipment_limit : constant natural := 600; unit_limit : constant natural := 600; chad_limit : constant natural := 8; earth : core.sprite; --~water : core.sprite; dark : core.sprite; border_upper : core.sprite; border_lower : core.sprite; border_left : core.sprite; border_right : core.sprite; corner_upper_left : core.sprite; corner_upper_right : core.sprite; corner_lower_left : core.sprite; corner_lower_right : core.sprite; ------------------------------------------------------------------------------------------ procedure configure is begin core.echo (core.comment, "Configuring world components..."); -- earth := core.import_sprite (core.folder & "/game/world/terrain/earth.png", 1, 1); --~water := core.import_sprite (core.folder & "/game/world/terrain/water.png", 1, 1); dark := core.import_sprite (core.folder & "/game/world/dark.png", 1, 1); border_upper := core.import_sprite (core.folder & "/game/world/frame/border_upper.png", 1, 1); border_lower := core.import_sprite (core.folder & "/game/world/frame/border_lower.png", 1, 1); border_left := core.import_sprite (core.folder & "/game/world/frame/border_left.png", 1, 1); border_right := core.import_sprite (core.folder & "/game/world/frame/border_right.png", 1, 1); corner_upper_left := core.import_sprite (core.folder & "/game/world/frame/corner_upper_left.png", 1, 1); corner_upper_right := core.import_sprite (core.folder & "/game/world/frame/corner_upper_right.png", 1, 1); corner_lower_left := core.import_sprite (core.folder & "/game/world/frame/corner_lower_left.png", 1, 1); corner_lower_right := core.import_sprite (core.folder & "/game/world/frame/corner_lower_right.png", 1, 1); -- for index in landmark_index loop landmarks (index) := core.import_sprite (file_path => core.folder & "/game/world/landmark/" & core.lowercase (index'image) & ".png", frames => landmark_trait (index).frames, states => 1); end loop; -- for index in location_index loop locations (index) := core.import_sprite (file_path => core.folder & "/game/world/location/" & core.lowercase (index'image) & ".png", frames => location_trait (index).frames, states => location_trait (index).states); end loop; end configure; ------------------------------------------------------------------------------------------ procedure make (index : in biome; width, height : in natural) is begin core.echo (core.comment, "-- Procedurally generating new map..."); -- core.echo (core.comment, "-- -- Map type : " & index'image); core.echo (core.comment, "-- -- Map width :" & width'image); core.echo (core.comment, "-- -- Map height :" & height'image); core.echo (core.comment, "-- -- Landmark count :" & landmark_limit'image); -- map.kind := index; map.width := width; map.height := height; -- map.earth := new integer_matrix (0 .. map.width - 1, 0 .. map.height - 1); --~map.water := new integer_matrix (0 .. map.width - 1, 0 .. map.height - 1); --~map.is_water := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1); map.clips := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1); map.views := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1); map.landmarks := new entity_array (1 .. landmark_limit); map.locations := new entity_array (1 .. location_limit); map.constructions := new entity_array (1 .. construction_limit); map.equipments := new entity_array (1 .. equipment_limit); map.units := new entity_array (1 .. unit_limit); map.chads := new entity_array (1 .. chad_limit); map.chad_data := new chad.data_list (1 .. chad_limit); -- for x in 0 .. width - 1 loop for y in 0 .. height - 1 loop map.earth (x, y) := (if core.random (0, 23) < 19 then core.random (0, 11) else core.random (0, 23)); --~map.is_water (x, y) := (if x > 9 and x < width - 9 and y > 9 and y < height - 9 then core.random (0, 1023) = 0 else false); --~map.water (x, y) := (if map.is_water (x, y) then core.random (0, 7) else 0); map.clips (x, y) := false; map.views (x, y) := false; end loop; end loop; -- --~for x in 9 .. width - 9 loop --~for y in 9 .. height - 9 loop --~if map.is_water (x, y) then --~for extend_x in -3 .. 3 loop --~for extend_y in -2 .. 2 loop --~map.is_water (extend_x + x, extend_y + y) := core.random (0, 3) /= 0; --~map.water (extend_x + x, extend_y + y) := (if map.is_water (extend_x + x, extend_y + y) then core.random (0, 7) else 0); --~end loop; --~end loop; --~end if; --~end loop; --~end loop; -- for index in 1 .. landmark_limit loop map.landmarks (index).index := core.random (0, landmark_count - 1); map.landmarks (index).x := core.random (6, map.width - 6); map.landmarks (index).y := core.random (6, map.height - 6); -- if landmark_trait (landmark_index'val (map.landmarks (index).index)).clip then declare reach_x : constant natural := landmarks (landmark_index'val (map.landmarks (index).index)).width / core.base; reach_y : constant natural := landmarks (landmark_index'val (map.landmarks (index).index)).height / core.base; begin for x in 0 .. reach_x - 1 loop for y in 0 .. reach_y - 1 loop map.clips (map.landmarks (index).x + x, map.landmarks (index).y + y) := true; end loop; end loop; end; end if; end loop; -- for index in 1 .. location_limit loop map.locations (index).index := core.random (0, location_count - 1); map.locations (index).x := core.random (6, map.width - 6); map.locations (index).y := core.random (6, map.height - 6); -- if location_trait (location_index'val (map.locations (index).index)).clip then declare reach_x : constant natural := locations (location_index'val (map.locations (index).index)).width / core.base; reach_y : constant natural := locations (location_index'val (map.locations (index).index)).height / core.base; begin for x in 0 .. reach_x - 1 loop for y in 0 .. reach_y - 1 loop map.clips (map.locations (index).x + x, map.locations (index).y + y) := true; end loop; end loop; end; end if; end loop; -- for index in 1 .. construction_limit loop map.constructions (index).index := core.random (0, construction.count - 1); map.constructions (index).x := core.random (6, map.width - 6); map.constructions (index).y := core.random (6, map.height - 6); -- declare reach_x : constant natural := construction.sprite (construction.enumeration'val (map.constructions (index).index)).width / core.base; reach_y : constant natural := construction.sprite (construction.enumeration'val (map.constructions (index).index)).height / core.base; begin for x in 0 .. reach_x - 1 loop for y in 0 .. reach_y - 1 loop map.clips (map.constructions (index).x + x, map.constructions (index).y + y) := true; end loop; end loop; end; end loop; -- for index in 1 .. equipment_limit loop map.equipments (index).index := core.random (0, equipment.count - 1); map.equipments (index).x := core.random (0, map.width - 1); map.equipments (index).y := core.random (0, map.height - 1); end loop; -- for index in 1 .. unit_limit loop map.units (index).index := core.random (0, unit.count - 1); map.units (index).x := core.random (0, map.width - 1); map.units (index).y := core.random (0, map.height - 1); -- map.clips (map.units (index).x, map.units (index).y) := true; end loop; -- core.echo (core.success, "Finished procedurally generating new map."); end make; ------------------------------------------------------------------------------------------ procedure draw is offset : core.vector := ((core.window_width - core.base) / 2, (core.window_height - core.base) / 2); begin for vertical in 0 .. map.height - 1 loop exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height; -- for horizontal in 0 .. map.width - 1 loop exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width; -- if not ((horizontal - core.camera.x) ** 2 + (vertical - core.camera.y) ** 2 > view_reach * 2) then map.views (horizontal, vertical) := true; end if; end loop; end loop; -- --~declare factor : constant integer := core.base * core.zoom; --~x : constant integer := factor * (-1- core.camera.x) + offset.x; --~y : constant integer := factor * (-1- core.camera.y) + offset.y; --~width : constant integer := core.base * (map.width + 2); --~height : constant integer := core.base * (map.height + 2); --~begin --~core.draw_horizontally (border_upper, x + factor, y, width - 2 * factor, core.zoom); --~core.draw_horizontally (border_lower, x + factor, y + height - factor, width - 2 * factor, core.zoom); --~core.draw_vertically (border_left, x, y + factor, height - 2 * factor, core.zoom); --~core.draw_vertically (border_right, x + width - factor, y + factor, height - 2 * factor, core.zoom); --~-- --~core.draw (corner_upper_left, x, y, core.zoom); --~core.draw (corner_upper_right, x + width - core.base, y, core.zoom); --~core.draw (corner_lower_left, x, y + height - core.base, core.zoom); --~core.draw (corner_lower_right, x + width - core.base, y + height - core.base, core.zoom); --~end; -- for vertical in 0 .. map.height - 1 loop exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height; -- for horizontal in 0 .. map.width - 1 loop exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width; -- if map.views (horizontal, vertical) then core.draw (data => earth, x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom, y => offset.y + (vertical - core.camera.y) * core.base * core.zoom, u => core.base * biome'pos (map.kind) * 4, v => core.base * map.earth (horizontal, vertical), width => core.base, height => core.base); --~if map.is_water (horizontal, vertical) then --~core.draw (data => water, --~x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom, --~y => offset.y + (vertical - core.camera.y) * core.base * core.zoom, --~u => core.base * biome'pos (map.kind) * 4 + (core.animation_time mod 4) * core.base, --~v => core.base * map.water (horizontal, vertical), --~width => core.base, --~height => core.base); --~end if; --~-- --~if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom - 6 --~and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom + 6 --~and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom - 6 --~and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom + 6 --~and core.cursor_mode = 1 --~and not ui.prioritize then --~core.camera.x := horizontal; --~core.camera.y := vertical; --~core.cursor_mode := 0; --~end if; end if; end loop; end loop; -- for index in 1 .. landmark_limit loop if map.views (map.landmarks (index).x, map.landmarks (index).y) then core.draw (data => landmarks (landmark_index'val (map.landmarks (index).index)), x => offset.x + (map.landmarks (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.landmarks (index).y - core.camera.y) * core.base * core.zoom); if core.cursor_inside (x => offset.x + (map.landmarks (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.landmarks (index).y - core.camera.y) * core.base * core.zoom, width => landmarks (landmark_index'val (map.landmarks (index).index)).width, height => landmarks (landmark_index'val (map.landmarks (index).index)).height) and core.cursor_mode = 2 and not ui.prioritize then core.write_text_box (landmark_trait (landmark_index'val (map.landmarks (index).index)).name); end if; end if; end loop; -- for index in 1 .. location_limit loop if map.views (map.locations (index).x, map.locations (index).y) then core.draw (data => locations (location_index'val (map.locations (index).index)), x => offset.x + (map.locations (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.locations (index).y - core.camera.y) * core.base * core.zoom); if core.cursor_inside (x => offset.x + (map.locations (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.locations (index).y - core.camera.y) * core.base * core.zoom, width => locations (location_index'val (map.locations (index).index)).width, height => locations (location_index'val (map.locations (index).index)).height) and core.cursor_mode = 2 and not ui.prioritize then core.write_text_box (location_trait (location_index'val (map.locations (index).index)).name); end if; end if; end loop; -- for index in 1 .. construction_limit loop if map.views (map.constructions (index).x, map.constructions (index).y) then construction.draw_plus (construction.enumeration'val (map.constructions (index).index), offset.x + (map.constructions (index).x - core.camera.x) * core.base * core.zoom, offset.y + (map.constructions (index).y - core.camera.y) * core.base * core.zoom); end if; end loop; -- for index in 1 .. equipment_limit loop if map.views (map.equipments (index).x, map.equipments (index).y) then equipment.draw_plus (equipment.enumeration'val (map.equipments (index).index), core.idle, offset.x + (map.equipments (index).x - core.camera.x) * core.base * core.zoom, offset.y + (map.equipments (index).y - core.camera.y) * core.base * core.zoom); end if; -- if map.equipments (index).x = core.camera.x and map.equipments (index).y = core.camera.y and core.signal_code'pos (core.signal_mode) = core.signal_code'pos (core.signal_e) then if chad.take_equipment_item (map.chad_data (1), equipment.enumeration'val (map.equipments (index).index)) then map.equipments (index).index := equipment.enumeration'pos (equipment.none); end if; end if; end loop; -- for index in 1 .. unit_limit loop if map.views (map.units (index).x, map.units (index).y) then unit.draw_full (map.units (index).index, offset.x + (map.units (index).x - core.camera.x) * core.base * core.zoom, offset.y + (map.units (index).y - core.camera.y) * core.base * core.zoom); end if; end loop; -- for vertical in 0 .. map.height - 1 loop exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height; -- for horizontal in 0 .. map.width - 1 loop exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width; -- if (horizontal - core.camera.x) ** 2 + (vertical - core.camera.y) ** 2 > view_reach then core.draw (data => dark, x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom, y => offset.y + (vertical - core.camera.y) * core.base * core.zoom); end if; end loop; end loop; end draw; ------------------------------------------------------------------------------------------ procedure mapshot (file_path : in string) is begin core.create_image (map.width, map.height); -- for vertical in 0 .. map.height - 1 loop for horizontal in 0 .. map.width - 1 loop core.render_image (data => earth, x => horizontal * core.base, y => vertical * core.base, u => core.base * biome'pos (map.kind) * 4, v => core.base * map.earth (horizontal, vertical), width => core.base, height => core.base); end loop; end loop; -- for index in 1 .. landmark_limit loop core.render_image (data => landmarks (landmark_index'val (map.landmarks (index).index)), x => map.landmarks (index).x * core.base, y => map.landmarks (index).y * core.base, u => 0, v => 0, width => landmarks (landmark_index'val (map.landmarks (index).index)).width, height => landmarks (landmark_index'val (map.landmarks (index).index)).height); end loop; -- for index in 1 .. location_limit loop core.render_image (data => locations (location_index'val (map.locations (index).index)), x => map.locations (index).x * core.base, y => map.locations (index).y * core.base, u => 0, v => 0, width => locations (location_index'val (map.locations (index).index)).width, height => locations (location_index'val (map.locations (index).index)).height); end loop; -- for index in 1 .. construction_limit loop core.render_image (data => construction.sprite (construction.enumeration'val (map.constructions (index).index)), x => map.constructions (index).x * core.base, y => map.constructions (index).y * core.base, u => 0, v => 0, width => construction.sprite (construction.enumeration'val (map.constructions (index).index)).width, height => construction.sprite (construction.enumeration'val (map.constructions (index).index)).height); end loop; -- for index in 1 .. equipment_limit loop core.render_image (data => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)), x => map.equipments (index).x * core.base, y => map.equipments (index).y * core.base, u => 0, v => 0, width => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)).width, height => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)).height); end loop; -- core.export_image (file_path); -- core.echo (core.success, "Exported current world mapshot."); -- core.dash; end mapshot; ------------------------------------------------------------------------------------------ procedure reveal_map is begin for x in 0 .. map.width - 1 loop for y in 0 .. map.height - 1 loop map.views (x, y) := true; end loop; end loop; end reveal_map; ------------------------------------------------------------------------------------------ procedure add_chad (data : in chad.data; entity : in entity_trait) is begin map.chads (1) := entity; map.chad_data (1) := data; end add_chad; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ end world;