2022-12-18 21:07:10 +00:00
|
|
|
// gamelogic.h: Function prototypes and data-structures for dealing with game logic.
|
2022-10-16 15:13:33 +00:00
|
|
|
// Barry Kane, 2022.
|
|
|
|
#ifndef GAMELOGIC_H
|
|
|
|
#define GAMELOGIC_H
|
2022-12-19 23:44:16 +00:00
|
|
|
#include "queue.h"
|
2022-10-16 20:28:32 +00:00
|
|
|
#include "areadata.h"
|
2022-10-16 15:13:33 +00:00
|
|
|
#include "constants.h"
|
|
|
|
#include "playerdata.h"
|
|
|
|
#include "inputoutput.h"
|
|
|
|
|
2022-12-21 00:49:26 +00:00
|
|
|
// ========================
|
|
|
|
// -=[ Data Structures ]=-:
|
|
|
|
// ========================
|
2022-12-19 23:44:16 +00:00
|
|
|
|
2023-02-12 23:32:39 +00:00
|
|
|
// An event for storing the information
|
2022-12-21 00:49:26 +00:00
|
|
|
typedef struct commandEvent commandEvent;
|
|
|
|
typedef struct commandEvent
|
|
|
|
{
|
|
|
|
playerInfo * caller;
|
|
|
|
commandEvent * next;
|
|
|
|
char * command;
|
|
|
|
char * arguments;
|
|
|
|
} commandEvent;
|
|
|
|
|
|
|
|
// A first-in first-out queue for message input from players:
|
|
|
|
typedef struct commandQueue
|
|
|
|
{
|
|
|
|
bool lock;
|
|
|
|
bool paused;
|
|
|
|
int currentLength;
|
|
|
|
commandEvent * back;
|
|
|
|
commandEvent * front;
|
|
|
|
} commandQueue;
|
2022-10-16 15:13:33 +00:00
|
|
|
|
2022-12-18 21:07:10 +00:00
|
|
|
// A data-structure containing the needed parameters for a main game loop:
|
2022-10-16 15:13:33 +00:00
|
|
|
typedef struct gameLogicParameters
|
|
|
|
{
|
2022-12-20 15:55:24 +00:00
|
|
|
// Players:
|
2022-10-16 15:13:33 +00:00
|
|
|
int * playerCount;
|
|
|
|
playerInfo * connectedPlayers;
|
2022-12-20 15:55:24 +00:00
|
|
|
|
|
|
|
// Queues:
|
2022-12-19 23:44:16 +00:00
|
|
|
queue * inputQueue;
|
2022-12-20 15:55:24 +00:00
|
|
|
queue * outputQueue;
|
|
|
|
|
|
|
|
// Lists:
|
|
|
|
list * areaList;
|
2022-11-29 21:04:36 +00:00
|
|
|
list * globalSkillList;
|
2022-10-16 15:13:33 +00:00
|
|
|
} gameLogicParameters;
|
|
|
|
|
2022-12-21 00:49:26 +00:00
|
|
|
// ========================
|
|
|
|
// -=[ Functions ]=-:
|
|
|
|
// ========================
|
2022-10-16 15:13:33 +00:00
|
|
|
|
2022-12-21 00:49:26 +00:00
|
|
|
// Player movement:
|
|
|
|
int movePlayerToArea(playerInfo * player, char * requestedPath);
|
2022-10-16 15:13:33 +00:00
|
|
|
|
2022-12-21 00:49:26 +00:00
|
|
|
// Thread function which runs the main game loop, given the needed parameters:
|
|
|
|
void * gameLogicHandler(void * parameters);
|
2022-10-16 15:13:33 +00:00
|
|
|
|
|
|
|
// Create a commandQueue:
|
|
|
|
commandQueue * createCommandQueue(void);
|
|
|
|
|
|
|
|
// Enqueue a command to a commandQueue:
|
|
|
|
int queueCommand(commandQueue * queue, char * command, char * arguments,
|
|
|
|
int commandLength, int argumentsLength , playerInfo * callingPlayer);
|
|
|
|
|
|
|
|
// Enqueue a messaged command to a commandQueue:
|
|
|
|
int queueMessagedCommand(commandQueue * queue, inputMessage * messageToQueue);
|
|
|
|
|
|
|
|
// Dequeue the front commandEvent from a commandQueue:
|
|
|
|
int dequeueCommand(commandQueue * queue);
|
|
|
|
|
|
|
|
// Return the front commandEvent from a commandQueue:
|
|
|
|
commandEvent * peekCommand(commandQueue * queue);
|
|
|
|
|
|
|
|
// Evaluate the next commandEvent:
|
|
|
|
int evaluateNextCommand(gameLogicParameters * parameters, commandQueue * queue);
|
|
|
|
|
|
|
|
/* // Evaluate the given commandEvent: */
|
|
|
|
/* int evaluateCommand(gameLogicParameters * parameters, commandEvent * command); */
|
|
|
|
|
|
|
|
// ============================
|
|
|
|
// -=[ Gameplay Primitives ]=-:
|
|
|
|
// ============================
|
|
|
|
|
2023-02-12 23:32:39 +00:00
|
|
|
// The possible outcomes of a check or challenge:
|
2022-10-16 15:13:33 +00:00
|
|
|
typedef enum outcome
|
|
|
|
{
|
|
|
|
CRITICAL_FAILURE,
|
|
|
|
FAILURE,
|
|
|
|
SUCCESS,
|
|
|
|
CRITICAL_SUCCESS,
|
|
|
|
ERROR
|
|
|
|
} outcome;
|
|
|
|
|
2022-12-21 00:49:26 +00:00
|
|
|
// Player movement:
|
|
|
|
int movePlayerToArea(playerInfo * player, char * requestedPath);
|
|
|
|
|
2022-10-16 15:13:33 +00:00
|
|
|
// Run a stat check:
|
|
|
|
outcome statCheck(playerInfo * player, int chance, coreStat statToCheck);
|
|
|
|
|
2022-10-18 20:00:57 +00:00
|
|
|
// Run a skill check:
|
2022-11-29 21:04:36 +00:00
|
|
|
outcome skillCheck(playerInfo * player, int chance, char * skillName, size_t skillNameLength, list * globalSkillList);
|
2022-10-18 20:00:57 +00:00
|
|
|
|
2022-10-16 15:13:33 +00:00
|
|
|
#endif
|