Merged fighterDefs.c in to fighters.c.
This commit is contained in:
parent
928b00749d
commit
87445c41ae
2
makefile
2
makefile
|
@ -22,7 +22,7 @@ OBJS += battle.o bullets.o
|
||||||
OBJS += challenges.o cJSON.o
|
OBJS += challenges.o cJSON.o
|
||||||
OBJS += draw.o
|
OBJS += draw.o
|
||||||
OBJS += effects.o entities.o extractionPoint.o
|
OBJS += effects.o entities.o extractionPoint.o
|
||||||
OBJS += fighters.o fighterDefs.o
|
OBJS += fighters.o
|
||||||
OBJS += galacticMap.o game.o grid.o
|
OBJS += galacticMap.o game.o grid.o
|
||||||
OBJS += hud.o
|
OBJS += hud.o
|
||||||
OBJS += init.o io.o items.o
|
OBJS += init.o io.o items.o
|
||||||
|
|
|
@ -1,155 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2015 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 "fighterDefs.h"
|
|
||||||
|
|
||||||
static void loadFighterDef(char *filename);
|
|
||||||
|
|
||||||
static Entity defHead, *defTail;
|
|
||||||
|
|
||||||
Entity *getFighterDef(char *name)
|
|
||||||
{
|
|
||||||
Entity *f;
|
|
||||||
|
|
||||||
for (f = defHead.next ; f != NULL ; f = f->next)
|
|
||||||
{
|
|
||||||
if (strcmp(f->name, name) == 0)
|
|
||||||
{
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Error: no such fighter '%s'\n", name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadFighterDefs(void)
|
|
||||||
{
|
|
||||||
cJSON *root, *node;
|
|
||||||
char *text;
|
|
||||||
|
|
||||||
text = readFile("data/fighters/list.json");
|
|
||||||
root = cJSON_Parse(text);
|
|
||||||
|
|
||||||
memset(&defHead, 0, sizeof(Entity));
|
|
||||||
defTail = &defHead;
|
|
||||||
|
|
||||||
for (node = root->child ; node != NULL ; node = node->next)
|
|
||||||
{
|
|
||||||
loadFighterDef(node->valuestring);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON_Delete(root);
|
|
||||||
free(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void loadFighterDef(char *filename)
|
|
||||||
{
|
|
||||||
cJSON *root, *node;
|
|
||||||
char *text;
|
|
||||||
Entity *f;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
|
||||||
|
|
||||||
text = readFile(filename);
|
|
||||||
|
|
||||||
f = malloc(sizeof(Entity));
|
|
||||||
memset(f, 0, sizeof(Entity));
|
|
||||||
defTail->next = f;
|
|
||||||
defTail = f;
|
|
||||||
|
|
||||||
f->type = ET_FIGHTER;
|
|
||||||
f->active = 1;
|
|
||||||
|
|
||||||
root = cJSON_Parse(text);
|
|
||||||
|
|
||||||
STRNCPY(f->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
|
|
||||||
STRNCPY(f->defName, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
|
|
||||||
f->health = f->maxHealth = cJSON_GetObjectItem(root, "health")->valueint;
|
|
||||||
f->shield = f->maxShield = cJSON_GetObjectItem(root, "shield")->valueint;
|
|
||||||
f->speed = cJSON_GetObjectItem(root, "speed")->valuedouble;
|
|
||||||
f->reloadTime = cJSON_GetObjectItem(root, "reloadTime")->valueint;
|
|
||||||
f->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
|
|
||||||
f->texture = getTexture(cJSON_GetObjectItem(root, "textureName")->valuestring);
|
|
||||||
|
|
||||||
SDL_QueryTexture(f->texture, NULL, NULL, &f->w, &f->h);
|
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(root, "guns"))
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
for (node = cJSON_GetObjectItem(root, "guns")->child ; node != NULL ; node = node->next)
|
|
||||||
{
|
|
||||||
f->guns[i].type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
|
||||||
f->guns[i].x = cJSON_GetObjectItem(node, "x")->valueint;
|
|
||||||
f->guns[i].y = cJSON_GetObjectItem(node, "y")->valueint;
|
|
||||||
|
|
||||||
i++;
|
|
||||||
|
|
||||||
if (i >= MAX_FIGHTER_GUNS)
|
|
||||||
{
|
|
||||||
printf("ERROR: cannot assign more than %d guns to a fighter\n", MAX_FIGHTER_GUNS);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(root, "combinedGuns"))
|
|
||||||
{
|
|
||||||
f->combinedGuns = cJSON_GetObjectItem(root, "combinedGuns")->valueint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f->selectedGunType = f->guns[0].type;
|
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(root, "missiles"))
|
|
||||||
{
|
|
||||||
node = cJSON_GetObjectItem(root, "missiles");
|
|
||||||
|
|
||||||
f->missiles.type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
|
||||||
f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cJSON_GetObjectItem(root, "flags"))
|
|
||||||
{
|
|
||||||
f->flags = flagsToLong(cJSON_GetObjectItem(root, "flags")->valuestring);
|
|
||||||
}
|
|
||||||
|
|
||||||
f->separationRadius = MAX(f->w, f->h);
|
|
||||||
f->separationRadius *= 2;
|
|
||||||
|
|
||||||
/* all craft default to 100 system power */
|
|
||||||
f->systemPower = 100;
|
|
||||||
|
|
||||||
cJSON_Delete(root);
|
|
||||||
free(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyFighterDefs(void)
|
|
||||||
{
|
|
||||||
Entity *f;
|
|
||||||
|
|
||||||
while (defHead.next)
|
|
||||||
{
|
|
||||||
f = defHead.next;
|
|
||||||
defHead.next = f->next;
|
|
||||||
free(f);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2015 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 "SDL2/SDL.h"
|
|
||||||
|
|
||||||
#include "../defs.h"
|
|
||||||
#include "../structs.h"
|
|
||||||
#include "../json/cJSON.h"
|
|
||||||
|
|
||||||
extern char *readFile(char *filename);
|
|
||||||
extern SDL_Texture *getTexture(char *filename);
|
|
||||||
extern long lookup(char *name);
|
|
||||||
extern long flagsToLong(char *flags);
|
|
||||||
|
|
|
@ -27,6 +27,9 @@ static void spinDie(void);
|
||||||
static void straightDie(void);
|
static void straightDie(void);
|
||||||
static void randomizeDart(Entity *dart);
|
static void randomizeDart(Entity *dart);
|
||||||
static void randomizeDartGuns(Entity *dart);
|
static void randomizeDartGuns(Entity *dart);
|
||||||
|
static void loadFighterDef(char *filename);
|
||||||
|
|
||||||
|
static Entity defHead, *defTail;
|
||||||
|
|
||||||
Entity *spawnFighter(char *name, int x, int y, int side)
|
Entity *spawnFighter(char *name, int x, int y, int side)
|
||||||
{
|
{
|
||||||
|
@ -492,3 +495,133 @@ void fleeAllEnemies(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Entity *getFighterDef(char *name)
|
||||||
|
{
|
||||||
|
Entity *f;
|
||||||
|
|
||||||
|
for (f = defHead.next ; f != NULL ; f = f->next)
|
||||||
|
{
|
||||||
|
if (strcmp(f->name, name) == 0)
|
||||||
|
{
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Error: no such fighter '%s'\n", name);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadFighterDefs(void)
|
||||||
|
{
|
||||||
|
cJSON *root, *node;
|
||||||
|
char *text;
|
||||||
|
|
||||||
|
text = readFile("data/fighters/list.json");
|
||||||
|
root = cJSON_Parse(text);
|
||||||
|
|
||||||
|
memset(&defHead, 0, sizeof(Entity));
|
||||||
|
defTail = &defHead;
|
||||||
|
|
||||||
|
for (node = root->child ; node != NULL ; node = node->next)
|
||||||
|
{
|
||||||
|
loadFighterDef(node->valuestring);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(root);
|
||||||
|
free(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void loadFighterDef(char *filename)
|
||||||
|
{
|
||||||
|
cJSON *root, *node;
|
||||||
|
char *text;
|
||||||
|
Entity *f;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
||||||
|
|
||||||
|
text = readFile(filename);
|
||||||
|
|
||||||
|
f = malloc(sizeof(Entity));
|
||||||
|
memset(f, 0, sizeof(Entity));
|
||||||
|
defTail->next = f;
|
||||||
|
defTail = f;
|
||||||
|
|
||||||
|
f->type = ET_FIGHTER;
|
||||||
|
f->active = 1;
|
||||||
|
|
||||||
|
root = cJSON_Parse(text);
|
||||||
|
|
||||||
|
STRNCPY(f->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
|
||||||
|
STRNCPY(f->defName, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
|
||||||
|
f->health = f->maxHealth = cJSON_GetObjectItem(root, "health")->valueint;
|
||||||
|
f->shield = f->maxShield = cJSON_GetObjectItem(root, "shield")->valueint;
|
||||||
|
f->speed = cJSON_GetObjectItem(root, "speed")->valuedouble;
|
||||||
|
f->reloadTime = cJSON_GetObjectItem(root, "reloadTime")->valueint;
|
||||||
|
f->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
|
||||||
|
f->texture = getTexture(cJSON_GetObjectItem(root, "textureName")->valuestring);
|
||||||
|
|
||||||
|
SDL_QueryTexture(f->texture, NULL, NULL, &f->w, &f->h);
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(root, "guns"))
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
for (node = cJSON_GetObjectItem(root, "guns")->child ; node != NULL ; node = node->next)
|
||||||
|
{
|
||||||
|
f->guns[i].type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
||||||
|
f->guns[i].x = cJSON_GetObjectItem(node, "x")->valueint;
|
||||||
|
f->guns[i].y = cJSON_GetObjectItem(node, "y")->valueint;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (i >= MAX_FIGHTER_GUNS)
|
||||||
|
{
|
||||||
|
printf("ERROR: cannot assign more than %d guns to a fighter\n", MAX_FIGHTER_GUNS);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(root, "combinedGuns"))
|
||||||
|
{
|
||||||
|
f->combinedGuns = cJSON_GetObjectItem(root, "combinedGuns")->valueint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f->selectedGunType = f->guns[0].type;
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(root, "missiles"))
|
||||||
|
{
|
||||||
|
node = cJSON_GetObjectItem(root, "missiles");
|
||||||
|
|
||||||
|
f->missiles.type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
|
||||||
|
f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cJSON_GetObjectItem(root, "flags"))
|
||||||
|
{
|
||||||
|
f->flags = flagsToLong(cJSON_GetObjectItem(root, "flags")->valuestring);
|
||||||
|
}
|
||||||
|
|
||||||
|
f->separationRadius = MAX(f->w, f->h);
|
||||||
|
f->separationRadius *= 2;
|
||||||
|
|
||||||
|
/* all craft default to 100 system power */
|
||||||
|
f->systemPower = 100;
|
||||||
|
|
||||||
|
cJSON_Delete(root);
|
||||||
|
free(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyFighterDefs(void)
|
||||||
|
{
|
||||||
|
Entity *f;
|
||||||
|
|
||||||
|
while (defHead.next)
|
||||||
|
{
|
||||||
|
f = defHead.next;
|
||||||
|
defHead.next = f->next;
|
||||||
|
free(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
#include "../structs.h"
|
#include "../structs.h"
|
||||||
|
#include "../json/cJSON.h"
|
||||||
|
|
||||||
extern SDL_Texture *getTexture(char *filename);
|
extern SDL_Texture *getTexture(char *filename);
|
||||||
extern void doAI(void);
|
extern void doAI(void);
|
||||||
|
@ -42,6 +43,9 @@ extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore);
|
||||||
extern Entity *spawnEntity(void);
|
extern Entity *spawnEntity(void);
|
||||||
extern void adjustObjectiveTargetValue(char *name, int type, int amount);
|
extern void adjustObjectiveTargetValue(char *name, int type, int amount);
|
||||||
extern void attachRope(void);
|
extern void attachRope(void);
|
||||||
|
extern char *readFile(char *filename);
|
||||||
|
extern long lookup(char *name);
|
||||||
|
extern long flagsToLong(char *flags);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
|
|
Loading…
Reference in New Issue