xabina/xabina.adb

677 lines
37 KiB
Ada
Raw Normal View History

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2023 - Ognjen 'xolatile' Milan Robovic
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
-- Xabina is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either
-- version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
-- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Experimental minimal terminal rogue-like game in Ada programming language. I used to write a lot of Ada programs some time ago, then went in full C and assembly mode, and came
-- back to Ada, but realized that I keep my folders messy... Since it's bothersome to find my old Ada projects and share them here, I decided that the most easy thing to do is to
-- write a new program in Ada, a tiny game. Work in progress, it's messy and ugly for now...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
with ada.text_io, ada.strings.unbounded;
use ada.text_io, ada.strings.unbounded;
2023-10-09 16:33:18 -04:00
-- Do not use this command below, it's for real-time game...
-- $ gnatmake xabina.adb
-- $ stty raw -echo && ./xabina && stty sane
function xabina return integer is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- System
2023-10-09 14:56:48 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 15:26:24 -04:00
type integer_subrange is
record
minimum : integer := 0;
maximum : integer := 0;
end record;
type natural_subrange is
record
minimum : natural := 0;
maximum : natural := 0;
end record;
type signal_list is (
SIGNAL_A, SIGNAL_B, SIGNAL_C, SIGNAL_D, SIGNAL_E, SIGNAL_F, SIGNAL_G, SIGNAL_H,
SIGNAL_I, SIGNAL_J, SIGNAL_K, SIGNAL_L, SIGNAL_M, SIGNAL_N, SIGNAL_O, SIGNAL_P,
SIGNAL_Q, SIGNAL_R, SIGNAL_S, SIGNAL_T, SIGNAL_U, SIGNAL_V, SIGNAL_W, SIGNAL_X,
SIGNAL_Y, SIGNAL_Z, SIGNAL_0, SIGNAL_1, SIGNAL_2, SIGNAL_3, SIGNAL_4, SIGNAL_5,
SIGNAL_6, SIGNAL_7, SIGNAL_8, SIGNAL_9, SIGNAL_ESCAPE, SIGNAL_TABULATOR, SIGNAL_RETURN, SIGNAL_NEW_LINE,
SIGNAL_SLASH, SIGNAL_BACKSLASH, SIGNAL_QUOTE, SIGNAL_BACKQUOTE, SIGNAL_SPACE, SIGNAL_BACKSPACE, SIGNAL_DOT, SIGNAL_IDLE
);
2023-10-09 16:33:18 -04:00
type colours is (
COLOUR_GREY, COLOUR_RED, COLOUR_GREEN, COLOUR_YELLOW, COLOUR_BLUE, COLOUR_PINK, COLOUR_CYAN, COLOUR_WHITE
);
2023-10-09 16:33:18 -04:00
type effects is (
EFFECT_NORMAL, EFFECT_BOLD, EFFECT_ITALIC, EFFECT_UNDERLINE, EFFECT_BLINK, EFFECT_REVERSE
);
escape : constant character := character'val (27);
function format_symbol (
2023-10-09 16:33:18 -04:00
symbol : character := ' ';
colour : colours := COLOUR_WHITE;
effect : effects := EFFECT_NORMAL
) return string is
format : string (1 .. 12) := escape & "[E;3CmS" & escape & "[0m";
2023-10-09 16:33:18 -04:00
begin
case effect is
when EFFECT_NORMAL => format (3) := '0';
when EFFECT_BOLD => format (3) := '1';
when EFFECT_ITALIC => format (3) := '3';
when EFFECT_UNDERLINE => format (3) := '4';
when EFFECT_BLINK => format (3) := '5';
when EFFECT_REVERSE => format (3) := '7';
2023-10-09 16:33:18 -04:00
end case;
case colour is
when COLOUR_GREY => format (6) := '0';
when COLOUR_RED => format (6) := '1';
when COLOUR_GREEN => format (6) := '2';
when COLOUR_YELLOW => format (6) := '3';
when COLOUR_BLUE => format (6) := '4';
when COLOUR_PINK => format (6) := '5';
when COLOUR_CYAN => format (6) := '6';
when COLOUR_WHITE => format (6) := '7';
2023-10-09 16:33:18 -04:00
end case;
format (8) := symbol;
return format;
end format_symbol;
2023-10-09 16:33:18 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Entity
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
type entities is (
2023-10-10 13:36:30 -04:00
ENTITY_NULL, ENTITY_MENU, ENTITY_MAP, ENTITY_ITEM, ENTITY_MAGIC, ENTITY_AMMUNITION, ENTITY_WEAPON, ENTITY_ARMOUR,
2023-10-09 16:49:02 -04:00
ENTITY_SCROLL, ENTITY_POTION, ENTITY_CONSUMABLE, ENTITY_NOTE, ENTITY_PLANT, ENTITY_ANIMAL, ENTITY_GOBLIN, ENTITY_PLAYER
2023-10-09 14:56:48 -04:00
);
type entity_constant_type is tagged
record
2023-10-09 16:49:02 -04:00
entity : entities := ENTITY_NULL; -- Entity identifier.
2023-10-09 16:33:18 -04:00
name : unbounded_string := null_unbounded_string; -- Entity general name.
symbol : character := ' '; -- Entity ASCII character representation.
colour : colours := COLOUR_WHITE; -- Entity VT100 escape sequence colour.
effect : effects := EFFECT_NORMAL; -- Entity VT100 escape sequence effect.
end record;
type entity_variable_type is tagged
record
x : integer := 0; -- Global X coordinate.
y : integer := 0; -- Global Y coordinate.
end record;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:49:02 -04:00
-- Menu
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Map:
-- -- Map data is only constant, not variable, since X and Y coordinates are determined by player, camera or global position.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
type map_list is (
2023-10-09 16:49:02 -04:00
STONE_WALL, WOODEN_WALL, STONE_FLOOR, WOODEN_FLOOR, WATER_SHALLOW, WATER_DEEP, SWAMP_SHALLOW, SWAMP_DEEP
);
type map_constant_type is new entity_constant_type with
record
2023-10-09 16:33:18 -04:00
collide : boolean := false;
end record;
2023-10-09 16:33:18 -04:00
type map_constant_list is array (map_list) of map_constant_type;
2023-10-09 16:33:18 -04:00
map_constant_data : constant map_constant_list := (
2023-10-09 16:49:02 -04:00
(ENTITY_MAP, to_unbounded_string ("Stone Wall"), '#', COLOUR_GREY, EFFECT_BOLD, true),
(ENTITY_MAP, to_unbounded_string ("Wooden Wall"), '#', COLOUR_YELLOW, EFFECT_NORMAL, true),
(ENTITY_MAP, to_unbounded_string ("Stone Floor"), '.', COLOUR_GREY, EFFECT_BOLD, false),
(ENTITY_MAP, to_unbounded_string ("Wooden Floor"), '.', COLOUR_YELLOW, EFFECT_NORMAL, false),
(ENTITY_MAP, to_unbounded_string ("Water (shallow)"), '~', COLOUR_BLUE, EFFECT_NORMAL, false),
(ENTITY_MAP, to_unbounded_string ("Water (deep)"), '~', COLOUR_BLUE, EFFECT_BOLD, true),
(ENTITY_MAP, to_unbounded_string ("Swamp (shallow)"), '~', COLOUR_GREEN, EFFECT_NORMAL, false),
(ENTITY_MAP, to_unbounded_string ("Swamp (deep)"), '~', COLOUR_GREEN, EFFECT_BOLD, true)
);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:49:02 -04:00
-- Item
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 23:10:19 -04:00
type item_list is (
WOOD, BARK, FLAX, PLANK, STICK, BRACES, NAILS, LINEN,
CHAMOMILE, MINT, WAX, SALT, SUGAR, PEPPER, CINNAMON, YEAST,
SKULL, BONE, INTESTINES, FUR, LEATHER, FAT, HORN, TUSK,
COPPER_ORE, IRON_ORE, SILVER_ORE, GOLD_ORE, COAL_ORE, TIN_ORE, ZINC_ORE, LEAD_ORE,
COPPER, IRON, SILVER, GOLD, COAL, TIN, ZINC, LEAD,
BRONZE, BRASS, STEEL, MERCURY, OIL, INK, VENOM, SILK,
PAPERS, PAPERWEIGHT
);
type item_mark is mod 72;
type item_constant_type is new entity_constant_type with
record
value : natural := 0;
weight : natural := 0;
end record;
type item_variable_type is new entity_variable_type with
record
owner : natural := 0;
end record;
type item_constant_list is array (item_list) of item_constant_type;
type item_variable_list is array (item_mark) of item_variable_type;
item_constant_data : constant item_constant_list := (
(ENTITY_ITEM, to_unbounded_string ("Wood"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 2, 2),
(ENTITY_ITEM, to_unbounded_string ("Bark"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 1, 2),
(ENTITY_ITEM, to_unbounded_string ("Flax"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 3, 1),
(ENTITY_ITEM, to_unbounded_string ("Plank"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 2, 2),
(ENTITY_ITEM, to_unbounded_string ("Stick"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 2, 2),
(ENTITY_ITEM, to_unbounded_string ("Braces"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 2, 1),
(ENTITY_ITEM, to_unbounded_string ("Nails"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 1, 1),
(ENTITY_ITEM, to_unbounded_string ("Linen"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 23, 1),
(ENTITY_ITEM, to_unbounded_string ("Chamomile"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 3, 1),
(ENTITY_ITEM, to_unbounded_string ("Mint"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 5, 1),
(ENTITY_ITEM, to_unbounded_string ("Wax"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 7, 1),
(ENTITY_ITEM, to_unbounded_string ("Salt"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 13, 1),
(ENTITY_ITEM, to_unbounded_string ("Sugar"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 17, 1),
(ENTITY_ITEM, to_unbounded_string ("Pepper"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 11, 1),
(ENTITY_ITEM, to_unbounded_string ("Cinnamon"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 23, 1),
(ENTITY_ITEM, to_unbounded_string ("Yeast"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 5, 1),
(ENTITY_ITEM, to_unbounded_string ("Skull"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 2, 1),
(ENTITY_ITEM, to_unbounded_string ("Bone"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 1, 1),
(ENTITY_ITEM, to_unbounded_string ("Intestines"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 1, 1),
(ENTITY_ITEM, to_unbounded_string ("Fur"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 7, 2),
(ENTITY_ITEM, to_unbounded_string ("Leather"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 3, 1),
(ENTITY_ITEM, to_unbounded_string ("Fat"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 1, 1),
(ENTITY_ITEM, to_unbounded_string ("Horn"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 2, 1),
(ENTITY_ITEM, to_unbounded_string ("Tusk"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 3, 5),
(ENTITY_ITEM, to_unbounded_string ("Copper Ore"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 5, 7),
(ENTITY_ITEM, to_unbounded_string ("Iron Ore"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 7, 11),
(ENTITY_ITEM, to_unbounded_string ("Silver Ore"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 17, 7),
(ENTITY_ITEM, to_unbounded_string ("Gold Ore"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 23, 7),
(ENTITY_ITEM, to_unbounded_string ("Coal Ore"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 2, 7),
(ENTITY_ITEM, to_unbounded_string ("Tin Ore"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 13, 7),
(ENTITY_ITEM, to_unbounded_string ("Zinc Ore"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 13, 7),
(ENTITY_ITEM, to_unbounded_string ("Lead Ore"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 11, 13),
(ENTITY_ITEM, to_unbounded_string ("Copper"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 17, 5),
(ENTITY_ITEM, to_unbounded_string ("Iron"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 19, 7),
(ENTITY_ITEM, to_unbounded_string ("Silver"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 23, 5),
(ENTITY_ITEM, to_unbounded_string ("Gold"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 29, 5),
(ENTITY_ITEM, to_unbounded_string ("Coal"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 19, 5),
(ENTITY_ITEM, to_unbounded_string ("Tin"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 11, 5),
(ENTITY_ITEM, to_unbounded_string ("Zinc"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 13, 5),
(ENTITY_ITEM, to_unbounded_string ("Lead"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 47, 7),
(ENTITY_ITEM, to_unbounded_string ("Bronze"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 61, 5),
(ENTITY_ITEM, to_unbounded_string ("Brass"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 67, 5),
(ENTITY_ITEM, to_unbounded_string ("Steel"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 71, 7),
(ENTITY_ITEM, to_unbounded_string ("Mercury"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 97, 11),
(ENTITY_ITEM, to_unbounded_string ("Oil"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 5, 1),
(ENTITY_ITEM, to_unbounded_string ("Ink"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 13, 1),
(ENTITY_ITEM, to_unbounded_string ("Venom"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 11, 1),
(ENTITY_ITEM, to_unbounded_string ("Silk"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 13, 1),
(ENTITY_ITEM, to_unbounded_string ("Papers"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 1, 1),
(ENTITY_ITEM, to_unbounded_string ("Paperweight"), '+', COLOUR_YELLOW, EFFECT_NORMAL, 2, 1)
);
item_variable_data : item_variable_list;
2023-10-09 16:49:02 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Spell
2023-10-10 13:36:30 -04:00
-- -- Place-holders mostly, implement self/target/target_range effect variations...
2023-10-09 16:49:02 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-10 13:36:30 -04:00
type magic_list is (
IGNITE, ILLUMINATE, BLADECHARM, BATTLECRY
);
type magic_mark is mod 72;
type magic_constant_type is new entity_constant_type with
record
self : boolean := false;
health : integer := 0;
armour : integer := 0;
mana : integer := 0;
stamina : integer := 0;
distance : integer := 0;
tribute : natural := 0;
end record;
type magic_variable_type is new entity_variable_type with
record
enchantment : natural := 0;
end record;
type magic_constant_list is array (magic_list) of magic_constant_type;
type magic_variable_list is array (magic_mark) of magic_variable_type;
magic_constant_data : constant magic_constant_list := (
(ENTITY_MAGIC, to_unbounded_string ("Ignite"), '*', COLOUR_YELLOW, EFFECT_ITALIC, false, -3, 0, 0, -1, 7, 1),
(ENTITY_MAGIC, to_unbounded_string ("Illuminate"), '*', COLOUR_YELLOW, EFFECT_ITALIC, false, 0, 0, 0, -1, 13, 1),
(ENTITY_MAGIC, to_unbounded_string ("Bladecharm"), '*', COLOUR_RED, EFFECT_ITALIC, true, 0, -3, 0, -1, 7, 3),
(ENTITY_MAGIC, to_unbounded_string ("Battlecry"), '*', COLOUR_RED, EFFECT_ITALIC, true, -1, -1, 0, -1, 7, 2)
);
magic_variable_data : magic_variable_list;
2023-10-09 16:49:02 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Ammunition
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-10 13:58:50 -04:00
type ammunition_list is (
ARROWS, BOLTS, SLINGSHOTS, JARIDS
);
type ammunition_mark is mod 72;
type ammunition_constant_type is new entity_constant_type with
record
value : natural := 0;
weight : natural := 0;
dual_wield : boolean := false;
amount_limit : natural := 0;
attack_range : natural_subrange := (0, 0);
distance_range : natural_subrange := (0, 0);
end record;
type ammunition_variable_type is new entity_variable_type with
record
amount : natural_subrange := (0, 0);
enchantment : natural := 0;
end record;
type ammunition_constant_list is array (ammunition_list) of ammunition_constant_type;
type ammunition_variable_list is array (ammunition_mark) of ammunition_variable_type;
ammunition_constant_data : constant ammunition_constant_list := (
(ENTITY_AMMUNITION, to_unbounded_string ("Arrows"), '^', COLOUR_RED, EFFECT_NORMAL, 11, 13, false, 23, (0, 7), (17, 67)),
(ENTITY_AMMUNITION, to_unbounded_string ("Bolts"), '^', COLOUR_RED, EFFECT_NORMAL, 13, 23, false, 29, (0, 5), (17, 67)),
(ENTITY_AMMUNITION, to_unbounded_string ("Slingshots"), '^', COLOUR_RED, EFFECT_NORMAL, 5, 7, true, 43, (0, 7), (17, 67)),
(ENTITY_AMMUNITION, to_unbounded_string ("Jarids"), '^', COLOUR_RED, EFFECT_NORMAL, 29, 37, true, 7, (0, 7), (17, 67))
);
ammunition_variable_data : ammunition_variable_list;
2023-10-09 16:49:02 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
-- Weapon
2023-10-09 14:56:48 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
type weapon_list is (
IRON_SWORD, IRON_GREATSWORD, IRON_AXE, IRON_BATTLEAXE, IRON_SPEAR, IRON_SHIELD, IRON_MACE, IRON_HAMMER,
BRONZE_SWORD, BRONZE_GREATSWORD, BRONZE_AXE, BRONZE_BATTLEAXE, BRONZE_SPEAR, BRONZE_SHIELD, BRONZE_MACE, BRONZE_HAMMER,
BRASS_SWORD, BRASS_GREATSWORD, BRASS_AXE, BRASS_BATTLEAXE, BRASS_SPEAR, BRASS_SHIELD, BRASS_MACE, BRASS_HAMMER
2023-10-09 15:26:24 -04:00
);
2023-10-09 16:33:18 -04:00
type weapon_mark is mod 72;
type weapon_constant_type is new entity_constant_type with
2023-10-09 15:26:24 -04:00
record
2023-10-09 16:33:18 -04:00
dual_wield : boolean := false;
value : natural := 0;
2023-10-09 23:27:39 -04:00
weight : natural := 0;
2023-10-10 13:36:30 -04:00
attack_range : natural_subrange := (0, 0);
defense_range : natural_subrange := (0, 0);
distance_range : natural_subrange := (0, 0);
2023-10-09 15:26:24 -04:00
end record;
2023-10-09 16:33:18 -04:00
type weapon_variable_type is new entity_variable_type with
2023-10-09 15:26:24 -04:00
record
2023-10-09 16:33:18 -04:00
enchantment : natural := 0;
condition : natural := 0;
2023-10-09 15:26:24 -04:00
end record;
2023-10-09 16:33:18 -04:00
type weapon_constant_list is array (weapon_list) of weapon_constant_type;
type weapon_variable_list is array (weapon_mark) of weapon_variable_type;
weapon_constant_data : constant weapon_constant_list := (
(ENTITY_WEAPON, to_unbounded_string ("Iron Sword"), 'l', COLOUR_RED, EFFECT_NORMAL, true, 11, 31, (3, 7), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Iron Greatsword"), 'L', COLOUR_RED, EFFECT_BOLD, false, 23, 67, (5, 11), (1, 3), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Iron Axe"), 'r', COLOUR_RED, EFFECT_NORMAL, true, 13, 43, (1, 7), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Iron Battleaxe"), 'T', COLOUR_RED, EFFECT_BOLD, false, 19, 73, (6, 13), (1, 2), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Iron Spear"), 'I', COLOUR_RED, EFFECT_BOLD, false, 17, 53, (4, 10), (2, 4), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Iron Shield"), 'o', COLOUR_RED, EFFECT_NORMAL, true, 13, 37, (0, 3), (4, 9), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Iron Mace"), 'i', COLOUR_RED, EFFECT_NORMAL, true, 11, 41, (3, 8), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Iron Hammer"), 't', COLOUR_RED, EFFECT_NORMAL, true, 13, 47, (4, 7), (0, 3), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Bronze Sword"), 'l', COLOUR_RED, EFFECT_NORMAL, true, 11, 31, (3, 7), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Bronze Greatsword"), 'L', COLOUR_RED, EFFECT_BOLD, false, 23, 67, (5, 11), (1, 3), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Bronze Axe"), 'r', COLOUR_RED, EFFECT_NORMAL, true, 13, 43, (1, 7), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Bronze Battleaxe"), 'T', COLOUR_RED, EFFECT_BOLD, false, 19, 73, (6, 13), (1, 2), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Bronze Spear"), 'I', COLOUR_RED, EFFECT_BOLD, false, 17, 53, (4, 10), (2, 4), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Bronze Shield"), 'o', COLOUR_RED, EFFECT_NORMAL, true, 13, 37, (0, 3), (4, 9), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Bronze Mace"), 'i', COLOUR_RED, EFFECT_NORMAL, true, 11, 41, (3, 8), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Bronze Hammer"), 't', COLOUR_RED, EFFECT_NORMAL, true, 13, 47, (4, 7), (0, 3), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Brass Sword"), 'l', COLOUR_RED, EFFECT_NORMAL, true, 11, 31, (3, 7), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Brass Greatsword"), 'L', COLOUR_RED, EFFECT_BOLD, false, 23, 67, (5, 11), (1, 3), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Brass Axe"), 'r', COLOUR_RED, EFFECT_NORMAL, true, 13, 43, (1, 7), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Brass Battleaxe"), 'T', COLOUR_RED, EFFECT_BOLD, false, 19, 73, (6, 13), (1, 2), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Brass Spear"), 'I', COLOUR_RED, EFFECT_BOLD, false, 17, 53, (4, 10), (2, 4), (0, 2)),
(ENTITY_WEAPON, to_unbounded_string ("Brass Shield"), 'o', COLOUR_RED, EFFECT_NORMAL, true, 13, 37, (0, 3), (4, 9), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Brass Mace"), 'i', COLOUR_RED, EFFECT_NORMAL, true, 11, 41, (3, 8), (0, 2), (0, 1)),
(ENTITY_WEAPON, to_unbounded_string ("Brass Hammer"), 't', COLOUR_RED, EFFECT_NORMAL, true, 13, 47, (4, 7), (0, 3), (0, 1))
2023-10-09 15:26:24 -04:00
);
2023-10-09 16:33:18 -04:00
weapon_variable_data : weapon_variable_list;
2023-10-09 14:56:48 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:49:02 -04:00
-- Armour
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 23:27:39 -04:00
type armour_list is (
IRON_HELMET, IRON_CHESTPLATE, IRON_GAUNTLETS, IRON_GREAVES, IRON_CUISSE, IRON_FAULD, IRON_GARDBRACE, IRON_REREBRACE
);
type armour_mark is mod 72;
type armour_constant_type is new entity_constant_type with
record
2023-10-10 13:36:30 -04:00
value : natural := 0;
weight : natural := 0;
defense_range : natural_subrange := (0, 0);
2023-10-09 23:27:39 -04:00
end record;
type armour_variable_type is new entity_variable_type with
record
enchantment : natural := 0;
condition : natural := 0;
end record;
type armour_constant_list is array (armour_list) of armour_constant_type;
type armour_variable_list is array (armour_mark) of armour_variable_type;
armour_constant_data : constant armour_constant_list := (
(ENTITY_ARMOUR, to_unbounded_string ("Iron Helmet"), 'm', COLOUR_YELLOW, EFFECT_NORMAL, 11, 31, (3, 7)),
(ENTITY_ARMOUR, to_unbounded_string ("Iron Chestplate"), 'M', COLOUR_YELLOW, EFFECT_BOLD, 23, 67, (5, 11)),
(ENTITY_ARMOUR, to_unbounded_string ("Iron Gauntlets"), 'i', COLOUR_YELLOW, EFFECT_NORMAL, 13, 43, (1, 7)),
(ENTITY_ARMOUR, to_unbounded_string ("Iron Greaves"), 'I', COLOUR_YELLOW, EFFECT_NORMAL, 19, 73, (6, 13)),
(ENTITY_ARMOUR, to_unbounded_string ("Iron Cuisse"), 'Y', COLOUR_YELLOW, EFFECT_BOLD, 17, 53, (4, 10)),
(ENTITY_ARMOUR, to_unbounded_string ("Iron Fauld"), '-', COLOUR_YELLOW, EFFECT_NORMAL, 13, 37, (0, 3)),
(ENTITY_ARMOUR, to_unbounded_string ("Iron Gardbrace"), 'v', COLOUR_YELLOW, EFFECT_NORMAL, 11, 41, (3, 8)),
(ENTITY_ARMOUR, to_unbounded_string ("Iron Rerebrace"), 'V', COLOUR_YELLOW, EFFECT_NORMAL, 13, 47, (4, 7))
);
armour_variable_data : armour_variable_list;
2023-10-09 16:49:02 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Scroll
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Potion
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Consumable
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Note
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 14:56:48 -04:00
-- Plant
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
type plant_list is (
2023-10-10 14:34:06 -04:00
OAK_TREE, PINE_TREE, BIRCH_TREE, ACACIA_TREE, APPLE_TREE, PEACH_TREE, ORANGE_TREE, PEAR_TREE,
BUSH, THORNY_BUSH, TALL_GRASS, REED
2023-10-09 14:56:48 -04:00
);
2023-10-10 14:34:06 -04:00
type plant_mark is mod 72;
type plant_constant_type is new entity_constant_type with
record
health_limit : natural := 0;
end record;
type plant_variable_type is new entity_variable_type with
record
health : natural := 0;
end record;
type plant_constant_list is array (plant_list) of plant_constant_type;
type plant_variable_list is array (plant_mark) of plant_variable_type;
plant_constant_data : constant plant_constant_list := (
(ENTITY_PLANT, to_unbounded_string ("Oak Tree"), 'T', COLOUR_GREEN, EFFECT_BOLD, 11),
(ENTITY_PLANT, to_unbounded_string ("Pine Tree"), 'T', COLOUR_GREEN, EFFECT_BOLD, 23),
(ENTITY_PLANT, to_unbounded_string ("Birch Tree"), 'T', COLOUR_GREEN, EFFECT_BOLD, 13),
(ENTITY_PLANT, to_unbounded_string ("Acacia Tree"), 'T', COLOUR_GREEN, EFFECT_BOLD, 19),
(ENTITY_PLANT, to_unbounded_string ("Apple Tree"), 'T', COLOUR_GREEN, EFFECT_BOLD, 17),
(ENTITY_PLANT, to_unbounded_string ("Peach Tree"), 'T', COLOUR_GREEN, EFFECT_BOLD, 13),
(ENTITY_PLANT, to_unbounded_string ("Orange Tree"), 'T', COLOUR_GREEN, EFFECT_BOLD, 11),
(ENTITY_PLANT, to_unbounded_string ("Pear Tree"), 'T', COLOUR_GREEN, EFFECT_BOLD, 13),
(ENTITY_PLANT, to_unbounded_string ("Bush"), '&', COLOUR_GREEN, EFFECT_NORMAL, 5),
(ENTITY_PLANT, to_unbounded_string ("Thorny Bush"), '&', COLOUR_GREEN, EFFECT_NORMAL, 7),
(ENTITY_PLANT, to_unbounded_string ("Tall Grass"), '%', COLOUR_GREEN, EFFECT_NORMAL, 3),
(ENTITY_PLANT, to_unbounded_string ("Reed"), '%', COLOUR_GREEN, EFFECT_NORMAL, 3)
);
plant_variable_data : plant_variable_list;
2023-10-09 14:56:48 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Animal
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
type animal_list is (
ANIMAL_ROACH, ANIMAL_RAT, ANIMAL_BAT, ANIMAL_SPIDER, ANIMAL_LIZARD, ANIMAL_SNAIL, ANIMAL_WORM, ANIMAL_MOLE
2023-10-09 14:56:48 -04:00
);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Goblin
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
type goblin_list is (
2023-10-10 14:34:06 -04:00
GOBLIN_SLAVE, GOBLIN_WORKER, GOBLIN_WARRIOR, GOBLIN_BOAR_RIDER, GOBLIN_SHAMAN, GOBLIN_CHIEF, GOBLIN_KING, GOBLIN_OGRE
2023-10-09 14:56:48 -04:00
);
type goblin_constant_type is new entity_constant_type with
record
2023-10-09 15:26:24 -04:00
health_limit : natural := 0;
armour_limit : natural := 0;
mana_limit : natural := 0;
stamina_limit : natural := 0;
attack_range : natural_subrange := (0, 0);
end record;
type goblin_variable_type is new entity_variable_type with
record
2023-10-09 15:26:24 -04:00
health : natural := 0;
armour : natural := 0;
mana : natural := 0;
stamina : natural := 0;
end record;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:49:02 -04:00
-- Player
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Gameplay
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2023-10-09 16:33:18 -04:00
x : natural := 0;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Terminal
-- -- Currently constant, gonna use either my xurses library or <termios.h> C bindings.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
active : boolean := true;
button : character := character'val (0);
signal : signal_list := SIGNAL_IDLE;
width : natural := 120;
height : natural := 40;
buffer : unbounded_string := null_unbounded_string;
--~procedure synchronize is
--~begin
--~signal := character'val (0);
--~put (to_string (buffer));
--~get_immediate (signal);
--~if signal = escape then
--~active := false;
--~end if;
--~end synchronize;
procedure action_idle is
begin
null;
end action_idle;
2023-10-10 13:58:50 -04:00
procedure action_exit is
begin
active := false;
end action_exit;
type procedure_pointer is access procedure;
type action_data is array (signal_list) of procedure_pointer;
action_list : action_data := (others => action_idle'access);
procedure bind (
key : signal_list := SIGNAL_IDLE;
act : procedure_pointer := action_idle'access
) is
begin
action_list (key) := act;
end bind;
2023-10-10 13:58:50 -04:00
procedure unbind (
key : signal_list := SIGNAL_IDLE
) is
begin
action_list (key) := action_idle'access;
end unbind;
procedure action_draw is
begin
buffer := buffer & format_symbol ('@', COLOUR_RED, EFFECT_BOLD);
end action_draw;
2023-10-09 23:27:39 -04:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Main
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
begin
2023-10-09 23:27:39 -04:00
bind (SIGNAL_Q, action_exit'access);
bind (SIGNAL_D, action_draw'access);
2023-10-10 14:34:06 -04:00
loop
exit when active = false;
buffer := to_unbounded_string (escape & "[H");
for y in 1 .. height
loop
for x in 1 .. width
loop
buffer := buffer & format_symbol ('X', COLOUR_GREY, EFFECT_BOLD);
end loop;
buffer := buffer & character'val (13);
buffer := buffer & character'val (10);
end loop;
button := character'val (0);
put (to_string (buffer));
get_immediate (button);
case button is
--~SIGNAL_6, SIGNAL_7, SIGNAL_8, SIGNAL_9, SIGNAL_ESCAPE, SIGNAL_TABULATOR, SIGNAL_RETURN, SIGNAL_NEW_LINE,
--~SIGNAL_SLASH, SIGNAL_BACKSLASH, SIGNAL_QUOTE, SIGNAL_BACKQUOTE, SIGNAL_SPACE, SIGNAL_BACKSPACE, SIGNAL_DOT, SIGNAL_ESCAPE
when 'a' | 'A' => signal := SIGNAL_A;
when 'b' | 'B' => signal := SIGNAL_B;
when 'c' | 'C' => signal := SIGNAL_C;
when 'd' | 'D' => signal := SIGNAL_D;
when 'e' | 'E' => signal := SIGNAL_E;
when 'f' | 'F' => signal := SIGNAL_F;
when 'g' | 'G' => signal := SIGNAL_G;
when 'h' | 'H' => signal := SIGNAL_H;
when 'i' | 'I' => signal := SIGNAL_I;
when 'j' | 'J' => signal := SIGNAL_J;
when 'k' | 'K' => signal := SIGNAL_K;
when 'l' | 'L' => signal := SIGNAL_L;
when 'm' | 'M' => signal := SIGNAL_M;
when 'n' | 'N' => signal := SIGNAL_N;
when 'o' | 'O' => signal := SIGNAL_O;
when 'p' | 'P' => signal := SIGNAL_P;
when 'q' | 'Q' => signal := SIGNAL_Q;
when 'r' | 'R' => signal := SIGNAL_R;
when 's' | 'S' => signal := SIGNAL_S;
when 't' | 'T' => signal := SIGNAL_T;
when 'u' | 'U' => signal := SIGNAL_U;
when 'v' | 'V' => signal := SIGNAL_V;
when 'w' | 'W' => signal := SIGNAL_W;
when 'x' | 'X' => signal := SIGNAL_X;
when 'y' | 'Y' => signal := SIGNAL_Y;
when 'z' | 'Z' => signal := SIGNAL_Z;
when '0' => signal := SIGNAL_0;
when '1' => signal := SIGNAL_1;
when '2' => signal := SIGNAL_2;
when '3' => signal := SIGNAL_3;
when '4' => signal := SIGNAL_4;
when '5' => signal := SIGNAL_5;
when '6' => signal := SIGNAL_6;
when '7' => signal := SIGNAL_7;
when '8' => signal := SIGNAL_8;
when '9' => signal := SIGNAL_9;
when escape => signal := SIGNAL_ESCAPE;
when others => signal := SIGNAL_IDLE;
end case;
action_list (signal).all;
if button = escape then
active := false;
end if;
2023-10-10 14:34:06 -04:00
end loop;
--~for this in magic_list
--~loop
--~put_line (format_symbol (magic_constant_data (this).symbol, magic_constant_data (this).colour, magic_constant_data (this).effect)
--~& " "
--~& to_string (magic_constant_data (this).name));
--~end loop;
--~for this in item_list
--~loop
--~put_line (format_symbol (item_constant_data (this).symbol, item_constant_data (this).colour, item_constant_data (this).effect)
--~& " "
--~& to_string (item_constant_data (this).name));
--~end loop;
--~for this in ammunition_list
--~loop
--~put_line (format_symbol (ammunition_constant_data (this).symbol, ammunition_constant_data (this).colour, ammunition_constant_data (this).effect)
--~& " "
--~& to_string (ammunition_constant_data (this).name));
--~end loop;
--~for this in weapon_list
--~loop
--~put_line (format_symbol (weapon_constant_data (this).symbol, weapon_constant_data (this).colour, weapon_constant_data (this).effect)
--~& " "
--~& to_string (weapon_constant_data (this).name));
--~end loop;
--~for this in armour_list
--~loop
--~put_line (format_symbol (armour_constant_data (this).symbol, armour_constant_data (this).colour, armour_constant_data (this).effect)
--~& " "
--~& to_string (armour_constant_data (this).name));
--~end loop;
--~for this in plant_list
--~loop
--~put_line (format_symbol (plant_constant_data (this).symbol, plant_constant_data (this).colour, plant_constant_data (this).effect)
--~& " "
--~& to_string (plant_constant_data (this).name));
--~end loop;
return 0;
end xabina;