phantasia

Phantasia - 2D SDL3 RPG prototype.
git clone git://git.beep.wimdupont.com/phantasia.git
Log | Files | Refs | README | LICENSE

game.h (3898B)


      1 #ifndef PH_GAME_GAME_H
      2 #define PH_GAME_GAME_H
      3 
      4 #include "engine/battle.h"
      5 #include "engine/clock.h"
      6 #include "game/content.h"
      7 
      8 
      9 typedef enum {
     10 	PH_ACTION_NONE,
     11 	PH_ACTION_UP,
     12 	PH_ACTION_DOWN,
     13 	PH_ACTION_LEFT,
     14 	PH_ACTION_RIGHT,
     15 	PH_ACTION_ACCEPT,
     16 	PH_ACTION_CANCEL,
     17 	PH_ACTION_BACK,
     18 	PH_ACTION_CHARACTER,
     19 	PH_ACTION_INVENTORY,
     20 	PH_ACTION_SPELLBOOK,
     21 } PhAction;
     22 
     23 typedef enum {
     24 	PH_MENU_NONE,
     25 	PH_MENU_CHARACTER,
     26 	PH_MENU_INVENTORY,
     27 	PH_MENU_SPELLBOOK,
     28 	PH_MENU_SHOP,
     29 	PH_MENU_MAIN,
     30 	PH_MENU_START,
     31 } PhMenu;
     32 
     33 typedef enum {
     34 	PH_START_STAY,
     35 	PH_START_CONTINUE,
     36 	PH_START_NEW,
     37 } PhStartAction;
     38 
     39 typedef struct {
     40 	int selected;
     41 	int can_continue;
     42 } PhStartUi;
     43 
     44 typedef enum {
     45 	PH_GAME_WORLD,
     46 	PH_GAME_TRANSITION,
     47 	PH_GAME_BATTLE,
     48 	PH_GAME_VICTORY,
     49 	PH_GAME_OVER,
     50 } PhGameMode;
     51 
     52 typedef enum {
     53 	PH_INVENTORY_BROWSE,
     54 	PH_INVENTORY_ACTIONS,
     55 	PH_INVENTORY_EXAMINE,
     56 } PhInventoryMode;
     57 
     58 typedef enum {
     59 	PH_INVENTORY_EQUIP,
     60 	PH_INVENTORY_USE,
     61 	PH_INVENTORY_DROP,
     62 	PH_INVENTORY_EXAMINE_ACTION,
     63 	PH_INVENTORY_ACTION_COUNT,
     64 } PhInventoryAction;
     65 
     66 typedef struct {
     67 	int selected;
     68 	int option;
     69 	PhInventoryMode mode;
     70 	char status[64];
     71 } PhInventoryUi;
     72 
     73 typedef enum {
     74 	PH_SPELLBOOK_BROWSE,
     75 	PH_SPELLBOOK_ACTIONS,
     76 	PH_SPELLBOOK_EXAMINE,
     77 } PhSpellbookMode;
     78 
     79 typedef enum {
     80 	PH_SPELLBOOK_USE,
     81 	PH_SPELLBOOK_EXAMINE_ACTION,
     82 	PH_SPELLBOOK_ACTION_COUNT,
     83 } PhSpellbookAction;
     84 
     85 typedef struct {
     86 	int selected;
     87 	int option;
     88 	PhSpellbookMode mode;
     89 	int spell_used;
     90 	char status[64];
     91 } PhSpellbookUi;
     92 
     93 typedef enum {
     94 	PH_SHOP_ROOT,
     95 	PH_SHOP_BUY,
     96 	PH_SHOP_SELL,
     97 	PH_SHOP_TALK,
     98 } PhShopMode;
     99 
    100 typedef struct {
    101 	int shop_id;
    102 	int selected;
    103 	PhShopMode mode;
    104 	char status[64];
    105 } PhShopUi;
    106 
    107 typedef enum {
    108 	PH_OPTIONS_ROOT,
    109 	PH_OPTIONS_SOUND,
    110 } PhOptionsMode;
    111 
    112 typedef enum {
    113 	PH_OPTIONS_STAY,
    114 	PH_OPTIONS_CLOSE,
    115 	PH_OPTIONS_EXIT,
    116 } PhOptionsAction;
    117 
    118 typedef struct {
    119 	int selected;
    120 	int music_enabled;
    121 	int effects_enabled;
    122 	PhOptionsMode mode;
    123 } PhOptionsUi;
    124 
    125 typedef struct {
    126 	PhWorld *world;
    127 	PhInventoryUi *inventory;
    128 	PhSpellbookUi *spellbook;
    129 	PhShopUi *shop;
    130 	PhOptionsUi *options;
    131 	PhStartUi *start;
    132 	PhGameMode *mode;
    133 	PhBattle *battle;
    134 	PhSpellBook *spells;
    135 	PhMenu menu;
    136 	PhClock clock;
    137 	int time_reset;
    138 } PhGameContext;
    139 
    140 int ph_inventory_step(const PhWorld *world, int selected, int direction);
    141 void ph_inventory_open(PhInventoryUi *ui, const PhWorld *world);
    142 int ph_inventory_input(PhInventoryUi *ui, PhWorld *world, PhAction key);
    143 void ph_spellbook_open(PhSpellbookUi *ui, const PhSpellBook *spells);
    144 int ph_spellbook_input(PhSpellbookUi *ui, PhWorld *world, PhSpellBook *spells,
    145 	PhAction key);
    146 void ph_shop_open(PhShopUi *ui, int shop_id);
    147 PhMenu ph_interaction_open(PhShopUi *shop_ui, int interaction_id);
    148 void ph_options_open(PhOptionsUi *ui);
    149 PhOptionsAction ph_options_input(PhOptionsUi *ui, PhAction key);
    150 PhStartAction ph_start_input(PhStartUi *ui, PhAction key);
    151 int ph_shop_input(PhShopUi *ui, PhWorld *world, PhSpellBook *spells,
    152 	PhAction key);
    153 /* Drawing and input share the same available menu actions. */
    154 int ph_inventory_action_enabled(const PhItemDef *item, int action);
    155 void ph_inventory_action_order(const PhItemDef *item, int actions[PH_INVENTORY_ACTION_COUNT]);
    156 int ph_spellbook_action_enabled(const PhSpellDef *spell, int action);
    157 
    158 enum {
    159 	PH_GAME_REQUEST_NEW = 1,
    160 	PH_GAME_REQUEST_EXIT = 2,
    161 	PH_GAME_MENU_SOUND = 4,
    162 };
    163 
    164 /* Returns request flags; the host performs lifecycle operations. */
    165 int ph_game_input(PhGameContext *context, PhAction key);
    166 /* Writes the pre-combat checkpoint if save_path is non-NULL; returns whether
    167  * an autosave is needed. NULL disables persistence for replay/tests. */
    168 int ph_game_update(PhGameContext *context, PhInput input, float dt, const char *save_path);
    169 void ph_game_interaction(PhGameContext *context);
    170 /* Discards paused time and the frame containing an input-driven state change. */
    171 int ph_game_steps(PhGameContext *context, uint64_t elapsed_ns);
    172 
    173 #endif