Merged config branch.

This commit is contained in:
Steve 2016-03-03 18:03:07 +00:00
parent b136a6bb6c
commit b6012a2e21
23 changed files with 667 additions and 250 deletions

View File

@ -10,7 +10,7 @@ DEPS += defs.h structs.h
OBJS += ai.o
OBJS += battle.o bullets.o
OBJS += capitalShips.o challengeHome.o challenges.o cJSON.o
OBJS += capitalShips.o challengeHome.o challenges.o cJSON.o controls.o
OBJS += debris.o dev.o draw.o
OBJS += effects.o entities.o extractionPoint.o
OBJS += fighters.o
@ -24,7 +24,7 @@ OBJS += player.o
OBJS += quadtree.o
OBJS += radar.o resources.o rope.o
OBJS += save.o script.o sound.o starfield.o starSystems.o stats.o
OBJS += testMission.o textures.o text.o title.o transition.o
OBJS += testMission.o textures.o text.o title.o transition.o trophies.o
OBJS += util.o
OBJS += waypoints.o widgets.o

View File

@ -1,8 +1,29 @@
{
"winWidth" : 1280,
"winHeight" : 720,
"vSync" : 1,
"fullscreen" : 0,
"musicVolume" : 8,
"soundVolume" : 10
"soundVolume" : 10,
"controls" : {
"keys": {
"CONTROL_BOOST" : 26,
"CONTROL_ECM" : 7,
"CONTROL_BRAKE" : 22,
"CONTROL_TARGET" : 4,
"CONTROL_MISSILE" : 44,
"CONTROL_GUNS" : 29,
"CONTROL_RADAR" : 27,
"CONTROL_NEXT_FIGHTER": 7,
"CONTROL_PREV_FIGHTER": 4
},
"mouse" : {
"CONTROL_BOOST" : -1,
"CONTROL_ECM" : -1,
"CONTROL_BRAKE" : -1,
"CONTROL_TARGET" : -1,
"CONTROL_MISSILE" : -1,
"CONTROL_GUNS" : -1,
"CONTROL_RADAR" : -1
}
}
}

View File

@ -0,0 +1,68 @@
[
{
"id" : "READY_DUTY",
"title" : "Ready for duty",
"description" : "Complete all the training missions at Sol",
"value" : "TROPHY_BRONZE"
},
{
"id" : "EPIC",
"title" : "Truly epic",
"description" : "Survive an epic battle",
"value" : "TROPHY_BRONZE"
},
{
"id" : "BIGGER_FALL",
"title" : "The bigger they are",
"description" : "Destroy an enemy capital ship",
"value" : "TROPHY_SILVER"
},
{
"id" : "CAMPAIGN_COYOTE",
"title" : "Coyote Ugly",
"description" : "Complete all missions at Coyote",
"value" : "TROPHY_BRONZE"
},
{
"id" : "PANDORAN_FIRST",
"title" : "Plenty more where that came from",
"description" : "Engage the Pandorans in battle",
"value" : "TROPHY_BRONZE"
},
{
"id" : "ATAF_FIRST",
"title" : "Man, I gotta get me one of these!",
"description" : "Pilot an ATAF during the campaign",
"value" : "TROPHY_BRONZE"
},
{
"id" : "CHALLENGE_25",
"title" : "",
"description" : "Complete 25% of all challenges",
"value" : "TROPHY_BRONZE"
},
{
"id" : "CHALLENGE_50",
"title" : "",
"description" : "Complete 50% of all challenges",
"value" : "TROPHY_SILVER"
},
{
"id" : "CHALLENGE_100",
"title" : "",
"description" : "Complete 100% of all challenges",
"value" : "TROPHY_GOLD"
},
{
"id" : "FIRE_10000",
"title" : "Your name's on one of these!",
"description" : "Fire 10,000 shots",
"value" : "TROPHY_SILVER"
},
{
"id" : "MISSILE_1000",
"title" : "Dodge this!",
"description" : "Launch 1,000 missiles",
"value" : "TROPHY_SILVER"
}
]

View File

