-- 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); function view_chad_basics (data : in chad.information; x, y, width : in integer) return core.vector; function view_chad_points (data : in chad.information; x, y, width : in integer) return core.vector; function view_chad_skills (data : in chad.information; x, y, width : in integer) return core.vector; function view_chad_equipment (data : in chad.information; x, y, width : in integer) return core.vector; function view_chad_inventory (data : in chad.information; x, y, width : in integer) return 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; -- core.echo (core.comment, "Configuring" & attribute.count'image & " attribute components..."); -- for index in attribute.enumeration loop attribute.icon (index) := core.import_sprite (core.folder & "/icon/attribute/" & core.lowercase (attribute.enumeration'image (index)) & ".png", 1, 1); end loop; -- core.echo (core.comment, "Configuring" & skill.count'image & " skill components..."); -- for index in skill.enumeration loop skill.icon (index) := core.import_sprite (core.folder & "/icon/skill/" & core.lowercase (skill.enumeration'image (index)) & ".png", 1, 1); end loop; -- core.echo (core.comment, "Configuring" & resource.count'image & " resource components..."); -- for index in resource.enumeration loop resource.icon (index) := core.import_sprite (core.folder & "/icon/resource/" & core.lowercase (resource.enumeration'image (index)) & ".png", 1, 1); end loop; -- core.echo (core.comment, "Configuring" & magic.count'image & " magic components..."); -- for index in magic.enumeration loop declare folder : constant string := core.lowercase (magic.school'image (magic.description (index).kind)); file : constant string := core.lowercase (magic.enumeration'image (index)); begin magic.view (index) := core.import_sprite (core.folder & "/view/magic/" & folder & "/" & file & ".png", 1, 1); end; end loop; -- core.echo (core.comment, "Configuring" & material.count'image & " material components..."); -- for index in material.enumeration loop material.icon (index) := core.import_sprite (core.folder & "/icon/material/" & core.lowercase (material.enumeration'image (index)) & ".png", 1, 1); end loop; -- core.echo (core.comment, "Configuring" & equipment.count'image & " equipment components..."); -- for index in equipment.enumeration loop declare folder : constant string := core.lowercase (equipment.kind'image (equipment.description (index).slot)); file : constant string := core.lowercase (equipment.enumeration'image (index)); begin equipment.game (index) := core.import_sprite (core.folder & "/game/equipment/" & folder & "/" & file & ".png", 4, 6); equipment.icon (index) := core.import_sprite (core.folder & "/icon/equipment/" & folder & "/" & file & ".png", 1, 1); end; end loop; -- for index in equipment.kind loop declare file : constant string := core.lowercase (equipment.kind'image (index)); begin equipment.slot (index) := core.import_sprite (core.folder & "/icon/engine/" & file & ".png", 1, 1); end; end loop; -- core.echo (core.comment, "Configuring" & unit.count'image & " unit components..."); -- for index in faction.enumeration loop unit.base (index) := core.import_sprite (core.folder & "/game/unit/" & core.lowercase (faction.enumeration'image (index)) & "/base.png", 4, 6); end loop; -- for index in unit.enumeration loop unit.icon (index) := core.import_sprite (core.folder & "/icon/unit/" & core.lowercase (unit.enumeration'image (index)) & ".png", 1, 1); unit.view (index) := core.import_sprite (core.folder & "/view/unit/" & core.lowercase (unit.enumeration'image (index)) & ".png", 1, 1); end loop; -- core.echo (core.comment, "Configuring" & deity.count'image & " deity components..."); -- for index in deity.enumeration loop deity.game (index) := core.import_sprite (core.folder & "/game/deity/" & deity.enumeration'image (index) & ".png", 4, 1); end loop; -- core.echo (core.comment, "Configuring" & construction.count'image & " construction components..."); -- for index in construction.enumeration loop declare folder : constant string := core.lowercase (faction.enumeration'image (construction.description (index).kind)); file : constant string := core.lowercase (construction.enumeration'image (index)); frames : constant integer := construction.description (index).frames; begin construction.game (index) := core.import_sprite (core.folder & "/game/construction/" & folder & "/" & file & ".png", frames, 1); end; end loop; -- core.echo (core.comment, "Configuring" & chad.count'image & " chad components..."); -- for index in chad.enumeration loop chad.game (index) := core.import_sprite (core.folder & "/game/chad/" & core.lowercase (chad.enumeration'image (index)) & ".png", 4, 6); chad.view (index) := core.import_sprite (core.folder & "/view/chad/" & core.lowercase (chad.enumeration'image (index)) & ".png", 1, 1); 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.state := core.idle; this.health := (12, 12); this.mana := (12, 12); this.stamina := (12, 12); <> 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 core.draw (landmark.game (data), x, y, factor => factor); -- if core.cursor_inside (x, y, landmark.game (data).width * factor, landmark.game (data).height * factor) and core.cursor_mode = core.cursor_middle then ui.draw_text (landmark.description (data).name.all, core.cursor.x + core.icon, core.cursor.y, border => 10); end if; end draw_landmark; ------------------------------------------------------------------------------------------ procedure draw_location (data : in location.enumeration; used : in boolean; x, y, factor : in integer) is begin core.draw (location.game (data), x, y, state => core.animation'val (boolean'pos (used)), factor => factor); -- if core.cursor_inside (x, y, location.game (data).width * factor, location.game (data).height * factor) and core.cursor_mode = core.cursor_middle then ui.draw_text (location.description (data).name.all, core.cursor.x + core.icon, core.cursor.y, border => 10); end if; 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 * factor, construction.game (data).height * factor) and core.cursor_mode = core.cursor_middle then ui.draw_text (construction.description (data).name.all, core.cursor.x + core.icon, core.cursor.y, border => 10); 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 * factor, equipment.game (data).height * factor) and core.cursor_mode = core.cursor_middle then ui.draw_text (equipment.description (data).name.all, core.cursor.x + core.icon, core.cursor.y, border => 10); 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; -- if core.cursor_inside (x, y, core.base * factor, core.base * factor) and core.cursor_mode = core.cursor_middle then ui.draw_text (unit.description (data).name.all, core.cursor.x + core.icon, core.cursor.y, border => 10); end if; 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_skill is begin ui.draw_text (skill.explanation (review_skill_data).all, core.center_x (90*9+20), core.center_y (5*15+20), offset => 10); end review_skill; ------------------------------------------------------------------------------------------ procedure review_unit is data : unit.definition := unit.description (review_unit_data); from : faction.definition := faction.description (data.kind); -- offset : constant integer := 8; boxy : constant natural := 3 * ui.monoheight + 2 * core.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 if unit.enumeration'pos (review_unit_data) = unit.enumeration'pos (unit.none) then return; end if; -- 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 + core.less, core.center_y (height) + offset + core.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 + core.more), border => core.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 review_chad is begin null; end review_chad; ------------------------------------------------------------------------------------------ procedure view_chad_information (data : in chad.information; x, y, width : in integer) is offset : constant integer := 8; height : constant integer := chad.view_height + 12 * core.icon + 4 * core.base + 2 * offset; -- orient : core.vector := (0, 0); begin ui.draw_frame (x, y, width, height); -- orient := orient + view_chad_basics (data, x + offset, y + offset, width - 2 * offset); ui.draw_separator ( x + offset, y + offset + orient.y, width - 2 * offset); orient := orient + view_chad_points (data, x + offset, y + offset + orient.y + 1 * core.base, width - 2 * offset); ui.draw_separator ( x + offset, y + offset + orient.y + 1 * core.base, width - 2 * offset); orient := orient + view_chad_equipment (data, x + offset, y + offset + orient.y + 2 * core.base, width - 2 * offset); ui.draw_separator ( x + offset, y + offset + orient.y + 2 * core.base, width - 2 * offset); orient := orient + view_chad_skills (data, x + offset, y + offset + orient.y + 3 * core.base, width - 2 * offset); ui.draw_separator ( x + offset, y + offset + orient.y + 3 * core.base, width - 2 * offset); orient := orient + view_chad_inventory (data, x + offset, y + offset + orient.y + 4 * core.base, width - 2 * offset); end view_chad_information; ------------------------------------------------------------------------------------------ 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, core.animation'pos (map.units (index).state)); -- core.save_point (file, map.units (index).health); core.save_point (file, map.units (index).mana); core.save_point (file, map.units (index).stamina); 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; -- for chad_index in 1 .. map.chad_count.limit loop core.io.write (file, chad.enumeration'pos (map.chads (chad_index).index)); core.io.write (file, core.animation'pos (map.chads (chad_index).state)); core.io.write (file, map.chads (chad_index).x); core.io.write (file, map.chads (chad_index).y); -- core.save_point (file, map.chads (chad_index).health); core.save_point (file, map.chads (chad_index).mana); core.save_point (file, map.chads (chad_index).stamina); -- for index in attribute.enumeration loop core.save_point (file, map.chads (chad_index).attributes (index)); end loop; for index in resource.enumeration loop core.save_point (file, map.chads (chad_index).resources (index)); end loop; -- for index in skill.limit loop core.io.write (file, skill.enumeration'pos (map.chads (chad_index).skills (index).index)); end loop; for index in skill.limit loop core.io.write (file, map.chads (chad_index).skills (index).value); end loop; for index in skill.limit loop core.io.write (file, map.chads (chad_index).skills (index).limit); end loop; -- for index in material.limit loop core.io.write (file, material.enumeration'pos (map.chads (chad_index).materials (index).index)); end loop; for index in material.limit loop core.io.write (file, map.chads (chad_index).materials (index).value); end loop; for index in material.limit loop core.io.write (file, map.chads (chad_index).materials (index).limit); end loop; -- for kind in equipment.kind loop core.io.write (file, equipment.enumeration'pos (map.chads (chad_index).equipments (kind))); end loop; -- --~core.io.write (file, map.chads (chad_index).item_count); --~-- --~if map.chads (chad_index).item_count > 0 then --~for index in 0 .. map.chads (chad_index).item_count - 1 loop --~core.io.write (file, equipment.enumeration'pos (map.chads (chad_index).items (index))); --~end loop; --~end if; 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).state := core.animation'val (this); -- core.load_point (file, map.units (index).health); core.load_point (file, map.units (index).mana); core.load_point (file, map.units (index).stamina); 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; -- for chad_index in 1 .. map.chad_count.limit loop core.io.read (file, this); map.chads (chad_index).index := chad.enumeration'val (this); core.io.read (file, this); map.chads (chad_index).state := core.animation'val (this); core.io.read (file, map.chads (chad_index).x); core.io.read (file, map.chads (chad_index).y); -- core.load_point (file, map.chads (chad_index).health); core.load_point (file, map.chads (chad_index).mana); core.load_point (file, map.chads (chad_index).stamina); -- for index in attribute.enumeration loop core.load_point (file, map.chads (chad_index).attributes (index)); end loop; for index in resource.enumeration loop core.load_point (file, map.chads (chad_index).resources (index)); end loop; -- for index in skill.limit loop core.io.read (file, this); map.chads (chad_index).skills (index).index := skill.enumeration'val (this); end loop; for index in skill.limit loop core.io.read (file, map.chads (chad_index).skills (index).value); end loop; for index in skill.limit loop core.io.read (file, map.chads (chad_index).skills (index).limit); end loop; -- for index in material.limit loop core.io.read (file, this); map.chads (chad_index).materials (index).index := material.enumeration'val (this); end loop; for index in material.limit loop core.io.read (file, map.chads (chad_index).materials (index).value); end loop; for index in material.limit loop core.io.read (file, map.chads (chad_index).materials (index).limit); end loop; -- for kind in equipment.kind loop core.io.read (file, this); map.chads (chad_index).equipments (kind) := equipment.enumeration'val (this); end loop; -- --~core.io.read (file, map.chads (chad_index).item_count); --~-- --~if map.chads (chad_index).item_count > 0 then --~for index in 0 .. map.chads (chad_index).item_count - 1 loop --~core.io.read (file, this); map.chads (chad_index).items (index) := equipment.enumeration'val (this); --~end loop; --~end if; 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 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).stamina.value := map.chads (1).stamina.limit; end restore_points; ------------------------------------------------------------------------------------------ procedure increase_attributes is begin for index in attribute.enumeration loop map.chads (1).attributes (index) := map.chads (1).attributes (index) + 1; end loop; end increase_attributes; ------------------------------------------------------------------------------------------ procedure increase_resources is begin for index in resource.enumeration loop map.chads (1).resources (index) := map.chads (1).resources (index) + 10; end loop; end increase_resources; ------------------------------------------------------------------------------------------ procedure player_up is begin if map.chads (1).stamina.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).stamina := map.chads (1).stamina - 1; if map.clips (map.chads (1).x, map.chads (1).y) then core.increment (map.chads (1).y); if map.chads (1).stamina.value > 0 then map.chads (1).stamina := map.chads (1).stamina + 1; end if; end if; end player_up; ------------------------------------------------------------------------------------------ procedure player_down is begin if map.chads (1).stamina.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).stamina := map.chads (1).stamina - 1; if map.clips (map.chads (1).x, map.chads (1).y) then core.decrement (map.chads (1).y); if map.chads (1).stamina.value > 0 then map.chads (1).stamina := map.chads (1).stamina + 1; end if; end if; end player_down; ------------------------------------------------------------------------------------------ procedure player_left is begin if map.chads (1).stamina.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).stamina := map.chads (1).stamina - 1; if map.clips (map.chads (1).x, map.chads (1).y) then core.increment (map.chads (1).x); if map.chads (1).stamina.value > 0 then map.chads (1).stamina := map.chads (1).stamina + 1; end if; end if; end player_left; ------------------------------------------------------------------------------------------ procedure player_right is begin if map.chads (1).stamina.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).stamina := map.chads (1).stamina - 1; if map.clips (map.chads (1).x, map.chads (1).y) then core.decrement (map.chads (1).x); if map.chads (1).stamina.value > 0 then map.chads (1).stamina := map.chads (1).stamina + 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 -- shit 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; ------------------------------------------------------------------------------------------ function view_chad_basics (data : in chad.information; x, y, width : in integer) return core.vector is side : constant integer := chad.view_width + attribute.count * core.icon; skip : integer := 0; begin ui.draw_sprite (chad.view (data.index), chad.description (data.index).name.all, x, y, 0, review_chad'access); -- ui.draw_text_box (x + chad.view_width, y, width - chad.view_width, core.icon); ui.write (chad.description (data.index).name.all, x + chad.view_width + core.less, y + core.less); -- ui.draw_text (chad.description (data.index).title.all, x + side, y + 1 * core.icon, width - side, core.icon, core.more); ui.draw_text ("Level" & data.level'image, x + side, y + 2 * core.icon, width - side, core.icon, core.more); -- for index in attribute.enumeration loop ui.draw_icon (attribute.icon (index), attribute.description (index).text.all, x + chad.view_width + skip, y + core.icon); --~ui.draw_text (data.attributes (index).value'image, x + chad.view_width + skip, y + 2 * core.icon, core.icon, core.icon, core.more); ui.draw_text_in_overicon (data.attributes (index).value'image, x + chad.view_width + skip, y + 2 * core.icon); -- skip := skip + core.icon; end loop; -- return (width, chad.view_height); end view_chad_basics; ------------------------------------------------------------------------------------------ function view_chad_points (data : in chad.information; x, y, width : in integer) return core.vector is begin ui.draw_tiny_fill_bar (x, y + 0 * core.icon + core.icon, width, float (data.health.value) / float (data.health.limit), (127, 0, 0, 255)); ui.draw_tiny_fill_bar (x, y + 1 * core.icon + core.icon, width, float (data.mana.value) / float (data.mana.limit), (0, 0, 127, 255)); ui.draw_tiny_fill_bar (x, y + 2 * core.icon + core.icon, width, float (data.stamina.value) / float (data.stamina.limit), (0, 127, 0, 255)); -- ui.write ("Health " & data.health.value'image & " /" & data.health.limit'image, x + core.icon, y + 0 * core.icon + core.more, code => true); ui.write ("Mana " & data.mana.value'image & " /" & data.mana.limit'image, x + core.icon, y + 1 * core.icon + core.more, code => true); ui.write ("Stamina" & data.stamina.value'image & " /" & data.stamina.limit'image, x + core.icon, y + 2 * core.icon + core.more, code => true); -- return (width, 3 * core.icon); end view_chad_points; ------------------------------------------------------------------------------------------ function view_chad_skills (data : in chad.information; x, y, width : in integer) return core.vector is count : constant natural := skill.limit'last + 1; begin for index in skill.limit loop review_skill_data := data.skills (index).index; -- ui.draw_icon_and_text (data => skill.icon (data.skills (index).index), text => skill.description (data.skills (index).index).name.all & data.skills (index).value'image, x => x + (index mod 2) * (width / 2), y => y + (index / 2) * core.icon, width => width / 2, action => review_skill'access); end loop; -- return (width, (count / 2) * core.icon); end view_chad_skills; ------------------------------------------------------------------------------------------ function view_chad_equipment (data : in chad.information; x, y, width : in integer) return core.vector is count : constant natural := equipment.kind'pos (equipment.kind'last) + 1; begin for index in equipment.kind loop ui.draw_overicon (data => (if equipment_valid (data.equipments (index)) then equipment.icon (data.equipments (index)) else equipment.slot (index)), text => (if equipment_valid (data.equipments (index)) then equipment.description (data.equipments (index)).name.all else "--"), x => x + equipment.kind'pos (index) * core.icon, y => y); end loop; -- ui.draw_text ("Equipment", x + count * core.icon, y, width - count * core.icon, core.icon, core.more); -- return (width, core.icon); end view_chad_equipment; ------------------------------------------------------------------------------------------ function view_chad_inventory (data : in chad.information; x, y, width : in integer) return core.vector is begin for index_y in 0 .. 3 loop for index_x in 0 .. 7 loop ui.draw_icon (data => material.icon (data.materials (8 * index_y + index_x).index), text => material.description (data.materials (8 * index_y + index_x).index).name.all, x => x + index_x * core.icon, y => y + index_y * core.icon); -- ui.write (text => (if data.materials (8 * index_y + index_x).value > 0 then data.materials (8 * index_y + index_x).value'image else ""), x => x + index_x * core.icon + (if data.materials (8 * index_y + index_x).value < 10 then 14 else 5), y => y + index_y * core.icon + 17, code => true); end loop; end loop; -- return (width, 4 * core.icon); end view_chad_inventory; ------------------------------------------------------------------------------------------ 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 draw_landmark (data => 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, factor => core.zoom); 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 draw_location (data => map.locations (index).index, used => map.locations (index).used, 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, factor => core.zoom); -- 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_mode = 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; done : boolean := false; -- 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 => 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.append_material => material_index := material.enumeration'val (data.modifier); -- for this in material.limit loop exit when done; if material.enumeration'pos (player.materials (this).index) = material.enumeration'pos (material_index) then player.materials (this).value := player.materials (this).value + data.amount; done := true; end if; end loop; -- if not done then for this in material.limit loop if material.enumeration'pos (player.materials (this).index) = material.enumeration'pos (material.none) then player.materials (this).index := material_index; player.materials (this).value := data.amount; exit; end if; end loop; end if; -- ui.echo ("+" & data.amount'image & " " & material.description (material_index).name.all); when others => null; end case; end; -- map.locations (index).used := true; end if; 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;