Integrated waypoints into objective system.

This commit is contained in:
Steve 2015-10-28 19:12:58 +00:00
parent 49832b114b
commit 5c7b2a24bf
18 changed files with 140 additions and 28 deletions

View File

@ -4,6 +4,14 @@
"background" : "gfx/backgrounds/background03.jpg", "background" : "gfx/backgrounds/background03.jpg",
"planet" : "gfx/planets/spirit.png", "planet" : "gfx/planets/spirit.png",
"music" : "", "music" : "",
"objectives" : [
{
"description" : "Reach Waypoints",
"targetName" : "Waypoint",
"targetValue" : 5,
"targetType" : "TT_WAYPOINT"
}
],
"player" : { "player" : {
"type" : "Nymph", "type" : "Nymph",
"side" : "SIDE_CSN" "side" : "SIDE_CSN"
@ -17,14 +25,13 @@
"y" : 200 "y" : 200
} }
], ],
"entitiesGroups" : [ "entityGroups" : [
{ {
"name" : "Waypoint",
"type" : "ET_WAYPOINT", "type" : "ET_WAYPOINT",
"number" : 10, "number" : 5,
"x" : 640, "x" : 0,
"y" : -10000, "y" : 1000,
"scatter" : 10000 "scatter" : 1000
} }
] ]
} }

View File

