xhads/source/main.adb

512 lines
22 KiB
Ada

-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
--
-- GNU General Public Licence (version 3 or later)
pragma ada_2012;
with core, ui, effect, attribute, skill, resource, faction, deity, material, magic, equipment, unit, construction, chad, world;
with ada.strings.unbounded;
use ada.strings.unbounded;
use core;
procedure main is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type view is (
map_preview_panel,
status_preview_panel,
text_box_panel,
fullscreen
);
------------------------------------------------------------------------------------------
procedure swap_map_preview_panel;
procedure swap_status_preview_panel;
procedure swap_text_box_panel;
procedure swap_fullscreen;
procedure ui_main_style;
procedure zoom_in;
procedure zoom_out;
------------------------------------------------------------------------------------------
signal_list : constant array (core.signal_code) of access procedure := (
core.signal_up => world.player_up'access,
core.signal_down => world.player_down'access,
core.signal_left => world.player_left'access,
core.signal_right => world.player_right'access,
core.signal_v => ui_main_style'access,
core.signal_kp_add => zoom_in'access,
core.signal_kp_subtract => zoom_out'access,
core.signal_f1 => world.resource_cheat_1'access,
core.signal_f2 => world.resource_cheat_2'access,
core.signal_f3 => world.resource_cheat_3'access,
core.signal_f4 => world.resource_cheat_4'access,
core.signal_f5 => world.resource_cheat_5'access,
core.signal_f6 => world.resource_cheat_6'access,
core.signal_f7 => world.reveal_map'access,
core.signal_f8 => world.restore_points'access,
others => core.idle_skip'access
);
view_show : array (view) of access procedure := (
swap_map_preview_panel'access,
swap_status_preview_panel'access,
swap_text_box_panel'access,
swap_fullscreen'access
);
view_icon : array (view) of core.sprite := (others => (others => 0));
view_list : array (view) of boolean := (fullscreen => false, others => true);
view_text : array (view) of core.long_string := (
"Toggle map preview panel. ",
"Toggle status preview panel. ",
"Toggle text box panel. ",
"Toggle fullscreen or windowed mode. "
);
game_title : core.sprite;
game_preview : array (world.biome) of core.sprite;
switch : natural := 0;
choose : world.biome := world.grass;
view_source_code : natural := 25;
source_code : array (0 .. 35) of unbounded_string := (
to_unbounded_string (core.folder & "/source/ai.adb"),
to_unbounded_string (core.folder & "/source/ai.ads"),
to_unbounded_string (core.folder & "/source/attribute.adb"),
to_unbounded_string (core.folder & "/source/attribute.ads"),
to_unbounded_string (core.folder & "/source/chad.adb"),
to_unbounded_string (core.folder & "/source/chad.ads"),
to_unbounded_string (core.folder & "/source/construction.adb"),
to_unbounded_string (core.folder & "/source/construction.ads"),
to_unbounded_string (core.folder & "/source/core.adb"),
to_unbounded_string (core.folder & "/source/core.ads"),
to_unbounded_string (core.folder & "/source/deity.adb"),
to_unbounded_string (core.folder & "/source/deity.ads"),
to_unbounded_string (core.folder & "/source/effect.adb"),
to_unbounded_string (core.folder & "/source/effect.ads"),
to_unbounded_string (core.folder & "/source/equipment.adb"),
to_unbounded_string (core.folder & "/source/equipment.ads"),
to_unbounded_string (core.folder & "/source/faction.adb"),
to_unbounded_string (core.folder & "/source/faction.ads"),
to_unbounded_string (core.folder & "/source/magic.adb"),
to_unbounded_string (core.folder & "/source/magic.ads"),
to_unbounded_string (core.folder & "/source/main.adb"),
to_unbounded_string (core.folder & "/source/material.adb"),
to_unbounded_string (core.folder & "/source/material.ads"),
to_unbounded_string (core.folder & "/source/might.adb"),
to_unbounded_string (core.folder & "/source/might.ads"),
to_unbounded_string (core.folder & "/source/ray.ads"),
to_unbounded_string (core.folder & "/source/resource.adb"),
to_unbounded_string (core.folder & "/source/resource.ads"),
to_unbounded_string (core.folder & "/source/skill.adb"),
to_unbounded_string (core.folder & "/source/skill.ads"),
to_unbounded_string (core.folder & "/source/ui.adb"),
to_unbounded_string (core.folder & "/source/ui.ads"),
to_unbounded_string (core.folder & "/source/unit.adb"),
to_unbounded_string (core.folder & "/source/unit.ads"),
to_unbounded_string (core.folder & "/source/world.adb"),
to_unbounded_string (core.folder & "/source/world.ads")
);
side_panel : integer := 0;
preview_width : integer := 0;
preview_height : integer := 0;
text_box_height : integer := 0;
player : chad.information := (
index => chad.ada,
state => core.idle,
x => 0,
y => 0,
health => (30, 40),
mana => (20, 30),
movement => (10, 20),
attributes => attribute.default,
skills => skill.default,
resources => ((29, 480), (11, 240), (23, 240), (13, 240), (17, 240), (7, 240)),
materials => material.default,
equipments => (equipment.chest => equipment.iron_chestplate,
equipment.head => equipment.iron_helmet,
equipment.hands => equipment.iron_gauntlets,
equipment.feet => equipment.iron_greaves,
equipment.main_hand => equipment.iron_sword,
others => equipment.none),
item_count => 0,
items => (others => equipment.none)
);
------------------------------------------------------------------------------------------
procedure swap_map_preview_panel is begin view_list (map_preview_panel) := not view_list (map_preview_panel); end swap_map_preview_panel;
procedure swap_status_preview_panel is begin view_list (status_preview_panel) := not view_list (status_preview_panel); end swap_status_preview_panel;
procedure swap_text_box_panel is begin view_list (text_box_panel) := not view_list (text_box_panel); end swap_text_box_panel;
procedure swap_fullscreen is begin view_list (fullscreen) := not view_list (fullscreen); end swap_fullscreen;
------------------------------------------------------------------------------------------
procedure ui_main_style is
begin
ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod ui.style_count);
end ui_main_style;
------------------------------------------------------------------------------------------
procedure zoom_in is begin core.zoom := 2; end zoom_in;
procedure zoom_out is begin core.zoom := 1; end zoom_out;
------------------------------------------------------------------------------------------
--~procedure main_menu is
--~begin
--~core.draw (game_preview (world.ash), core.center_x (game_preview (world.ash).width * 2), core.center_y (game_preview (world.ash).height * 2), factor => 2);
--~core.draw (game_title, core.center_x (game_title.width * 2), core.center_y (game_title.height * 2), factor => 2);
--~--
--~ui.write ("Main Menu", 0, 0);
--~--
--~ui.draw_check_box (0, 32, view_list (map_preview_panel), "map_preview_panel");
--~ui.draw_check_box (0, 64, view_list (status_preview_panel), "status_preview_panel");
--~ui.draw_check_box (0, 96, view_list (text_box_panel), "text_box_panel");
--~end main_menu;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin
core.dash;
core.echo (core.comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic");
core.echo (core.comment, "Version -- 1.0.0");
core.echo (core.comment, "License -- GNU/GPLv3+");
core.echo (core.comment, "Xorana is free software, you can redistribute it and modify it under the terms of the GNU General Public License by Free Software Foundation.");
core.dash;
core.initialize;
ui.active := ui.main;
ui.configure;
--~core.play (core.import_song (core.c_string (core.folder & "/song/main_menu.ogg")).index);
core.echo (core.comment, "Configuring" & attribute.count'image & " attribute components...");
--
for index in attribute.enumeration loop
attribute.icon (index) := core.import_sprite (core.folder & "/icon/attribute/" & core.lowercase (attribute.enumeration'image (index)) & ".png", 1, 1);
end loop;
core.echo (core.comment, "Configuring" & skill.count'image & " skill components...");
--
for index in skill.enumeration loop
skill.icon (index) := core.import_sprite (core.folder & "/icon/skill/" & core.lowercase (skill.enumeration'image (index)) & ".png", 1, 1);
end loop;
core.echo (core.comment, "Configuring" & resource.count'image & " resource components...");
--
for index in resource.enumeration loop
resource.icon (index) := core.import_sprite (core.folder & "/icon/resource/" & core.lowercase (resource.enumeration'image (index)) & ".png", 1, 1);
end loop;
core.echo (core.comment, "Configuring" & magic.count'image & " magic components...");
--
for index in magic.enumeration loop
declare folder : constant string := core.lowercase (magic.school'image (magic.description (index).kind));
file : constant string := core.lowercase (magic.enumeration'image (index));
begin
magic.view (index) := core.import_sprite (core.folder & "/view/magic/" & folder & "/" & file & ".png", 1, 1);
end;
end loop;
core.echo (core.comment, "Configuring" & material.count'image & " material components...");
--
for index in material.enumeration loop
material.icon (index) := core.import_sprite (core.folder & "/icon/material/" & core.lowercase (material.enumeration'image (index)) & ".png", 1, 1);
end loop;
core.echo (core.comment, "Configuring" & equipment.count'image & " equipment components...");
--
for index in equipment.enumeration loop
declare folder : constant string := core.lowercase (equipment.slot'image (equipment.description (index).kind));
file : constant string := core.lowercase (equipment.enumeration'image (index));
begin
equipment.sprite (index) := core.import_sprite (core.folder & "/game/equipment/" & folder & "/" & file & ".png", 4, 6);
equipment.icon (index) := core.import_sprite (core.folder & "/icon/equipment/" & folder & "/" & file & ".png", 1, 1);
end;
end loop;
core.echo (core.comment, "Configuring" & unit.count'image & " unit components...");
--
for index in faction.fairy .. faction.imp loop
unit.base (index) := core.import_sprite (core.folder & "/game/unit/" & core.lowercase (faction.enumeration'image (index)) & "/base.png", 4, 6);
end loop;
core.echo (core.comment, "Configuring" & deity.count'image & " deity components...");
--
for index in deity.enumeration loop
deity.sprite (index) := core.import_sprite (core.folder & "/game/deity/" & deity.enumeration'image (index) & ".png", 4, 1);
end loop;
core.echo (core.comment, "Configuring" & construction.count'image & "construction components...");
--
for index in construction.enumeration loop
declare folder : constant string := core.lowercase (faction.enumeration'image (construction.description (index).kind));
file : constant string := core.lowercase (construction.enumeration'image (index));
frames : constant integer := construction.description (index).frames;
begin
construction.sprite (index) := core.import_sprite (core.folder & "/game/construction/" & folder & "/" & file & ".png", frames, 1);
end;
end loop;
core.echo (core.comment, "Configuring" & chad.count'image & "chad components...");
--
for index in chad.enumeration loop
chad.sprite (index) := core.import_sprite (core.folder & "/game/chad/" & core.lowercase (chad.enumeration'image (index)) & ".png", 4, 6);
chad.view (index) := core.import_sprite (core.folder & "/view/chad/" & core.lowercase (chad.enumeration'image (index)) & ".png", 1, 1);
end loop;
world.configure;
--~ai.configure;
world.make (world.grass, 640, 480, 8);
world.add_chad (player);
core.dash;
core.echo (core.success, "Successfully initialized game data, entering main gameplay loop.");
core.dash;
for index in view loop
view_icon (index) := core.import_sprite (core.folder & "/icon/engine/" & core.lowercase (view'image (index)) & ".png", 1, 2);
end loop;
game_title := core.import_sprite (core.folder & "/ui/game_title.png", 1, 1);
for index in world.biome loop
game_preview (index) := core.import_sprite (core.folder & "/ui/preview/" & core.lowercase (world.biome'image (index)) & "land.png", 1, 1);
end loop;
------------------------------------------------------------------------------------------
introduction_loop: loop
core.synchronize;
--
exit when core.signal_mode = core.signal_space or core.cursor_mode = core.cursor_right;
--
case core.signal_mode is
when core.signal_none => null;
when core.signal_space => null;
when others => switch := (switch + 1) mod world.biome_count;
choose := world.biome'val (switch);
end case;
--
core.draw (game_preview (choose), core.center_x (game_preview (choose).width * 2), core.center_y (game_preview (choose).height * 2), factor => 2);
core.draw (game_title, core.center_x (game_title.width * 2), core.center_y (game_title.height * 2), factor => 2);
--
ui.write ("[-- Press Spacebar or RMB to continue]", 0, core.center_y (24), (102, 102, 102, 255));
end loop introduction_loop;
core.cursor_mode := core.cursor_none;
main_menu_loop: loop
core.synchronize;
--
exit when core.signal_mode = core.signal_space or core.cursor_mode = core.cursor_right;
--
declare source_code_data : core.string_box_data;
begin
core.import_text (source_code_data, to_string (source_code (view_source_code)));
--
if core.cursor_mode = core.cursor_left then
view_source_code := (view_source_code + 1) mod 36;
core.cursor_mode := core.cursor_none;
core.wheel := 0.0;
end if;
--
ui.write_ada_code (source_code_data, 0, integer (core.wheel) * 30);
end;
end loop main_menu_loop;
core.cursor_mode := core.cursor_none;
world.load ("heyo");
ui.active := ui.style'val (faction.enumeration'pos (chad.description (player.index).kind) + 1);
gameplay_loop: loop
core.synchronize;
--
exit when core.engine_active = false;
--
if not view_list (status_preview_panel) then
side_panel := 0;
else
side_panel := 376 + 2 * 32;
end if;
--
preview_width := core.window_width - side_panel;
preview_height := core.window_height - text_box_height;
text_box_height := 32;
--
world.draw;
--
if view_list (map_preview_panel) then
ui.draw_menu (0, 0, preview_width, preview_height);
end if;
--
if view_list (status_preview_panel) then
ui.draw_tiny_menu (preview_width, 0, side_panel, preview_height);
--
declare player : chad.information := world.map.chads (1);
x : integer := preview_width + core.icon;
y : integer := core.icon;
begin
ui.draw_frame ("--", x, y, 360 + 2 * 8, 96 + 2 * 8);
--
ui.draw_sprite (chad.view (player.index), chad.description (player.index).name, x + 8, y + 8, 0);
--
ui.draw_tiny_fill_bar (x + chad.view_width + 2 * 8, y + 1 * core.icon + 8, 360 - chad.view_width - 8, float (player.health.value) / float (player.health.limit), (127, 0, 0, 255));
ui.draw_tiny_fill_bar (x + chad.view_width + 2 * 8, y + 2 * core.icon + 8, 360 - chad.view_width - 8, float (player.mana.value) / float (player.mana.limit), (0, 0, 127, 255));
ui.draw_tiny_fill_bar (x + chad.view_width + 2 * 8, y + 3 * core.icon + 8, 360 - chad.view_width - 8, float (player.movement.value) / float (player.movement.limit), (0, 127, 0, 255));
--
ui.write (text => "Health " & player.health.value'image & " /" & player.health.limit'image,
x => x + chad.view_width + core.icon + 3 * 8,
y => y + 2 * 8,
tint => (255, 127, 127, 255),
size => 15,
code => true);
ui.write (text => "Mana " & player.mana.value'image & " /" & player.mana.limit'image,
x => x + chad.view_width + core.icon + 3 * 8,
y => y + core.icon + 2 * 8,
tint => (127, 127, 255, 255),
size => 15,
code => true);
ui.write (text => "Stamina" & player.movement.value'image & " /" & player.movement.limit'image,
x => x + chad.view_width + core.icon + 3 * 8,
y => y + 2 * core.icon + 2 * 8,
tint => (127, 255, 127, 255),
size => 15,
code => true);
--
declare move_x : integer := x;
begin
for index in attribute.enumeration loop
ui.draw_icon (attribute.icon (index), -(attribute.description (index).text), move_x, y + 96 + 3 * 8);
ui.draw_text_box (move_x, y + 96 + 3 * 8 + core.icon, core.icon, core.icon);
ui.write (player.attributes (index).value'image, move_x + 4, y + 96 + 3 * 8 + core.icon + 8, (others => 255), 15, true);
--
move_x := move_x + core.icon;
end loop;
end;
--
for index_y in 0 .. 3 loop
for index_x in 0 .. 5 loop
ui.draw_icon (data => equipment.icon (player.items (6 * index_y + index_x)),
text => -(equipment.description (player.items (6 * index_y + index_x)).name),
x => x + index_x * core.icon,
y => y + 96 + 4 * 8 + 2 * core.icon + index_y * core.icon);
end loop;
end loop;
--
declare move_x : integer := x;
move_y : integer := y + 96 + 5 * 8 + 6 * core.icon;
begin
for index in skill.enumeration loop
if (skill.enumeration'pos (index) + 1) mod (skill.count / 2 + 1) = 0 then
move_x := x + 2 * core.icon + 120;
move_y := y + 96 + 5 * 8 + 6 * core.icon;
end if;
--
ui.draw_icon (skill.icon (index), -(skill.description (index).text), move_x, move_y);
ui.draw_text_box (move_x + core.icon, move_y, core.icon, core.icon);
ui.write (player.skills (index).value'image, move_x + core.icon, move_y + 8, (others => 255), 15, true);
ui.write (-(skill.description (index).name), move_x + 2 * core.icon + 4, move_y + 8, (others => 255), 15, true);
--
move_y := move_y + core.icon;
end loop;
end;
end;
--
ui.draw_end_turn_button (x => core.window_width - side_panel + side_panel / 2 - core.icon,
y => core.window_height - core.icon - text_box_height - 106 - 2 * core.icon);
--
ui.draw_console_box (x => core.window_width - core.icon - (side_panel - 2 * core.icon),
y => core.window_height - core.icon - text_box_height - 106,
width => side_panel - 2 * core.icon,
height => 106);
--~ui.draw_state_box (preview_width + 32, 32);
end if;
--
if view_list (text_box_panel) then
ui.draw_help_box (0, core.window_height - text_box_height, core.window_width - core.icon * (view'pos (view'last) + 1), text_box_height);
--
ui.write (core.framerate'image, core.window_width - core.icon * (view'pos (view'last) + 1) - 64, core.window_height - 27);
end if;
--
for index in view loop
ui.draw_frame (description => view_text (index),
x => core.window_width - core.icon * (view'pos (view'last) + 1) + core.icon * view'pos (index),
y => core.window_height - core.icon,
width => core.icon,
height => core.icon,
action => view_show (index));
--
core.draw (data => view_icon (index),
x => core.window_width - core.icon * (view'pos (view'last) + 1) + core.icon * view'pos (index),
y => core.window_height - core.icon,
ignore => true,
u => 0,
v => boolean'pos (view_list (index)) * core.icon,
factor => 1);
end loop;
--
for index in resource.enumeration loop
ui.draw_icon (resource.icon (index), -(resource.description (index).text), (preview_width - 6 * core.icon * resource.count) / 2 + (6 * core.icon) * resource.enumeration'pos (index), core.base);
ui.draw_frame (-(resource.description (index).text), (preview_width - 6 * core.icon * resource.count) / 2 + (6 * core.icon) * resource.enumeration'pos (index) + core.icon, core.base, 6 * core.icon, core.icon);
--
ui.write (text => world.map.chads (1).resources (index).value'image & " /" & world.map.chads (1).resources (index).limit'image,
x => (preview_width - 6 * core.icon * resource.count) / 2 + (6 * core.icon) * resource.enumeration'pos (index) + core.icon - 1,
y => core.base + 7,
size => 18);
end loop;
--
declare move_x : integer := (preview_width - core.icon * material.count) / 2;
begin
for index in material.enumeration loop
if world.map.chads (1).materials (index).value > 0 then
ui.draw_icon (material.icon (index), -(material.description (index).name), move_x, core.base + core.icon);
ui.draw_text_box (move_x, core.base + core.icon + core.icon, core.icon, core.icon);
ui.write (world.map.chads (1).materials (index).value'image, move_x, core.base + core.icon + core.icon + 8, (255, 255, 255, 255), 15, true);
--
move_x := move_x + core.icon;
end if;
end loop;
end;
--
signal_list (core.signal_mode).all;
--
core.camera.x := world.map.chads (1).x;
core.camera.y := world.map.chads (1).y;
--
--~world.draw_performance_box;
--
ui.synchronize;
end loop gameplay_loop;
world.save ("heyo");
--~world.mapshot (folder & "/mapshot.png");
------------------------------------------------------------------------------------------
core.deinitialize;
core.dash;
end main;