diff --git a/data/missions/test/test.json b/data/missions/test/test.json index 7731afd..1228862 100644 --- a/data/missions/test/test.json +++ b/data/missions/test/test.json @@ -4,6 +4,14 @@ "background" : "gfx/backgrounds/background03.jpg", "planet" : "gfx/planets/spirit.png", "music" : "", + "objectives" : [ + { + "description" : "Reach Waypoints", + "targetName" : "Waypoint", + "targetValue" : 5, + "targetType" : "TT_WAYPOINT" + } + ], "player" : { "type" : "Nymph", "side" : "SIDE_CSN" @@ -17,14 +25,13 @@ "y" : 200 } ], - "entitiesGroups" : [ + "entityGroups" : [ { - "name" : "Waypoint", "type" : "ET_WAYPOINT", - "number" : 10, - "x" : 640, - "y" : -10000, - "scatter" : 10000 + "number" : 5, + "x" : 0, + "y" : 1000, + "scatter" : 1000 } ] } diff --git a/src/battle/ai.c b/src/battle/ai.c index 297596b..8acb268 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -150,7 +150,7 @@ static void findTarget(void) for (f = battle.entityHead.next ; f != NULL ; f = f->next) { - if (f->type == ET_FIGHTER && f->side != self->side && f->health > 0 && canAttack(f)) + if (f->active && f->type == ET_FIGHTER && f->side != self->side && f->health > 0 && canAttack(f)) { dist = getDistance(self->x, self->y, f->x, f->y); if (dist < closest) @@ -257,7 +257,7 @@ static int hasClearShot(void) for (f = battle.entityHead.next ; f != NULL ; f = f->next) { - if (f != self && f != self->target && (getDistance(self->x, self->y, f->x, f->y) < dist)) + if (f->active && f != self && f != self->target && (getDistance(self->x, self->y, f->x, f->y) < dist)) { if (isInFOV(f, 8)) { diff --git a/src/battle/battle.c b/src/battle/battle.c index ef56e6c..3811194 100644 --- a/src/battle/battle.c +++ b/src/battle/battle.c @@ -58,6 +58,8 @@ void initBattle(void) initMissionInfo(); + resetWaypoints(); + show = SHOW_BATTLE; getWidget("ok", "startBattle")->action = start; diff --git a/src/battle/battle.h b/src/battle/battle.h index 6be9e3f..07e89f0 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -61,6 +61,7 @@ extern void initOptions(void (*returnFromOptions)(void)); extern void drawOptions(void); extern void playSound(int id); extern void checkTrigger(char *name, int type); +extern void resetWaypoints(void); extern App app; extern Battle battle; diff --git a/src/battle/bullets.c b/src/battle/bullets.c index e0e3403..1ec6ed2 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -101,6 +101,11 @@ static void checkCollisions(Bullet *b) for (f = battle.entityHead.next ; f != NULL ; f = f->next) { + if (!f->active) + { + continue; + } + if (f->type == ET_FIGHTER) { SDL_QueryTexture(f->texture, NULL, NULL, &ew, &eh); diff --git a/src/battle/entities.c b/src/battle/entities.c index 1b949de..d031657 100644 --- a/src/battle/entities.c +++ b/src/battle/entities.c @@ -28,6 +28,7 @@ Entity *spawnEntity(void) Entity *e = malloc(sizeof(Entity)); memset(e, 0, sizeof(Entity)); e->id = battle.entId++; + e->active = 1; battle.entityTail->next = e; battle.entityTail = e; @@ -45,6 +46,11 @@ void doEntities(void) for (e = battle.entityHead.next ; e != NULL ; e = e->next) { + if (!e->active) + { + continue; + } + self = e; if (self->target != NULL && self->target->health <= 0) @@ -71,7 +77,7 @@ void doEntities(void) } } - switch (e->type) + switch (self->type) { case ET_FIGHTER: doFighter(prev); @@ -112,6 +118,11 @@ void drawEntities(void) for (e = battle.entityHead.next ; e != NULL ; e = e->next) { + if (!e->active) + { + continue; + } + switch (e->type) { case ET_FIGHTER: diff --git a/src/battle/fighterDefs.c b/src/battle/fighterDefs.c index e1e6564..cb17d29 100644 --- a/src/battle/fighterDefs.c +++ b/src/battle/fighterDefs.c @@ -76,6 +76,8 @@ static void loadFighterDef(char *filename) defTail->next = f; defTail = f; + f->active = 1; + root = cJSON_Parse(text); STRNCPY(f->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH); diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 30bbcab..86ce529 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -282,7 +282,7 @@ static void separate(void) for (f = battle.entityHead.next ; f != NULL ; f = f->next) { - if (f != self) + if (f != self && f->active) { distance = getDistance(f->x, f->y, self->x, self->y); diff --git a/src/battle/hud.c b/src/battle/hud.c index 40cef5a..0433568 100644 --- a/src/battle/hud.c +++ b/src/battle/hud.c @@ -27,6 +27,7 @@ static void drawHealthBars(void); static void drawWeaponInfo(void); static void drawObjectives(void); static void drawTargetDistance(void); +static void drawMissionTargetDistance(void); static void drawHudMessages(void); static HudMessage hudMessageHead; @@ -165,6 +166,11 @@ static void drawHealthBars(void) drawHealthShieldBar(player->target->shield, player->target->maxShield, SCREEN_WIDTH - 260, 30, 0, 200, 255); drawTargetDistance(); } + + if (battle.missionTarget) + { + drawMissionTargetDistance(); + } } static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g, int b) @@ -214,6 +220,20 @@ static void drawPlayerTargeter(void) float angle; int x, y; + if (player->target || battle.missionTarget) + { + if (player->target) + { + SDL_SetTextureColorMod(targetCircle, 255, 0, 0); + } + else + { + SDL_SetTextureColorMod(targetCircle, 0, 255, 0); + } + + blit(targetCircle, player->x, player->y, 1); + } + if (player->target) { angle = getAngle(player->x, player->y, player->target->x, player->target->y); @@ -224,10 +244,8 @@ static void drawPlayerTargeter(void) y += -cos(TO_RAIDANS(angle)) * 45; SDL_SetTextureColorMod(targetPointer, 255, 0, 0); - SDL_SetTextureColorMod(targetCircle, 255, 0, 0); blitRotated(targetPointer, x, y, angle); - blitRotated(targetCircle, player->x, player->y, angle); } if (battle.missionTarget) @@ -277,6 +295,11 @@ static void drawTargetDistance(void) drawText(SCREEN_WIDTH - 15, 50, 14, TA_RIGHT, colors.red, "Target: %.2fkm", distance); } +} + +static void drawMissionTargetDistance(void) +{ + float distance; if (battle.missionTarget != NULL) { diff --git a/src/battle/player.c b/src/battle/player.c index f5181a2..2a69a1e 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -148,6 +148,11 @@ static void selectTarget(void) for (e = battle.entityHead.next ; e != NULL ; e = e->next) { + if (!e->active) + { + continue; + } + if (e != player && e->type == ET_FIGHTER && e->side != player->side && e->alive == ALIVE_ALIVE) { dist = getDistance(self->x, self->y, e->x, e->y); @@ -170,6 +175,11 @@ static void selectMissionTarget(void) for (e = battle.entityHead.next ; e != NULL ; e = e->next) { + if (!e->active) + { + continue; + } + if (e->flags & EF_MISSION_TARGET && e->alive == ALIVE_ALIVE) { if (battle.missionTarget == NULL) diff --git a/src/battle/radar.c b/src/battle/radar.c index 3ee5614..0ed9c1b 100644 --- a/src/battle/radar.c +++ b/src/battle/radar.c @@ -36,7 +36,7 @@ void drawRadar(void) for (f = battle.entityHead.next ; f != NULL ; f = f->next) { - if (getDistance(f->x, f->y, player->x, player->y) / RADAR_RANGE < 70) + if (f->active && getDistance(f->x, f->y, player->x, player->y) / RADAR_RANGE < 70) { r.x = SCREEN_WIDTH - 85; r.y = SCREEN_HEIGHT - 85; diff --git a/src/battle/waypoints.c b/src/battle/waypoints.c index 0c77c6a..93af793 100644 --- a/src/battle/waypoints.c +++ b/src/battle/waypoints.c @@ -22,12 +22,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void think(void); static int teamMatesClose(void); +void activateNextWaypoint(int id); + +static int waypointId; + +void resetWaypoints(void) +{ + waypointId = 1; +} Entity *spawnWaypoint(void) { Entity *waypoint = spawnEntity(); + sprintf(waypoint->name, "Waypoint #%d", waypointId++); waypoint->type = ET_WAYPOINT; + waypoint->active = 0; waypoint->health = waypoint->maxHealth = FPS; waypoint->texture = getTexture("gfx/entities/waypoint.png"); waypoint->flags = EF_MISSION_TARGET; @@ -43,12 +53,18 @@ static void think(void) self->angle++; if (self->angle >= 360) { - self -= 360; + self->angle -= 360; } if (getDistance(player->x, player->y, self->x, self->y) <= 32 && teamMatesClose()) { self->health = 0; + + updateObjective("Waypoint", TT_WAYPOINT); + + checkTrigger(self->name, TRIGGER_WAYPOINT); + + activateNextWaypoint(self->id); } } @@ -58,7 +74,7 @@ static int teamMatesClose(void) for (e = battle.entityHead.next ; e != NULL ; e = e->next) { - if (e->type == ET_FIGHTER && e->side == player->side) + if (e->active && e->type == ET_FIGHTER && e->side == player->side) { if (getDistance(player->x, player->y, e->x, e->y) > 350) { @@ -71,3 +87,22 @@ static int teamMatesClose(void) return 1; } + +void activateNextWaypoint(int id) +{ + Entity *e; + Entity *nextWaypoint = NULL; + + for (e = battle.entityHead.next ; e != NULL ; e = e->next) + { + if (e->type == ET_WAYPOINT && e->id > id && (nextWaypoint == NULL || e->id < nextWaypoint->id)) + { + nextWaypoint = e; + } + } + + if (nextWaypoint != NULL) + { + nextWaypoint->active = 1; + } +} diff --git a/src/battle/waypoints.h b/src/battle/waypoints.h index 2f7d614..6a14ea9 100644 --- a/src/battle/waypoints.h +++ b/src/battle/waypoints.h @@ -27,6 +27,8 @@ extern SDL_Texture *getTexture(char *filename); extern int getDistance(int x1, int y1, int x2, int y2); extern void addHudMessage(SDL_Color c, char *format, ...); extern Entity *spawnEntity(void); +extern void updateObjective(char *name, int type); +extern void checkTrigger(char *name, int type); extern Battle battle; extern Colors colors; diff --git a/src/defs.h b/src/defs.h index cf7deb5..149e82c 100644 --- a/src/defs.h +++ b/src/defs.h @@ -56,7 +56,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define EF_DISABLE (2 << 1) #define EF_IMMORTAL (2 << 2) #define EF_MISSION_TARGET (2 << 3) -#define EF_INVISIBLE (2 << 4) enum { @@ -147,13 +146,15 @@ enum enum { TT_DESTROY, - TT_DISABLE + TT_DISABLE, + TT_WAYPOINT }; enum { TRIGGER_TIME, - TRIGGER_KILLS + TRIGGER_KILLS, + TRIGGER_WAYPOINT }; enum diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 0050d70..ac406bc 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -83,6 +83,7 @@ void loadMission(char *filename) battle.status = MS_IN_PROGRESS; } + activateNextWaypoint(); initPlayer(); @@ -271,8 +272,12 @@ static void loadEntities(cJSON *node) e = spawnWaypoint(); break; } - - STRNCPY(e->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH); + + if (cJSON_GetObjectItem(node, "name")) + { + STRNCPY(e->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH); + } + e->x = cJSON_GetObjectItem(node, "x")->valueint; e->y = cJSON_GetObjectItem(node, "y")->valueint; @@ -291,10 +296,8 @@ static void loadEntityGroups(cJSON *node) Entity *e; char *name; int i, type, x, y, scatter, number; - long flags; scatter = 1; - flags = 0; if (node) { @@ -303,14 +306,18 @@ static void loadEntityGroups(cJSON *node) while (node) { type = lookup(cJSON_GetObjectItem(node, "type")->valuestring); - name = cJSON_GetObjectItem(node, "name")->valuestring; number = cJSON_GetObjectItem(node, "number")->valueint; x = cJSON_GetObjectItem(node, "x")->valueint; y = cJSON_GetObjectItem(node, "y")->valueint; - if (cJSON_GetObjectItem(node, "flags")) + if (cJSON_GetObjectItem(node, "name")) { - flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring); + name = cJSON_GetObjectItem(node, "name")->valuestring; + } + + if (cJSON_GetObjectItem(node, "scatter")) + { + scatter = cJSON_GetObjectItem(node, "scatter")->valueint; } for (i = 0 ; i < number ; i++) @@ -321,12 +328,15 @@ static void loadEntityGroups(cJSON *node) e = spawnWaypoint(); break; } - - STRNCPY(e->name, name, MAX_NAME_LENGTH); + + if (name) + { + STRNCPY(e->name, name, MAX_NAME_LENGTH); + } + e->id = battle.entId++; e->x = x; e->y = y; - e->flags = flags; e->x += (rand() % scatter) - (rand() % scatter); e->y += (rand() % scatter) - (rand() % scatter); diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index be3d88c..8131e52 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -36,6 +36,7 @@ extern void stopMusic(void); extern void initPlayer(void); extern long flagsToLong(char *flags); extern Entity *spawnWaypoint(void); +extern void activateNextWaypoint(void); extern Battle battle; extern Entity *player; diff --git a/src/structs.h b/src/structs.h index 20936aa..7ed0a8d 100644 --- a/src/structs.h +++ b/src/structs.h @@ -71,6 +71,7 @@ struct Weapon { struct Entity { int type; char name[MAX_NAME_LENGTH]; + int active; int id; int side; float x; diff --git a/src/system/lookup.c b/src/system/lookup.c index b1d5cef..247d0e3 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -39,6 +39,7 @@ void initLookups(void) addLookup("TT_DESTROY", TT_DESTROY); addLookup("TT_DISABLE", TT_DISABLE); + addLookup("TT_WAYPOINT", TT_WAYPOINT); addLookup("WT_BUTTON", WT_BUTTON); addLookup("WT_SELECT", WT_SELECT);