Cleaned up gamelogic.c/h

- Improved comments to clarify the purpose and usage of the data structures and functions.
- Brought the files in line with the SilverMUD style guide.
This commit is contained in:
Barry Kane 2023-02-15 21:43:13 +00:00
parent c2af4a551a
commit f31f0c79a5
2 changed files with 74 additions and 76 deletions

View File

@ -93,7 +93,7 @@ void * gameLogicHandler(void * parameters)
pthread_exit(NULL); pthread_exit(NULL);
} }
// Enqueue a messaged command to a commandQueue: // Evaluate the next commandEvent in a queue:
void queueMessagedCommand(queue * queue, inputMessage * messageToQueue) void queueMessagedCommand(queue * queue, inputMessage * messageToQueue)
{ {
// Prepare the new commandEvent: // Prepare the new commandEvent:
@ -126,8 +126,9 @@ void queueMessagedCommand(queue * queue, inputMessage * messageToQueue)
pushQueue(queue, newCommand, COMMAND); pushQueue(queue, newCommand, COMMAND);
} }
// Enqueue a command to a commandQueue: // Enqueue a command to a queue:
void queueCommand(queue * queue, char * command, char * arguments, int commandLength, int argumentsLength, playerInfo * callingPlayer) void queueCommand(queue * queue, char * command, char * arguments, int commandLength, int argumentsLength,
playerInfo * callingPlayer)
{ {
// Prepare the new commandEvent: // Prepare the new commandEvent:
commandEvent * newCommand = calloc(1, sizeof(commandEvent)); commandEvent * newCommand = calloc(1, sizeof(commandEvent));
@ -147,7 +148,7 @@ void queueCommand(queue * queue, char * command, char * arguments, int commandLe
pushQueue(queue, newCommand, COMMAND); pushQueue(queue, newCommand, COMMAND);
} }
// Evaluate the next commandEvent: // Evaluate the next commandEvent in a queue:
int evaluateNextCommand(gameLogicParameters * parameters, queue * queue) int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
{ {
commandEvent * currentCommand = peekQueue(queue)->data.command; commandEvent * currentCommand = peekQueue(queue)->data.command;
@ -555,7 +556,7 @@ int evaluateNextCommand(gameLogicParameters * parameters, queue * queue)
return 0; return 0;
} }
// Run a stat check: // Run a stat check for the given player, returning an outcome:
outcome statCheck(playerInfo * player, int chance, coreStat statToCheck) outcome statCheck(playerInfo * player, int chance, coreStat statToCheck)
{ {
// Calculate the chance: // Calculate the chance:
@ -624,7 +625,7 @@ outcome statCheck(playerInfo * player, int chance, coreStat statToCheck)
} }
} }
// Run a skill check: // Run a skill check for the given player, returning an outcome:
outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t skillNameLength, list * globalSkillList) outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t skillNameLength, list * globalSkillList)
{ {
// Calculate the chance: // Calculate the chance:
@ -697,7 +698,7 @@ outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t ski
} }
} }
// Move a player to a different area given a path in the area: // Move a player along a path in their current area:
int movePlayerToArea(playerInfo * player, char * requestedPath) int movePlayerToArea(playerInfo * player, char * requestedPath)
{ {
// Check if a number was given first: // Check if a number was given first:

View File

@ -12,7 +12,7 @@
// -=[ Data Structures ]=-: // -=[ Data Structures ]=-:
// ======================== // ========================
// An event for storing the information // An event for storing the information needed to evaluate a command:
typedef struct commandEvent commandEvent; typedef struct commandEvent commandEvent;
typedef struct commandEvent typedef struct commandEvent
{ {
@ -22,7 +22,7 @@ typedef struct commandEvent
char * arguments; char * arguments;
} commandEvent; } commandEvent;
// A data-structure containing the needed parameters for a main game loop: // A data-structure containing the needed parameters for the main game loop:
typedef struct gameLogicParameters typedef struct gameLogicParameters
{ {
// Players: // Players:
@ -42,22 +42,19 @@ typedef struct gameLogicParameters
// -=[ Functions ]=-: // -=[ Functions ]=-:
// ======================== // ========================
// Player movement:
int movePlayerToArea(playerInfo * player, char * requestedPath);
// Thread function which runs the main game loop, given the needed parameters: // Thread function which runs the main game loop, given the needed parameters:
void * gameLogicHandler(void * parameters); void * gameLogicHandler(void * parameters);
// Enqueue a command to a commandQueue: // Enqueue a command that has been sent as a message from a user to a queue:
void queueCommand(queue * queue, char * command, char * arguments,
int commandLength, int argumentsLength , playerInfo * callingPlayer);
// Enqueue a messaged command to a commandQueue:
void queueMessagedCommand(queue * queue, inputMessage * messageToQueue); void queueMessagedCommand(queue * queue, inputMessage * messageToQueue);
// Evaluate the next commandEvent: // Evaluate the next commandEvent in a queue:
int evaluateNextCommand(gameLogicParameters * parameters, queue * queue); int evaluateNextCommand(gameLogicParameters * parameters, queue * queue);
// Enqueue a command to a queue:
void queueCommand(queue * queue, char * command, char * arguments, int commandLength, int argumentsLength,
playerInfo * callingPlayer);
// ============================ // ============================
// -=[ Gameplay Primitives ]=-: // -=[ Gameplay Primitives ]=-:
// ============================ // ============================
@ -72,13 +69,13 @@ typedef enum outcome
ERROR ERROR
} outcome; } outcome;
// Player movement: // Move a player along a path in their current area:
int movePlayerToArea(playerInfo * player, char * requestedPath); int movePlayerToArea(playerInfo * player, char * requestedPath);
// Run a stat check: // Run a stat check for the given player, returning an outcome:
outcome statCheck(playerInfo * player, int chance, coreStat statToCheck); outcome statCheck(playerInfo * player, int chance, coreStat statToCheck);
// Run a skill check: // Run a skill check for the given player, returning an outcome:
outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t skillNameLength, list * globalSkillList); outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t skillNameLength, list * globalSkillList);
#endif #endif