diff --git a/xabina.adb b/xabina.adb index 791b715..c89c847 100644 --- a/xabina.adb +++ b/xabina.adb @@ -14,7 +14,8 @@ with ada.text_io, ada.strings.unbounded; use ada.text_io, ada.strings.unbounded; -- Do not use this command below, it's for real-time game... --- $ gnatmake xabina.adb && stty raw -echo && ./xabina && reset +-- $ gnatmake xabina.adb +-- $ stty raw -echo && ./xabina && stty sane function xabina return integer is @@ -294,7 +295,9 @@ function xabina return integer is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ type weapon_list is ( - IRON_SWORD, IRON_GREATSWORD, IRON_AXE, IRON_BATTLEAXE, IRON_SPEAR, IRON_SHIELD, IRON_MACE, IRON_HAMMER + 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 ); type weapon_mark is mod 72; @@ -319,14 +322,30 @@ function xabina return integer is 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 ("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)) ); weapon_variable_data : weapon_variable_list; @@ -470,43 +489,114 @@ function xabina return integer is x : natural := 0; +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +-- Terminal +-- -- Currently constant, gonna use either my xurses library or C bindings. +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + + escape : character := character'val (27); + + terminal_active : boolean := true; + terminal_signal : character := character'val (0); + terminal_width : natural := 120; + terminal_height : natural := 40; + terminal_buffer : unbounded_string := null_unbounded_string; + + function format_symbol ( + symbol : character := ' '; + colour : colours := COLOUR_WHITE; + effect : effects := EFFECT_NORMAL + ) return string is + format : string (1 .. 12) := escape & "[E;3CmS" & escape & "[0m"; + 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'; + 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'; + end case; + format (8) := symbol; + return format; + end format_symbol; + + procedure terminal_synchronize is + begin + terminal_signal := character'val (0); + put (to_string (terminal_buffer)); + get_immediate (terminal_signal); + if terminal_signal = escape then + terminal_active := false; + end if; + end terminal_synchronize; + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +-- Main +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ + begin - for this in magic_list loop - x := x + render_character (magic_constant_data (this).symbol, magic_constant_data (this).colour, magic_constant_data (this).effect); - put_line (" " & to_string (magic_constant_data (this).name)); + exit when terminal_active = false; + terminal_buffer := to_unbounded_string (escape & "[H"); + for y in 1 .. terminal_height + loop + for x in 1 .. terminal_width + loop + terminal_buffer := terminal_buffer & format_symbol ('X', COLOUR_GREY, EFFECT_BOLD); + end loop; + terminal_buffer := terminal_buffer & character'val (13); + terminal_buffer := terminal_buffer & character'val (10); + end loop; + terminal_synchronize; end loop; - for this in item_list - loop - x := x + render_character (item_constant_data (this).symbol, item_constant_data (this).colour, item_constant_data (this).effect); - put_line (" " & to_string (item_constant_data (this).name)); - end loop; + --~for this in magic_list + --~loop + --~x := x + render_character (magic_constant_data (this).symbol, magic_constant_data (this).colour, magic_constant_data (this).effect); + --~put_line (" " & to_string (magic_constant_data (this).name)); + --~end loop; - for this in ammunition_list - loop - x := x + render_character (ammunition_constant_data (this).symbol, ammunition_constant_data (this).colour, ammunition_constant_data (this).effect); - put_line (" " & to_string (ammunition_constant_data (this).name)); - end loop; + --~for this in item_list + --~loop + --~x := x + render_character (item_constant_data (this).symbol, item_constant_data (this).colour, item_constant_data (this).effect); + --~put_line (" " & to_string (item_constant_data (this).name)); + --~end loop; - for this in weapon_list - loop - x := x + render_character (weapon_constant_data (this).symbol, weapon_constant_data (this).colour, weapon_constant_data (this).effect); - put_line (" " & to_string (weapon_constant_data (this).name)); - end loop; + --~for this in ammunition_list + --~loop + --~x := x + render_character (ammunition_constant_data (this).symbol, ammunition_constant_data (this).colour, ammunition_constant_data (this).effect); + --~put_line (" " & to_string (ammunition_constant_data (this).name)); + --~end loop; - for this in armour_list - loop - x := x + render_character (armour_constant_data (this).symbol, armour_constant_data (this).colour, armour_constant_data (this).effect); - put_line (" " & to_string (armour_constant_data (this).name)); - end loop; + --~for this in weapon_list + --~loop + --~x := x + render_character (weapon_constant_data (this).symbol, weapon_constant_data (this).colour, weapon_constant_data (this).effect); + --~put_line (" " & to_string (weapon_constant_data (this).name)); + --~end loop; - for this in plant_list - loop - x := x + render_character (plant_constant_data (this).symbol, plant_constant_data (this).colour, plant_constant_data (this).effect); - put_line (" " & to_string (plant_constant_data (this).name)); - end loop; + --~for this in armour_list + --~loop + --~x := x + render_character (armour_constant_data (this).symbol, armour_constant_data (this).colour, armour_constant_data (this).effect); + --~put_line (" " & to_string (armour_constant_data (this).name)); + --~end loop; + + --~for this in plant_list + --~loop + --~x := x + render_character (plant_constant_data (this).symbol, plant_constant_data (this).colour, plant_constant_data (this).effect); + --~put_line (" " & to_string (plant_constant_data (this).name)); + --~end loop; return 0;