2024-04-25 00:27:13 -04:00
|
|
|
-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
|
|
|
|
--
|
|
|
|
-- GNU General Public Licence (version 3 or later)
|
|
|
|
|
2024-05-11 03:38:33 -04:00
|
|
|
with core, ui, resource, equipment, unit, construction;
|
2024-02-15 21:03:09 -05:00
|
|
|
|
|
|
|
package body world is
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2024-05-08 18:06:37 -04:00
|
|
|
view_reach : constant integer := 48;
|
|
|
|
|
2024-05-11 05:13:45 -04:00
|
|
|
construction_limit : constant natural := 120;
|
|
|
|
equipment_limit : constant natural := 600;
|
|
|
|
unit_limit : constant natural := 600;
|
|
|
|
|
2024-05-09 06:16:11 -04:00
|
|
|
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-05-08 17:14:49 -04:00
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-02-15 21:03:09 -05:00
|
|
|
procedure configure is
|
|
|
|
begin
|
2024-03-11 08:42:25 -04:00
|
|
|
core.echo (core.comment, "Configuring world components...");
|
|
|
|
--
|
2024-05-09 06:16:11 -04:00
|
|
|
tiles := core.import_sprite ("./sprite/world/terrain/terrain.png", 1, 1);
|
|
|
|
dark := core.import_sprite ("./sprite/world/dark.png", 1, 1);
|
|
|
|
border_upper := core.import_sprite ("./sprite/world/frame/border_upper.png", 1, 1);
|
|
|
|
border_lower := core.import_sprite ("./sprite/world/frame/border_lower.png", 1, 1);
|
|
|
|
border_left := core.import_sprite ("./sprite/world/frame/border_left.png", 1, 1);
|
|
|
|
border_right := core.import_sprite ("./sprite/world/frame/border_right.png", 1, 1);
|
|
|
|
corner_upper_left := core.import_sprite ("./sprite/world/frame/corner_upper_left.png", 1, 1);
|
|
|
|
corner_upper_right := core.import_sprite ("./sprite/world/frame/corner_upper_right.png", 1, 1);
|
|
|
|
corner_lower_left := core.import_sprite ("./sprite/world/frame/corner_lower_left.png", 1, 1);
|
|
|
|
corner_lower_right := core.import_sprite ("./sprite/world/frame/corner_lower_right.png", 1, 1);
|
2024-02-15 21:03:09 -05:00
|
|
|
--
|
2024-04-26 19:46:09 -04:00
|
|
|
for index in landmark_index loop
|
|
|
|
declare file : constant string := core.lowercase (index'image);
|
|
|
|
begin
|
|
|
|
landmarks (index) := core.import_sprite ("./sprite/world/landmark/" & file & ".png", trait (index).frames, 1);
|
|
|
|
end;
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
end configure;
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-26 19:46:09 -04:00
|
|
|
procedure make (index : in biome; width, height : in natural) is
|
2024-02-15 21:03:09 -05:00
|
|
|
begin
|
2024-03-21 18:28:26 -04:00
|
|
|
core.echo (core.comment, "-- Procedurally generating new map...");
|
2024-04-25 04:14:45 -04:00
|
|
|
--
|
2024-05-05 11:38:15 -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);
|
2024-03-21 18:28:26 -04:00
|
|
|
--
|
2024-05-05 11:46:56 -04:00
|
|
|
map.kind := index;
|
|
|
|
map.width := width;
|
|
|
|
map.height := height;
|
|
|
|
--
|
|
|
|
map.tiles := new tile_array (0 .. map.width - 1, 0 .. map.height - 1);
|
2024-05-06 08:38:47 -04:00
|
|
|
map.clips := new clip_array (0 .. map.width - 1, 0 .. map.height - 1);
|
2024-05-06 13:59:08 -04:00
|
|
|
map.views := new view_array (0 .. map.width - 1, 0 .. map.height - 1);
|
2024-05-05 11:46:56 -04:00
|
|
|
map.landmarks := new entity_array (1 .. landmark_limit);
|
2024-05-11 05:13:45 -04:00
|
|
|
map.constructions := new entity_array (1 .. construction_limit);
|
2024-05-13 09:20:16 -04:00
|
|
|
map.equipments := new entity_array (1 .. equipment_limit);
|
2024-05-11 05:13:45 -04:00
|
|
|
map.units := new entity_array (1 .. unit_limit);
|
2024-02-15 21:03:09 -05:00
|
|
|
--
|
2024-04-27 03:49:02 -04:00
|
|
|
for x in 0 .. width - 1 loop
|
|
|
|
for y in 0 .. height - 1 loop
|
2024-05-09 06:16:11 -04:00
|
|
|
map.tiles (x, y) := (if core.random (0, 23) < 20 then 0 else core.random (0, 23));
|
2024-05-06 08:38:47 -04:00
|
|
|
map.clips (x, y) := false;
|
2024-05-06 13:59:08 -04:00
|
|
|
map.views (x, y) := false;
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
end loop;
|
|
|
|
--
|
2024-04-26 19:46:09 -04:00
|
|
|
for index in 1 .. landmark_limit loop
|
2024-05-15 05:06:15 -04:00
|
|
|
map.landmarks (index).index := core.random (0, landmark_count - 1);
|
2024-05-06 14:35:19 -04:00
|
|
|
map.landmarks (index).x := core.random (6, map.width - 6);
|
|
|
|
map.landmarks (index).y := core.random (6, map.height - 6);
|
2024-05-06 13:59:08 -04:00
|
|
|
--
|
2024-05-06 08:38:47 -04:00
|
|
|
if trait (landmark_index'val (map.landmarks (index).index)).clip then
|
2024-05-06 14:35:19 -04:00
|
|
|
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;
|
2024-05-06 08:38:47 -04:00
|
|
|
end if;
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
--
|
2024-05-11 05:13:45 -04:00
|
|
|
for index in 1 .. construction_limit loop
|
2024-05-05 11:46:56 -04:00
|
|
|
map.constructions (index).index := core.random (0, construction.count - 1);
|
2024-05-06 14:18:30 -04:00
|
|
|
map.constructions (index).x := core.random (6, map.width - 6);
|
|
|
|
map.constructions (index).y := core.random (6, map.height - 6);
|
|
|
|
--
|
|
|
|
declare reach_x : constant natural := construction.sprite (construction.enumeration'val (map.constructions (index).index)).width / core.base;
|
|
|
|
reach_y : constant natural := construction.sprite (construction.enumeration'val (map.constructions (index).index)).height / core.base;
|
|
|
|
begin
|
|
|
|
for x in 0 .. reach_x - 1 loop
|
|
|
|
for y in 0 .. reach_y - 1 loop
|
|
|
|
map.clips (map.constructions (index).x + x, map.constructions (index).y + y) := true;
|
|
|
|
end loop;
|
|
|
|
end loop;
|
|
|
|
end;
|
2024-05-05 11:46:56 -04:00
|
|
|
end loop;
|
|
|
|
--
|
2024-05-11 05:13:45 -04:00
|
|
|
for index in 1 .. equipment_limit loop
|
2024-05-11 03:38:33 -04:00
|
|
|
map.equipments (index).index := core.random (0, equipment.count - 1);
|
|
|
|
map.equipments (index).x := core.random (0, map.width - 1);
|
|
|
|
map.equipments (index).y := core.random (0, map.height - 1);
|
2024-05-05 11:46:56 -04:00
|
|
|
end loop;
|
2024-05-05 11:38:15 -04:00
|
|
|
--
|
2024-05-11 05:13:45 -04:00
|
|
|
for index in 1 .. unit_limit loop
|
2024-05-09 05:07:20 -04:00
|
|
|
map.units (index).index := core.random (0, unit.count - 1);
|
|
|
|
map.units (index).x := core.random (0, map.width - 1);
|
|
|
|
map.units (index).y := core.random (0, map.height - 1);
|
|
|
|
--
|
|
|
|
map.clips (map.units (index).x, map.units (index).y) := true;
|
|
|
|
end loop;
|
|
|
|
--
|
2024-03-21 18:28:26 -04:00
|
|
|
core.echo (core.success, "Finished procedurally generating new map.");
|
2024-02-15 21:03:09 -05:00
|
|
|
end make;
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-27 03:49:02 -04:00
|
|
|
procedure draw is
|
2024-05-05 11:46:56 -04:00
|
|
|
u : integer := 0;
|
|
|
|
v : integer := 0;
|
|
|
|
--
|
2024-05-01 14:41:55 -04:00
|
|
|
offset : core.vector := ((core.window_width - core.base) / 2,
|
|
|
|
(core.window_height - core.base) / 2);
|
2024-02-15 21:03:09 -05:00
|
|
|
begin
|
2024-05-09 06:16:11 -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;
|
2024-05-06 13:59:08 -04:00
|
|
|
--
|
2024-05-09 06:16:11 -04:00
|
|
|
declare x : integer := core.base * core.zoom * (-1- core.camera.x) + offset.x;
|
|
|
|
y : integer := core.base * core.zoom * (-1- core.camera.y) + offset.y;
|
|
|
|
width : integer := core.base * core.zoom * (map.width + 2);
|
|
|
|
height : integer := core.base * core.zoom * (map.height + 2);
|
|
|
|
begin
|
2024-05-16 12:35:36 -04:00
|
|
|
core.draw_horizontally (border_upper, x + core.base, y, width - 2 * core.base, core.zoom);
|
|
|
|
core.draw_horizontally (border_lower, x + core.base, y + height - core.base, width - 2 * core.base, core.zoom);
|
|
|
|
core.draw_vertically (border_left, x, y + core.base, height - 2 * core.base, core.zoom);
|
|
|
|
core.draw_vertically (border_right, x + width - core.base, y + core.base, height - 2 * core.base, core.zoom);
|
2024-05-09 06:16:11 -04:00
|
|
|
--
|
2024-05-16 12:35:36 -04:00
|
|
|
core.draw (corner_upper_left, x, y, core.zoom);
|
|
|
|
core.draw (corner_upper_right, x + width - core.base, y, core.zoom);
|
|
|
|
core.draw (corner_lower_left, x, y + height - core.base, core.zoom);
|
|
|
|
core.draw (corner_lower_right, x + width - core.base, y + height - core.base, core.zoom);
|
2024-05-09 06:16:11 -04:00
|
|
|
end;
|
2024-05-09 04:07:25 -04:00
|
|
|
--
|
2024-05-03 05:28:44 -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;
|
2024-05-01 13:27:41 -04:00
|
|
|
--
|
2024-05-03 05:28:44 -04:00
|
|
|
for horizontal in 0 .. map.width - 1 loop
|
|
|
|
exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width;
|
2024-05-01 13:27:41 -04:00
|
|
|
--
|
2024-05-06 13:59:08 -04:00
|
|
|
if map.views (horizontal, vertical) then
|
|
|
|
u := core.base * biome'pos (map.kind) * 4;
|
|
|
|
v := core.base * map.tiles (horizontal, vertical);
|
|
|
|
--
|
|
|
|
core.draw (data => tiles,
|
|
|
|
x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom,
|
2024-05-08 17:14:49 -04:00
|
|
|
y => offset.y + (vertical - core.camera.y) * core.base * core.zoom,
|
2024-05-06 13:59:08 -04:00
|
|
|
u => u,
|
|
|
|
v => v,
|
|
|
|
width => core.base,
|
|
|
|
height => core.base);
|
2024-05-16 10:43:39 -04:00
|
|
|
--~if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom - 6
|
|
|
|
--~and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom + 6
|
|
|
|
--~and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom - 6
|
|
|
|
--~and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom + 6
|
|
|
|
--~and core.cursor_mode = 1
|
|
|
|
--~and not ui.prioritize then
|
|
|
|
--~core.camera.x := horizontal;
|
|
|
|
--~core.camera.y := vertical;
|
|
|
|
--~core.cursor_mode := 0;
|
|
|
|
--~end if;
|
2024-05-06 13:59:08 -04:00
|
|
|
end if;
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
end loop;
|
|
|
|
--
|
2024-04-27 07:03:40 -04:00
|
|
|
for index in 1 .. landmark_limit loop
|
2024-05-06 13:59:08 -04:00
|
|
|
if map.views (map.landmarks (index).x, map.landmarks (index).y) then
|
|
|
|
core.draw (data => landmarks (landmark_index'val (map.landmarks (index).index)),
|
|
|
|
x => offset.x + (map.landmarks (index).x - core.camera.x) * core.base * core.zoom,
|
|
|
|
y => offset.y + (map.landmarks (index).y - core.camera.y) * core.base * core.zoom);
|
|
|
|
end if;
|
2024-04-27 07:03:40 -04:00
|
|
|
end loop;
|
2024-05-05 11:46:56 -04:00
|
|
|
--
|
2024-05-11 05:13:45 -04:00
|
|
|
for index in 1 .. construction_limit loop
|
2024-05-06 13:59:08 -04:00
|
|
|
if map.views (map.constructions (index).x, map.constructions (index).y) then
|
2024-05-11 06:01:07 -04:00
|
|
|
construction.draw_plus (construction.enumeration'val (map.constructions (index).index),
|
|
|
|
offset.x + (map.constructions (index).x - core.camera.x) * core.base * core.zoom,
|
|
|
|
offset.y + (map.constructions (index).y - core.camera.y) * core.base * core.zoom);
|
2024-05-06 13:59:08 -04:00
|
|
|
end if;
|
2024-05-05 11:46:56 -04:00
|
|
|
end loop;
|
|
|
|
--
|
2024-05-11 05:13:45 -04:00
|
|
|
for index in 1 .. equipment_limit loop
|
2024-05-11 03:38:33 -04:00
|
|
|
if map.views (map.equipments (index).x, map.equipments (index).y) then
|
2024-05-11 06:01:07 -04:00
|
|
|
equipment.draw_plus (equipment.enumeration'val (map.equipments (index).index),
|
|
|
|
core.idle,
|
|
|
|
offset.x + (map.equipments (index).x - core.camera.x) * core.base * core.zoom,
|
|
|
|
offset.y + (map.equipments (index).y - core.camera.y) * core.base * core.zoom);
|
2024-05-06 13:59:08 -04:00
|
|
|
end if;
|
2024-05-05 11:46:56 -04:00
|
|
|
end loop;
|
2024-05-08 17:14:49 -04:00
|
|
|
--
|
2024-05-11 05:13:45 -04:00
|
|
|
for index in 1 .. unit_limit loop
|
2024-05-09 05:07:20 -04:00
|
|
|
if map.views (map.units (index).x, map.units (index).y) then
|
2024-05-11 02:13:20 -04:00
|
|
|
unit.draw_full (map.units (index).index,
|
2024-05-09 05:07:20 -04:00
|
|
|
offset.x + (map.units (index).x - core.camera.x) * core.base * core.zoom,
|
|
|
|
offset.y + (map.units (index).y - core.camera.y) * core.base * core.zoom);
|
|
|
|
end if;
|
|
|
|
end loop;
|
|
|
|
--
|
2024-05-08 17:14:49 -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;
|
|
|
|
--
|
2024-05-09 03:53:38 -04:00
|
|
|
if (horizontal - core.camera.x) ** 2 + (vertical - core.camera.y) ** 2 > view_reach then
|
2024-05-08 17:14:49 -04:00
|
|
|
core.draw (data => dark,
|
|
|
|
x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom,
|
|
|
|
y => offset.y + (vertical - core.camera.y) * core.base * core.zoom);
|
|
|
|
end if;
|
|
|
|
end loop;
|
|
|
|
end loop;
|
2024-02-15 21:03:09 -05:00
|
|
|
end draw;
|
|
|
|
|
2024-05-09 15:54:39 -04:00
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
procedure mapshot (file_path : in string) is
|
|
|
|
begin
|
|
|
|
core.create_image (map.width, map.height);
|
|
|
|
--
|
|
|
|
for vertical in 0 .. map.height - 1 loop
|
|
|
|
for horizontal in 0 .. map.width - 1 loop
|
|
|
|
core.render_image (data => tiles,
|
|
|
|
x => horizontal * core.base,
|
|
|
|
y => vertical * core.base,
|
|
|
|
u => core.base * biome'pos (map.kind) * 4,
|
|
|
|
v => core.base * map.tiles (horizontal, vertical),
|
|
|
|
width => core.base,
|
|
|
|
height => core.base);
|
|
|
|
end loop;
|
|
|
|
end loop;
|
|
|
|
--
|
|
|
|
for index in 1 .. landmark_limit loop
|
|
|
|
core.render_image (data => landmarks (landmark_index'val (map.landmarks (index).index)),
|
|
|
|
x => map.landmarks (index).x * core.base,
|
|
|
|
y => map.landmarks (index).y * core.base,
|
|
|
|
u => 0,
|
|
|
|
v => 0,
|
|
|
|
width => landmarks (landmark_index'val (map.landmarks (index).index)).width,
|
|
|
|
height => landmarks (landmark_index'val (map.landmarks (index).index)).height);
|
|
|
|
end loop;
|
|
|
|
--
|
2024-05-11 05:13:45 -04:00
|
|
|
for index in 1 .. construction_limit loop
|
2024-05-09 15:54:39 -04:00
|
|
|
core.render_image (data => construction.sprite (construction.enumeration'val (map.constructions (index).index)),
|
|
|
|
x => map.landmarks (index).x * core.base,
|
|
|
|
y => map.landmarks (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;
|
|
|
|
--
|
2024-05-11 05:13:45 -04:00
|
|
|
for index in 1 .. equipment_limit loop
|
2024-05-11 03:38:33 -04:00
|
|
|
core.render_image (data => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)),
|
2024-05-09 15:54:39 -04:00
|
|
|
x => map.landmarks (index).x * core.base,
|
|
|
|
y => map.landmarks (index).y * core.base,
|
|
|
|
u => 0,
|
|
|
|
v => 0,
|
2024-05-11 03:38:33 -04:00
|
|
|
width => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)).width,
|
|
|
|
height => equipment.sprite (equipment.enumeration'val (map.equipments (index).index)).height);
|
2024-05-09 15:54:39 -04:00
|
|
|
end loop;
|
|
|
|
--
|
|
|
|
core.export_image (file_path);
|
|
|
|
--
|
|
|
|
core.echo (core.success, "Exported current world mapshot.");
|
|
|
|
--
|
|
|
|
core.dash;
|
|
|
|
end mapshot;
|
|
|
|
|
2024-05-12 10:07:37 -04:00
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-02-15 21:03:09 -05:00
|
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
end world;
|