@ -43,6 +43,16 @@
"w" : 400,
"h": 34
},
{
"name" : "controls",
"group" : "options",
"type" : "WT_BUTTON",
"text" : "Controls ...",
"x" : -1,
"y" : 475,
"w" : 400,
"h": 34
},
{
"name" : "ok",
"group" : "options",

View File

@ -9,7 +9,7 @@ OBJS += unixInit.o
include common.mk
CXXFLAGS += `sdl2-config --cflags` -DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDATA_DIR=\"$(DATA_DIR)\" -DLOCALE_DIR=\"$(LOCALE_DIR)\"
CXXFLAGS += `sdl2-config --cflags` -DVERSION=$(VERSION) -DREVISION=$(REVISION) -DDATA_DIR=\"$(DATA_DIR)\" -DLOCALE_DIR=\"$(LOCALE_DIR)\" -DFIXED_RESOLUTION=1
CXXFLAGS += -ansi -Wstrict-prototypes
CXXFLAGS += -g -lefence -flto -flto-odr-type-merging

View File

@ -173,7 +173,7 @@ static void handleKeyboard(void)
{
if (battle.status == MS_IN_PROGRESS)
{
if (app.keyboard[SDL_SCANCODE_W])
if (isKeyControl(CONTROL_BOOST))
{
if (battle.boostTimer == BOOST_RECHARGE_TIME)
{
@ -186,17 +186,17 @@ static void handleKeyboard(void)
playSound(SND_GUI_DENIED);
}
app.keyboard[SDL_SCANCODE_W] = 0;
clearControl(CONTROL_BOOST);
}
if (app.keyboard[SDL_SCANCODE_A])
if (isKeyControl(CONTROL_TARGET))
{
selectTarget();
app.keyboard[SDL_SCANCODE_A] = 0;
clearControl(CONTROL_TARGET);
}
if (app.keyboard[SDL_SCANCODE_D])
if (isKeyControl(CONTROL_ECM))
{
if (battle.ecmTimer == ECM_RECHARGE_TIME)
{
@ -209,33 +209,33 @@ static void handleKeyboard(void)
playSound(SND_GUI_DENIED);
}
app.keyboard[SDL_SCANCODE_D] = 0;
clearControl(CONTROL_ECM);
}
if (app.keyboard[SDL_SCANCODE_S])
if (isKeyControl(CONTROL_BRAKE))
{
applyFighterBrakes();
}
if (app.keyboard[SDL_SCANCODE_Z])
if (isKeyControl(CONTROL_GUNS))
{
switchGuns();
app.keyboard[SDL_SCANCODE_Z] = 0;
clearControl(CONTROL_GUNS);
}
if (app.keyboard[SDL_SCANCODE_X])
if (isKeyControl(CONTROL_RADAR))
{
cycleRadarZoom();
app.keyboard[SDL_SCANCODE_X] = 0;
clearControl(CONTROL_RADAR);
}
if (app.keyboard[SDL_SCANCODE_SPACE])
if (isKeyControl(CONTROL_MISSILE))
{
preFireMissile();
app.keyboard[SDL_SCANCODE_SPACE] = 0;
clearControl(CONTROL_MISSILE);
}
}
else

View File

@ -37,6 +37,9 @@ extern float getAngle(int x1, int y1, int x2, int y2);
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
extern char *getTranslatedString(char *string);
extern void addECMEffect(Entity *ent);
extern int isKeyControl(int type);
extern int isMouseControl(int type);
extern void clearControl(int type);
extern App app;
extern Battle battle;

View File

@ -26,6 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define DATA_DIR ""
#endif
#ifndef FIXED_RESOLUTION
#define FIXED_RESOLUTION 0
#endif
#define _(string) getTranslatedString(string)
#define PI 3.14159265358979323846
@ -39,7 +43,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define SCREEN_HEIGHT 720
#define MAX_KEYBOARD_KEYS 350
#define MAX_MOUSE_BUTTONS 8
#define MAX_MOUSE_BUTTONS 5
#define FPS 60
#define LOGIC_RATE (1000 / FPS)
@ -113,6 +117,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define BOOST_FINISHED_TIME (FPS * 0.75)
#define ECM_RECHARGE_TIME (FPS * 7)
enum
{
CONTROL_FIRE,
CONTROL_ACCELERATE,
CONTROL_BOOST,
CONTROL_ECM,
CONTROL_BRAKE,
CONTROL_TARGET,
CONTROL_MISSILE,
CONTROL_GUNS,
CONTROL_RADAR,
CONTROL_NEXT_FIGHTER,
CONTROL_PREV_FIGHTER,
CONTROL_MAX
};
enum
{
MD_NONE,

View File

@ -19,11 +19,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
#include "../json/cJSON.h"
#include "time.h"
#include "../json/cJSON.h"
extern long lookup(char *name);
extern char *readFile(char *filename);
extern SDL_Texture *getTexture(char *filename);

31
src/game/controls.c Normal file
View File

@ -0,0 +1,31 @@
/*
Copyright (C) 2015-2016 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 "controls.h"
int isKeyControl(int type)
{
return app.keyboard[app.keyControls[type]];
}
void clearControl(int type)
{
app.keyboard[app.keyControls[type]] = 0;
}

24
src/game/controls.h Normal file
View File

@ -0,0 +1,24 @@
/*
Copyright (C) 2015-2016 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 "../common.h"
extern App app;
extern Game game;

115
src/game/trophies.c Normal file
View File

@ -0,0 +1,115 @@
/*
Copyright (C) 2015-2016 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 "trophies.h"
static int recentlyAwarded;
static void loadTrophyData(char *filename);
void initTrophies(void)
{
recentlyAwarded = 0;
loadTrophyData("data/trophies/trophies.json");
}
void awardTrophy(char *id)
{
Trophy *t;
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{
if (!t->awarded && strcmp(t->id, id) == 0)
{
t->awarded = 1;
t->awardDate = time(NULL);
t->notify = 1;
recentlyAwarded++;
}
}
}
void drawTrophyAlerts(void)
{
Trophy *t;
if (recentlyAwarded)
{
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{
if (t->notify)
{
/* handle notification */
return;
}
}
}
}
void drawTrophies(void)
{
}
Trophy *getTrophy(char *id)
{
Trophy *t;
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{
if (strcmp(t->id, id) == 0)
{
return t;
}
}
return NULL;
}
static void loadTrophyData(char *filename)
{
cJSON *root, *node;
char *text;
Trophy *t, *tail;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
text = readFile(getFileLocation(filename));
root = cJSON_Parse(text);
tail = &game.trophyHead;
for (node = root->child ; node != NULL ; node = node->next)
{
t = malloc(sizeof(Trophy));
memset(t, 0, sizeof(Trophy));
STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH);
STRNCPY(t->title, cJSON_GetObjectItem(node, "title")->valuestring, MAX_DESCRIPTION_LENGTH);
STRNCPY(t->description, cJSON_GetObjectItem(node, "description")->valuestring, MAX_DESCRIPTION_LENGTH);
t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring);
tail->next = t;
tail = t;
}
cJSON_Delete(root);
free(text);
}

