-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic -- -- GNU General Public Licence (version 3 or later) package body world is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ lake_count : constant natural := 6; target : core.vector := (-1, -1); 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; arrow_target : core.sprite; arrow_upper : core.sprite; arrow_lower : core.sprite; arrow_left : core.sprite; arrow_right : core.sprite; arrow_upper_left : core.sprite; arrow_upper_right : core.sprite; arrow_lower_left : core.sprite; arrow_lower_right : core.sprite; ------------------------------------------------------------------------------------------ procedure generate_lake (x, y : in integer; size : in natural); procedure compute_world_visibility_grid (offset : in core.vector); procedure compute_world_frame (offset : in core.vector); procedure draw_tiles (offset, view_from, view_to : in core.vector); procedure draw_landmarks (offset, view_from, view_to : in core.vector); procedure draw_locations (offset, view_from, view_to : in core.vector); procedure draw_constructions (offset, view_from, view_to : in core.vector); procedure draw_equipments (offset, view_from, view_to : in core.vector); procedure draw_units (offset, view_from, view_to : in core.vector); procedure draw_chads (offset, view_from, view_to : in core.vector); procedure draw_alternative (offset, view_from, view_to : in core.vector); procedure compute_earth_to_water_transition; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ procedure configure is begin core.echo (core.comment, "Configuring world components..."); -- for index in biome.enumeration loop biome.tiles (index) := core.import_sprite (core.folder & "/game/biome/" & core.lowercase (index'image) & ".png", 4, 1); end loop; -- 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); arrow_target := core.import_sprite (core.folder & "/game/world/arrow/target.png", 1, 1); arrow_upper := core.import_sprite (core.folder & "/game/world/arrow/upper.png", 1, 1); arrow_lower := core.import_sprite (core.folder & "/game/world/arrow/lower.png", 1, 1); arrow_left := core.import_sprite (core.folder & "/game/world/arrow/left.png", 1, 1); arrow_right := core.import_sprite (core.folder & "/game/world/arrow/right.png", 1, 1); arrow_upper_left := core.import_sprite (core.folder & "/game/world/arrow/upper_left.png", 1, 1); arrow_upper_right := core.import_sprite (core.folder & "/game/world/arrow/upper_right.png", 1, 1); arrow_lower_left := core.import_sprite (core.folder & "/game/world/arrow/lower_left.png", 1, 1); arrow_lower_right := core.import_sprite (core.folder & "/game/world/arrow/lower_right.png", 1, 1); -- for index in landmark.enumeration loop landmark.game (index) := core.import_sprite (file_path => core.folder & "/game/landmark/" & core.lowercase (index'image) & ".png", frames => landmark.description (index).frames, states => 1); end loop; -- for index in location.enumeration loop location.game (index) := core.import_sprite (file_path => core.folder & "/game/location/" & core.lowercase (index'image) & ".png", frames => location.description (index).frames, states => 2); end loop; end configure; ------------------------------------------------------------------------------------------ function equipment_valid (data : in equipment.enumeration) return boolean is begin return equipment.enumeration'pos (data) /= equipment.error; end equipment_valid; ------------------------------------------------------------------------------------------ function random_landmark return landmark.information is this : landmark.information; begin this.index := landmark.enumeration'val (core.random (0, landmark.count - 1)); <> this.x := core.random (6, map.width - 6); this.y := core.random (6, map.height - 6); -- if map.clips (this.x, this.y) then goto repeat_landmark_generation; end if; -- return this; end random_landmark; ------------------------------------------------------------------------------------------ function random_location return location.information is this : location.information; begin this.index := location.enumeration'val (core.random (0, location.count - 1)); this.used := false; <> this.x := core.random (6, map.width - 6); this.y := core.random (6, map.height - 6); -- if map.clips (this.x, this.y) then goto repeat_location_generation; end if; -- return this; end random_location; ------------------------------------------------------------------------------------------ function random_construction return construction.information is this : construction.information; begin this.index := construction.enumeration'val (core.random (0, construction.count - 1)); <> this.x := core.random (6, map.width - 6); this.y := core.random (6, map.height - 6); -- if map.clips (this.x, this.y) then goto repeat_construction_generation; end if; -- return this; end random_construction; ------------------------------------------------------------------------------------------ function random_equipment return equipment.information is this : equipment.information; begin this.index := equipment.enumeration'val (core.random (0, equipment.count - 1)); <> this.x := core.random (0, map.width - 1); this.y := core.random (0, map.height - 1); -- if map.clips (this.x, this.y) then goto repeat_equipment_generation; end if; -- return this; end random_equipment; ------------------------------------------------------------------------------------------ function random_unit return unit.information is this : unit.information; begin this.index := unit.enumeration'val (core.random (1, unit.count - 1)); -- none this.count := core.random (1, 10); this.enemy := true; <> this.x := core.random (0, map.width - 1); this.y := core.random (0, map.height - 1); -- if map.clips (this.x, this.y) then goto repeat_unit_generation; end if; -- return this; end random_unit; ------------------------------------------------------------------------------------------ procedure insert_landmark (data : in landmark.information) is this : constant natural := map.landmark_count.value + 1; begin core.echo_when (map.landmark_count.value = map.landmark_count.limit, core.failure, "Can't add new landmark, limit reached."); core.increment (map.landmark_count.value); -- map.landmarks (this) := data; -- if landmark.description (map.landmarks (this).index).clip then for x in 0 .. landmark.game (map.landmarks (this).index).width / core.base - 1 loop for y in 0 .. landmark.game (map.landmarks (this).index).height / core.base - 1 loop map.clips (map.landmarks (this).x + x, map.landmarks (this).y + y) := true; end loop; end loop; end if; end insert_landmark; ------------------------------------------------------------------------------------------ procedure insert_location (data : in location.information) is this : constant natural := map.location_count.value + 1; begin core.echo_when (map.location_count.value = map.location_count.limit, core.failure, "Can't add new location, limit reached."); core.increment (map.location_count.value); -- map.locations (this) := data; -- if location.description (map.locations (this).index).clip then for x in 0 .. location.game (map.locations (this).index).width / core.base - 1 loop for y in 0 .. location.game (map.locations (this).index).height / core.base - 1 loop map.clips (map.locations (this).x + x, map.locations (this).y + y) := true; end loop; end loop; end if; end insert_location; ------------------------------------------------------------------------------------------ procedure insert_construction (data : in construction.information) is this : constant natural := map.construction_count.value + 1; begin core.echo_when (map.construction_count.value = map.construction_count.limit, core.failure, "Can't add new construction, limit reached."); core.increment (map.construction_count.value); -- map.constructions (map.construction_count.value) := data; -- declare reach_x : constant natural := construction.game (map.constructions (this).index).width / core.base; reach_y : constant natural := construction.game (map.constructions (this).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 (this).x + x, map.constructions (this).y + y) := true; end loop; end loop; end; end insert_construction; ------------------------------------------------------------------------------------------ procedure insert_equipment (data : in equipment.information) is begin core.echo_when (map.equipment_count.value = map.equipment_count.limit, core.failure, "Can't add new equipment, limit reached."); core.increment (map.equipment_count.value); -- map.equipments (map.equipment_count.value) := data; end insert_equipment; ------------------------------------------------------------------------------------------ procedure insert_unit (data : in unit.information) is begin core.echo_when (map.unit_count.value = map.unit_count.limit, core.failure, "Can't add new unit, limit reached."); core.increment (map.unit_count.value); -- map.units (map.unit_count.value) := data; end insert_unit; ------------------------------------------------------------------------------------------ procedure insert_chad (data : in chad.information) is begin core.echo_when (map.chad_count.value = map.chad_count.limit, core.failure, "Can't add new chad, limit reached."); core.increment (map.chad_count.value); -- map.chads (map.chad_count.value) := data; end insert_chad; ------------------------------------------------------------------------------------------ procedure draw_landmark (data : in landmark.enumeration; x, y, factor : in integer) is begin end draw_landmark; ------------------------------------------------------------------------------------------ procedure draw_location (data : in location.enumeration; used : in boolean; x, y, factor : in integer) is begin end draw_location; ------------------------------------------------------------------------------------------ procedure draw_construction (data : in construction.enumeration; x, y, factor : in integer) is begin core.draw (construction.game (data), x, y, factor => factor); -- if core.cursor_inside (x, y, construction.game (data).width, construction.game (data).height) and core.cursor_mode = core.cursor_middle core.write_text_box (construction.description (data).name.all); end if; end draw_construction; ------------------------------------------------------------------------------------------ procedure draw_equipment (data : in equipment.enumeration; x, y, factor : in integer) is begin core.draw (equipment.game (data), x, y, state => core.idle, factor => factor); -- if core.cursor_inside (x, y, equipment.game (data).width, equipment.game (data).height) and core.cursor_mode = core.cursor_middle and equipment_valid (data) core.write_text_box (equipment.description (data).name.all); end if; end draw_equipment; ------------------------------------------------------------------------------------------ procedure draw_unit (data : in unit.enumeration; state : in core.animation; x, y, factor : in integer) is begin core.draw (unit.base (unit.description (data).kind), x, y, state => state, factor => factor); -- for kind in equipment.kind loop core.draw (equipment.game (unit.description (data).equipments (kind)), x, y, state => state, factor => factor); end loop; end draw_unit; ------------------------------------------------------------------------------------------ procedure draw_chad (data : in chad.information; state : in core.animation; x, y, factor : in integer) is begin core.draw (chad.game (data.index), x, y, state => state, factor => factor); -- for kind in equipment.kind loop core.draw (equipment.game (data.equipments (kind)), x, y, state => state, factor => factor); end loop; end draw_chad; ------------------------------------------------------------------------------------------ procedure review_unit is data : unit.definition := unit.description (review_unit_data); from : faction.definition := faction.description (data.kind); -- offset : constant integer := 8; more : constant natural := 10; less : constant natural := 5; boxy : constant natural := 3 * ui.monoheight + 2 * more; width : constant integer := chad.view_width + 3 * 2 * core.icon + 2 * offset; height : constant integer := chad.view_height + 8 * core.icon + 2 * core.base + boxy + 2 * offset; begin ui.draw_frame (core.center_x (width), core.center_y (height), width, height); ui.draw_sprite (unit.view (review_unit_data), data.name.all, core.center_x (width) + offset, core.center_y (height) + offset, 0); ui.write (data.name.all, core.center_x (width) + offset + unit.view_width + less, core.center_y (height) + offset + less); -- for index in attribute.enumeration loop ui.draw_icon_and_text (data => attribute.icon (index), text => data.attributes (index)'image, x => core.center_x (width) + offset + unit.view_width + (attribute.enumeration'pos (index) / 2) * 2 * core.icon, y => core.center_y (height) + offset + core.icon + core.icon * (attribute.enumeration'pos (index) mod 2), width => 2 * core.icon); end loop; -- ui.draw_separator (core.center_x (width) + offset, core.center_y (height) + offset + unit.view_height, width - 2 * offset); -- ui.draw_text (text => "Hiring fee:" & data.hiring_fee'image & core.line_feed & "Weekly fee:" & data.weekly_fee'image & core.line_feed & "Battle fee:" & data.battle_fee'image, x => core.center_x (width) + offset, y => core.center_y (height) + offset + unit.view_height + core.base, width => width - 2 * (offset + more), border => more); -- ui.draw_separator (core.center_x (width) + offset, core.center_y (height) + offset + unit.view_height + core.base + boxy, width - 2 * offset); -- for index in equipment.kind loop ui.draw_icon_and_text (data => (if equipment_valid (data.equipments (index)) then equipment.icon (data.equipments (index)) else equipment.slot (index)), text => equipment.description (data.equipments (index)).name.all, x => core.center_x (width) + offset, y => core.center_y (height) + offset + unit.view_height + 2 * core.base + boxy + equipment.kind'pos (index) * (core.icon), width => width - 2 * offset); end loop; end review_unit; ------------------------------------------------------------------------------------------ procedure make (index : in biome.enumeration; width, height, landmark_limit, location_limit, construction_limit, equipment_limit, unit_limit, chad_limit : 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); core.echo (core.comment, "-- -- Location count :" & location_limit'image); core.echo (core.comment, "-- -- Construction count :" & construction_limit'image); core.echo (core.comment, "-- -- Equipment count :" & equipment_limit'image); core.echo (core.comment, "-- -- Unit count :" & unit_limit'image); core.echo (core.comment, "-- -- Chad count :" & chad_limit'image); -- map.kind := index; map.width := width; map.height := height; map.landmark_count := (0, landmark_limit); map.location_count := (0, location_limit); map.construction_count := (0, construction_limit); map.equipment_count := (0, equipment_limit); map.unit_count := (0, unit_limit); map.chad_count := (0, chad_limit); -- map.tiles := new integer_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 landmark.informations (1 .. landmark_limit); map.locations := new location.informations (1 .. location_limit); map.constructions := new construction.informations (1 .. construction_limit); map.equipments := new equipment.informations (1 .. equipment_limit); map.units := new unit.informations (1 .. unit_limit); map.chads := new chad.informations (1 .. chad_limit); -- for x in 0 .. width - 1 loop for y in 0 .. height - 1 loop map.tiles (x, y) := (if core.random (0, 17) > 3 then core.random (0, 5) else core.random (0, 17)); map.clips (x, y) := false; map.views (x, y) := false; end loop; end loop; -- for this in 1 .. lake_count loop generate_lake (x => core.random (23, map.width - 23), y => core.random (23, map.height - 23), size => core.random (7, 19)); end loop; -- compute_earth_to_water_transition; -- for x in 0 .. width - 1 loop for y in 0 .. height - 1 loop if map.tiles (x, y) > 17 then map.clips (x, y) := true; end if; end loop; end loop; -- for index in 1 .. landmark_limit loop insert_landmark (random_landmark); end loop; for index in 1 .. location_limit loop insert_location (random_location); end loop; for index in 1 .. construction_limit loop insert_construction (random_construction); end loop; for index in 1 .. equipment_limit loop insert_equipment (random_equipment); end loop; for index in 1 .. unit_limit loop insert_unit (random_unit); end loop; -- core.echo (core.success, "Finished procedurally generating new map."); end make; ------------------------------------------------------------------------------------------ procedure save (file_name : in string) is file : core.io.file_type; begin core.io.create (file, core.io.out_file, core.folder & "/map/" & file_name); -- core.io.write (file, biome.enumeration'pos (map.kind)); core.io.write (file, map.width); core.io.write (file, map.height); -- core.save_point (file, map.landmark_count); core.save_point (file, map.location_count); core.save_point (file, map.construction_count); core.save_point (file, map.equipment_count); core.save_point (file, map.unit_count); core.save_point (file, map.chad_count); -- for x in 0 .. map.width - 1 loop for y in 0 .. map.height - 1 loop core.io.write (file, map.tiles (x, y)); core.io.write (file, boolean'pos (map.clips (x, y))); core.io.write (file, boolean'pos (map.views (x, y))); end loop; end loop; -- for index in 1 .. map.landmark_count.limit loop core.io.write (file, landmark.enumeration'pos (map.landmarks (index).index)); end loop; for index in 1 .. map.location_count.limit loop core.io.write (file, location.enumeration'pos (map.locations (index).index)); end loop; for index in 1 .. map.construction_count.limit loop core.io.write (file, construction.enumeration'pos (map.constructions (index).index)); end loop; for index in 1 .. map.equipment_count.limit loop core.io.write (file, equipment.enumeration'pos (map.equipments (index).index)); end loop; for index in 1 .. map.unit_count.limit loop core.io.write (file, unit.enumeration'pos (map.units (index).index)); end loop; -- for index in 1 .. map.location_count.limit loop core.io.write (file, boolean'pos (map.locations (index).used)); end loop; for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).count); end loop; for index in 1 .. map.unit_count.limit loop core.io.write (file, boolean'pos (map.units (index).enemy)); end loop; -- for index in 1 .. map.landmark_count.limit loop core.io.write (file, map.landmarks (index).x); end loop; for index in 1 .. map.landmark_count.limit loop core.io.write (file, map.landmarks (index).y); end loop; for index in 1 .. map.location_count.limit loop core.io.write (file, map.locations (index).x); end loop; for index in 1 .. map.location_count.limit loop core.io.write (file, map.locations (index).y); end loop; for index in 1 .. map.construction_count.limit loop core.io.write (file, map.constructions (index).x); end loop; for index in 1 .. map.construction_count.limit loop core.io.write (file, map.constructions (index).y); end loop; for index in 1 .. map.equipment_count.limit loop core.io.write (file, map.equipments (index).x); end loop; for index in 1 .. map.equipment_count.limit loop core.io.write (file, map.equipments (index).y); end loop; for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).x); end loop; for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).y); end loop; -- core.io.write (file, chad.enumeration'pos (map.chads (1).index)); core.io.write (file, core.animation'pos (map.chads (1).state)); core.io.write (file, map.chads (1).x); core.io.write (file, map.chads (1).y); -- core.save_point (file, map.chads (1).health); core.save_point (file, map.chads (1).mana); core.save_point (file, map.chads (1).movement); -- for index in attribute.enumeration loop core.save_point (file, map.chads (1).attributes (index)); end loop; for index in resource.enumeration loop core.save_point (file, map.chads (1).resources (index)); end loop; for index in material.enumeration loop core.save_point (file, map.chads (1).materials (index)); end loop; -- for index in 0 .. skill.limit - 1 loop core.io.write (file, skill.enumeration'pos (map.chads (1).skills (index).index)); end loop; for index in 0 .. skill.limit - 1 loop core.io.write (file, map.chads (1).skills (index).value); end loop; for index in 0 .. skill.limit - 1 loop core.io.write (file, map.chads (1).skills (index).limit); end loop; -- for kind in equipment.kind loop core.io.write (file, equipment.enumeration'pos (map.chads (1).equipments (kind))); end loop; -- core.io.write (file, map.chads (1).item_count); -- if map.chads (1).item_count > 0 then for index in 0 .. map.chads (1).item_count - 1 loop core.io.write (file, equipment.enumeration'pos (map.chads (1).items (index))); end loop; end if; -- for index in 0 .. unit.limit - 1 loop core.io.write (file, unit.enumeration'pos (map.chads (1).units (index).index)); end loop; for index in 0 .. unit.limit - 1 loop core.io.write (file, map.chads (1).units (index).value); end loop; for index in 0 .. unit.limit - 1 loop core.io.write (file, map.chads (1).units (index).limit); end loop; -- core.io.close (file); -- core.echo (core.success, "Saved current map as '" & file_name & "'."); -- core.dash; end save; ------------------------------------------------------------------------------------------ procedure load (file_name : in string) is file : core.io.file_type; this : integer; begin core.io.open (file, core.io.in_file, core.folder & "/map/" & file_name); -- core.io.read (file, this); map.kind := biome.enumeration'val (this); core.io.read (file, map.width); core.io.read (file, map.height); -- core.load_point (file, map.landmark_count); core.load_point (file, map.location_count); core.load_point (file, map.construction_count); core.load_point (file, map.equipment_count); core.load_point (file, map.unit_count); core.load_point (file, map.chad_count); -- for x in 0 .. map.width - 1 loop for y in 0 .. map.height - 1 loop core.io.read (file, map.tiles (x, y)); core.io.read (file, this); map.clips (x, y) := boolean'val (this); core.io.read (file, this); map.views (x, y) := boolean'val (this); end loop; end loop; -- for index in 1 .. map.landmark_count.limit loop core.io.read (file, this); map.landmarks (index).index := landmark.enumeration'val (this); end loop; for index in 1 .. map.location_count.limit loop core.io.read (file, this); map.locations (index).index := location.enumeration'val (this); end loop; for index in 1 .. map.construction_count.limit loop core.io.read (file, this); map.constructions (index).index := construction.enumeration'val (this); end loop; for index in 1 .. map.equipment_count.limit loop core.io.read (file, this); map.equipments (index).index := equipment.enumeration'val (this); end loop; for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).index := unit.enumeration'val (this); end loop; -- for index in 1 .. map.location_count.limit loop core.io.read (file, this); map.locations (index).used := boolean'val (this); end loop; for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).count := this; end loop; for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).enemy := boolean'val (this); end loop; -- for index in 1 .. map.landmark_count.limit loop core.io.read (file, map.landmarks (index).x); end loop; for index in 1 .. map.landmark_count.limit loop core.io.read (file, map.landmarks (index).y); end loop; for index in 1 .. map.location_count.limit loop core.io.read (file, map.locations (index).x); end loop; for index in 1 .. map.location_count.limit loop core.io.read (file, map.locations (index).y); end loop; for index in 1 .. map.construction_count.limit loop core.io.read (file, map.constructions (index).x); end loop; for index in 1 .. map.construction_count.limit loop core.io.read (file, map.constructions (index).y); end loop; for index in 1 .. map.equipment_count.limit loop core.io.read (file, map.equipments (index).x); end loop; for index in 1 .. map.equipment_count.limit loop core.io.read (file, map.equipments (index).y); end loop; for index in 1 .. map.unit_count.limit loop core.io.read (file, map.units (index).x); end loop; for index in 1 .. map.unit_count.limit loop core.io.read (file, map.units (index).y); end loop; -- core.io.read (file, this); map.chads (1).index := chad.enumeration'val (this); core.io.read (file, this); map.chads (1).state := core.animation'val (this); core.io.read (file, map.chads (1).x); core.io.read (file, map.chads (1).y); -- core.load_point (file, map.chads (1).health); core.load_point (file, map.chads (1).mana); core.load_point (file, map.chads (1).movement); -- for index in attribute.enumeration loop core.load_point (file, map.chads (1).attributes (index)); end loop; for index in resource.enumeration loop core.load_point (file, map.chads (1).resources (index)); end loop; for index in material.enumeration loop core.load_point (file, map.chads (1).materials (index)); end loop; -- for index in 0 .. skill.limit - 1 loop core.io.read (file, this); map.chads (1).skills (index).index := skill.enumeration'val (this); end loop; for index in 0 .. skill.limit - 1 loop core.io.read (file, map.chads (1).skills (index).value); end loop; for index in 0 .. skill.limit - 1 loop core.io.read (file, map.chads (1).skills (index).limit); end loop; -- for kind in equipment.kind loop core.io.read (file, this); map.chads (1).equipments (kind) := equipment.enumeration'val (this); end loop; -- core.io.read (file, map.chads (1).item_count); -- if map.chads (1).item_count > 0 then for index in 0 .. map.chads (1).item_count - 1 loop core.io.read (file, this); map.chads (1).items (index) := equipment.enumeration'val (this); end loop; end if; -- for index in 0 .. unit.limit - 1 loop core.io.read (file, this); map.chads (1).units (index).index := unit.enumeration'val (this); end loop; for index in 0 .. unit.limit - 1 loop core.io.read (file, map.chads (1).units (index).value); end loop; for index in 0 .. unit.limit - 1 loop core.io.read (file, map.chads (1).units (index).limit); end loop; -- core.io.close (file); -- core.echo (core.success, "Loaded map from file '" & file_name & "'."); -- core.dash; end load; ------------------------------------------------------------------------------------------ procedure draw is offset : core.vector := ((core.window_width - core.base) / 2, (core.window_height - core.base) / 2); view_from : core.vector := (core.camera.x - core.window_width / core.base / core.zoom / 2, core.camera.y - core.window_height / core.base / core.zoom / 2); view_to : core.vector := (core.window_width / core.base / core.zoom, core.window_height / core.base / core.zoom); begin core.clip (view_from.x, 0, map.width - 1); core.clip (view_from.y, 0, map.height - 1); core.clip (view_to.x, 0, map.width - 1); core.clip (view_to.y, 0, map.height - 1); -- compute_world_visibility_grid (offset); compute_world_frame (offset); -- draw_tiles (offset, view_from, view_to); draw_landmarks (offset, view_from, view_to); draw_locations (offset, view_from, view_to); draw_constructions (offset, view_from, view_to); draw_equipments (offset, view_from, view_to); draw_units (offset, view_from, view_to); draw_chads (offset, view_from, view_to); -- draw_alternative (offset, view_from, view_to); end draw; ------------------------------------------------------------------------------------------ procedure mapshot (file_path : in string) is begin if not map_is_revealed then core.echo (core.warning, "You need to reveal entire map in order to make a mapshot."); -- return; end if; -- core.create_image (map.width * core.base, map.height * core.base); -- for vertical in 0 .. map.height - 1 loop for horizontal in 0 .. map.width - 1 loop core.render_image (data => biome.tiles (map.kind), x => horizontal * core.base, y => vertical * core.base, u => core.base * map.tiles (horizontal, vertical), v => 0, width => core.base, height => core.base); end loop; end loop; -- for index in 1 .. map.landmark_count.limit loop core.render_image (data => landmark.game (map.landmarks (index).index), x => map.landmarks (index).x * core.base, y => map.landmarks (index).y * core.base, u => 0, v => 0, width => landmark.game (map.landmarks (index).index).width, height => landmark.game (map.landmarks (index).index).height); end loop; -- for index in 1 .. map.location_count.limit loop core.render_image (data => location.game (map.locations (index).index), x => map.locations (index).x * core.base, y => map.locations (index).y * core.base, u => 0, v => 0, width => location.game (map.locations (index).index).width, height => location.game (map.locations (index).index).height); end loop; -- for index in 1 .. map.construction_count.limit loop core.render_image (data => construction.game (map.constructions (index).index), x => map.constructions (index).x * core.base, y => map.constructions (index).y * core.base, u => 0, v => 0, width => construction.game (map.constructions (index).index).width, height => construction.game (map.constructions (index).index).height); end loop; -- for index in 1 .. map.equipment_count.limit loop core.render_image (data => equipment.game (map.equipments (index).index), x => map.equipments (index).x * core.base, y => map.equipments (index).y * core.base, u => 0, v => 0, width => equipment.game (map.equipments (index).index).width, height => equipment.game (map.equipments (index).index).height); end loop; -- core.export_image (file_path); -- core.echo (core.success, "Exported current world mapshot."); -- core.dash; end mapshot; ------------------------------------------------------------------------------------------ function map_is_revealed return boolean is begin for x in 0 .. map.width - 1 loop for y in 0 .. map.height - 1 loop if map.views (x, y) = false then return false; end if; end loop; end loop; -- return true; end map_is_revealed; ------------------------------------------------------------------------------------------ procedure resource_cheat_1 is begin core.increment (map.chads (1).resources (resource.gold).value, 20); end resource_cheat_1; procedure resource_cheat_2 is begin core.increment (map.chads (1).resources (resource.wood).value, 10); end resource_cheat_2; procedure resource_cheat_3 is begin core.increment (map.chads (1).resources (resource.stone).value, 10); end resource_cheat_3; procedure resource_cheat_4 is begin core.increment (map.chads (1).resources (resource.metal).value, 10); end resource_cheat_4; procedure resource_cheat_5 is begin core.increment (map.chads (1).resources (resource.leather).value, 10); end resource_cheat_5; procedure resource_cheat_6 is begin core.increment (map.chads (1).resources (resource.gem).value, 10); end resource_cheat_6; ------------------------------------------------------------------------------------------ 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 restore_points is begin map.chads (1).health.value := map.chads (1).health.limit; map.chads (1).mana.value := map.chads (1).mana.limit; map.chads (1).movement.value := map.chads (1).movement.limit; end restore_points; ------------------------------------------------------------------------------------------ procedure player_up is begin if map.chads (1).movement.value = 0 then return; end if; core.decrement (map.chads (1).y); core.clip (map.chads (1).y, 0, map.height - 1); map.chads (1).movement := map.chads (1).movement - 1; if map.clips (map.chads (1).x, map.chads (1).y) then core.increment (map.chads (1).y); if map.chads (1).movement.value > 0 then map.chads (1).movement := map.chads (1).movement + 1; end if; end if; end player_up; ------------------------------------------------------------------------------------------ procedure player_down is begin if map.chads (1).movement.value = 0 then return; end if; core.increment (map.chads (1).y); core.clip (map.chads (1).y, 0, map.height - 1); map.chads (1).movement := map.chads (1).movement - 1; if map.clips (map.chads (1).x, map.chads (1).y) then core.decrement (map.chads (1).y); if map.chads (1).movement.value > 0 then map.chads (1).movement := map.chads (1).movement + 1; end if; end if; end player_down; ------------------------------------------------------------------------------------------ procedure player_left is begin if map.chads (1).movement.value = 0 then return; end if; core.decrement (map.chads (1).x); core.clip (map.chads (1).x, 0, map.width - 1); map.chads (1).movement := map.chads (1).movement - 1; if map.clips (map.chads (1).x, map.chads (1).y) then core.increment (map.chads (1).x); if map.chads (1).movement.value > 0 then map.chads (1).movement := map.chads (1).movement + 1; end if; end if; end player_left; ------------------------------------------------------------------------------------------ procedure player_right is begin if map.chads (1).movement.value = 0 then return; end if; core.increment (map.chads (1).x); core.clip (map.chads (1).x, 0, map.width - 1); map.chads (1).movement := map.chads (1).movement - 1; if map.clips (map.chads (1).x, map.chads (1).y) then core.decrement (map.chads (1).x); if map.chads (1).movement.value > 0 then map.chads (1).movement := map.chads (1).movement + 1; end if; end if; end player_right; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ procedure generate_lake (x, y : in integer; size : in natural) is starts, length : integer; begin for offset_x in -size / 2 .. size / 2 loop starts := core.random (0, abs offset_x); length := core.random (size / 2, size - starts); -- for repeat in 0 .. 1 loop for offset_y in starts .. starts + length loop map.tiles (x + 2 * offset_x + repeat, y + offset_y) := core.random (18, 23); end loop; end loop; end loop; end generate_lake; ------------------------------------------------------------------------------------------ procedure draw_tiles (offset, view_from, view_to : in core.vector) is step : core.vector := core.camera; size : constant integer := core.base * core.zoom; hits : natural := 0; begin for vertical in view_from.y .. view_from.y + view_to.y loop exit when vertical > map.height - 1; -- for horizontal in view_from.x .. view_from.x + view_to.x loop exit when horizontal > map.width - 1; -- if map.views (horizontal, vertical) then core.draw (data => biome.tiles (map.kind), x => offset.x + (horizontal - core.camera.x) * size, y => offset.y + (vertical - core.camera.y) * size, u => core.base * map.tiles (horizontal, vertical), v => core.base * (core.animation_time mod biome.tiles (map.kind).frames), width => core.base, height => core.base, ignore => true); -- if core.cursor_inside (x => offset.x + (horizontal - core.camera.x) * size, y => offset.y + (vertical - core.camera.y) * size, width => size, height => size) and core.cursor_inside (x => core.window_width / 2 - 6 * size, y => core.window_height / 2 - 6 * size, width => 12 * size, height => 12 * size) and core.cursor_mode = core.cursor_left and not ui.prioritize then target.x := horizontal; target.y := vertical; core.cursor_mode := core.cursor_none; end if; -- if core.cursor_inside (x => offset.x + (target.x - core.camera.x) * size, y => offset.y + (target.y - core.camera.y) * size, width => size, height => size) and core.cursor_mode = core.cursor_left and not ui.prioritize then world.map.chads (1).x := horizontal + 1; world.map.chads (1).y := vertical; end if; end if; end loop; end loop; -- if target.x /= -1 and target.y /= -1 then step := core.camera; hits := 0; -- core.draw (data => arrow_target, x => offset.x + (target.x - core.camera.x) * size, y => offset.y + (target.y - core.camera.y) * size, factor => core.zoom); -- loop exit when (step.x = target.x - 1 and step.y = target.y - 1) or (hits = 6); -- if step.x < target.x and step.y < target.y then core.draw (arrow_lower_right, offset.x + (step.x + 1 - core.camera.x) * size, offset.y + (step.y + 1 - core.camera.y) * size, factor => core.zoom); step.x := step.x + 1; step.y := step.y + 1; elsif step.x > target.x and step.y < target.y then core.draw (arrow_lower_left, offset.x + (step.x - 1 - core.camera.x) * size, offset.y + (step.y + 1 - core.camera.y) * size, factor => core.zoom); step.x := step.x - 1; step.y := step.y + 1; elsif step.x = target.x and step.y < target.y then core.draw (arrow_lower, offset.x + (step.x - core.camera.x) * size, offset.y + (step.y + 1 - core.camera.y) * size, factor => core.zoom); step.y := step.y + 1; elsif step.x < target.x and step.y = target.y then core.draw (arrow_right, offset.x + (step.x + 1 - core.camera.x) * size, offset.y + (step.y - core.camera.y) * size, factor => core.zoom); step.x := step.x + 1; elsif step.x > target.x and step.y = target.y then core.draw (arrow_left, offset.x + (step.x - 1 - core.camera.x) * size, offset.y + (step.y - core.camera.y) * size, factor => core.zoom); step.x := step.x - 1; elsif step.x < target.x and step.y > target.y then core.draw (arrow_upper_right, offset.x + (step.x + 1 - core.camera.x) * size, offset.y + (step.y - 1 - core.camera.y) * size, factor => core.zoom); step.x := step.x + 1; step.y := step.y - 1; elsif step.x > target.x and step.y > target.y then core.draw (arrow_upper_left, offset.x + (step.x - 1 - core.camera.x) * size, offset.y + (step.y - 1 - core.camera.y) * size, factor => core.zoom); step.x := step.x - 1; step.y := step.y - 1; elsif step.x = target.x and step.y > target.y then core.draw (arrow_upper, offset.x + (step.x - core.camera.x) * size, offset.y + (step.y - 1 - core.camera.y) * size, factor => core.zoom); step.y := step.y - 1; end if; -- hits := hits + 1; end loop; end if; end draw_tiles; ------------------------------------------------------------------------------------------ procedure compute_world_visibility_grid (offset : in core.vector) is 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 > map.chads (1).attributes (attribute.reach).value * 64) then map.views (horizontal, vertical) := true; end if; end loop; end loop; end compute_world_visibility_grid; ------------------------------------------------------------------------------------------ procedure compute_world_frame (offset : in core.vector) is x : constant integer := core.base * core.zoom * (-1 - core.camera.x) + offset.x; y : constant integer := core.base * core.zoom * (-1 - core.camera.y) + offset.y; width : constant integer := core.base * core.zoom * (map.width + 2); height : constant integer := core.base * core.zoom * (map.height + 2); begin core.draw_horizontally (border_upper, x + core.base * core.zoom, y, width - 2 * core.base * core.zoom, core.zoom); core.draw_horizontally (border_lower, x + core.base * core.zoom, y - core.base * core.zoom + height, width - 2 * core.base * core.zoom, core.zoom); core.draw_vertically (border_left, x, y + core.base * core.zoom, height - 2 * core.base * core.zoom, core.zoom); core.draw_vertically (border_right, x - core.base * core.zoom + width, y + core.base * core.zoom, height - 2 * core.base * core.zoom, core.zoom); -- core.draw (corner_upper_left, x, y, factor => core.zoom); core.draw (corner_upper_right, x - core.base * core.zoom + width, y, factor => core.zoom); core.draw (corner_lower_left, x, y - core.base * core.zoom + height, factor => core.zoom); core.draw (corner_lower_right, x - core.base * core.zoom + width, y - core.base * core.zoom + height, factor => core.zoom); end compute_world_frame; ------------------------------------------------------------------------------------------ procedure draw_landmarks (offset, view_from, view_to : in core.vector) is begin for index in 1 .. map.landmark_count.limit loop if map.views (map.landmarks (index).x, map.landmarks (index).y) and map.landmarks (index).x > view_from.x and map.landmarks (index).x < view_from.x + view_to.x and map.landmarks (index).y > view_from.y and map.landmarks (index).y < view_from.y + view_to.y then core.draw (data => landmark.game (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 => landmark.game (map.landmarks (index).index).width, height => landmark.game (map.landmarks (index).index).height) and core.cursor_mode = core.cursor_middle and not ui.prioritize then core.write_text_box (landmark.description (map.landmarks (index).index).name.all); end if; end if; end loop; end draw_landmarks; ------------------------------------------------------------------------------------------ procedure draw_locations (offset, view_from, view_to : in core.vector) is begin for index in 1 .. map.location_count.limit loop if map.views (map.locations (index).x, map.locations (index).y) and map.locations (index).x > view_from.x and map.locations (index).x < view_from.x + view_to.x and map.locations (index).y > view_from.y and map.locations (index).y < view_from.y + view_to.y then core.draw (data => location.game (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, state => core.animation'val (boolean'pos (map.locations (index).used))); -- 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 => location.game (map.locations (index).index).width, height => location.game (map.locations (index).index).height) and core.cursor_mode = core.cursor_middle and not ui.prioritize then core.write_text_box (location.description (map.locations (index).index).name.all); end if; end if; -- if core.camera.x > map.locations (index).x - 2 and core.camera.x < map.locations (index).x + 1 + location.game (map.locations (index).index).width / core.base and core.camera.y > map.locations (index).y - 2 and core.camera.y < map.locations (index).y + 1 + location.game (map.locations (index).index).height / core.base and map.locations (index).used = false and core.signal_code'pos (core.signal_mode) = core.signal_code'pos (core.signal_e) and not ui.prioritize then declare player : chad.information renames world.map.chads (1); -- data : effect.information := location.description (map.locations (index).index).evoke; -- attribute_index : attribute.enumeration; --~skill_index : skill.enumeration; resource_index : resource.enumeration; material_index : material.enumeration; begin case data.kind is when effect.idle => null; -- when effect.modify_attribute => attribute_index := attribute.enumeration'val (data.modifier); player.attributes (attribute_index) := player.attributes (attribute_index) + data.amount; ui.echo ("Player " & (if data.amount < 0 then "lost" else "gained") & integer'image (abs data.amount) & " " & attribute.description (attribute_index).name.all & " attribute points."); -- when effect.modify_skill => null; --~when effect.modify_skill => skill_index := skill.enumeration'val (data.modifier); --~player.skills (skill_index) := player.skills (skill_index) + data.amount; --~ui.echo ("Player " & (if data.amount < 0 then "lost" else "gained") & integer'image (abs data.amount) & " " --~& skill.description (skill_index).name.all & " skill points."); -- when effect.modify_resource => resource_index := resource.enumeration'val (data.modifier); player.resources (resource_index) := player.resources (resource_index) + data.amount; ui.echo ("Player " & (if data.amount < 0 then "lost" else "gained") & integer'image (abs data.amount) & " " & resource.description (resource_index).name.all & " resource points."); -- when effect.modify_material => material_index := material.enumeration'val (data.modifier); player.materials (material_index) := player.materials (material_index) + data.amount; ui.echo ("+" & data.amount'image & " " & material.description (material_index).name.all); end case; end; -- map.locations (index).used := true; end if; end loop; end draw_locations; ------------------------------------------------------------------------------------------ procedure draw_constructions (offset, view_from, view_to : in core.vector) is begin for index in 1 .. map.construction_count.limit loop if map.views (map.constructions (index).x, map.constructions (index).y) and map.constructions (index).x > view_from.x and map.constructions (index).x < view_from.x + view_to.x and map.constructions (index).y > view_from.y and map.constructions (index).y < view_from.y + view_to.y then draw_construction (data => map.constructions (index).index, x => offset.x + (map.constructions (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.constructions (index).y - core.camera.y) * core.base * core.zoom, factor => core.zoom); end if; end loop; end draw_constructions; ------------------------------------------------------------------------------------------ procedure draw_equipments (offset, view_from, view_to : in core.vector) is begin for index in 1 .. map.equipment_count.limit loop if map.views (map.equipments (index).x, map.equipments (index).y) and map.equipments (index).x > view_from.x and map.equipments (index).x < view_from.x + view_to.x and map.equipments (index).y > view_from.y and map.equipments (index).y < view_from.y + view_to.y then draw_equipment (data => map.equipments (index).index, x => offset.x + (map.equipments (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.equipments (index).y - core.camera.y) * core.base * core.zoom, factor => core.zoom); -- if map.equipments (index).x = core.camera.x and map.equipments (index).y = core.camera.y then if map.chads (1).item_count < chad.item_limit and equipment_valid (map.equipments (index).index) then map.chads (1).items (map.chads (1).item_count) := map.equipments (index).index; -- core.increment (map.chads (1).item_count); -- map.equipments (index).index := equipment.none; end if; end if; end if; end loop; end draw_equipments; ------------------------------------------------------------------------------------------ procedure draw_units (offset, view_from, view_to : in core.vector) is begin for index in 1 .. map.unit_count.limit loop if map.views (map.units (index).x, map.units (index).y) and map.units (index).x > view_from.x and map.units (index).x < view_from.x + view_to.x and map.units (index).y > view_from.y and map.units (index).y < view_from.y + view_to.y then draw_unit (data => map.units (index).index, state => core.idle, x => offset.x + (map.units (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.units (index).y - core.camera.y) * core.base * core.zoom, factor => core.zoom); end if; end loop; end draw_units; ------------------------------------------------------------------------------------------ procedure draw_chads (offset, view_from, view_to : in core.vector) is begin for index in 1 .. map.chad_count.value loop if map.views (map.chads (index).x, map.chads (index).y) then draw_chad (data => map.chads (index), state => map.chads (index).state, x => offset.x + (map.chads (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.chads (index).y - core.camera.y) * core.base * core.zoom, factor => core.zoom); end if; end loop; end draw_chads; ------------------------------------------------------------------------------------------ procedure draw_alternative (offset, view_from, view_to : in core.vector) is begin for vertical in view_from.y .. view_from.y + view_to.y loop exit when vertical > map.height - 1; -- for horizontal in view_from.x .. view_from.x + view_to.x loop exit when horizontal > map.width - 1; -- if (horizontal - core.camera.x) ** 2 + (vertical - core.camera.y) ** 2 > map.chads (1).attributes (attribute.reach).value * 32 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_alternative; ------------------------------------------------------------------------------------------ procedure compute_earth_to_water_transition is matrix : array (0 .. 1, 0 .. 1) of natural; begin for x in 1 .. map.width - 2 loop for y in 1 .. map.height - 2 loop matrix (0, 0) := boolean'pos (map.tiles (x - 1, y - 1) not in 18 .. 23); matrix (1, 0) := boolean'pos (map.tiles (x, y - 1) not in 18 .. 23); matrix (0, 1) := boolean'pos (map.tiles (x - 1, y ) not in 18 .. 23); matrix (1, 1) := boolean'pos (map.tiles (x, y ) not in 18 .. 23); -- if map.tiles (x, y) not in 18 .. 23 and map.tiles (x, y + 1) in 18 .. 23 then map.tiles (x, y ) := 24; end if; if map.tiles (x, y) in 18 .. 23 and map.tiles (x, y + 1) not in 18 .. 23 then map.tiles (x, y + 1) := 25; end if; if map.tiles (x, y) not in 18 .. 23 and map.tiles (x + 1, y ) in 18 .. 23 then map.tiles (x, y ) := 26; end if; if map.tiles (x, y) in 18 .. 23 and map.tiles (x + 1, y ) not in 18 .. 23 then map.tiles (x + 1, y ) := 27; end if; -- if matrix = ((1, 1), (1, 0)) then map.tiles (x - 1, y - 1) := 28; elsif matrix = ((1, 0), (1, 1)) then map.tiles (x, y - 1) := 29; elsif matrix = ((1, 1), (0, 1)) then map.tiles (x - 1, y ) := 30; elsif matrix = ((0, 1), (1, 1)) then map.tiles (x, y ) := 31; elsif matrix = ((0, 0), (0, 1)) then map.tiles (x, y ) := 32; elsif matrix = ((0, 1), (0, 0)) then map.tiles (x - 1, y ) := 33; elsif matrix = ((0, 0), (1, 0)) then map.tiles (x, y - 1) := 34; elsif matrix = ((1, 0), (0, 0)) then map.tiles (x - 1, y - 1) := 35; end if; end loop; end loop; end compute_earth_to_water_transition; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ end world;