-
Notifications
You must be signed in to change notification settings - Fork 13
Game State ~ How to implement a new CLI mode
When working on our run_battle function, Emilio, Nafis, and I realized we would need to switch our mode into battle mode, but we were unsure how to do so and what exactly that meant. This document goes through how to switch to the desired mode and how CLI works in each mode. We will use the battle mode as an example.
The cli loop has four main steps:
- it takes a user input.
- it runs the
mode_operation
function for its current mode. - it takes the string returned by the
mode_operation
and prints it as a prompt.
The mode_operation in NORMAL
mode parses the user's input and searches a hash table of commands for the command the user inputted, then runs the command operation function designated to that command (e.g. the PULL
entry in the hash table has a value pull_operation()
) the given operation function is run and the return string printed as a prompt.
If the cli mode is changed by set_game_mode()
, a different mode_operation will be run.
The chiventure_ctx of a given game contains a mode struct:
/* Mode data type */
typedef struct game_mode {
mode_type_t curr_mode;
mode_operation *run_mode; //the mode's run function
char* mode_ctx; //for specifying mode's context, e.g. npc_id
} game_mode_t;
curr_mode specifies the mode, currently either NORMAL, CONVERSATION, or BATTLE.
run_mode is a mode_operation function which has to be a function in the form:
int mode_operation(char *str, cli_callback callback_func, void *callback_args, chiventure_ctx_t *ctx);
mode_ctx is just a string that describes the battle (e.g. "fight Gandalf the Grey"
) for an instance of the battle mode.
the mode tells the cli how to handle an input by specifying a mode_operation that takes an input string and returns an output/prompt string.
A CLI callback function prints the given string to the CLI. A callback function takes in a pointer to a Chiventure context struct, a string to be printed as a result of running this command, and additional arguments. See cli/cmd.h for more information.
The first step in the process is adding the desired entry to the normal mode. The add_entry function will take in a command name, operation of added entry, an action type, and a lookup table.
For example, this is what adding the entry for the fight operation would look like:
add_entry("FIGHT", fight_operation, NULL, ctx->cli_ctx->table);
Now, the CLI knows to switch to battle mode when a player inputs "FIGHT <enemy". It does so with the fight operation. The fight operation is a CLI operation for starting a fight, and it will check if the enemy name that was inputting is valid. If it is, the CLI will print the beginning string of the battle and start the first turn of the battle. For different modes, the keyword will be different--for example, you can enter NPC conversation mode by typing "TALK ".
Now that the CLI has switched to the desired mode, it will run the mode with the corresponding run function found in game-state/mode.h. For example, the run_battle_mode will now parse user input and run another turn of the fight. Once the fight is over, the mode will be switched back to regular mode.
While the battle mode was used in this example, this may be applied to all modes, such as the NPC conversation mode.
In summary, to implement a mode, you need to add support for it in set_game_mode in game_state/mode.c, write a function in the mode module that runs any setup that you need before the mode starts running and then returns the first line to be printed, then add it as an entry in the cli/operations module. Finally you need to write a mode_operation that takes an input string and calls callback_func to send back an output string.
-
Action Management
-
Battles
- Design Document
- Text Based Combat in Other Games
- User Stories
- Wishlist
- Battle Planning 2022
- Battle User Stories Review 2022
- Structs in Other Modules Related to Battles 2022
- Stat Changes Design Document
- Run Function Design Document
- CLI Integration Design Document
- Move Changes Design Document
- Unstubbing Stubs Design Document
- Battle Items and Equipment Design Document
- Battle Item Stats
- Battles Demo Design Document
- Battles Testing Moves, Items, and Equipment Design Document
- Sound integration with battle (design document)
-
Custom Actions
-
Custom Scripts
-
DSL
-
CLI
-
Enhanced CLI
-
Game-State
-
Graphics
- Design Plan
- Design document for integrating split screen graphics with chiventure
- GDL (Graphical Description Language)
- Graphics Sandbox
- Design Document for NPC Graphics and Dialogue
- Feature Wishlist (Spring 2021)
- Installing and Building raylib on a VM
- LibSDL Research
- Module Interactions
- Working with Raylib and SSH
- raylib
- GDL
-
Linking the Libzip and Json C to chiventure on CSIL machines
-
Lua
-
NPC
- Dependencies: Player class, Open world, Battle
- Action Documentation
- Design Document for NPC Generation in Openworld
- Design and Planning
- Establishing Dependencies
- Implementation of Custom Scripts
- Independent Feature: NPC Movement Design Document
- Player Interaction Design and Planning
- Dialogue
- Design Document for NPC Dialogue and Action Implementation
- Loading NPCs from WDL Files
- NPC Battle Integration Design Document
- NPC Battle Integration Changes Design Document
-
Open World
- Autogeneration and Game State
- Deciding an integration approach
- Designing approach for static integration into chiventure
- Feature Wishlist
- Generation Module Design layout
- Potential connections to the rest of chiventure
- Single Room Generation Module Design
- Source Document
- User Stories
- World Generation Algorithm Plan
- Loading OpenWorld Attribute from WDL
-
Player Class
-
Player
-
Quests
-
Rooms
-
Skill Trees
- Avoiding soft locks in skill tree integration
- Components of Exemplary Skill Trees
- Design Document and Interface Guide
- Environment interactions based on skill characteristics
- Integrating complex skill (combined, random, sequential, etc.) implementation
- Integration of a Leveling System
- Potential Integration with existing WDL
- Research on game balancing in regards to skill trees
- Research on skill tree support in modern day game engines
- SkillTree Wiki Summary
- Skilltree "effect" implementation and roadmap
- Summary of md doc file for skilltrees
- Design ideas in connection to other features
- Summary of Skill Tree Integration 2022
- The Difficulty of the Reading the World
- Complex Skills Summary
-
Sound
-
Stats
-
WDL