30
src/game/trophies.h Normal file
View File

@ -0,0 +1,30 @@
/*
Copyright (C) 2015-2016 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 "../common.h"
#include "../json/cJSON.h"
#include "time.h"
extern char *getFileLocation(char *filename);
extern long lookup(char *name);
extern char *readFile(char *filename);
extern Game game;

View File

@ -39,6 +39,8 @@ int main(int argc, char *argv[])
init18N(argc, argv);
initLookups();
initSDL();
initGameSystem();

View File

@ -44,6 +44,8 @@ extern void loadGame(void);
extern int fileExists(char *filename);
extern char *getSaveFilePath(char *filename);
extern void init18N(int argc, char *argv[]);
extern void initLookups(void);
extern void initGame(void);
App app;
Colors colors;

View File

@ -38,6 +38,7 @@ typedef struct GridCell GridCell;
typedef struct ScriptRunner ScriptRunner;
typedef struct Location Location;
typedef struct Bucket Bucket;
typedef struct Trophy Trophy;
typedef struct {
int debug;
@ -261,6 +262,7 @@ struct Mission {
char pilot[MAX_NAME_LENGTH];
char squadron[MAX_NAME_LENGTH];
char craft[MAX_NAME_LENGTH];
char trophyId[MAX_NAME_LENGTH];
int available;
int completed;
int completedChallenges;
@ -336,6 +338,17 @@ struct ScriptRunner {
ScriptRunner *next;
};
struct Trophy {
char id[MAX_NAME_LENGTH];
char title[MAX_DESCRIPTION_LENGTH];
char description[MAX_DESCRIPTION_LENGTH];
int value;
int awarded;
unsigned long awardDate;
int notify;
Trophy *next;
};
typedef struct {
StarSystem starSystemHead;
Mission challengeMissionHead;
@ -345,6 +358,7 @@ typedef struct {
int availableMissions;
int totalMissions;
unsigned int stats[STAT_MAX];
Trophy trophyHead;
} Game;
struct Widget {
@ -408,6 +422,8 @@ typedef struct {
SDL_Window *window;
Delegate delegate;
ModalDialog modalDialog;
int keyControls[CONTROL_MAX];
int mouseControls[CONTROL_MAX];
} App;
typedef struct {

View File

@ -120,7 +120,6 @@ void initGameSystem(void)
void (*initFuncs[]) (void) = {
initFonts,
initInput,
initLookups,
initResources,
initSounds,
initWidgets,
@ -202,7 +201,8 @@ static void initColor(SDL_Color *c, int r, int g, int b)
static void loadConfig(void)
{
cJSON *root;
int i;
cJSON *root, *controlsJSON, *node;
char *text, *configFilename;
configFilename = getSaveFilePath("config.json");
@ -224,6 +224,30 @@ static void loadConfig(void)
app.musicVolume = cJSON_GetObjectItem(root, "musicVolume")->valueint;
app.soundVolume = cJSON_GetObjectItem(root, "soundVolume")->valueint;
controlsJSON = cJSON_GetObjectItem(root, "controls");
if (controlsJSON)
{
node = cJSON_GetObjectItem(controlsJSON, "keys")->child;
while (node)
{
i = lookup(node->string);
app.keyControls[i] = node->valueint;
node = node->next;
}
node = cJSON_GetObjectItem(controlsJSON, "mouse")->child;
while (node)
{
i = lookup(node->string);
app.mouseControls[i] = node->valueint;
node = node->next;
}
}
cJSON_Delete(root);
free(text);
@ -233,8 +257,9 @@ static void loadConfig(void)
void saveConfig(void)
{
int i;
char *out, *configFilename;
cJSON *root;
cJSON *root, *controlsJSON, *keysJSON, *mouseJSON;
configFilename = getSaveFilePath("config.json");
@ -247,11 +272,29 @@ void saveConfig(void)
cJSON_AddNumberToObject(root, "musicVolume", app.musicVolume);
cJSON_AddNumberToObject(root, "soundVolume", app.soundVolume);
keysJSON = cJSON_CreateObject();
for (i = 0 ; i < CONTROL_MAX ; i++)
{
cJSON_AddNumberToObject(keysJSON, getLookupName("CONTROL_", i), app.keyControls[i]);
}
mouseJSON = cJSON_CreateObject();
for (i = 0 ; i < CONTROL_MAX ; i++)
{
cJSON_AddNumberToObject(mouseJSON, getLookupName("CONTROL_", i), app.mouseControls[i]);
}
controlsJSON = cJSON_CreateObject();
cJSON_AddItemToObject(controlsJSON, "keys", keysJSON);
cJSON_AddItemToObject(controlsJSON, "mouse", mouseJSON);
cJSON_AddItemToObject(root, "controls", controlsJSON);
out = cJSON_Print(root);
if (!writeFile(configFilename, out))
{
printf("Failed to save config\n");
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save config");
}
cJSON_Delete(root);

View File

@ -40,7 +40,6 @@ extern void loadCapitalShipDefs(void);
extern void loadItemDefs(void);
extern void initFonts(void);
extern void initBulletDefs(void);
extern void initLookups(void);
extern void initBattle(void);
extern void initGame(void);
extern void initStats(void);
@ -69,6 +68,9 @@ extern void initModalDialog(void);
extern void createSaveFolder(void);
extern char *getFileLocation(char *filename);
extern void setLanguage(char *applicationName, char *languageCode);
extern char *getLookupName(char *prefix, long num);
extern long lookup(char *name);
extern App app;
extern Colors colors;
extern Game game;

View File

@ -33,14 +33,23 @@ void initInput(void)
void doMouseDown(SDL_MouseButtonEvent *event)
{
if (event->button >= 0 && event->button < MAX_MOUSE_BUTTONS)
{
app.mouse.button[event->button] = 1;
}
}
void doMouseUp(SDL_MouseButtonEvent *event)
{
if (event->button >= 0 && event->button < MAX_MOUSE_BUTTONS)
{
app.mouse.button[event->button] = 0;
}
}
/*
* Note: the following assumes that SDL_BUTTON_X1 and SDL_BUTTON_X2 are 4 and 5, respectively. They usually are.
*/
void doMouseWheel(SDL_MouseWheelEvent *event)
{
if (event->y == -1)

View File

@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "load.h"
static void loadStats(cJSON *stats);
static void loadStats(cJSON *statsJSON);
static void loadStarSystems(cJSON *starSystemsJSON);
static void loadMissions(cJSON *missionsCJSON);
static void loadChallenges(cJSON *challengesCJSON);
@ -103,7 +103,7 @@ static void loadChallenges(cJSON *missionsJSON)
}
}
static void loadStats(cJSON *stats)
static void loadStats(cJSON *statsJSON)
{
int i;
char *statName;
@ -112,9 +112,9 @@ static void loadStats(cJSON *stats)
{
statName = getLookupName("STAT_", i);
if (statName && cJSON_GetObjectItem(stats, statName))
if (statName && cJSON_GetObjectItem(statsJSON, statName))
{
game.stats[i] = cJSON_GetObjectItem(stats, statName)->valueint;
game.stats[i] = cJSON_GetObjectItem(statsJSON, statName)->valueint;
}
}
}

View File

@ -30,6 +30,18 @@ void initLookups(void)
memset(&head, 0, sizeof(Lookup));
tail = &head;
addLookup("CONTROL_FIRE", CONTROL_FIRE);
addLookup("CONTROL_ACCELERATE", CONTROL_ACCELERATE);
addLookup("CONTROL_BOOST", CONTROL_BOOST);
addLookup("CONTROL_ECM", CONTROL_ECM);
addLookup("CONTROL_BRAKE", CONTROL_BRAKE);
addLookup("CONTROL_TARGET", CONTROL_TARGET);
addLookup("CONTROL_MISSILE", CONTROL_MISSILE);
addLookup("CONTROL_GUNS", CONTROL_GUNS);
addLookup("CONTROL_RADAR", CONTROL_RADAR);
addLookup("CONTROL_NEXT_FIGHTER", CONTROL_NEXT_FIGHTER);
addLookup("CONTROL_PREV_FIGHTER", CONTROL_PREV_FIGHTER);
addLookup("ET_WAYPOINT", ET_WAYPOINT);
addLookup("ET_EXTRACTION_POINT", ET_EXTRACTION_POINT);
addLookup("ET_CAPITAL_SHIP", ET_CAPITAL_SHIP);

View File

@ -51,6 +51,11 @@ void initOptions(void (*rtn)(void))
setWidgetOption("fullscreen", "options", app.fullscreen ? "On" : "Off");
#if FIXED_RESOLUTION
getWidget("windowSize", "options")->enabled = 0;
getWidget("fullscreen", "options")->enabled = 0;
#endif
returnFromOptions = rtn;
}
@ -81,7 +86,12 @@ void drawOptions(void)
drawWidgets("options");
limitTextWidth(r.w - 100);
#if !FIXED_RESOLUTION
drawText(SCREEN_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, _("Note: you must restart the game for window size and fullscreen options to take effect."));
#else
drawText(SCREEN_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, _("Note: this device does not support changing the screen resolution."));
#endif
limitTextWidth(0);
}