2018-01-21 10:31:38 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2018 Parallel Realities
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "game.h"
|
|
|
|
|
2018-01-28 16:48:20 +01:00
|
|
|
static void loadMetaInfo(void);
|
2018-01-24 08:16:52 +01:00
|
|
|
|
|
|
|
void initGame(void)
|
|
|
|
{
|
|
|
|
memset(&game, 0, sizeof(Game));
|
|
|
|
|
2018-01-28 17:14:17 +01:00
|
|
|
game.missionStatusTail = &game.missionStatusHead;
|
|
|
|
|
2018-01-24 08:16:52 +01:00
|
|
|
game.cells = 5;
|
|
|
|
game.hearts = 10;
|
|
|
|
|
|
|
|
game.timePlayed = 0;
|
2018-01-28 16:48:20 +01:00
|
|
|
|
|
|
|
loadMetaInfo();
|
2018-01-24 08:16:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-26 08:56:12 +01:00
|
|
|
void addRescuedMIA(char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < game.totalMIAs ; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(game.mias[i], "") == 0)
|
|
|
|
{
|
|
|
|
STRNCPY(game.mias[i], name, MAX_NAME_LENGTH);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void addDefeatedTarget(char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0 ; i < game.totalTargets ; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(game.targets[i], "") == 0)
|
|
|
|
{
|
|
|
|
STRNCPY(game.targets[i], name, MAX_NAME_LENGTH);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-26 20:14:18 +01:00
|
|
|
void addKey(char *name)
|
2018-01-24 08:16:52 +01:00
|
|
|
{
|
2018-01-26 20:14:18 +01:00
|
|
|
|
2018-01-24 08:16:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-27 09:53:08 +01:00
|
|
|
int hasItem(char *name)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-27 11:47:53 +01:00
|
|
|
Entity *getItem(char *name)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void removeItem(char *name)
|
2018-01-27 09:53:08 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-28 16:48:20 +01:00
|
|
|
static void loadMetaInfo(void)
|
|
|
|
{
|
|
|
|
cJSON *root;
|
|
|
|
char *text;
|
2018-02-03 17:21:37 +01:00
|
|
|
int i;
|
2018-01-28 16:48:20 +01:00
|
|
|
|
|
|
|
text = readFile("data/meta/meta.json");
|
|
|
|
|
|
|
|
root = cJSON_Parse(text);
|
|
|
|
|
|
|
|
game.totalKeys = cJSON_GetObjectItem(root, "totalKeys")->valueint;
|
|
|
|
game.totalTargets = cJSON_GetObjectItem(root, "totalTargets")->valueint;
|
|
|
|
game.totalMIAs = cJSON_GetObjectItem(root, "totalMIAs")->valueint;
|
|
|
|
game.totalHearts = cJSON_GetObjectItem(root, "totalHearts")->valueint;
|
|
|
|
game.totalCells = cJSON_GetObjectItem(root, "totalCells")->valueint;
|
|
|
|
|
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Meta [keys=%d, targets=%d, mias=%d, hearts=%d, cells=%d]", game.totalKeys, game.totalTargets, game.totalMIAs, game.totalHearts, game.totalCells);
|
|
|
|
|
2018-02-03 17:21:37 +01:00
|
|
|
game.mias = malloc(sizeof(char*) * game.totalMIAs);
|
|
|
|
for (i = 0 ; i < game.totalMIAs ; i++)
|
|
|
|
{
|
|
|
|
game.mias[i] = malloc(MAX_NAME_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
game.targets = malloc(sizeof(char*) * game.totalTargets);
|
|
|
|
for (i = 0 ; i < game.totalTargets ; i++)
|
|
|
|
{
|
|
|
|
game.targets[i] = malloc(MAX_NAME_LENGTH);
|
|
|
|
}
|
|
|
|
|
2018-01-28 16:48:20 +01:00
|
|
|
cJSON_Delete(root);
|
|
|
|
|
|
|
|
free(text);
|
|
|
|
}
|
|
|
|
|
2018-01-21 10:31:38 +01:00
|
|
|
void destroyGame(void)
|
|
|
|
{
|
|
|
|
}
|