Skip to content

Game State ~ How to implement a new CLI mode

aliu65803 edited this page May 18, 2022 · 12 revisions

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.

How CLI uses modes:

What is a mode operation?

What is a cli_callback function? 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.

How to implement a mode:

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 ".

When in battle mode,

Clone this wiki locally