Allow waypoints to be manually activated. Removed entId from Battle (redundant).

This commit is contained in:
Steve 2016-04-04 11:23:32 +01:00
parent 77da136e75
commit 29d873d28a
15 changed files with 36 additions and 44 deletions

View File

@ -6,6 +6,7 @@
"planet" : "gfx/planets/torelli.png", "planet" : "gfx/planets/torelli.png",
"music" : "music/battle/heroism.ogg", "music" : "music/battle/heroism.ogg",
"manualComplete" : 1, "manualComplete" : 1,
"waypointAutoAdvance" : 1,
"objectives" : [ "objectives" : [
{ {
"description" : "Check all waypoints", "description" : "Check all waypoints",
@ -42,12 +43,6 @@
} }
], ],
"script" : [ "script" : [
{
"function" : "TIME 0",
"lines" : [
"ACTIVATE_NEXT_WAYPOINT"
]
},
{ {
"function" : "Waypoint #2", "function" : "Waypoint #2",
"lines" : [ "lines" : [

View File

@ -6,6 +6,7 @@
"planet" : "gfx/planets/torelli.png", "planet" : "gfx/planets/torelli.png",
"music" : "music/battle/heroism.ogg", "music" : "music/battle/heroism.ogg",
"manualComplete" : 1, "manualComplete" : 1,
"waypointAutoAdvance" : 1,
"objectives" : [ "objectives" : [
{ {
"description" : "Check all Waypoints", "description" : "Check all Waypoints",
@ -59,12 +60,6 @@
} }
], ],
"script" : [ "script" : [
{
"function" : "TIME 0",
"lines" : [
"ACTIVATE_NEXT_WAYPOINT"
]
},
{ {
"function" : "Waypoint #3", "function" : "Waypoint #3",
"lines" : [ "lines" : [

View File

@ -9,6 +9,7 @@
"planet" : "gfx/planets/torelli.png", "planet" : "gfx/planets/torelli.png",
"music" : "", "music" : "",
"manualComplete" : 1, "manualComplete" : 1,
"waypointAutoAdvance" : 1,
"objectives" : [ "objectives" : [
{ {
"description" : "Check all Waypoints", "description" : "Check all Waypoints",
@ -45,12 +46,6 @@
} }
], ],
"script" : [ "script" : [
{
"function" : "TIME 0",
"lines" : [
"ACTIVATE_NEXT_WAYPOINT"
]
},
{ {
"function" : "TIME 3", "function" : "TIME 3",
"lines" : [ "lines" : [

View File

@ -6,6 +6,7 @@
"planet" : "gfx/planets/bluePlanet.png", "planet" : "gfx/planets/bluePlanet.png",
"music" : "music/battle/determination.mp3", "music" : "music/battle/determination.mp3",
"manualComplete" : 1, "manualComplete" : 1,
"waypointAutoAdvance" : 1,
"objectives" : [ "objectives" : [
{ {
"description" : "Check all wayponts", "description" : "Check all wayponts",
@ -126,12 +127,6 @@
} }
], ],
"script" : [ "script" : [
{
"function" : "TIME 0",
"lines" : [
"ACTIVATE_NEXT_WAYPOINT"
]
},
{ {
"function" : "Waypoint #2", "function" : "Waypoint #2",
"lines" : [ "lines" : [

View File

@ -6,6 +6,7 @@
"planet" : "gfx/planets/bluePlanet.png", "planet" : "gfx/planets/bluePlanet.png",
"music" : "music/battle/determination.mp3", "music" : "music/battle/determination.mp3",
"manualComplete" : 1, "manualComplete" : 1,
"waypointAutoAdvance" : 1,
"player" : { "player" : {
"pilot" : "Lt. Cdr. Daniel Carr", "pilot" : "Lt. Cdr. Daniel Carr",
"squadron" : "Iron Patriots", "squadron" : "Iron Patriots",
@ -126,12 +127,6 @@
} }
], ],
"script" : [ "script" : [
{
"function" : "TIME 0",
"lines" : [
"ACTIVATE_NEXT_WAYPOINT"
]
},
{ {
"function" : "Waypoint #1", "function" : "Waypoint #1",
"lines" : [ "lines" : [

View File

@ -50,7 +50,6 @@ Entity *spawnCapitalShip(char *name, int x, int y, int side)
memcpy(e, def, sizeof(Entity)); memcpy(e, def, sizeof(Entity));
e->id = battle.entId;
e->next = NULL; e->next = NULL;
e->x = x; e->x = x;

View File

@ -59,7 +59,6 @@ Entity *spawnEntity(void)
{ {
Entity *e = malloc(sizeof(Entity)); Entity *e = malloc(sizeof(Entity));
memset(e, 0, sizeof(Entity)); memset(e, 0, sizeof(Entity));
e->id = battle.entId++;
e->active = 1; e->active = 1;
battle.entityTail->next = e; battle.entityTail->next = e;
@ -291,7 +290,7 @@ static void resizeDrawList(void)
n = drawCapacity + INITIAL_ENTITY_DRAW_CAPACITY; 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); entsToDraw = resize(entsToDraw, sizeof(Entity*) * drawCapacity, sizeof(Entity*) * n);

View File

@ -44,7 +44,6 @@ Entity *spawnFighter(char *name, int x, int y, int side)
memcpy(e, def, sizeof(Entity)); memcpy(e, def, sizeof(Entity));
e->id = battle.entId;
e->next = NULL; e->next = NULL;
e->x = x; e->x = x;
@ -276,7 +275,7 @@ void doFighter(void)
if (self->alive == ALIVE_DEAD) if (self->alive == ALIVE_DEAD)
{ {
if (player != NULL && self == player) if (player != NULL && self != player)
{ {
if (player->alive == ALIVE_ALIVE) if (player->alive == ALIVE_ALIVE)
{ {

View File

@ -564,7 +564,7 @@ static void selectMissionTarget(void)
closest = dist; 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; battle.missionTarget = e;
} }

View File

@ -162,7 +162,7 @@ static void executeNextLine(ScriptRunner *runner)
} }
else if (strcmp(command, "ACTIVATE_NEXT_WAYPOINT") == 0) else if (strcmp(command, "ACTIVATE_NEXT_WAYPOINT") == 0)
{ {
activateNextWaypoint(0); activateNextWaypoint();
} }
else if (strcmp(command, "ACTIVATE_SPAWNERS") == 0) else if (strcmp(command, "ACTIVATE_SPAWNERS") == 0)
{ {

View File

@ -34,7 +34,7 @@ extern void activateLocations(char *locations);
void activateObjectives(char *objectives); void activateObjectives(char *objectives);
extern int showingMessageBoxes(void); extern int showingMessageBoxes(void);
extern char *getTranslatedString(char *string); extern char *getTranslatedString(char *string);
extern void activateNextWaypoint(int id); extern void activateNextWaypoint(void);
extern void activateJumpgate(int activate); extern void activateJumpgate(int activate);
extern void activateSpawner(char *name, int active); extern void activateSpawner(char *name, int active);

View File

@ -23,20 +23,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void think(void); static void think(void);
static int teamMatesClose(void); static int teamMatesClose(void);
static int isCurrentObjective(void); static int isCurrentObjective(void);
void activateNextWaypoint(int id); void activateNextWaypoint(void);
static int waypointId; static int waypointId;
static int currentWaypointId;
void resetWaypoints(void) void resetWaypoints(void)
{ {
waypointId = 1; waypointId = 1;
currentWaypointId = 0;
} }
Entity *spawnWaypoint(void) Entity *spawnWaypoint(void)
{ {
Entity *waypoint = spawnEntity(); Entity *waypoint = spawnEntity();
sprintf(waypoint->name, "Waypoint #%d", waypointId++); sprintf(waypoint->name, "Waypoint #%d", waypointId);
waypoint->id = waypointId;
waypoint->type = ET_WAYPOINT; waypoint->type = ET_WAYPOINT;
waypoint->active = 0; waypoint->active = 0;
waypoint->health = waypoint->maxHealth = FPS; waypoint->health = waypoint->maxHealth = FPS;
@ -47,6 +50,8 @@ Entity *spawnWaypoint(void)
SDL_QueryTexture(waypoint->texture, NULL, NULL, &waypoint->w, &waypoint->h); SDL_QueryTexture(waypoint->texture, NULL, NULL, &waypoint->w, &waypoint->h);
waypointId++;
return waypoint; return waypoint;
} }
@ -71,7 +76,10 @@ static void think(void)
runScriptFunction(self->name); runScriptFunction(self->name);
activateNextWaypoint(self->id); if (battle.waypointAutoAdvance)
{
activateNextWaypoint();
}
battle.stats[STAT_WAYPOINTS_VISITED]++; battle.stats[STAT_WAYPOINTS_VISITED]++;
} }
@ -112,14 +120,16 @@ static int teamMatesClose(void)
return 1; return 1;
} }
void activateNextWaypoint(int id) void activateNextWaypoint(void)
{ {
Entity *e; Entity *e;
Entity *nextWaypoint = NULL; Entity *nextWaypoint = NULL;
currentWaypointId++;
for (e = battle.entityHead.next ; e != NULL ; e = e->next) 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; nextWaypoint = e;
} }
@ -128,5 +138,7 @@ void activateNextWaypoint(int id)
if (nextWaypoint != NULL) if (nextWaypoint != NULL)
{ {
nextWaypoint->active = 1; nextWaypoint->active = 1;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Activating %s", nextWaypoint->name);
} }
} }

View File

@ -167,6 +167,7 @@ void loadMission(char *filename)
battle.manualComplete = getJSONValue(root, "manualComplete", 0); battle.manualComplete = getJSONValue(root, "manualComplete", 0);
battle.unwinnable = getJSONValue(root, "unwinnable", 0); battle.unwinnable = getJSONValue(root, "unwinnable", 0);
battle.waypointAutoAdvance = getJSONValue(root, "waypointAutoAdvance", 0);
initScript(cJSON_GetObjectItem(root, "script")); initScript(cJSON_GetObjectItem(root, "script"));
@ -219,6 +220,11 @@ void loadMission(char *filename)
battle.status = MS_IN_PROGRESS; battle.status = MS_IN_PROGRESS;
} }
if (battle.waypointAutoAdvance)
{
activateNextWaypoint();
}
countNumEnemies(); countNumEnemies();
initPlayer(); initPlayer();
@ -350,6 +356,7 @@ static void loadEntities(cJSON *node)
{ {
case ET_WAYPOINT: case ET_WAYPOINT:
e = spawnWaypoint(); e = spawnWaypoint();
active = 0;
break; break;
case ET_JUMPGATE: case ET_JUMPGATE:

View File

@ -58,6 +58,7 @@ extern void loadItems(cJSON *node);
extern void loadLocations(cJSON *node); extern void loadLocations(cJSON *node);
extern void loadSpawners(cJSON *node); extern void loadSpawners(cJSON *node);
extern Entity *spawnMine(void); extern Entity *spawnMine(void);
extern void activateNextWaypoint(void);
extern Battle battle; extern Battle battle;
extern Dev dev; extern Dev dev;

View File

@ -325,7 +325,6 @@ struct Spawner {
}; };
typedef struct { typedef struct {
int entId;
SDL_Point camera; SDL_Point camera;
int numAllies; int numAllies;
int numEnemies; int numEnemies;
@ -336,6 +335,7 @@ typedef struct {
int playerSelect; int playerSelect;
int manualComplete; int manualComplete;
int unwinnable; int unwinnable;
int waypointAutoAdvance;
int missionFinishedTimer; int missionFinishedTimer;
int boostTimer; int boostTimer;
int ecmTimer; int ecmTimer;