2023-11-20 09:43:12 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
|
|
|
|
|
|
|
|
Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
|
|
|
|
And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
|
|
|
|
It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CHAPTER_5_HEADER
|
|
|
|
#define CHAPTER_5_HEADER
|
|
|
|
|
|
|
|
#include "chapter_0.h"
|
|
|
|
#include "chapter_1.h"
|
|
|
|
#include "chapter_2.h"
|
|
|
|
#include "chapter_3.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
Okay, we're finally on chapter five, and now we'll write something fun, not serious and boring. Before the Great Flood, when our ancestors were riding dinosaurs, building
|
|
|
|
pyramids, killing African men and mating with Asian women, people didn't have dedicated nor integrated graphical processing units, called GPUs. They only had their terminals,
|
|
|
|
built inside some of their spaceships. And what did they do with them? They played terminal rogue-like games, similar to those that archeologists discovered in ancient Egypt,
|
|
|
|
Syria, Sumeria, Greece and Atlantis. They were reconstructed around 50 years ago by some guy that made the game Rogue. So, all those myths, sagas and legends about Anubis,
|
|
|
|
Gilgamesh, Achilles, Inana, Gaea, they were just playable characters or main characters in those games, with different statistics, skills, attributes and back-story. Now, lets
|
|
|
|
make a simple terminal rogue-like game using what we wrote in previous chapters.
|
|
|
|
|
|
|
|
First of all, lets talk briefly about keyword 'typedef' and why I hate to use it.
|
|
|
|
*/
|
|
|
|
|
2023-11-21 08:43:45 -05:00
|
|
|
typedef int number_t;
|
2023-11-22 14:37:39 -05:00
|
|
|
typedef void procedure_t;
|
2023-11-21 08:43:45 -05:00
|
|
|
typedef char * string_t;
|
|
|
|
typedef void * memory_t;
|
|
|
|
|
2023-11-20 09:43:12 -05:00
|
|
|
typedef enum action_t {
|
2023-11-21 08:43:45 -05:00
|
|
|
GAME_ACTION_NONE,
|
|
|
|
GAME_ACTION_WAIT, GAME_ACTION_WALK, GAME_ACTION_REST, GAME_ACTION_CAMP,
|
2023-11-20 09:43:12 -05:00
|
|
|
GAME_ACTION_SWING_BLADE, GAME_ACTION_SWING_AXE, GAME_ACTION_SHOOT_ARROW, GAME_ACTION_THROW_SPEAR,
|
|
|
|
GAME_ACTION_SUMMON_PUPPET, GAME_ACTION_CALL_NATURE, GAME_ACTION_CITE_RUNE, GAME_ACTION_CAST_CHARM,
|
|
|
|
GAME_ACTION_COUNT
|
|
|
|
} action_t;
|
|
|
|
|
|
|
|
typedef struct bundle_t {
|
2023-11-22 07:47:27 -05:00
|
|
|
number_t minimum, maximum, current;
|
2023-11-20 09:43:12 -05:00
|
|
|
} bundle_t;
|
2023-11-21 08:43:45 -05:00
|
|
|
|
2023-11-22 13:51:06 -05:00
|
|
|
typedef struct symbol_t {
|
|
|
|
number_t character, colour, effect;
|
|
|
|
} symbol_t;
|
|
|
|
|
2023-11-20 09:43:12 -05:00
|
|
|
typedef struct attribute_t {
|
2023-11-21 08:43:45 -05:00
|
|
|
string_t name;
|
2023-11-22 19:55:58 -05:00
|
|
|
number_t positive_count;
|
|
|
|
number_t negative_count;
|
2023-11-21 08:43:45 -05:00
|
|
|
bundle_t * points;
|
2023-11-22 13:51:06 -05:00
|
|
|
action_t * positive;
|
|
|
|
action_t * negative;
|
2023-11-20 09:43:12 -05:00
|
|
|
} attribute_t;
|
2023-11-21 08:43:45 -05:00
|
|
|
|
2023-11-22 09:35:02 -05:00
|
|
|
typedef struct skill_t {
|
|
|
|
string_t name;
|
2023-11-22 19:55:58 -05:00
|
|
|
number_t positive_count;
|
|
|
|
number_t learning_rate;
|
2023-11-22 09:35:02 -05:00
|
|
|
bundle_t * points;
|
|
|
|
action_t * positive;
|
|
|
|
} skill_t;
|
2023-11-22 07:47:27 -05:00
|
|
|
|
2023-11-24 06:41:20 -05:00
|
|
|
typedef struct bot_t {
|
|
|
|
string_t name;
|
|
|
|
number_t x;
|
|
|
|
number_t y;
|
|
|
|
symbol_t * symbol;
|
|
|
|
bundle_t * health;
|
|
|
|
bundle_t * mana;
|
|
|
|
bundle_t * stamina;
|
|
|
|
} bot_t;
|
|
|
|
|
2023-11-20 09:43:12 -05:00
|
|
|
typedef struct player_t {
|
2023-11-24 06:41:20 -05:00
|
|
|
string_t name;
|
|
|
|
number_t x;
|
|
|
|
number_t y;
|
|
|
|
symbol_t * symbol;
|
|
|
|
bundle_t * health;
|
|
|
|
bundle_t * mana;
|
|
|
|
bundle_t * stamina;
|
|
|
|
number_t attribute_count;
|
|
|
|
number_t skill_count;
|
|
|
|
attribute_t * * attributes;
|
|
|
|
skill_t * * skills;
|
2023-11-20 09:43:12 -05:00
|
|
|
} player_t;
|
|
|
|
|
2023-11-22 09:35:02 -05:00
|
|
|
typedef struct block_t {
|
|
|
|
string_t name;
|
2023-11-22 19:55:58 -05:00
|
|
|
number_t collision;
|
|
|
|
number_t override;
|
2023-11-22 09:35:02 -05:00
|
|
|
symbol_t * symbol;
|
|
|
|
} block_t;
|
|
|
|
|
|
|
|
typedef struct world_t {
|
2023-11-22 19:55:58 -05:00
|
|
|
number_t width;
|
|
|
|
number_t height;
|
2023-11-22 09:35:02 -05:00
|
|
|
block_t * * block;
|
|
|
|
} world_t;
|
|
|
|
|
2023-11-22 14:37:39 -05:00
|
|
|
typedef procedure_t (* generate_t) (world_t *, number_t, number_t, number_t, number_t, block_t *);
|
2023-11-22 13:51:06 -05:00
|
|
|
|
|
|
|
typedef struct generator_t {
|
|
|
|
generate_t generate;
|
|
|
|
} generator_t;
|
|
|
|
|
2023-11-23 15:23:23 -05:00
|
|
|
extern memory_t memorize (number_t size);
|
|
|
|
extern number_t randomize (number_t lower, number_t upper);
|
2023-11-22 09:35:02 -05:00
|
|
|
|
2023-11-24 06:41:20 -05:00
|
|
|
extern bundle_t * game_bundle (number_t minimum, number_t maximum, number_t current);
|
|
|
|
extern symbol_t * game_symbol (number_t character, number_t colour, number_t effect);
|
2023-11-21 08:43:45 -05:00
|
|
|
|
2023-11-22 13:51:06 -05:00
|
|
|
extern generator_t * game_generator (generate_t generator);
|
2023-11-24 06:41:20 -05:00
|
|
|
|
2023-11-21 08:43:45 -05:00
|
|
|
extern attribute_t * game_attribute (string_t name, bundle_t * points, ...);
|
2023-11-22 09:35:02 -05:00
|
|
|
extern skill_t * game_skill (string_t name, bundle_t * points, ...);
|
2023-11-24 06:41:20 -05:00
|
|
|
|
|
|
|
extern bot_t * game_bot (string_t name, symbol_t * symbol, bundle_t * health, bundle_t * mana, bundle_t * stamina);
|
|
|
|
extern player_t * game_player (string_t name, symbol_t * symbol, bundle_t * health, bundle_t * mana, bundle_t * stamina, ...);
|
|
|
|
|
|
|
|
extern block_t * game_block (string_t name, symbol_t * symbol, number_t collision, number_t override);
|
|
|
|
extern world_t * game_world (number_t width, number_t height, ...);
|
2023-11-21 08:43:45 -05:00
|
|
|
|
2023-11-23 16:32:15 -05:00
|
|
|
extern procedure_t game_render_attribute (number_t x, number_t y, ...);
|
|
|
|
extern procedure_t game_render_skill (number_t x, number_t y, ...);
|
2023-11-21 08:43:45 -05:00
|
|
|
|
2023-11-24 06:41:20 -05:00
|
|
|
extern procedure_t game_render_bot (bot_t * bot);
|
|
|
|
extern procedure_t game_render_player (player_t * player);
|
|
|
|
|
|
|
|
extern procedure_t game_render_block (block_t * block, number_t x, number_t y);
|
|
|
|
extern procedure_t game_render_world (world_t * world, number_t x, number_t y, number_t width, number_t height);
|
2023-11-20 09:43:12 -05:00
|
|
|
|
|
|
|
#endif
|