Completed Reorganization of Area Data
- Moved the appropriate data structures and functions into areaData. - Made movePlayerToArea a gameplay primitive.
This commit is contained in:
parent
52b4b1e2f0
commit
f2dd83857f
|
@ -1,8 +1,81 @@
|
||||||
// areadata.c: Implements functions for playerAreas and playerPaths in SilverMUD:
|
// areadata.c: Implements functions for playerAreas and playerPaths in SilverMUD:
|
||||||
// Barra Ó Catháin, 2022.
|
// Barra Ó Catháin, 2022.
|
||||||
|
#include <string.h>
|
||||||
#include "areadata.h"
|
#include "areadata.h"
|
||||||
#include "playerdata.h"
|
#include "playerdata.h"
|
||||||
|
|
||||||
|
// ====================
|
||||||
|
// -=[ Area/Paths: ]=-:
|
||||||
|
// ====================
|
||||||
|
|
||||||
|
// Create an area given a name and description:
|
||||||
|
playerArea * createArea(char * nameString, char * descriptionString)
|
||||||
|
{
|
||||||
|
// Allocate and zero memory for the new area:
|
||||||
|
playerArea * createdArea = calloc(1, sizeof(playerArea));
|
||||||
|
|
||||||
|
// Copy the strings into the newly created area:
|
||||||
|
strncpy(createdArea->areaName, nameString, 32 - 1);
|
||||||
|
strncpy(createdArea->areaDescription, descriptionString, MAX - 35);
|
||||||
|
|
||||||
|
// Properly null-terminate the strings:
|
||||||
|
createdArea->areaName[31] = '\0';
|
||||||
|
createdArea->areaDescription[MAX] = '\0';
|
||||||
|
|
||||||
|
// Ensure that all the paths are set to NULL:
|
||||||
|
for(int index = 0; index < 16; index++)
|
||||||
|
{
|
||||||
|
createdArea->areaExits[index] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the pointer:
|
||||||
|
return createdArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a path between two areas given two areas and two strings:
|
||||||
|
int createPath(playerArea * fromArea, playerArea * toArea, char * fromDescription, char * toDescription)
|
||||||
|
{
|
||||||
|
int fromAreaSlot, toAreaSlot;
|
||||||
|
for(fromAreaSlot = 0; fromAreaSlot < 16; fromAreaSlot++)
|
||||||
|
{
|
||||||
|
if(fromArea->areaExits[fromAreaSlot] == NULL)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if((fromArea->areaExits[fromAreaSlot] != NULL) && (fromAreaSlot == 15))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(toAreaSlot = 0; toAreaSlot < 32; toAreaSlot++)
|
||||||
|
{
|
||||||
|
if(toArea->areaExits[toAreaSlot] == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if((toArea->areaExits[toAreaSlot] != 0) && (toAreaSlot == 31))
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
playerPath * fromPath = malloc(sizeof(playerPath));
|
||||||
|
playerPath * toPath = malloc(sizeof(playerPath));
|
||||||
|
fromArea->areaExits[fromAreaSlot] = fromPath;
|
||||||
|
toArea->areaExits[toAreaSlot] = toPath;
|
||||||
|
strncpy(fromPath->pathName, fromDescription, 32 - 1);
|
||||||
|
fromPath->pathName[31] = '\0';
|
||||||
|
strncpy(toPath->pathName, toDescription, 32 - 1);
|
||||||
|
toPath->pathName[31] = '\0';
|
||||||
|
fromArea->areaExits[fromAreaSlot]->areaToJoin = toArea;
|
||||||
|
toArea->areaExits[toAreaSlot]->areaToJoin = fromArea;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// -=[ Area/Path Lists: ]=-:
|
||||||
|
// =========================
|
||||||
|
|
||||||
|
// Create and initialize an areaList:
|
||||||
areaNode * createAreaList(playerArea * initialArea)
|
areaNode * createAreaList(playerArea * initialArea)
|
||||||
{
|
{
|
||||||
areaNode * newAreaList = malloc(sizeof(areaNode));
|
areaNode * newAreaList = malloc(sizeof(areaNode));
|
||||||
|
@ -12,7 +85,7 @@ areaNode * createAreaList(playerArea * initialArea)
|
||||||
return newAreaList;
|
return newAreaList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create and initialize an pathList:
|
||||||
pathNode * createPathList(playerPath * initialPath)
|
pathNode * createPathList(playerPath * initialPath)
|
||||||
{
|
{
|
||||||
pathNode * newPathList = malloc(sizeof(pathNode));
|
pathNode * newPathList = malloc(sizeof(pathNode));
|
||||||
|
@ -22,13 +95,16 @@ pathNode * createPathList(playerPath * initialPath)
|
||||||
return newPathList;
|
return newPathList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds an areaNode to the end of a list, returning it's position:
|
||||||
int addAreaNodeToList(areaNode * toList, playerArea * areaToAdd)
|
int addAreaNodeToList(areaNode * toList, playerArea * areaToAdd)
|
||||||
{
|
{
|
||||||
areaNode * current;
|
areaNode * current;
|
||||||
|
int index = 0;
|
||||||
current = toList;
|
current = toList;
|
||||||
while(current->next != NULL)
|
while(current->next != NULL)
|
||||||
{
|
{
|
||||||
current = current->next;
|
current = current->next;
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
current->next = malloc(sizeof(areaNode));
|
current->next = malloc(sizeof(areaNode));
|
||||||
current->next->prev = current;
|
current->next->prev = current;
|
||||||
|
@ -37,6 +113,7 @@ int addAreaNodeToList(areaNode * toList, playerArea * areaToAdd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes an areaNode from the list, returning 0 on success and -1 on failure:
|
||||||
int deleteAreaNodeFromList(areaNode * fromList, playerArea * areaToDelete)
|
int deleteAreaNodeFromList(areaNode * fromList, playerArea * areaToDelete)
|
||||||
{
|
{
|
||||||
areaNode * current = fromList;
|
areaNode * current = fromList;
|
||||||
|
@ -46,7 +123,7 @@ int deleteAreaNodeFromList(areaNode * fromList, playerArea * areaToDelete)
|
||||||
}
|
}
|
||||||
if(current->next == NULL && current->data != areaToDelete)
|
if(current->next == NULL && current->data != areaToDelete)
|
||||||
{
|
{
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
current->prev->next = current->next;
|
current->prev->next = current->next;
|
||||||
if(current->next != NULL)
|
if(current->next != NULL)
|
||||||
|
@ -57,21 +134,25 @@ int deleteAreaNodeFromList(areaNode * fromList, playerArea * areaToDelete)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds an pathNode to the end of a list, returning it's position:
|
||||||
int addPathNodeToList(pathNode * toList, playerPath * pathToAdd)
|
int addPathNodeToList(pathNode * toList, playerPath * pathToAdd)
|
||||||
{
|
{
|
||||||
pathNode * current;
|
pathNode * current;
|
||||||
|
int index = 0;
|
||||||
current = toList;
|
current = toList;
|
||||||
while(current->next != NULL)
|
while(current->next != NULL)
|
||||||
{
|
{
|
||||||
current = current->next;
|
current = current->next;
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
current->next = malloc(sizeof(pathNode));
|
current->next = malloc(sizeof(pathNode));
|
||||||
current->next->prev = current;
|
current->next->prev = current;
|
||||||
current->next->data = pathToAdd;
|
current->next->data = pathToAdd;
|
||||||
current->next->next = NULL;
|
current->next->next = NULL;
|
||||||
return 0;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes an pathNode from the list, returning 0 on success and -1 on failure:
|
||||||
int deletePathNodeFromList(pathNode * fromList, playerPath * pathToDelete)
|
int deletePathNodeFromList(pathNode * fromList, playerPath * pathToDelete)
|
||||||
{
|
{
|
||||||
pathNode * current = fromList;
|
pathNode * current = fromList;
|
||||||
|
@ -81,7 +162,7 @@ int deletePathNodeFromList(pathNode * fromList, playerPath * pathToDelete)
|
||||||
}
|
}
|
||||||
if(current->next == NULL && current->data != pathToDelete)
|
if(current->next == NULL && current->data != pathToDelete)
|
||||||
{
|
{
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
current->prev->next = current->next;
|
current->prev->next = current->next;
|
||||||
if(current->next != NULL)
|
if(current->next != NULL)
|
||||||
|
@ -92,6 +173,7 @@ int deletePathNodeFromList(pathNode * fromList, playerPath * pathToDelete)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the areaNode at the given index from the list:
|
||||||
areaNode * getAreaNode(areaNode * fromList, int listIndex)
|
areaNode * getAreaNode(areaNode * fromList, int listIndex)
|
||||||
{
|
{
|
||||||
areaNode * current = fromList;
|
areaNode * current = fromList;
|
||||||
|
@ -109,6 +191,7 @@ areaNode * getAreaNode(areaNode * fromList, int listIndex)
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the pathNode at the given index from the list:
|
||||||
pathNode * getPathNode(pathNode * fromList, int listIndex)
|
pathNode * getPathNode(pathNode * fromList, int listIndex)
|
||||||
{
|
{
|
||||||
pathNode * current = fromList;
|
pathNode * current = fromList;
|
||||||
|
@ -126,9 +209,9 @@ pathNode * getPathNode(pathNode * fromList, int listIndex)
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the playerArea of the areaNode at the given index from the list:
|
||||||
playerArea * getAreaFromList(areaNode * fromList, int listIndex)
|
playerArea * getAreaFromList(areaNode * fromList, int listIndex)
|
||||||
{
|
{
|
||||||
areaNode * current = getAreaNode(fromList, listIndex);
|
areaNode * current = getAreaNode(fromList, listIndex);
|
||||||
return current->data;
|
return current->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,36 @@
|
||||||
// Barra Ó Catháin, 2022.
|
// Barra Ó Catháin, 2022.
|
||||||
#ifndef AREADATA_H
|
#ifndef AREADATA_H
|
||||||
#define AREADATA_H
|
#define AREADATA_H
|
||||||
#include "playerdata.h"
|
#include "constants.h"
|
||||||
|
// ====================
|
||||||
|
// -=[ Area/Paths: ]=-:
|
||||||
|
// ====================
|
||||||
|
|
||||||
|
typedef struct playerPath playerPath;
|
||||||
|
typedef struct playerArea playerArea;
|
||||||
|
|
||||||
|
struct playerPath
|
||||||
|
{
|
||||||
|
char pathName[32];
|
||||||
|
playerArea * areaToJoin;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct playerArea
|
||||||
|
{
|
||||||
|
char areaName[32];
|
||||||
|
char areaDescription[MAX - 35];
|
||||||
|
playerPath * areaExits[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create an area given a name and description:
|
||||||
|
playerArea * createArea(char * nameString, char * descriptionString);
|
||||||
|
|
||||||
|
// Create a path between two areas given two areas and two strings:
|
||||||
|
int createPath(playerArea * fromArea, playerArea * toArea, char * fromDescription, char * toDescription);
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// -=[ Area/Path Lists: ]=-:
|
||||||
|
// =========================
|
||||||
|
|
||||||
typedef struct areaNode areaNode;
|
typedef struct areaNode areaNode;
|
||||||
typedef struct pathNode pathNode;
|
typedef struct pathNode pathNode;
|
||||||
|
@ -21,22 +50,31 @@ struct areaNode
|
||||||
areaNode * prev;
|
areaNode * prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create and initialize an areaList:
|
||||||
areaNode * createAreaList(playerArea * initialArea);
|
areaNode * createAreaList(playerArea * initialArea);
|
||||||
|
|
||||||
|
// Create and initialize an pathList:
|
||||||
pathNode * createPathList(playerPath * initialPath);
|
pathNode * createPathList(playerPath * initialPath);
|
||||||
|
|
||||||
|
// Adds an areaNode to the end of a list, returning it's position:
|
||||||
int addAreaNodeToList(areaNode * toList, playerArea * areaToAdd);
|
int addAreaNodeToList(areaNode * toList, playerArea * areaToAdd);
|
||||||
|
|
||||||
|
// Removes an areaNode from the list, returning 0 on success and -1 on failure:
|
||||||
int deleteAreaNodeFromList(areaNode * fromList, playerArea * areaToDelete);
|
int deleteAreaNodeFromList(areaNode * fromList, playerArea * areaToDelete);
|
||||||
|
|
||||||
|
// Adds an pathNode to the end of a list, returning it's position:
|
||||||
int addPathNodeToList(pathNode * toList, playerPath * pathToAdd);
|
int addPathNodeToList(pathNode * toList, playerPath * pathToAdd);
|
||||||
|
|
||||||
|
// Removes an pathNode from the list, returning 0 on success and -1 on failure:
|
||||||
int deletePathNodeFromList(pathNode * fromList, playerPath * pathToDelete);
|
int deletePathNodeFromList(pathNode * fromList, playerPath * pathToDelete);
|
||||||
|
|
||||||
|
// Return the areaNode at the given index from the list:
|
||||||
areaNode * getAreaNode(areaNode * fromList, int listIndex);
|
areaNode * getAreaNode(areaNode * fromList, int listIndex);
|
||||||
|
|
||||||
|
// Return the pathNode at the given index from the list:
|
||||||
pathNode * getPathNode(pathNode * fromList, int listIndex);
|
pathNode * getPathNode(pathNode * fromList, int listIndex);
|
||||||
|
|
||||||
|
// Return the playerArea of the areaNode at the given index from the list:
|
||||||
playerArea * getAreaFromList(areaNode * fromList, int listIndex);
|
playerArea * getAreaFromList(areaNode * fromList, int listIndex);
|
||||||
|
|
||||||
// TO BE IMPLEMENTED:
|
// TO BE IMPLEMENTED:
|
||||||
|
|
|
@ -708,3 +708,37 @@ outcome statCheck(playerInfo * player, int chance, coreStat statToCheck)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move a player to a different area given a path in the area:
|
||||||
|
int movePlayerToArea(playerInfo * player, char * requestedPath)
|
||||||
|
{
|
||||||
|
// Check if a number was given first:
|
||||||
|
int selected = atoi(requestedPath);
|
||||||
|
if(selected != 0)
|
||||||
|
{
|
||||||
|
if(player->currentArea->areaExits[selected - 1] != NULL &&
|
||||||
|
player->currentArea->areaExits[selected - 1]->areaToJoin != NULL)
|
||||||
|
{
|
||||||
|
player->currentArea = player->currentArea->areaExits[selected - 1]->areaToJoin;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise search for the description:
|
||||||
|
for (int index = 0; index < 16; index++)
|
||||||
|
{
|
||||||
|
if(player->currentArea->areaExits[index] != NULL)
|
||||||
|
{
|
||||||
|
if(strncmp(player->currentArea->areaExits[index]->pathName, requestedPath, 32) == 0)
|
||||||
|
{
|
||||||
|
printf("%s: %s\n", player->playerName, player->currentArea->areaExits[index]->pathName);
|
||||||
|
player->currentArea = player->currentArea->areaExits[index]->areaToJoin;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
@ -74,6 +74,9 @@ int evaluateNextCommand(gameLogicParameters * parameters, commandQueue * queue);
|
||||||
// -=[ Gameplay Primitives ]=-:
|
// -=[ Gameplay Primitives ]=-:
|
||||||
// ============================
|
// ============================
|
||||||
|
|
||||||
|
// Player movement:
|
||||||
|
int movePlayerToArea(playerInfo * player, char * requestedPath);
|
||||||
|
|
||||||
typedef enum outcome
|
typedef enum outcome
|
||||||
{
|
{
|
||||||
CRITICAL_FAILURE,
|
CRITICAL_FAILURE,
|
||||||
|
|
|
@ -24,6 +24,7 @@ int messageSend(gnutls_session_t receivingSession, userMessage * messageToSend)
|
||||||
returnValue = gnutls_record_send(receivingSession, messageToSend->messageContent,
|
returnValue = gnutls_record_send(receivingSession, messageToSend->messageContent,
|
||||||
sizeof(((userMessage*)0)->messageContent));
|
sizeof(((userMessage*)0)->messageContent));
|
||||||
} while (returnValue == GNUTLS_E_AGAIN || returnValue == GNUTLS_E_INTERRUPTED);
|
} while (returnValue == GNUTLS_E_AGAIN || returnValue == GNUTLS_E_INTERRUPTED);
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ int messageReceive(gnutls_session_t receiveFromSession, userMessage * receiveToM
|
||||||
returnValue = gnutls_record_recv(receiveFromSession, receiveToMessage->messageContent,
|
returnValue = gnutls_record_recv(receiveFromSession, receiveToMessage->messageContent,
|
||||||
sizeof(((userMessage*)0)->messageContent));
|
sizeof(((userMessage*)0)->messageContent));
|
||||||
} while (returnValue == GNUTLS_E_AGAIN || returnValue == GNUTLS_E_INTERRUPTED);
|
} while (returnValue == GNUTLS_E_AGAIN || returnValue == GNUTLS_E_INTERRUPTED);
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,10 +63,6 @@ int queueOutputMessage(outputMessageQueue * queue, userMessage messageToQueue)
|
||||||
|
|
||||||
// Allocate the internal userMessage to store the message:
|
// Allocate the internal userMessage to store the message:
|
||||||
newOutputMessage->content = malloc(sizeof(userMessage));
|
newOutputMessage->content = malloc(sizeof(userMessage));
|
||||||
|
|
||||||
// Allocate the internal strings to store the message:
|
|
||||||
//outputMessage->content->senderName = malloc(sizeof(char)*32);
|
|
||||||
//outputMessage->content->messageContent = malloc(sizeof(char)*MAX);
|
|
||||||
|
|
||||||
// Copy the userMessage to the internal userMessage:
|
// Copy the userMessage to the internal userMessage:
|
||||||
strncpy(newOutputMessage->content->senderName, messageToQueue.senderName, 32);
|
strncpy(newOutputMessage->content->senderName, messageToQueue.senderName, 32);
|
||||||
|
@ -134,8 +132,7 @@ int queueTargetedOutputMessage(outputMessageQueue * queue,
|
||||||
// Copy the userMessage to the internal userMessage:
|
// Copy the userMessage to the internal userMessage:
|
||||||
strncpy(newOutputMessage->content->senderName, messageToQueue->senderName, 32);
|
strncpy(newOutputMessage->content->senderName, messageToQueue->senderName, 32);
|
||||||
strncpy(newOutputMessage->content->messageContent, messageToQueue->messageContent, MAX);
|
strncpy(newOutputMessage->content->messageContent, messageToQueue->messageContent, MAX);
|
||||||
|
|
||||||
|
|
||||||
// Wait for the queue to unlock:
|
// Wait for the queue to unlock:
|
||||||
while (queue->lock);
|
while (queue->lock);
|
||||||
|
|
||||||
|
|
|
@ -8,103 +8,6 @@
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "playerdata.h"
|
#include "playerdata.h"
|
||||||
|
|
||||||
// Move a player to a different area given a path in the area:
|
|
||||||
int movePlayerToArea(playerInfo * player, char * requestedPath)
|
|
||||||
{
|
|
||||||
// Check if a number was given first:
|
|
||||||
int selected = atoi(requestedPath);
|
|
||||||
if(selected != 0)
|
|
||||||
{
|
|
||||||
if(player->currentArea->areaExits[selected -1] != NULL && player->currentArea->areaExits[selected -1]->areaToJoin != NULL)
|
|
||||||
{
|
|
||||||
player->currentArea = player->currentArea->areaExits[selected - 1]->areaToJoin;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise search for the description:
|
|
||||||
for (int index = 0; index < 16; index++)
|
|
||||||
{
|
|
||||||
if(player->currentArea->areaExits[index] != NULL)
|
|
||||||
{
|
|
||||||
if(strncmp(player->currentArea->areaExits[index]->pathName, requestedPath, 32) == 0)
|
|
||||||
{
|
|
||||||
printf("%s: %s\n", player->playerName, player->currentArea->areaExits[index]->pathName);
|
|
||||||
player->currentArea = player->currentArea->areaExits[index]->areaToJoin;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create an area given a name and description:
|
|
||||||
playerArea * createArea(char * nameString, char * descriptionString)
|
|
||||||
{
|
|
||||||
// Allocate and zero memory for the new area:
|
|
||||||
playerArea * createdArea = calloc(1, sizeof(playerArea));
|
|
||||||
|
|
||||||
// Copy the strings into the newly created area:
|
|
||||||
strncpy(createdArea->areaName, nameString, 32 - 1);
|
|
||||||
strncpy(createdArea->areaDescription, descriptionString, MAX - 35);
|
|
||||||
|
|
||||||
// Properly null-terminate the strings:
|
|
||||||
createdArea->areaName[31] = '\0';
|
|
||||||
createdArea->areaDescription[MAX] = '\0';
|
|
||||||
|
|
||||||
// Ensure that all the paths are set to NULL:
|
|
||||||
for(int index = 0; index < 16; index++)
|
|
||||||
{
|
|
||||||
createdArea->areaExits[index] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the pointer:
|
|
||||||
return createdArea;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a path between two areas given two areas and two strings:
|
|
||||||
int createPath(playerArea * fromArea, playerArea * toArea, char * fromDescription, char * toDescription)
|
|
||||||
{
|
|
||||||
int fromAreaSlot, toAreaSlot;
|
|
||||||
for(fromAreaSlot = 0; fromAreaSlot < 16; fromAreaSlot++)
|
|
||||||
{
|
|
||||||
if(fromArea->areaExits[fromAreaSlot] == NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if((fromArea->areaExits[fromAreaSlot] != NULL) && (fromAreaSlot == 15))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(toAreaSlot = 0; toAreaSlot < 32; toAreaSlot++)
|
|
||||||
{
|
|
||||||
if(toArea->areaExits[toAreaSlot] == 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if((toArea->areaExits[toAreaSlot] != 0) && (toAreaSlot == 31))
|
|
||||||
{
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
playerPath * fromPath = malloc(sizeof(playerPath));
|
|
||||||
playerPath * toPath = malloc(sizeof(playerPath));
|
|
||||||
fromArea->areaExits[fromAreaSlot] = fromPath;
|
|
||||||
toArea->areaExits[toAreaSlot] = toPath;
|
|
||||||
strncpy(fromPath->pathName, fromDescription, 32 - 1);
|
|
||||||
fromPath->pathName[31] = '\0';
|
|
||||||
strncpy(toPath->pathName, toDescription, 32 - 1);
|
|
||||||
toPath->pathName[31] = '\0';
|
|
||||||
fromArea->areaExits[fromAreaSlot]->areaToJoin = toArea;
|
|
||||||
toArea->areaExits[toAreaSlot]->areaToJoin = fromArea;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new skill and add it to the global skill list:
|
// Create a new skill and add it to the global skill list:
|
||||||
int createSkill(skillList * globalSkillList, char * skillName, int skillNameLength, bool trainedSkill)
|
int createSkill(skillList * globalSkillList, char * skillName, int skillNameLength, bool trainedSkill)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,24 +4,9 @@
|
||||||
#define PLAYERDATA_H
|
#define PLAYERDATA_H
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "areadata.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
|
||||||
typedef struct playerPath playerPath;
|
|
||||||
typedef struct playerArea playerArea;
|
|
||||||
|
|
||||||
struct playerPath
|
|
||||||
{
|
|
||||||
char pathName[32];
|
|
||||||
playerArea * areaToJoin;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct playerArea
|
|
||||||
{
|
|
||||||
char areaName[32];
|
|
||||||
char areaDescription[MAX - 35];
|
|
||||||
playerPath * areaExits[16];
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct statBlock
|
typedef struct statBlock
|
||||||
{
|
{
|
||||||
// Levelling:
|
// Levelling:
|
||||||
|
@ -83,15 +68,6 @@ typedef enum coreStat
|
||||||
INVALID
|
INVALID
|
||||||
} coreStat;
|
} coreStat;
|
||||||
|
|
||||||
// Move a player to a different area given a path in the area:
|
|
||||||
int movePlayerToArea(playerInfo * player, char * requestedPath);
|
|
||||||
|
|
||||||
// Create an area given a name and description:
|
|
||||||
playerArea * createArea(char * nameString, char * descriptionString);
|
|
||||||
|
|
||||||
// Create a path between two areas given two areas and two strings:
|
|
||||||
int createPath(playerArea * fromArea, playerArea * toArea, char * fromDescription, char * toDescription);
|
|
||||||
|
|
||||||
// Create a new skill and add it to the global skill list:
|
// Create a new skill and add it to the global skill list:
|
||||||
int createSkill(skillList * globalSkillList, char * skillName, int skillNameLength, bool trainedSkill);
|
int createSkill(skillList * globalSkillList, char * skillName, int skillNameLength, bool trainedSkill);
|
||||||
|
|
||||||
|
@ -111,4 +87,5 @@ coreStat getCoreStatFromString(char * string, int stringLength);
|
||||||
|
|
||||||
// Deallocate a player:
|
// Deallocate a player:
|
||||||
int deallocatePlayer(playerInfo * playerToDeallocate);
|
int deallocatePlayer(playerInfo * playerToDeallocate);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue