From 29d873d28a7208c3e8097a2d798aaa551518dabd Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 4 Apr 2016 11:23:32 +0100 Subject: [PATCH] Allow waypoints to be manually activated. Removed entId from Battle (redundant). --- data/missions/alba/01 - patrol #1.json | 7 +----- data/missions/alba/02 - patrol #2.json | 7 +----- data/missions/alba/03 - patrol #3.json | 7 +----- .../granada/02 - suspect packages #2.json | 7 +----- .../granada/03 - suspect packages #3.json | 7 +----- src/battle/capitalShips.c | 1 - src/battle/entities.c | 3 +-- src/battle/fighters.c | 3 +-- src/battle/player.c | 2 +- src/battle/script.c | 2 +- src/battle/script.h | 2 +- src/battle/waypoints.c | 22 ++++++++++++++----- src/galaxy/mission.c | 7 ++++++ src/galaxy/mission.h | 1 + src/structs.h | 2 +- 15 files changed, 36 insertions(+), 44 deletions(-) diff --git a/data/missions/alba/01 - patrol #1.json b/data/missions/alba/01 - patrol #1.json index 34495c5..e6da433 100644 --- a/data/missions/alba/01 - patrol #1.json +++ b/data/missions/alba/01 - patrol #1.json @@ -6,6 +6,7 @@ "planet" : "gfx/planets/torelli.png", "music" : "music/battle/heroism.ogg", "manualComplete" : 1, + "waypointAutoAdvance" : 1, "objectives" : [ { "description" : "Check all waypoints", @@ -42,12 +43,6 @@ } ], "script" : [ - { - "function" : "TIME 0", - "lines" : [ - "ACTIVATE_NEXT_WAYPOINT" - ] - }, { "function" : "Waypoint #2", "lines" : [ diff --git a/data/missions/alba/02 - patrol #2.json b/data/missions/alba/02 - patrol #2.json index 74a8b56..77e0815 100644 --- a/data/missions/alba/02 - patrol #2.json +++ b/data/missions/alba/02 - patrol #2.json @@ -6,6 +6,7 @@ "planet" : "gfx/planets/torelli.png", "music" : "music/battle/heroism.ogg", "manualComplete" : 1, + "waypointAutoAdvance" : 1, "objectives" : [ { "description" : "Check all Waypoints", @@ -59,12 +60,6 @@ } ], "script" : [ - { - "function" : "TIME 0", - "lines" : [ - "ACTIVATE_NEXT_WAYPOINT" - ] - }, { "function" : "Waypoint #3", "lines" : [ diff --git a/data/missions/alba/03 - patrol #3.json b/data/missions/alba/03 - patrol #3.json index 32e6290..5d0b85f 100644 --- a/data/missions/alba/03 - patrol #3.json +++ b/data/missions/alba/03 - patrol #3.json @@ -9,6 +9,7 @@ "planet" : "gfx/planets/torelli.png", "music" : "", "manualComplete" : 1, + "waypointAutoAdvance" : 1, "objectives" : [ { "description" : "Check all Waypoints", @@ -45,12 +46,6 @@ } ], "script" : [ - { - "function" : "TIME 0", - "lines" : [ - "ACTIVATE_NEXT_WAYPOINT" - ] - }, { "function" : "TIME 3", "lines" : [ diff --git a/data/missions/granada/02 - suspect packages #2.json b/data/missions/granada/02 - suspect packages #2.json index 2f76c94..81cf110 100644 --- a/data/missions/granada/02 - suspect packages #2.json +++ b/data/missions/granada/02 - suspect packages #2.json @@ -6,6 +6,7 @@ "planet" : "gfx/planets/bluePlanet.png", "music" : "music/battle/determination.mp3", "manualComplete" : 1, + "waypointAutoAdvance" : 1, "objectives" : [ { "description" : "Check all wayponts", @@ -126,12 +127,6 @@ } ], "script" : [ - { - "function" : "TIME 0", - "lines" : [ - "ACTIVATE_NEXT_WAYPOINT" - ] - }, { "function" : "Waypoint #2", "lines" : [ diff --git a/data/missions/granada/03 - suspect packages #3.json b/data/missions/granada/03 - suspect packages #3.json index 893d39f..fb978c9 100644 --- a/data/missions/granada/03 - suspect packages #3.json +++ b/data/missions/granada/03 - suspect packages #3.json @@ -6,6 +6,7 @@ "planet" : "gfx/planets/bluePlanet.png", "music" : "music/battle/determination.mp3", "manualComplete" : 1, + "waypointAutoAdvance" : 1, "player" : { "pilot" : "Lt. Cdr. Daniel Carr", "squadron" : "Iron Patriots", @@ -126,12 +127,6 @@ } ], "script" : [ - { - "function" : "TIME 0", - "lines" : [ - "ACTIVATE_NEXT_WAYPOINT" - ] - }, { "function" : "Waypoint #1", "lines" : [ diff --git a/src/battle/capitalShips.c b/src/battle/capitalShips.c index ecdc1d3..6a417f0 100644 --- a/src/battle/capitalShips.c +++ b/src/battle/capitalShips.c @@ -50,7 +50,6 @@ Entity *spawnCapitalShip(char *name, int x, int y, int side) memcpy(e, def, sizeof(Entity)); - e->id = battle.entId; e->next = NULL; e->x = x; diff --git a/src/battle/entities.c b/src/battle/entities.c index 6c23d66..2d44a86 100644 --- a/src/battle/entities.c +++ b/src/battle/entities.c @@ -59,7 +59,6 @@ Entity *spawnEntity(void) { Entity *e = malloc(sizeof(Entity)); memset(e, 0, sizeof(Entity)); - e->id = battle.entId++; e->active = 1; battle.entityTail->next = e; @@ -291,7 +290,7 @@ static void resizeDrawList(void) n = drawCapacity + INITIAL_ENTITY_DRAW_CAPACITY; - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing entity draw capacity: %d -> %d\n", drawCapacity, n); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing entity draw capacity: %d -> %d", drawCapacity, n); entsToDraw = resize(entsToDraw, sizeof(Entity*) * drawCapacity, sizeof(Entity*) * n); diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 27dfd18..6fdc73d 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -44,7 +44,6 @@ Entity *spawnFighter(char *name, int x, int y, int side) memcpy(e, def, sizeof(Entity)); - e->id = battle.entId; e->next = NULL; e->x = x; @@ -276,7 +275,7 @@ void doFighter(void) if (self->alive == ALIVE_DEAD) { - if (player != NULL && self == player) + if (player != NULL && self != player) { if (player->alive == ALIVE_ALIVE) { diff --git a/src/battle/player.c b/src/battle/player.c index 196fa32..0f024d4 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -564,7 +564,7 @@ static void selectMissionTarget(void) closest = dist; } } - else if (battle.missionTarget->type == ET_WAYPOINT && e->type == ET_WAYPOINT && e->id < battle.missionTarget->id) + else if (battle.missionTarget->type == ET_WAYPOINT && e->type == ET_WAYPOINT && e->id == battle.missionTarget->id) { battle.missionTarget = e; } diff --git a/src/battle/script.c b/src/battle/script.c index 8cd4a4b..f510457 100644 --- a/src/battle/script.c +++ b/src/battle/script.c @@ -162,7 +162,7 @@ static void executeNextLine(ScriptRunner *runner) } else if (strcmp(command, "ACTIVATE_NEXT_WAYPOINT") == 0) { - activateNextWaypoint(0); + activateNextWaypoint(); } else if (strcmp(command, "ACTIVATE_SPAWNERS") == 0) { diff --git a/src/battle/script.h b/src/battle/script.h index 7fb5f4c..073c08c 100644 --- a/src/battle/script.h +++ b/src/battle/script.h @@ -34,7 +34,7 @@ extern void activateLocations(char *locations); void activateObjectives(char *objectives); extern int showingMessageBoxes(void); extern char *getTranslatedString(char *string); -extern void activateNextWaypoint(int id); +extern void activateNextWaypoint(void); extern void activateJumpgate(int activate); extern void activateSpawner(char *name, int active); diff --git a/src/battle/waypoints.c b/src/battle/waypoints.c index 7f95402..74f1c4b 100644 --- a/src/battle/waypoints.c +++ b/src/battle/waypoints.c @@ -23,20 +23,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void think(void); static int teamMatesClose(void); static int isCurrentObjective(void); -void activateNextWaypoint(int id); +void activateNextWaypoint(void); static int waypointId; +static int currentWaypointId; void resetWaypoints(void) { waypointId = 1; + currentWaypointId = 0; } Entity *spawnWaypoint(void) { Entity *waypoint = spawnEntity(); - sprintf(waypoint->name, "Waypoint #%d", waypointId++); + sprintf(waypoint->name, "Waypoint #%d", waypointId); + waypoint->id = waypointId; waypoint->type = ET_WAYPOINT; waypoint->active = 0; waypoint->health = waypoint->maxHealth = FPS; @@ -47,6 +50,8 @@ Entity *spawnWaypoint(void) SDL_QueryTexture(waypoint->texture, NULL, NULL, &waypoint->w, &waypoint->h); + waypointId++; + return waypoint; } @@ -71,7 +76,10 @@ static void think(void) runScriptFunction(self->name); - activateNextWaypoint(self->id); + if (battle.waypointAutoAdvance) + { + activateNextWaypoint(); + } battle.stats[STAT_WAYPOINTS_VISITED]++; } @@ -112,14 +120,16 @@ static int teamMatesClose(void) return 1; } -void activateNextWaypoint(int id) +void activateNextWaypoint(void) { Entity *e; Entity *nextWaypoint = NULL; + currentWaypointId++; + for (e = battle.entityHead.next ; e != NULL ; e = e->next) { - if (e->type == ET_WAYPOINT && e->id > id && (nextWaypoint == NULL || e->id < nextWaypoint->id)) + if (e->type == ET_WAYPOINT && e->id == currentWaypointId) { nextWaypoint = e; } @@ -128,5 +138,7 @@ void activateNextWaypoint(int id) if (nextWaypoint != NULL) { nextWaypoint->active = 1; + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Activating %s", nextWaypoint->name); } } diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index df5960b..367531d 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -167,6 +167,7 @@ void loadMission(char *filename) battle.manualComplete = getJSONValue(root, "manualComplete", 0); battle.unwinnable = getJSONValue(root, "unwinnable", 0); + battle.waypointAutoAdvance = getJSONValue(root, "waypointAutoAdvance", 0); initScript(cJSON_GetObjectItem(root, "script")); @@ -218,6 +219,11 @@ void loadMission(char *filename) { battle.status = MS_IN_PROGRESS; } + + if (battle.waypointAutoAdvance) + { + activateNextWaypoint(); + } countNumEnemies(); @@ -350,6 +356,7 @@ static void loadEntities(cJSON *node) { case ET_WAYPOINT: e = spawnWaypoint(); + active = 0; break; case ET_JUMPGATE: diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 1565040..eb36d89 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -58,6 +58,7 @@ extern void loadItems(cJSON *node); extern void loadLocations(cJSON *node); extern void loadSpawners(cJSON *node); extern Entity *spawnMine(void); +extern void activateNextWaypoint(void); extern Battle battle; extern Dev dev; diff --git a/src/structs.h b/src/structs.h index 7eb12b0..659d8b5 100644 --- a/src/structs.h +++ b/src/structs.h @@ -325,7 +325,6 @@ struct Spawner { }; typedef struct { - int entId; SDL_Point camera; int numAllies; int numEnemies; @@ -336,6 +335,7 @@ typedef struct { int playerSelect; int manualComplete; int unwinnable; + int waypointAutoAdvance; int missionFinishedTimer; int boostTimer; int ecmTimer;