-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic -- -- GNU General Public Licence (version 3 or later) with core, ui, attribute, skill, resource, faction, equipment, unit, construction, chad, effect; use type core.cursor_code; use type core.signal_code; use type core.point; package body world is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ view_reach : constant integer := 96; lake_count : constant natural := 6; landmark_limit : constant integer := 480; location_limit : constant integer := 240; construction_limit : constant natural := 120; equipment_limit : constant natural := 300; unit_limit : constant natural := 600; tiles : array (biome) of core.sprite; 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; draw_tiles_timer : natural := 0; draw_views_timer : natural := 0; draw_landmarks_timer : natural := 0; draw_locations_timer : natural := 0; draw_constructions_timer : natural := 0; draw_equipments_timer : natural := 0; draw_units_timer : natural := 0; draw_world_timer : natural := 0; drawn_tiles : natural := 0; drawn_views : natural := 0; drawn_landmarks : natural := 0; drawn_locations : natural := 0; drawn_constructions : natural := 0; drawn_equipments : natural := 0; drawn_units : natural := 0; ------------------------------------------------------------------------------------------ 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_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 loop tiles (index) := core.import_sprite (core.folder & "/game/world/terrain/" & 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_index loop landmarks (index) := core.import_sprite (file_path => core.folder & "/game/world/landmark/" & core.lowercase (index'image) & ".png", frames => landmark_description (index).frames, states => 1); end loop; -- for index in location_index loop locations (index) := core.import_sprite (file_path => core.folder & "/game/world/location/" & core.lowercase (index'image) & ".png", frames => location_description (index).frames, states => location_description (index).states); end loop; end configure; ------------------------------------------------------------------------------------------ procedure make (index : in biome; width, height, 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); -- map.kind := index; map.width := width; map.height := height; map.chad_limit := chad_limit; map.chad_count := 0; -- 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 entity_array (1 .. landmark_limit); map.locations := new entity_array (1 .. location_limit); map.constructions := new entity_array (1 .. construction_limit); map.equipments := new entity_array (1 .. equipment_limit); map.units := new entity_array (1 .. unit_limit); map.chads := new chad.informations (1 .. map.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 map.landmarks (index).index := core.random (0, landmark_count - 1); map.landmarks (index).state := 0; <> map.landmarks (index).x := core.random (6, map.width - 6); map.landmarks (index).y := core.random (6, map.height - 6); -- if map.clips (map.landmarks (index).x, map.landmarks (index).y) then goto repeat_landmark_generation; end if; -- if landmark_description (landmark_index'val (map.landmarks (index).index)).clip then declare reach_x : constant natural := landmarks (landmark_index'val (map.landmarks (index).index)).width / core.base; reach_y : constant natural := landmarks (landmark_index'val (map.landmarks (index).index)).height / core.base; begin for x in 0 .. reach_x - 1 loop for y in 0 .. reach_y - 1 loop map.clips (map.landmarks (index).x + x, map.landmarks (index).y + y) := true; end loop; end loop; end; end if; end loop; -- for index in 1 .. location_limit loop map.locations (index).index := core.random (0, location_count - 1); map.locations (index).state := 0; <> map.locations (index).x := core.random (6, map.width - 6); map.locations (index).y := core.random (6, map.height - 6); -- if map.clips (map.locations (index).x, map.locations (index).y) then goto repeat_location_generation; end if; -- if location_description (location_index'val (map.locations (index).index)).clip then declare reach_x : constant natural := locations (location_index'val (map.locations (index).index)).width / core.base; reach_y : constant natural := locations (location_index'val (map.locations (index).index)).height / core.base; begin for x in 0 .. reach_x - 1 loop for y in 0 .. reach_y - 1 loop map.clips (map.locations (index).x + x, map.locations (index).y + y) := true; end loop; end loop; end; end if; end loop; -- for index in 1 .. construction_limit loop map.constructions (index).index := core.random (0, construction.count - 1); map.constructions (index).state := 0; <> map.constructions (index).x := core.random (6, map.width - 6); map.constructions (index).y := core.random (6, map.height - 6); -- if map.clips (map.constructions (index).x, map.constructions (index).y) then goto repeat_construction_generation; end if; -- declare reach_x : constant natural := construction.sprite (construction.enumeration'val (map.constructions (index).index)).width / core.base; reach_y : constant natural := construction.sprite (construction.enumeration'val (map.constructions (index).index)).height / core.base; begin for x in 0 .. reach_x - 1 loop for y in 0 .. reach_y - 1 loop map.clips (map.constructions (index).x + x, map.constructions (index).y + y) := true; end loop; end loop; end; end loop; -- for index in 1 .. equipment_limit loop map.equipments (index).index := core.random (0, equipment.count - 1); map.equipments (index).state := 0; <> map.equipments (index).x := core.random (0, map.width - 1); map.equipments (index).y := core.random (0, map.height - 1); -- if map.clips (map.equipments (index).x, map.equipments (index).y) then goto repeat_equipment_generation; end if; end loop; -- for index in 1 .. unit_limit loop map.units (index).index := core.random (1, unit.count - 1); map.units (index).state := 0; <> map.units (index).x := core.random (0, map.width - 1); map.units (index).y := core.random (0, map.height - 1); -- if map.clips (map.units (index).x, map.units (index).y) then goto repeat_unit_generation; end if; -- map.clips (map.units (index).x, map.units (index).y) := true; end loop; -- core.echo (core.success, "Finished procedurally generating new map."); end make; ------------------------------------------------------------------------------------------ procedure save (file_name : in string) is procedure save_entity (here : in core.io.file_type; data : in entity_description) is begin core.io.write (here, data.index); core.io.write (here, data.state); core.io.write (here, data.x); core.io.write (here, data.y); end save_entity; -- file : core.io.file_type; begin core.io.create (file, core.io.out_file, core.folder & "/map/" & file_name); -- core.io.write (file, biome'pos (map.kind)); core.io.write (file, map.width); core.io.write (file, map.height); core.io.write (file, map.chad_count); core.io.write (file, map.chad_limit); -- 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 .. landmark_limit loop save_entity (file, map.landmarks (index)); end loop; for index in 1 .. location_limit loop save_entity (file, map.locations (index)); end loop; for index in 1 .. construction_limit loop save_entity (file, map.constructions (index)); end loop; for index in 1 .. equipment_limit loop save_entity (file, map.equipments (index)); end loop; for index in 1 .. unit_limit loop save_entity (file, map.units (index)); 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 procedure load_entity (here : in core.io.file_type; data : out entity_description) is begin core.io.read (here, data.index); core.io.read (here, data.state); core.io.read (here, data.x); core.io.read (here, data.y); end load_entity; -- 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'val (this); core.io.read (file, map.width); core.io.read (file, map.height); core.io.read (file, map.chad_count); core.io.read (file, map.chad_limit); -- 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 .. landmark_limit loop load_entity (file, map.landmarks (index)); end loop; for index in 1 .. location_limit loop load_entity (file, map.locations (index)); end loop; for index in 1 .. construction_limit loop load_entity (file, map.constructions (index)); end loop; for index in 1 .. equipment_limit loop load_entity (file, map.equipments (index)); end loop; for index in 1 .. unit_limit loop load_entity (file, map.units (index)); 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); -- time : float := 0.0; begin time := core.time; -- drawn_tiles := 0; drawn_views := 0; drawn_landmarks := 0; drawn_locations := 0; drawn_constructions := 0; drawn_equipments := 0; drawn_units := 0; -- 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_alternative (offset, view_from, view_to); -- draw_world_timer := natural (1_000_000.0 * (core.time - time)); end draw; ------------------------------------------------------------------------------------------ procedure draw_performance_box is width : constant integer := 640; height : constant integer := 8 * 15 + 2 * core.icon; x : constant integer := core.center_x (width); y : constant integer := core.center_y (height); begin ui.draw_text_box (x, y, width, height); -- ui.write ("draw_tiles_timer :" & draw_tiles_timer'image, x + 3 * core.icon, y + core.icon + 0 * 15, size => 15, code => true); ui.write ("draw_views_timer :" & draw_views_timer'image, x + 3 * core.icon, y + core.icon + 1 * 15, size => 15, code => true); ui.write ("draw_landmarks_timer :" & draw_landmarks_timer'image, x + 3 * core.icon, y + core.icon + 2 * 15, size => 15, code => true); ui.write ("draw_locations_timer :" & draw_locations_timer'image, x + 3 * core.icon, y + core.icon + 3 * 15, size => 15, code => true); ui.write ("draw_constructions_timer :" & draw_constructions_timer'image, x + 3 * core.icon, y + core.icon + 4 * 15, size => 15, code => true); ui.write ("draw_equipments_timer :" & draw_equipments_timer'image, x + 3 * core.icon, y + core.icon + 5 * 15, size => 15, code => true); ui.write ("draw_units_timer :" & draw_units_timer'image, x + 3 * core.icon, y + core.icon + 6 * 15, size => 15, code => true); ui.write ("draw_world_timer :" & draw_world_timer'image, x + 3 * core.icon, y + core.icon + 7 * 15, size => 15, code => true); -- ui.write (drawn_tiles'image, x + core.icon, y + core.icon + 0 * 15, size => 15, code => true, tint => (255, 0, 0, 255)); ui.write (drawn_views'image, x + core.icon, y + core.icon + 1 * 15, size => 15, code => true, tint => (255, 0, 0, 255)); ui.write (drawn_landmarks'image, x + core.icon, y + core.icon + 2 * 15, size => 15, code => true, tint => (255, 0, 0, 255)); ui.write (drawn_locations'image, x + core.icon, y + core.icon + 3 * 15, size => 15, code => true, tint => (255, 0, 0, 255)); ui.write (drawn_constructions'image, x + core.icon, y + core.icon + 4 * 15, size => 15, code => true, tint => (255, 0, 0, 255)); ui.write (drawn_equipments'image, x + core.icon, y + core.icon + 5 * 15, size => 15, code => true, tint => (255, 0, 0, 255)); ui.write (drawn_units'image, x + core.icon, y + core.icon + 6 * 15, size => 15, code => true, tint => (255, 0, 0, 255)); end draw_performance_box; ------------------------------------------------------------------------------------------ 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 => 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 .. landmark_limit loop core.render_image (data => landmarks (landmark_index'val (map.landmarks (index).index)), x => map.landmarks (index).x * core.base, y => map.landmarks (index).y * core.base, u => 0, v => 0, width => landmarks (landmark_index'val (map.landmarks (index).index)).width, height => landmarks (landmark_index'val (map.landmarks (index).index)).height); end loop; -- for index in 1 .. location_limit loop core.render_image (data => locations (location_index'val (map.locations (index).index)), x => map.locations (index).x * core.base, y => map.locations (index).y * core.base, u => 0, v => 0, width => locations (location_index'val (map.locations (index).index)).width, height => locations (location_index'val (map.locations (index).index)).height); end loop; -- for index in 1 .. construction_limit loop core.render_image (data => construction.sprite (construction.enumeration'val (map.constructions (index).index)), x => map.constructions (index).x * core.base, y => map.constructions (index).y * core.base, u => 0, v => 0, width => construction.sprite (construction.enumeration'val (map.constructions (index).index)).width, height => construction.sprite (construction.enumeration'val (map.constructions (index).index)).height); end loop; -- for index in 1 .. equipment_limit loop core.render_image (data => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)), x => map.equipments (index).x * core.base, y => map.equipments (index).y * core.base, u => 0, v => 0, width => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)).width, height => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)).height); end loop; -- core.export_image (file_path); -- core.echo (core.success, "Exported current world mapshot."); -- core.dash; end mapshot; ------------------------------------------------------------------------------------------ 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 add_chad (data : in chad.information) is begin core.echo_when (map.chad_count = map.chad_limit, core.failure, "Can't add new chad, limit reached."); core.increment (map.chad_count); -- map.chads (map.chad_count) := data; end add_chad; ------------------------------------------------------------------------------------------ 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 time : float := 0.0; step : core.vector := core.camera; size : constant integer := core.base * core.zoom; hits : natural := 0; begin time := core.time; -- 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 => 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 tiles (map.kind).frames), width => core.base, height => core.base, ignore => true); -- core.increment (drawn_tiles); -- 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; -- draw_tiles_timer := natural (1_000_000.0 * (core.time - time)); 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 > view_reach * 2) 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 time : float := 0.0; begin time := core.time; -- for index in 1 .. landmark_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 => landmarks (landmark_index'val (map.landmarks (index).index)), x => offset.x + (map.landmarks (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.landmarks (index).y - core.camera.y) * core.base * core.zoom); -- core.increment (drawn_landmarks); -- if core.cursor_inside (x => offset.x + (map.landmarks (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.landmarks (index).y - core.camera.y) * core.base * core.zoom, width => landmarks (landmark_index'val (map.landmarks (index).index)).width, height => landmarks (landmark_index'val (map.landmarks (index).index)).height) and core.cursor_mode = core.cursor_middle and not ui.prioritize then core.write_text_box (landmark_description (landmark_index'val (map.landmarks (index).index)).name.all); end if; end if; end loop; -- draw_landmarks_timer := natural (1_000_000.0 * (core.time - time)); end draw_landmarks; ------------------------------------------------------------------------------------------ procedure draw_locations (offset, view_from, view_to : in core.vector) is time : float := 0.0; sprite : core.sprite; begin time := core.time; -- for index in 1 .. location_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 => locations (location_index'val (map.locations (index).index)), x => offset.x + (map.locations (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.locations (index).y - core.camera.y) * core.base * core.zoom, state => core.animation'val (map.locations (index).state)); -- core.increment (drawn_locations); -- if core.cursor_inside (x => offset.x + (map.locations (index).x - core.camera.x) * core.base * core.zoom, y => offset.y + (map.locations (index).y - core.camera.y) * core.base * core.zoom, width => locations (location_index'val (map.locations (index).index)).width, height => locations (location_index'val (map.locations (index).index)).height) and core.cursor_mode = core.cursor_middle and not ui.prioritize then core.write_text_box (location_description (location_index'val (map.locations (index).index)).name.all); end if; end if; -- if map.locations (index).state = 1 and core.animation_time = 0 then map.locations (index).state := 2; end if; -- if core.camera.x > map.locations (index).x - 2 and core.camera.x < map.locations (index).x + 1 + locations (location_index'val (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 + locations (location_index'val (map.locations (index).index)).height / core.base and map.locations (index).state = 0 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 (location_index'val (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).state := 1; end if; end loop; -- draw_locations_timer := natural (1_000_000.0 * (core.time - time)); end draw_locations; ------------------------------------------------------------------------------------------ procedure draw_constructions (offset, view_from, view_to : in core.vector) is time : float := 0.0; x : integer := 0; y : integer := 0; -- this : construction.enumeration; begin time := core.time; -- for index in 1 .. construction_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 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; this := construction.enumeration'val (map.constructions (index).index); -- core.draw (construction.sprite (this), x, y); -- if core.cursor_inside (x, y, construction.sprite (this).width, construction.sprite (this).height) and core.cursor_mode = core.cursor_middle and not ui.prioritize then core.write_text_box (construction.description (this).name.all); end if; -- core.increment (drawn_constructions); end if; end loop; -- draw_constructions_timer := natural (1_000_000.0 * (core.time - time)); end draw_constructions; ------------------------------------------------------------------------------------------ procedure draw_equipments (offset, view_from, view_to : in core.vector) is time : float := 0.0; x : integer := 0; y : integer := 0; -- this : equipment.enumeration; begin time := core.time; -- for index in 1 .. equipment_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 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; this := equipment.enumeration'val (map.equipments (index).index); -- core.draw (equipment.sprite (this), x, y, state => core.idle); -- if core.cursor_inside (x, y, equipment.sprite (this).width, equipment.sprite (this).height) and core.cursor_mode = core.cursor_middle and equipment.enumeration'pos (this) /= equipment.enumeration'pos (equipment.none) and not ui.prioritize then core.write_text_box (equipment.description (this).name.all); end if; -- core.increment (drawn_equipments); end if; -- if map.equipments (index).x = core.camera.x and map.equipments (index).y = core.camera.y and core.signal_code'pos (core.signal_mode) = core.signal_code'pos (core.signal_e) then if map.chads (1).item_count < chad.item_limit and map.equipments (index).index /= equipment.enumeration'pos (equipment.none) then map.chads (1).items (map.chads (1).item_count) := equipment.enumeration'val (map.equipments (index).index); -- core.increment (map.chads (1).item_count); -- map.equipments (index).index := equipment.enumeration'pos (equipment.none); end if; end if; end loop; -- draw_equipments_timer := natural (1_000_000.0 * (core.time - time)); end draw_equipments; ------------------------------------------------------------------------------------------ procedure draw_unit (data : in unit.enumeration; state : in core.animation; x, y : in integer) is begin core.draw (unit.base (unit.description (data).kind), x, y, state => state); -- for kind in equipment.kind loop core.draw (equipment.sprite (unit.description (data).equipments (kind)), x, y, state => state); end loop; end draw_unit; ------------------------------------------------------------------------------------------ procedure show_unit is data : unit.definition := unit.description (show_unit_data); -- offset : constant integer := 8; width : constant integer := 640; more : constant natural := 10; less : constant natural := 5; height : constant integer := chad.view_height + 4 * core.icon + 2 * core.base + 3 * ui.monoheight + 2 * more + 2 * offset; at_x : integer := core.center_x (width) + offset; at_y : integer := core.center_y (height) + offset; begin ui.draw_frame (core.center_x (width), core.center_y (height), width, height); -- ui.draw_sprite (unit.view (show_unit_data), data.name.all, at_x, at_y, 0); -- at_x := at_x + unit.view_width; -- ui.draw_text_box (at_x, at_y, width - unit.view_width - 2 * offset, core.icon); ui.write (data.name.all, at_x + less, at_y + less); -- for index in attribute.enumeration loop if attribute.enumeration'pos (index) = attribute.count / 2 or attribute.enumeration'pos (index) = 0 then -- hack at_y := at_y + core.icon; at_x := core.center_x (width) + offset + unit.view_width; end if; -- ui.draw_icon_menu (at_x, at_y, core.icon * 3, core.icon, attribute.description (index).text.all); core.draw (attribute.icon (index), at_x, at_y, factor => 1); ui.write (data.attributes (index)'image, at_x + core.icon + more, at_y + more, code => true); -- at_x := at_x + 3 * core.icon; end loop; -- at_x := core.center_x (width) + offset; at_y := core.center_y (height) + offset + unit.view_height; -- ui.draw_separator (at_x, at_y, width - 2 * offset); -- at_y := at_y + core.base; -- ui.draw_text ("Hiring fee:" & data.hiring_fee'image & character'val (10) & "Weekly fee:" & data.weekly_fee'image & character'val (10) & "Battle fee:" & data.battle_fee'image, at_x, at_y, (width - 3 * offset) / 2 - 2 * more, 0, 0, more); ui.draw_text ("Faction: " & faction.description (data.kind).name.all & character'val (10) & "Stack:" & data.limit'image & character'val (10) & "Bonus: " & attribute.description (faction.description (data.kind).bonus_attribute).name.all, at_x + (width - offset) / 2, at_y, (width - 3 * offset) / 2 - 2 * more, 0, 0, more); -- at_y := at_y + 3 * ui.monoheight + 2 * more; -- ui.draw_separator (at_x, at_y, width - 2 * offset); -- at_y := at_y + core.base - core.icon; -- for index in equipment.kind loop if equipment.kind'pos (index) mod 2 = 0 then -- hack at_y := at_y + core.icon; at_x := core.center_x (width) + offset; end if; -- ui.draw_icon_menu (at_x, at_y, (width - 2 * offset) / 2, core.icon, equipment.description (data.equipments (index)).name.all); ui.write (equipment.description (data.equipments (index)).name.all, at_x + core.icon + more, at_y + more, code => true); -- if equipment.enumeration'pos (data.equipments (index)) /= equipment.enumeration'pos (equipment.none) then core.draw (equipment.icon (data.equipments (index)), at_x, at_y, factor => 1); else core.draw (equipment.slot (index), at_x, at_y, factor => 1); end if; -- at_x := at_x + (width - 2 * offset) / 2; end loop; end show_unit; ------------------------------------------------------------------------------------------ procedure draw_units (offset, view_from, view_to : in core.vector) is time : float := 0.0; begin time := core.time; -- for index in 1 .. unit_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 => unit.enumeration'val (map.units (index).index), state => core.animation'val (map.units (index).state), 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); -- core.increment (drawn_units); end if; end loop; -- for index in 1 .. map.chad_count loop if map.views (map.chads (index).x, map.chads (index).y) then core.draw (data => chad.sprite (map.chads (index).index), 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, state => map.chads (index).state); -- for kind in equipment.kind loop core.draw (data => equipment.sprite (map.chads (index).equipments (kind)), 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, state => map.chads (index).state); end loop; -- core.increment (drawn_units); end if; end loop; -- draw_units_timer := natural (1_000_000.0 * (core.time - time)); end draw_units; ------------------------------------------------------------------------------------------ procedure draw_alternative (offset, view_from, view_to : in core.vector) is time : float := 0.0; begin time := core.time; -- 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 > view_reach then core.draw (data => dark, x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom, y => offset.y + (vertical - core.camera.y) * core.base * core.zoom); -- core.increment (drawn_views); end if; end loop; end loop; -- draw_views_timer := natural (1_000_000.0 * (core.time - time)); 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;