xhads/source/world.adb

1292 lines
63 KiB
Ada
Raw Normal View History

-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
--
-- GNU General Public Licence (version 3 or later)
2024-02-15 21:03:09 -05:00
package body world is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
view_reach : constant integer := 96;
2024-05-26 16:20:08 -04:00
lake_count : constant natural := 6;
2024-05-25 08:56:49 -04:00
2024-06-02 08:11:48 -04:00
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;
2024-06-02 08:11:48 -04:00
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;
2024-05-08 17:14:49 -04:00
2024-06-01 20:42:12 -04:00
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;
2024-05-08 17:14:49 -04:00
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
procedure generate_lake (x, y : in integer; size : in natural);
2024-06-05 09:40:18 -04:00
procedure compute_world_visibility_grid (offset : in core.vector);
procedure compute_world_frame (offset : in core.vector);
2024-06-05 09:40:18 -04:00
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
2024-05-27 12:45:31 -04:00
begin
2024-06-05 09:40:18 -04:00
core.echo (core.comment, "Configuring world components...");
2024-05-27 12:45:31 -04:00
--
for index in biome.enumeration loop
biome.tiles (index) := core.import_sprite (core.folder & "/game/world/terrain/" & core.lowercase (index'image) & ".png", 4, 1);
2024-05-27 12:45:31 -04:00
end loop;
--
2024-06-05 09:40:18 -04:00
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);
2024-06-02 08:42:47 -04:00
--
for index in landmark.enumeration loop
landmark.game (index) := core.import_sprite (file_path => core.folder & "/game/world/landmark/" & core.lowercase (index'image) & ".png",
frames => landmark.description (index).frames,
states => 1);
2024-06-05 09:40:18 -04:00
end loop;
--
for index in location.enumeration loop
location.game (index) := core.import_sprite (file_path => core.folder & "/game/world/location/" & core.lowercase (index'image) & ".png",
frames => location.description (index).frames,
states => 2);
2024-06-05 09:40:18 -04:00
end loop;
end configure;
2024-05-27 12:45:31 -04:00
------------------------------------------------------------------------------------------
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;
2024-05-27 12:45:31 -04:00
begin
this.index := landmark.enumeration'val (core.random (0, landmark.count - 1));
<<repeat_landmark_generation>>
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;
<<repeat_location_generation>>
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));
<<repeat_construction_generation>>
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));
<<repeat_equipment_generation>>
this.x := core.random (0, map.width - 1);
this.y := core.random (0, map.height - 1);
--
if map.clips (this.x, this.y) then
goto repeat_equipment_generation;
end if;
--
return this;
end random_equipment;
------------------------------------------------------------------------------------------
function random_unit return unit.information is
this : unit.information;
begin
this.index := unit.enumeration'val (core.random (1, unit.count - 1)); -- none
this.count := core.random (1, 10);
this.enemy := true;
<<repeat_unit_generation>>
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);
2024-06-05 09:40:18 -04:00
--
map.landmarks (this) := data;
--
if landmark.description (map.landmarks (this).index).clip then
declare reach_x : constant natural := landmark.game (map.landmarks (this).index).width / core.base;
reach_y : constant natural := landmark.game (map.landmarks (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.landmarks (this).x + x, map.landmarks (this).y + y) := true;
end loop;
end loop;
end;
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 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...");
2024-06-05 09:40:18 -04:00
--
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);
2024-06-05 09:40:18 -04:00
--
2024-06-10 04:15:35 -04:00
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);
2024-06-10 04:25:10 -04:00
map.equipments := new equipment.informations (1 .. equipment_limit);
2024-06-10 04:38:05 -04:00
map.units := new unit.informations (1 .. unit_limit);
map.chads := new chad.informations (1 .. chad_limit);
2024-06-05 09:40:18 -04:00
--
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;
2024-05-27 12:45:31 -04:00
end loop;
end loop;
--
2024-06-05 09:40:18 -04:00
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;
2024-05-27 12:45:31 -04:00
--
2024-06-05 09:40:18 -04:00
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;
2024-05-27 12:45:31 -04:00
end if;
2024-06-05 09:40:18 -04:00
end loop;
2024-05-27 12:45:31 -04:00
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;
2024-05-27 12:45:31 -04:00
--
2024-06-05 09:40:18 -04:00
core.echo (core.success, "Finished procedurally generating new map.");
end make;
2024-02-15 21:03:09 -05:00
------------------------------------------------------------------------------------------
procedure save (file_name : in string) is
2024-05-25 03:00:30 -04:00
file : core.io.file_type;
begin
2024-05-25 03:00:30 -04:00
core.io.create (file, core.io.out_file, core.folder & "/map/" & file_name);
--
core.io.write (file, biome.enumeration'pos (map.kind));
2024-05-25 03:00:30 -04:00
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);
2024-05-25 03:00:30 -04:00
--
for x in 0 .. map.width - 1 loop
for y in 0 .. map.height - 1 loop
core.io.write (file, map.tiles (x, y));
2024-05-25 03:00:30 -04:00
core.io.write (file, boolean'pos (map.clips (x, y)));
core.io.write (file, boolean'pos (map.views (x, y)));
end loop;
end loop;
--
for index in 1 .. map.landmark_count.limit loop core.io.write (file, landmark.enumeration'pos (map.landmarks (index).index)); end loop;
for index in 1 .. map.location_count.limit loop core.io.write (file, location.enumeration'pos (map.locations (index).index)); end loop;
for index in 1 .. map.construction_count.limit loop core.io.write (file, construction.enumeration'pos (map.constructions (index).index)); end loop;
for index in 1 .. map.equipment_count.limit loop core.io.write (file, equipment.enumeration'pos (map.equipments (index).index)); end loop;
for index in 1 .. map.unit_count.limit loop core.io.write (file, unit.enumeration'pos (map.units (index).index)); end loop;
--
for index in 1 .. map.location_count.limit loop core.io.write (file, boolean'pos (map.locations (index).used)); end loop;
for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).count); end loop;
for index in 1 .. map.unit_count.limit loop core.io.write (file, boolean'pos (map.units (index).enemy)); end loop;
--
for index in 1 .. map.landmark_count.limit loop core.io.write (file, map.landmarks (index).x); end loop;
for index in 1 .. map.landmark_count.limit loop core.io.write (file, map.landmarks (index).y); end loop;
for index in 1 .. map.location_count.limit loop core.io.write (file, map.locations (index).x); end loop;
for index in 1 .. map.location_count.limit loop core.io.write (file, map.locations (index).y); end loop;
for index in 1 .. map.construction_count.limit loop core.io.write (file, map.constructions (index).x); end loop;
for index in 1 .. map.construction_count.limit loop core.io.write (file, map.constructions (index).y); end loop;
for index in 1 .. map.equipment_count.limit loop core.io.write (file, map.equipments (index).x); end loop;
for index in 1 .. map.equipment_count.limit loop core.io.write (file, map.equipments (index).y); end loop;
for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).x); end loop;
for index in 1 .. map.unit_count.limit loop core.io.write (file, map.units (index).y); end loop;
2024-05-25 03:00:30 -04:00
--
2024-06-03 15:49:56 -04:00
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;
--
2024-06-09 11:07:49 -04:00
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;
--
2024-06-06 10:31:17 -04:00
for kind in equipment.kind loop
core.io.write (file, equipment.enumeration'pos (map.chads (1).equipments (kind)));
2024-06-03 15:49:56 -04:00
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;
2024-05-25 03:19:58 -04:00
--
2024-06-09 12:38:38 -04:00
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;
--
2024-05-25 03:00:30 -04:00
core.io.close (file);
--
core.echo (core.success, "Saved current map as '" & file_name & "'.");
--
core.dash;
end save;
------------------------------------------------------------------------------------------
procedure load (file_name : in string) is
file : core.io.file_type;
this : integer;
begin
core.io.open (file, core.io.in_file, core.folder & "/map/" & file_name);
--
core.io.read (file, this); map.kind := biome.enumeration'val (this);
core.io.read (file, map.width);
core.io.read (file, map.height);
--
core.load_point (file, map.landmark_count);
core.load_point (file, map.location_count);
core.load_point (file, map.construction_count);
core.load_point (file, map.equipment_count);
core.load_point (file, map.unit_count);
core.load_point (file, map.chad_count);
--
for x in 0 .. map.width - 1 loop
for y in 0 .. map.height - 1 loop
core.io.read (file, map.tiles (x, y));
core.io.read (file, this); map.clips (x, y) := boolean'val (this);
core.io.read (file, this); map.views (x, y) := boolean'val (this);
end loop;
end loop;
--
for index in 1 .. map.landmark_count.limit loop core.io.read (file, this); map.landmarks (index).index := landmark.enumeration'val (this); end loop;
for index in 1 .. map.location_count.limit loop core.io.read (file, this); map.locations (index).index := location.enumeration'val (this); end loop;
for index in 1 .. map.construction_count.limit loop core.io.read (file, this); map.constructions (index).index := construction.enumeration'val (this); end loop;
for index in 1 .. map.equipment_count.limit loop core.io.read (file, this); map.equipments (index).index := equipment.enumeration'val (this); end loop;
for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).index := unit.enumeration'val (this); end loop;
--
for index in 1 .. map.location_count.limit loop core.io.read (file, this); map.locations (index).used := boolean'val (this); end loop;
for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).count := this; end loop;
for index in 1 .. map.unit_count.limit loop core.io.read (file, this); map.units (index).enemy := boolean'val (this); end loop;
--
for index in 1 .. map.landmark_count.limit loop core.io.read (file, map.landmarks (index).x); end loop;
for index in 1 .. map.landmark_count.limit loop core.io.read (file, map.landmarks (index).y); end loop;
for index in 1 .. map.location_count.limit loop core.io.read (file, map.locations (index).x); end loop;
for index in 1 .. map.location_count.limit loop core.io.read (file, map.locations (index).y); end loop;
for index in 1 .. map.construction_count.limit loop core.io.read (file, map.constructions (index).x); end loop;
for index in 1 .. map.construction_count.limit loop core.io.read (file, map.constructions (index).y); end loop;
for index in 1 .. map.equipment_count.limit loop core.io.read (file, map.equipments (index).x); end loop;
for index in 1 .. map.equipment_count.limit loop core.io.read (file, map.equipments (index).y); end loop;
for index in 1 .. map.unit_count.limit loop core.io.read (file, map.units (index).x); end loop;
for index in 1 .. map.unit_count.limit loop core.io.read (file, map.units (index).y); end loop;
--
2024-06-03 15:49:56 -04:00
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;
--
2024-06-09 11:07:49 -04:00
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;
--
2024-06-06 10:31:17 -04:00
for kind in equipment.kind loop
core.io.read (file, this); map.chads (1).equipments (kind) := equipment.enumeration'val (this);
2024-06-03 15:49:56 -04:00
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;
--
2024-06-09 12:38:38 -04:00
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;
--
2024-06-05 09:40:18 -04:00
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 => biome.tiles (map.kind),
2024-06-05 09:40:18 -04:00
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
2024-06-09 19:58:49 -04:00
core.render_image (data => landmark.game (map.landmarks (index).index),
2024-06-05 09:40:18 -04:00
x => map.landmarks (index).x * core.base,
y => map.landmarks (index).y * core.base,
u => 0,
v => 0,
2024-06-09 19:58:49 -04:00
width => landmark.game (map.landmarks (index).index).width,
height => landmark.game (map.landmarks (index).index).height);
2024-06-05 09:40:18 -04:00
end loop;
--
for index in 1 .. map.location_count.limit loop
core.render_image (data => location.game (map.locations (index).index),
2024-06-05 09:40:18 -04:00
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);
2024-06-05 09:40:18 -04:00
end loop;
--
for index in 1 .. map.construction_count.limit loop
2024-06-10 04:15:35 -04:00
core.render_image (data => construction.game (map.constructions (index).index),
2024-06-05 09:40:18 -04:00
x => map.constructions (index).x * core.base,
y => map.constructions (index).y * core.base,
u => 0,
v => 0,
2024-06-10 04:15:35 -04:00
width => construction.game (map.constructions (index).index).width,
height => construction.game (map.constructions (index).index).height);
2024-06-05 09:40:18 -04:00
end loop;
--
for index in 1 .. map.equipment_count.limit loop
2024-06-10 04:25:10 -04:00
core.render_image (data => equipment.game (map.equipments (index).index),
2024-06-05 09:40:18 -04:00
x => map.equipments (index).x * core.base,
y => map.equipments (index).y * core.base,
u => 0,
v => 0,
2024-06-10 04:25:10 -04:00
width => equipment.game (map.equipments (index).index).width,
height => equipment.game (map.equipments (index).index).height);
2024-06-05 09:40:18 -04:00
end loop;
--
core.export_image (file_path);
--
core.echo (core.success, "Exported current world mapshot.");
--
core.dash;
end mapshot;
------------------------------------------------------------------------------------------
function map_is_revealed return boolean is
begin
for x in 0 .. map.width - 1 loop
for y in 0 .. map.height - 1 loop
if map.views (x, y) = false then
return false;
end if;
end loop;
end loop;
--
return true;
end map_is_revealed;
------------------------------------------------------------------------------------------
procedure resource_cheat_1 is begin core.increment (map.chads (1).resources (resource.gold).value, 20); end resource_cheat_1;
procedure resource_cheat_2 is begin core.increment (map.chads (1).resources (resource.wood).value, 10); end resource_cheat_2;
procedure resource_cheat_3 is begin core.increment (map.chads (1).resources (resource.stone).value, 10); end resource_cheat_3;
procedure resource_cheat_4 is begin core.increment (map.chads (1).resources (resource.metal).value, 10); end resource_cheat_4;
procedure resource_cheat_5 is begin core.increment (map.chads (1).resources (resource.leather).value, 10); end resource_cheat_5;
procedure resource_cheat_6 is begin core.increment (map.chads (1).resources (resource.gem).value, 10); end resource_cheat_6;
------------------------------------------------------------------------------------------
procedure reveal_map is
begin
for x in 0 .. map.width - 1 loop
for y in 0 .. map.height - 1 loop
map.views (x, y) := true;
end loop;
end loop;
end reveal_map;
------------------------------------------------------------------------------------------
procedure restore_points is
begin
map.chads (1).health.value := map.chads (1).health.limit;
map.chads (1).mana.value := map.chads (1).mana.limit;
map.chads (1).movement.value := map.chads (1).movement.limit;
end restore_points;
------------------------------------------------------------------------------------------
procedure player_up is
begin
if map.chads (1).movement.value = 0 then return; end if;
core.decrement (map.chads (1).y);
core.clip (map.chads (1).y, 0, map.height - 1);
map.chads (1).movement := map.chads (1).movement - 1;
if map.clips (map.chads (1).x, map.chads (1).y) then
core.increment (map.chads (1).y);
if map.chads (1).movement.value > 0 then
map.chads (1).movement := map.chads (1).movement + 1;
end if;
end if;
end player_up;
------------------------------------------------------------------------------------------
procedure player_down is
begin
if map.chads (1).movement.value = 0 then return; end if;
core.increment (map.chads (1).y);
core.clip (map.chads (1).y, 0, map.height - 1);
map.chads (1).movement := map.chads (1).movement - 1;
if map.clips (map.chads (1).x, map.chads (1).y) then
core.decrement (map.chads (1).y);
if map.chads (1).movement.value > 0 then
map.chads (1).movement := map.chads (1).movement + 1;
end if;
end if;
end player_down;
------------------------------------------------------------------------------------------
procedure player_left is
begin
if map.chads (1).movement.value = 0 then return; end if;
core.decrement (map.chads (1).x);
core.clip (map.chads (1).x, 0, map.width - 1);
map.chads (1).movement := map.chads (1).movement - 1;
if map.clips (map.chads (1).x, map.chads (1).y) then
core.increment (map.chads (1).x);
if map.chads (1).movement.value > 0 then
map.chads (1).movement := map.chads (1).movement + 1;
end if;
end if;
end player_left;
------------------------------------------------------------------------------------------
procedure player_right is
begin
if map.chads (1).movement.value = 0 then return; end if;
core.increment (map.chads (1).x);
core.clip (map.chads (1).x, 0, map.width - 1);
map.chads (1).movement := map.chads (1).movement - 1;
if map.clips (map.chads (1).x, map.chads (1).y) then
core.decrement (map.chads (1).x);
if map.chads (1).movement.value > 0 then
map.chads (1).movement := map.chads (1).movement + 1;
end if;
end if;
end player_right;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
procedure generate_lake (x, y : in integer; size : in natural) is
starts, length : integer;
begin
for offset_x in -size / 2 .. size / 2 loop
starts := core.random (0, abs offset_x);
length := core.random (size / 2, size - starts);
--
for repeat in 0 .. 1 loop
for offset_y in starts .. starts + length loop
map.tiles (x + 2 * offset_x + repeat, y + offset_y) := core.random (18, 23);
end loop;
end loop;
end loop;
end generate_lake;
------------------------------------------------------------------------------------------
procedure draw_tiles (offset, view_from, view_to : in core.vector) is
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 => biome.tiles (map.kind),
2024-06-05 09:40:18 -04:00
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),
2024-06-05 09:40:18 -04:00
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;
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
procedure compute_world_visibility_grid (offset : in core.vector) is
2024-02-15 21:03:09 -05:00
begin
2024-06-05 09:40:18 -04:00
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;
2024-02-15 21:03:09 -05:00
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
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);
2024-06-01 20:42:12 -04:00
begin
2024-06-05 09:40:18 -04:00
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);
2024-06-01 20:42:12 -04:00
--
2024-06-05 09:40:18 -04:00
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;
2024-06-01 20:42:12 -04:00
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
procedure draw_landmarks (offset, view_from, view_to : in core.vector) is
time : float := 0.0;
begin
2024-06-05 09:40:18 -04:00
time := core.time;
--
for index in 1 .. map.landmark_count.limit loop
2024-06-05 09:40:18 -04:00
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
2024-06-09 19:58:49 -04:00
core.draw (data => landmark.game (map.landmarks (index).index),
2024-06-05 09:40:18 -04:00
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,
2024-06-09 19:58:49 -04:00
width => landmark.game (map.landmarks (index).index).width,
height => landmark.game (map.landmarks (index).index).height)
2024-06-05 09:40:18 -04:00
and core.cursor_mode = core.cursor_middle
and not ui.prioritize then
2024-06-09 19:58:49 -04:00
core.write_text_box (landmark.description (map.landmarks (index).index).name.all);
2024-06-05 09:40:18 -04:00
end if;
end if;
end loop;
--
2024-06-05 09:40:18 -04:00
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;
2024-06-05 09:40:18 -04:00
begin
time := core.time;
--
for index in 1 .. map.location_count.limit loop
2024-06-05 09:40:18 -04:00
if map.views (map.locations (index).x, map.locations (index).y)
and map.locations (index).x > view_from.x and map.locations (index).x < view_from.x + view_to.x
and map.locations (index).y > view_from.y and map.locations (index).y < view_from.y + view_to.y then
core.draw (data => location.game (map.locations (index).index),
2024-06-05 09:40:18 -04:00
x => offset.x + (map.locations (index).x - core.camera.x) * core.base * core.zoom,
y => offset.y + (map.locations (index).y - core.camera.y) * core.base * core.zoom,
state => core.animation'val (boolean'pos (map.locations (index).used)));
2024-06-05 09:40:18 -04:00
--
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 => location.game (map.locations (index).index).width,
height => location.game (map.locations (index).index).height)
2024-06-05 09:40:18 -04:00
and core.cursor_mode = core.cursor_middle
and not ui.prioritize then
core.write_text_box (location.description (map.locations (index).index).name.all);
2024-06-05 09:40:18 -04:00
end if;
end if;
--
if core.camera.x > map.locations (index).x - 2
and core.camera.x < map.locations (index).x + 1 + location.game (map.locations (index).index).width / core.base
2024-06-05 09:40:18 -04:00
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
2024-06-05 09:40:18 -04:00
and core.signal_code'pos (core.signal_mode) = core.signal_code'pos (core.signal_e)
and not ui.prioritize then
declare player : chad.information renames world.map.chads (1);
--
data : effect.information := location.description (map.locations (index).index).evoke;
2024-06-05 09:40:18 -04:00
--
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.");
2024-06-05 09:40:18 -04:00
--
when effect.modify_resource => resource_index := resource.enumeration'val (data.modifier);
player.resources (resource_index) := player.resources (resource_index) + data.amount;
ui.echo ("Player " & (if data.amount < 0 then "lost" else "gained") & integer'image (abs data.amount) & " "
& resource.description (resource_index).name.all & " resource points.");
--
when effect.modify_material => material_index := material.enumeration'val (data.modifier);
player.materials (material_index) := player.materials (material_index) + data.amount;
ui.echo ("+" & data.amount'image & " " & material.description (material_index).name.all);
end case;
end;
--
map.locations (index).used := true;
2024-06-05 09:40:18 -04:00
end if;
end loop;
--
2024-06-05 09:40:18 -04:00
draw_locations_timer := natural (1_000_000.0 * (core.time - time));
end draw_locations;
2024-05-12 10:07:37 -04:00
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
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;
2024-05-12 10:07:37 -04:00
begin
2024-06-05 09:40:18 -04:00
time := core.time;
--
for index in 1 .. map.construction_count.limit loop
2024-06-05 09:40:18 -04:00
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;
2024-06-10 04:15:35 -04:00
this := map.constructions (index).index;
2024-06-05 09:40:18 -04:00
--
2024-06-10 04:15:35 -04:00
core.draw (construction.game (this), x, y);
2024-06-05 09:40:18 -04:00
--
2024-06-10 04:15:35 -04:00
if core.cursor_inside (x, y, construction.game (this).width, construction.game (this).height)
2024-06-05 09:40:18 -04:00
and core.cursor_mode = core.cursor_middle
and not ui.prioritize then
core.write_text_box (construction.description (this).name.all);
2024-05-22 21:22:34 -04:00
end if;
2024-06-05 09:40:18 -04:00
--
core.increment (drawn_constructions);
end if;
2024-05-12 10:07:37 -04:00
end loop;
2024-05-22 21:22:34 -04:00
--
2024-06-05 09:40:18 -04:00
draw_constructions_timer := natural (1_000_000.0 * (core.time - time));
end draw_constructions;
2024-05-12 10:07:37 -04:00
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
procedure draw_equipments (offset, view_from, view_to : in core.vector) is
time : float := 0.0;
x : integer := 0;
y : integer := 0;
--
2024-06-05 09:40:18 -04:00
this : equipment.enumeration;
2024-05-22 21:22:34 -04:00
begin
2024-06-05 09:40:18 -04:00
time := core.time;
--
for index in 1 .. map.equipment_count.limit loop
2024-06-05 09:40:18 -04:00
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;
2024-06-10 04:25:10 -04:00
this := map.equipments (index).index;
2024-06-05 09:40:18 -04:00
--
2024-06-10 04:25:10 -04:00
core.draw (equipment.game (this), x, y, state => core.idle);
2024-06-05 09:40:18 -04:00
--
2024-06-10 04:25:10 -04:00
if core.cursor_inside (x, y, equipment.game (this).width, equipment.game (this).height)
2024-06-05 09:40:18 -04:00
and core.cursor_mode = core.cursor_middle
and equipment_valid (this)
2024-06-05 09:40:18 -04:00
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
2024-06-10 04:25:10 -04:00
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;
2024-06-05 09:40:18 -04:00
--
core.increment (map.chads (1).item_count);
--
2024-06-10 04:25:10 -04:00
map.equipments (index).index := equipment.none;
2024-06-05 09:40:18 -04:00
end if;
end if;
2024-05-22 21:22:34 -04:00
end loop;
2024-06-05 09:40:18 -04:00
--
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, factor : in integer) is
2024-06-09 12:38:38 -04:00
begin
core.draw (unit.base (unit.description (data).kind), x, y, state => state, factor => factor);
2024-06-09 12:38:38 -04:00
--
for kind in equipment.kind loop
2024-06-10 04:25:10 -04:00
core.draw (equipment.game (unit.description (data).equipments (kind)), x, y, state => state, factor => factor);
2024-06-09 12:38:38 -04:00
end loop;
end draw_unit;
------------------------------------------------------------------------------------------
2024-06-09 12:57:11 -04:00
procedure show_unit is
2024-06-09 17:45:44 -04:00
data : unit.definition := unit.description (show_unit_data);
from : faction.definition := faction.description (data.kind);
2024-06-09 14:39:09 -04:00
--
offset : constant integer := 8;
2024-06-09 14:55:53 -04:00
more : constant natural := 10;
less : constant natural := 5;
2024-06-09 17:45:44 -04:00
boxy : constant natural := 3 * ui.monoheight + 2 * more;
width : constant integer := chad.view_width + 3 * 2 * core.icon + 2 * offset;
height : constant integer := chad.view_height + 8 * core.icon + 2 * core.base + boxy + 2 * offset;
2024-06-09 12:57:11 -04:00
begin
2024-06-09 17:45:44 -04:00
ui.draw_frame (core.center_x (width), core.center_y (height), width, height);
ui.draw_sprite (unit.view (show_unit_data), data.name.all, core.center_x (width) + offset, core.center_y (height) + offset, 0);
ui.write (data.name.all, core.center_x (width) + offset + unit.view_width + less, core.center_y (height) + offset + less);
2024-06-09 14:55:53 -04:00
--
for index in attribute.enumeration loop
2024-06-09 17:45:44 -04:00
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);
2024-06-09 14:55:53 -04:00
end loop;
--
2024-06-09 17:45:44 -04:00
ui.draw_separator (core.center_x (width) + offset, core.center_y (height) + offset + unit.view_height, width - 2 * offset);
2024-06-09 14:39:09 -04:00
--
2024-06-09 18:39:01 -04:00
ui.draw_text (text => "Hiring fee:" & data.hiring_fee'image & core.line_feed &
"Weekly fee:" & data.weekly_fee'image & core.line_feed &
2024-06-09 17:45:44 -04:00
"Battle fee:" & data.battle_fee'image,
x => core.center_x (width) + offset,
y => core.center_y (height) + offset + unit.view_height + core.base,
width => width - 2 * (offset + more),
border => more);
2024-06-09 14:39:09 -04:00
--
2024-06-09 17:45:44 -04:00
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,
2024-06-09 17:45:44 -04:00
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;
2024-06-09 12:57:11 -04:00
end show_unit;
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
procedure draw_units (offset, view_from, view_to : in core.vector) is
time : float := 0.0;
begin
2024-06-05 09:40:18 -04:00
time := core.time;
--
for index in 1 .. map.unit_count.limit loop
2024-06-05 09:40:18 -04:00
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
2024-06-10 04:38:05 -04:00
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);
2024-06-05 09:40:18 -04:00
--
core.increment (drawn_units);
end if;
2024-06-05 09:40:18 -04:00
end loop;
--
for index in 1 .. map.chad_count.value loop
2024-06-05 09:40:18 -04:00
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);
--
2024-06-06 10:31:17 -04:00
for kind in equipment.kind loop
2024-06-10 04:25:10 -04:00
core.draw (data => equipment.game (map.chads (index).equipments (kind)),
2024-06-05 09:40:18 -04:00
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;
2024-06-05 09:40:18 -04:00
end loop;
--
draw_units_timer := natural (1_000_000.0 * (core.time - time));
end draw_units;
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
procedure draw_alternative (offset, view_from, view_to : in core.vector) is
time : float := 0.0;
begin
2024-06-05 09:40:18 -04:00
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;
------------------------------------------------------------------------------------------
2024-06-05 09:40:18 -04:00
procedure compute_earth_to_water_transition is
matrix : array (0 .. 1, 0 .. 1) of natural;
begin
2024-06-05 09:40:18 -04:00
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;
2024-02-15 21:03:09 -05:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end world;