@ -150,7 +150,7 @@ static void findTarget(void)
for (f = battle.entityHead.next ; f != NULL ; f = f->next) 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); dist = getDistance(self->x, self->y, f->x, f->y);
if (dist < closest) if (dist < closest)
@ -257,7 +257,7 @@ static int hasClearShot(void)
for (f = battle.entityHead.next ; f != NULL ; f = f->next) 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)) if (isInFOV(f, 8))
{ {

View File

@ -58,6 +58,8 @@ void initBattle(void)
initMissionInfo(); initMissionInfo();
resetWaypoints();
show = SHOW_BATTLE; show = SHOW_BATTLE;
getWidget("ok", "startBattle")->action = start; getWidget("ok", "startBattle")->action = start;

View File

@ -61,6 +61,7 @@ extern void initOptions(void (*returnFromOptions)(void));
extern void drawOptions(void); extern void drawOptions(void);
extern void playSound(int id); extern void playSound(int id);
extern void checkTrigger(char *name, int type); extern void checkTrigger(char *name, int type);
extern void resetWaypoints(void);
extern App app; extern App app;
extern Battle battle; extern Battle battle;

View File

@ -101,6 +101,11 @@ static void checkCollisions(Bullet *b)
for (f = battle.entityHead.next ; f != NULL ; f = f->next) for (f = battle.entityHead.next ; f != NULL ; f = f->next)
{ {
if (!f->active)
{
continue;
}
if (f->type == ET_FIGHTER) if (f->type == ET_FIGHTER)
{ {
SDL_QueryTexture(f->texture, NULL, NULL, &ew, &eh); SDL_QueryTexture(f->texture, NULL, NULL, &ew, &eh);

View File

@ -28,6 +28,7 @@ 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->id = battle.entId++;
e->active = 1;
battle.entityTail->next = e; battle.entityTail->next = e;
battle.entityTail = e; battle.entityTail = e;
@ -45,6 +46,11 @@ void doEntities(void)
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (!e->active)
{
continue;
}
self = e; self = e;
if (self->target != NULL && self->target->health <= 0) if (self->target != NULL && self->target->health <= 0)
@ -71,7 +77,7 @@ void doEntities(void)
} }
} }
switch (e->type) switch (self->type)
{ {
case ET_FIGHTER: case ET_FIGHTER:
doFighter(prev); doFighter(prev);
@ -112,6 +118,11 @@ void drawEntities(void)
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (!e->active)
{
continue;
}
switch (e->type) switch (e->type)
{ {
case ET_FIGHTER: case ET_FIGHTER:

View File

@ -76,6 +76,8 @@ static void loadFighterDef(char *filename)
defTail->next = f; defTail->next = f;
defTail = f; defTail = f;
f->active = 1;
root = cJSON_Parse(text); root = cJSON_Parse(text);
STRNCPY(f->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH); STRNCPY(f->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);

View File

@ -282,7 +282,7 @@ static void separate(void)
for (f = battle.entityHead.next ; f != NULL ; f = f->next) 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); distance = getDistance(f->x, f->y, self->x, self->y);

View File

@ -27,6 +27,7 @@ static void drawHealthBars(void);
static void drawWeaponInfo(void); static void drawWeaponInfo(void);
static void drawObjectives(void); static void drawObjectives(void);
static void drawTargetDistance(void); static void drawTargetDistance(void);
static void drawMissionTargetDistance(void);
static void drawHudMessages(void); static void drawHudMessages(void);
static HudMessage hudMessageHead; 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); drawHealthShieldBar(player->target->shield, player->target->maxShield, SCREEN_WIDTH - 260, 30, 0, 200, 255);
drawTargetDistance(); drawTargetDistance();
} }
if (battle.missionTarget)
{
drawMissionTargetDistance();
}
} }
static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g, int b) 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; float angle;
int x, y; 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) if (player->target)
{ {
angle = getAngle(player->x, player->y, player->target->x, player->target->y); 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; y += -cos(TO_RAIDANS(angle)) * 45;
SDL_SetTextureColorMod(targetPointer, 255, 0, 0); SDL_SetTextureColorMod(targetPointer, 255, 0, 0);
SDL_SetTextureColorMod(targetCircle, 255, 0, 0);
blitRotated(targetPointer, x, y, angle); blitRotated(targetPointer, x, y, angle);
blitRotated(targetCircle, player->x, player->y, angle);
} }
if (battle.missionTarget) if (battle.missionTarget)
@ -277,6 +295,11 @@ static void drawTargetDistance(void)
drawText(SCREEN_WIDTH - 15, 50, 14, TA_RIGHT, colors.red, "Target: %.2fkm", distance); drawText(SCREEN_WIDTH - 15, 50, 14, TA_RIGHT, colors.red, "Target: %.2fkm", distance);
} }
}
static void drawMissionTargetDistance(void)
{
float distance;
if (battle.missionTarget != NULL) if (battle.missionTarget != NULL)
{ {

View File

@ -148,6 +148,11 @@ static void selectTarget(void)
for (e = battle.entityHead.next ; e != NULL ; e = e->next) 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) 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); 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) 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 (e->flags & EF_MISSION_TARGET && e->alive == ALIVE_ALIVE)
{ {
if (battle.missionTarget == NULL) if (battle.missionTarget == NULL)

View File

@ -36,7 +36,7 @@ void drawRadar(void)
for (f = battle.entityHead.next ; f != NULL ; f = f->next) 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.x = SCREEN_WIDTH - 85;
r.y = SCREEN_HEIGHT - 85; r.y = SCREEN_HEIGHT - 85;

View File

@ -22,12 +22,22 @@ 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);
void activateNextWaypoint(int id);
static int waypointId;
void resetWaypoints(void)
{
waypointId = 1;
}
Entity *spawnWaypoint(void) Entity *spawnWaypoint(void)
{ {
Entity *waypoint = spawnEntity(); Entity *waypoint = spawnEntity();
sprintf(waypoint->name, "Waypoint #%d", waypointId++);
waypoint->type = ET_WAYPOINT; waypoint->type = ET_WAYPOINT;
waypoint->active = 0;
waypoint->health = waypoint->maxHealth = FPS; waypoint->health = waypoint->maxHealth = FPS;
waypoint->texture = getTexture("gfx/entities/waypoint.png"); waypoint->texture = getTexture("gfx/entities/waypoint.png");
waypoint->flags = EF_MISSION_TARGET; waypoint->flags = EF_MISSION_TARGET;
@ -43,12 +53,18 @@ static void think(void)
self->angle++; self->angle++;
if (self->angle >= 360) if (self->angle >= 360)
{ {
self -= 360; self->angle -= 360;
} }
if (getDistance(player->x, player->y, self->x, self->y) <= 32 && teamMatesClose()) if (getDistance(player->x, player->y, self->x, self->y) <= 32 && teamMatesClose())
{ {
self->health = 0; 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) 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) if (getDistance(player->x, player->y, e->x, e->y) > 350)
{ {
@ -71,3 +87,22 @@ static int teamMatesClose(void)
return 1; 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;
}
}

View File

@ -27,6 +27,8 @@ extern SDL_Texture *getTexture(char *filename);
extern int getDistance(int x1, int y1, int x2, int y2); extern int getDistance(int x1, int y1, int x2, int y2);
extern void addHudMessage(SDL_Color c, char *format, ...); extern void addHudMessage(SDL_Color c, char *format, ...);
extern Entity *spawnEntity(void); extern Entity *spawnEntity(void);
extern void updateObjective(char *name, int type);
extern void checkTrigger(char *name, int type);
extern Battle battle; extern Battle battle;
extern Colors colors; extern Colors colors;

View File

@ -56,7 +56,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define EF_DISABLE (2 << 1) #define EF_DISABLE (2 << 1)
#define EF_IMMORTAL (2 << 2) #define EF_IMMORTAL (2 << 2)
#define EF_MISSION_TARGET (2 << 3) #define EF_MISSION_TARGET (2 << 3)
#define EF_INVISIBLE (2 << 4)
enum enum
{ {
@ -147,13 +146,15 @@ enum
enum enum
{ {
TT_DESTROY, TT_DESTROY,
TT_DISABLE TT_DISABLE,
TT_WAYPOINT
}; };
enum enum
{ {
TRIGGER_TIME, TRIGGER_TIME,
TRIGGER_KILLS TRIGGER_KILLS,
TRIGGER_WAYPOINT
}; };
enum enum

View File

@ -83,6 +83,7 @@ void loadMission(char *filename)
battle.status = MS_IN_PROGRESS; battle.status = MS_IN_PROGRESS;
} }
activateNextWaypoint();
initPlayer(); initPlayer();
@ -271,8 +272,12 @@ static void loadEntities(cJSON *node)
e = spawnWaypoint(); e = spawnWaypoint();
break; 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->x = cJSON_GetObjectItem(node, "x")->valueint;
e->y = cJSON_GetObjectItem(node, "y")->valueint; e->y = cJSON_GetObjectItem(node, "y")->valueint;
@ -291,10 +296,8 @@ static void loadEntityGroups(cJSON *node)
Entity *e; Entity *e;
char *name; char *name;
int i, type, x, y, scatter, number; int i, type, x, y, scatter, number;
long flags;
scatter = 1; scatter = 1;
flags = 0;
if (node) if (node)
{ {
@ -303,14 +306,18 @@ static void loadEntityGroups(cJSON *node)
while (node) while (node)
{ {
type = lookup(cJSON_GetObjectItem(node, "type")->valuestring); type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
name = cJSON_GetObjectItem(node, "name")->valuestring;
number = cJSON_GetObjectItem(node, "number")->valueint; number = cJSON_GetObjectItem(node, "number")->valueint;
x = cJSON_GetObjectItem(node, "x")->valueint; x = cJSON_GetObjectItem(node, "x")->valueint;
y = cJSON_GetObjectItem(node, "y")->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++) for (i = 0 ; i < number ; i++)
@ -321,12 +328,15 @@ static void loadEntityGroups(cJSON *node)
e = spawnWaypoint(); e = spawnWaypoint();
break; break;
} }
STRNCPY(e->name, name, MAX_NAME_LENGTH); if (name)
{
STRNCPY(e->name, name, MAX_NAME_LENGTH);
}
e->id = battle.entId++; e->id = battle.entId++;
e->x = x; e->x = x;
e->y = y; e->y = y;
e->flags = flags;
e->x += (rand() % scatter) - (rand() % scatter); e->x += (rand() % scatter) - (rand() % scatter);
e->y += (rand() % scatter) - (rand() % scatter); e->y += (rand() % scatter) - (rand() % scatter);

View File

@ -36,6 +36,7 @@ extern void stopMusic(void);
extern void initPlayer(void); extern void initPlayer(void);
extern long flagsToLong(char *flags); extern long flagsToLong(char *flags);
extern Entity *spawnWaypoint(void); extern Entity *spawnWaypoint(void);
extern void activateNextWaypoint(void);
extern Battle battle; extern Battle battle;
extern Entity *player; extern Entity *player;

View File

@ -71,6 +71,7 @@ struct Weapon {
struct Entity { struct Entity {
int type; int type;
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
int active;
int id; int id;
int side; int side;
float x; float x;

View File

@ -39,6 +39,7 @@ void initLookups(void)
addLookup("TT_DESTROY", TT_DESTROY); addLookup("TT_DESTROY", TT_DESTROY);
addLookup("TT_DISABLE", TT_DISABLE); addLookup("TT_DISABLE", TT_DISABLE);
addLookup("TT_WAYPOINT", TT_WAYPOINT);
addLookup("WT_BUTTON", WT_BUTTON); addLookup("WT_BUTTON", WT_BUTTON);
addLookup("WT_SELECT", WT_SELECT); addLookup("WT_SELECT", WT_SELECT);