Trim all whitespace.

This commit is contained in:
Steve 2019-11-07 08:13:57 +00:00
parent 98274ffa34
commit 3329d1375a
57 changed files with 1486 additions and 1486 deletions

File diff suppressed because it is too large Load Diff

View File

@ -57,7 +57,7 @@ void initBattle(void)
app.delegate.logic = &logic; app.delegate.logic = &logic;
app.delegate.draw = &draw; app.delegate.draw = &draw;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
battle.hasThreats = 1; battle.hasThreats = 1;
initQuadtree(&battle.quadtree); initQuadtree(&battle.quadtree);
@ -96,7 +96,7 @@ void initBattle(void)
getWidget("quit", "battleLost")->action = quitBattle; getWidget("quit", "battleLost")->action = quitBattle;
selectWidget("ok", "startBattle"); selectWidget("ok", "startBattle");
SDL_SetWindowGrab(app.window, 1); SDL_SetWindowGrab(app.window, 1);
} }
@ -117,9 +117,9 @@ static void logic(void)
doPlayerSelect(); doPlayerSelect();
} }
} }
app.doTrophyAlerts = (battle.status != MS_IN_PROGRESS && battle.missionFinishedTimer <= -FPS * 2); app.doTrophyAlerts = (battle.status != MS_IN_PROGRESS && battle.missionFinishedTimer <= -FPS * 2);
if (battle.campaignFinished) if (battle.campaignFinished)
{ {
endCampaign(); endCampaign();
@ -163,9 +163,9 @@ static void doBattle(void)
doDebris(); doDebris();
doPlayer(); doPlayer();
checkSuspicionLevel(); checkSuspicionLevel();
doTorelliFireStorm(); doTorelliFireStorm();
if (player->alive == ALIVE_ALIVE) if (player->alive == ALIVE_ALIVE)
@ -175,7 +175,7 @@ static void doBattle(void)
doLocations(); doLocations();
doMessageBox(); doMessageBox();
if (battle.status == MS_IN_PROGRESS || battle.status == MS_COMPLETE) if (battle.status == MS_IN_PROGRESS || battle.status == MS_COMPLETE)
{ {
doScript(); doScript();
@ -186,7 +186,7 @@ static void doBattle(void)
if (battle.stats[STAT_TIME]++ % FPS == 0) if (battle.stats[STAT_TIME]++ % FPS == 0)
{ {
runScriptFunction("TIME %d", battle.stats[STAT_TIME] / FPS); runScriptFunction("TIME %d", battle.stats[STAT_TIME] / FPS);
if (game.currentMission->challengeData.timeLimit && game.currentMission->challengeData.timeLimit - battle.stats[STAT_TIME] < 11 * FPS) if (game.currentMission->challengeData.timeLimit && game.currentMission->challengeData.timeLimit - battle.stats[STAT_TIME] < 11 * FPS)
{ {
playSound(SND_TIME_WARNING); playSound(SND_TIME_WARNING);
@ -198,11 +198,11 @@ static void doBattle(void)
if (battle.status != MS_IN_PROGRESS) if (battle.status != MS_IN_PROGRESS)
{ {
battle.missionFinishedTimer--; battle.missionFinishedTimer--;
if (battle.unwinnable && battle.missionFinishedTimer <= -FPS * 6) if (battle.unwinnable && battle.missionFinishedTimer <= -FPS * 6)
{ {
battle.status = MS_COMPLETE; battle.status = MS_COMPLETE;
postBattle(); postBattle();
destroyBattle(); destroyBattle();
@ -221,11 +221,11 @@ static void draw(void)
} }
drawBackground(battle.background); drawBackground(battle.background);
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
blitScaled(battle.planetTexture, battle.planet.x, battle.planet.y, battle.planetWidth, battle.planetHeight, 0); blitScaled(battle.planetTexture, battle.planet.x, battle.planet.y, battle.planetWidth, battle.planetHeight, 0);
if (battle.destroyTorelli) if (battle.destroyTorelli)
{ {
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
@ -273,14 +273,14 @@ static void draw(void)
static void drawMenu(void) static void drawMenu(void)
{ {
SDL_Rect r; SDL_Rect r;
if (app.modalDialog.type == MD_NONE) if (app.modalDialog.type == MD_NONE)
{ {
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 400; r.w = 400;
@ -294,7 +294,7 @@ static void drawMenu(void)
SDL_RenderDrawRect(app.renderer, &r); SDL_RenderDrawRect(app.renderer, &r);
drawWidgets("inBattle"); drawWidgets("inBattle");
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
} }
@ -331,9 +331,9 @@ static void handleKeyboard(void)
if (battle.status == MS_IN_PROGRESS && app.keyboard[SDL_SCANCODE_TAB]) if (battle.status == MS_IN_PROGRESS && app.keyboard[SDL_SCANCODE_TAB])
{ {
battle.status = MS_PAUSED; battle.status = MS_PAUSED;
selectWidget("ok", "startBattle"); selectWidget("ok", "startBattle");
SDL_SetWindowGrab(app.window, 0); SDL_SetWindowGrab(app.window, 0);
} }
} }
@ -341,14 +341,14 @@ static void handleKeyboard(void)
static void start(void) static void start(void)
{ {
battle.status = MS_IN_PROGRESS; battle.status = MS_IN_PROGRESS;
SDL_SetWindowGrab(app.window, 1); SDL_SetWindowGrab(app.window, 1);
} }
static void resume(void) static void resume(void)
{ {
show = SHOW_BATTLE; show = SHOW_BATTLE;
SDL_SetWindowGrab(app.window, 1); SDL_SetWindowGrab(app.window, 1);
clearInput(); clearInput();
@ -397,7 +397,7 @@ static void restart(void)
static void retry(void) static void retry(void)
{ {
app.modalDialog.type = MD_NONE; app.modalDialog.type = MD_NONE;
postBattle(); postBattle();
destroyBattle(); destroyBattle();
@ -415,7 +415,7 @@ static void optQuitBattle(void)
static void quitBattle(void) static void quitBattle(void)
{ {
app.modalDialog.type = MD_NONE; app.modalDialog.type = MD_NONE;
postBattle(); postBattle();
destroyBattle(); destroyBattle();
@ -441,13 +441,13 @@ static void postBattle(void)
game.stats[i] += battle.stats[i]; game.stats[i] += battle.stats[i];
} }
} }
game.stats[STAT_EPIC_KILL_STREAK] = MAX(game.stats[STAT_EPIC_KILL_STREAK], battle.stats[STAT_EPIC_KILL_STREAK]); game.stats[STAT_EPIC_KILL_STREAK] = MAX(game.stats[STAT_EPIC_KILL_STREAK], battle.stats[STAT_EPIC_KILL_STREAK]);
updateAccuracyStats(game.stats); updateAccuracyStats(game.stats);
game.currentMission->completed = (game.currentMission->completed || battle.status == MS_COMPLETE || !battle.numObjectivesTotal); game.currentMission->completed = (game.currentMission->completed || battle.status == MS_COMPLETE || !battle.numObjectivesTotal);
app.saveGame = 1; app.saveGame = 1;
} }
@ -456,11 +456,11 @@ static void checkSuspicionLevel(void)
if (battle.hasSuspicionLevel && battle.suspicionLevel >= MAX_SUSPICION_LEVEL) if (battle.hasSuspicionLevel && battle.suspicionLevel >= MAX_SUSPICION_LEVEL)
{ {
cancelScript(); cancelScript();
resetMessageBox(); resetMessageBox();
runScriptFunction("MAX_SUSPICION_LEVEL"); runScriptFunction("MAX_SUSPICION_LEVEL");
battle.hasSuspicionLevel = 0; battle.hasSuspicionLevel = 0;
} }
} }
@ -476,11 +476,11 @@ static void doTorelliFireStorm(void)
static void endCampaign(void) static void endCampaign(void)
{ {
awardTrophy("CAMPAIGN_COMPLETE"); awardTrophy("CAMPAIGN_COMPLETE");
postBattle(); postBattle();
destroyBattle(); destroyBattle();
initCredits(); initCredits();
} }
@ -567,7 +567,7 @@ void destroyBattle(void)
destroyBullets(); destroyBullets();
destroyEffects(); destroyEffects();
memset(&battle, 0, sizeof(Battle)); memset(&battle, 0, sizeof(Battle));
battle.bulletTail = &battle.bulletHead; battle.bulletTail = &battle.bulletHead;
battle.debrisTail = &battle.debrisHead; battle.debrisTail = &battle.debrisHead;

View File

@ -179,7 +179,7 @@ static void checkCollisions(Bullet *b)
{ {
battle.stats[STAT_ROCKETS_HIT]++; battle.stats[STAT_ROCKETS_HIT]++;
} }
if (battle.hasSuspicionLevel) if (battle.hasSuspicionLevel)
{ {
if (e->aiFlags & (AIF_AVOIDS_COMBAT|AIF_DEFENSIVE)) if (e->aiFlags & (AIF_AVOIDS_COMBAT|AIF_DEFENSIVE))
@ -192,14 +192,14 @@ static void checkCollisions(Bullet *b)
} }
} }
} }
if (e->flags & EF_IMMORTAL) if (e->flags & EF_IMMORTAL)
{ {
b->damage = 0; b->damage = 0;
} }
damageFighter(e, b->damage, b->flags); damageFighter(e, b->damage, b->flags);
doBulletHitEffect(b); doBulletHitEffect(b);
b->life = 0; b->life = 0;
@ -215,13 +215,13 @@ static void checkCollisions(Bullet *b)
battle.stats[STAT_MISSILES_STRUCK]++; battle.stats[STAT_MISSILES_STRUCK]++;
} }
} }
/* missile was targetting player, but hit something else */ /* missile was targetting player, but hit something else */
if (b->type == BT_MISSILE && b->target == player && e != player) if (b->type == BT_MISSILE && b->target == player && e != player)
{ {
battle.stats[STAT_MISSILES_EVADED]++; battle.stats[STAT_MISSILES_EVADED]++;
} }
if (b->type == BT_MISSILE && b->target != e) if (b->type == BT_MISSILE && b->target != e)
{ {
if (e == player) if (e == player)
@ -233,23 +233,23 @@ static void checkCollisions(Bullet *b)
awardTrophy("BODYGUARD"); awardTrophy("BODYGUARD");
} }
} }
/* assuming that health <= 0 will always mean killed */ /* assuming that health <= 0 will always mean killed */
if (e->health <= 0) if (e->health <= 0)
{ {
e->killedBy = b->owner; e->killedBy = b->owner;
if (e == player) if (e == player)
{ {
battle.lastKilledPlayer = b->owner; battle.lastKilledPlayer = b->owner;
} }
if (battle.isEpic && b->owner == player && e == battle.lastKilledPlayer) if (battle.isEpic && b->owner == player && e == battle.lastKilledPlayer)
{ {
awardTrophy("REVENGE"); awardTrophy("REVENGE");
} }
} }
if (b->owner == player && b->type == BT_MISSILE) if (b->owner == player && b->type == BT_MISSILE)
{ {
battle.stats[STAT_MISSILES_HIT]++; battle.stats[STAT_MISSILES_HIT]++;
@ -268,19 +268,19 @@ void doBulletHitEffect(Bullet *b)
case BT_PARTICLE: case BT_PARTICLE:
addBulletHitEffect(b->x, b->y, 255, 0, 255); addBulletHitEffect(b->x, b->y, 255, 0, 255);
break; break;
case BT_PLASMA: case BT_PLASMA:
addBulletHitEffect(b->x, b->y, 0, 255, 0); addBulletHitEffect(b->x, b->y, 0, 255, 0);
break; break;
case BT_LASER: case BT_LASER:
addBulletHitEffect(b->x, b->y, 255, 0, 0); addBulletHitEffect(b->x, b->y, 255, 0, 0);
break; break;
case BT_MAG: case BT_MAG:
addBulletHitEffect(b->x, b->y, 196, 196, 255); addBulletHitEffect(b->x, b->y, 196, 196, 255);
break; break;
default: default:
addBulletHitEffect(b->x, b->y, 255, 255, 255); addBulletHitEffect(b->x, b->y, 255, 255, 255);
break; break;
@ -291,7 +291,7 @@ void drawBullets(void)
{ {
int i; int i;
Bullet *b; Bullet *b;
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
for (i = 0, b = bulletsToDraw[i] ; b != NULL ; b = bulletsToDraw[++i]) for (i = 0, b = bulletsToDraw[i] ; b != NULL ; b = bulletsToDraw[++i])
@ -303,7 +303,7 @@ void drawBullets(void)
static void faceTarget(Bullet *b) static void faceTarget(Bullet *b)
{ {
int dir, wantedAngle, dist; int dir, wantedAngle, dist;
wantedAngle = (int)getAngle(b->x, b->y, b->target->x, b->target->y) % 360; wantedAngle = (int)getAngle(b->x, b->y, b->target->x, b->target->y) % 360;
if (abs(wantedAngle - b->angle) > TURN_THRESHOLD) if (abs(wantedAngle - b->angle) > TURN_THRESHOLD)
@ -311,23 +311,23 @@ static void faceTarget(Bullet *b)
dir = (wantedAngle - b->angle + 360) % 360 > 180 ? -1 : 1; dir = (wantedAngle - b->angle + 360) % 360 > 180 ? -1 : 1;
b->angle += dir * TURN_SPEED; b->angle += dir * TURN_SPEED;
dist = getDistance(b->x, b->y, b->target->x, b->target->y); dist = getDistance(b->x, b->y, b->target->x, b->target->y);
if (dist < 250) if (dist < 250)
{ {
dist = 250 - dist; dist = 250 - dist;
while (dist > 0) while (dist > 0)
{ {
b->angle += dir; b->angle += dir;
dist -= 50; dist -= 50;
} }
} }
b->angle = mod(b->angle, 360); b->angle = mod(b->angle, 360);
b->dx *= 0.5; b->dx *= 0.5;
b->dy *= 0.5; b->dy *= 0.5;
} }
@ -378,29 +378,29 @@ static void selectNewTarget(Bullet *b)
{ {
int i; int i;
Entity *e, **candidates; Entity *e, **candidates;
if (app.gameplay.missileReTarget) if (app.gameplay.missileReTarget)
{ {
b->target = NULL; b->target = NULL;
candidates = getAllEntsInRadius(b->x, b->y, SCREEN_HEIGHT, NULL); candidates = getAllEntsInRadius(b->x, b->y, SCREEN_HEIGHT, NULL);
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
{ {
if (e->type == ET_FIGHTER && e->side != b->owner->side && e->health > 0) if (e->type == ET_FIGHTER && e->side != b->owner->side && e->health > 0)
{ {
b->target = e; b->target = e;
if (b->target == player) if (b->target == player)
{ {
playSound(SND_INCOMING); playSound(SND_INCOMING);
} }
return; return;
} }
} }
} }
/* no target, just explode */ /* no target, just explode */
b->life = 0; b->life = 0;
addMissileExplosion(b); addMissileExplosion(b);
@ -438,7 +438,7 @@ void fireGuns(Entity *owner)
int i; int i;
float x, y; float x, y;
float c, s; float c, s;
b = NULL; b = NULL;
for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++) for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++)
@ -492,7 +492,7 @@ void fireMissile(Entity *owner)
Bullet *b; Bullet *b;
b = createBullet(BT_MISSILE, owner->x, owner->y, owner); b = createBullet(BT_MISSILE, owner->x, owner->y, owner);
b->dx *= 0.5; b->dx *= 0.5;
b->dy *= 0.5; b->dy *= 0.5;

View File

@ -87,7 +87,7 @@ void doCapitalShip(void)
if (self->alive == ALIVE_ALIVE) if (self->alive == ALIVE_ALIVE)
{ {
handleDisabled(); handleDisabled();
if (self->health <= 0) if (self->health <= 0)
{ {
self->health = 0; self->health = 0;
@ -111,7 +111,7 @@ void doCapitalShip(void)
runScriptFunction("CAPITAL_SHIPS_DESTROYED %d", battle.stats[STAT_CAPITAL_SHIPS_DESTROYED]); runScriptFunction("CAPITAL_SHIPS_DESTROYED %d", battle.stats[STAT_CAPITAL_SHIPS_DESTROYED]);
} }
runScriptFunction(self->name); runScriptFunction(self->name);
} }
} }
@ -243,7 +243,7 @@ static int steer(void)
static void gunThink(void) static void gunThink(void)
{ {
doAI(); doAI();
handleDisabled(); handleDisabled();
} }
@ -259,7 +259,7 @@ static void componentDie(void)
if (self->owner->health > 0) if (self->owner->health > 0)
{ {
runScriptFunction("CAP_HEALTH %s %d", self->owner->name, self->owner->health); runScriptFunction("CAP_HEALTH %s %d", self->owner->name, self->owner->health);
if (self->side != SIDE_PANDORAN && self->side == player->side) if (self->side != SIDE_PANDORAN && self->side == player->side)
{ {
issueDamageMessage(self->owner); issueDamageMessage(self->owner);
@ -270,12 +270,12 @@ static void componentDie(void)
static void gunDie(void) static void gunDie(void)
{ {
Entity *e; Entity *e;
self->alive = ALIVE_DEAD; self->alive = ALIVE_DEAD;
addSmallExplosion(); addSmallExplosion();
playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y); playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y);
addDebris(self->x, self->y, 3 + rand() % 4); addDebris(self->x, self->y, 3 + rand() % 4);
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (e != self && e->health > 0 && e->owner == self->owner && e->type == ET_COMPONENT_GUN) if (e != self && e->health > 0 && e->owner == self->owner && e->type == ET_COMPONENT_GUN)
@ -283,14 +283,14 @@ static void gunDie(void)
return; return;
} }
} }
runScriptFunction("CAP_GUNS_DESTROYED %s", self->owner->name); runScriptFunction("CAP_GUNS_DESTROYED %s", self->owner->name);
if (self->side != SIDE_PANDORAN && self->side == player->side) if (self->side != SIDE_PANDORAN && self->side == player->side)
{ {
issueGunsDestroyedMessage(self->owner); issueGunsDestroyedMessage(self->owner);
} }
if (--self->owner->systemPower == 1) if (--self->owner->systemPower == 1)
{ {
disable(); disable();
@ -300,7 +300,7 @@ static void gunDie(void)
static void engineThink(void) static void engineThink(void)
{ {
handleDisabled(); handleDisabled();
addLargeEngineEffect(); addLargeEngineEffect();
} }
@ -329,13 +329,13 @@ static void engineDie(void)
self->owner->dx = self->owner->dy = 0; self->owner->dx = self->owner->dy = 0;
runScriptFunction("CAP_ENGINES_DESTROYED %s", self->owner->name); runScriptFunction("CAP_ENGINES_DESTROYED %s", self->owner->name);
if (self->side != SIDE_PANDORAN && self->side == player->side) if (self->side != SIDE_PANDORAN && self->side == player->side)
{ {
issueEnginesDestroyedMessage(self->owner); issueEnginesDestroyedMessage(self->owner);
} }
} }
if (--self->owner->systemPower == 1) if (--self->owner->systemPower == 1)
{ {
disable(); disable();
@ -347,11 +347,11 @@ static void die(void)
Entity *e; Entity *e;
self->alive = ALIVE_DEAD; self->alive = ALIVE_DEAD;
playBattleSound(SND_CAP_DEATH, self->x, self->y); playBattleSound(SND_CAP_DEATH, self->x, self->y);
addLargeExplosion(); addLargeExplosion();
addDebris(self->x, self->y, 12); addDebris(self->x, self->y, 12);
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
@ -364,7 +364,7 @@ static void die(void)
updateObjective(self->name, TT_DESTROY); updateObjective(self->name, TT_DESTROY);
updateObjective(self->groupName, TT_DESTROY); updateObjective(self->groupName, TT_DESTROY);
updateCondition(self->name, TT_DESTROY); updateCondition(self->name, TT_DESTROY);
updateCondition(self->groupName, TT_DESTROY); updateCondition(self->groupName, TT_DESTROY);
} }
@ -384,9 +384,9 @@ static void handleDisabled(void)
static void disable(void) static void disable(void)
{ {
Entity *e; Entity *e;
runScriptFunction("CAP_DISABLED %s", self->owner->name); runScriptFunction("CAP_DISABLED %s", self->owner->name);
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (e->owner == self->owner || e == self->owner) if (e->owner == self->owner || e == self->owner)
@ -395,7 +395,7 @@ static void disable(void)
e->flags |= EF_DISABLED; e->flags |= EF_DISABLED;
} }
} }
updateObjective(self->owner->name, TT_DISABLE); updateObjective(self->owner->name, TT_DISABLE);
updateObjective(self->owner->groupName, TT_DISABLE); updateObjective(self->owner->groupName, TT_DISABLE);
} }
@ -631,7 +631,7 @@ static void loadEngines(Entity *parent, cJSON *engines)
void updateCapitalShipComponentProperties(Entity *parent, long flags) void updateCapitalShipComponentProperties(Entity *parent, long flags)
{ {
Entity *e; Entity *e;
if (flags != -1) if (flags != -1)
{ {
flags &= ~EF_AI_LEADER; flags &= ~EF_AI_LEADER;
@ -645,7 +645,7 @@ void updateCapitalShipComponentProperties(Entity *parent, long flags)
{ {
e->flags |= flags; e->flags |= flags;
} }
switch (e->type) switch (e->type)
{ {
case ET_COMPONENT_ENGINE: case ET_COMPONENT_ENGINE:
@ -743,9 +743,9 @@ void loadCapitalShips(cJSON *node)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
} }
} }
updateCapitalShipComponentProperties(e, flags); updateCapitalShipComponentProperties(e, flags);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "%s (%d / %d)", e->name, e->health, e->maxHealth); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "%s (%d / %d)", e->name, e->health, e->maxHealth);
} }

View File

@ -48,9 +48,9 @@ void doEffects(void)
int i, onScreen; int i, onScreen;
Effect *e; Effect *e;
Effect *prev = &battle.effectHead; Effect *prev = &battle.effectHead;
i = 0; i = 0;
memset(effectsToDraw, 0, sizeof(Effect*) * drawCapacity); memset(effectsToDraw, 0, sizeof(Effect*) * drawCapacity);
for (e = battle.effectHead.next ; e != NULL ; e = e->next) for (e = battle.effectHead.next ; e != NULL ; e = e->next)
@ -79,22 +79,22 @@ void doEffects(void)
else else
{ {
onScreen = 0; onScreen = 0;
switch (e->type) switch (e->type)
{ {
case EFFECT_LINE: case EFFECT_LINE:
onScreen = pointOnScreen(e->x - battle.camera.x, e->y - battle.camera.y) || pointOnScreen(e->x + (e->dx * 3) - battle.camera.x, e->y + (e->dy * 3) - battle.camera.y); onScreen = pointOnScreen(e->x - battle.camera.x, e->y - battle.camera.y) || pointOnScreen(e->x + (e->dx * 3) - battle.camera.x, e->y + (e->dy * 3) - battle.camera.y);
break; break;
case EFFECT_POINT: case EFFECT_POINT:
onScreen = pointOnScreen(e->x - battle.camera.x, e->y - battle.camera.y); onScreen = pointOnScreen(e->x - battle.camera.x, e->y - battle.camera.y);
break; break;
default: default:
onScreen = isOnBattleScreen(e->x, e->y, e->size, e->size); onScreen = isOnBattleScreen(e->x, e->y, e->size, e->size);
break; break;
} }
if (onScreen) if (onScreen)
{ {
effectsToDraw[i++] = e; effectsToDraw[i++] = e;
@ -124,7 +124,7 @@ static void resizeDrawList(void)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing effect draw capacity: %d -> %d", drawCapacity, n); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing effect draw capacity: %d -> %d", drawCapacity, n);
effectsToDraw = resize(effectsToDraw, sizeof(Effect*) * drawCapacity, sizeof(Effect*) * n); effectsToDraw = resize(effectsToDraw, sizeof(Effect*) * drawCapacity, sizeof(Effect*) * n);
drawCapacity = n; drawCapacity = n;
} }
@ -169,20 +169,20 @@ void drawEffects(void)
blitScaled(e->texture, app.winWidth / 2 - (e->size / 2), app.winHeight / 2 - (e->size / 2), e->size, e->size, 0); blitScaled(e->texture, app.winWidth / 2 - (e->size / 2), app.winHeight / 2 - (e->size / 2), e->size, e->size, 0);
break; break;
} }
if (e->texture != NULL) if (e->texture != NULL)
{ {
SDL_SetTextureBlendMode(e->texture->texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(e->texture->texture, SDL_BLENDMODE_BLEND);
} }
} }
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
} }
void drawShieldHitEffect(Entity *e) void drawShieldHitEffect(Entity *e)
{ {
int size = MAX(e->w, e->h) + 32; int size = MAX(e->w, e->h) + 32;
SDL_SetTextureBlendMode(shieldHitTexture->texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(shieldHitTexture->texture, SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(shieldHitTexture->texture, e->shieldHit); SDL_SetTextureAlphaMod(shieldHitTexture->texture, e->shieldHit);
blitScaled(shieldHitTexture, e->x - battle.camera.x, e->y - battle.camera.y, size, size, 1); blitScaled(shieldHitTexture, e->x - battle.camera.x, e->y - battle.camera.y, size, size, 1);
@ -192,7 +192,7 @@ void addBulletHitEffect(int x, int y, int r, int g, int b)
{ {
Effect *e; Effect *e;
int i; int i;
for (i = 0 ; i < 4 ; i++) for (i = 0 ; i < 4 ; i++)
{ {
e = malloc(sizeof(Effect)); e = malloc(sizeof(Effect));
@ -205,7 +205,7 @@ void addBulletHitEffect(int x, int y, int r, int g, int b)
e->size = 16; e->size = 16;
e->x = x; e->x = x;
e->y = y; e->y = y;
e->dx = (rand() % 25) - (rand() % 25); e->dx = (rand() % 25) - (rand() % 25);
e->dx *= 0.01; e->dx *= 0.01;
e->dy = (rand() % 25) - (rand() % 25); e->dy = (rand() % 25) - (rand() % 25);
@ -406,7 +406,7 @@ void addLargeExplosion(void)
e->x -= e->size / 2; e->x -= e->size / 2;
e->y -= e->size / 2; e->y -= e->size / 2;
} }
e = malloc(sizeof(Effect)); e = malloc(sizeof(Effect));
memset(e, 0, sizeof(Effect)); memset(e, 0, sizeof(Effect));
@ -603,7 +603,7 @@ void addShieldSplinterEffect(Entity *ent)
e->dy = rand() % 64 - rand() % 64; e->dy = rand() % 64 - rand() % 64;
e->dy *= 0.1; e->dy *= 0.1;
e->a = 255; e->a = 255;
e->health = e->a; e->health = e->a;
setRandomShieldHue(e); setRandomShieldHue(e);

View File

@ -84,7 +84,7 @@ void doEntities(void)
e->health = e->maxHealth; e->health = e->maxHealth;
e->shield = e->maxShield; e->shield = e->maxShield;
} }
if (e->active) if (e->active)
{ {
self = e; self = e;
@ -149,19 +149,19 @@ void doEntities(void)
e->action(); e->action();
} }
} }
doRope(e); doRope(e);
restrictToBattleArea(e); restrictToBattleArea(e);
if (!e->speed) if (!e->speed)
{ {
e->dx = e->dy = 0; e->dx = e->dy = 0;
} }
e->x += e->dx; e->x += e->dx;
e->y += e->dy; e->y += e->dy;
addToQuadtree(e, &battle.quadtree); addToQuadtree(e, &battle.quadtree);
} }
else else
@ -175,7 +175,7 @@ void doEntities(void)
{ {
battle.missionTarget = NULL; battle.missionTarget = NULL;
} }
if (e->killedBy == player && battle.hasSuspicionLevel) if (e->killedBy == player && battle.hasSuspicionLevel)
{ {
if (e->aiFlags & (AIF_AVOIDS_COMBAT|AIF_DEFENSIVE)) if (e->aiFlags & (AIF_AVOIDS_COMBAT|AIF_DEFENSIVE))
@ -196,12 +196,12 @@ void doEntities(void)
cutRope(e); cutRope(e);
prev->next = e->next; prev->next = e->next;
e->next = NULL; e->next = NULL;
deadTail->next = e; deadTail->next = e;
deadTail = e; deadTail = e;
/* actually just creates another fighter in this one's place */ /* actually just creates another fighter in this one's place */
if (e->type == ET_FIGHTER && battle.isEpic && e->side != player->side && battle.unlimitedEnemies) if (e->type == ET_FIGHTER && battle.isEpic && e->side != player->side && battle.unlimitedEnemies)
{ {
@ -230,13 +230,13 @@ void doEntities(void)
if (e->health > 0 && e->active) if (e->health > 0 && e->active)
{ {
numActiveEnemies++; numActiveEnemies++;
if (e->spawned) if (e->spawned)
{ {
numSpawnedEnemies++; numSpawnedEnemies++;
} }
} }
if (!(e->flags & EF_DISABLED) || battle.isEpic) if (!(e->flags & EF_DISABLED) || battle.isEpic)
{ {
battle.hasThreats = 1; battle.hasThreats = 1;
@ -249,7 +249,7 @@ void doEntities(void)
battle.numAllies = (battle.isEpic) ? numAllies : numActiveAllies; battle.numAllies = (battle.isEpic) ? numAllies : numActiveAllies;
battle.numEnemies = (battle.isEpic) ? numEnemies : numActiveEnemies; battle.numEnemies = (battle.isEpic) ? numEnemies : numActiveEnemies;
if (battle.status == MS_IN_PROGRESS && battle.stats[STAT_TIME] % (FPS * 30) == 0) if (battle.status == MS_IN_PROGRESS && battle.stats[STAT_TIME] % (FPS * 30) == 0)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "numEnemies=%d, numActiveEnemies=%d, hasThreats=%d", numEnemies, numActiveEnemies, battle.hasThreats); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "numEnemies=%d, numActiveEnemies=%d, hasThreats=%d", numEnemies, numActiveEnemies, battle.hasThreats);
@ -261,7 +261,7 @@ void doEntities(void)
{ {
activateEpicFighters(SIDE_ALLIES); activateEpicFighters(SIDE_ALLIES);
} }
numActiveEnemies -= numSpawnedEnemies; numActiveEnemies -= numSpawnedEnemies;
if (numActiveEnemies < battle.epicFighterLimit) if (numActiveEnemies < battle.epicFighterLimit)
@ -357,7 +357,7 @@ static void alignComponents(void)
if (isComponent(e)) if (isComponent(e))
{ {
removeFromQuadtree(e, &battle.quadtree); removeFromQuadtree(e, &battle.quadtree);
s = sin(TO_RAIDANS(e->owner->angle)); s = sin(TO_RAIDANS(e->owner->angle));
c = cos(TO_RAIDANS(e->owner->angle)); c = cos(TO_RAIDANS(e->owner->angle));
@ -389,12 +389,12 @@ void drawEntities(void)
{ {
int i; int i;
Entity *e, **candidates; Entity *e, **candidates;
candidates = getAllEntsWithin(battle.camera.x, battle.camera.y, app.winWidth, app.winHeight, NULL); candidates = getAllEntsWithin(battle.camera.x, battle.camera.y, app.winWidth, app.winHeight, NULL);
/* counting entities to draw */ /* counting entities to draw */
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) {}; for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) {};
qsort(candidates, i, sizeof(Entity*), drawComparator); qsort(candidates, i, sizeof(Entity*), drawComparator);
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
@ -409,11 +409,11 @@ void drawEntities(void)
{ {
drawEntity(e); drawEntity(e);
} }
drawHealthBar(e); drawHealthBar(e);
drawTargetRects(e); drawTargetRects(e);
drawRope(e); drawRope(e);
} }
} }
@ -448,14 +448,14 @@ static void drawEntity(Entity *e)
static void drawHealthBar(Entity *e) static void drawHealthBar(Entity *e)
{ {
SDL_Rect r; SDL_Rect r;
if (app.gameplay.healthBars && !(e->flags & EF_NO_HEALTH_BAR) && e->health > 0) if (app.gameplay.healthBars && !(e->flags & EF_NO_HEALTH_BAR) && e->health > 0)
{ {
r.x = e->x - (e->w / 2) - battle.camera.x; r.x = e->x - (e->w / 2) - battle.camera.x;
r.y = e->y - e->h - battle.camera.y; r.y = e->y - e->h - battle.camera.y;
r.w = 32; r.w = 32;
r.h = 1; r.h = 1;
if (e->side == player->side || e->flags & EF_FRIENDLY_HEALTH_BAR) if (e->side == player->side || e->flags & EF_FRIENDLY_HEALTH_BAR)
{ {
SDL_SetRenderDrawColor(app.renderer, 0, 128, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 128, 0, 255);
@ -464,11 +464,11 @@ static void drawHealthBar(Entity *e)
{ {
SDL_SetRenderDrawColor(app.renderer, 128, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 128, 0, 0, 255);
} }
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
r.w = 32 * (e->health * 1.0f / e->maxHealth); r.w = 32 * (e->health * 1.0f / e->maxHealth);
if (e->side == player->side || e->flags & EF_FRIENDLY_HEALTH_BAR) if (e->side == player->side || e->flags & EF_FRIENDLY_HEALTH_BAR)
{ {
SDL_SetRenderDrawColor(app.renderer, 0, 255, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 255, 0, 255);
@ -477,7 +477,7 @@ static void drawHealthBar(Entity *e)
{ {
SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255);
} }
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
} }
} }
@ -509,7 +509,7 @@ static void drawTargetRects(Entity *e)
SDL_SetRenderDrawColor(app.renderer, 0, 255, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 255, 0, 255);
SDL_RenderDrawRect(app.renderer, &r); SDL_RenderDrawRect(app.renderer, &r);
} }
if (e == battle.messageSpeaker && e != player && battle.stats[STAT_TIME] % 40 < 20) if (e == battle.messageSpeaker && e != player && battle.stats[STAT_TIME] % 40 < 20)
{ {
r.x = e->x - (size / 2) - battle.camera.x; r.x = e->x - (size / 2) - battle.camera.x;
@ -564,9 +564,9 @@ void activateEntityGroups(char *groupNames)
if (strcmp(e->groupName, groupName) == 0) if (strcmp(e->groupName, groupName) == 0)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Activated %s (%s)", e->name, groupName); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Activated %s (%s)", e->name, groupName);
e->active = 1; e->active = 1;
if (e->type == ET_CAPITAL_SHIP) if (e->type == ET_CAPITAL_SHIP)
{ {
updateCapitalShipComponentProperties(e, 0); updateCapitalShipComponentProperties(e, 0);
@ -600,23 +600,23 @@ static void notifyNewArrivals(void)
static void activateEpicFighters(int side) static void activateEpicFighters(int side)
{ {
Entity *e; Entity *e;
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (!e->active && e->type == ET_FIGHTER && !(e->flags & EF_NO_EPIC) && ((side == SIDE_ALLIES && e->side == SIDE_ALLIES) || (side != SIDE_ALLIES && e->side != SIDE_ALLIES))) if (!e->active && e->type == ET_FIGHTER && !(e->flags & EF_NO_EPIC) && ((side == SIDE_ALLIES && e->side == SIDE_ALLIES) || (side != SIDE_ALLIES && e->side != SIDE_ALLIES)))
{ {
e->active = 1; e->active = 1;
/* don't spring into existence in front of the player */ /* don't spring into existence in front of the player */
if (isOnBattleScreen(e->x, e->y, e->w, e->h)) if (isOnBattleScreen(e->x, e->y, e->w, e->h))
{ {
e->x = player->x; e->x = player->x;
e->y = player->y; e->y = player->y;
e->x += (rand() % 2) ? -app.winWidth : app.winWidth; e->x += (rand() % 2) ? -app.winWidth : app.winWidth;
e->y += (rand() % 2) ? -app.winHeight : app.winHeight; e->y += (rand() % 2) ? -app.winHeight : app.winHeight;
} }
return; return;
} }
} }
@ -640,7 +640,7 @@ void countNumEnemies(void)
void addAllToQuadtree(void) void addAllToQuadtree(void)
{ {
Entity *e; Entity *e;
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (e->active) if (e->active)
@ -661,14 +661,14 @@ static int drawComparator(const void *a, const void *b)
void killEntity(char *name) void killEntity(char *name)
{ {
Entity *e; Entity *e;
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (strcmp(e->name, name) == 0) if (strcmp(e->name, name) == 0)
{ {
e->health = 0; e->health = 0;
e->deathType = DT_INSTANT; e->deathType = DT_INSTANT;
/* prevent objectives and conditions from firing */ /* prevent objectives and conditions from firing */
strcpy(e->name, ""); strcpy(e->name, "");
strcpy(e->groupName, ""); strcpy(e->groupName, "");
@ -680,15 +680,15 @@ void updateEntitySide(char *sideStr, char *name)
{ {
Entity *e; Entity *e;
int side; int side;
side = lookup(sideStr); side = lookup(sideStr);
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (strcmp(e->name, name) == 0) if (strcmp(e->name, name) == 0)
{ {
e->side = side; e->side = side;
if (e->side != player->side) if (e->side != player->side)
{ {
e->flags |= EF_MISSION_TARGET; e->flags |= EF_MISSION_TARGET;
@ -700,7 +700,7 @@ void updateEntitySide(char *sideStr, char *name)
void awardPandoranCraftTrophy(void) void awardPandoranCraftTrophy(void)
{ {
Entity *e; Entity *e;
for (e = deadHead.next ; e != NULL ; e = e->next) for (e = deadHead.next ; e != NULL ; e = e->next)
{ {
if (e->killedBy == player && e->side == SIDE_PANDORAN) if (e->killedBy == player && e->side == SIDE_PANDORAN)

View File

@ -97,7 +97,7 @@ Entity *spawnFighter(char *name, int x, int y, int side)
e->action = doAI; e->action = doAI;
e->die = die; e->die = die;
if (game.currentMission->challengeData.isDeathMatch) if (game.currentMission->challengeData.isDeathMatch)
{ {
e->side = SDL_GetTicks(); e->side = SDL_GetTicks();
@ -193,14 +193,14 @@ static void randomizeDartGuns(Entity *dart)
void resetFighter(Entity *fighter) void resetFighter(Entity *fighter)
{ {
Entity *e; Entity *e;
e = spawnFighter(fighter->defName, fighter->x, fighter->y, fighter->side); e = spawnFighter(fighter->defName, fighter->x, fighter->y, fighter->side);
e->x += (rand() % 7500) - (rand() % 7500); e->x += (rand() % 7500) - (rand() % 7500);
e->y += (rand() % 7500) - (rand() % 7500); e->y += (rand() % 7500) - (rand() % 7500);
e->active = 0; e->active = 0;
if (rand() % 4) if (rand() % 4)
{ {
e->aiFlags |= AIF_TARGET_FOCUS; e->aiFlags |= AIF_TARGET_FOCUS;
@ -251,7 +251,7 @@ void doFighter(void)
self->flags |= EF_DISABLED; self->flags |= EF_DISABLED;
self->flags |= EF_SECONDARY_TARGET; self->flags |= EF_SECONDARY_TARGET;
if (self->aiFlags & AIF_SURRENDERING) if (self->aiFlags & AIF_SURRENDERING)
{ {
self->aiFlags |= AIF_SURRENDERED; self->aiFlags |= AIF_SURRENDERED;
@ -262,7 +262,7 @@ void doFighter(void)
updateObjective(self->name, TT_DISABLE); updateObjective(self->name, TT_DISABLE);
updateObjective(self->groupName, TT_DISABLE); updateObjective(self->groupName, TT_DISABLE);
if (self->side != player->side) if (self->side != player->side)
{ {
runScriptFunction("ENEMIES_DISABLED %d", battle.stats[STAT_ENEMIES_DISABLED]); runScriptFunction("ENEMIES_DISABLED %d", battle.stats[STAT_ENEMIES_DISABLED]);
@ -279,12 +279,12 @@ void doFighter(void)
self->action = doAI; self->action = doAI;
} }
} }
if (self->aiFlags & AIF_SUSPICIOUS) if (self->aiFlags & AIF_SUSPICIOUS)
{ {
checkSuspicionLevel(); checkSuspicionLevel();
} }
if (self->aiFlags & AIF_ZAK_SUSPICIOUS) if (self->aiFlags & AIF_ZAK_SUSPICIOUS)
{ {
checkZackariaSuspicionLevel(); checkZackariaSuspicionLevel();
@ -296,7 +296,7 @@ void doFighter(void)
if (self == player && !game.currentMission->challengeData.isChallenge) if (self == player && !game.currentMission->challengeData.isChallenge)
{ {
updateObjective("Player", TT_ESCAPED); updateObjective("Player", TT_ESCAPED);
completeMission(); completeMission();
} }
@ -346,7 +346,7 @@ void doFighter(void)
{ {
addHudMessage(colors.red, _("Civilian has been killed")); addHudMessage(colors.red, _("Civilian has been killed"));
} }
runScriptFunction("CIVILIANS_KILLED %d", battle.stats[STAT_CIVILIANS_KILLED]); runScriptFunction("CIVILIANS_KILLED %d", battle.stats[STAT_CIVILIANS_KILLED]);
} }
else else
@ -360,10 +360,10 @@ void doFighter(void)
runScriptFunction("ALLIES_KILLED %d", battle.stats[STAT_ALLIES_KILLED]); runScriptFunction("ALLIES_KILLED %d", battle.stats[STAT_ALLIES_KILLED]);
} }
} }
updateObjective(self->name, TT_DESTROY); updateObjective(self->name, TT_DESTROY);
updateObjective(self->groupName, TT_DESTROY); updateObjective(self->groupName, TT_DESTROY);
if (battle.isEpic && self->killedBy == player) if (battle.isEpic && self->killedBy == player)
{ {
updateObjective("EPIC_PLAYER_KILLS", TT_DESTROY); updateObjective("EPIC_PLAYER_KILLS", TT_DESTROY);
@ -373,7 +373,7 @@ void doFighter(void)
updateCondition(self->name, TT_DESTROY); updateCondition(self->name, TT_DESTROY);
updateCondition(self->groupName, TT_DESTROY); updateCondition(self->groupName, TT_DESTROY);
/* don't fire if the opposing side is responsible */ /* don't fire if the opposing side is responsible */
if (self->aiFlags & AIF_SURRENDERED && self->killedBy->side == player->side) if (self->aiFlags & AIF_SURRENDERED && self->killedBy->side == player->side)
{ {
@ -461,21 +461,21 @@ void damageFighter(Entity *e, int amount, long flags)
e->aiDamageTimer = FPS; e->aiDamageTimer = FPS;
e->aiDamagePerSec += amount; e->aiDamagePerSec += amount;
if (flags & BF_SYSTEM_DAMAGE) if (flags & BF_SYSTEM_DAMAGE)
{ {
if (e->shield > 0) if (e->shield > 0)
{ {
amount /= 2; amount /= 2;
e->shield -= amount; e->shield -= amount;
if (e->shield < 0) if (e->shield < 0)
{ {
amount = -e->shield; amount = -e->shield;
} }
} }
if (amount >= 0) if (amount >= 0)
{ {
e->systemPower = MAX(0, e->systemPower - amount); e->systemPower = MAX(0, e->systemPower - amount);
@ -487,7 +487,7 @@ void damageFighter(Entity *e, int amount, long flags)
e->shield = e->maxShield = 0; e->shield = e->maxShield = 0;
e->action = NULL; e->action = NULL;
} }
playBattleSound(SND_MAG_HIT, e->x, e->y); playBattleSound(SND_MAG_HIT, e->x, e->y);
} }
} }
@ -509,13 +509,13 @@ void damageFighter(Entity *e, int amount, long flags)
if (e->shield > 0) if (e->shield > 0)
{ {
e->shield -= amount; e->shield -= amount;
if (e->shield <= 0) if (e->shield <= 0)
{ {
e->armourHit = 255; e->armourHit = 255;
e->health += e->shield; e->health += e->shield;
e->shield = 0; e->shield = 0;
playBattleSound(SND_ARMOUR_HIT, e->x, e->y); playBattleSound(SND_ARMOUR_HIT, e->x, e->y);
} }
} }
@ -534,7 +534,7 @@ void damageFighter(Entity *e, int amount, long flags)
playBattleSound(SND_SHIELD_HIT, e->x, e->y); playBattleSound(SND_SHIELD_HIT, e->x, e->y);
} }
/* don't allow the shield to recharge immediately after taking a hit */ /* don't allow the shield to recharge immediately after taking a hit */
e->shieldRecharge = e->shieldRechargeRate; e->shieldRecharge = e->shieldRechargeRate;
@ -596,22 +596,22 @@ static void die(void)
self->action = simpleDie; self->action = simpleDie;
break; break;
} }
if (self->killedBy == player && (!(self->flags & EF_NO_KILL_INC))) if (self->killedBy == player && (!(self->flags & EF_NO_KILL_INC)))
{ {
battle.stats[STAT_ENEMIES_KILLED_PLAYER]++; battle.stats[STAT_ENEMIES_KILLED_PLAYER]++;
if (self->flags & EF_COMMON_FIGHTER) if (self->flags & EF_COMMON_FIGHTER)
{ {
incFighterStat(self->defName); incFighterStat(self->defName);
} }
if (battle.isEpic && player->flags & EF_COMMON_FIGHTER) if (battle.isEpic && player->flags & EF_COMMON_FIGHTER)
{ {
battle.stats[STAT_EPIC_KILL_STREAK]++; battle.stats[STAT_EPIC_KILL_STREAK]++;
} }
} }
if (self->flags & EF_DROPS_ITEMS) if (self->flags & EF_DROPS_ITEMS)
{ {
addRandomItem(self->x, self->y); addRandomItem(self->x, self->y);
@ -688,14 +688,14 @@ void retreatEnemies(void)
if (e->type == ET_FIGHTER && e->side != player->side) if (e->type == ET_FIGHTER && e->side != player->side)
{ {
e->flags |= EF_RETREATING; e->flags |= EF_RETREATING;
e->aiFlags |= AIF_AVOIDS_COMBAT; e->aiFlags |= AIF_AVOIDS_COMBAT;
e->aiFlags |= AIF_UNLIMITED_RANGE; e->aiFlags |= AIF_UNLIMITED_RANGE;
e->aiFlags &= ~AIF_MOVES_TO_LEADER; e->aiFlags &= ~AIF_MOVES_TO_LEADER;
e->aiFlags &= ~AIF_WANDERS; e->aiFlags &= ~AIF_WANDERS;
e->aiActionTime = MIN(e->aiActionTime, FPS); e->aiActionTime = MIN(e->aiActionTime, FPS);
if (!game.currentMission->challengeData.isChallenge) if (!game.currentMission->challengeData.isChallenge)
{ {
e->aiFlags |= AIF_GOAL_JUMPGATE; e->aiFlags |= AIF_GOAL_JUMPGATE;
@ -720,9 +720,9 @@ void retreatAllies(void)
e->aiFlags &= ~AIF_MOVES_TO_PLAYER; e->aiFlags &= ~AIF_MOVES_TO_PLAYER;
e->aiFlags &= ~AIF_MOVES_TO_LEADER; e->aiFlags &= ~AIF_MOVES_TO_LEADER;
e->aiFlags &= ~AIF_WANDERS; e->aiFlags &= ~AIF_WANDERS;
e->aiActionTime = MIN(e->aiActionTime, FPS); e->aiActionTime = MIN(e->aiActionTime, FPS);
if (!game.currentMission->challengeData.isChallenge) if (!game.currentMission->challengeData.isChallenge)
{ {
e->aiFlags |= AIF_GOAL_JUMPGATE; e->aiFlags |= AIF_GOAL_JUMPGATE;
@ -751,7 +751,7 @@ Entity **getDBFighters(int *num)
{ {
Entity *e, **dbFighters; Entity *e, **dbFighters;
int i; int i;
i = *num = 0; i = *num = 0;
for (e = defHead.next ; e != NULL ; e = e->next) for (e = defHead.next ; e != NULL ; e = e->next)
@ -761,19 +761,19 @@ Entity **getDBFighters(int *num)
*num = *num + 1; *num = *num + 1;
} }
} }
dbFighters = malloc(sizeof(Entity*) * *num); dbFighters = malloc(sizeof(Entity*) * *num);
for (e = defHead.next ; e != NULL ; e = e->next) for (e = defHead.next ; e != NULL ; e = e->next)
{ {
if (e->description != NULL) if (e->description != NULL)
{ {
dbFighters[i] = e; dbFighters[i] = e;
i++; i++;
} }
} }
return dbFighters; return dbFighters;
} }
@ -839,7 +839,7 @@ static void loadFighterDef(char *filename)
e->reloadTime = getJSONValue(root, "reloadTime", 0); e->reloadTime = getJSONValue(root, "reloadTime", 0);
e->shieldRechargeRate = getJSONValue(root, "shieldRechargeRate", 0); e->shieldRechargeRate = getJSONValue(root, "shieldRechargeRate", 0);
e->texture = getAtlasImage(cJSON_GetObjectItem(root, "texture")->valuestring); e->texture = getAtlasImage(cJSON_GetObjectItem(root, "texture")->valuestring);
if (strlen(cJSON_GetObjectItem(root, "description")->valuestring) > 0) if (strlen(cJSON_GetObjectItem(root, "description")->valuestring) > 0)
{ {
len = strlen(_(cJSON_GetObjectItem(root, "description")->valuestring)) + 1; len = strlen(_(cJSON_GetObjectItem(root, "description")->valuestring)) + 1;
@ -890,7 +890,7 @@ static void loadFighterDef(char *filename)
{ {
e->deathType = lookup(cJSON_GetObjectItem(root, "deathType")->valuestring); e->deathType = lookup(cJSON_GetObjectItem(root, "deathType")->valuestring);
} }
if (e->flags & EF_COMMON_FIGHTER) if (e->flags & EF_COMMON_FIGHTER)
{ {
addFighterStat(e->name); addFighterStat(e->name);
@ -913,33 +913,33 @@ static void loadFighterDef(char *filename)
static void addFighterStat(char *key) static void addFighterStat(char *key)
{ {
Tuple *t, *tail; Tuple *t, *tail;
tail = &game.fighterStatHead; tail = &game.fighterStatHead;
for (t = game.fighterStatHead.next ; t != NULL ; t = t->next) for (t = game.fighterStatHead.next ; t != NULL ; t = t->next)
{ {
if (strcmp(t->key, key) == 0) if (strcmp(t->key, key) == 0)
{ {
return; return;
} }
tail = t; tail = t;
} }
t = malloc(sizeof(Tuple)); t = malloc(sizeof(Tuple));
memset(t, 0, sizeof(Tuple)); memset(t, 0, sizeof(Tuple));
tail->next = t; tail->next = t;
STRNCPY(t->key, key, MAX_NAME_LENGTH); STRNCPY(t->key, key, MAX_NAME_LENGTH);
t->value = 0; t->value = 0;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Added '%s' to fighter stats", key); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Added '%s' to fighter stats", key);
} }
static void incFighterStat(char *key) static void incFighterStat(char *key)
{ {
Tuple *t; Tuple *t;
for (t = game.fighterStatHead.next ; t != NULL ; t = t->next) for (t = game.fighterStatHead.next ; t != NULL ; t = t->next)
{ {
if (strcmp(t->key, key) == 0) if (strcmp(t->key, key) == 0)
@ -962,7 +962,7 @@ void loadFighters(cJSON *node)
if (node) if (node)
{ {
id = 0; id = 0;
node = node->child; node = node->child;
while (node) while (node)
@ -1018,7 +1018,7 @@ void loadFighters(cJSON *node)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName);
} }
if (e->flags & EF_DISABLED) if (e->flags & EF_DISABLED)
{ {
e->speed = 0; e->speed = 0;
@ -1042,10 +1042,10 @@ void loadFighters(cJSON *node)
if (name) if (name)
{ {
STRNCPY(e->name, name, MAX_NAME_LENGTH); STRNCPY(e->name, name, MAX_NAME_LENGTH);
/* update 'name #?' to 'name #1', etc. */ /* update 'name #?' to 'name #1', etc. */
strpos = strstr(e->name, "#?"); strpos = strstr(e->name, "#?");
if (strpos) if (strpos)
{ {
*(++strpos) = ('0' + ++id); *(++strpos) = ('0' + ++id);
@ -1078,12 +1078,12 @@ void destroyFighterDefs(void)
{ {
e = defHead.next; e = defHead.next;
defHead.next = e->next; defHead.next = e->next;
if (e->description) if (e->description)
{ {
free(e->description); free(e->description);
} }
free(e); free(e);
} }
} }
@ -1091,7 +1091,7 @@ void destroyFighterDefs(void)
void destroyFighterStats(void) void destroyFighterStats(void)
{ {
Tuple *t; Tuple *t;
while (game.fighterStatHead.next) while (game.fighterStatHead.next)
{ {
t = game.fighterStatHead.next; t = game.fighterStatHead.next;

View File

@ -68,7 +68,7 @@ void initHud(void)
{ {
memset(&hudMessageHead, 0, sizeof(HudMessage)); memset(&hudMessageHead, 0, sizeof(HudMessage));
hudMessageTail = &hudMessageHead; hudMessageTail = &hudMessageHead;
gunName[BT_NONE] = ""; gunName[BT_NONE] = "";
gunName[BT_PARTICLE] = _("Particle Cannon"); gunName[BT_PARTICLE] = _("Particle Cannon");
gunName[BT_PLASMA] = _("Plasma Cannon"); gunName[BT_PLASMA] = _("Plasma Cannon");
@ -76,7 +76,7 @@ void initHud(void)
gunName[BT_MAG] = _("Mag Cannon"); gunName[BT_MAG] = _("Mag Cannon");
gunName[BT_ROCKET] = _("Rockets"); gunName[BT_ROCKET] = _("Rockets");
gunName[BT_MISSILE] = _("Missiles"); gunName[BT_MISSILE] = _("Missiles");
MISSILES_TEXT = _("Missiles (%d)"); MISSILES_TEXT = _("Missiles (%d)");
TARGET_TEXT = _("Target: %.2fkm"); TARGET_TEXT = _("Target: %.2fkm");
NONE_TEXT = _("(None)"); NONE_TEXT = _("(None)");
@ -90,7 +90,7 @@ void initHud(void)
SUSPICION_TEXT = _("Suspicion"); SUSPICION_TEXT = _("Suspicion");
REMAINING_PILOTS_TEXT = _("Remaining Pilots: %d"); REMAINING_PILOTS_TEXT = _("Remaining Pilots: %d");
WARNING_TEXT = _("WARNING: INCOMING MISSILE!"); WARNING_TEXT = _("WARNING: INCOMING MISSILE!");
targetPointer = getAtlasImage("gfx/hud/targetPointer.png"); targetPointer = getAtlasImage("gfx/hud/targetPointer.png");
targetCircle = getAtlasImage("gfx/hud/targetCircle.png"); targetCircle = getAtlasImage("gfx/hud/targetCircle.png");
smallFighter = getAtlasImage("gfx/hud/smallFighter.png"); smallFighter = getAtlasImage("gfx/hud/smallFighter.png");
@ -108,31 +108,31 @@ void initHud(void)
void doHud(void) void doHud(void)
{ {
HudMessage *hudMessage, *prev; HudMessage *hudMessage, *prev;
numMessages = 0; numMessages = 0;
prev = &hudMessageHead; prev = &hudMessageHead;
for (hudMessage = hudMessageHead.next ; hudMessage != NULL ; hudMessage = hudMessage->next) for (hudMessage = hudMessageHead.next ; hudMessage != NULL ; hudMessage = hudMessage->next)
{ {
hudMessage->life--; hudMessage->life--;
numMessages++; numMessages++;
if (hudMessage->life <= 0) if (hudMessage->life <= 0)
{ {
if (hudMessage == hudMessageTail) if (hudMessage == hudMessageTail)
{ {
hudMessageTail = prev; hudMessageTail = prev;
} }
prev->next = hudMessage->next; prev->next = hudMessage->next;
free(hudMessage); free(hudMessage);
hudMessage = prev; hudMessage = prev;
numMessages--; numMessages--;
} }
prev = hudMessage; prev = hudMessage;
} }
} }
@ -140,7 +140,7 @@ void doHud(void)
void addHudMessage(SDL_Color c, char *format, ...) void addHudMessage(SDL_Color c, char *format, ...)
{ {
va_list args; va_list args;
HudMessage *hudMessage = malloc(sizeof(HudMessage)); HudMessage *hudMessage = malloc(sizeof(HudMessage));
memset(hudMessage, 0, sizeof(HudMessage)); memset(hudMessage, 0, sizeof(HudMessage));
hudMessageTail->next = hudMessage; hudMessageTail->next = hudMessage;
@ -149,18 +149,18 @@ void addHudMessage(SDL_Color c, char *format, ...)
va_start(args, format); va_start(args, format);
vsprintf(hudMessageTail->message, format, args); vsprintf(hudMessageTail->message, format, args);
va_end(args); va_end(args);
hudMessage->color = c; hudMessage->color = c;
hudMessage->life = FPS * 5; hudMessage->life = FPS * 5;
numMessages++; numMessages++;
while (numMessages > MAX_HUD_MESSAGES) while (numMessages > MAX_HUD_MESSAGES)
{ {
hudMessage = hudMessageHead.next; hudMessage = hudMessageHead.next;
hudMessageHead.next = hudMessage->next; hudMessageHead.next = hudMessage->next;
free(hudMessage); free(hudMessage);
numMessages--; numMessages--;
} }
} }
@ -170,30 +170,30 @@ void drawHud(void)
if (player->alive == ALIVE_ALIVE) if (player->alive == ALIVE_ALIVE)
{ {
drawHealthBars(); drawHealthBars();
drawAbilityBars(); drawAbilityBars();
drawPlayerTargeter(); drawPlayerTargeter();
drawWeaponInfo(); drawWeaponInfo();
drawNumFighters(); drawNumFighters();
drawObjectives(); drawObjectives();
drawDistancesInfo(); drawDistancesInfo();
drawRadar(); drawRadar();
drawRadarRangeWarning(); drawRadarRangeWarning();
drawMissileWarning(); drawMissileWarning();
drawSuspicionLevel(); drawSuspicionLevel();
} }
drawHudMessages(); drawHudMessages();
if (battle.playerSelect) if (battle.playerSelect)
{ {
drawPlayerSelect(); drawPlayerSelect();
@ -204,11 +204,11 @@ static void drawHealthBars(void)
{ {
float p; float p;
int r, g, b; int r, g, b;
r = g = b = 0; r = g = b = 0;
p = player->health; p = player->health;
p /= player->maxHealth; p /= player->maxHealth;
if (p <= 0.25) if (p <= 0.25)
{ {
r = 255; r = 255;
@ -222,12 +222,12 @@ static void drawHealthBars(void)
{ {
g = 200; g = 200;
} }
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
blit(armour, 6, 9, 0); blit(armour, 6, 9, 0);
drawHealthShieldBar(player->health, player->maxHealth, 30, 10, r, g, b, 1); drawHealthShieldBar(player->health, player->maxHealth, 30, 10, r, g, b, 1);
blit(shield, 6, 29, 0); blit(shield, 6, 29, 0);
drawHealthShieldBar(player->shield, player->maxShield, 30, 30, 0, 200, 255, 0); drawHealthShieldBar(player->shield, player->maxShield, 30, 30, 0, 200, 255, 0);
} }
@ -236,38 +236,38 @@ static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g
{ {
SDL_Rect rect; SDL_Rect rect;
float percent = 0; float percent = 0;
if (max > 0) if (max > 0)
{ {
percent = current; percent = current;
percent /= max; percent /= max;
if (flashLow && percent <= 0.25 && battle.stats[STAT_TIME] % FPS < 30) if (flashLow && percent <= 0.25 && battle.stats[STAT_TIME] % FPS < 30)
{ {
percent = 0; percent = 0;
} }
} }
rect.x = x; rect.x = x;
rect.y = y; rect.y = y;
rect.w = 250; rect.w = 250;
rect.h = 12; rect.h = 12;
SDL_SetRenderDrawColor(app.renderer, r / 2, g / 2, b / 2, 255); SDL_SetRenderDrawColor(app.renderer, r / 2, g / 2, b / 2, 255);
SDL_RenderFillRect(app.renderer, &rect); SDL_RenderFillRect(app.renderer, &rect);
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
SDL_RenderDrawRect(app.renderer, &rect); SDL_RenderDrawRect(app.renderer, &rect);
if (current > 0) if (current > 0)
{ {
rect.x += 2; rect.x += 2;
rect.y += 2; rect.y += 2;
rect.w -= 4; rect.w -= 4;
rect.h -= 4; rect.h -= 4;
rect.w *= percent; rect.w *= percent;
SDL_SetRenderDrawColor(app.renderer, r, g, b, 255); SDL_SetRenderDrawColor(app.renderer, r, g, b, 255);
SDL_RenderFillRect(app.renderer, &rect); SDL_RenderFillRect(app.renderer, &rect);
} }
@ -276,10 +276,10 @@ static void drawHealthShieldBar(int current, int max, int x, int y, int r, int g
static void drawAbilityBars(void) static void drawAbilityBars(void)
{ {
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
blit(boost, 6, 49, 0); blit(boost, 6, 49, 0);
drawBoostECMBar(battle.boostTimer, BOOST_RECHARGE_TIME, 30, 50, 128, 128, 255); drawBoostECMBar(battle.boostTimer, BOOST_RECHARGE_TIME, 30, 50, 128, 128, 255);
blit(ecm, 155, 49, 0); blit(ecm, 155, 49, 0);
drawBoostECMBar(battle.ecmTimer, ECM_RECHARGE_TIME, 175, 50, 255, 128, 0); drawBoostECMBar(battle.ecmTimer, ECM_RECHARGE_TIME, 175, 50, 255, 128, 0);
} }
@ -287,35 +287,35 @@ static void drawAbilityBars(void)
static void drawBoostECMBar(int current, int max, int x, int y, int r, int g, int b) static void drawBoostECMBar(int current, int max, int x, int y, int r, int g, int b)
{ {
SDL_Rect rect; SDL_Rect rect;
float percent = current; float percent = current;
percent /= max; percent /= max;
rect.x = x; rect.x = x;
rect.y = y; rect.y = y;
rect.w = 105; rect.w = 105;
rect.h = 12; rect.h = 12;
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
SDL_RenderFillRect(app.renderer, &rect); SDL_RenderFillRect(app.renderer, &rect);
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
SDL_RenderDrawRect(app.renderer, &rect); SDL_RenderDrawRect(app.renderer, &rect);
rect.x += 2; rect.x += 2;
rect.y += 2; rect.y += 2;
rect.w -= 4; rect.w -= 4;
rect.h -= 4; rect.h -= 4;
rect.w *= percent; rect.w *= percent;
if (current < max) if (current < max)
{ {
r /= 2; r /= 2;
g /= 2; g /= 2;
b /= 2; b /= 2;
} }
SDL_SetRenderDrawColor(app.renderer, r, g, b, 255); SDL_SetRenderDrawColor(app.renderer, r, g, b, 255);
SDL_RenderFillRect(app.renderer, &rect); SDL_RenderFillRect(app.renderer, &rect);
} }
@ -323,15 +323,15 @@ static void drawBoostECMBar(int current, int max, int x, int y, int r, int g, in
static void drawWeaponInfo(void) static void drawWeaponInfo(void)
{ {
int i, y; int i, y;
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
if (!player->combinedGuns) if (!player->combinedGuns)
{ {
if (battle.numPlayerGuns) if (battle.numPlayerGuns)
{ {
y = 70; y = 70;
for (i = 0 ; i < BT_MAX ; i++) for (i = 0 ; i < BT_MAX ; i++)
{ {
if (playerHasGun(i)) if (playerHasGun(i))
@ -339,14 +339,14 @@ static void drawWeaponInfo(void)
if (player->selectedGunType == i) if (player->selectedGunType == i)
{ {
drawText(30, y, 14, TA_LEFT, colors.green, "%s", gunName[i]); drawText(30, y, 14, TA_LEFT, colors.green, "%s", gunName[i]);
blit(nextGun, 8, y + 5, 0); blit(nextGun, 8, y + 5, 0);
} }
else else
{ {
drawText(30, y, 14, TA_LEFT, colors.darkGrey, "%s", gunName[i]); drawText(30, y, 14, TA_LEFT, colors.darkGrey, "%s", gunName[i]);
} }
y += 20; y += 20;
} }
} }
@ -360,7 +360,7 @@ static void drawWeaponInfo(void)
{ {
drawText(30, 70, 14, TA_LEFT, colors.white, COMBINED_TEXT); drawText(30, 70, 14, TA_LEFT, colors.white, COMBINED_TEXT);
} }
drawText(280, 70, 14, TA_RIGHT, colors.white, MISSILES_TEXT, player->missiles); drawText(280, 70, 14, TA_RIGHT, colors.white, MISSILES_TEXT, player->missiles);
} }
@ -368,7 +368,7 @@ static void drawPlayerTargeter(void)
{ {
float angle; float angle;
int x, y; int x, y;
if (player->target || battle.missionTarget || jumpgateEnabled() || battle.messageSpeaker) if (player->target || battle.missionTarget || jumpgateEnabled() || battle.messageSpeaker)
{ {
if (player->target) if (player->target)
@ -387,63 +387,63 @@ static void drawPlayerTargeter(void)
{ {
setAtlasColor(255, 255, 0, 255); setAtlasColor(255, 255, 0, 255);
} }
blit(targetCircle, player->x - battle.camera.x, player->y - battle.camera.y, 1); blit(targetCircle, player->x - battle.camera.x, player->y - battle.camera.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);
x = player->x; x = player->x;
y = player->y; y = player->y;
x += sin(TO_RAIDANS(angle)) * 45; x += sin(TO_RAIDANS(angle)) * 45;
y += -cos(TO_RAIDANS(angle)) * 45; y += -cos(TO_RAIDANS(angle)) * 45;
setAtlasColor(255, 0, 0, 255); setAtlasColor(255, 0, 0, 255);
blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle); blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle);
} }
if (battle.missionTarget) if (battle.missionTarget)
{ {
angle = getAngle(player->x, player->y, battle.missionTarget->x, battle.missionTarget->y); angle = getAngle(player->x, player->y, battle.missionTarget->x, battle.missionTarget->y);
x = player->x; x = player->x;
y = player->y; y = player->y;
x += sin(TO_RAIDANS(angle)) * 45; x += sin(TO_RAIDANS(angle)) * 45;
y += -cos(TO_RAIDANS(angle)) * 45; y += -cos(TO_RAIDANS(angle)) * 45;
setAtlasColor(0, 255, 0, 255); setAtlasColor(0, 255, 0, 255);
blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle); blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle);
} }
if (jumpgateEnabled()) if (jumpgateEnabled())
{ {
angle = getAngle(player->x, player->y, battle.jumpgate->x, battle.jumpgate->y); angle = getAngle(player->x, player->y, battle.jumpgate->x, battle.jumpgate->y);
x = player->x; x = player->x;
y = player->y; y = player->y;
x += sin(TO_RAIDANS(angle)) * 45; x += sin(TO_RAIDANS(angle)) * 45;
y += -cos(TO_RAIDANS(angle)) * 45; y += -cos(TO_RAIDANS(angle)) * 45;
setAtlasColor(255, 255, 0, 255); setAtlasColor(255, 255, 0, 255);
blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle); blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle);
} }
if (battle.messageSpeaker && battle.messageSpeaker != player) if (battle.messageSpeaker && battle.messageSpeaker != player)
{ {
angle = getAngle(player->x, player->y, battle.messageSpeaker->x, battle.messageSpeaker->y); angle = getAngle(player->x, player->y, battle.messageSpeaker->x, battle.messageSpeaker->y);
x = player->x; x = player->x;
y = player->y; y = player->y;
x += sin(TO_RAIDANS(angle)) * 45; x += sin(TO_RAIDANS(angle)) * 45;
y += -cos(TO_RAIDANS(angle)) * 45; y += -cos(TO_RAIDANS(angle)) * 45;
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle); blitRotated(targetPointer, x - battle.camera.x, y - battle.camera.y, angle);
} }
} }
@ -454,7 +454,7 @@ static void drawNumFighters(void)
setAtlasColor(150, 200, 255, 255); setAtlasColor(150, 200, 255, 255);
blit(smallFighter, (app.winWidth / 2) - 185, 15, 0); blit(smallFighter, (app.winWidth / 2) - 185, 15, 0);
drawText((app.winWidth / 2) - 160, 11, 14, TA_LEFT, colors.white, battle.numAllies < 1000 ? "(%d)" : "(999+)", battle.numAllies); drawText((app.winWidth / 2) - 160, 11, 14, TA_LEFT, colors.white, battle.numAllies < 1000 ? "(%d)" : "(999+)", battle.numAllies);
/* Enemies */ /* Enemies */
setAtlasColor(255, 100, 100, 255); setAtlasColor(255, 100, 100, 255);
blit(smallFighter, (app.winWidth / 2) + 170, 15, 0); blit(smallFighter, (app.winWidth / 2) + 170, 15, 0);
@ -464,14 +464,14 @@ static void drawNumFighters(void)
static void drawObjectives(void) static void drawObjectives(void)
{ {
int timeRemaining; int timeRemaining;
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
if (!game.currentMission->challengeData.isChallenge) if (!game.currentMission->challengeData.isChallenge)
{ {
blit(objectives, (app.winWidth / 2) - 50, 14, 0); blit(objectives, (app.winWidth / 2) - 50, 14, 0);
drawText(app.winWidth / 2, 10, 16, TA_CENTER, colors.white, "%d / %d", battle.numObjectivesComplete, (battle.numObjectivesTotal + battle.numConditions)); drawText(app.winWidth / 2, 10, 16, TA_CENTER, colors.white, "%d / %d", battle.numObjectivesComplete, (battle.numObjectivesTotal + battle.numConditions));
if (battle.isEpic && battle.epicLives > 0) if (battle.isEpic && battle.epicLives > 0)
{ {
drawText(app.winWidth / 2, 35, 14, TA_CENTER, colors.white, REMAINING_PILOTS_TEXT, battle.epicLives - 1); drawText(app.winWidth / 2, 35, 14, TA_CENTER, colors.white, REMAINING_PILOTS_TEXT, battle.epicLives - 1);
@ -482,7 +482,7 @@ static void drawObjectives(void)
if (game.currentMission->challengeData.timeLimit) if (game.currentMission->challengeData.timeLimit)
{ {
timeRemaining = game.currentMission->challengeData.timeLimit - battle.stats[STAT_TIME]; timeRemaining = game.currentMission->challengeData.timeLimit - battle.stats[STAT_TIME];
blit(clockIcon, (app.winWidth / 2) - 50, 14, 0); blit(clockIcon, (app.winWidth / 2) - 50, 14, 0);
drawText(app.winWidth / 2, 10, 16, TA_CENTER, (timeRemaining < 11 * FPS) ? colors.red : colors.white, timeToString(timeRemaining, 0)); drawText(app.winWidth / 2, 10, 16, TA_CENTER, (timeRemaining < 11 * FPS) ? colors.red : colors.white, timeToString(timeRemaining, 0));
} }
@ -491,7 +491,7 @@ static void drawObjectives(void)
drawText(app.winWidth / 2, 10, 16, TA_CENTER, colors.white, timeToString(battle.stats[STAT_TIME], 0)); drawText(app.winWidth / 2, 10, 16, TA_CENTER, colors.white, timeToString(battle.stats[STAT_TIME], 0));
blit(clockIcon, (app.winWidth / 2) - 50, 14, 0); blit(clockIcon, (app.winWidth / 2) - 50, 14, 0);
} }
if (game.currentMission->challengeData.killLimit) if (game.currentMission->challengeData.killLimit)
{ {
drawText(app.winWidth / 2, 35, 14, TA_CENTER, colors.white, "%d / %d", battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_ENEMIES_DISABLED], game.currentMission->challengeData.killLimit); drawText(app.winWidth / 2, 35, 14, TA_CENTER, colors.white, "%d / %d", battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_ENEMIES_DISABLED], game.currentMission->challengeData.killLimit);
@ -530,14 +530,14 @@ static void drawObjectives(void)
static float distanceToKM(int x1, int y1, int x2, int y2) static float distanceToKM(int x1, int y1, int x2, int y2)
{ {
float distance; float distance;
distance = getDistance(x1, y1, x2, y2); distance = getDistance(x1, y1, x2, y2);
/* 2px = 1m approx */ /* 2px = 1m approx */
distance /= 2; distance /= 2;
distance = (int)distance; distance = (int)distance;
distance /= 1000; distance /= 1000;
return distance; return distance;
} }
@ -545,9 +545,9 @@ static void drawDistancesInfo(void)
{ {
int y; int y;
float distance; float distance;
y = 11; y = 11;
if (player->target) if (player->target)
{ {
if (player->target->flags & EF_AI_LEADER && player->target->speed > 0) if (player->target->flags & EF_AI_LEADER && player->target->speed > 0)
@ -558,40 +558,40 @@ static void drawDistancesInfo(void)
{ {
drawText(app.winWidth - 15, y, 18, TA_RIGHT, colors.red, player->target->name); drawText(app.winWidth - 15, y, 18, TA_RIGHT, colors.red, player->target->name);
} }
y += 30; y += 30;
distance = distanceToKM(player->x, player->y, player->target->x, player->target->y); distance = distanceToKM(player->x, player->y, player->target->x, player->target->y);
drawText(app.winWidth - 15, y, 14, TA_RIGHT, colors.red, TARGET_DIST_TEXT, distance); drawText(app.winWidth - 15, y, 14, TA_RIGHT, colors.red, TARGET_DIST_TEXT, distance);
y += 25; y += 25;
} }
if (battle.missionTarget) if (battle.missionTarget)
{ {
distance = distanceToKM(player->x, player->y, battle.missionTarget->x, battle.missionTarget->y); distance = distanceToKM(player->x, player->y, battle.missionTarget->x, battle.missionTarget->y);
drawText(app.winWidth - 15, y, 14, TA_RIGHT, colors.green, OBJECTIVE_DIST_TEXT, distance); drawText(app.winWidth - 15, y, 14, TA_RIGHT, colors.green, OBJECTIVE_DIST_TEXT, distance);
y += 25; y += 25;
} }
if (jumpgateEnabled()) if (jumpgateEnabled())
{ {
distance = distanceToKM(player->x, player->y, battle.jumpgate->x, battle.jumpgate->y); distance = distanceToKM(player->x, player->y, battle.jumpgate->x, battle.jumpgate->y);
drawText(app.winWidth - 15, y, 14, TA_RIGHT, colors.yellow, JUMPGATE_DIST_TEXT, distance); drawText(app.winWidth - 15, y, 14, TA_RIGHT, colors.yellow, JUMPGATE_DIST_TEXT, distance);
y += 25; y += 25;
} }
if (battle.messageSpeaker) if (battle.messageSpeaker)
{ {
distance = distanceToKM(player->x, player->y, battle.messageSpeaker->x, battle.messageSpeaker->y); distance = distanceToKM(player->x, player->y, battle.messageSpeaker->x, battle.messageSpeaker->y);
drawText(app.winWidth - 15, y, 14, TA_RIGHT, colors.white, "%s: %.2fkm", battle.messageSpeaker->name, distance); drawText(app.winWidth - 15, y, 14, TA_RIGHT, colors.white, "%s: %.2fkm", battle.messageSpeaker->name, distance);
y += 25; y += 25;
} }
} }
@ -600,11 +600,11 @@ static void drawHudMessages(void)
{ {
HudMessage *hudMessage; HudMessage *hudMessage;
int y = app.winHeight - 25; int y = app.winHeight - 25;
for (hudMessage = hudMessageHead.next ; hudMessage != NULL ; hudMessage = hudMessage->next) for (hudMessage = hudMessageHead.next ; hudMessage != NULL ; hudMessage = hudMessage->next)
{ {
drawText(10, y, 14, TA_LEFT, hudMessage->color, hudMessage->message); drawText(10, y, 14, TA_LEFT, hudMessage->color, hudMessage->message);
y -= 25; y -= 25;
} }
} }
@ -615,20 +615,20 @@ static void drawPlayerSelect(void)
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
setAtlasColor(0, 200, 255, 255); setAtlasColor(0, 200, 255, 255);
blit(targetCircle, player->x - battle.camera.x, player->y - battle.camera.y, 1); blit(targetCircle, player->x - battle.camera.x, player->y - battle.camera.y, 1);
drawText(app.winWidth / 2, 500, 28, TA_CENTER, colors.white, NEW_FIGHTER_TEXT); drawText(app.winWidth / 2, 500, 28, TA_CENTER, colors.white, NEW_FIGHTER_TEXT);
if (player->health > 0) if (player->health > 0)
{ {
drawText(app.winWidth / 2, 540, 20, TA_CENTER, colors.white, "%s (%d%% / %d%%)", player->defName, getPercent(player->health, player->maxHealth), getPercent(player->shield, player->maxShield)); drawText(app.winWidth / 2, 540, 20, TA_CENTER, colors.white, "%s (%d%% / %d%%)", player->defName, getPercent(player->health, player->maxHealth), getPercent(player->shield, player->maxShield));
} }
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
blit(arrowLeft, (app.winWidth / 2) - 200, 520, 1); blit(arrowLeft, (app.winWidth / 2) - 200, 520, 1);
blit(arrowRight, (app.winWidth / 2) + 200, 520, 1); blit(arrowRight, (app.winWidth / 2) + 200, 520, 1);
} }
@ -636,33 +636,33 @@ static void drawPlayerSelect(void)
static void drawSuspicionLevel(void) static void drawSuspicionLevel(void)
{ {
SDL_Rect r; SDL_Rect r;
if (battle.hasSuspicionLevel && !battle.incomingMissile) if (battle.hasSuspicionLevel && !battle.incomingMissile)
{ {
battle.suspicionLevel = MIN(battle.suspicionLevel, MAX_SUSPICION_LEVEL); battle.suspicionLevel = MIN(battle.suspicionLevel, MAX_SUSPICION_LEVEL);
drawText((app.winWidth / 2) - 150, app.winHeight - 60, 18, TA_RIGHT, colors.white, SUSPICION_TEXT); drawText((app.winWidth / 2) - 150, app.winHeight - 60, 18, TA_RIGHT, colors.white, SUSPICION_TEXT);
r.x = (app.winWidth / 2) - 140; r.x = (app.winWidth / 2) - 140;
r.y = app.winHeight - 58; r.y = app.winHeight - 58;
r.w = 400; r.w = 400;
r.h = 20; r.h = 20;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(app.renderer, 192, 192, 192, 255); SDL_SetRenderDrawColor(app.renderer, 192, 192, 192, 255);
SDL_RenderDrawRect(app.renderer, &r); SDL_RenderDrawRect(app.renderer, &r);
r.x += 2; r.x += 2;
r.y += 2; r.y += 2;
r.w -= 4; r.w -= 4;
r.h -= 4; r.h -= 4;
r.w = MAX((r.w / MAX_SUSPICION_LEVEL) * battle.suspicionLevel, 0); r.w = MAX((r.w / MAX_SUSPICION_LEVEL) * battle.suspicionLevel, 0);
if (battle.suspicionLevel < (MAX_SUSPICION_LEVEL * 0.5)) if (battle.suspicionLevel < (MAX_SUSPICION_LEVEL * 0.5))
{ {
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
@ -675,9 +675,9 @@ static void drawSuspicionLevel(void)
{ {
SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255);
} }
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
drawText(r.x + r.w + 7, app.winHeight - 57, 12, TA_LEFT, colors.white, "%d%%", (battle.suspicionLevel > 0) ? getPercent(battle.suspicionLevel, MAX_SUSPICION_LEVEL) : 0); drawText(r.x + r.w + 7, app.winHeight - 57, 12, TA_LEFT, colors.white, "%d%%", (battle.suspicionLevel > 0) ? getPercent(battle.suspicionLevel, MAX_SUSPICION_LEVEL) : 0);
} }
} }
@ -693,7 +693,7 @@ static void drawMissileWarning(void)
void resetHud(void) void resetHud(void)
{ {
HudMessage *hudMessage; HudMessage *hudMessage;
while (hudMessageHead.next) while (hudMessageHead.next)
{ {
hudMessage = hudMessageHead.next; hudMessage = hudMessageHead.next;

View File

@ -50,7 +50,7 @@ void loadItemDefs(void)
e->texture = getAtlasImage(cJSON_GetObjectItem(node, "texture")->valuestring); e->texture = getAtlasImage(cJSON_GetObjectItem(node, "texture")->valuestring);
e->health = e->maxHealth = FPS; e->health = e->maxHealth = FPS;
e->flags = EF_NO_HEALTH_BAR; e->flags = EF_NO_HEALTH_BAR;
e->w = e->texture->rect.w; e->w = e->texture->rect.w;
e->h = e->texture->rect.h; e->h = e->texture->rect.h;
@ -65,7 +65,7 @@ void loadItemDefs(void)
Entity *spawnItem(char *name) Entity *spawnItem(char *name)
{ {
Entity *e, *def, *item; Entity *e, *def, *item;
def = NULL; def = NULL;
item = spawnEntity(); item = spawnEntity();
@ -86,9 +86,9 @@ Entity *spawnItem(char *name)
} }
memcpy(item, def, sizeof(Entity)); memcpy(item, def, sizeof(Entity));
item->next = NULL; item->next = NULL;
item->action = action; item->action = action;
return item; return item;
@ -97,7 +97,7 @@ Entity *spawnItem(char *name)
void addRandomItem(int x, int y) void addRandomItem(int x, int y)
{ {
Entity *item; Entity *item;
item = spawnItem("RANDOM"); item = spawnItem("RANDOM");
item->x = x; item->x = x;
item->y = y; item->y = y;

View File

@ -33,13 +33,13 @@ static float portalAngle;
Entity *spawnJumpgate(int side, long flags) Entity *spawnJumpgate(int side, long flags)
{ {
Entity *jumpgate; Entity *jumpgate;
if (battle.jumpgate) if (battle.jumpgate)
{ {
printf("ERROR: Only one jumpgate is allowed\n"); printf("ERROR: Only one jumpgate is allowed\n");
exit(1); exit(1);
} }
jumpgate = spawnEntity(); jumpgate = spawnEntity();
jumpgate->type = ET_JUMPGATE; jumpgate->type = ET_JUMPGATE;
jumpgate->health = jumpgate->maxHealth = 1; jumpgate->health = jumpgate->maxHealth = 1;
@ -48,20 +48,20 @@ Entity *spawnJumpgate(int side, long flags)
jumpgate->draw = draw; jumpgate->draw = draw;
jumpgate->side = side; jumpgate->side = side;
jumpgate->flags = EF_NO_MT_BOX+EF_IMMORTAL+EF_AI_IGNORE+EF_NON_SOLID+EF_NO_HEALTH_BAR; jumpgate->flags = EF_NO_MT_BOX+EF_IMMORTAL+EF_AI_IGNORE+EF_NON_SOLID+EF_NO_HEALTH_BAR;
if (flags != -1 && flags & EF_DISABLED) if (flags != -1 && flags & EF_DISABLED)
{ {
jumpgate->flags |= EF_DISABLED; jumpgate->flags |= EF_DISABLED;
} }
addNodes(jumpgate, flags); addNodes(jumpgate, flags);
portal = getAtlasImage("gfx/entities/portal.png"); portal = getAtlasImage("gfx/entities/portal.png");
portalAngle = 0; portalAngle = 0;
jumpgate->w = jumpgate->texture->rect.w; jumpgate->w = jumpgate->texture->rect.w;
jumpgate->h = jumpgate->texture->rect.h; jumpgate->h = jumpgate->texture->rect.h;
battle.jumpgate = jumpgate; battle.jumpgate = jumpgate;
return jumpgate; return jumpgate;
@ -72,9 +72,9 @@ static void addNodes(Entity *jumpgate, long flags)
Entity *node; Entity *node;
AtlasImage *nodeTexture; AtlasImage *nodeTexture;
int i; int i;
nodeTexture = getAtlasImage("gfx/entities/jumpgateNode.png"); nodeTexture = getAtlasImage("gfx/entities/jumpgateNode.png");
for (i = 0 ; i < 360 ; i += 36) for (i = 0 ; i < 360 ; i += 36)
{ {
node = spawnEntity(); node = spawnEntity();
@ -90,20 +90,20 @@ static void addNodes(Entity *jumpgate, long flags)
node->die = nodeDie; node->die = nodeDie;
node->w = node->texture->rect.w; node->w = node->texture->rect.w;
node->h = node->texture->rect.h; node->h = node->texture->rect.h;
if (jumpgate->side == SIDE_NONE) if (jumpgate->side == SIDE_NONE)
{ {
node->flags |= EF_NO_HEALTH_BAR; node->flags |= EF_NO_HEALTH_BAR;
} }
if (flags != -1) if (flags != -1)
{ {
node->flags = flags; node->flags = flags;
} }
jumpgate->maxHealth++; jumpgate->maxHealth++;
} }
jumpgate->health = jumpgate->maxHealth; jumpgate->health = jumpgate->maxHealth;
} }
@ -117,7 +117,7 @@ static void nodeDie(void)
if (--battle.jumpgate->health == 1) if (--battle.jumpgate->health == 1)
{ {
battle.jumpgate->flags |= EF_DISABLED; battle.jumpgate->flags |= EF_DISABLED;
updateObjective("Jumpgate", TT_DESTROY); updateObjective("Jumpgate", TT_DESTROY);
updateCondition("Jumpgate", TT_DESTROY); updateCondition("Jumpgate", TT_DESTROY);
} }
@ -133,7 +133,7 @@ int jumpgateEnabled(void)
void activateJumpgate(int activate) void activateJumpgate(int activate)
{ {
Entity *e; Entity *e;
if (battle.jumpgate && battle.jumpgate->health > 1) if (battle.jumpgate && battle.jumpgate->health > 1)
{ {
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
@ -158,19 +158,19 @@ static void think(void)
self->thinkTime = 4; self->thinkTime = 4;
self->angle += 0.1; self->angle += 0.1;
if (self->angle >= 360) if (self->angle >= 360)
{ {
self->angle -= 360; self->angle -= 360;
} }
if (jumpgateEnabled()) if (jumpgateEnabled())
{ {
handleFleeingEntities(); handleFleeingEntities();
} }
portalAngle += 2; portalAngle += 2;
if (portalAngle >= 360) if (portalAngle >= 360)
{ {
portalAngle -= 360; portalAngle -= 360;

View File

@ -23,20 +23,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void doLocations(void) void doLocations(void)
{ {
Location *l, *prev; Location *l, *prev;
prev = &battle.locationHead; prev = &battle.locationHead;
for (l = battle.locationHead.next ; l != NULL ; l = l->next) for (l = battle.locationHead.next ; l != NULL ; l = l->next)
{ {
if (l->active && getDistance(player->x, player->y, l->x, l->y) <= l->size) if (l->active && getDistance(player->x, player->y, l->x, l->y) <= l->size)
{ {
runScriptFunction(l->name); runScriptFunction(l->name);
prev->next = l->next; prev->next = l->next;
free(l); free(l);
l = prev; l = prev;
} }
prev = l; prev = l;
} }
} }
@ -44,7 +44,7 @@ void doLocations(void)
void drawLocations(void) void drawLocations(void)
{ {
Location *l; Location *l;
for (l = battle.locationHead.next ; l != NULL ; l = l->next) for (l = battle.locationHead.next ; l != NULL ; l = l->next)
{ {
if (l->active) if (l->active)
@ -58,9 +58,9 @@ void activateLocations(char *locations)
{ {
char *token; char *token;
Location *l; Location *l;
token = strtok(locations, ";"); token = strtok(locations, ";");
while (token) while (token)
{ {
for (l = battle.locationHead.next ; l != NULL ; l = l->next) for (l = battle.locationHead.next ; l != NULL ; l = l->next)
@ -70,7 +70,7 @@ void activateLocations(char *locations)
l->active = 1; l->active = 1;
} }
} }
token = strtok(NULL, ";"); token = strtok(NULL, ";");
} }
} }
@ -82,7 +82,7 @@ void createChristabelLocation(void)
{ {
Location *l; Location *l;
Entity *e; Entity *e;
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (strcmp(e->name, "Christabel") == 0) if (strcmp(e->name, "Christabel") == 0)
@ -100,7 +100,7 @@ void createChristabelLocation(void)
l->x -= l->size / 2; l->x -= l->size / 2;
l->y -= l->size / 2; l->y -= l->size / 2;
return; return;
} }
} }
@ -130,7 +130,7 @@ void loadLocations(cJSON *node)
l->x += (SCREEN_WIDTH / 2); l->x += (SCREEN_WIDTH / 2);
l->y += (SCREEN_HEIGHT / 2); l->y += (SCREEN_HEIGHT / 2);
node = node->next; node = node->next;
} }

View File

@ -31,7 +31,7 @@ void initMessageBox(void)
{ {
memset(&head, 0, sizeof(MessageBox)); memset(&head, 0, sizeof(MessageBox));
tail = &head; tail = &head;
lastWingmate = NULL; lastWingmate = NULL;
} }
@ -40,22 +40,22 @@ void addMessageBox(char *title, char *body, int type)
MessageBox *msg; MessageBox *msg;
int isFirst; int isFirst;
float time; float time;
isFirst = (tail == &head); isFirst = (tail == &head);
msg = malloc(sizeof(MessageBox)); msg = malloc(sizeof(MessageBox));
memset(msg, 0, sizeof(MessageBox)); memset(msg, 0, sizeof(MessageBox));
tail->next = msg; tail->next = msg;
tail = msg; tail = msg;
time = 0.075 * strlen(body); time = 0.075 * strlen(body);
time = MIN(MAX(time, 3), 7); time = MIN(MAX(time, 3), 7);
STRNCPY(msg->title, title, MAX_NAME_LENGTH); STRNCPY(msg->title, title, MAX_NAME_LENGTH);
STRNCPY(msg->body, body, MAX_DESCRIPTION_LENGTH); STRNCPY(msg->body, body, MAX_DESCRIPTION_LENGTH);
msg->time = time * FPS; msg->time = time * FPS;
msg->type = type; msg->type = type;
if (isFirst) if (isFirst)
{ {
nextMessage(); nextMessage();
@ -65,9 +65,9 @@ void addMessageBox(char *title, char *body, int type)
void doMessageBox(void) void doMessageBox(void)
{ {
MessageBox *msg; MessageBox *msg;
msg = head.next; msg = head.next;
if (msg) if (msg)
{ {
if (--msg->time <= -(FPS / 4)) if (--msg->time <= -(FPS / 4))
@ -76,13 +76,13 @@ void doMessageBox(void)
{ {
tail = &head; tail = &head;
} }
head.next = msg->next; head.next = msg->next;
free(msg); free(msg);
msg = &head; msg = &head;
battle.messageSpeaker = NULL; battle.messageSpeaker = NULL;
if (head.next) if (head.next)
{ {
nextMessage(); nextMessage();
@ -94,7 +94,7 @@ void doMessageBox(void)
static void calculateMessageBoxHeight(MessageBox *msg) static void calculateMessageBoxHeight(MessageBox *msg)
{ {
app.textWidth = MSG_BOX_TEXT_WIDTH; app.textWidth = MSG_BOX_TEXT_WIDTH;
if (msg->type == MB_PANDORAN) if (msg->type == MB_PANDORAN)
{ {
useFont("khosrau"); useFont("khosrau");
@ -103,11 +103,11 @@ static void calculateMessageBoxHeight(MessageBox *msg)
{ {
useFont("roboto"); useFont("roboto");
} }
msg->height = getWrappedTextHeight(msg->body, 18); msg->height = getWrappedTextHeight(msg->body, 18);
app.textWidth = 0; app.textWidth = 0;
useFont("roboto"); useFont("roboto");
} }
@ -120,21 +120,21 @@ void drawMessageBox(void)
{ {
MessageBox *msg = head.next; MessageBox *msg = head.next;
SDL_Rect r; SDL_Rect r;
if (msg && msg->time > 0) if (msg && msg->time > 0)
{ {
if (!msg->height) if (!msg->height)
{ {
calculateMessageBoxHeight(msg); calculateMessageBoxHeight(msg);
} }
r.y = 50; r.y = 50;
r.w = 650; r.w = 650;
r.h = msg->height + 40; r.h = msg->height + 40;
r.x = (app.winWidth - r.w) / 2; r.x = (app.winWidth - r.w) / 2;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
if (msg->type == MB_IMPORTANT) if (msg->type == MB_IMPORTANT)
{ {
SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 64); SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 64);
@ -144,15 +144,15 @@ void drawMessageBox(void)
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
} }
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 128); SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 128);
SDL_RenderDrawRect(app.renderer, &r); SDL_RenderDrawRect(app.renderer, &r);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
drawText(r.x + 10, r.y + 5, 18, TA_LEFT, colors.cyan, msg->title); drawText(r.x + 10, r.y + 5, 18, TA_LEFT, colors.cyan, msg->title);
app.textWidth = MSG_BOX_TEXT_WIDTH; app.textWidth = MSG_BOX_TEXT_WIDTH;
if (msg->type == MB_PANDORAN) if (msg->type == MB_PANDORAN)
{ {
useFont("khosrau"); useFont("khosrau");
@ -161,12 +161,12 @@ void drawMessageBox(void)
{ {
useFont("roboto"); useFont("roboto");
} }
drawText(r.x + 10, r.y + 30, 18, TA_LEFT, (msg->type != MB_IMPORTANT) ? colors.white : colors.red, msg->body); drawText(r.x + 10, r.y + 30, 18, TA_LEFT, (msg->type != MB_IMPORTANT) ? colors.white : colors.red, msg->body);
app.textWidth = 0; app.textWidth = 0;
} }
useFont("roboto"); useFont("roboto");
} }
@ -174,13 +174,13 @@ static void nextMessage(void)
{ {
Entity *e, *wingmate; Entity *e, *wingmate;
int isWingmate; int isWingmate;
wingmate = NULL; wingmate = NULL;
isWingmate = strcmp(head.next->title, "Wingmate") == 0; isWingmate = strcmp(head.next->title, "Wingmate") == 0;
playSound(SND_RADIO); playSound(SND_RADIO);
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (e->active && e != player) if (e->active && e != player)
@ -190,11 +190,11 @@ static void nextMessage(void)
battle.messageSpeaker = lastWingmate = e; battle.messageSpeaker = lastWingmate = e;
return; return;
} }
if (isWingmate && e->side == player->side && e->type == ET_FIGHTER && e->speed > 0) if (isWingmate && e->side == player->side && e->type == ET_FIGHTER && e->speed > 0)
{ {
wingmate = e; wingmate = e;
if (rand() % 2 && e != lastWingmate) if (rand() % 2 && e != lastWingmate)
{ {
battle.messageSpeaker = lastWingmate = e; battle.messageSpeaker = lastWingmate = e;
@ -203,20 +203,20 @@ static void nextMessage(void)
} }
} }
} }
battle.messageSpeaker = wingmate; battle.messageSpeaker = wingmate;
} }
void resetMessageBox(void) void resetMessageBox(void)
{ {
MessageBox *messageBox; MessageBox *messageBox;
while (head.next) while (head.next)
{ {
messageBox = head.next; messageBox = head.next;
head.next = messageBox->next; head.next = messageBox->next;
free(messageBox); free(messageBox);
} }
tail = &head; tail = &head;
} }

View File

@ -33,7 +33,7 @@ static AtlasImage *shadowMine = NULL;
Entity *spawnMine(int type) Entity *spawnMine(int type)
{ {
Entity *mine = spawnEntity(); Entity *mine = spawnEntity();
if (!mineWarning) if (!mineWarning)
{ {
shadowMine = getAtlasImage("gfx/entities/shadowMine.png"); shadowMine = getAtlasImage("gfx/entities/shadowMine.png");
@ -50,14 +50,14 @@ Entity *spawnMine(int type)
mine->action = think; mine->action = think;
mine->die = die; mine->die = die;
mine->flags = EF_TAKES_DAMAGE+EF_NO_PLAYER_TARGET+EF_SHORT_RADAR_RANGE+EF_NON_SOLID+EF_NO_HEALTH_BAR; mine->flags = EF_TAKES_DAMAGE+EF_NO_PLAYER_TARGET+EF_SHORT_RADAR_RANGE+EF_NON_SOLID+EF_NO_HEALTH_BAR;
if (type == ET_SHADOW_MINE) if (type == ET_SHADOW_MINE)
{ {
mine->flags &= ~EF_NO_PLAYER_TARGET; mine->flags &= ~EF_NO_PLAYER_TARGET;
mine->speed = 100 + rand() % 100; mine->speed = 100 + rand() % 100;
mine->speed *= 0.01; mine->speed *= 0.01;
} }
mine->w = mine->texture->rect.w; mine->w = mine->texture->rect.w;
mine->h = mine->texture->rect.h; mine->h = mine->texture->rect.h;
@ -67,17 +67,17 @@ Entity *spawnMine(int type)
static void think(void) static void think(void)
{ {
self->texture = (self->type == ET_MINE) ? mineNormal : shadowMine; self->texture = (self->type == ET_MINE) ? mineNormal : shadowMine;
self->angle += 0.1; self->angle += 0.1;
if (self->angle >= 360) if (self->angle >= 360)
{ {
self->angle -= 360; self->angle -= 360;
} }
self->dx *= 0.99; self->dx *= 0.99;
self->dy *= 0.99; self->dy *= 0.99;
if (self->type == ET_MINE) if (self->type == ET_MINE)
{ {
lookForFighters(); lookForFighters();
@ -86,11 +86,11 @@ static void think(void)
{ {
lookForPlayer(); lookForPlayer();
} }
if (self->systemPower < SYSTEM_POWER && battle.stats[STAT_TIME] % 8 < 4) if (self->systemPower < SYSTEM_POWER && battle.stats[STAT_TIME] % 8 < 4)
{ {
playBattleSound(SND_MINE_WARNING, self->x, self->y); playBattleSound(SND_MINE_WARNING, self->x, self->y);
self->texture = mineWarning; self->texture = mineWarning;
} }
} }
@ -107,16 +107,16 @@ static void lookForFighters(void)
if (e->side != self->side && e->health > 0 && e->type == ET_FIGHTER && getDistance(self->x, self->y, e->x, e->y) <= TRIGGER_RANGE) if (e->side != self->side && e->health > 0 && e->type == ET_FIGHTER && getDistance(self->x, self->y, e->x, e->y) <= TRIGGER_RANGE)
{ {
self->systemPower--; self->systemPower--;
if (self->systemPower <= 0) if (self->systemPower <= 0)
{ {
self->health = 0; self->health = 0;
} }
return; return;
} }
} }
self->systemPower = SYSTEM_POWER; self->systemPower = SYSTEM_POWER;
} }
@ -124,11 +124,11 @@ static void lookForPlayer(void)
{ {
float dx, dy, norm; float dx, dy, norm;
int distance; int distance;
if (player->alive == ALIVE_ALIVE) if (player->alive == ALIVE_ALIVE)
{ {
distance = getDistance(self->x, self->y, player->x, player->y); distance = getDistance(self->x, self->y, player->x, player->y);
if (distance < SCREEN_WIDTH * 2) if (distance < SCREEN_WIDTH * 2)
{ {
dx = player->x - self->x; dx = player->x - self->x;
@ -140,37 +140,37 @@ static void lookForPlayer(void)
{ {
return; return;
} }
dx = rand() % 1000; dx = rand() % 1000;
dx -= rand() % 1000; dx -= rand() % 1000;
dy = rand() % 1000; dy = rand() % 1000;
dy -= rand() % 1000; dy -= rand() % 1000;
self->aiActionTime = FPS * (5 + (rand() % 15)); self->aiActionTime = FPS * (5 + (rand() % 15));
} }
norm = sqrt(dx * dx + dy * dy); norm = sqrt(dx * dx + dy * dy);
dx /= norm; dx /= norm;
dy /= norm; dy /= norm;
self->dx = dx * self->speed; self->dx = dx * self->speed;
self->dy = dy * self->speed; self->dy = dy * self->speed;
if (distance <= TRIGGER_RANGE) if (distance <= TRIGGER_RANGE)
{ {
self->systemPower--; self->systemPower--;
if (self->systemPower <= 0) if (self->systemPower <= 0)
{ {
self->health = 0; self->health = 0;
} }
return; return;
} }
} }
self->systemPower = SYSTEM_POWER; self->systemPower = SYSTEM_POWER;
} }
@ -180,17 +180,17 @@ static void die(void)
{ {
battle.stats[STAT_MINES_DESTROYED]++; battle.stats[STAT_MINES_DESTROYED]++;
} }
addMineExplosion(); addMineExplosion();
doSplashDamage(); doSplashDamage();
playBattleSound(SND_EXPLOSION_5, self->x, self->y); playBattleSound(SND_EXPLOSION_5, self->x, self->y);
self->alive = ALIVE_DEAD; self->alive = ALIVE_DEAD;
updateObjective(self->name, TT_DESTROY); updateObjective(self->name, TT_DESTROY);
runScriptFunction("MINES_DESTROYED %d", battle.stats[STAT_MINES_DESTROYED]); runScriptFunction("MINES_DESTROYED %d", battle.stats[STAT_MINES_DESTROYED]);
} }
@ -201,7 +201,7 @@ static void doSplashDamage(void)
float damage, percent; float damage, percent;
candidates = getAllEntsInRadius(self->x, self->y, DAMAGE_RANGE, self); candidates = getAllEntsInRadius(self->x, self->y, DAMAGE_RANGE, self);
kills = 0; kills = 0;
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
@ -209,20 +209,20 @@ static void doSplashDamage(void)
if (e->health > 0 && (e->type == ET_FIGHTER || e->type == ET_MINE) && !(e->flags & EF_IMMORTAL)) if (e->health > 0 && (e->type == ET_FIGHTER || e->type == ET_MINE) && !(e->flags & EF_IMMORTAL))
{ {
dist = getDistance(self->x, self->y, e->x, e->y); dist = getDistance(self->x, self->y, e->x, e->y);
if (dist <= DAMAGE_RANGE) if (dist <= DAMAGE_RANGE)
{ {
percent = dist; percent = dist;
percent /= DAMAGE_RANGE; percent /= DAMAGE_RANGE;
percent = 1 - percent; percent = 1 - percent;
damage = DAMAGE_RANGE; damage = DAMAGE_RANGE;
damage *= percent; damage *= percent;
if (e->type == ET_FIGHTER) if (e->type == ET_FIGHTER)
{ {
damageFighter(e, damage, 0); damageFighter(e, damage, 0);
if (self->killedBy == player && e != player && e->health <= 0) if (self->killedBy == player && e != player && e->health <= 0)
{ {
kills++; kills++;
@ -232,14 +232,14 @@ static void doSplashDamage(void)
{ {
e->dx = e->x - self->x; e->dx = e->x - self->x;
e->dy = e->y - self->y; e->dy = e->y - self->y;
e->dx *= 0.01; e->dx *= 0.01;
e->dy *= 0.01; e->dy *= 0.01;
} }
} }
} }
} }
if (kills >= 2) if (kills >= 2)
{ {
awardTrophy("2_BIRDS"); awardTrophy("2_BIRDS");

View File

@ -37,16 +37,16 @@ static char *TIME_LIMIT_TEXT;
void initMissionInfo(void) void initMissionInfo(void)
{ {
int isChallenge = game.currentMission->challengeData.isChallenge; int isChallenge = game.currentMission->challengeData.isChallenge;
objectiveStatus[OS_INCOMPLETE] = _("Incomplete"); objectiveStatus[OS_INCOMPLETE] = _("Incomplete");
objectiveStatus[OS_COMPLETE] = _("Complete"); objectiveStatus[OS_COMPLETE] = _("Complete");
objectiveStatus[OS_FAILED] = _("Failed"); objectiveStatus[OS_FAILED] = _("Failed");
objectiveStatus[OS_CONDITION] = _("Condition"); objectiveStatus[OS_CONDITION] = _("Condition");
OBJECTIVES_TEXT = _("OBJECTIVES"); OBJECTIVES_TEXT = _("OBJECTIVES");
NONE_TEXT = _("(none)"); NONE_TEXT = _("(none)");
TIME_LIMIT_TEXT = _("Time Limit: %s"); TIME_LIMIT_TEXT = _("Time Limit: %s");
missionStartTexture = !isChallenge ? getAtlasImage("gfx/battle/missionStart.png") : getAtlasImage("gfx/battle/challengeStart.png"); missionStartTexture = !isChallenge ? getAtlasImage("gfx/battle/missionStart.png") : getAtlasImage("gfx/battle/challengeStart.png");
missionInProgressTexture = !isChallenge ? getAtlasImage("gfx/battle/missionInProgress.png") : getAtlasImage("gfx/battle/challengeInProgress.png"); missionInProgressTexture = !isChallenge ? getAtlasImage("gfx/battle/missionInProgress.png") : getAtlasImage("gfx/battle/challengeInProgress.png");
missionCompleteTexture = !isChallenge ? getAtlasImage("gfx/battle/missionComplete.png") : getAtlasImage("gfx/battle/challengeComplete.png"); missionCompleteTexture = !isChallenge ? getAtlasImage("gfx/battle/missionComplete.png") : getAtlasImage("gfx/battle/challengeComplete.png");
@ -57,19 +57,19 @@ void initMissionInfo(void)
void drawMissionInfo(void) void drawMissionInfo(void)
{ {
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
switch (battle.status) switch (battle.status)
{ {
case MS_START: case MS_START:
drawMissionSummary(missionStartTexture); drawMissionSummary(missionStartTexture);
drawWidgets("startBattle"); drawWidgets("startBattle");
break; break;
case MS_PAUSED: case MS_PAUSED:
drawMissionSummary(missionInProgressTexture); drawMissionSummary(missionInProgressTexture);
drawWidgets("startBattle"); drawWidgets("startBattle");
break; break;
case MS_COMPLETE: case MS_COMPLETE:
case MS_FAILED: case MS_FAILED:
if (!battle.unwinnable) if (!battle.unwinnable)
@ -77,7 +77,7 @@ void drawMissionInfo(void)
if (battle.missionFinishedTimer <= -FPS) if (battle.missionFinishedTimer <= -FPS)
{ {
drawMissionSummary(battle.status == MS_COMPLETE ? missionCompleteTexture : missionFailedTexture); drawMissionSummary(battle.status == MS_COMPLETE ? missionCompleteTexture : missionFailedTexture);
if (battle.missionFinishedTimer <= -(FPS * 2)) if (battle.missionFinishedTimer <= -(FPS * 2))
{ {
drawWidgets(battle.status == MS_COMPLETE ? "battleWon" : "battleLost"); drawWidgets(battle.status == MS_COMPLETE ? "battleWon" : "battleLost");
@ -85,12 +85,12 @@ void drawMissionInfo(void)
} }
} }
break; break;
case MS_TIME_UP: case MS_TIME_UP:
if (battle.missionFinishedTimer <= -FPS) if (battle.missionFinishedTimer <= -FPS)
{ {
drawMissionSummary(timeUpTexture); drawMissionSummary(timeUpTexture);
if (battle.missionFinishedTimer <= -(FPS * 2)) if (battle.missionFinishedTimer <= -(FPS * 2))
{ {
drawWidgets("battleWon"); drawWidgets("battleWon");
@ -98,7 +98,7 @@ void drawMissionInfo(void)
} }
break; break;
} }
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
@ -108,11 +108,11 @@ static void drawMissionSummary(AtlasImage *header)
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
blit(header, UI_WIDTH / 2, 150, 1); blit(header, UI_WIDTH / 2, 150, 1);
if (!game.currentMission->challengeData.isChallenge) if (!game.currentMission->challengeData.isChallenge)
{ {
drawObjectives(); drawObjectives();
@ -128,50 +128,50 @@ static void drawObjectives(void)
Objective *o; Objective *o;
SDL_Color color; SDL_Color color;
int y = 215; int y = 215;
drawText(UI_WIDTH / 2, y, 28, TA_CENTER, colors.white, OBJECTIVES_TEXT); drawText(UI_WIDTH / 2, y, 28, TA_CENTER, colors.white, OBJECTIVES_TEXT);
y += 10; y += 10;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
if (o->active) if (o->active)
{ {
y += 50; y += 50;
switch (o->status) switch (o->status)
{ {
case OS_INCOMPLETE: case OS_INCOMPLETE:
color = colors.white; color = colors.white;
break; break;
case OS_COMPLETE: case OS_COMPLETE:
color = colors.green; color = colors.green;
break; break;
case OS_FAILED: case OS_FAILED:
color = colors.red; color = colors.red;
break; break;
} }
drawText(UI_WIDTH / 2 - 100, y, 22, TA_RIGHT, colors.white, o->description); drawText(UI_WIDTH / 2 - 100, y, 22, TA_RIGHT, colors.white, o->description);
if (o->targetValue > 1 && !o->hideNumbers) if (o->targetValue > 1 && !o->hideNumbers)
{ {
drawText(UI_WIDTH / 2, y, 22, TA_CENTER, colors.white, "%d / %d", o->currentValue, o->targetValue); drawText(UI_WIDTH / 2, y, 22, TA_CENTER, colors.white, "%d / %d", o->currentValue, o->targetValue);
} }
drawText(UI_WIDTH / 2 + 100, y, 22, TA_LEFT, color, objectiveStatus[o->status]); drawText(UI_WIDTH / 2 + 100, y, 22, TA_LEFT, color, objectiveStatus[o->status]);
} }
} }
if (!battle.objectiveHead.next) if (!battle.objectiveHead.next)
{ {
y += 50; y += 50;
drawText(UI_WIDTH / 2, y, 22, TA_CENTER, colors.white, NONE_TEXT); drawText(UI_WIDTH / 2, y, 22, TA_CENTER, colors.white, NONE_TEXT);
} }
y += 75; y += 75;
} }
@ -182,43 +182,43 @@ static void drawChallenges(void)
char *challengeStatus; char *challengeStatus;
SDL_Color color; SDL_Color color;
int y = 215; int y = 215;
drawText(UI_WIDTH / 2, y, 24, TA_CENTER, colors.white, game.currentMission->description); drawText(UI_WIDTH / 2, y, 24, TA_CENTER, colors.white, game.currentMission->description);
if (battle.status == MS_START && game.currentMission->challengeData.timeLimit) if (battle.status == MS_START && game.currentMission->challengeData.timeLimit)
{ {
y+= 50; y+= 50;
drawText(UI_WIDTH / 2, y, 20, TA_CENTER, colors.white, TIME_LIMIT_TEXT, timeToString(game.currentMission->challengeData.timeLimit, 0)); drawText(UI_WIDTH / 2, y, 20, TA_CENTER, colors.white, TIME_LIMIT_TEXT, timeToString(game.currentMission->challengeData.timeLimit, 0));
} }
y += 25; y += 25;
for (i = 0 ; i < MAX_CHALLENGES ; i++) for (i = 0 ; i < MAX_CHALLENGES ; i++)
{ {
c = game.currentMission->challengeData.challenges[i]; c = game.currentMission->challengeData.challenges[i];
if (c) if (c)
{ {
y += 50; y += 50;
color = colors.white; color = colors.white;
challengeStatus = _("Incomplete"); challengeStatus = _("Incomplete");
if (c->passed) if (c->passed)
{ {
color = colors.green; color = colors.green;
challengeStatus = _("Complete"); challengeStatus = _("Complete");
} }
else if (battle.status == MS_COMPLETE ||battle.status == MS_FAILED) else if (battle.status == MS_COMPLETE ||battle.status == MS_FAILED)
{ {
color = colors.red; color = colors.red;
challengeStatus = _("Failed"); challengeStatus = _("Failed");
} }
drawText(UI_WIDTH / 2 - 50, y, 22, TA_RIGHT, colors.white, "%s", getChallengeDescription(c)); drawText(UI_WIDTH / 2 - 50, y, 22, TA_RIGHT, colors.white, "%s", getChallengeDescription(c));
drawText(UI_WIDTH / 2 + 50, y, 22, TA_LEFT, color, challengeStatus); drawText(UI_WIDTH / 2 + 50, y, 22, TA_LEFT, color, challengeStatus);
} }

View File

@ -27,11 +27,11 @@ void doObjectives(void)
int objectiveFailed; int objectiveFailed;
int hasHidden; int hasHidden;
Objective *o; Objective *o;
battle.numObjectivesComplete = battle.numObjectivesTotal = battle.numConditions = 0; battle.numObjectivesComplete = battle.numObjectivesTotal = battle.numConditions = 0;
objectiveFailed = 0; objectiveFailed = 0;
hasHidden = 0; hasHidden = 0;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
if (o->active) if (o->active)
@ -44,17 +44,17 @@ void doObjectives(void)
{ {
battle.numConditions++; battle.numConditions++;
} }
if (o->isEliminateAll && o->status != OS_COMPLETE && !battle.hasThreats) if (o->isEliminateAll && o->status != OS_COMPLETE && !battle.hasThreats)
{ {
addHudMessage(colors.green, _("%s - Objective Complete!"), o->description); addHudMessage(colors.green, _("%s - Objective Complete!"), o->description);
o->currentValue = o->targetValue; o->currentValue = o->targetValue;
o->status = OS_COMPLETE; o->status = OS_COMPLETE;
runScriptFunction("OBJECTIVES_COMPLETE %d", battle.numObjectivesComplete + 1); runScriptFunction("OBJECTIVES_COMPLETE %d", battle.numObjectivesComplete + 1);
playSound(SND_OBJECTIVE_COMPLETE); playSound(SND_OBJECTIVE_COMPLETE);
} }
} }
@ -62,7 +62,7 @@ void doObjectives(void)
{ {
hasHidden = 1; hasHidden = 1;
} }
if (o->currentValue == o->targetValue) if (o->currentValue == o->targetValue)
{ {
switch (o->status) switch (o->status)
@ -70,14 +70,14 @@ void doObjectives(void)
case OS_COMPLETE: case OS_COMPLETE:
battle.numObjectivesComplete++; battle.numObjectivesComplete++;
break; break;
case OS_FAILED: case OS_FAILED:
objectiveFailed = 1; objectiveFailed = 1;
break; break;
} }
} }
} }
if (battle.status == MS_IN_PROGRESS) if (battle.status == MS_IN_PROGRESS)
{ {
if (!hasHidden && battle.numObjectivesTotal > 0 && battle.numObjectivesComplete == battle.numObjectivesTotal) if (!hasHidden && battle.numObjectivesTotal > 0 && battle.numObjectivesComplete == battle.numObjectivesTotal)
@ -85,16 +85,16 @@ void doObjectives(void)
if (fireObjectivesComplete) if (fireObjectivesComplete)
{ {
fireObjectivesComplete = 0; fireObjectivesComplete = 0;
runScriptFunction("ALL_OBJECTIVES_COMPLETE"); runScriptFunction("ALL_OBJECTIVES_COMPLETE");
} }
if (!battle.manualComplete) if (!battle.manualComplete)
{ {
completeMission(); completeMission();
} }
} }
if (objectiveFailed) if (objectiveFailed)
{ {
failMission(); failMission();
@ -106,13 +106,13 @@ void updateObjective(char *name, int type)
{ {
Objective *o; Objective *o;
int completed, hasHidden; int completed, hasHidden;
if (strlen(name)) if (strlen(name))
{ {
completed = battle.numObjectivesComplete; completed = battle.numObjectivesComplete;
hasHidden = 0; hasHidden = 0;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
if (o->active && o->status != OS_COMPLETE) if (o->active && o->status != OS_COMPLETE)
@ -120,7 +120,7 @@ void updateObjective(char *name, int type)
if (!o->isEliminateAll && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0) if (!o->isEliminateAll && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
{ {
o->currentValue++; o->currentValue++;
if (!o->hideNumbers) if (!o->hideNumbers)
{ {
if (o->targetValue - o->currentValue <= 10) if (o->targetValue - o->currentValue <= 10)
@ -132,32 +132,32 @@ void updateObjective(char *name, int type)
addHudMessage(colors.cyan, "%s - %d / %d", o->description, o->currentValue, o->targetValue); addHudMessage(colors.cyan, "%s - %d / %d", o->description, o->currentValue, o->targetValue);
} }
} }
if (o->currentValue == o->targetValue) if (o->currentValue == o->targetValue)
{ {
addHudMessage(colors.green, _("%s - Objective Complete!"), o->description); addHudMessage(colors.green, _("%s - Objective Complete!"), o->description);
runScriptFunction(o->description); runScriptFunction(o->description);
o->status = OS_COMPLETE; o->status = OS_COMPLETE;
runScriptFunction("OBJECTIVES_COMPLETE %d", ++completed); runScriptFunction("OBJECTIVES_COMPLETE %d", ++completed);
playSound(SND_OBJECTIVE_COMPLETE); playSound(SND_OBJECTIVE_COMPLETE);
} }
} }
} }
if (!o->active) if (!o->active)
{ {
hasHidden = 1; hasHidden = 1;
} }
} }
if (completed == battle.numObjectivesTotal && !hasHidden && fireObjectivesComplete) if (completed == battle.numObjectivesTotal && !hasHidden && fireObjectivesComplete)
{ {
fireObjectivesComplete = 0; fireObjectivesComplete = 0;
runScriptFunction("ALL_OBJECTIVES_COMPLETE"); runScriptFunction("ALL_OBJECTIVES_COMPLETE");
} }
} }
@ -166,20 +166,20 @@ void updateObjective(char *name, int type)
void adjustObjectiveTargetValue(char *name, int type, int amount) void adjustObjectiveTargetValue(char *name, int type, int amount)
{ {
Objective *o; Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
if (o->active && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0) if (o->active && !o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
{ {
o->targetValue += amount; o->targetValue += amount;
o->currentValue = MIN(o->currentValue, o->targetValue); o->currentValue = MIN(o->currentValue, o->targetValue);
if (o->currentValue >= o->targetValue && o->targetValue > 0) if (o->currentValue >= o->targetValue && o->targetValue > 0)
{ {
o->status = OS_COMPLETE; o->status = OS_COMPLETE;
addHudMessage(colors.green, _("%s - Objective Complete!"), o->description); addHudMessage(colors.green, _("%s - Objective Complete!"), o->description);
playSound(SND_OBJECTIVE_COMPLETE); playSound(SND_OBJECTIVE_COMPLETE);
} }
} }
@ -189,7 +189,7 @@ void adjustObjectiveTargetValue(char *name, int type, int amount)
void updateCondition(char *name, int type) void updateCondition(char *name, int type)
{ {
Objective *o; Objective *o;
if (strlen(name)) if (strlen(name))
{ {
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
@ -197,7 +197,7 @@ void updateCondition(char *name, int type)
if (o->active && o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0) if (o->active && o->isCondition && o->targetType == type && o->currentValue < o->targetValue && strcmp(o->targetName, name) == 0)
{ {
o->currentValue++; o->currentValue++;
if (o->currentValue == o->targetValue) if (o->currentValue == o->targetValue)
{ {
o->status = OS_FAILED; o->status = OS_FAILED;
@ -216,7 +216,7 @@ void updateCondition(char *name, int type)
void completeAllObjectives(void) void completeAllObjectives(void)
{ {
Objective *o; Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
o->status = OS_COMPLETE; o->status = OS_COMPLETE;
@ -226,13 +226,13 @@ void completeAllObjectives(void)
void completeConditions(void) void completeConditions(void)
{ {
Objective *o; Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
if (o->isCondition) if (o->isCondition)
{ {
o->currentValue = o->targetValue; o->currentValue = o->targetValue;
o->status = OS_COMPLETE; o->status = OS_COMPLETE;
} }
} }
@ -242,7 +242,7 @@ void completeConditions(void)
void failIncompleteObjectives(void) void failIncompleteObjectives(void)
{ {
Objective *o; Objective *o;
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
{ {
if (o->status != OS_COMPLETE) if (o->status != OS_COMPLETE)
@ -257,11 +257,11 @@ void activateObjectives(char *objectives)
char *token; char *token;
Objective *o; Objective *o;
int activated; int activated;
activated = 0; activated = 0;
token = strtok(objectives, ";"); token = strtok(objectives, ";");
while (token) while (token)
{ {
for (o = battle.objectiveHead.next ; o != NULL ; o = o->next) for (o = battle.objectiveHead.next ; o != NULL ; o = o->next)
@ -269,24 +269,24 @@ void activateObjectives(char *objectives)
if (strcmp(token, o->id) == 0) if (strcmp(token, o->id) == 0)
{ {
addHudMessage(colors.cyan, _("New Objective : %s"), o->description); addHudMessage(colors.cyan, _("New Objective : %s"), o->description);
o->active = 1; o->active = 1;
/* prevent race condition */ /* prevent race condition */
doObjectives(); doObjectives();
if (o->isEliminateAll) if (o->isEliminateAll)
{ {
updateObjective(o->targetName, o->targetType); updateObjective(o->targetName, o->targetType);
} }
activated = 1; activated = 1;
} }
} }
token = strtok(NULL, ";"); token = strtok(NULL, ";");
} }
if (activated) if (activated)
{ {
playSound(SND_NEW_OBJECTIVE); playSound(SND_NEW_OBJECTIVE);
@ -326,7 +326,7 @@ void loadObjectives(cJSON *node)
node = node->next; node = node->next;
} }
} }
fireObjectivesComplete = 1; fireObjectivesComplete = 1;
} }
@ -334,12 +334,12 @@ void addEpicLivesObjective(void)
{ {
Objective *o; Objective *o;
char id[MAX_DESCRIPTION_LENGTH]; char id[MAX_DESCRIPTION_LENGTH];
o = malloc(sizeof(Objective)); o = malloc(sizeof(Objective));
memset(o, 0, sizeof(Objective)); memset(o, 0, sizeof(Objective));
battle.objectiveTail->next = o; battle.objectiveTail->next = o;
battle.objectiveTail = o; battle.objectiveTail = o;
sprintf(id, _("Do not lose more than %d pilots"), battle.epicLives); sprintf(id, _("Do not lose more than %d pilots"), battle.epicLives);
STRNCPY(o->id, id, MAX_DESCRIPTION_LENGTH); STRNCPY(o->id, id, MAX_DESCRIPTION_LENGTH);
@ -355,12 +355,12 @@ void addEpicKillsObjective(void)
{ {
Objective *o; Objective *o;
char id[MAX_DESCRIPTION_LENGTH]; char id[MAX_DESCRIPTION_LENGTH];
o = malloc(sizeof(Objective)); o = malloc(sizeof(Objective));
memset(o, 0, sizeof(Objective)); memset(o, 0, sizeof(Objective));
battle.objectiveTail->next = o; battle.objectiveTail->next = o;
battle.objectiveTail = o; battle.objectiveTail = o;
sprintf(id, _("Destroy at least %d enemy fighters"), battle.epicKills); sprintf(id, _("Destroy at least %d enemy fighters"), battle.epicKills);
STRNCPY(o->id, id, MAX_DESCRIPTION_LENGTH); STRNCPY(o->id, id, MAX_DESCRIPTION_LENGTH);

View File

@ -81,30 +81,30 @@ void initPlayer(void)
{ {
player->selectedGunType = 0; player->selectedGunType = 0;
} }
setPilotName(); setPilotName();
player->action = NULL; player->action = NULL;
battle.boostTimer = BOOST_RECHARGE_TIME; battle.boostTimer = BOOST_RECHARGE_TIME;
battle.ecmTimer = ECM_RECHARGE_TIME; battle.ecmTimer = ECM_RECHARGE_TIME;
player->flags |= EF_NO_HEALTH_BAR; player->flags |= EF_NO_HEALTH_BAR;
player->flags &= ~EF_IMMORTAL; player->flags &= ~EF_IMMORTAL;
player->target = NULL; player->target = NULL;
game.stats[STAT_EPIC_KILL_STREAK] = MAX(game.stats[STAT_EPIC_KILL_STREAK], battle.stats[STAT_EPIC_KILL_STREAK]); game.stats[STAT_EPIC_KILL_STREAK] = MAX(game.stats[STAT_EPIC_KILL_STREAK], battle.stats[STAT_EPIC_KILL_STREAK]);
battle.stats[STAT_EPIC_KILL_STREAK] = 0; battle.stats[STAT_EPIC_KILL_STREAK] = 0;
} }
static void setPilotName(void) static void setPilotName(void)
{ {
int i, pos; int i, pos;
pos = -1; pos = -1;
for (i = 0 ; i < strlen(game.currentMission->pilot) ; i++) for (i = 0 ; i < strlen(game.currentMission->pilot) ; i++)
{ {
if (game.currentMission->pilot[i] == ' ') if (game.currentMission->pilot[i] == ' ')
@ -112,34 +112,34 @@ static void setPilotName(void)
pos = i; pos = i;
} }
} }
memset(player->name, '\0', MAX_NAME_LENGTH); memset(player->name, '\0', MAX_NAME_LENGTH);
if (pos != -1) if (pos != -1)
{ {
memcpy(player->name, game.currentMission->pilot + pos + 1, strlen(game.currentMission->pilot) - pos - 1); memcpy(player->name, game.currentMission->pilot + pos + 1, strlen(game.currentMission->pilot) - pos - 1);
} }
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Pilot name = '%s'", player->name); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Pilot name = '%s'", player->name);
} }
void doPlayer(void) void doPlayer(void)
{ {
self = player; self = player;
rechargeBoostECM(); rechargeBoostECM();
if (game.currentMission->challengeData.isChallenge) if (game.currentMission->challengeData.isChallenge)
{ {
applyRestrictions(); applyRestrictions();
} }
if (player->alive == ALIVE_ALIVE && player->systemPower > 0) if (player->alive == ALIVE_ALIVE && player->systemPower > 0)
{ {
handleKeyboard(); handleKeyboard();
handleMouse(); handleMouse();
handleSuspicionLevel(); handleSuspicionLevel();
if (!player->target || player->target->health <= 0 || player->target->systemPower <= 0 || targetOutOfRange()) if (!player->target || player->target->health <= 0 || player->target->systemPower <= 0 || targetOutOfRange())
@ -157,22 +157,22 @@ void doPlayer(void)
if (!game.currentMission->challengeData.allowPlayerDeath) if (!game.currentMission->challengeData.allowPlayerDeath)
{ {
updateDeathStats(); updateDeathStats();
failMission(); failMission();
} }
} }
else if (!battle.isEpic) else if (!battle.isEpic)
{ {
updateDeathStats(); updateDeathStats();
failMission(); failMission();
} }
else if (player->health == -FPS) else if (player->health == -FPS)
{ {
updateDeathStats(); updateDeathStats();
updateCondition("PLAYER", TT_DESTROY); updateCondition("PLAYER", TT_DESTROY);
if (battle.status == MS_IN_PROGRESS) if (battle.status == MS_IN_PROGRESS)
{ {
initPlayerSelect(); initPlayerSelect();
@ -189,7 +189,7 @@ void doPlayer(void)
{ {
player->missiles = 999; player->missiles = 999;
} }
/* really only used in challenge mode */ /* really only used in challenge mode */
if (player->systemPower <= 0 && battle.status == MS_IN_PROGRESS) if (player->systemPower <= 0 && battle.status == MS_IN_PROGRESS)
{ {
@ -209,7 +209,7 @@ void doPlayer(void)
static void updateDeathStats(void) static void updateDeathStats(void)
{ {
battle.stats[STAT_PLAYER_KILLED]++; battle.stats[STAT_PLAYER_KILLED]++;
/* the player is known as "Player", so we need to check the craft they were assigned to */ /* the player is known as "Player", so we need to check the craft they were assigned to */
if (strcmp(game.currentMission->craft, "ATAF") == 0) if (strcmp(game.currentMission->craft, "ATAF") == 0)
{ {
@ -220,14 +220,14 @@ static void updateDeathStats(void)
static void rechargeBoostECM(void) static void rechargeBoostECM(void)
{ {
int boostTimer, ecmTimer; int boostTimer, ecmTimer;
boostTimer = battle.boostTimer; boostTimer = battle.boostTimer;
battle.boostTimer = MIN(battle.boostTimer + 1, BOOST_RECHARGE_TIME); battle.boostTimer = MIN(battle.boostTimer + 1, BOOST_RECHARGE_TIME);
if (boostTimer < BOOST_RECHARGE_TIME && battle.boostTimer == BOOST_RECHARGE_TIME) if (boostTimer < BOOST_RECHARGE_TIME && battle.boostTimer == BOOST_RECHARGE_TIME)
{ {
playSound(SND_RECHARGED); playSound(SND_RECHARGED);
} }
ecmTimer = battle.ecmTimer; ecmTimer = battle.ecmTimer;
battle.ecmTimer = MIN(battle.ecmTimer + 1, ECM_RECHARGE_TIME); battle.ecmTimer = MIN(battle.ecmTimer + 1, ECM_RECHARGE_TIME);
if (ecmTimer < ECM_RECHARGE_TIME && battle.ecmTimer == ECM_RECHARGE_TIME) if (ecmTimer < ECM_RECHARGE_TIME && battle.ecmTimer == ECM_RECHARGE_TIME)
@ -247,17 +247,17 @@ static void applyRestrictions(void)
{ {
player->missiles = 0; player->missiles = 0;
} }
if (game.currentMission->challengeData.noBoost) if (game.currentMission->challengeData.noBoost)
{ {
battle.boostTimer = 0; battle.boostTimer = 0;
} }
if (game.currentMission->challengeData.noECM) if (game.currentMission->challengeData.noECM)
{ {
battle.ecmTimer = 0; battle.ecmTimer = 0;
} }
if (game.currentMission->challengeData.noGuns) if (game.currentMission->challengeData.noGuns)
{ {
player->reload = 1; player->reload = 1;
@ -342,7 +342,7 @@ static void handleKeyboard(void)
static void handleMouse(void) static void handleMouse(void)
{ {
faceMouse(); faceMouse();
if (battle.status == MS_IN_PROGRESS) if (battle.status == MS_IN_PROGRESS)
{ {
if (isControl(CONTROL_FIRE) && !player->reload && player->guns[0].type) if (isControl(CONTROL_FIRE) && !player->reload && player->guns[0].type)
@ -355,13 +355,13 @@ static void handleMouse(void)
{ {
fireRocket(player); fireRocket(player);
} }
if (battle.hasSuspicionLevel && !battle.numEnemies && !battle.suspicionCoolOff) if (battle.hasSuspicionLevel && !battle.numEnemies && !battle.suspicionCoolOff)
{ {
battle.suspicionLevel += (MAX_SUSPICION_LEVEL * 0.05); battle.suspicionLevel += (MAX_SUSPICION_LEVEL * 0.05);
} }
} }
if (isControl(CONTROL_ACCELERATE)) if (isControl(CONTROL_ACCELERATE))
{ {
if (battle.boostTimer > BOOST_FINISHED_TIME || game.currentMission->challengeData.noBoost) if (battle.boostTimer > BOOST_FINISHED_TIME || game.currentMission->challengeData.noBoost)
@ -369,25 +369,25 @@ static void handleMouse(void)
applyFighterThrust(); applyFighterThrust();
} }
} }
if (isControl(CONTROL_MISSILE)) if (isControl(CONTROL_MISSILE))
{ {
preFireMissile(); preFireMissile();
app.mouse.button[SDL_BUTTON_MIDDLE] = 0; app.mouse.button[SDL_BUTTON_MIDDLE] = 0;
} }
if (isControl(CONTROL_GUNS)) if (isControl(CONTROL_GUNS))
{ {
switchGuns(); switchGuns();
app.mouse.button[SDL_BUTTON_X1] = 0; app.mouse.button[SDL_BUTTON_X1] = 0;
} }
if (isControl(CONTROL_RADAR)) if (isControl(CONTROL_RADAR))
{ {
cycleRadarZoom(); cycleRadarZoom();
app.mouse.button[SDL_BUTTON_X2] = 0; app.mouse.button[SDL_BUTTON_X2] = 0;
} }
} }
@ -425,14 +425,14 @@ static void preFireMissile(void)
else else
{ {
playSound(SND_GUI_DENIED); playSound(SND_GUI_DENIED);
addHudMessage(colors.white, _("Target not in range")); addHudMessage(colors.white, _("Target not in range"));
} }
} }
else if (!player->missiles) else if (!player->missiles)
{ {
addHudMessage(colors.white, _("Out of missiles")); addHudMessage(colors.white, _("Out of missiles"));
playSound(SND_NO_MISSILES); playSound(SND_NO_MISSILES);
} }
} }
@ -440,11 +440,11 @@ static void preFireMissile(void)
static void initPlayerSelect(void) static void initPlayerSelect(void)
{ {
Entity *e; Entity *e;
memset(&availablePlayerUnits, 0, sizeof(Entity*) * MAX_SELECTABLE_PLAYERS); memset(&availablePlayerUnits, 0, sizeof(Entity*) * MAX_SELECTABLE_PLAYERS);
selectedPlayerIndex = 0; selectedPlayerIndex = 0;
if (battle.epicLives == 0 || (battle.epicLives > 0 && --battle.epicLives > 0)) if (battle.epicLives == 0 || (battle.epicLives > 0 && --battle.epicLives > 0))
{ {
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
@ -465,7 +465,7 @@ static void initPlayerSelect(void)
else else
{ {
battle.isEpic = 0; battle.isEpic = 0;
if (battle.epicKills > 0 && battle.stats[STAT_ENEMIES_KILLED_PLAYER] < battle.epicKills) if (battle.epicKills > 0 && battle.stats[STAT_ENEMIES_KILLED_PLAYER] < battle.epicKills)
{ {
battle.unwinnable = 0; battle.unwinnable = 0;
@ -480,23 +480,23 @@ void doPlayerSelect(void)
if (isControl(CONTROL_PREV_FIGHTER)) if (isControl(CONTROL_PREV_FIGHTER))
{ {
selectNewPlayer(-1); selectNewPlayer(-1);
clearControl(CONTROL_PREV_FIGHTER); clearControl(CONTROL_PREV_FIGHTER);
} }
if (isControl(CONTROL_NEXT_FIGHTER)) if (isControl(CONTROL_NEXT_FIGHTER))
{ {
selectNewPlayer(1); selectNewPlayer(1);
clearControl(CONTROL_NEXT_FIGHTER); clearControl(CONTROL_NEXT_FIGHTER);
} }
if (player->health > 0 && isAcceptControl()) if (player->health > 0 && isAcceptControl())
{ {
battle.playerSelect = 0; battle.playerSelect = 0;
initPlayer(); initPlayer();
resetAcceptControls(); resetAcceptControls();
} }
} }
@ -504,7 +504,7 @@ void doPlayerSelect(void)
static void selectNewPlayer(int dir) static void selectNewPlayer(int dir)
{ {
player = NULL; player = NULL;
do do
{ {
selectedPlayerIndex += dir; selectedPlayerIndex += dir;
@ -554,7 +554,7 @@ static void activateECM(void)
addECMEffect(player); addECMEffect(player);
battle.stats[STAT_ECM]++; battle.stats[STAT_ECM]++;
if (battle.hasSuspicionLevel && !battle.numEnemies && !battle.suspicionCoolOff) if (battle.hasSuspicionLevel && !battle.numEnemies && !battle.suspicionCoolOff)
{ {
battle.suspicionLevel += (MAX_SUSPICION_LEVEL * 0.25); battle.suspicionLevel += (MAX_SUSPICION_LEVEL * 0.25);
@ -594,18 +594,18 @@ static void selectTarget(void)
i = 0; i = 0;
near = NULL; near = NULL;
memset(targets, 0, sizeof(Entity*) * MAX_SELECTABLE_TARGETS); memset(targets, 0, sizeof(Entity*) * MAX_SELECTABLE_TARGETS);
if (player->target && (!player->target->health || !player->target->systemPower)) if (player->target && (!player->target->health || !player->target->systemPower))
{ {
player->target = NULL; player->target = NULL;
} }
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (e->active && e != player && (e->flags & EF_TAKES_DAMAGE) && (!(e->flags & EF_NO_PLAYER_TARGET)) && e->side != player->side && e->alive == ALIVE_ALIVE && e->systemPower > 0 && i < MAX_SELECTABLE_TARGETS) if (e->active && e != player && (e->flags & EF_TAKES_DAMAGE) && (!(e->flags & EF_NO_PLAYER_TARGET)) && e->side != player->side && e->alive == ALIVE_ALIVE && e->systemPower > 0 && i < MAX_SELECTABLE_TARGETS)
{ {
dist = getDistance(player->x, player->y, e->x, e->y); dist = getDistance(player->x, player->y, e->x, e->y);
if (dist < closest) if (dist < closest)
{ {
near = e; near = e;
@ -693,13 +693,13 @@ static int isPriorityMissionTarget(Entity *e, int dist, int closest)
{ {
return 1; return 1;
} }
/* battle.missionTarget is not secondary, e is */ /* battle.missionTarget is not secondary, e is */
if ((battle.missionTarget->flags & EF_SECONDARY_TARGET) < (e->flags & EF_SECONDARY_TARGET)) if ((battle.missionTarget->flags & EF_SECONDARY_TARGET) < (e->flags & EF_SECONDARY_TARGET))
{ {
return 0; return 0;
} }
/* normal distance check */ /* normal distance check */
return dist < closest; return dist < closest;
} }
@ -707,9 +707,9 @@ static int isPriorityMissionTarget(Entity *e, int dist, int closest)
void setInitialPlayerAngle(void) void setInitialPlayerAngle(void)
{ {
Entity *e; Entity *e;
selectMissionTarget(); selectMissionTarget();
if (battle.missionTarget) if (battle.missionTarget)
{ {
player->angle = getAngle(player->x, player->y, battle.missionTarget->x, battle.missionTarget->y); player->angle = getAngle(player->x, player->y, battle.missionTarget->x, battle.missionTarget->y);
@ -717,7 +717,7 @@ void setInitialPlayerAngle(void)
else else
{ {
selectTarget(); selectTarget();
if (player->target) if (player->target)
{ {
player->angle = getAngle(player->x, player->y, player->target->x, player->target->y); player->angle = getAngle(player->x, player->y, player->target->x, player->target->y);
@ -730,7 +730,7 @@ void setInitialPlayerAngle(void)
} }
} }
} }
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
if (e->side == player->side) if (e->side == player->side)
@ -743,7 +743,7 @@ void setInitialPlayerAngle(void)
static void cycleRadarZoom(void) static void cycleRadarZoom(void)
{ {
battle.radarRange = (battle.radarRange + 1) % 3; battle.radarRange = (battle.radarRange + 1) % 3;
playSound(SND_ZOOM); playSound(SND_ZOOM);
} }
@ -780,12 +780,12 @@ void loadPlayer(cJSON *node)
player->x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH; player->x = (cJSON_GetObjectItem(node, "x")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_WIDTH;
player->y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT; player->y = (cJSON_GetObjectItem(node, "y")->valuedouble / BATTLE_AREA_CELLS) * BATTLE_AREA_HEIGHT;
} }
if (cJSON_GetObjectItem(node, "flags")) if (cJSON_GetObjectItem(node, "flags"))
{ {
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags); flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
} }
if (flags != -1) if (flags != -1)
{ {
if (addFlags) if (addFlags)

View File

@ -36,7 +36,7 @@ void initQuadtree(Quadtree *root)
{ {
Quadtree *node; Quadtree *node;
int i, w, h; int i, w, h;
/* entire battlefield */ /* entire battlefield */
if (root->depth == 0) if (root->depth == 0)
{ {
@ -45,16 +45,16 @@ void initQuadtree(Quadtree *root)
root->capacity = QT_INITIAL_CAPACITY; root->capacity = QT_INITIAL_CAPACITY;
root->ents = malloc(sizeof(Entity*) * root->capacity); root->ents = malloc(sizeof(Entity*) * root->capacity);
memset(root->ents, 0, sizeof(Entity*) * root->capacity); memset(root->ents, 0, sizeof(Entity*) * root->capacity);
cIndex = 0; cIndex = 0;
cCapacity = QT_INITIAL_CAPACITY; cCapacity = QT_INITIAL_CAPACITY;
candidates = malloc(sizeof(Entity*) * cCapacity); candidates = malloc(sizeof(Entity*) * cCapacity);
memset(candidates, 0, sizeof(Entity*) * cCapacity); memset(candidates, 0, sizeof(Entity*) * cCapacity);
} }
w = root->w / 2; w = root->w / 2;
h = root->h / 2; h = root->h / 2;
if (root->depth + 1 < QT_MAX_DEPTH) if (root->depth + 1 < QT_MAX_DEPTH)
{ {
for (i = 0 ; i < 4 ; i++) for (i = 0 ; i < 4 ; i++)
@ -62,12 +62,12 @@ void initQuadtree(Quadtree *root)
node = malloc(sizeof(Quadtree)); node = malloc(sizeof(Quadtree));
memset(node, 0, sizeof(Quadtree)); memset(node, 0, sizeof(Quadtree));
root->node[i] = node; root->node[i] = node;
node->depth = root->depth + 1; node->depth = root->depth + 1;
node->capacity = QT_INITIAL_CAPACITY; node->capacity = QT_INITIAL_CAPACITY;
node->ents = malloc(sizeof(Entity*) * node->capacity); node->ents = malloc(sizeof(Entity*) * node->capacity);
memset(node->ents, 0, sizeof(Entity*) * node->capacity); memset(node->ents, 0, sizeof(Entity*) * node->capacity);
if (i == 0) if (i == 0)
{ {
node->x = root->x; node->x = root->x;
@ -96,7 +96,7 @@ void initQuadtree(Quadtree *root)
node->w = w; node->w = w;
node->h = h; node->h = h;
} }
initQuadtree(node); initQuadtree(node);
} }
} }
@ -105,36 +105,36 @@ void initQuadtree(Quadtree *root)
void addToQuadtree(Entity *e, Quadtree *root) void addToQuadtree(Entity *e, Quadtree *root)
{ {
int index; int index;
root->addedTo = 1; root->addedTo = 1;
if (root->node[0]) if (root->node[0])
{ {
index = getIndex(root, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h); index = getIndex(root, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h);
if (index != -1) if (index != -1)
{ {
addToQuadtree(e, root->node[index]); addToQuadtree(e, root->node[index]);
return; return;
} }
} }
if (root->numEnts == root->capacity) if (root->numEnts == root->capacity)
{ {
resizeQTEntCapacity(root); resizeQTEntCapacity(root);
} }
root->ents[root->numEnts++] = e; root->ents[root->numEnts++] = e;
} }
static void resizeQTEntCapacity(Quadtree *root) static void resizeQTEntCapacity(Quadtree *root)
{ {
int n; int n;
n = root->capacity + QT_INITIAL_CAPACITY; n = root->capacity + QT_INITIAL_CAPACITY;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing QT node: %d -> %d", root->capacity, n); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing QT node: %d -> %d", root->capacity, n);
root->ents = resize(root->ents, sizeof(Entity*) * root->capacity, sizeof(Entity*) * n); root->ents = resize(root->ents, sizeof(Entity*) * root->capacity, sizeof(Entity*) * n);
root->capacity = n; root->capacity = n;
} }
@ -177,26 +177,26 @@ static int getIndex(Quadtree *root, int x, int y, int w, int h)
void removeFromQuadtree(Entity *e, Quadtree *root) void removeFromQuadtree(Entity *e, Quadtree *root)
{ {
int index; int index;
if (root->addedTo) if (root->addedTo)
{ {
if (root->node[0]) if (root->node[0])
{ {
index = getIndex(root, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h); index = getIndex(root, e->x - (e->w / 2), e->y - (e->h / 2), e->w, e->h);
if (index != -1) if (index != -1)
{ {
removeFromQuadtree(e, root->node[index]); removeFromQuadtree(e, root->node[index]);
return; return;
} }
} }
removeEntity(e, root); removeEntity(e, root);
if (root->numEnts == 0) if (root->numEnts == 0)
{ {
root->addedTo = 0; root->addedTo = 0;
if (root->node[0]) if (root->node[0])
{ {
root->addedTo = root->node[0]->addedTo || root->node[1]->addedTo || root->node[2]->addedTo || root->node[3]->addedTo; root->addedTo = root->node[0]->addedTo || root->node[1]->addedTo || root->node[2]->addedTo || root->node[3]->addedTo;
@ -208,9 +208,9 @@ void removeFromQuadtree(Entity *e, Quadtree *root)
static void removeEntity(Entity *e, Quadtree *root) static void removeEntity(Entity *e, Quadtree *root)
{ {
int i, n; int i, n;
n = root->numEnts; n = root->numEnts;
for (i = 0 ; i < root->capacity ; i++) for (i = 0 ; i < root->capacity ; i++)
{ {
if (root->ents[i] == e) if (root->ents[i] == e)
@ -219,7 +219,7 @@ static void removeEntity(Entity *e, Quadtree *root)
root->numEnts--; root->numEnts--;
} }
} }
qsort(root->ents, n, sizeof(Entity*), candidatesComparator); qsort(root->ents, n, sizeof(Entity*), candidatesComparator);
} }
@ -227,9 +227,9 @@ Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore)
{ {
cIndex = 0; cIndex = 0;
memset(candidates, 0, sizeof(Entity*) * cCapacity); memset(candidates, 0, sizeof(Entity*) * cCapacity);
getAllEntsWithinNode(x, y, w, h, ignore, &battle.quadtree); getAllEntsWithinNode(x, y, w, h, ignore, &battle.quadtree);
return candidates; return candidates;
} }
@ -241,13 +241,13 @@ Entity **getAllEntsInRadius(int x, int y, int radius, Entity *ignore)
static void getAllEntsWithinNode(int x, int y, int w, int h, Entity *ignore, Quadtree *root) static void getAllEntsWithinNode(int x, int y, int w, int h, Entity *ignore, Quadtree *root)
{ {
int index, i; int index, i;
if (root->addedTo) if (root->addedTo)
{ {
if (root->node[0]) if (root->node[0])
{ {
index = getIndex(root, x, y, w, h); index = getIndex(root, x, y, w, h);
if (index != -1) if (index != -1)
{ {
getAllEntsWithinNode(x, y, w, h, ignore, root->node[index]); getAllEntsWithinNode(x, y, w, h, ignore, root->node[index]);
@ -260,11 +260,11 @@ static void getAllEntsWithinNode(int x, int y, int w, int h, Entity *ignore, Qua
} }
} }
} }
for (i = 0 ; i < root->numEnts ; i++) for (i = 0 ; i < root->numEnts ; i++)
{ {
candidates[cIndex++] = root->ents[i]; candidates[cIndex++] = root->ents[i];
if (cIndex == cCapacity) if (cIndex == cCapacity)
{ {
resizeCandidates(); resizeCandidates();
@ -276,11 +276,11 @@ static void getAllEntsWithinNode(int x, int y, int w, int h, Entity *ignore, Qua
static void resizeCandidates(void) static void resizeCandidates(void)
{ {
int n; int n;
n = cCapacity + QT_INITIAL_CAPACITY; n = cCapacity + QT_INITIAL_CAPACITY;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing candidates: %d -> %d", cCapacity, n); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Resizing candidates: %d -> %d", cCapacity, n);
candidates = resize(candidates, sizeof(Entity*) * cCapacity, sizeof(Entity*) * n); candidates = resize(candidates, sizeof(Entity*) * cCapacity, sizeof(Entity*) * n);
cCapacity = n; cCapacity = n;
} }
@ -288,11 +288,11 @@ static void resizeCandidates(void)
void destroyQuadtree(void) void destroyQuadtree(void)
{ {
destroyQuadtreeNode(&battle.quadtree); destroyQuadtreeNode(&battle.quadtree);
if (candidates) if (candidates)
{ {
free(candidates); free(candidates);
candidates = NULL; candidates = NULL;
} }
} }
@ -300,19 +300,19 @@ void destroyQuadtree(void)
static void destroyQuadtreeNode(Quadtree *root) static void destroyQuadtreeNode(Quadtree *root)
{ {
int i; int i;
free(root->ents); free(root->ents);
root->ents = NULL; root->ents = NULL;
if (root->node[0]) if (root->node[0])
{ {
for (i = 0 ; i < 4 ; i++) for (i = 0 ; i < 4 ; i++)
{ {
destroyQuadtreeNode(root->node[i]); destroyQuadtreeNode(root->node[i]);
free(root->node[i]); free(root->node[i]);
root->node[i] = NULL; root->node[i] = NULL;
} }
} }
@ -322,7 +322,7 @@ static int candidatesComparator(const void *a, const void *b)
{ {
Entity *e1 = *((Entity**)a); Entity *e1 = *((Entity**)a);
Entity *e2 = *((Entity**)b); Entity *e2 = *((Entity**)b);
if (!e1) if (!e1)
{ {
return 1; return 1;

View File

@ -29,10 +29,10 @@ void initRadar(void)
{ {
radarTexture = getAtlasImage("gfx/hud/radar.png"); radarTexture = getAtlasImage("gfx/hud/radar.png");
radarWarningTexture = getAtlasImage("gfx/hud/radarWarning.png"); radarWarningTexture = getAtlasImage("gfx/hud/radarWarning.png");
/* medium range by default */ /* medium range by default */
battle.radarRange = 1; battle.radarRange = 1;
CAUTION_TEXT = _("Caution: Leaving battle area - turn around."); CAUTION_TEXT = _("Caution: Leaving battle area - turn around.");
} }
@ -41,34 +41,34 @@ void drawRadar(void)
SDL_Rect r; SDL_Rect r;
Entity *e; Entity *e;
int dist, inRange, blink; int dist, inRange, blink;
blit(radarTexture, app.winWidth - 85, app.winHeight - 85, 1); blit(radarTexture, app.winWidth - 85, app.winHeight - 85, 1);
drawText(app.winWidth - 160, app.winHeight - 30, 14, TA_RIGHT, colors.white, "%dx", battle.radarRange + 1); drawText(app.winWidth - 160, app.winHeight - 30, 14, TA_RIGHT, colors.white, "%dx", battle.radarRange + 1);
r.w = r.h = 3; r.w = r.h = 3;
blink = battle.stats[STAT_TIME] % 60 < 30; blink = battle.stats[STAT_TIME] % 60 < 30;
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{ {
dist = getDistance(e->x, e->y, player->x, player->y); dist = getDistance(e->x, e->y, player->x, player->y);
if (e->active) if (e->active)
{ {
inRange = (!(e->flags & EF_SHORT_RADAR_RANGE)) ? (dist / radarRanges[battle.radarRange]) < 70 : dist < 500; inRange = (!(e->flags & EF_SHORT_RADAR_RANGE)) ? (dist / radarRanges[battle.radarRange]) < 70 : dist < 500;
if (inRange) if (inRange)
{ {
r.x = app.winWidth - 85; r.x = app.winWidth - 85;
r.y = app.winHeight - 85; r.y = app.winHeight - 85;
r.x -= (player->x - e->x) / radarRanges[battle.radarRange]; r.x -= (player->x - e->x) / radarRanges[battle.radarRange];
r.y -= (player->y - e->y) / radarRanges[battle.radarRange]; r.y -= (player->y - e->y) / radarRanges[battle.radarRange];
r.x--; r.x--;
r.y--; r.y--;
if (e->side == SIDE_NONE) if (e->side == SIDE_NONE)
{ {
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
@ -81,25 +81,25 @@ void drawRadar(void)
{ {
SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255);
} }
if (e->type == ET_MINE || e->type == ET_SHADOW_MINE || e->type == ET_JUMPGATE || (e->owner && e->owner->type == ET_JUMPGATE)) if (e->type == ET_MINE || e->type == ET_SHADOW_MINE || e->type == ET_JUMPGATE || (e->owner && e->owner->type == ET_JUMPGATE))
{ {
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
} }
if (blink) if (blink)
{ {
if (e == player->target || e == battle.missionTarget) if (e == player->target || e == battle.missionTarget)
{ {
SDL_SetRenderDrawColor(app.renderer, 255, 255, 0, 255); SDL_SetRenderDrawColor(app.renderer, 255, 255, 0, 255);
} }
if (e->flags & EF_DISABLED) if (e->flags & EF_DISABLED)
{ {
SDL_SetRenderDrawColor(app.renderer, 0, 192, 255, 255); SDL_SetRenderDrawColor(app.renderer, 0, 192, 255, 255);
} }
} }
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
} }
} }
@ -109,39 +109,39 @@ void drawRadar(void)
void drawRadarRangeWarning(void) void drawRadarRangeWarning(void)
{ {
int x, y, leaving; int x, y, leaving;
x = (int)player->x / (app.winWidth / 2); x = (int)player->x / (app.winWidth / 2);
y = (int)player->y / (app.winHeight / 2); y = (int)player->y / (app.winHeight / 2);
leaving = 0; leaving = 0;
if (x <= 2 && player->dx < 0) if (x <= 2 && player->dx < 0)
{ {
blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 270); blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 270);
leaving = 1; leaving = 1;
} }
if (y <= 3 && player->dy < 0) if (y <= 3 && player->dy < 0)
{ {
blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 0); blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 0);
leaving = 1; leaving = 1;
} }
if (x >= BATTLE_AREA_CELLS - 2 && player->dx > 0) if (x >= BATTLE_AREA_CELLS - 2 && player->dx > 0)
{ {
blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 90); blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 90);
leaving = 1; leaving = 1;
} }
if (y >= BATTLE_AREA_CELLS - 3 && player->dy > 0) if (y >= BATTLE_AREA_CELLS - 3 && player->dy > 0)
{ {
blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 180); blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 180);
leaving = 1; leaving = 1;
} }
if (leaving && battle.stats[STAT_TIME] % FPS < 40) if (leaving && battle.stats[STAT_TIME] % FPS < 40)
{ {
drawText(app.winWidth / 2, app.winHeight - 30, 14, TA_CENTER, colors.white, CAUTION_TEXT); drawText(app.winWidth / 2, app.winHeight - 30, 14, TA_CENTER, colors.white, CAUTION_TEXT);

View File

@ -24,35 +24,35 @@ void attachRope(void)
{ {
int i, distance; int i, distance;
Entity *e, **candidates; Entity *e, **candidates;
if ((self->flags & EF_HAS_ROPE) && self->towing == NULL) if ((self->flags & EF_HAS_ROPE) && self->towing == NULL)
{ {
candidates = getAllEntsInRadius(self->x, self->y, self->separationRadius, self); candidates = getAllEntsInRadius(self->x, self->y, self->separationRadius, self);
for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i]) for (i = 0, e = candidates[i] ; e != NULL ; e = candidates[++i])
{ {
if (!e->owner && e->type == ET_FIGHTER && (e->flags & EF_DISABLED) && (e->flags & EF_ROPED_ATTACHED) == 0 && e->alive == ALIVE_ALIVE) if (!e->owner && e->type == ET_FIGHTER && (e->flags & EF_DISABLED) && (e->flags & EF_ROPED_ATTACHED) == 0 && e->alive == ALIVE_ALIVE)
{ {
distance = getDistance(e->x, e->y, self->x, self->y); distance = getDistance(e->x, e->y, self->x, self->y);
if (distance > 0 && distance <= self->separationRadius) if (distance > 0 && distance <= self->separationRadius)
{ {
self->towing = e; self->towing = e;
self->aiFlags |= AIF_GOAL_JUMPGATE; self->aiFlags |= AIF_GOAL_JUMPGATE;
e->owner = self; e->owner = self;
e->speed = 1; e->speed = 1;
e->flags |= EF_RETREATING; e->flags |= EF_RETREATING;
e->flags |= EF_ROPED_ATTACHED; e->flags |= EF_ROPED_ATTACHED;
runScriptFunction("TOWING %s", e->name); runScriptFunction("TOWING %s", e->name);
if (self == player) if (self == player)
{ {
battle.stats[STAT_NUM_TOWED]++; battle.stats[STAT_NUM_TOWED]++;
addHudMessage(colors.white, _("Tow rope attached")); addHudMessage(colors.white, _("Tow rope attached"));
} }
playBattleSound(SND_TOW_ROPE, e->x, e->y); playBattleSound(SND_TOW_ROPE, e->x, e->y);
} }
} }
@ -64,23 +64,23 @@ void doRope(Entity *owner)
{ {
float dx, dy, angle, force; float dx, dy, angle, force;
int distance; int distance;
if (owner->towing) if (owner->towing)
{ {
distance = getDistance(owner->towing->x, owner->towing->y, owner->x, owner->y); distance = getDistance(owner->towing->x, owner->towing->y, owner->x, owner->y);
if (distance > ROPE_DISTANCE) if (distance > ROPE_DISTANCE)
{ {
angle = getAngle(owner->x, owner->y, owner->towing->x, owner->towing->y); angle = getAngle(owner->x, owner->y, owner->towing->x, owner->towing->y);
dx = sin(TO_RAIDANS(angle)); dx = sin(TO_RAIDANS(angle));
dy = -cos(TO_RAIDANS(angle)); dy = -cos(TO_RAIDANS(angle));
force = (distance - ROPE_DISTANCE) * 0.02; force = (distance - ROPE_DISTANCE) * 0.02;
owner->towing->dx -= (dx * force); owner->towing->dx -= (dx * force);
owner->towing->dy -= (dy * force); owner->towing->dy -= (dy * force);
} }
owner->towing->dx *= 0.985; owner->towing->dx *= 0.985;
owner->towing->dy *= 0.985; owner->towing->dy *= 0.985;
} }
@ -91,7 +91,7 @@ void drawRope(Entity *e)
if (e->towing) if (e->towing)
{ {
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255); SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
SDL_RenderDrawLine(app.renderer, e->x - battle.camera.x, e->y - battle.camera.y, e->towing->x - battle.camera.x, e->towing->y - battle.camera.y); SDL_RenderDrawLine(app.renderer, e->x - battle.camera.x, e->y - battle.camera.y, e->towing->x - battle.camera.x, e->towing->y - battle.camera.y);
} }
} }
@ -104,7 +104,7 @@ void cutRope(Entity *e)
e->owner->towing = NULL; e->owner->towing = NULL;
e->owner->aiFlags &= ~AIF_GOAL_JUMPGATE; e->owner->aiFlags &= ~AIF_GOAL_JUMPGATE;
} }
/* tug is dead - reset thing being tugged */ /* tug is dead - reset thing being tugged */
if (e->towing) if (e->towing)
{ {

View File

@ -31,16 +31,16 @@ static int runScript;
void initScript(cJSON *root) void initScript(cJSON *root)
{ {
cJSON *function; cJSON *function;
memset(&head, 0, sizeof(ScriptRunner)); memset(&head, 0, sizeof(ScriptRunner));
tail = &head; tail = &head;
rootJSON = root; rootJSON = root;
runScript = 0; runScript = 0;
scriptJSON = cJSON_GetObjectItem(root, "script"); scriptJSON = cJSON_GetObjectItem(root, "script");
if (scriptJSON) if (scriptJSON)
{ {
function = scriptJSON->child; function = scriptJSON->child;
@ -48,10 +48,10 @@ void initScript(cJSON *root)
while (function) while (function)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Found script function: '%s'", cJSON_GetObjectItem(function, "function")->valuestring); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Found script function: '%s'", cJSON_GetObjectItem(function, "function")->valuestring);
function = function->next; function = function->next;
} }
runScript = 1; runScript = 1;
} }
} }
@ -128,7 +128,7 @@ void runScriptFunction(const char *format, ...)
tail = scriptRunner; tail = scriptRunner;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Running script '%s'", funcNameBuffer); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Running script '%s'", funcNameBuffer);
return; return;
} }
@ -284,25 +284,25 @@ static void executeNextLine(ScriptRunner *runner)
void cancelScript(void) void cancelScript(void)
{ {
ScriptRunner *runner; ScriptRunner *runner;
while (head.next) while (head.next)
{ {
runner = head.next; runner = head.next;
head.next = runner->next; head.next = runner->next;
free(runner); free(runner);
} }
tail = &head; tail = &head;
} }
void destroyScript(void) void destroyScript(void)
{ {
ScriptRunner *scriptRunner; ScriptRunner *scriptRunner;
if (rootJSON) if (rootJSON)
{ {
cJSON_Delete(rootJSON); cJSON_Delete(rootJSON);
rootJSON = NULL; rootJSON = NULL;
} }
@ -314,6 +314,6 @@ void destroyScript(void)
} }
tail = &head; tail = &head;
scriptJSON = NULL; scriptJSON = NULL;
} }

View File

@ -27,27 +27,27 @@ void doSpawners(void)
char *type; char *type;
int i, num, addFlags, addAIFlags; int i, num, addFlags, addAIFlags;
long flags, aiFlags; long flags, aiFlags;
for (s = battle.spawnerHead.next ; s != NULL ; s = s->next) for (s = battle.spawnerHead.next ; s != NULL ; s = s->next)
{ {
if (s->active && --s->time <= 0) if (s->active && --s->time <= 0)
{ {
aiFlags = flags = -1; aiFlags = flags = -1;
num = s->step; num = s->step;
if (s->total != -1) if (s->total != -1)
{ {
num = MIN(s->step, s->total); num = MIN(s->step, s->total);
s->total -= num; s->total -= num;
} }
if (s->side != SIDE_ALLIES) if (s->side != SIDE_ALLIES)
{ {
battle.numInitialEnemies += num; battle.numInitialEnemies += num;
} }
if (strlen(s->flags)) if (strlen(s->flags))
{ {
flags = flagsToLong(s->flags, &addFlags); flags = flagsToLong(s->flags, &addFlags);
@ -57,15 +57,15 @@ void doSpawners(void)
{ {
aiFlags = flagsToLong(s->aiFlags, &addAIFlags); aiFlags = flagsToLong(s->aiFlags, &addAIFlags);
} }
for (i = 0 ; i < num ; i++) for (i = 0 ; i < num ; i++)
{ {
type = s->types[rand() % s->numTypes]; type = s->types[rand() % s->numTypes];
e = spawnFighter(type, 0, 0, s->side); e = spawnFighter(type, 0, 0, s->side);
e->spawned = 1; e->spawned = 1;
if (s->offscreen) if (s->offscreen)
{ {
e->x = player->x; e->x = player->x;
@ -76,10 +76,10 @@ void doSpawners(void)
e->x = rand() % 2 ? 0 : BATTLE_AREA_WIDTH; e->x = rand() % 2 ? 0 : BATTLE_AREA_WIDTH;
e->y = rand() % 2 ? 0 : BATTLE_AREA_HEIGHT; e->y = rand() % 2 ? 0 : BATTLE_AREA_HEIGHT;
} }
e->x += (rand() % 2) ? -SCREEN_WIDTH * 3 : SCREEN_WIDTH * 3; e->x += (rand() % 2) ? -SCREEN_WIDTH * 3 : SCREEN_WIDTH * 3;
e->y += (rand() % 2) ? -SCREEN_HEIGHT * 3 : SCREEN_HEIGHT * 3; e->y += (rand() % 2) ? -SCREEN_HEIGHT * 3 : SCREEN_HEIGHT * 3;
if (flags != -1) if (flags != -1)
{ {
if (addFlags) if (addFlags)
@ -91,7 +91,7 @@ void doSpawners(void)
e->flags = flags; e->flags = flags;
} }
} }
if (aiFlags != -1) if (aiFlags != -1)
{ {
if (addAIFlags) if (addAIFlags)
@ -104,7 +104,7 @@ void doSpawners(void)
} }
} }
} }
s->time = s->interval; s->time = s->interval;
} }
} }
@ -127,12 +127,12 @@ void activateTrespasserSpawner(void)
{ {
Spawner *s; Spawner *s;
char types[MAX_DESCRIPTION_LENGTH]; char types[MAX_DESCRIPTION_LENGTH];
s = malloc(sizeof(Spawner)); s = malloc(sizeof(Spawner));
memset(s, 0, sizeof(Spawner)); memset(s, 0, sizeof(Spawner));
battle.spawnerTail->next = s; battle.spawnerTail->next = s;
battle.spawnerTail = s; battle.spawnerTail = s;
STRNCPY(types, "Jackal;Mantis;Sphinx;Scarab", MAX_DESCRIPTION_LENGTH); STRNCPY(types, "Jackal;Mantis;Sphinx;Scarab", MAX_DESCRIPTION_LENGTH);
s->types = toTypeArray(types, &s->numTypes); s->types = toTypeArray(types, &s->numTypes);

View File

@ -25,15 +25,15 @@ static Star stars[MAX_STARS];
void initStars(void) void initStars(void)
{ {
int i; int i;
memset(stars, 0, sizeof(Star) * MAX_STARS); memset(stars, 0, sizeof(Star) * MAX_STARS);
for (i = 0 ; i < MAX_STARS ; i++) for (i = 0 ; i < MAX_STARS ; i++)
{ {
stars[i].x = rand() % app.winWidth; stars[i].x = rand() % app.winWidth;
stars[i].y = rand() % app.winHeight; stars[i].y = rand() % app.winHeight;
stars[i].speed = 5 + rand() % 35; stars[i].speed = 5 + rand() % 35;
stars[i].speed *= 0.1; stars[i].speed *= 0.1;
} }
} }
@ -41,12 +41,12 @@ void initStars(void)
void doStars(float dx, float dy) void doStars(float dx, float dy)
{ {
int i; int i;
for (i = 0 ; i < MAX_STARS ; i++) for (i = 0 ; i < MAX_STARS ; i++)
{ {
stars[i].x -= (dx * stars[i].speed); stars[i].x -= (dx * stars[i].speed);
stars[i].y -= (dy * stars[i].speed); stars[i].y -= (dy * stars[i].speed);
stars[i].x = mod(stars[i].x, app.winWidth - 1); stars[i].x = mod(stars[i].x, app.winWidth - 1);
stars[i].y = mod(stars[i].y, app.winHeight - 1); stars[i].y = mod(stars[i].y, app.winHeight - 1);
} }
@ -56,15 +56,15 @@ void drawStars(void)
{ {
int i; int i;
int c; int c;
for (i = 0 ; i < MAX_STARS ; i++) for (i = 0 ; i < MAX_STARS ; i++)
{ {
c = 64 * stars[i].speed; c = 64 * stars[i].speed;
SDL_SetRenderDrawColor(app.renderer, c, c, c, 255); SDL_SetRenderDrawColor(app.renderer, c, c, c, 255);
SDL_RenderDrawPoint(app.renderer, stars[i].x, stars[i].y); SDL_RenderDrawPoint(app.renderer, stars[i].x, stars[i].y);
if (c >= 240) if (c >= 240)
{ {
SDL_RenderDrawPoint(app.renderer, stars[i].x + 1, stars[i].y + 1); SDL_RenderDrawPoint(app.renderer, stars[i].x + 1, stars[i].y + 1);

View File

@ -37,7 +37,7 @@ void resetWaypoints(void)
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->id = waypointId;
waypoint->type = ET_WAYPOINT; waypoint->type = ET_WAYPOINT;
@ -46,43 +46,43 @@ Entity *spawnWaypoint(void)
waypoint->texture = getAtlasImage("gfx/entities/waypoint.png"); waypoint->texture = getAtlasImage("gfx/entities/waypoint.png");
waypoint->flags = EF_NO_MT_BOX+EF_MISSION_TARGET+EF_NO_HEALTH_BAR; waypoint->flags = EF_NO_MT_BOX+EF_MISSION_TARGET+EF_NO_HEALTH_BAR;
waypoint->action = think; waypoint->action = think;
waypoint->w = waypoint->texture->rect.w; waypoint->w = waypoint->texture->rect.w;
waypoint->h = waypoint->texture->rect.h; waypoint->h = waypoint->texture->rect.h;
waypointId++; waypointId++;
return waypoint; return waypoint;
} }
static void think(void) static void think(void)
{ {
self->angle += 0.25; self->angle += 0.25;
if (self->angle >= 360) if (self->angle >= 360)
{ {
self->angle -= 360; self->angle -= 360;
} }
if (--self->aiActionTime <= 0) if (--self->aiActionTime <= 0)
{ {
self->aiActionTime = 0; self->aiActionTime = 0;
if (self->health && player->alive == ALIVE_ALIVE && getDistance(player->x, player->y, self->x, self->y) <= 128 && isCurrentObjective() && teamMatesClose()) if (self->health && player->alive == ALIVE_ALIVE && getDistance(player->x, player->y, self->x, self->y) <= 128 && isCurrentObjective() && teamMatesClose())
{ {
self->health = 0; self->health = 0;
updateObjective("Waypoint", TT_WAYPOINT); updateObjective("Waypoint", TT_WAYPOINT);
runScriptFunction(self->name); runScriptFunction(self->name);
if (battle.waypointAutoAdvance) if (battle.waypointAutoAdvance)
{ {
activateNextWaypoint(); activateNextWaypoint();
} }
battle.stats[STAT_WAYPOINTS_VISITED]++; battle.stats[STAT_WAYPOINTS_VISITED]++;
playSound(SND_WAYPOINT); playSound(SND_WAYPOINT);
} }
} }
@ -91,28 +91,28 @@ static void think(void)
static int isCurrentObjective(void) static int isCurrentObjective(void)
{ {
int numActiveObjectives = battle.numObjectivesTotal - battle.numObjectivesComplete; int numActiveObjectives = battle.numObjectivesTotal - battle.numObjectivesComplete;
if (numActiveObjectives > 1) if (numActiveObjectives > 1)
{ {
addHudMessage(colors.cyan, _("Cannot activate waypoint - outstanding objectives not yet complete")); addHudMessage(colors.cyan, _("Cannot activate waypoint - outstanding objectives not yet complete"));
self->aiActionTime = FPS; self->aiActionTime = FPS;
return 0; return 0;
} }
if (game.currentMission->challengeData.isChallenge && game.currentMission->challengeData.clearWaypointEnemies && battle.numEnemies > 0) if (game.currentMission->challengeData.isChallenge && game.currentMission->challengeData.clearWaypointEnemies && battle.numEnemies > 0)
{ {
addHudMessage(colors.cyan, _("Cannot activate waypoint - eliminate enemies first")); addHudMessage(colors.cyan, _("Cannot activate waypoint - eliminate enemies first"));
self->aiActionTime = FPS; self->aiActionTime = FPS;
return 0; return 0;
} }
return 1; return 1;
} }
static int teamMatesClose(void) static int teamMatesClose(void)
{ {
Entity *e; Entity *e;
if (player->side != SIDE_PANDORAN) if (player->side != SIDE_PANDORAN)
{ {
for (e = battle.entityHead.next ; e != NULL ; e = e->next) for (e = battle.entityHead.next ; e != NULL ; e = e->next)
@ -128,7 +128,7 @@ static int teamMatesClose(void)
} }
} }
} }
return 1; return 1;
} }
@ -136,9 +136,9 @@ void activateNextWaypoint(void)
{ {
Entity *e; Entity *e;
Entity *nextWaypoint = NULL; Entity *nextWaypoint = NULL;
currentWaypointId++; 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 == currentWaypointId) if (e->type == ET_WAYPOINT && e->id == currentWaypointId)
@ -146,11 +146,11 @@ void activateNextWaypoint(void)
nextWaypoint = e; nextWaypoint = e;
} }
} }
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); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Activating %s", nextWaypoint->name);
} }
} }

View File

@ -66,7 +66,7 @@ static char *RESTRICTIONS_TEXT;
void initChallengeHome(void) void initChallengeHome(void)
{ {
Mission *m; Mission *m;
startSectionTransition(); startSectionTransition();
stopMusic(); stopMusic();
@ -80,7 +80,7 @@ void initChallengeHome(void)
awardStatsTrophies(); awardStatsTrophies();
app.saveGame = 1; app.saveGame = 1;
CHALLENGES_TEXT = _("Challenges"); CHALLENGES_TEXT = _("Challenges");
COMPLETED_TEXT = _("Completed : %d / %d"); COMPLETED_TEXT = _("Completed : %d / %d");
PAGE_TEXT = _("Page : %d / %d"); PAGE_TEXT = _("Page : %d / %d");
@ -102,14 +102,14 @@ void initChallengeHome(void)
planet.x = rand() % app.winWidth; planet.x = rand() % app.winWidth;
planet.y = rand() % app.winHeight; planet.y = rand() % app.winHeight;
maxPages = page = 0; maxPages = page = 0;
for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next) for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next)
{ {
maxPages++; maxPages++;
} }
maxPages /= CHALLENGES_PER_PAGE; maxPages /= CHALLENGES_PER_PAGE;
maxPages = ceil(maxPages); maxPages = ceil(maxPages);
@ -128,11 +128,11 @@ void initChallengeHome(void)
getWidget("ok", "stats")->action = ok; getWidget("ok", "stats")->action = ok;
getWidget("ok", "trophies")->action = ok; getWidget("ok", "trophies")->action = ok;
getWidget("ok", "fighterDB")->action = ok; getWidget("ok", "fighterDB")->action = ok;
prev = getWidget("prev", "challenges"); prev = getWidget("prev", "challenges");
prev->action = prevPage; prev->action = prevPage;
prev->visible = 0; prev->visible = 0;
next = getWidget("next", "challenges"); next = getWidget("next", "challenges");
next->action = nextPage; next->action = nextPage;
next->visible = 1; next->visible = 1;
@ -143,9 +143,9 @@ void initChallengeHome(void)
game.currentMission = game.challengeMissionHead.next; game.currentMission = game.challengeMissionHead.next;
updateChallengeMissionData(); updateChallengeMissionData();
} }
SDL_SetWindowGrab(app.window, 0); SDL_SetWindowGrab(app.window, 0);
autoSizeWidgetButtons("challenges", 1); autoSizeWidgetButtons("challenges", 1);
endSectionTransition(); endSectionTransition();
@ -156,7 +156,7 @@ void initChallengeHome(void)
static void nextPage(void) static void nextPage(void)
{ {
page = MIN(page + 1, maxPages - 1); page = MIN(page + 1, maxPages - 1);
next->visible = page < maxPages - 1; next->visible = page < maxPages - 1;
prev->visible = 1; prev->visible = 1;
} }
@ -164,7 +164,7 @@ static void nextPage(void)
static void prevPage(void) static void prevPage(void)
{ {
page = MAX(0, page - 1); page = MAX(0, page - 1);
next->visible = 1; next->visible = 1;
prev->visible = page > 0; prev->visible = page > 0;
} }
@ -223,12 +223,12 @@ static void logic(void)
} }
doWidgets(); doWidgets();
if (show == SHOW_FIGHTER_DB) if (show == SHOW_FIGHTER_DB)
{ {
doFighterDatabase(); doFighterDatabase();
} }
app.doTrophyAlerts = 1; app.doTrophyAlerts = 1;
} }
@ -236,11 +236,11 @@ static void doChallenges(void)
{ {
Mission *c; Mission *c;
int i, startIndex, end; int i, startIndex, end;
i = 0; i = 0;
startIndex = page * CHALLENGES_PER_PAGE; startIndex = page * CHALLENGES_PER_PAGE;
end = startIndex + CHALLENGES_PER_PAGE; end = startIndex + CHALLENGES_PER_PAGE;
for (c = game.challengeMissionHead.next ; c != NULL ; c = c->next) for (c = game.challengeMissionHead.next ; c != NULL ; c = c->next)
{ {
if (i >= startIndex && i < end && app.mouse.button[SDL_BUTTON_LEFT] && collision(app.uiMouse.x, app.uiMouse.y, 3, 3, c->rect.x, c->rect.y, c->rect.w, c->rect.h)) if (i >= startIndex && i < end && app.mouse.button[SDL_BUTTON_LEFT] && collision(app.uiMouse.x, app.uiMouse.y, 3, 3, c->rect.x, c->rect.y, c->rect.w, c->rect.h))
@ -258,7 +258,7 @@ static void doChallenges(void)
app.mouse.button[SDL_BUTTON_LEFT] = 0; app.mouse.button[SDL_BUTTON_LEFT] = 0;
} }
i++; i++;
} }
} }
@ -307,7 +307,7 @@ static void draw(void)
blit(planetTexture, planet.x, planet.y, 1); blit(planetTexture, planet.x, planet.y, 1);
drawStars(); drawStars();
if (show == SHOW_MENU) if (show == SHOW_MENU)
{ {
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
@ -315,9 +315,9 @@ static void draw(void)
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
} }
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
drawText(UI_WIDTH / 2, 40, 28, TA_CENTER, colors.white, CHALLENGES_TEXT); drawText(UI_WIDTH / 2, 40, 28, TA_CENTER, colors.white, CHALLENGES_TEXT);
drawText(UI_WIDTH / 2, 83, 16, TA_CENTER, colors.lightGrey, COMPLETED_TEXT, game.completedChallenges, game.totalChallenges); drawText(UI_WIDTH / 2, 83, 16, TA_CENTER, colors.lightGrey, COMPLETED_TEXT, game.completedChallenges, game.totalChallenges);
drawText(UI_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages); drawText(UI_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages);
@ -337,7 +337,7 @@ static void draw(void)
case SHOW_STATS: case SHOW_STATS:
drawStats(); drawStats();
break; break;
case SHOW_TROPHIES: case SHOW_TROPHIES:
drawTrophies(); drawTrophies();
break; break;
@ -345,12 +345,12 @@ static void draw(void)
case SHOW_OPTIONS: case SHOW_OPTIONS:
drawOptions(); drawOptions();
break; break;
case SHOW_FIGHTER_DB: case SHOW_FIGHTER_DB:
drawFighterDatabase(); drawFighterDatabase();
break; break;
} }
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
@ -367,7 +367,7 @@ static void drawChallenges(void)
start = page * CHALLENGES_PER_PAGE; start = page * CHALLENGES_PER_PAGE;
end = start + CHALLENGES_PER_PAGE; end = start + CHALLENGES_PER_PAGE;
i = 0; i = 0;
for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next) for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next)
@ -492,7 +492,7 @@ static void stats(void)
static void fighterDatabase(void) static void fighterDatabase(void)
{ {
show = SHOW_FIGHTER_DB; show = SHOW_FIGHTER_DB;
initFighterDatabaseDisplay(); initFighterDatabaseDisplay();
} }

View File

@ -76,13 +76,13 @@ void initChallenges(void)
sprintf(path, "data/challenges/%s", filenames[i]); sprintf(path, "data/challenges/%s", filenames[i]);
mission = loadMissionMeta(path); mission = loadMissionMeta(path);
if (mission) if (mission)
{ {
tail->next = mission; tail->next = mission;
tail = mission; tail = mission;
} }
free(filenames[i]); free(filenames[i]);
} }
@ -93,7 +93,7 @@ void loadChallenge(Mission *mission, cJSON *node)
{ {
int i; int i;
Challenge *challenge; Challenge *challenge;
mission->challengeData.isChallenge = 1; mission->challengeData.isChallenge = 1;
/* limits */ /* limits */
@ -112,12 +112,12 @@ void loadChallenge(Mission *mission, cJSON *node)
mission->challengeData.noECM = getJSONValue(node, "noECM", 0); mission->challengeData.noECM = getJSONValue(node, "noECM", 0);
mission->challengeData.noBoost = getJSONValue(node, "noBoost", 0); mission->challengeData.noBoost = getJSONValue(node, "noBoost", 0);
mission->challengeData.noGuns = getJSONValue(node, "noGuns", 0); mission->challengeData.noGuns = getJSONValue(node, "noGuns", 0);
if (getJSONValue(node, "noWeapons", 0)) if (getJSONValue(node, "noWeapons", 0))
{ {
mission->challengeData.noMissiles = mission->challengeData.noGuns = 1; mission->challengeData.noMissiles = mission->challengeData.noGuns = 1;
} }
/* misc */ /* misc */
mission->challengeData.allowPlayerDeath = getJSONValue(node, "allowPlayerDeath", 0); mission->challengeData.allowPlayerDeath = getJSONValue(node, "allowPlayerDeath", 0);
mission->challengeData.clearWaypointEnemies = getJSONValue(node, "clearWaypointEnemies", 0); mission->challengeData.clearWaypointEnemies = getJSONValue(node, "clearWaypointEnemies", 0);
@ -152,18 +152,18 @@ void loadChallenge(Mission *mission, cJSON *node)
void doChallenges(void) void doChallenges(void)
{ {
int passed; int passed;
if (game.currentMission->challengeData.isChallenge && battle.status == MS_IN_PROGRESS) if (game.currentMission->challengeData.isChallenge && battle.status == MS_IN_PROGRESS)
{ {
if (challengeFinished()) if (challengeFinished())
{ {
passed = 0; passed = 0;
if (player->health > 0 || (player->health <= 0 && game.currentMission->challengeData.allowPlayerDeath)) if (player->health > 0 || (player->health <= 0 && game.currentMission->challengeData.allowPlayerDeath))
{ {
passed = updateChallenges(); passed = updateChallenges();
} }
if (passed) if (passed)
{ {
completeChallenge(); completeChallenge();
@ -182,53 +182,53 @@ static int challengeFinished(void)
{ {
return 1; return 1;
} }
/* disabled enemies count as killed during challenges - not player exclusive, but no need to worry about AI contributions here */ /* disabled enemies count as killed during challenges - not player exclusive, but no need to worry about AI contributions here */
if (game.currentMission->challengeData.killLimit > 0 && (battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_CAPITAL_SHIPS_DESTROYED] + battle.stats[STAT_ENEMIES_DISABLED]) >= game.currentMission->challengeData.killLimit) if (game.currentMission->challengeData.killLimit > 0 && (battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_CAPITAL_SHIPS_DESTROYED] + battle.stats[STAT_ENEMIES_DISABLED]) >= game.currentMission->challengeData.killLimit)
{ {
return 1; return 1;
} }
if (game.currentMission->challengeData.escapeLimit > 0 && (battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_ENEMIES_ESCAPED]) >= game.currentMission->challengeData.escapeLimit) if (game.currentMission->challengeData.escapeLimit > 0 && (battle.stats[STAT_ENEMIES_KILLED_PLAYER] + battle.stats[STAT_ENEMIES_ESCAPED]) >= game.currentMission->challengeData.escapeLimit)
{ {
return 1; return 1;
} }
if (game.currentMission->challengeData.waypointLimit > 0 && battle.stats[STAT_WAYPOINTS_VISITED] >= game.currentMission->challengeData.waypointLimit) if (game.currentMission->challengeData.waypointLimit > 0 && battle.stats[STAT_WAYPOINTS_VISITED] >= game.currentMission->challengeData.waypointLimit)
{ {
return 1; return 1;
} }
if (game.currentMission->challengeData.itemLimit > 0 && battle.stats[STAT_ITEMS_COLLECTED] + battle.stats[STAT_ITEMS_COLLECTED_PLAYER] >= game.currentMission->challengeData.itemLimit) if (game.currentMission->challengeData.itemLimit > 0 && battle.stats[STAT_ITEMS_COLLECTED] + battle.stats[STAT_ITEMS_COLLECTED_PLAYER] >= game.currentMission->challengeData.itemLimit)
{ {
return 1; return 1;
} }
if (game.currentMission->challengeData.playerItemLimit > 0 && battle.stats[STAT_ITEMS_COLLECTED_PLAYER] >= game.currentMission->challengeData.playerItemLimit) if (game.currentMission->challengeData.playerItemLimit > 0 && battle.stats[STAT_ITEMS_COLLECTED_PLAYER] >= game.currentMission->challengeData.playerItemLimit)
{ {
return 1; return 1;
} }
if (game.currentMission->challengeData.rescueLimit > 0 && (battle.stats[STAT_CIVILIANS_RESCUED] + battle.stats[STAT_CIVILIANS_KILLED]) >= game.currentMission->challengeData.rescueLimit) if (game.currentMission->challengeData.rescueLimit > 0 && (battle.stats[STAT_CIVILIANS_RESCUED] + battle.stats[STAT_CIVILIANS_KILLED]) >= game.currentMission->challengeData.rescueLimit)
{ {
return 1; return 1;
} }
if (game.currentMission->challengeData.surrenderLimit > 0 && battle.stats[STAT_ENEMIES_SURRENDERED] >= game.currentMission->challengeData.surrenderLimit) if (game.currentMission->challengeData.surrenderLimit > 0 && battle.stats[STAT_ENEMIES_SURRENDERED] >= game.currentMission->challengeData.surrenderLimit)
{ {
return 1; return 1;
} }
if (game.currentMission->challengeData.waypointLimit > 0 && (battle.stats[STAT_WAYPOINTS_VISITED]) >= game.currentMission->challengeData.waypointLimit) if (game.currentMission->challengeData.waypointLimit > 0 && (battle.stats[STAT_WAYPOINTS_VISITED]) >= game.currentMission->challengeData.waypointLimit)
{ {
return 1; return 1;
} }
if (game.currentMission->challengeData.eliminateThreats && !battle.hasThreats) if (game.currentMission->challengeData.eliminateThreats && !battle.hasThreats)
{ {
return 1; return 1;
} }
return (player->health <= 0 || player->alive == ALIVE_ESCAPED || battle.scriptedEnd); return (player->health <= 0 || player->alive == ALIVE_ESCAPED || battle.scriptedEnd);
} }
@ -238,7 +238,7 @@ static int updateChallenges(void)
Challenge *c; Challenge *c;
updateAccuracyStats(battle.stats); updateAccuracyStats(battle.stats);
numPassed = 0; numPassed = 0;
for (i = 0 ; i < MAX_CHALLENGES ; i++) for (i = 0 ; i < MAX_CHALLENGES ; i++)
@ -254,7 +254,7 @@ static int updateChallenges(void)
case CHALLENGE_TIME: case CHALLENGE_TIME:
updateTimeChallenge(c); updateTimeChallenge(c);
break; break;
case CHALLENGE_SURVIVE: case CHALLENGE_SURVIVE:
updateSurvivalChallenge(c); updateSurvivalChallenge(c);
break; break;
@ -282,26 +282,26 @@ static int updateChallenges(void)
case CHALLENGE_DISABLE: case CHALLENGE_DISABLE:
updateDisabledChallenge(c); updateDisabledChallenge(c);
break; break;
case CHALLENGE_ITEMS: case CHALLENGE_ITEMS:
case CHALLENGE_PLAYER_ITEMS: case CHALLENGE_PLAYER_ITEMS:
updateItemsChallenge(c); updateItemsChallenge(c);
break; break;
case CHALLENGE_SURRENDER: case CHALLENGE_SURRENDER:
updateSurrenderChallenge(c); updateSurrenderChallenge(c);
break; break;
case CHALLENGE_WAYPOINTS: case CHALLENGE_WAYPOINTS:
updateWaypointChallenge(c); updateWaypointChallenge(c);
break; break;
case CHALLENGE_RESCUE: case CHALLENGE_RESCUE:
updateRescueChallenge(c); updateRescueChallenge(c);
break; break;
} }
} }
if (c->passed) if (c->passed)
{ {
numPassed++; numPassed++;
@ -313,7 +313,7 @@ static int updateChallenges(void)
{ {
printStats(); printStats();
} }
return numPassed; return numPassed;
} }
@ -472,7 +472,7 @@ char *getChallengeDescription(Challenge *c)
return getFormattedChallengeDescription(_("Complete challenge in %s or less"), timeToString(c->value * FPS, 0)); return getFormattedChallengeDescription(_("Complete challenge in %s or less"), timeToString(c->value * FPS, 0));
} }
} }
return getFormattedChallengeDescription(challengeDescription[c->type], c->value); return getFormattedChallengeDescription(challengeDescription[c->type], c->value);
} }
@ -545,13 +545,13 @@ static void completeChallenge(void)
game.stats[STAT_CHALLENGES_COMPLETED]++; game.stats[STAT_CHALLENGES_COMPLETED]++;
player->flags |= EF_IMMORTAL; player->flags |= EF_IMMORTAL;
retreatAllies(); retreatAllies();
retreatEnemies(); retreatEnemies();
awardStatsTrophies(); awardStatsTrophies();
awardCraftTrophy(); awardCraftTrophy();
} }
} }
@ -565,16 +565,16 @@ static void failChallenge(void)
selectWidget("retry", "battleLost"); selectWidget("retry", "battleLost");
player->flags |= EF_IMMORTAL; player->flags |= EF_IMMORTAL;
if (alreadyPassed()) if (alreadyPassed())
{ {
battle.status = MS_TIME_UP; battle.status = MS_TIME_UP;
} }
retreatAllies(); retreatAllies();
retreatEnemies(); retreatEnemies();
awardStatsTrophies(); awardStatsTrophies();
} }
} }
@ -593,6 +593,6 @@ static int alreadyPassed(void)
return 1; return 1;
} }
} }
return 0; return 0;
} }

View File

@ -87,7 +87,7 @@ void initGalacticMap(void)
app.delegate.logic = &logic; app.delegate.logic = &logic;
app.delegate.draw = &draw; app.delegate.draw = &draw;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
MISSIONS_TEXT = _("Missions: %d / %d"); MISSIONS_TEXT = _("Missions: %d / %d");
PILOT_TEXT = _("Pilot: %s"); PILOT_TEXT = _("Pilot: %s");
CRAFT_TEXT = _("Craft: %s"); CRAFT_TEXT = _("Craft: %s");
@ -113,9 +113,9 @@ void initGalacticMap(void)
awardCampaignTrophies(); awardCampaignTrophies();
awardStatsTrophies(); awardStatsTrophies();
updateCampaignProgress(); updateCampaignProgress();
hoverMission = NULL; hoverMission = NULL;
app.saveGame = 1; app.saveGame = 1;
@ -123,7 +123,7 @@ void initGalacticMap(void)
pulseTimer = 0; pulseTimer = 0;
arrowPulse = 0; arrowPulse = 0;
selectedStarSystem = NULL; selectedStarSystem = NULL;
/* clear the pulses */ /* clear the pulses */
@ -145,11 +145,11 @@ void initGalacticMap(void)
getWidget("ok", "fighterDB")->action = ok; getWidget("ok", "fighterDB")->action = ok;
getWidget("ok", "fallen")->action = fallenOK; getWidget("ok", "fallen")->action = fallenOK;
autoSizeWidgetButtons("galacticMap", 1); autoSizeWidgetButtons("galacticMap", 1);
endSectionTransition(); endSectionTransition();
SDL_SetWindowGrab(app.window, 0); SDL_SetWindowGrab(app.window, 0);
playMusic("music/main/Pressure.ogg", 1); playMusic("music/main/Pressure.ogg", 1);
@ -158,7 +158,7 @@ void initGalacticMap(void)
static void updateCampaignProgress(void) static void updateCampaignProgress(void)
{ {
StarSystem *starSystem; StarSystem *starSystem;
if (!campaignComplete && game.completedMissions == game.totalMissions) if (!campaignComplete && game.completedMissions == game.totalMissions)
{ {
for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next) for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next)
@ -168,9 +168,9 @@ static void updateCampaignProgress(void)
starSystem->activeMission = starSystem->missionHead.next; starSystem->activeMission = starSystem->missionHead.next;
} }
} }
campaignComplete = 1; campaignComplete = 1;
showOKDialog(&campaignCompleteOK, _("Congratulations, you have completed the campaign! You may now replay past missions, for fun, to boost stats, or to earn missing trophies!")); showOKDialog(&campaignCompleteOK, _("Congratulations, you have completed the campaign! You may now replay past missions, for fun, to boost stats, or to earn missing trophies!"));
} }
} }
@ -230,12 +230,12 @@ static void logic(void)
arrowPulse += 0.1; arrowPulse += 0.1;
doWidgets(); doWidgets();
if (show == SHOW_FIGHTER_DB) if (show == SHOW_FIGHTER_DB)
{ {
doFighterDatabase(); doFighterDatabase();
} }
app.doTrophyAlerts = 1; app.doTrophyAlerts = 1;
} }
@ -302,13 +302,13 @@ static void scrollGalaxy(void)
ssx = -app.mouse.dx; ssx = -app.mouse.dx;
ssx /= 3; ssx /= 3;
ssy = -app.mouse.dy; ssy = -app.mouse.dy;
ssy /= 3; ssy /= 3;
camera.x = MAX(cameraMin.x, MIN(camera.x, cameraMax.x)); camera.x = MAX(cameraMin.x, MIN(camera.x, cameraMax.x));
camera.y = MAX(cameraMin.y, MIN(camera.y, cameraMax.y)); camera.y = MAX(cameraMin.y, MIN(camera.y, cameraMax.y));
if (lastX == camera.x) if (lastX == camera.x)
{ {
ssx = 0; ssx = 0;
@ -330,7 +330,7 @@ static void doStarSystemView(void)
if (mission->available && collision(app.uiMouse.x - app.mouse.w / 2, app.uiMouse.y - app.mouse.h / 2, app.mouse.w, app.mouse.h, mission->rect.x, mission->rect.y, mission->rect.w, mission->rect.h)) if (mission->available && collision(app.uiMouse.x - app.mouse.w / 2, app.uiMouse.y - app.mouse.h / 2, app.mouse.w, app.mouse.h, mission->rect.x, mission->rect.y, mission->rect.w, mission->rect.h))
{ {
hoverMission = mission; hoverMission = mission;
if (app.mouse.button[SDL_BUTTON_LEFT]) if (app.mouse.button[SDL_BUTTON_LEFT])
{ {
if (game.currentMission != mission) if (game.currentMission != mission)
@ -343,12 +343,12 @@ static void doStarSystemView(void)
} }
} }
} }
/* allow closing by pressing the right mouse button */ /* allow closing by pressing the right mouse button */
if (app.mouse.button[SDL_BUTTON_RIGHT]) if (app.mouse.button[SDL_BUTTON_RIGHT])
{ {
show = SHOW_GALAXY; show = SHOW_GALAXY;
playSound(SND_GUI_CLOSE); playSound(SND_GUI_CLOSE);
} }
} }
@ -368,7 +368,7 @@ static void addPulses(void)
pulse->x = starSystem->x; pulse->x = starSystem->x;
pulse->y = starSystem->y; pulse->y = starSystem->y;
pulse->life = 255; pulse->life = 255;
switch (starSystem->type) switch (starSystem->type)
{ {
case SS_NORMAL: case SS_NORMAL:
@ -383,18 +383,18 @@ static void addPulses(void)
pulse->b = 255; pulse->b = 255;
} }
break; break;
case SS_SOL: case SS_SOL:
pulse->g = 255; pulse->g = 255;
break; break;
case SS_PANDORAN: case SS_PANDORAN:
pulse->r = 128; pulse->r = 128;
pulse->g = 128; pulse->g = 128;
pulse->b = 255; pulse->b = 255;
break; break;
} }
pulseTail->next = pulse; pulseTail->next = pulse;
pulseTail = pulse; pulseTail = pulse;
} }
@ -453,7 +453,7 @@ static void draw(void)
case SHOW_STATS: case SHOW_STATS:
drawStats(); drawStats();
break; break;
case SHOW_TROPHIES: case SHOW_TROPHIES:
drawTrophies(); drawTrophies();
break; break;
@ -461,7 +461,7 @@ static void draw(void)
case SHOW_OPTIONS: case SHOW_OPTIONS:
drawOptions(); drawOptions();
break; break;
case SHOW_FIGHTER_DB: case SHOW_FIGHTER_DB:
drawFighterDatabase(); drawFighterDatabase();
break; break;
@ -555,18 +555,18 @@ static void drawGalaxy(void)
case SS_NORMAL: case SS_NORMAL:
setAtlasColor(255, 0, 0, 255); setAtlasColor(255, 0, 0, 255);
break; break;
case SS_SOL: case SS_SOL:
setAtlasColor(0, 255, 0, 255); setAtlasColor(0, 255, 0, 255);
break; break;
case SS_PANDORAN: case SS_PANDORAN:
setAtlasColor(64, 128, 255, 255); setAtlasColor(64, 128, 255, 255);
break; break;
} }
blitRotated(arrowTexture, ax, ay, aa); blitRotated(arrowTexture, ax, ay, aa);
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
} }
} }
@ -618,7 +618,7 @@ static void selectStarSystem(void)
static Mission *nextAvailableMission(StarSystem *starSystem) static Mission *nextAvailableMission(StarSystem *starSystem)
{ {
Mission *m; Mission *m;
for (m = starSystem->missionHead.next ; m != NULL ; m = m->next) for (m = starSystem->missionHead.next ; m != NULL ; m = m->next)
{ {
if (m->available && !m->completed) if (m->available && !m->completed)
@ -626,7 +626,7 @@ static Mission *nextAvailableMission(StarSystem *starSystem)
return m; return m;
} }
} }
return starSystem->missionHead.next; return starSystem->missionHead.next;
} }
@ -635,7 +635,7 @@ static void drawStarSystemDetail(void)
int y; int y;
Mission *mission; Mission *mission;
SDL_Rect r; SDL_Rect r;
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 900; r.w = 900;
@ -668,7 +668,7 @@ static void drawStarSystemDetail(void)
mission->rect.y = y - 2; mission->rect.y = y - 2;
mission->rect.w = 300; mission->rect.w = 300;
mission->rect.h = 38; mission->rect.h = 38;
if (mission == hoverMission) if (mission == hoverMission)
{ {
SDL_SetRenderDrawColor(app.renderer, 16, 32, 64, 255); SDL_SetRenderDrawColor(app.renderer, 16, 32, 64, 255);
@ -690,7 +690,7 @@ static void drawStarSystemDetail(void)
if (mission->available) if (mission->available)
{ {
drawText(210, y, 22, TA_LEFT, mission->completed ? colors.lightGrey : colors.yellow, mission->name); drawText(210, y, 22, TA_LEFT, mission->completed ? colors.lightGrey : colors.yellow, mission->name);
y += 42; y += 42;
} }
} }
@ -702,9 +702,9 @@ static void drawStarSystemDetail(void)
drawText(525, 185, 18, TA_LEFT, colors.lightGrey, SQUADRON_TEXT, game.currentMission->squadron); drawText(525, 185, 18, TA_LEFT, colors.lightGrey, SQUADRON_TEXT, game.currentMission->squadron);
app.textWidth = 525; app.textWidth = 525;
drawText(525, 230, 22, TA_LEFT, colors.white, game.currentMission->description); drawText(525, 230, 22, TA_LEFT, colors.white, game.currentMission->description);
app.textWidth = 0; app.textWidth = 0;
} }
@ -724,7 +724,7 @@ static void drawStarSystemDetail(void)
startMissionButton->enabled = (!game.currentMission->completed || selectedStarSystem->type == SS_SOL || campaignComplete); startMissionButton->enabled = (!game.currentMission->completed || selectedStarSystem->type == SS_SOL || campaignComplete);
drawWidgets("starSystem"); drawWidgets("starSystem");
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
@ -740,7 +740,7 @@ static void campaignCompleteOK(void)
show = SHOW_GALAXY; show = SHOW_GALAXY;
app.modalDialog.type = MD_NONE; app.modalDialog.type = MD_NONE;
campaignComplete = 2; campaignComplete = 2;
} }
@ -791,7 +791,7 @@ static void handleMouse(void)
{ {
scrollingMap = 0; scrollingMap = 0;
} }
setMouseCursor(app.mouse.button[SDL_BUTTON_LEFT] && show == SHOW_GALAXY); setMouseCursor(app.mouse.button[SDL_BUTTON_LEFT] && show == SHOW_GALAXY);
} }
@ -805,12 +805,12 @@ static void startMission(void)
static void drawMenu(void) static void drawMenu(void)
{ {
SDL_Rect r; SDL_Rect r;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 400; r.w = 400;
@ -824,7 +824,7 @@ static void drawMenu(void)
SDL_RenderDrawRect(app.renderer, &r); SDL_RenderDrawRect(app.renderer, &r);
drawWidgets("galacticMap"); drawWidgets("galacticMap");
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
@ -843,7 +843,7 @@ static void options(void)
static void fighterDatabase(void) static void fighterDatabase(void)
{ {
show = SHOW_FIGHTER_DB; show = SHOW_FIGHTER_DB;
initFighterDatabaseDisplay(); initFighterDatabaseDisplay();
} }

View File

@ -51,11 +51,11 @@ Mission *loadMissionMeta(char *filename)
STRNCPY(mission->filename, filename, MAX_DESCRIPTION_LENGTH); STRNCPY(mission->filename, filename, MAX_DESCRIPTION_LENGTH);
mission->requires = getJSONValue(root, "requires", 0); mission->requires = getJSONValue(root, "requires", 0);
mission->isOptional = getJSONValue(root, "isOptional", 0); mission->isOptional = getJSONValue(root, "isOptional", 0);
mission->requiresOptional = getJSONValue(root, "requiresOptional", 0); mission->requiresOptional = getJSONValue(root, "requiresOptional", 0);
mission->expires = getJSONValue(root, "expires", 0); mission->expires = getJSONValue(root, "expires", 0);
if (cJSON_GetObjectItem(root, "epic")) if (cJSON_GetObjectItem(root, "epic"))
{ {
mission->epic = 1; mission->epic = 1;
@ -154,27 +154,27 @@ void loadMission(char *filename)
{ {
planet = getAutoPlanet(filename); planet = getAutoPlanet(filename);
} }
battle.planetTexture = getAtlasImage(planet); battle.planetTexture = getAtlasImage(planet);
battle.fireStormTexture = getAtlasImage("gfx/misc/torelliFireStorm.png"); battle.fireStormTexture = getAtlasImage("gfx/misc/torelliFireStorm.png");
battle.planet.x = (app.winWidth / 2) - (rand() % app.winWidth) + (rand() % app.winWidth); battle.planet.x = (app.winWidth / 2) - (rand() % app.winWidth) + (rand() % app.winWidth);
battle.planet.y = (app.winHeight / 2) - (rand() % app.winHeight) + (rand() % app.winHeight); battle.planet.y = (app.winHeight / 2) - (rand() % app.winHeight) + (rand() % app.winHeight);
if (strcmp(planet, "gfx/planets/star.png") != 0) if (strcmp(planet, "gfx/planets/star.png") != 0)
{ {
battle.planetWidth = battle.planetTexture->rect.w; battle.planetWidth = battle.planetTexture->rect.w;
battle.planetHeight = battle.planetTexture->rect.h; battle.planetHeight = battle.planetTexture->rect.h;
planetScale = 75 + (rand() % 125); planetScale = 75 + (rand() % 125);
planetScale *= 0.01; planetScale *= 0.01;
if (getJSONValue(root, "largePlanet", 0)) if (getJSONValue(root, "largePlanet", 0))
{ {
battle.planet.x = (app.winWidth / 2); battle.planet.x = (app.winWidth / 2);
battle.planet.y = (app.winHeight / 2); battle.planet.y = (app.winHeight / 2);
planetScale = 5; planetScale = 5;
} }
battle.planetWidth *= planetScale; battle.planetWidth *= planetScale;
battle.planetHeight *= planetScale; battle.planetHeight *= planetScale;
} }
@ -198,7 +198,7 @@ void loadMission(char *filename)
{ {
battle.status = MS_IN_PROGRESS; battle.status = MS_IN_PROGRESS;
} }
if (battle.waypointAutoAdvance) if (battle.waypointAutoAdvance)
{ {
activateNextWaypoint(); activateNextWaypoint();
@ -209,7 +209,7 @@ void loadMission(char *filename)
initPlayer(); initPlayer();
initMissionInfo(); initMissionInfo();
setInitialPlayerAngle(); setInitialPlayerAngle();
addAllToQuadtree(); addAllToQuadtree();
@ -274,10 +274,10 @@ void completeMission(void)
selectWidget("continue", "battleWon"); selectWidget("continue", "battleWon");
game.stats[STAT_MISSIONS_COMPLETED]++; game.stats[STAT_MISSIONS_COMPLETED]++;
if (game.currentMission->isOptional) if (game.currentMission->isOptional)
{ {
game.stats[STAT_OPTIONAL_COMPLETED]++; game.stats[STAT_OPTIONAL_COMPLETED]++;
} }
completeConditions(); completeConditions();
@ -285,11 +285,11 @@ void completeMission(void)
retreatEnemies(); retreatEnemies();
player->flags |= EF_IMMORTAL; player->flags |= EF_IMMORTAL;
awardStatsTrophies(); awardStatsTrophies();
awardPostMissionTrophies(); awardPostMissionTrophies();
awardCraftTrophy(); awardCraftTrophy();
} }
} }
@ -305,7 +305,7 @@ void failMission(void)
failIncompleteObjectives(); failIncompleteObjectives();
player->flags |= EF_IMMORTAL; player->flags |= EF_IMMORTAL;
awardStatsTrophies(); awardStatsTrophies();
} }
} }
@ -338,7 +338,7 @@ static void loadEntities(cJSON *node)
active = getJSONValue(node, "active", 1); active = getJSONValue(node, "active", 1);
scatter = getJSONValue(node, "scatter", 1); scatter = getJSONValue(node, "scatter", 1);
side = lookup(getJSONValueStr(node, "side", "SIDE_NONE")); side = lookup(getJSONValueStr(node, "side", "SIDE_NONE"));
if (cJSON_GetObjectItem(node, "flags")) if (cJSON_GetObjectItem(node, "flags"))
{ {
flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags); flags = flagsToLong(cJSON_GetObjectItem(node, "flags")->valuestring, &addFlags);
@ -356,7 +356,7 @@ static void loadEntities(cJSON *node)
case ET_JUMPGATE: case ET_JUMPGATE:
e = spawnJumpgate(side, flags); e = spawnJumpgate(side, flags);
break; break;
case ET_MINE: case ET_MINE:
case ET_SHADOW_MINE: case ET_SHADOW_MINE:
e = spawnMine(type); e = spawnMine(type);
@ -394,7 +394,7 @@ static void loadEntities(cJSON *node)
e->x = x; e->x = x;
e->y = y; e->y = y;
e->side = side; e->side = side;
if (scatter > 1) if (scatter > 1)
@ -423,12 +423,12 @@ static void loadEpicData(cJSON *node)
battle.unlimitedEnemies = getJSONValue(node, "unlimitedEnemies", 0); battle.unlimitedEnemies = getJSONValue(node, "unlimitedEnemies", 0);
battle.epicLives = getJSONValue(node, "lives", 0); battle.epicLives = getJSONValue(node, "lives", 0);
battle.epicKills = getJSONValue(node, "kills", 0); battle.epicKills = getJSONValue(node, "kills", 0);
if (battle.epicLives > 0) if (battle.epicLives > 0)
{ {
addEpicLivesObjective(); addEpicLivesObjective();
} }
if (battle.epicKills != 0) if (battle.epicKills != 0)
{ {
addEpicKillsObjective(); addEpicKillsObjective();
@ -490,7 +490,7 @@ int isMissionAvailable(Mission *mission, Mission *prev)
else else
{ {
return mission->completed || ( return mission->completed || (
game.completedMissions >= mission->requires && game.completedMissions >= mission->requires &&
game.stats[STAT_OPTIONAL_COMPLETED] >= mission->requiresOptional && game.stats[STAT_OPTIONAL_COMPLETED] >= mission->requiresOptional &&
game.completedMissions < mission->expires game.completedMissions < mission->expires
) || dev.debug; ) || dev.debug;

View File

@ -57,7 +57,7 @@ static StarSystem *loadStarSystem(cJSON *starSystemJSON)
starSystem->x = cJSON_GetObjectItem(starSystemJSON, "x")->valueint; starSystem->x = cJSON_GetObjectItem(starSystemJSON, "x")->valueint;
starSystem->y = cJSON_GetObjectItem(starSystemJSON, "y")->valueint; starSystem->y = cJSON_GetObjectItem(starSystemJSON, "y")->valueint;
starSystem->fallsToPandorans = getJSONValue(starSystemJSON, "fallsToPandorans", 0); starSystem->fallsToPandorans = getJSONValue(starSystemJSON, "fallsToPandorans", 0);
starSystem->type = (starSystem->side != SIDE_PANDORAN) ? SS_NORMAL : SS_PANDORAN; starSystem->type = (starSystem->side != SIDE_PANDORAN) ? SS_NORMAL : SS_PANDORAN;
if (strcmp(starSystem->name, "Sol") == 0) if (strcmp(starSystem->name, "Sol") == 0)
@ -91,26 +91,26 @@ static void loadMissions(StarSystem *starSystem)
{ {
name[i] = tolower(name[i]); name[i] = tolower(name[i]);
} }
sprintf(path, "data/missions/%s", name); sprintf(path, "data/missions/%s", name);
filenames = getFileList(path, &count); filenames = getFileList(path, &count);
for (i = 0 ; i < count ; i++) for (i = 0 ; i < count ; i++)
{ {
sprintf(path, "data/missions/%s/%s", name, filenames[i]); sprintf(path, "data/missions/%s/%s", name, filenames[i]);
mission = loadMissionMeta(path); mission = loadMissionMeta(path);
if (mission) if (mission)
{ {
tail->next = mission; tail->next = mission;
tail = mission; tail = mission;
} }
free(filenames[i]); free(filenames[i]);
} }
free(filenames); free(filenames);
} }
@ -143,16 +143,16 @@ void updateStarSystemMissions(void)
for (mission = starSystem->missionHead.next ; mission != NULL ; mission = mission->next) for (mission = starSystem->missionHead.next ; mission != NULL ; mission = mission->next)
{ {
starSystem->totalMissions++; starSystem->totalMissions++;
if (starSystem->type == SS_NORMAL && !mission->isOptional) if (starSystem->type == SS_NORMAL && !mission->isOptional)
{ {
game.totalMissions++; game.totalMissions++;
} }
if (mission->completed) if (mission->completed)
{ {
starSystem->completedMissions++; starSystem->completedMissions++;
if (starSystem->type == SS_NORMAL && !mission->isOptional) if (starSystem->type == SS_NORMAL && !mission->isOptional)
{ {
game.completedMissions++; game.completedMissions++;
@ -172,12 +172,12 @@ void updateStarSystemMissions(void)
if (mission->available) if (mission->available)
{ {
starSystem->availableMissions++; starSystem->availableMissions++;
if (starSystem->type == SS_NORMAL && !mission->isOptional) if (starSystem->type == SS_NORMAL && !mission->isOptional)
{ {
game.availableMissions++; game.availableMissions++;
} }
if (!mission->completed) if (!mission->completed)
{ {
starSystem->activeMission = mission; starSystem->activeMission = mission;

View File

@ -36,51 +36,51 @@ static int timeout;
void initCredits(void) void initCredits(void)
{ {
startSectionTransition(); startSectionTransition();
stopMusic(); stopMusic();
memset(&head, 0, sizeof(Credit)); memset(&head, 0, sizeof(Credit));
tail = &head; tail = &head;
app.delegate.logic = &logic; app.delegate.logic = &logic;
app.delegate.draw = &draw; app.delegate.draw = &draw;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
background = getTexture("gfx/backgrounds/background02.jpg"); background = getTexture("gfx/backgrounds/background02.jpg");
earthTexture = getAtlasImage("gfx/planets/earth.png"); earthTexture = getAtlasImage("gfx/planets/earth.png");
loadCredits(); loadCredits();
app.hideMouse = 1; app.hideMouse = 1;
endSectionTransition(); endSectionTransition();
playMusic("music/main/Her Violet Eyes.mp3", 0); playMusic("music/main/Her Violet Eyes.mp3", 0);
} }
static void logic(void) static void logic(void)
{ {
Credit *c; Credit *c;
handleKeyboard(); handleKeyboard();
for (c = head.next ; c != NULL ; c = c->next) for (c = head.next ; c != NULL ; c = c->next)
{ {
c->y -= creditSpeed; c->y -= creditSpeed;
if (!c->next) if (!c->next)
{ {
c->y = MAX(c->y, (app.winHeight - c->h) / 2); c->y = MAX(c->y, (app.winHeight - c->h) / 2);
} }
} }
if (--timeout <= 0) if (--timeout <= 0)
{ {
app.hideMouse = 0; app.hideMouse = 0;
destroyCredits(); destroyCredits();
initTitle(); initTitle();
} }
} }
@ -88,13 +88,13 @@ static void logic(void)
static void draw(void) static void draw(void)
{ {
Credit *c; Credit *c;
drawBackground(background); drawBackground(background);
blit(earthTexture, app.winWidth - 200, (app.winHeight / 2) + 100, 1); blit(earthTexture, app.winWidth - 200, (app.winHeight / 2) + 100, 1);
app.textWidth = CREDIT_LINE_LIMIT; app.textWidth = CREDIT_LINE_LIMIT;
for (c = head.next ; c != NULL ; c = c->next) for (c = head.next ; c != NULL ; c = c->next)
{ {
if (c->y > -c->h && c->y < app.winHeight) if (c->y > -c->h && c->y < app.winHeight)
@ -102,7 +102,7 @@ static void draw(void)
drawText(app.winWidth / 2, (int)c->y, c->size, TA_CENTER, colors.white, c->text); drawText(app.winWidth / 2, (int)c->y, c->size, TA_CENTER, colors.white, c->text);
} }
} }
app.textWidth = 0; app.textWidth = 0;
} }
@ -112,12 +112,12 @@ static void loadCredits(void)
int y, dist; int y, dist;
char *text; char *text;
Credit *c; Credit *c;
y = app.winHeight + 100; y = app.winHeight + 100;
text = readFile("data/credits/credits.json"); text = readFile("data/credits/credits.json");
root = cJSON_Parse(text); root = cJSON_Parse(text);
app.textWidth = CREDIT_LINE_LIMIT; app.textWidth = CREDIT_LINE_LIMIT;
for (node = root->child ; node != NULL ; node = node->next) for (node = root->child ; node != NULL ; node = node->next)
@ -126,28 +126,28 @@ static void loadCredits(void)
memset(c, 0, sizeof(Credit)); memset(c, 0, sizeof(Credit));
tail->next = c; tail->next = c;
tail = c; tail = c;
c->y = y; c->y = y;
c->text = malloc(sizeof(char) * strlen(node->valuestring)); c->text = malloc(sizeof(char) * strlen(node->valuestring));
memset(c->text, '\0', sizeof(char) * strlen(node->valuestring)); memset(c->text, '\0', sizeof(char) * strlen(node->valuestring));
sscanf(node->valuestring, "%d %d %[^\n]", &dist, &c->size, c->text); sscanf(node->valuestring, "%d %d %[^\n]", &dist, &c->size, c->text);
c->y += dist; c->y += dist;
c->h = getWrappedTextHeight(c->text, c->size); c->h = getWrappedTextHeight(c->text, c->size);
y += c->h + dist; y += c->h + dist;
} }
app.textWidth = 0; app.textWidth = 0;
/* the music that plays over the credits is 2m 44s, so scroll credits roughly inline with that (plus 2 seconds) */ /* the music that plays over the credits is 2m 44s, so scroll credits roughly inline with that (plus 2 seconds) */
timeout = ((2 * 60) + 46) * FPS; timeout = ((2 * 60) + 46) * FPS;
creditSpeed = y; creditSpeed = y;
creditSpeed /= timeout; creditSpeed /= timeout;
cJSON_Delete(root); cJSON_Delete(root);
free(text); free(text);
} }
@ -163,7 +163,7 @@ static void handleKeyboard(void)
void destroyCredits(void) void destroyCredits(void)
{ {
Credit *c; Credit *c;
while (head.next) while (head.next)
{ {
c = head.next; c = head.next;

View File

@ -48,7 +48,7 @@ void initFighterDatabase(void)
{ {
DB_TEXT = _("Fighter Database"); DB_TEXT = _("Fighter Database");
PAGE_TEXT = _("Page %d / %d"); PAGE_TEXT = _("Page %d / %d");
COMMON_TEXT = _("(Common)"); COMMON_TEXT = _("(Common)");
DESTROYED_TEXT = _("Destroyed"); DESTROYED_TEXT = _("Destroyed");
AFFILIATION_TEXT = _("Affiliation"); AFFILIATION_TEXT = _("Affiliation");
@ -57,9 +57,9 @@ void initFighterDatabase(void)
SPEED_TEXT = _("Speed"); SPEED_TEXT = _("Speed");
MISSILES_TEXT = _("Missiles"); MISSILES_TEXT = _("Missiles");
MISSILE_NUM_TEXT = _("Missiles x %d"); MISSILE_NUM_TEXT = _("Missiles x %d");
dbFighters = getDBFighters(&maxPages); dbFighters = getDBFighters(&maxPages);
gunName[BT_NONE] = ""; gunName[BT_NONE] = "";
gunName[BT_PARTICLE] = _("Particle Cannon"); gunName[BT_PARTICLE] = _("Particle Cannon");
gunName[BT_PLASMA] = _("Plasma Cannon"); gunName[BT_PLASMA] = _("Plasma Cannon");
@ -67,7 +67,7 @@ void initFighterDatabase(void)
gunName[BT_MAG] = _("Mag Cannon"); gunName[BT_MAG] = _("Mag Cannon");
gunName[BT_ROCKET] = _("Rockets"); gunName[BT_ROCKET] = _("Rockets");
gunName[BT_MISSILE] = _("Missiles"); gunName[BT_MISSILE] = _("Missiles");
rotation = 0; rotation = 0;
} }
@ -79,13 +79,13 @@ void destroyFighterDatabase(void)
void initFighterDatabaseDisplay(void) void initFighterDatabaseDisplay(void)
{ {
page = 0; page = 0;
prev = getWidget("prev", "fighterDB"); prev = getWidget("prev", "fighterDB");
prev->action = prevFighter; prev->action = prevFighter;
next = getWidget("next", "fighterDB"); next = getWidget("next", "fighterDB");
next->action = nextFighter; next->action = nextFighter;
setNumDestroyed(); setNumDestroyed();
} }
@ -99,83 +99,83 @@ void drawFighterDatabase(void)
SDL_Rect r; SDL_Rect r;
Entity *fighter; Entity *fighter;
int i, y, numCannons; int i, y, numCannons;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 700; r.w = 700;
r.h = 650; r.h = 650;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;
r.y = (UI_HEIGHT / 2) - r.h / 2; r.y = (UI_HEIGHT / 2) - r.h / 2;
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255); SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
SDL_RenderDrawRect(app.renderer, &r); SDL_RenderDrawRect(app.renderer, &r);
drawText(UI_WIDTH / 2, 50, 28, TA_CENTER, colors.white, DB_TEXT); drawText(UI_WIDTH / 2, 50, 28, TA_CENTER, colors.white, DB_TEXT);
drawText(UI_WIDTH / 2, 90, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages); drawText(UI_WIDTH / 2, 90, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages);
fighter = dbFighters[page]; fighter = dbFighters[page];
drawText(UI_WIDTH / 2, 130, 28, TA_CENTER, colors.white, fighter->name); drawText(UI_WIDTH / 2, 130, 28, TA_CENTER, colors.white, fighter->name);
blitRotated(fighter->texture, r.x + (r.w / 2), 250, rotation); blitRotated(fighter->texture, r.x + (r.w / 2), 250, rotation);
if (fighter->flags & EF_COMMON_FIGHTER) if (fighter->flags & EF_COMMON_FIGHTER)
{ {
drawText(UI_WIDTH / 2, 170, 18, TA_CENTER, colors.darkGrey, COMMON_TEXT); drawText(UI_WIDTH / 2, 170, 18, TA_CENTER, colors.darkGrey, COMMON_TEXT);
drawText(r.x + (r.w / 2), 290, 18, TA_CENTER, colors.lightGrey, "%s: %d", DESTROYED_TEXT, numDestroyed); drawText(r.x + (r.w / 2), 290, 18, TA_CENTER, colors.lightGrey, "%s: %d", DESTROYED_TEXT, numDestroyed);
} }
drawText(r.x + 25, 200, 22, TA_LEFT, colors.white, "%s: %s", AFFILIATION_TEXT, fighter->affiliation); drawText(r.x + 25, 200, 22, TA_LEFT, colors.white, "%s: %s", AFFILIATION_TEXT, fighter->affiliation);
drawText(r.x + 25, 240, 22, TA_LEFT, colors.white, "%s: %d", ARMOUR_TEXT, fighter->health); drawText(r.x + 25, 240, 22, TA_LEFT, colors.white, "%s: %d", ARMOUR_TEXT, fighter->health);
drawText(r.x + 25, 280, 22, TA_LEFT, colors.white, "%s: %d", SHIELD_TEXT, fighter->shield); drawText(r.x + 25, 280, 22, TA_LEFT, colors.white, "%s: %d", SHIELD_TEXT, fighter->shield);
drawText(r.x + 25, 320, 22, TA_LEFT, colors.white, "%s: %.0f", SPEED_TEXT, ((fighter->speed * fighter->speed) * FPS)); drawText(r.x + 25, 320, 22, TA_LEFT, colors.white, "%s: %.0f", SPEED_TEXT, ((fighter->speed * fighter->speed) * FPS));
y = 200; y = 200;
for (i = 1 ; i < BT_MAX ; i++) for (i = 1 ; i < BT_MAX ; i++)
{ {
numCannons = countFighterGuns(fighter, i); numCannons = countFighterGuns(fighter, i);
if (numCannons > 0) if (numCannons > 0)
{ {
drawText(r.x + r.w - 25, y, 22, TA_RIGHT, colors.white, "%s x %d", gunName[i], numCannons); drawText(r.x + r.w - 25, y, 22, TA_RIGHT, colors.white, "%s x %d", gunName[i], numCannons);
y += 40; y += 40;
} }
} }
if (fighter->missiles > 0) if (fighter->missiles > 0)
{ {
drawText(r.x + r.w - 25, y, 22, TA_RIGHT, colors.white, MISSILE_NUM_TEXT, fighter->missiles); drawText(r.x + r.w - 25, y, 22, TA_RIGHT, colors.white, MISSILE_NUM_TEXT, fighter->missiles);
} }
y = MAX(y, 320) + 75; y = MAX(y, 320) + 75;
app.textWidth = r.w - 50; app.textWidth = r.w - 50;
drawText(r.x + 25, y, 18, TA_LEFT, colors.white, fighter->description); drawText(r.x + 25, y, 18, TA_LEFT, colors.white, fighter->description);
app.textWidth = 0; app.textWidth = 0;
drawWidgets("fighterDB"); drawWidgets("fighterDB");
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
static int countFighterGuns(Entity *fighter, int type) static int countFighterGuns(Entity *fighter, int type)
{ {
int i, num; int i, num;
num = 0; num = 0;
for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++) for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++)
{ {
if (fighter->guns[i].type == type) if (fighter->guns[i].type == type)
@ -183,21 +183,21 @@ static int countFighterGuns(Entity *fighter, int type)
num++; num++;
} }
} }
return num; return num;
} }
static void prevFighter(void) static void prevFighter(void)
{ {
page = mod(page - 1, maxPages); page = mod(page - 1, maxPages);
setNumDestroyed(); setNumDestroyed();
} }
static void nextFighter(void) static void nextFighter(void)
{ {
page = mod(page + 1, maxPages); page = mod(page + 1, maxPages);
setNumDestroyed(); setNumDestroyed();
} }
@ -205,11 +205,11 @@ static void setNumDestroyed(void)
{ {
Tuple *t; Tuple *t;
Entity *fighter; Entity *fighter;
fighter = dbFighters[page]; fighter = dbFighters[page];
numDestroyed = 0; numDestroyed = 0;
for (t = game.fighterStatHead.next ; t != NULL ; t = t->next) for (t = game.fighterStatHead.next ; t != NULL ; t = t->next)
{ {
if (strcmp(t->key, fighter->name) == 0) if (strcmp(t->key, fighter->name) == 0)

View File

@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void initGame(void) void initGame(void)
{ {
memset(&game, 0, sizeof(Game)); memset(&game, 0, sizeof(Game));
STRNCPY(game.selectedStarSystem, "Sol", MAX_NAME_LENGTH); STRNCPY(game.selectedStarSystem, "Sol", MAX_NAME_LENGTH);
} }

View File

@ -44,9 +44,9 @@ void loadGame(void)
loadChallenges(cJSON_GetObjectItem(gameJSON, "challenges")); loadChallenges(cJSON_GetObjectItem(gameJSON, "challenges"));
loadStats(cJSON_GetObjectItem(gameJSON, "stats")); loadStats(cJSON_GetObjectItem(gameJSON, "stats"));
loadTrophies(cJSON_GetObjectItem(gameJSON, "trophies")); loadTrophies(cJSON_GetObjectItem(gameJSON, "trophies"));
loadFighterStats(cJSON_GetObjectItem(gameJSON, "fighterStats")); loadFighterStats(cJSON_GetObjectItem(gameJSON, "fighterStats"));
cJSON_Delete(root); cJSON_Delete(root);
@ -76,7 +76,7 @@ static void loadMissions(cJSON *missionsJSON)
for (missionJSON = missionsJSON->child ; missionJSON != NULL ; missionJSON = missionJSON->next) for (missionJSON = missionsJSON->child ; missionJSON != NULL ; missionJSON = missionJSON->next)
{ {
mission = getMission(cJSON_GetObjectItem(missionJSON, "filename")->valuestring); mission = getMission(cJSON_GetObjectItem(missionJSON, "filename")->valuestring);
if (mission) if (mission)
{ {
mission->completed = cJSON_GetObjectItem(missionJSON, "completed")->valueint; mission->completed = cJSON_GetObjectItem(missionJSON, "completed")->valueint;
@ -133,13 +133,13 @@ static void loadTrophies(cJSON *trophiesJSON)
{ {
Trophy *t; Trophy *t;
cJSON *trophyJSON; cJSON *trophyJSON;
if (trophiesJSON) if (trophiesJSON)
{ {
for (trophyJSON = trophiesJSON->child ; trophyJSON != NULL ; trophyJSON = trophyJSON->next) for (trophyJSON = trophiesJSON->child ; trophyJSON != NULL ; trophyJSON = trophyJSON->next)
{ {
t = getTrophy(cJSON_GetObjectItem(trophyJSON, "id")->valuestring); t = getTrophy(cJSON_GetObjectItem(trophyJSON, "id")->valuestring);
if (t) if (t)
{ {
t->awardDate = cJSON_GetObjectItem(trophyJSON, "awardDate")->valueint; t->awardDate = cJSON_GetObjectItem(trophyJSON, "awardDate")->valueint;
@ -153,21 +153,21 @@ static void loadFighterStats(cJSON *fighterStatsJSON)
{ {
Tuple *t, *tail; Tuple *t, *tail;
cJSON *fighterStatJSON; cJSON *fighterStatJSON;
destroyFighterStats(); destroyFighterStats();
tail = &game.fighterStatHead; tail = &game.fighterStatHead;
if (fighterStatsJSON) if (fighterStatsJSON)
{ {
for (fighterStatJSON = fighterStatsJSON->child ; fighterStatJSON != NULL ; fighterStatJSON = fighterStatJSON->next) for (fighterStatJSON = fighterStatsJSON->child ; fighterStatJSON != NULL ; fighterStatJSON = fighterStatJSON->next)
{ {
t = malloc(sizeof(Tuple)); t = malloc(sizeof(Tuple));
memset(t, 0, sizeof(Tuple)); memset(t, 0, sizeof(Tuple));
STRNCPY(t->key, cJSON_GetObjectItem(fighterStatJSON, "key")->valuestring, MAX_NAME_LENGTH); STRNCPY(t->key, cJSON_GetObjectItem(fighterStatJSON, "key")->valuestring, MAX_NAME_LENGTH);
t->value = cJSON_GetObjectItem(fighterStatJSON, "value")->valueint; t->value = cJSON_GetObjectItem(fighterStatJSON, "value")->valueint;
tail->next = t; tail->next = t;
tail = t; tail = t;
} }

View File

@ -58,7 +58,7 @@ void initOptions(void (*rtn)(void))
setWidgetOption("musicVolume", "options", optionStr); setWidgetOption("musicVolume", "options", optionStr);
setWidgetOption("fullscreen", "options", app.fullscreen ? "On" : "Off"); setWidgetOption("fullscreen", "options", app.fullscreen ? "On" : "Off");
OPTIONS_TEXT = _("Options"); OPTIONS_TEXT = _("Options");
RESOLUTION_TEXT = _("Note: you must restart the game for window size and fullscreen options to take effect."); RESOLUTION_TEXT = _("Note: you must restart the game for window size and fullscreen options to take effect.");
@ -69,7 +69,7 @@ void initOptions(void (*rtn)(void))
#endif #endif
returnFromOptions = rtn; returnFromOptions = rtn;
show = SHOW_MAIN; show = SHOW_MAIN;
} }
@ -80,7 +80,7 @@ void drawOptions(void)
case SHOW_MAIN: case SHOW_MAIN:
drawMain(); drawMain();
break; break;
case SHOW_CONTROLS: case SHOW_CONTROLS:
drawControls(); drawControls();
break; break;
@ -90,12 +90,12 @@ void drawOptions(void)
static void drawMain(void) static void drawMain(void)
{ {
SDL_Rect r; SDL_Rect r;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 500; r.w = 500;
@ -116,11 +116,11 @@ static void drawMain(void)
drawWidgets("options"); drawWidgets("options");
app.textWidth = r.w - 100; app.textWidth = r.w - 100;
drawText(UI_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, RESOLUTION_TEXT); drawText(UI_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, RESOLUTION_TEXT);
app.textWidth = 0; app.textWidth = 0;
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
@ -129,11 +129,11 @@ void updateCustomResolutionOption(void)
Widget *w; Widget *w;
char value[MAX_NAME_LENGTH]; char value[MAX_NAME_LENGTH];
int i; int i;
sprintf(value, "%d x %d", app.winWidth, app.winHeight); sprintf(value, "%d x %d", app.winWidth, app.winHeight);
w = getWidget("windowSize", "options"); w = getWidget("windowSize", "options");
for (i = 0 ; i < w->numOptions - 1 ; i++) for (i = 0 ; i < w->numOptions - 1 ; i++)
{ {
if (strcmp(w->options[i], value) == 0) if (strcmp(w->options[i], value) == 0)
@ -142,7 +142,7 @@ void updateCustomResolutionOption(void)
return; return;
} }
} }
w->options[w->numOptions - 1] = malloc(strlen(value) + 1); w->options[w->numOptions - 1] = malloc(strlen(value) + 1);
strcpy(w->options[w->numOptions - 1], value); strcpy(w->options[w->numOptions - 1], value);
} }
@ -150,25 +150,25 @@ void updateCustomResolutionOption(void)
static void controls(void) static void controls(void)
{ {
initControlsDisplay(); initControlsDisplay();
show = SHOW_CONTROLS; show = SHOW_CONTROLS;
} }
static void changeWindowSize(char *value) static void changeWindowSize(char *value)
{ {
sscanf(value, "%d x %d", &app.winWidth, &app.winHeight); sscanf(value, "%d x %d", &app.winWidth, &app.winHeight);
SDL_SetWindowSize(app.window, app.winWidth, app.winHeight); SDL_SetWindowSize(app.window, app.winWidth, app.winHeight);
app.uiOffset.x = (app.winWidth / 2) - (UI_WIDTH / 2); app.uiOffset.x = (app.winWidth / 2) - (UI_WIDTH / 2);
app.uiOffset.y = (app.winHeight / 2) - (UI_HEIGHT / 2); app.uiOffset.y = (app.winHeight / 2) - (UI_HEIGHT / 2);
SDL_DestroyTexture(app.backBuffer); SDL_DestroyTexture(app.backBuffer);
app.backBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, app.winWidth, app.winHeight); app.backBuffer = SDL_CreateTexture(app.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, app.winWidth, app.winHeight);
initGraphics(); initGraphics();
initStars(); initStars();
} }
@ -189,7 +189,7 @@ static void changeMusicVolume(char *value)
static void changeFullscreen(char *value) static void changeFullscreen(char *value)
{ {
app.fullscreen = strcmp(value, "On") == 0; app.fullscreen = strcmp(value, "On") == 0;
SDL_SetWindowFullscreen(app.window, app.fullscreen? SDL_WINDOW_FULLSCREEN : 0); SDL_SetWindowFullscreen(app.window, app.fullscreen? SDL_WINDOW_FULLSCREEN : 0);
} }

View File

@ -45,9 +45,9 @@ void saveGame(void)
saveChallenges(gameJSON); saveChallenges(gameJSON);
saveStats(gameJSON); saveStats(gameJSON);
saveTrophies(gameJSON); saveTrophies(gameJSON);
saveFighterStats(gameJSON); saveFighterStats(gameJSON);
out = cJSON_Print(root); out = cJSON_Print(root);
@ -118,18 +118,18 @@ static void saveChallenges(cJSON *gameJSON)
cJSON_AddStringToObject(missionJSON, "filename", mission->filename); cJSON_AddStringToObject(missionJSON, "filename", mission->filename);
challengesJSON = cJSON_CreateArray(); challengesJSON = cJSON_CreateArray();
for (i = 0 ; i < MAX_CHALLENGES ; i++) for (i = 0 ; i < MAX_CHALLENGES ; i++)
{ {
c = mission->challengeData.challenges[i]; c = mission->challengeData.challenges[i];
if (c) if (c)
{ {
challengeJSON = cJSON_CreateObject(); challengeJSON = cJSON_CreateObject();
cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type)); cJSON_AddStringToObject(challengeJSON, "type", getLookupName("CHALLENGE_", c->type));
cJSON_AddNumberToObject(challengeJSON, "value", c->value); cJSON_AddNumberToObject(challengeJSON, "value", c->value);
cJSON_AddNumberToObject(challengeJSON, "passed", c->passed); cJSON_AddNumberToObject(challengeJSON, "passed", c->passed);
cJSON_AddItemToArray(challengesJSON, challengeJSON); cJSON_AddItemToArray(challengesJSON, challengeJSON);
} }
} }
@ -160,7 +160,7 @@ static void saveTrophies(cJSON *gameJSON)
{ {
Trophy *t; Trophy *t;
cJSON *trophiesJSON, *trophyJSON; cJSON *trophiesJSON, *trophyJSON;
trophiesJSON = cJSON_CreateArray(); trophiesJSON = cJSON_CreateArray();
for (t = game.trophyHead.next ; t != NULL ; t = t->next) for (t = game.trophyHead.next ; t != NULL ; t = t->next)
@ -168,14 +168,14 @@ static void saveTrophies(cJSON *gameJSON)
if (t->awarded) if (t->awarded)
{ {
trophyJSON = cJSON_CreateObject(); trophyJSON = cJSON_CreateObject();
cJSON_AddStringToObject(trophyJSON, "id", t->id); cJSON_AddStringToObject(trophyJSON, "id", t->id);
cJSON_AddNumberToObject(trophyJSON, "awardDate", t->awardDate); cJSON_AddNumberToObject(trophyJSON, "awardDate", t->awardDate);
cJSON_AddItemToArray(trophiesJSON, trophyJSON); cJSON_AddItemToArray(trophiesJSON, trophyJSON);
} }
} }
cJSON_AddItemToObject(gameJSON, "trophies", trophiesJSON); cJSON_AddItemToObject(gameJSON, "trophies", trophiesJSON);
} }
@ -183,18 +183,18 @@ static void saveFighterStats(cJSON *gameJSON)
{ {
Tuple *t; Tuple *t;
cJSON *fighterStatsJSON, *fighterStatJSON; cJSON *fighterStatsJSON, *fighterStatJSON;
fighterStatsJSON = cJSON_CreateArray(); fighterStatsJSON = cJSON_CreateArray();
for (t = game.fighterStatHead.next ; t != NULL ; t = t->next) for (t = game.fighterStatHead.next ; t != NULL ; t = t->next)
{ {
fighterStatJSON = cJSON_CreateObject(); fighterStatJSON = cJSON_CreateObject();
cJSON_AddStringToObject(fighterStatJSON, "key", t->key); cJSON_AddStringToObject(fighterStatJSON, "key", t->key);
cJSON_AddNumberToObject(fighterStatJSON, "value", t->value); cJSON_AddNumberToObject(fighterStatJSON, "value", t->value);
cJSON_AddItemToArray(fighterStatsJSON, fighterStatJSON); cJSON_AddItemToArray(fighterStatsJSON, fighterStatJSON);
} }
cJSON_AddItemToObject(gameJSON, "fighterStats", fighterStatsJSON); cJSON_AddItemToObject(gameJSON, "fighterStats", fighterStatsJSON);
} }

View File

@ -74,7 +74,7 @@ void initStats(void)
statDescription[STAT_MINES_DESTROYED] = _("Mines Destroyed"); statDescription[STAT_MINES_DESTROYED] = _("Mines Destroyed");
statDescription[STAT_ENEMIES_SURRENDERED] = _("Enemies Surrendered"); statDescription[STAT_ENEMIES_SURRENDERED] = _("Enemies Surrendered");
statDescription[STAT_TIME] = _("Time Played"); statDescription[STAT_TIME] = _("Time Played");
STATS_TEXT = _("Stats"); STATS_TEXT = _("Stats");
PAGE_TEXT = _("Page %d / %d"); PAGE_TEXT = _("Page %d / %d");
} }
@ -82,21 +82,21 @@ void initStats(void)
void initStatsDisplay(void) void initStatsDisplay(void)
{ {
page = 0; page = 0;
maxPages = STAT_TIME; maxPages = STAT_TIME;
maxPages /= STATS_PER_PAGE; maxPages /= STATS_PER_PAGE;
maxPages = ceil(maxPages); maxPages = ceil(maxPages);
prev = getWidget("prev", "stats"); prev = getWidget("prev", "stats");
prev->action = prevPage; prev->action = prevPage;
prev->visible = 0; prev->visible = 0;
next = getWidget("next", "stats"); next = getWidget("next", "stats");
next->action = nextPage; next->action = nextPage;
next->visible = 1; next->visible = 1;
calculatePercentComplete(); calculatePercentComplete();
updateAccuracyStats(game.stats); updateAccuracyStats(game.stats);
} }
@ -105,9 +105,9 @@ static void calculatePercentComplete(void)
StarSystem *starSystem; StarSystem *starSystem;
Mission *mission; Mission *mission;
int completed, total; int completed, total;
completed = total = 0; completed = total = 0;
for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next) for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next)
{ {
if (starSystem->type == SS_NORMAL) if (starSystem->type == SS_NORMAL)
@ -116,13 +116,13 @@ static void calculatePercentComplete(void)
total += starSystem->totalMissions; total += starSystem->totalMissions;
} }
} }
for (mission = game.challengeMissionHead.next ; mission != NULL ; mission = mission->next) for (mission = game.challengeMissionHead.next ; mission != NULL ; mission = mission->next)
{ {
completed += mission->completedChallenges; completed += mission->completedChallenges;
total += mission->totalChallenges; total += mission->totalChallenges;
} }
game.stats[STAT_PERCENT_COMPLETE] = getPercent(completed, total); game.stats[STAT_PERCENT_COMPLETE] = getPercent(completed, total);
} }
@ -130,41 +130,41 @@ void drawStats(void)
{ {
int i, y, startIndex; int i, y, startIndex;
SDL_Rect r; SDL_Rect r;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 500; r.w = 500;
r.h = 600; r.h = 600;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;
r.y = (UI_HEIGHT / 2) - r.h / 2; r.y = (UI_HEIGHT / 2) - r.h / 2;
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255); SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
SDL_RenderDrawRect(app.renderer, &r); SDL_RenderDrawRect(app.renderer, &r);
drawText(UI_WIDTH / 2, 70, 28, TA_CENTER, colors.white, STATS_TEXT); drawText(UI_WIDTH / 2, 70, 28, TA_CENTER, colors.white, STATS_TEXT);
drawText(UI_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages); drawText(UI_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages);
SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255); SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
SDL_RenderDrawLine(app.renderer, r.x, 150, r.x + r.w, 150); SDL_RenderDrawLine(app.renderer, r.x, 150, r.x + r.w, 150);
y = 170; y = 170;
startIndex = (page * STATS_PER_PAGE); startIndex = (page * STATS_PER_PAGE);
for (i = startIndex ; i < startIndex + STATS_PER_PAGE ; i++) for (i = startIndex ; i < startIndex + STATS_PER_PAGE ; i++)
{ {
if (i < STAT_TIME) if (i < STAT_TIME)
{ {
drawText(r.x + 20, y, 18, TA_LEFT, colors.white, statDescription[i]); drawText(r.x + 20, y, 18, TA_LEFT, colors.white, statDescription[i]);
switch (i) switch (i)
{ {
case STAT_PERCENT_COMPLETE: case STAT_PERCENT_COMPLETE:
@ -173,28 +173,28 @@ void drawStats(void)
case STAT_MISSILE_ACCURACY: case STAT_MISSILE_ACCURACY:
drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d%%", game.stats[i]); drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d%%", game.stats[i]);
break; break;
default: default:
drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats[i]); drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats[i]);
break; break;
} }
y += 40; y += 40;
} }
} }
drawText(r.x + 20, 565, 18, TA_LEFT, colors.white, statDescription[STAT_TIME]); drawText(r.x + 20, 565, 18, TA_LEFT, colors.white, statDescription[STAT_TIME]);
drawText(r.x + r.w - 20, 565, 18, TA_RIGHT, colors.white, timeToString(game.stats[STAT_TIME], 1)); drawText(r.x + r.w - 20, 565, 18, TA_RIGHT, colors.white, timeToString(game.stats[STAT_TIME], 1));
drawWidgets("stats"); drawWidgets("stats");
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
static void nextPage(void) static void nextPage(void)
{ {
page = MIN(page + 1, maxPages - 1); page = MIN(page + 1, maxPages - 1);
next->visible = page < maxPages - 1; next->visible = page < maxPages - 1;
prev->visible = 1; prev->visible = 1;
} }
@ -202,7 +202,7 @@ static void nextPage(void)
static void prevPage(void) static void prevPage(void)
{ {
page = MAX(0, page - 1); page = MAX(0, page - 1);
next->visible = 1; next->visible = 1;
prev->visible = page > 0; prev->visible = page > 0;
} }

View File

@ -49,35 +49,35 @@ static int show;
void initTitle(void) void initTitle(void)
{ {
startSectionTransition(); startSectionTransition();
stopMusic(); stopMusic();
app.delegate.logic = &logic; app.delegate.logic = &logic;
app.delegate.draw = &draw; app.delegate.draw = &draw;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
battle.camera.x = battle.camera.y = 0; battle.camera.x = battle.camera.y = 0;
destroyBattle(); destroyBattle();
logo[0] = getAtlasImage("gfx/title/logo01.png"); logo[0] = getAtlasImage("gfx/title/logo01.png");
logo[1] = getAtlasImage("gfx/title/logo02.png"); logo[1] = getAtlasImage("gfx/title/logo02.png");
pandoranWar = getAtlasImage("gfx/title/pandoran.png"); pandoranWar = getAtlasImage("gfx/title/pandoran.png");
background = getTexture("gfx/backgrounds/background02.jpg"); background = getTexture("gfx/backgrounds/background02.jpg");
earthTexture = getAtlasImage("gfx/planets/earth.png"); earthTexture = getAtlasImage("gfx/planets/earth.png");
earth.x = rand() % app.winWidth; earth.x = rand() % app.winWidth;
earth.y = -(128 + (rand() % 128)); earth.y = -(128 + (rand() % 128));
initEffects(); initEffects();
initFighters(); initFighters();
updateAllMissions(); updateAllMissions();
getWidget("campaign", "title")->action = campaign; getWidget("campaign", "title")->action = campaign;
getWidget("challenges", "title")->action = challenges; getWidget("challenges", "title")->action = challenges;
getWidget("trophies", "title")->action = trophies; getWidget("trophies", "title")->action = trophies;
@ -86,28 +86,28 @@ void initTitle(void)
getWidget("options", "title")->action = options; getWidget("options", "title")->action = options;
getWidget("credits", "title")->action = credits; getWidget("credits", "title")->action = credits;
getWidget("quit", "title")->action = quit; getWidget("quit", "title")->action = quit;
getWidget("ok", "stats")->action = ok; getWidget("ok", "stats")->action = ok;
getWidget("ok", "trophies")->action = ok; getWidget("ok", "trophies")->action = ok;
getWidget("ok", "fighterDB")->action = ok; getWidget("ok", "fighterDB")->action = ok;
autoSizeWidgetButtons("title", 1); autoSizeWidgetButtons("title", 1);
show = SHOW_TITLE; show = SHOW_TITLE;
endSectionTransition(); endSectionTransition();
playMusic("music/main/Rise of spirit.ogg", 0); playMusic("music/main/Rise of spirit.ogg", 0);
} }
static void initFighters(void) static void initFighters(void)
{ {
int i, numTextures; int i, numTextures;
numTextures = sizeof(fighterTextures) / sizeof(char*); numTextures = sizeof(fighterTextures) / sizeof(char*);
memset(&fighters, 0, sizeof(Entity) * NUM_FIGHTERS); memset(&fighters, 0, sizeof(Entity) * NUM_FIGHTERS);
for (i = 0 ; i < NUM_FIGHTERS ; i++) for (i = 0 ; i < NUM_FIGHTERS ; i++)
{ {
fighters[i].x = rand() % (app.winWidth - 32); fighters[i].x = rand() % (app.winWidth - 32);
@ -120,50 +120,50 @@ static void initFighters(void)
static void logic(void) static void logic(void)
{ {
handleKeyboard(); handleKeyboard();
scrollBackground(0, 0.25); scrollBackground(0, 0.25);
doStars(0, -0.5); doStars(0, -0.5);
earth.y += 0.1; earth.y += 0.1;
if (earth.y > app.winHeight + 128) if (earth.y > app.winHeight + 128)
{ {
earth.x = rand() % app.winWidth; earth.x = rand() % app.winWidth;
earth.y = -(128 + (rand() % 128)); earth.y = -(128 + (rand() % 128));
} }
doFighters(); doFighters();
doEffects(); doEffects();
app.doTrophyAlerts = 1; app.doTrophyAlerts = 1;
if (show == SHOW_FIGHTER_DB) if (show == SHOW_FIGHTER_DB)
{ {
doFighterDatabase(); doFighterDatabase();
} }
doWidgets(); doWidgets();
} }
static void doFighters(void) static void doFighters(void)
{ {
int i, numTextures; int i, numTextures;
numTextures = sizeof(fighterTextures) / sizeof(char*); numTextures = sizeof(fighterTextures) / sizeof(char*);
for (i = 0 ; i < NUM_FIGHTERS ; i++) for (i = 0 ; i < NUM_FIGHTERS ; i++)
{ {
self = &fighters[i]; self = &fighters[i];
/* engine position hack, due to camera being fixed */ /* engine position hack, due to camera being fixed */
self->y += 16; self->y += 16;
addEngineEffect(); addEngineEffect();
self->y -= 16; self->y -= 16;
self->y += self->dy; self->y += self->dy;
if (self->y <= -64) if (self->y <= -64)
{ {
self->x = rand() % (app.winWidth - 32); self->x = rand() % (app.winWidth - 32);
@ -177,27 +177,27 @@ static void doFighters(void)
static void draw(void) static void draw(void)
{ {
drawBackground(background); drawBackground(background);
drawStars(); drawStars();
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
blit(earthTexture, earth.x, earth.y, 1); blit(earthTexture, earth.x, earth.y, 1);
drawFighters(); drawFighters();
drawEffects(); drawEffects();
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
blit(logo[0], (app.winWidth / 2) - logo[0]->rect.w, 30, 0); blit(logo[0], (app.winWidth / 2) - logo[0]->rect.w, 30, 0);
blit(logo[1], (app.winWidth / 2), 30, 0); blit(logo[1], (app.winWidth / 2), 30, 0);
blit(pandoranWar, app.winWidth / 2, 110, 1); blit(pandoranWar, app.winWidth / 2, 110, 1);
drawText(10, app.winHeight - 25, 14, TA_LEFT, colors.white, "Copyright Parallel Realities, 2015-2019"); drawText(10, app.winHeight - 25, 14, TA_LEFT, colors.white, "Copyright Parallel Realities, 2015-2019");
drawText(app.winWidth - 10, app.winHeight - 25, 14, TA_RIGHT, colors.white, "Version %.2f.%d", VERSION, REVISION); drawText(app.winWidth - 10, app.winHeight - 25, 14, TA_RIGHT, colors.white, "Version %.2f.%d", VERSION, REVISION);
switch (show) switch (show)
{ {
case SHOW_TITLE: case SHOW_TITLE:
@ -205,19 +205,19 @@ static void draw(void)
drawWidgets("title"); drawWidgets("title");
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
break; break;
case SHOW_STATS: case SHOW_STATS:
drawStats(); drawStats();
break; break;
case SHOW_OPTIONS: case SHOW_OPTIONS:
drawOptions(); drawOptions();
break; break;
case SHOW_TROPHIES: case SHOW_TROPHIES:
drawTrophies(); drawTrophies();
break; break;
case SHOW_FIGHTER_DB: case SHOW_FIGHTER_DB:
drawFighterDatabase(); drawFighterDatabase();
break; break;
@ -227,9 +227,9 @@ static void draw(void)
static void drawFighters(void) static void drawFighters(void)
{ {
int i; int i;
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
for (i = 0 ; i < NUM_FIGHTERS ; i++) for (i = 0 ; i < NUM_FIGHTERS ; i++)
{ {
blit(fighters[i].texture, fighters[i].x, fighters[i].y, 1); blit(fighters[i].texture, fighters[i].x, fighters[i].y, 1);
@ -242,7 +242,7 @@ static void handleKeyboard(void)
{ {
returnFromOptions(); returnFromOptions();
playSound(SND_GUI_CLOSE); playSound(SND_GUI_CLOSE);
clearInput(); clearInput();
} }
} }
@ -250,57 +250,57 @@ static void handleKeyboard(void)
static void campaign(void) static void campaign(void)
{ {
destroyBattle(); destroyBattle();
initGalacticMap(); initGalacticMap();
} }
static void challenges(void) static void challenges(void)
{ {
destroyBattle(); destroyBattle();
game.currentMission = NULL; game.currentMission = NULL;
initChallengeHome(); initChallengeHome();
} }
static void trophies(void) static void trophies(void)
{ {
selectWidget("ok", "trophies"); selectWidget("ok", "trophies");
show = SHOW_TROPHIES; show = SHOW_TROPHIES;
initTrophiesDisplay(); initTrophiesDisplay();
} }
static void fighterDatabase(void) static void fighterDatabase(void)
{ {
show = SHOW_FIGHTER_DB; show = SHOW_FIGHTER_DB;
initFighterDatabaseDisplay(); initFighterDatabaseDisplay();
} }
static void options(void) static void options(void)
{ {
selectWidget("ok", "options"); selectWidget("ok", "options");
show = SHOW_OPTIONS; show = SHOW_OPTIONS;
initOptions(returnFromOptions); initOptions(returnFromOptions);
} }
static void stats(void) static void stats(void)
{ {
selectWidget("ok", "stats"); selectWidget("ok", "stats");
show = SHOW_STATS; show = SHOW_STATS;
initStatsDisplay(); initStatsDisplay();
} }
static void ok(void) static void ok(void)
{ {
selectWidget("stats", "title"); selectWidget("stats", "title");
show = SHOW_TITLE; show = SHOW_TITLE;
} }

View File

@ -57,12 +57,12 @@ void initTrophies(void)
trophyIcons[TROPHY_UNEARNED] = getAtlasImage("gfx/trophies/unearned.png"); trophyIcons[TROPHY_UNEARNED] = getAtlasImage("gfx/trophies/unearned.png");
sparkle = getAtlasImage("gfx/trophies/sparkle.png"); sparkle = getAtlasImage("gfx/trophies/sparkle.png");
alertSphere = getAtlasImage("gfx/trophies/alertSphere.png"); alertSphere = getAtlasImage("gfx/trophies/alertSphere.png");
alertRect.h = 90; alertRect.h = 90;
alertRect.y = 10; alertRect.y = 10;
sparkleAngle = 0; sparkleAngle = 0;
TROPHIES_TEXT = _("Trophies"); TROPHIES_TEXT = _("Trophies");
AWARDED_TEXT = _("Awarded : %d / %d"); AWARDED_TEXT = _("Awarded : %d / %d");
PAGE_TEXT = _("Page : %d / %d"); PAGE_TEXT = _("Page : %d / %d");
@ -75,37 +75,37 @@ void initTrophiesDisplay(void)
{ {
int w, h; int w, h;
Trophy *t; Trophy *t;
boxWidth = total = awarded = 0; boxWidth = total = awarded = 0;
for (t = game.trophyHead.next ; t != NULL ; t = t->next) for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{ {
total++; total++;
if (t->awarded) if (t->awarded)
{ {
awarded++; awarded++;
STRNCPY(t->awardDateStr, timeToDate(t->awardDate), MAX_NAME_LENGTH); STRNCPY(t->awardDateStr, timeToDate(t->awardDate), MAX_NAME_LENGTH);
} }
calcTextDimensions(t->description, 18, &w, &h); calcTextDimensions(t->description, 18, &w, &h);
boxWidth = MAX(boxWidth, w); boxWidth = MAX(boxWidth, w);
} }
boxWidth += 125; boxWidth += 125;
page = 0; page = 0;
maxPages = total; maxPages = total;
maxPages /= TROPHIES_PER_PAGE; maxPages /= TROPHIES_PER_PAGE;
maxPages = ceil(maxPages); maxPages = ceil(maxPages);
prev = getWidget("prev", "trophies"); prev = getWidget("prev", "trophies");
prev->action = prevPage; prev->action = prevPage;
prev->visible = 0; prev->visible = 0;
next = getWidget("next", "trophies"); next = getWidget("next", "trophies");
next->action = nextPage; next->action = nextPage;
next->visible = 1; next->visible = 1;
@ -114,7 +114,7 @@ void initTrophiesDisplay(void)
static void nextPage(void) static void nextPage(void)
{ {
page = MIN(page + 1, maxPages - 1); page = MIN(page + 1, maxPages - 1);
next->visible = page < maxPages - 1; next->visible = page < maxPages - 1;
prev->visible = 1; prev->visible = 1;
} }
@ -122,7 +122,7 @@ static void nextPage(void)
static void prevPage(void) static void prevPage(void)
{ {
page = MAX(0, page - 1); page = MAX(0, page - 1);
next->visible = 1; next->visible = 1;
prev->visible = page > 0; prev->visible = page > 0;
} }
@ -132,37 +132,37 @@ void drawTrophies(void)
Trophy *t; Trophy *t;
SDL_Rect r; SDL_Rect r;
int start, end, i, x, y; int start, end, i, x, y;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = boxWidth; r.w = boxWidth;
r.h = 650; r.h = 650;
r.x = (UI_WIDTH / 2) - r.w / 2; r.x = (UI_WIDTH / 2) - r.w / 2;
r.y = (UI_HEIGHT / 2) - r.h / 2; r.y = (UI_HEIGHT / 2) - r.h / 2;
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
SDL_RenderFillRect(app.renderer, &r); SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255); SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
SDL_RenderDrawRect(app.renderer, &r); SDL_RenderDrawRect(app.renderer, &r);
drawText(UI_WIDTH / 2, 40, 28, TA_CENTER, colors.white, TROPHIES_TEXT); drawText(UI_WIDTH / 2, 40, 28, TA_CENTER, colors.white, TROPHIES_TEXT);
drawText(UI_WIDTH / 2, 83, 16, TA_CENTER, colors.lightGrey, AWARDED_TEXT, awarded, total); drawText(UI_WIDTH / 2, 83, 16, TA_CENTER, colors.lightGrey, AWARDED_TEXT, awarded, total);
drawText(UI_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages); drawText(UI_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages);
SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255); SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
SDL_RenderDrawLine(app.renderer, r.x, 150, r.x + r.w, 150); SDL_RenderDrawLine(app.renderer, r.x, 150, r.x + r.w, 150);
x = r.x + 15; x = r.x + 15;
y = 180; y = 180;
start = page * TROPHIES_PER_PAGE; start = page * TROPHIES_PER_PAGE;
end = start + TROPHIES_PER_PAGE; end = start + TROPHIES_PER_PAGE;
i = 0; i = 0;
for (t = game.trophyHead.next ; t != NULL ; t = t->next) for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{ {
if (i >= start && i < end) if (i >= start && i < end)
@ -172,7 +172,7 @@ void drawTrophies(void)
setSparkleColor(t); setSparkleColor(t);
blitRotated(sparkle, x + 32, y + 32, sparkleAngle); blitRotated(sparkle, x + 32, y + 32, sparkleAngle);
blitRotated(sparkle, x + 32, y + 32, -sparkleAngle); blitRotated(sparkle, x + 32, y + 32, -sparkleAngle);
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
blitScaled(trophyIcons[t->value], x, y, 64, 64, 0); blitScaled(trophyIcons[t->value], x, y, 64, 64, 0);
drawText(x + 85, y - 10, 20, TA_LEFT, colors.yellow, t->title); drawText(x + 85, y - 10, 20, TA_LEFT, colors.yellow, t->title);
@ -195,15 +195,15 @@ void drawTrophies(void)
drawText(x + 85, y + 20, 20, TA_LEFT, colors.darkGrey, HIDDEN_TEXT); drawText(x + 85, y + 20, 20, TA_LEFT, colors.darkGrey, HIDDEN_TEXT);
} }
} }
y += 120; y += 120;
} }
i++; i++;
} }
drawWidgets("trophies"); drawWidgets("trophies");
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
@ -211,9 +211,9 @@ void awardTrophy(char *id)
{ {
Trophy *t; Trophy *t;
int numRemaining; int numRemaining;
numRemaining = 0; numRemaining = 0;
for (t = game.trophyHead.next ; t != NULL ; t = t->next) for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{ {
if (!t->awarded && strcmp(t->id, id) == 0) if (!t->awarded && strcmp(t->id, id) == 0)
@ -221,21 +221,21 @@ void awardTrophy(char *id)
t->awarded = 1; t->awarded = 1;
t->awardDate = time(NULL); t->awardDate = time(NULL);
t->notify = SDL_GetTicks(); t->notify = SDL_GetTicks();
/* prevent race condition */ /* prevent race condition */
SDL_Delay(1); SDL_Delay(1);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Awarding trophy '%s'", t->id); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Awarding trophy '%s'", t->id);
app.saveGame = 1; app.saveGame = 1;
} }
if (!t->awarded) if (!t->awarded)
{ {
numRemaining++; numRemaining++;
} }
} }
/* the Platinum will always be the last trophy to unlock */ /* the Platinum will always be the last trophy to unlock */
if (numRemaining == 1) if (numRemaining == 1)
{ {
@ -264,7 +264,7 @@ void doTrophyAlerts(void)
resetAlert(); resetAlert();
} }
} }
sparkleAngle = mod(sparkleAngle + 0.25, 360); sparkleAngle = mod(sparkleAngle + 0.25, 360);
} }
@ -283,15 +283,15 @@ static void nextAlert(void)
} }
} }
} }
if (alertTrophy) if (alertTrophy)
{ {
playSound(SND_TROPHY); playSound(SND_TROPHY);
calcTextDimensions(alertTrophy->title, 30, &alertRect.w, &h); calcTextDimensions(alertTrophy->title, 30, &alertRect.w, &h);
calcTextDimensions(alertTrophy->description, 20, &w, &h); calcTextDimensions(alertTrophy->description, 20, &w, &h);
alertRect.w = MAX(alertRect.w, w); alertRect.w = MAX(alertRect.w, w);
alertRect.w = MAX(400, alertRect.w); alertRect.w = MAX(400, alertRect.w);
alertRect.w += 125; alertRect.w += 125;
@ -308,7 +308,7 @@ static void resetAlert(void)
void drawTrophyAlert(void) void drawTrophyAlert(void)
{ {
int x, y; int x, y;
if (alertTrophy) if (alertTrophy)
{ {
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
@ -319,9 +319,9 @@ void drawTrophyAlert(void)
drawText(alertRect.x + 15, alertRect.y + 5, 30, TA_LEFT, colors.white, alertTrophy->title); drawText(alertRect.x + 15, alertRect.y + 5, 30, TA_LEFT, colors.white, alertTrophy->title);
drawText(alertRect.x + 15, alertRect.y + 45, 20, TA_LEFT, colors.white, alertTrophy->description); drawText(alertRect.x + 15, alertRect.y + 45, 20, TA_LEFT, colors.white, alertTrophy->description);
setSparkleColor(alertTrophy); setSparkleColor(alertTrophy);
x = alertRect.x + alertRect.w - 72; x = alertRect.x + alertRect.w - 72;
y = alertRect.y + 20; y = alertRect.y + 20;
@ -360,7 +360,7 @@ static void loadTrophyData(char *filename)
root = cJSON_Parse(text); root = cJSON_Parse(text);
tail = &game.trophyHead; tail = &game.trophyHead;
memset(count, 0, sizeof(int) * TROPHY_MAX); memset(count, 0, sizeof(int) * TROPHY_MAX);
for (node = root->child ; node != NULL ; node = node->next) for (node = root->child ; node != NULL ; node = node->next)
@ -375,16 +375,16 @@ static void loadTrophyData(char *filename)
STRNCPY(t->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH); STRNCPY(t->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH);
t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring); t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring);
t->hidden = getJSONValue(node, "hidden", 0); t->hidden = getJSONValue(node, "hidden", 0);
t->stat = -1; t->stat = -1;
/* can't use the getJSONValue here, as it could lead to false positives */ /* can't use the getJSONValue here, as it could lead to false positives */
if (cJSON_GetObjectItem(node, "stat")) if (cJSON_GetObjectItem(node, "stat"))
{ {
t->stat = lookup(cJSON_GetObjectItem(node, "stat")->valuestring); t->stat = lookup(cJSON_GetObjectItem(node, "stat")->valuestring);
t->statValue = cJSON_GetObjectItem(node, "statValue")->valueint; t->statValue = cJSON_GetObjectItem(node, "statValue")->valueint;
} }
count[t->value]++; count[t->value]++;
count[TROPHY_UNEARNED]++; count[TROPHY_UNEARNED]++;
@ -392,7 +392,7 @@ static void loadTrophyData(char *filename)
tail = t; tail = t;
} }
} }
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Trophies (%d) [Bronze=%d, Silver=%d, Gold=%d, Platinum=%d]", count[TROPHY_UNEARNED], count[TROPHY_BRONZE], count[TROPHY_SILVER], count[TROPHY_GOLD], count[TROPHY_PLATINUM]); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Trophies (%d) [Bronze=%d, Silver=%d, Gold=%d, Platinum=%d]", count[TROPHY_UNEARNED], count[TROPHY_BRONZE], count[TROPHY_SILVER], count[TROPHY_GOLD], count[TROPHY_PLATINUM]);
cJSON_Delete(root); cJSON_Delete(root);
@ -411,7 +411,7 @@ void awardStatsTrophies(void)
awardTrophy(t->id); awardTrophy(t->id);
} }
} }
/* check to see if we've destroyed one of each common starfighter */ /* check to see if we've destroyed one of each common starfighter */
for (tp = game.fighterStatHead.next ; tp != NULL ; tp = tp->next) for (tp = game.fighterStatHead.next ; tp != NULL ; tp = tp->next)
{ {
@ -420,7 +420,7 @@ void awardStatsTrophies(void)
return; return;
} }
} }
awardTrophy("FREQUENT_FLYER"); awardTrophy("FREQUENT_FLYER");
} }
@ -430,7 +430,7 @@ void awardCampaignTrophies(void)
char name[MAX_NAME_LENGTH]; char name[MAX_NAME_LENGTH];
int i, len; int i, len;
StarSystem *starSystem; StarSystem *starSystem;
if (game.completedMissions) if (game.completedMissions)
{ {
awardTrophy("CAMPAIGN_1"); awardTrophy("CAMPAIGN_1");
@ -449,7 +449,7 @@ void awardCampaignTrophies(void)
{ {
name[i] = toupper(starSystem->name[i]); name[i] = toupper(starSystem->name[i]);
} }
sprintf(trophyId, "CAMPAIGN_%s", name); sprintf(trophyId, "CAMPAIGN_%s", name);
awardTrophy(trophyId); awardTrophy(trophyId);
} }
@ -472,13 +472,13 @@ void awardPostMissionTrophies(void)
if (game.currentMission->epic) if (game.currentMission->epic)
{ {
awardTrophy("EPIC"); awardTrophy("EPIC");
if (battle.stats[STAT_PLAYER_KILLED] == 0 && player->flags & EF_COMMON_FIGHTER) if (battle.stats[STAT_PLAYER_KILLED] == 0 && player->flags & EF_COMMON_FIGHTER)
{ {
awardTrophy("SURVIVOR"); awardTrophy("SURVIVOR");
} }
} }
/* /*
* Must be a non-challenge mission, a common fighter, must not be Sol, and must not have fired any shots or missiles (and there should have been some enemies present) * Must be a non-challenge mission, a common fighter, must not be Sol, and must not have fired any shots or missiles (and there should have been some enemies present)
*/ */
@ -508,7 +508,7 @@ void awardCraftTrophy(void)
awardTrophy("SHUTTLE"); awardTrophy("SHUTTLE");
} }
} }
awardPandoranCraftTrophy(); awardPandoranCraftTrophy();
} }
@ -519,15 +519,15 @@ static void setSparkleColor(Trophy *t)
case TROPHY_BRONZE: case TROPHY_BRONZE:
setAtlasColor(255, 128, 0, 255); setAtlasColor(255, 128, 0, 255);
break; break;
case TROPHY_SILVER: case TROPHY_SILVER:
setAtlasColor(192, 192, 192, 255); setAtlasColor(192, 192, 192, 255);
break; break;
case TROPHY_GOLD: case TROPHY_GOLD:
setAtlasColor(255, 255, 0, 255); setAtlasColor(255, 255, 0, 255);
break; break;
case TROPHY_PLATINUM: case TROPHY_PLATINUM:
setAtlasColor(0, 128, 255, 255); setAtlasColor(0, 128, 255, 255);
break; break;

View File

@ -1,16 +1,16 @@
/* /*
Copyright (c) 2009 Dave Gamble Copyright (c) 2009 Dave Gamble
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -36,7 +36,7 @@ extern "C"
#define cJSON_String 4 #define cJSON_String 4
#define cJSON_Array 5 #define cJSON_Array 5
#define cJSON_Object 6 #define cJSON_Object 6
#define cJSON_IsReference 256 #define cJSON_IsReference 256
#define cJSON_StringIsConst 512 #define cJSON_StringIsConst 512
@ -83,7 +83,7 @@ extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
extern const char *cJSON_GetErrorPtr(void); extern const char *cJSON_GetErrorPtr(void);
/* These calls create a cJSON item of the appropriate type. */ /* These calls create a cJSON item of the appropriate type. */
extern cJSON *cJSON_CreateNull(void); extern cJSON *cJSON_CreateNull(void);
extern cJSON *cJSON_CreateTrue(void); extern cJSON *cJSON_CreateTrue(void);
@ -113,7 +113,7 @@ extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
extern void cJSON_DeleteItemFromArray(cJSON *array,int which); extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
/* Update array items. */ /* Update array items. */
extern void cJSON_InsertItemInArray(cJSON *array,int which,cJSON *newitem); /* Shifts pre-existing items to the right. */ extern void cJSON_InsertItemInArray(cJSON *array,int which,cJSON *newitem); /* Shifts pre-existing items to the right. */
extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem); extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);

View File

@ -28,103 +28,103 @@ int main(int argc, char *argv[])
{ {
long then, lastFrameTime, frames; long then, lastFrameTime, frames;
float remainder; float remainder;
memset(&app, 0, sizeof(App)); memset(&app, 0, sizeof(App));
memset(&dev, 0, sizeof(Dev)); memset(&dev, 0, sizeof(Dev));
handleLoggingArgs(argc, argv); handleLoggingArgs(argc, argv);
atexit(cleanup); atexit(cleanup);
srand(time(NULL)); srand(time(NULL));
init18N(argc, argv); init18N(argc, argv);
initLookups(); initLookups();
initSDL(argc, argv); initSDL(argc, argv);
initGameSystem(); initGameSystem();
createScreenshotFolder(); createScreenshotFolder();
if (fileExists(getSaveFilePath(SAVE_FILENAME))) if (fileExists(getSaveFilePath(SAVE_FILENAME)))
{ {
loadGame(); loadGame();
} }
handleMissionArgs(argc, argv); handleMissionArgs(argc, argv);
remainder = 0; remainder = 0;
dev.fps = frames = 0; dev.fps = frames = 0;
then = SDL_GetTicks(); then = SDL_GetTicks();
lastFrameTime = SDL_GetTicks() + 1000; lastFrameTime = SDL_GetTicks() + 1000;
while (1) while (1)
{ {
capFrameRate(&then, &remainder); capFrameRate(&then, &remainder);
doInput(); doInput();
if (app.modalDialog.type != MD_NONE) if (app.modalDialog.type != MD_NONE)
{ {
doModalDialog(); doModalDialog();
} }
/* let the delegate decide during logic() */ /* let the delegate decide during logic() */
app.doTrophyAlerts = 0; app.doTrophyAlerts = 0;
app.delegate.logic(); app.delegate.logic();
if (app.doTrophyAlerts) if (app.doTrophyAlerts)
{ {
doTrophyAlerts(); doTrophyAlerts();
} }
game.stats[STAT_TIME]++; game.stats[STAT_TIME]++;
/* always zero the mouse motion */ /* always zero the mouse motion */
app.mouse.dx = app.mouse.dy = 0; app.mouse.dx = app.mouse.dy = 0;
prepareScene(); prepareScene();
app.delegate.draw(); app.delegate.draw();
if (app.doTrophyAlerts) if (app.doTrophyAlerts)
{ {
drawTrophyAlert(); drawTrophyAlert();
} }
if (app.modalDialog.type != MD_NONE) if (app.modalDialog.type != MD_NONE)
{ {
drawModalDialog(); drawModalDialog();
} }
presentScene(); presentScene();
doDevKeys(); doDevKeys();
frames++; frames++;
if (SDL_GetTicks() > lastFrameTime) if (SDL_GetTicks() > lastFrameTime)
{ {
dev.fps = frames; dev.fps = frames;
frames = 0; frames = 0;
lastFrameTime = SDL_GetTicks() + 1000; lastFrameTime = SDL_GetTicks() + 1000;
if (dev.takeScreenshots) if (dev.takeScreenshots)
{ {
saveScreenshot(); saveScreenshot();
} }
} }
if (isControl(CONTROL_SCREENSHOT)) if (isControl(CONTROL_SCREENSHOT))
{ {
saveScreenshot(); saveScreenshot();
clearControl(CONTROL_SCREENSHOT); clearControl(CONTROL_SCREENSHOT);
} }
/* don't save more than once per request, and not in the middle of battle */ /* don't save more than once per request, and not in the middle of battle */
if (app.saveGame && battle.status != MS_IN_PROGRESS) if (app.saveGame && battle.status != MS_IN_PROGRESS)
{ {
@ -141,40 +141,40 @@ int main(int argc, char *argv[])
static void capFrameRate(long *then, float *remainder) static void capFrameRate(long *then, float *remainder)
{ {
long wait; long wait;
wait = 16 + *remainder; wait = 16 + *remainder;
*remainder -= (int)*remainder; *remainder -= (int)*remainder;
wait -= (SDL_GetTicks() - *then); wait -= (SDL_GetTicks() - *then);
if (wait < 1) if (wait < 1)
{ {
wait = 1; wait = 1;
} }
SDL_Delay(wait); SDL_Delay(wait);
*remainder += 0.666667; *remainder += 0.666667;
*then = SDL_GetTicks(); *then = SDL_GetTicks();
} }
static void handleLoggingArgs(int argc, char *argv[]) static void handleLoggingArgs(int argc, char *argv[])
{ {
int i; int i;
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN); SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN);
for (i = 1 ; i < argc ; i++) for (i = 1 ; i < argc ; i++)
{ {
if (strcmp(argv[i], "-debug") == 0) if (strcmp(argv[i], "-debug") == 0)
{ {
dev.debug = 1; dev.debug = 1;
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
} }
if (strcmp(argv[i], "-info") == 0) if (strcmp(argv[i], "-info") == 0)
{ {
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@ -185,25 +185,25 @@ static void handleLoggingArgs(int argc, char *argv[])
static void handleMissionArgs(int argc, char *argv[]) static void handleMissionArgs(int argc, char *argv[])
{ {
int i, testingMission, showCredits; int i, testingMission, showCredits;
showCredits = testingMission = 0; showCredits = testingMission = 0;
for (i = 1 ; i < argc ; i++) for (i = 1 ; i < argc ; i++)
{ {
/* assume this is filename for testing */ /* assume this is filename for testing */
if (strcmp(argv[i], "-mission") == 0) if (strcmp(argv[i], "-mission") == 0)
{ {
loadTestMission(argv[++i]); loadTestMission(argv[++i]);
testingMission = 1; testingMission = 1;
} }
if (strcmp(argv[i], "-credits") == 0) if (strcmp(argv[i], "-credits") == 0)
{ {
showCredits = 1; showCredits = 1;
} }
} }
if (showCredits) if (showCredits)
{ {
initCredits(); initCredits();

View File

@ -19,35 +19,35 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "unixInit.h" #include "unixInit.h"
void createSaveFolder(void) void createSaveFolder(void)
{ {
char *userHome; char *userHome;
char dir[MAX_FILENAME_LENGTH]; char dir[MAX_FILENAME_LENGTH];
userHome = getenv("HOME"); userHome = getenv("HOME");
if (!userHome) if (!userHome)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir."); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir.");
return; return;
} }
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome);
sprintf(dir, "%s/.local/share/tbftss", userHome); sprintf(dir, "%s/.local/share/tbftss", userHome);
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST) if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir);
return; return;
} }
STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH); STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH);
} }
void createScreenshotFolder(void) void createScreenshotFolder(void)
{ {
mkdir("/tmp/tbftss", S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH); mkdir("/tmp/tbftss", S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH);
dev.screenshotFolder = "/tmp/tbftss"; dev.screenshotFolder = "/tmp/tbftss";
} }

View File

@ -24,24 +24,24 @@ void createSaveFolder(void)
{ {
char *userHome; char *userHome;
char dir[MAX_FILENAME_LENGTH]; char dir[MAX_FILENAME_LENGTH];
userHome = getenv("USERPROFILE"); userHome = getenv("USERPROFILE");
if (!userHome) if (!userHome)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir."); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir.");
return; return;
} }
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome);
sprintf(dir, "%s\\tbftss", userHome); sprintf(dir, "%s\\tbftss", userHome);
if (mkdir(dir) != 0 && errno != EEXIST) if (mkdir(dir) != 0 && errno != EEXIST)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir);
return; return;
} }
STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH); STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH);
} }

View File

@ -28,7 +28,7 @@ static SDL_Texture *atlasTexture;
void initAtlas(void) void initAtlas(void)
{ {
memset(&atlases, 0, sizeof(AtlasImage) * NUM_ATLAS_BUCKETS); memset(&atlases, 0, sizeof(AtlasImage) * NUM_ATLAS_BUCKETS);
atlasTexture = getTexture("gfx/atlas/atlas.png"); atlasTexture = getTexture("gfx/atlas/atlas.png");
loadAtlasData(); loadAtlasData();
@ -46,7 +46,7 @@ AtlasImage *getAtlasImage(char *filename)
unsigned long i; unsigned long i;
i = hashcode(filename) % NUM_ATLAS_BUCKETS; i = hashcode(filename) % NUM_ATLAS_BUCKETS;
for (a = atlases[i].next ; a != NULL ; a = a->next) for (a = atlases[i].next ; a != NULL ; a = a->next)
{ {
if (strcmp(a->filename, filename) == 0) if (strcmp(a->filename, filename) == 0)
@ -54,10 +54,10 @@ AtlasImage *getAtlasImage(char *filename)
return a; return a;
} }
} }
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_CRITICAL, "No such atlas image '%s'", filename); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_CRITICAL, "No such atlas image '%s'", filename);
exit(1); exit(1);
return NULL; return NULL;
} }
@ -80,7 +80,7 @@ char **getAtlasFileList(char *dir, int *count)
} }
} }
} }
if (i > 0) if (i > 0)
{ {
filenames = malloc(sizeof(char*) * i); filenames = malloc(sizeof(char*) * i);
@ -121,11 +121,11 @@ static void loadAtlasData(void)
cJSON *root, *node; cJSON *root, *node;
char *text, *filename; char *text, *filename;
unsigned long i; unsigned long i;
text = readFile("data/atlas/atlas.json"); text = readFile("data/atlas/atlas.json");
root = cJSON_Parse(text); root = cJSON_Parse(text);
for (node = root->child ; node != NULL ; node = node->next) for (node = root->child ; node != NULL ; node = node->next)
{ {
filename = cJSON_GetObjectItem(node, "filename")->valuestring; filename = cJSON_GetObjectItem(node, "filename")->valuestring;
@ -143,21 +143,21 @@ static void loadAtlasData(void)
{ {
a = a->next; a = a->next;
} }
atlasImage = malloc(sizeof(AtlasImage)); atlasImage = malloc(sizeof(AtlasImage));
memset(atlasImage, 0, sizeof(AtlasImage)); memset(atlasImage, 0, sizeof(AtlasImage));
a->next = atlasImage; a->next = atlasImage;
STRNCPY(atlasImage->filename, filename, MAX_FILENAME_LENGTH); STRNCPY(atlasImage->filename, filename, MAX_FILENAME_LENGTH);
atlasImage->rect.x = x; atlasImage->rect.x = x;
atlasImage->rect.y = y; atlasImage->rect.y = y;
atlasImage->rect.w = w; atlasImage->rect.w = w;
atlasImage->rect.h = h; atlasImage->rect.h = h;
atlasImage->texture = atlasTexture; atlasImage->texture = atlasTexture;
} }
cJSON_Delete(root); cJSON_Delete(root);
free(text); free(text);
} }

View File

@ -32,7 +32,7 @@ static char *ESCAPE_TEXT;
void initControls(void) void initControls(void)
{ {
int i; int i;
controlName[CONTROL_FIRE] = _("Fire"); controlName[CONTROL_FIRE] = _("Fire");
controlName[CONTROL_ACCELERATE] = _("Accelerate"); controlName[CONTROL_ACCELERATE] = _("Accelerate");
controlName[CONTROL_BOOST] = _("Boost"); controlName[CONTROL_BOOST] = _("Boost");
@ -45,7 +45,7 @@ void initControls(void)
controlName[CONTROL_NEXT_FIGHTER] = _("Next Fighter"); controlName[CONTROL_NEXT_FIGHTER] = _("Next Fighter");
controlName[CONTROL_PREV_FIGHTER] = _("Previous Fighter"); controlName[CONTROL_PREV_FIGHTER] = _("Previous Fighter");
controlName[CONTROL_SCREENSHOT] = _("Screenshot"); controlName[CONTROL_SCREENSHOT] = _("Screenshot");
for (i = 0 ; i < CONTROL_MAX ; i++) for (i = 0 ; i < CONTROL_MAX ; i++)
{ {
controlWidget[i] = getWidget(getLookupName("CONTROL_", i), "controls"); controlWidget[i] = getWidget(getLookupName("CONTROL_", i), "controls");
@ -56,7 +56,7 @@ void initControls(void)
strcpy(controlWidget[i]->options[0], ""); strcpy(controlWidget[i]->options[0], "");
strcpy(controlWidget[i]->options[1], ""); strcpy(controlWidget[i]->options[1], "");
} }
CONTROLS_TEXT = _("Controls"); CONTROLS_TEXT = _("Controls");
HELP_TEXT = _("Click a control to change it, and then the key or mouse button you want to use."); HELP_TEXT = _("Click a control to change it, and then the key or mouse button you want to use.");
BACKSPACE_TEXT = _("[BACKSPACE] - Clear"); BACKSPACE_TEXT = _("[BACKSPACE] - Clear");
@ -66,23 +66,23 @@ void initControls(void)
void initControlsDisplay(void) void initControlsDisplay(void)
{ {
int i; int i;
for (i = 0 ; i < CONTROL_MAX ; i++) for (i = 0 ; i < CONTROL_MAX ; i++)
{ {
strcpy(controlWidget[i]->options[0], ""); strcpy(controlWidget[i]->options[0], "");
strcpy(controlWidget[i]->options[1], ""); strcpy(controlWidget[i]->options[1], "");
if (app.keyControls[i] != 0) if (app.keyControls[i] != 0)
{ {
sprintf(controlWidget[i]->options[0], "%s", SDL_GetScancodeName(app.keyControls[i])); sprintf(controlWidget[i]->options[0], "%s", SDL_GetScancodeName(app.keyControls[i]));
} }
if (app.mouseControls[i] != 0) if (app.mouseControls[i] != 0)
{ {
sprintf(controlWidget[i]->options[1], "Btn %d", app.mouseControls[i]); sprintf(controlWidget[i]->options[1], "Btn %d", app.mouseControls[i]);
} }
} }
getWidget("restore", "controls")->action = restoreDefaults; getWidget("restore", "controls")->action = restoreDefaults;
} }
@ -90,7 +90,7 @@ int isControl(int type)
{ {
int key = app.keyControls[type]; int key = app.keyControls[type];
int btn = app.mouseControls[type]; int btn = app.mouseControls[type];
return ((key != 0 && app.keyboard[key]) || (btn != 0 && app.mouse.button[btn])); return ((key != 0 && app.keyboard[key]) || (btn != 0 && app.mouse.button[btn]));
} }
@ -103,12 +103,12 @@ void clearControl(int type)
{ {
int key = app.keyControls[type]; int key = app.keyControls[type];
int btn = app.mouseControls[type]; int btn = app.mouseControls[type];
if (key != 0) if (key != 0)
{ {
app.keyboard[key] = 0; app.keyboard[key] = 0;
} }
if (btn != 0) if (btn != 0)
{ {
app.mouse.button[btn] = 0; app.mouse.button[btn] = 0;
@ -118,32 +118,32 @@ void clearControl(int type)
void resetAcceptControls(void) void resetAcceptControls(void)
{ {
app.keyboard[SDL_SCANCODE_SPACE] = app.keyboard[SDL_SCANCODE_RETURN] = 0; app.keyboard[SDL_SCANCODE_SPACE] = app.keyboard[SDL_SCANCODE_RETURN] = 0;
clearControl(CONTROL_FIRE); clearControl(CONTROL_FIRE);
} }
void updateControlKey(char *name) void updateControlKey(char *name)
{ {
app.keyControls[lookup(name)] = app.lastKeyPressed; app.keyControls[lookup(name)] = app.lastKeyPressed;
initControlsDisplay(); initControlsDisplay();
} }
void updateControlButton(char *name) void updateControlButton(char *name)
{ {
app.mouseControls[lookup(name)] = app.lastButtonPressed; app.mouseControls[lookup(name)] = app.lastButtonPressed;
initControlsDisplay(); initControlsDisplay();
} }
void clearControlConfig(char *name) void clearControlConfig(char *name)
{ {
int i; int i;
i = lookup(name); i = lookup(name);
app.keyControls[i] = app.mouseControls[i] = 0; app.keyControls[i] = app.mouseControls[i] = 0;
initControlsDisplay(); initControlsDisplay();
} }
@ -151,12 +151,12 @@ void drawControls(void)
{ {
int i; int i;
SDL_Rect r; SDL_Rect r;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 800; r.w = 800;
@ -173,37 +173,37 @@ void drawControls(void)
SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255); SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
SDL_RenderDrawLine(app.renderer, r.x, r.y + 65, r.x + r.w, r.y + 65); SDL_RenderDrawLine(app.renderer, r.x, r.y + 65, r.x + r.w, r.y + 65);
r.x += 25; r.x += 25;
r.y = 125; r.y = 125;
for (i = 0 ; i < CONTROL_MAX ; i++) for (i = 0 ; i < CONTROL_MAX ; i++)
{ {
drawText(r.x, r.y + 2, 20, TA_LEFT, colors.white, controlName[i]); drawText(r.x, r.y + 2, 20, TA_LEFT, colors.white, controlName[i]);
controlWidget[i]->rect.x = r.x + 175; controlWidget[i]->rect.x = r.x + 175;
controlWidget[i]->rect.y = r.y; controlWidget[i]->rect.y = r.y;
r.y += 65; r.y += 65;
if (r.y > 500) if (r.y > 500)
{ {
r.y = 125; r.y = 125;
r.x += 400; r.x += 400;
} }
} }
drawText((UI_WIDTH / 2) - 50, 525, 16, TA_RIGHT, colors.white, BACKSPACE_TEXT); drawText((UI_WIDTH / 2) - 50, 525, 16, TA_RIGHT, colors.white, BACKSPACE_TEXT);
drawText((UI_WIDTH / 2) + 50, 525, 16, TA_LEFT, colors.white, ESCAPE_TEXT); drawText((UI_WIDTH / 2) + 50, 525, 16, TA_LEFT, colors.white, ESCAPE_TEXT);
app.textWidth = r.w - 100; app.textWidth = r.w - 100;
drawText(UI_WIDTH / 2, 560, 16, TA_CENTER, colors.white, HELP_TEXT); drawText(UI_WIDTH / 2, 560, 16, TA_CENTER, colors.white, HELP_TEXT);
app.textWidth = 0; app.textWidth = 0;
drawWidgets("controls"); drawWidgets("controls");
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }
@ -243,6 +243,6 @@ static void restoreDefaults(void)
cJSON_Delete(root); cJSON_Delete(root);
free(text); free(text);
initControlsDisplay(); initControlsDisplay();
} }

View File

@ -30,48 +30,48 @@ void doDevKeys(void)
app.keyboard[SDL_SCANCODE_1] = 0; app.keyboard[SDL_SCANCODE_1] = 0;
printf("DEBUG: dev.playerImmortal=%d\n", dev.playerImmortal); printf("DEBUG: dev.playerImmortal=%d\n", dev.playerImmortal);
} }
if (app.keyboard[SDL_SCANCODE_2]) if (app.keyboard[SDL_SCANCODE_2])
{ {
dev.playerUnlimitedMissiles = !dev.playerUnlimitedMissiles; dev.playerUnlimitedMissiles = !dev.playerUnlimitedMissiles;
app.keyboard[SDL_SCANCODE_2] = 0; app.keyboard[SDL_SCANCODE_2] = 0;
printf("DEBUG: dev.playerUnlimitedMissiles=%d\n", dev.playerUnlimitedMissiles); printf("DEBUG: dev.playerUnlimitedMissiles=%d\n", dev.playerUnlimitedMissiles);
} }
if (app.keyboard[SDL_SCANCODE_3]) if (app.keyboard[SDL_SCANCODE_3])
{ {
dev.noAIWeapons = !dev.noAIWeapons; dev.noAIWeapons = !dev.noAIWeapons;
app.keyboard[SDL_SCANCODE_3] = 0; app.keyboard[SDL_SCANCODE_3] = 0;
printf("DEBUG: dev.noAIWeapons=%d\n", dev.noAIWeapons); printf("DEBUG: dev.noAIWeapons=%d\n", dev.noAIWeapons);
} }
if (app.keyboard[SDL_SCANCODE_4]) if (app.keyboard[SDL_SCANCODE_4])
{ {
dev.noEntityActions = !dev.noEntityActions; dev.noEntityActions = !dev.noEntityActions;
app.keyboard[SDL_SCANCODE_4] = 0; app.keyboard[SDL_SCANCODE_4] = 0;
printf("DEBUG: dev.noEntityActions=%d\n", dev.noEntityActions); printf("DEBUG: dev.noEntityActions=%d\n", dev.noEntityActions);
} }
if (app.keyboard[SDL_SCANCODE_5]) if (app.keyboard[SDL_SCANCODE_5])
{ {
dev.allImmortal = !dev.allImmortal; dev.allImmortal = !dev.allImmortal;
app.keyboard[SDL_SCANCODE_5] = 0; app.keyboard[SDL_SCANCODE_5] = 0;
printf("DEBUG: dev.allImmortal=%d\n", dev.allImmortal); printf("DEBUG: dev.allImmortal=%d\n", dev.allImmortal);
} }
if (app.keyboard[SDL_SCANCODE_6]) if (app.keyboard[SDL_SCANCODE_6])
{ {
completeMission(); completeMission();
battle.missionFinishedTimer = -FPS; battle.missionFinishedTimer = -FPS;
} }
if (app.keyboard[SDL_SCANCODE_9]) if (app.keyboard[SDL_SCANCODE_9])
{ {
dev.showFPS = !dev.showFPS; dev.showFPS = !dev.showFPS;
app.keyboard[SDL_SCANCODE_9] = 0; app.keyboard[SDL_SCANCODE_9] = 0;
printf("DEBUG: dev.showFPS=%d\n", dev.showFPS); printf("DEBUG: dev.showFPS=%d\n", dev.showFPS);
} }
if (app.keyboard[SDL_SCANCODE_0]) if (app.keyboard[SDL_SCANCODE_0])
{ {
dev.takeScreenshots = !dev.takeScreenshots; dev.takeScreenshots = !dev.takeScreenshots;

View File

@ -28,16 +28,16 @@ void initGraphics(void)
{ {
backgroundPoint[0].x = -app.winWidth / 2; backgroundPoint[0].x = -app.winWidth / 2;
backgroundPoint[0].y = -app.winHeight / 2; backgroundPoint[0].y = -app.winHeight / 2;
backgroundPoint[1].x = app.winWidth / 2; backgroundPoint[1].x = app.winWidth / 2;
backgroundPoint[1].y = -app.winHeight / 2; backgroundPoint[1].y = -app.winHeight / 2;
backgroundPoint[2].x = -app.winWidth / 2; backgroundPoint[2].x = -app.winWidth / 2;
backgroundPoint[2].y = app.winHeight / 2; backgroundPoint[2].y = app.winHeight / 2;
backgroundPoint[3].x = app.winWidth / 2; backgroundPoint[3].x = app.winWidth / 2;
backgroundPoint[3].y = app.winHeight / 2; backgroundPoint[3].y = app.winHeight / 2;
initColor(&colors.red, 255, 0, 0); initColor(&colors.red, 255, 0, 0);
initColor(&colors.orange, 255, 128, 0); initColor(&colors.orange, 255, 128, 0);
initColor(&colors.yellow, 255, 255, 0); initColor(&colors.yellow, 255, 255, 0);
@ -65,7 +65,7 @@ void prepareScene(void)
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
SDL_RenderClear(app.renderer); SDL_RenderClear(app.renderer);
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
SDL_RenderClear(app.renderer); SDL_RenderClear(app.renderer);
@ -74,22 +74,22 @@ void prepareScene(void)
void presentScene(void) void presentScene(void)
{ {
SDL_Rect uiDest; SDL_Rect uiDest;
uiDest.w = UI_WIDTH; uiDest.w = UI_WIDTH;
uiDest.h = UI_HEIGHT; uiDest.h = UI_HEIGHT;
uiDest.x = app.uiOffset.x; uiDest.x = app.uiOffset.x;
uiDest.y = app.uiOffset.y; uiDest.y = app.uiOffset.y;
if (dev.debug) if (dev.debug)
{ {
drawText(5, app.winHeight - 25, 14, TA_LEFT, colors.white, "DEBUG MODE"); drawText(5, app.winHeight - 25, 14, TA_LEFT, colors.white, "DEBUG MODE");
if (dev.showFPS) if (dev.showFPS)
{ {
drawText(app.winWidth / 2, app.winHeight - 25, 14, TA_CENTER, colors.white, "FPS: %d", dev.fps); drawText(app.winWidth / 2, app.winHeight - 25, 14, TA_CENTER, colors.white, "FPS: %d", dev.fps);
} }
} }
SDL_SetRenderTarget(app.renderer, NULL); SDL_SetRenderTarget(app.renderer, NULL);
SDL_RenderCopy(app.renderer, app.backBuffer, NULL, NULL); SDL_RenderCopy(app.renderer, app.backBuffer, NULL, NULL);
SDL_RenderCopy(app.renderer, app.uiBuffer, NULL, &uiDest); SDL_RenderCopy(app.renderer, app.uiBuffer, NULL, &uiDest);
@ -103,7 +103,7 @@ void presentScene(void)
void blit(AtlasImage *atlasImage, int x, int y, int center) void blit(AtlasImage *atlasImage, int x, int y, int center)
{ {
SDL_Rect dstRect; SDL_Rect dstRect;
dstRect.x = x; dstRect.x = x;
dstRect.y = y; dstRect.y = y;
dstRect.w = atlasImage->rect.w; dstRect.w = atlasImage->rect.w;
@ -114,19 +114,19 @@ void blit(AtlasImage *atlasImage, int x, int y, int center)
dstRect.x -= (dstRect.w / 2); dstRect.x -= (dstRect.w / 2);
dstRect.y -= (dstRect.h / 2); dstRect.y -= (dstRect.h / 2);
} }
SDL_RenderCopy(app.renderer, atlasImage->texture, &atlasImage->rect, &dstRect); SDL_RenderCopy(app.renderer, atlasImage->texture, &atlasImage->rect, &dstRect);
} }
void blitScaled(AtlasImage *atlasImage, int x, int y, int w, int h, int center) void blitScaled(AtlasImage *atlasImage, int x, int y, int w, int h, int center)
{ {
SDL_Rect dstRect; SDL_Rect dstRect;
dstRect.x = x; dstRect.x = x;
dstRect.y = y; dstRect.y = y;
dstRect.w = w; dstRect.w = w;
dstRect.h = h; dstRect.h = h;
if (center) if (center)
{ {
dstRect.x -= (dstRect.w / 2); dstRect.x -= (dstRect.w / 2);
@ -139,12 +139,12 @@ void blitScaled(AtlasImage *atlasImage, int x, int y, int w, int h, int center)
void blitRotated(AtlasImage *atlasImage, int x, int y, float angle) void blitRotated(AtlasImage *atlasImage, int x, int y, float angle)
{ {
SDL_Rect dstRect; SDL_Rect dstRect;
dstRect.x = x; dstRect.x = x;
dstRect.y = y; dstRect.y = y;
dstRect.w = atlasImage->rect.w; dstRect.w = atlasImage->rect.w;
dstRect.h = atlasImage->rect.h; dstRect.h = atlasImage->rect.h;
dstRect.x -= (dstRect.w / 2); dstRect.x -= (dstRect.w / 2);
dstRect.y -= (dstRect.h / 2); dstRect.y -= (dstRect.h / 2);
@ -192,27 +192,27 @@ void drawCircle(int cx, int cy, int radius, int r, int g, int b, int a)
void scrollBackground(float x, float y) void scrollBackground(float x, float y)
{ {
int i; int i;
for (i = 0 ; i < 4 ; i++) for (i = 0 ; i < 4 ; i++)
{ {
backgroundPoint[i].x += x; backgroundPoint[i].x += x;
backgroundPoint[i].y += y; backgroundPoint[i].y += y;
if (backgroundPoint[i].x < 0) if (backgroundPoint[i].x < 0)
{ {
backgroundPoint[i].x += (app.winWidth * 2); backgroundPoint[i].x += (app.winWidth * 2);
} }
if (backgroundPoint[i].x >= app.winWidth) if (backgroundPoint[i].x >= app.winWidth)
{ {
backgroundPoint[i].x -= (app.winWidth * 2); backgroundPoint[i].x -= (app.winWidth * 2);
} }
if (backgroundPoint[i].y < 0) if (backgroundPoint[i].y < 0)
{ {
backgroundPoint[i].y += (app.winHeight * 2); backgroundPoint[i].y += (app.winHeight * 2);
} }
if (backgroundPoint[i].y >= app.winHeight) if (backgroundPoint[i].y >= app.winHeight)
{ {
backgroundPoint[i].y -= (app.winHeight * 2); backgroundPoint[i].y -= (app.winHeight * 2);
@ -224,7 +224,7 @@ void drawBackground(SDL_Texture *texture)
{ {
int i; int i;
SDL_Rect dstRect; SDL_Rect dstRect;
for (i = 0 ; i < 4 ; i++) for (i = 0 ; i < 4 ; i++)
{ {
dstRect.x = backgroundPoint[i].x; dstRect.x = backgroundPoint[i].x;
@ -241,17 +241,17 @@ int isOnBattleScreen(int x, int y, int w, int h)
x -= (w / 2); x -= (w / 2);
x -= (app.winWidth / 2); x -= (app.winWidth / 2);
x -= battle.camera.x; x -= battle.camera.x;
y -= (h / 2); y -= (h / 2);
y -= (app.winHeight / 2); y -= (app.winHeight / 2);
y -= battle.camera.y; y -= battle.camera.y;
w *= 2; w *= 2;
w += app.winWidth; w += app.winWidth;
h *= 2; h *= 2;
h += app.winHeight; h += app.winHeight;
return collision(x, y, w, h, 0, 0, app.winWidth, app.winHeight); return collision(x, y, w, h, 0, 0, app.winWidth, app.winHeight);
} }
@ -260,14 +260,14 @@ void saveScreenshot(void)
static int i = 0; static int i = 0;
char filename[MAX_NAME_LENGTH]; char filename[MAX_NAME_LENGTH];
SDL_Surface *sshot; SDL_Surface *sshot;
sprintf(filename, "/tmp/tbftss/%d.bmp", ++i); sprintf(filename, "/tmp/tbftss/%d.bmp", ++i);
sshot = SDL_CreateRGBSurface(0, app.winWidth, app.winHeight, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); sshot = SDL_CreateRGBSurface(0, app.winWidth, app.winHeight, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
SDL_RenderReadPixels(app.renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch); SDL_RenderReadPixels(app.renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch);
SDL_SaveBMP(sshot, filename); SDL_SaveBMP(sshot, filename);
SDL_FreeSurface(sshot); SDL_FreeSurface(sshot);
if (!dev.takeScreenshots) if (!dev.takeScreenshots)
{ {
printf("Saved '%s'\n", filename); printf("Saved '%s'\n", filename);

View File

@ -77,7 +77,7 @@ void setLanguage(char *applicationName, char *languageCode)
{ {
STRNCPY(language, languageCode, MAX_DESCRIPTION_LENGTH); STRNCPY(language, languageCode, MAX_DESCRIPTION_LENGTH);
} }
strtok(language, "."); strtok(language, ".");
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Locale is %s", language); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Locale is %s", language);
@ -100,9 +100,9 @@ void setLanguage(char *applicationName, char *languageCode)
{ {
return; return;
} }
strtok(language, "_"); strtok(language, "_");
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Language is %s", language); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Language is %s", language);
sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName); sprintf(c, "%s/%s/LC_MESSAGES/%s.mo", LOCALE_DIR, language, applicationName);

View File

@ -117,7 +117,7 @@ void doInput(void)
{ {
SDL_Event event; SDL_Event event;
int x, y; int x, y;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
switch (event.type) switch (event.type)
@ -125,11 +125,11 @@ void doInput(void)
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
doMouseMotion(&event.motion); doMouseMotion(&event.motion);
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
doMouseWheel(&event.wheel); doMouseWheel(&event.wheel);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
doMouseDown(&event.button); doMouseDown(&event.button);
break; break;
@ -137,11 +137,11 @@ void doInput(void)
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
doMouseUp(&event.button); doMouseUp(&event.button);
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
doKeyDown(&event.key); doKeyDown(&event.key);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
doKeyUp(&event.key); doKeyUp(&event.key);
break; break;
@ -163,12 +163,12 @@ void doInput(void)
break; break;
} }
} }
SDL_GetMouseState(&x, &y); SDL_GetMouseState(&x, &y);
app.mouse.x = x; app.mouse.x = x;
app.mouse.y = y; app.mouse.y = y;
app.uiMouse.x = x - app.uiOffset.x; app.uiMouse.x = x - app.uiOffset.x;
app.uiMouse.y = y - app.uiOffset.y; app.uiMouse.y = y - app.uiOffset.y;
} }
@ -176,7 +176,7 @@ void doInput(void)
void clearInput(void) void clearInput(void)
{ {
SDL_Event event; SDL_Event event;
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
memset(app.mouse.button, 0, sizeof(int) * MAX_MOUSE_BUTTONS); memset(app.mouse.button, 0, sizeof(int) * MAX_MOUSE_BUTTONS);

View File

@ -47,7 +47,7 @@ char *readFile(char *filename)
char *buffer; char *buffer;
long length; long length;
FILE *file; FILE *file;
file = fopen(getFileLocation(filename), "rb"); file = fopen(getFileLocation(filename), "rb");
if (file) if (file)

View File

@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static Lookup head; static Lookup head;
static Lookup *tail; static Lookup *tail;
static void addLookup(char *name, long value); static void addLookup(char *name, long value);
void initLookups(void) void initLookups(void)
{ {
@ -42,13 +42,13 @@ void initLookups(void)
addLookup("CONTROL_NEXT_FIGHTER", CONTROL_NEXT_FIGHTER); addLookup("CONTROL_NEXT_FIGHTER", CONTROL_NEXT_FIGHTER);
addLookup("CONTROL_PREV_FIGHTER", CONTROL_PREV_FIGHTER); addLookup("CONTROL_PREV_FIGHTER", CONTROL_PREV_FIGHTER);
addLookup("CONTROL_SCREENSHOT", CONTROL_SCREENSHOT); addLookup("CONTROL_SCREENSHOT", CONTROL_SCREENSHOT);
addLookup("ET_WAYPOINT", ET_WAYPOINT); addLookup("ET_WAYPOINT", ET_WAYPOINT);
addLookup("ET_JUMPGATE", ET_JUMPGATE); addLookup("ET_JUMPGATE", ET_JUMPGATE);
addLookup("ET_CAPITAL_SHIP", ET_CAPITAL_SHIP); addLookup("ET_CAPITAL_SHIP", ET_CAPITAL_SHIP);
addLookup("ET_MINE", ET_MINE); addLookup("ET_MINE", ET_MINE);
addLookup("ET_SHADOW_MINE", ET_SHADOW_MINE); addLookup("ET_SHADOW_MINE", ET_SHADOW_MINE);
addLookup("EF_NO_KILL", EF_NO_KILL); addLookup("EF_NO_KILL", EF_NO_KILL);
addLookup("EF_DISABLED", EF_DISABLED); addLookup("EF_DISABLED", EF_DISABLED);
addLookup("EF_MUST_DISABLE", EF_MUST_DISABLE); addLookup("EF_MUST_DISABLE", EF_MUST_DISABLE);
@ -261,14 +261,14 @@ long flagsToLong(char *in, int *add)
{ {
char *flag, *flags; char *flag, *flags;
long total; long total;
total = 0; total = 0;
if (add) if (add)
{ {
*add = (in[0] == '+'); *add = (in[0] == '+');
} }
flags = malloc(strlen(in) + 1); flags = malloc(strlen(in) + 1);
STRNCPY(flags, in, strlen(in) + 1); STRNCPY(flags, in, strlen(in) + 1);
@ -278,7 +278,7 @@ long flagsToLong(char *in, int *add)
total += lookup(flag); total += lookup(flag);
flag = strtok(NULL, "+"); flag = strtok(NULL, "+");
} }
free(flags); free(flags);
return total; return total;

View File

@ -100,13 +100,13 @@ void doModalDialog(void)
void drawModalDialog(void) void drawModalDialog(void)
{ {
SDL_Rect r; SDL_Rect r;
app.textWidth = 700; app.textWidth = 700;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 96); SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 96);
SDL_RenderFillRect(app.renderer, NULL); SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderTarget(app.renderer, app.uiBuffer); SDL_SetRenderTarget(app.renderer, app.uiBuffer);
r.w = 800; r.w = 800;
@ -138,6 +138,6 @@ void drawModalDialog(void)
} }
app.textWidth = 0; app.textWidth = 0;
SDL_SetRenderTarget(app.renderer, app.backBuffer); SDL_SetRenderTarget(app.renderer, app.backBuffer);
} }

View File

@ -43,7 +43,7 @@ void initResources(void)
sprintf(backgrounds[i], "gfx/backgrounds/%s", filenames[i]); sprintf(backgrounds[i], "gfx/backgrounds/%s", filenames[i]);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]);
free(filenames[i]); free(filenames[i]);
} }
@ -56,9 +56,9 @@ void initResources(void)
{ {
planets[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH); planets[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
strcpy(planets[i], filenames[i]); strcpy(planets[i], filenames[i]);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]);
free(filenames[i]); free(filenames[i]);
} }
@ -72,9 +72,9 @@ void initResources(void)
{ {
musicFiles[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH); musicFiles[i] = malloc(sizeof(char) * MAX_FILENAME_LENGTH);
sprintf(musicFiles[i], "music/battle/%s", filenames[i]); sprintf(musicFiles[i], "music/battle/%s", filenames[i]);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Adding AUTO %s", filenames[i]);
free(filenames[i]); free(filenames[i]);
} }
@ -99,17 +99,17 @@ char *getMusicFilename(unsigned long i)
void destroyResources(void) void destroyResources(void)
{ {
int i; int i;
for (i = 0 ; i < numBackgrounds ; i++) for (i = 0 ; i < numBackgrounds ; i++)
{ {
free(backgrounds[i]); free(backgrounds[i]);
} }
for (i = 0 ; i < numPlanets ; i++) for (i = 0 ; i < numPlanets ; i++)
{ {
free(planets[i]); free(planets[i]);
} }
for (i = 0 ; i < numMusicFiles ; i++) for (i = 0 ; i < numMusicFiles ; i++)
{ {
free(musicFiles[i]); free(musicFiles[i]);

View File

@ -92,7 +92,7 @@ void playBattleSound(int id, int x, int y)
if (distance <= MAX_BATTLE_SOUND_DISTANCE) if (distance <= MAX_BATTLE_SOUND_DISTANCE)
{ {
channel = Mix_PlayChannel(-1, sounds[id], 0); channel = Mix_PlayChannel(-1, sounds[id], 0);
if (channel != -1) if (channel != -1)
{ {
vol = 255; vol = 255;

View File

@ -56,13 +56,13 @@ static SDL_Texture *loadTexture(char *filename)
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s ...", filename); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s ...", filename);
texture = IMG_LoadTexture(app.renderer, getFileLocation(filename)); texture = IMG_LoadTexture(app.renderer, getFileLocation(filename));
if (!texture) if (!texture)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_CRITICAL, "Failed to load texture '%s'", filename); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_CRITICAL, "Failed to load texture '%s'", filename);
exit(1); exit(1);
} }
addTextureToCache(filename, texture); addTextureToCache(filename, texture);
return texture; return texture;
@ -83,23 +83,23 @@ SDL_Texture *getTexture(char *filename)
return t->texture; return t->texture;
} }
} }
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "%s not in texture cache", filename); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "%s not in texture cache", filename);
return loadTexture(filename); return loadTexture(filename);
} }
SDL_Texture *toTexture(SDL_Surface *surface, int destroySurface) SDL_Texture *toTexture(SDL_Surface *surface, int destroySurface)
{ {
SDL_Texture *texture; SDL_Texture *texture;
texture = SDL_CreateTextureFromSurface(app.renderer, surface); texture = SDL_CreateTextureFromSurface(app.renderer, surface);
if (destroySurface) if (destroySurface)
{ {
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
} }
return texture; return texture;
} }

View File

@ -27,9 +27,9 @@ void startSectionTransition(void)
transitionStartTime = SDL_GetTicks(); transitionStartTime = SDL_GetTicks();
prepareScene(); prepareScene();
clearInput(); clearInput();
presentScene(); presentScene();
} }

View File

@ -109,16 +109,16 @@ char *timeToString(long millis, int showHours)
char *timeToDate(long millis) char *timeToDate(long millis)
{ {
static char DATE[MAX_NAME_LENGTH]; static char DATE[MAX_NAME_LENGTH];
struct tm *timeinfo; struct tm *timeinfo;
time_t time; time_t time;
time = millis; time = millis;
timeinfo = localtime(&time); timeinfo = localtime(&time);
strftime(DATE, MAX_NAME_LENGTH, "%d %b %Y, %I:%M%p", timeinfo); strftime(DATE, MAX_NAME_LENGTH, "%d %b %Y, %I:%M%p", timeinfo);
return DATE; return DATE;
} }
@ -160,14 +160,14 @@ void *resize(void *array, int oldSize, int newSize)
{ {
void **newArray; void **newArray;
int copySize; int copySize;
copySize = newSize > oldSize ? oldSize : newSize; copySize = newSize > oldSize ? oldSize : newSize;
newArray = malloc(newSize); newArray = malloc(newSize);
memset(newArray, 0, newSize); memset(newArray, 0, newSize);
memcpy(newArray, array, copySize); memcpy(newArray, array, copySize);
free(array); free(array);
return newArray; return newArray;
} }
@ -186,7 +186,7 @@ unsigned long hashcode(const char *str)
} }
hash = ((hash << 5) + hash); hash = ((hash << 5) + hash);
return hash; return hash;
} }

View File

@ -59,17 +59,17 @@ void doWidgets(void)
if (drawingWidgets) if (drawingWidgets)
{ {
updateSelectWidgets(); updateSelectWidgets();
handleMouse(); handleMouse();
handleKeyboard(); handleKeyboard();
if (app.awaitingWidgetInput) if (app.awaitingWidgetInput)
{ {
handleControlWidgets(); handleControlWidgets();
} }
} }
if (hoverWidget != selectedWidget) if (hoverWidget != selectedWidget)
{ {
selectedWidget = NULL; selectedWidget = NULL;
@ -87,12 +87,12 @@ static void updateSelectWidgets(void)
if (w->type == WT_SELECT_BUTTON && w->parent) if (w->type == WT_SELECT_BUTTON && w->parent)
{ {
w->visible = 1; w->visible = 1;
if (w->value == -1 && w->parent->value == 0) if (w->value == -1 && w->parent->value == 0)
{ {
w->visible = 0; w->visible = 0;
} }
if (w->value == 1 && w->parent->value == w->parent->numOptions - 1) if (w->value == 1 && w->parent->value == w->parent->numOptions - 1)
{ {
w->visible = 0; w->visible = 0;
@ -130,7 +130,7 @@ void drawWidgets(const char *group)
drawingWidgets = 1; drawingWidgets = 1;
mouseOver = 0; mouseOver = 0;
hoverWidget = NULL; hoverWidget = NULL;
for (w = head.next; w != NULL ; w = w->next) for (w = head.next; w != NULL ; w = w->next)
@ -144,7 +144,7 @@ void drawWidgets(const char *group)
if (mouseOver) if (mouseOver)
{ {
hoverWidget = w; hoverWidget = w;
if (selectedWidget != w) if (selectedWidget != w)
{ {
if (w->type == WT_BUTTON || w->type == WT_IMG_BUTTON || w->type == WT_CONTROL_CONFIG) if (w->type == WT_BUTTON || w->type == WT_IMG_BUTTON || w->type == WT_CONTROL_CONFIG)
@ -160,12 +160,12 @@ void drawWidgets(const char *group)
if (w->texture) if (w->texture)
{ {
setAtlasColor(255, 255, 255, 255); setAtlasColor(255, 255, 255, 255);
if (selectedWidget == w) if (selectedWidget == w)
{ {
setAtlasColor(128, 192, 255, 255); setAtlasColor(128, 192, 255, 255);
} }
blit(w->texture , w->rect.x, w->rect.y, 0); blit(w->texture , w->rect.x, w->rect.y, 0);
} }
else else
@ -198,10 +198,10 @@ void drawWidgets(const char *group)
drawText(w->rect.x + 10, w->rect.y + 2, 20, TA_LEFT, colors.white, w->text); drawText(w->rect.x + 10, w->rect.y + 2, 20, TA_LEFT, colors.white, w->text);
drawText(w->rect.x + w->rect.w - 10, w->rect.y + 2, 20, TA_RIGHT, colors.white, w->options[w->value]); drawText(w->rect.x + w->rect.w - 10, w->rect.y + 2, 20, TA_RIGHT, colors.white, w->options[w->value]);
break; break;
case WT_CONTROL_CONFIG: case WT_CONTROL_CONFIG:
SDL_RenderDrawRect(app.renderer, &w->rect); SDL_RenderDrawRect(app.renderer, &w->rect);
if (!app.awaitingWidgetInput || (app.awaitingWidgetInput && w != selectedWidget)) if (!app.awaitingWidgetInput || (app.awaitingWidgetInput && w != selectedWidget))
{ {
if (strlen(w->options[0]) && strlen(w->options[1])) if (strlen(w->options[0]) && strlen(w->options[1]))
@ -302,7 +302,7 @@ static void handleMouse(void)
changeSelectedValue(selectedWidget->parent, selectedWidget->value); changeSelectedValue(selectedWidget->parent, selectedWidget->value);
app.mouse.button[SDL_BUTTON_LEFT] = 0; app.mouse.button[SDL_BUTTON_LEFT] = 0;
break; break;
case WT_CONTROL_CONFIG: case WT_CONTROL_CONFIG:
if (!app.awaitingWidgetInput) if (!app.awaitingWidgetInput)
{ {
@ -320,7 +320,7 @@ static void handleMouse(void)
static void handleKeyboard(void) static void handleKeyboard(void)
{ {
Widget *old; Widget *old;
if (selectedWidget != NULL) if (selectedWidget != NULL)
{ {
if (selectedWidget->type == WT_BUTTON) if (selectedWidget->type == WT_BUTTON)
@ -347,7 +347,7 @@ static void handleControlWidgets(void)
if (app.lastKeyPressed == SDL_SCANCODE_BACKSPACE) if (app.lastKeyPressed == SDL_SCANCODE_BACKSPACE)
{ {
clearControlConfig(selectedWidget->name); clearControlConfig(selectedWidget->name);
app.awaitingWidgetInput = 0; app.awaitingWidgetInput = 0;
} }
else if (app.lastKeyPressed == SDL_SCANCODE_ESCAPE) else if (app.lastKeyPressed == SDL_SCANCODE_ESCAPE)
@ -360,23 +360,23 @@ static void handleControlWidgets(void)
if (app.lastKeyPressed != -1) if (app.lastKeyPressed != -1)
{ {
updateControlKey(selectedWidget->name); updateControlKey(selectedWidget->name);
app.awaitingWidgetInput = 0; app.awaitingWidgetInput = 0;
} }
if (app.lastButtonPressed != -1) if (app.lastButtonPressed != -1)
{ {
updateControlButton(selectedWidget->name); updateControlButton(selectedWidget->name);
app.awaitingWidgetInput = 0; app.awaitingWidgetInput = 0;
} }
} }
if (!app.awaitingWidgetInput) if (!app.awaitingWidgetInput)
{ {
clearInput(); clearInput();
} }
app.lastKeyPressed = app.lastButtonPressed = -1; app.lastKeyPressed = app.lastButtonPressed = -1;
} }
@ -410,7 +410,7 @@ static void loadWidgetSet(char *filename)
text = readFile(filename); text = readFile(filename);
root = cJSON_Parse(text); root = cJSON_Parse(text);
if (root) if (root)
{ {
for (node = root->child ; node != NULL ; node = node->next) for (node = root->child ; node != NULL ; node = node->next)
@ -456,12 +456,12 @@ static void loadWidgetSet(char *filename)
createSelectButtons(w); createSelectButtons(w);
createOptions(w, cJSON_GetObjectItem(node, "options")->valuestring); createOptions(w, cJSON_GetObjectItem(node, "options")->valuestring);
break; break;
case WT_CONTROL_CONFIG: case WT_CONTROL_CONFIG:
w->rect.w = cJSON_GetObjectItem(node, "w")->valueint; w->rect.w = cJSON_GetObjectItem(node, "w")->valueint;
w->rect.h = cJSON_GetObjectItem(node, "h")->valueint; w->rect.h = cJSON_GetObjectItem(node, "h")->valueint;
break; break;
default: default:
printf("Widget type %d not handled\n", w->type); printf("Widget type %d not handled\n", w->type);
exit(1); exit(1);
@ -478,7 +478,7 @@ static void loadWidgetSet(char *filename)
{ {
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to load '%s'", filename); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to load '%s'", filename);
} }
free(text); free(text);
} }
@ -504,7 +504,7 @@ static void createOptions(Widget *w, char *options)
while (option) while (option)
{ {
option = _(option); option = _(option);
w->options[i] = malloc(strlen(option) + 1); w->options[i] = malloc(strlen(option) + 1);
strcpy(w->options[i], option); strcpy(w->options[i], option);
@ -552,25 +552,25 @@ void autoSizeWidgetButtons(char *group, int recenter)
{ {
int width, height, maxWidth; int width, height, maxWidth;
Widget *w; Widget *w;
maxWidth = 0; maxWidth = 0;
for (w = head.next; w != NULL ; w = w->next) for (w = head.next; w != NULL ; w = w->next)
{ {
if (strcmp(w->group, group) == 0 && w->type == WT_BUTTON) if (strcmp(w->group, group) == 0 && w->type == WT_BUTTON)
{ {
calcTextDimensions(w->text, 20, &width, &height); calcTextDimensions(w->text, 20, &width, &height);
maxWidth = MAX(MAX(w->rect.w, width), maxWidth); maxWidth = MAX(MAX(w->rect.w, width), maxWidth);
} }
} }
for (w = head.next; w != NULL ; w = w->next) for (w = head.next; w != NULL ; w = w->next)
{ {
if (strcmp(w->group, group) == 0 && w->type == WT_BUTTON) if (strcmp(w->group, group) == 0 && w->type == WT_BUTTON)
{ {
w->rect.w = maxWidth + 20; w->rect.w = maxWidth + 20;
if (recenter) if (recenter)
{ {
w->rect.x = (UI_WIDTH / 2) - (w->rect.w / 2); w->rect.x = (UI_WIDTH / 2) - (w->rect.w / 2);
@ -591,7 +591,7 @@ void destroyWidgets(void)
{ {
free(w->options[i]); free(w->options[i]);
} }
free(w->options); free(w->options);
next = w->next; next = w->next;

View File

@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void loadTestMission(char *filename) void loadTestMission(char *filename)
{ {
game.currentMission = loadMissionMeta(filename); game.currentMission = loadMissionMeta(filename);
initBattle(); initBattle();
loadMission(filename); loadMission(filename);
} }