Only a few were actual errors.
if (!loadData("data/defines.h"))
return false;
- char *token = strtok((char*)dataBuffer, "\n");
-
- Data *data;
+ strtok((char*)dataBuffer, "\n");
while (true)
{
- token = strtok(NULL, "\n");
+ char *token = strtok(NULL, "\n");
if (!token)
break;
if (!strstr(token, "/*"))
{
sscanf(token, "%*s %s %[^\n\r]", string[0], string[1]);
- data = new Data();
+ Data *data = new Data();
data->set(string[0], string[1], 1, 1);
defineList.add(data);
}
void Graphics::setTransparent(SDL_Surface *sprite)
{
- SDL_SetColorKey(sprite, SDL_TRUE, SDL_MapRGB(sprite->format, 0, 0, 0));
+ if (sprite)
+ SDL_SetColorKey(sprite, SDL_TRUE, SDL_MapRGB(sprite->format, 0, 0, 0));
}
bool Graphics::canShowMedalMessage() const
#endif
if (!image)
- showErrorAndExit(ERR_FILE, filename);
+ return showErrorAndExit(ERR_FILE, filename), image;
newImage = SDL_ConvertSurface(image, screen->format, 0);
#endif
if (!image)
- showErrorAndExit(ERR_FILE, filename);
+ return showErrorAndExit(ERR_FILE, filename), image;
if ((hue != 0) || (sat != 0) || (value != 0))
{
{
tile[i] = loadImage(filename);
+ if (!tile[i])
+ abort();
+
if (autoAlpha)
{
if ((i < MAP_EXITSIGN) || (i >= MAP_WATERANIM))
{
if (!image)
{
- showErrorAndExit("graphics::blit() - NULL pointer", SDL_GetError());
+ return showErrorAndExit("graphics::blit() - NULL pointer", SDL_GetError());
}
if ((x < -image->w) || (x > 640 + image->w))
if (!fp)
{
printf("ERROR: Replay file '%s' could not be loaded.\n", filename);
- replayMode = REPLAY_MODE::NONE;
+ this->replayMode = REPLAY_MODE::NONE;
return;
}
if (fread(&header, sizeof(ReplayDataHeader), 1, fp) != 1)
{
printf("ERROR: Replay file '%s' is corrupt\n", filename);
- replayMode = REPLAY_MODE::NONE;
+ this->replayMode = REPLAY_MODE::NONE;
fclose(fp);
return;
}
if (!fp)
{
printf("ERROR: Replay file '%s' could not be opened for writing.\n", filename);
- replayMode = REPLAY_MODE::NONE;
+ this->replayMode = REPLAY_MODE::NONE;
return;
}
if (size != 1)
{
printf("Error writing replay data header: %s\n", strerror(errno));
- replayMode = REPLAY_MODE::NONE;
+ this->replayMode = REPLAY_MODE::NONE;
fclose(fp);
fp = NULL;
return;
line = strtok(NULL, "\n");
}
- if (strcmp(line, "@none@") != 0)
+ if (scene && strcmp(line, "@none@") != 0)
{
scene->appendText(line);
}
char sceneLine[1024];
if (!engine.loadData(_("data/ending")))
- graphics.showErrorAndExit("Couldn't load cutscene data file (%s)", _("data/ending"));
+ return graphics.showErrorAndExit("Couldn't load cutscene data file (%s)", _("data/ending")), false;
char *line = strtok((char*)engine.dataBuffer, "\n");
int i = 0;
void addEnemy(const char *name, int x, int y, int flags)
{
- Entity *enemy = new Entity();
Entity *defEnemy = getDefinedEnemy(name);
if (defEnemy == NULL)
return;
}
+ Entity *enemy = new Entity();
enemy->setName(defEnemy->name);
enemy->setSprites(defEnemy->sprite[0], defEnemy->sprite[1], defEnemy->sprite[2]);
enemy->currentWeapon = defEnemy->currentWeapon;
if (!engine.loadData("data/defEnemies"))
{
- graphics.showErrorAndExit("Couldn't load enemy definitions file (%s)", "data/defEnemies");
+ return graphics.showErrorAndExit("Couldn't load enemy definitions file (%s)", "data/defEnemies");
}
char *token = strtok((char*)engine.dataBuffer, "\n");
{
if (!engine.loadWidgets(_("data/inGameWidgets")))
{
- graphics.showErrorAndExit(ERR_FILE, _("data/inGameWidgets"));
+ return graphics.showErrorAndExit(ERR_FILE, _("data/inGameWidgets"));
}
graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen);
if (!engine.loadWidgets(_("data/gameOverWidgets")))
{
- graphics.showErrorAndExit(ERR_FILE, _("data/gameOverWidgets"));
+ return graphics.showErrorAndExit(ERR_FILE, _("data/gameOverWidgets")), SECTION_GAME;
}
SDL_Surface *gameover = graphics.quickSprite("Game Over", graphics.loadImage("gfx/main/gameover.png"));
SDL_FillRect(graphics.screen, NULL, graphics.black);
graphics.delay(1000);
- Uint32 then, frames, frameLimit, millis;
+ Uint32 frames, frameLimit, millis;
Uint32 start, cur;
#if DEBUG
- Uint32 now, frameCounter;
+ Uint32 now, then, frameCounter;
char fps[10];
strlcpy(fps, "fps", sizeof fps);
#endif
frameLimit = SDL_GetTicks() + 16;
frames = millis = 0;
- start = then = SDL_GetTicks();
+ start = SDL_GetTicks();
#ifdef DEBUG
- frameCounter = SDL_GetTicks();
+ then = frameCounter = start;
#endif
if ((strcmp(map.name, "Space Station") == 0) && (!game.continueFromCheckPoint))
config.populate();
config.doPause();
graphics.updateScreen();
+ #ifdef DEBUG
then = SDL_GetTicks();
+ #endif
frames = 0;
if (!engine.paused)
{
loadResources();
- Sprite *sprite = graphics.getSpriteHead();
-
int x, y, h;
unsigned int frameLimit = SDL_GetTicks() + 16;
SDL_FillRect(graphics.screen, NULL, graphics.black);
- sprite = graphics.getSpriteHead();
+ Sprite *sprite = graphics.getSpriteHead();
while (sprite->next != NULL)
{
#endif
#if !defined(OpenBSD) && !defined(FreeBSD)
-#define strlcat(dest, src, n) strncat((dest), (src), (n) - 1)
-#define strlcpy(dest, src, n) do {strncpy((dest), (src), (n)); (dest)[(n) - 1] = 0;} while(false)
+static inline void strlcat(char *dest, const char *src, size_t n) { strncat(dest, src, n - 1); }
+static inline void strlcpy(char *dest, const char *src, size_t n) { strncpy(dest, src, n); dest[n - 1] = 0; }
#endif
#include "defs.h"
graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
- y += 10;
-
snprintf(string, sizeof string, "%s - %.2d:%.2d:%.2d", _("Mission Time"), game.currentMissionHours, game.currentMissionMinutes, game.currentMissionSeconds);
graphics.drawString(string, 320, 430, TXT_CENTERED, graphics.screen);
}
if (!line[i])
{
- graphics.showErrorAndExit("Malformed Intro Data", "");
+ return graphics.showErrorAndExit("Malformed Intro Data", "");
}
text[i] = NULL;
audio.playMusic();
- char *line = strtok((char*)engine.dataBuffer, "\n");
+ strtok((char*)engine.dataBuffer, "\n");
while (true)
{
- line = strtok(NULL, "\n");
+ char *line = strtok(NULL, "\n");
sscanf(line, "%d %d %d", &x, &y, &delay);
if (delay == -1)
void doItems()
{
Entity *item = (Entity*)map.itemList.getHead();
- Entity *previous = item;
-
- int x, y;
while (item->next != NULL)
{
- previous = item;
+ Entity *previous = item;
item = (Entity*)item->next;
continue;
}
- x = (int)(item->x - engine.playerPosX);
- y = (int)(item->y - engine.playerPosY);
+ int x = (int)(item->x - engine.playerPosX);
+ int y = (int)(item->y - engine.playerPosY);
item->think();
graphics.blit(background, 0, 0, panel, false);
- int color = graphics.black;
-
for (int y = 0 ; y < 48 ; y++)
{
for (int x = 0 ; x < 64 ; x++)
{
for (int x = 0 ; x < 64 ; x++)
{
- color = graphics.black;
+ int color = graphics.black;
if (map.data[x1 + x][y1 + y] == MAP_AIR)
{
int y = 520;
int miaY = 335;
int clearY = 520;
- Objective *objective = (Objective*)map.objectiveList.getHead();
Entity *mia = (Entity*)map.miaList.getHead();
Sprite *teleportStar = graphics.getSprite("TeleportStar", true);
char message[256];
place += 25;
}
- if (count > colCount)
- count = colCount;
-
if (place > (colCount * 25))
place = colCount * 25;
}
}
- objective = (Objective*)map.objectiveList.getHead();
+ Objective *objective = (Objective*)map.objectiveList.getHead();
engine.setPlayerPosition(0, 0, -1, -1, -1, -1);
void addWindParticles()
{
- int c = graphics.white;
+ int c;
float x, y, dx, dy;
dx = -1;
}
- int x = (int)self->x;
+ int x;
int y = (int)self->y + 10;
Entity *enemy = NULL;
int i = 0;
int numberOfCredits = 0;
int pos1 = 0, pos2 = 0, size = 0;
- float *y, deviceY;
+ float *y, deviceY = 0;
SDL_Surface *backdrop = graphics.quickSprite("CreditsBackGround", graphics.loadImage("gfx/main/creditsBack.png"));
{
oldX = (int)train->x;
oldY = (int)train->y;
- playSound = false;
playSound = train->openClose();
setTrainSprite(train);
}
- if ((abs(x) <= 800) && (abs(y) <= 600))
+ if (train->sprite && (abs(x) <= 800) && (abs(y) <= 600))
{
graphics.blit(train->sprite->getCurrentFrame(), x, y, graphics.screen, false);
}