Some code cleanup.

Fixed some cases where I put spaces instead of tabs earlier, and
changed all cases of "weapons[0]" with "weapons[W_PLAYER_WEAPON]".
This commit is contained in:
onpon4 2015-02-28 08:15:53 -05:00
parent 71abee2a16
commit 26a82a6385
10 changed files with 79 additions and 56 deletions

View File

@ -224,7 +224,8 @@ bool addAlien()
signed char randEnemy = alienArray[rand() % numberOfAliens]; signed char randEnemy = alienArray[rand() % numberOfAliens];
if ((currentGame.area != 10) && (currentGame.area != 15) && (currentGame.area != 24)) if ((currentGame.area != 10) && (currentGame.area != 15) &&
(currentGame.area != 24))
{ {
if ((currentGame.system == 1) && (currentGame.area == MAX_MISSIONS - 1)) if ((currentGame.system == 1) && (currentGame.area == MAX_MISSIONS - 1))
{ {
@ -1088,12 +1089,14 @@ void doAliens()
limitCharAdd(&theEnemy->reload[0], -1, 0, 999); limitCharAdd(&theEnemy->reload[0], -1, 0, 999);
limitCharAdd(&theEnemy->reload[1], -1, 0, 999); limitCharAdd(&theEnemy->reload[1], -1, 0, 999);
if ((!(theEnemy->flags & FL_DISABLED)) && (!(theEnemy->flags & FL_NOFIRE))) if ((!(theEnemy->flags & FL_DISABLED)) &&
(!(theEnemy->flags & FL_NOFIRE)))
{ {
if ((theEnemy->target->shield > 0)) if ((theEnemy->target->shield > 0))
canFire = traceTarget(theEnemy); canFire = traceTarget(theEnemy);
if (((theEnemy->thinktime % 2) == 0) && (theEnemy->flags & FL_FRIEND)) if (((theEnemy->thinktime % 2) == 0) &&
(theEnemy->flags & FL_FRIEND))
canFire = traceView(theEnemy); canFire = traceView(theEnemy);
} }
else else
@ -1103,13 +1106,18 @@ void doAliens()
if ((canFire) && (dev.fireAliens)) if ((canFire) && (dev.fireAliens))
{ {
if ((theEnemy->reload[0] == 0) && ((rand() % 1000 < theEnemy->chance[0]) || (theEnemy->flags & FL_CONTINUOUS_FIRE))) if ((theEnemy->reload[0] == 0) &&
((rand() % 1000 < theEnemy->chance[0]) ||
(theEnemy->flags & FL_CONTINUOUS_FIRE)))
{ {
fireBullet(theEnemy, 0); fireBullet(theEnemy, 0);
} }
if ((theEnemy->reload[1] == 0) && ((rand() % 1000 < theEnemy->chance[1]) || (theEnemy->flags & FL_CONTINUOUS_FIRE))) if ((theEnemy->reload[1] == 0) &&
((rand() % 1000 < theEnemy->chance[1]) ||
(theEnemy->flags & FL_CONTINUOUS_FIRE)))
{ {
if ((theEnemy->weaponType[1] != W_ENERGYRAY) && (theEnemy->weaponType[1] != W_LASER)) if ((theEnemy->weaponType[1] != W_ENERGYRAY) &&
(theEnemy->weaponType[1] != W_LASER))
{ {
if (theEnemy->weaponType[1] == W_CHARGER) if (theEnemy->weaponType[1] == W_CHARGER)
theEnemy->ammo[1] = 50 + rand() % 150; theEnemy->ammo[1] = 50 + rand() % 150;
@ -1119,7 +1127,8 @@ void doAliens()
{ {
theEnemy->flags += FL_FIRELASER; theEnemy->flags += FL_FIRELASER;
} }
else if ((theEnemy->weaponType[1] == W_ENERGYRAY) && (theEnemy->ammo[0] == 250)) else if ((theEnemy->weaponType[1] == W_ENERGYRAY) &&
(theEnemy->ammo[0] == 250))
{ {
theEnemy->flags += FL_FIRERAY; theEnemy->flags += FL_FIRERAY;
playSound(SFX_ENERGYRAY, theEnemy->x); playSound(SFX_ENERGYRAY, theEnemy->x);
@ -1151,12 +1160,14 @@ void doAliens()
if (theEnemy->flags & FL_DROPMINES) if (theEnemy->flags & FL_DROPMINES)
if ((rand() % 150) == 0) if ((rand() % 150) == 0)
addCollectable(theEnemy->x, theEnemy->y, P_MINE, 25, 600 + rand() % 2400); addCollectable(theEnemy->x, theEnemy->y, P_MINE, 25,
600 + rand() % 2400);
// Kline drops mines a lot more often // Kline drops mines a lot more often
if ((theEnemy->flags & FL_DROPMINES) && (theEnemy == &enemy[WC_KLINE])) if ((theEnemy->flags & FL_DROPMINES) && (theEnemy == &enemy[WC_KLINE]))
if ((rand() % 10) == 0) if ((rand() % 10) == 0)
addCollectable(theEnemy->x, theEnemy->y, P_MINE, 25, 600 + rand() % 2400); addCollectable(theEnemy->x, theEnemy->y, P_MINE, 25,
600 + rand() % 2400);
// ------------------------------------------------------- // -------------------------------------------------------
@ -1194,8 +1205,13 @@ void doAliens()
if (theEnemy->shield < theEnemy->deathCounter) if (theEnemy->shield < theEnemy->deathCounter)
{ {
theEnemy->active = false; theEnemy->active = false;
if ((theEnemy->classDef == CD_BOSS) || (theEnemy->owner == &enemy[WC_BOSS]) || (theEnemy->flags & FL_FRIEND) || (theEnemy->classDef == CD_ASTEROID) || (theEnemy->classDef == CD_KLINE)) if ((theEnemy->classDef == CD_BOSS) ||
addDebris((int)theEnemy->x, (int)theEnemy->y, theEnemy->maxShield); (theEnemy->owner == &enemy[WC_BOSS]) ||
(theEnemy->flags & FL_FRIEND) ||
(theEnemy->classDef == CD_ASTEROID) ||
(theEnemy->classDef == CD_KLINE))
addDebris((int)theEnemy->x, (int)theEnemy->y,
theEnemy->maxShield);
if (theEnemy->classDef == CD_ASTEROID) if (theEnemy->classDef == CD_ASTEROID)
{ {
@ -1207,10 +1223,9 @@ void doAliens()
} }
// Adjust the movement even whilst exploding // Adjust the movement even whilst exploding
if ((dev.moveAliens) && (!(theEnemy->flags & FL_NOMOVE)) && (!(theEnemy->flags & FL_DISABLED))) if ((dev.moveAliens) && (!(theEnemy->flags & FL_NOMOVE)) &&
{ (!(theEnemy->flags & FL_DISABLED)))
moveAndSeparate(theEnemy); moveAndSeparate(theEnemy);
}
if ((currentGame.area != 18) || (theEnemy->shield < 0)) if ((currentGame.area != 18) || (theEnemy->shield < 0))
theEnemy->x += engine.ssx + engine.smx; theEnemy->x += engine.ssx + engine.smx;

View File

@ -215,9 +215,9 @@ void fireBullet(object *attacker, int weaponType)
player.ammo[0]--; player.ammo[0]--;
if (player.ammo[0] == 0) if (player.ammo[0] == 0)
{ {
weapon[0].ammo[0] = currentGame.minPlasmaOutput; weapon[W_PLAYER_WEAPON].ammo[0] = currentGame.minPlasmaOutput;
weapon[0].damage = currentGame.minPlasmaDamage; weapon[W_PLAYER_WEAPON].damage = currentGame.minPlasmaDamage;
weapon[0].reload[0] = rate2reload[currentGame.minPlasmaRate]; weapon[W_PLAYER_WEAPON].reload[0] = rate2reload[currentGame.minPlasmaRate];
} }
} }
} }

View File

@ -301,11 +301,11 @@ void doCollectables()
case P_PLASMA_RATE: case P_PLASMA_RATE:
if (player.ammo[0] < 50) if (player.ammo[0] < 50)
player.ammo[0] = 50; player.ammo[0] = 50;
if (weapon[0].reload[0] <= rate2reload[currentGame.maxPlasmaRate]) if (weapon[W_PLAYER_WEAPON].reload[0] <= rate2reload[currentGame.maxPlasmaRate])
sprintf(temp, "Firing Rate already at Maximum"); sprintf(temp, "Firing Rate already at Maximum");
else else
{ {
weapon[0].reload[0] -= 2; weapon[W_PLAYER_WEAPON].reload[0] -= 2;
sprintf(temp, "Firing rate increased"); sprintf(temp, "Firing rate increased");
} }
currentGame.powerups++; currentGame.powerups++;
@ -314,11 +314,11 @@ void doCollectables()
case P_PLASMA_SHOT: case P_PLASMA_SHOT:
if (player.ammo[0] < 50) if (player.ammo[0] < 50)
player.ammo[0] = 50; player.ammo[0] = 50;
if (weapon[0].ammo[0] >= currentGame.maxPlasmaOutput) if (weapon[W_PLAYER_WEAPON].ammo[0] >= currentGame.maxPlasmaOutput)
sprintf(temp, "Plasma output already at Maximum"); sprintf(temp, "Plasma output already at Maximum");
else else
{ {
weapon[0].ammo[0]++; weapon[W_PLAYER_WEAPON].ammo[0]++;
sprintf(temp, "Plasma output increased"); sprintf(temp, "Plasma output increased");
} }
currentGame.powerups++; currentGame.powerups++;
@ -327,20 +327,20 @@ void doCollectables()
case P_PLASMA_DAMAGE: case P_PLASMA_DAMAGE:
if (player.ammo[0] < 50) if (player.ammo[0] < 50)
player.ammo[0] = 50; player.ammo[0] = 50;
if (weapon[0].damage >= currentGame.maxPlasmaDamage) if (weapon[W_PLAYER_WEAPON].damage >= currentGame.maxPlasmaDamage)
sprintf(temp, "Plasma damage already at Maximum"); sprintf(temp, "Plasma damage already at Maximum");
else { else {
weapon[0].damage++; weapon[W_PLAYER_WEAPON].damage++;
sprintf(temp, "Plasma damage increased"); sprintf(temp, "Plasma damage increased");
} }
currentGame.powerups++; currentGame.powerups++;
break; break;
case P_SUPER: case P_SUPER:
weapon[0].ammo[0] = 5; weapon[W_PLAYER_WEAPON].ammo[0] = 5;
weapon[0].damage = 5; weapon[W_PLAYER_WEAPON].damage = 5;
weapon[0].reload[0] = rate2reload[5]; weapon[W_PLAYER_WEAPON].reload[0] = rate2reload[5];
weapon[0].flags |= WF_SPREAD; weapon[W_PLAYER_WEAPON].flags |= WF_SPREAD;
sprintf(temp, "Picked up a Super Charge!!"); sprintf(temp, "Picked up a Super Charge!!");
@ -404,9 +404,9 @@ void doCollectables()
// stop people from exploiting a weapon check condition // stop people from exploiting a weapon check condition
if (player.ammo[0] == 0) if (player.ammo[0] == 0)
{ {
weapon[0].ammo[0] = currentGame.minPlasmaOutput; weapon[W_PLAYER_WEAPON].ammo[0] = currentGame.minPlasmaOutput;
weapon[0].damage = currentGame.minPlasmaDamage; weapon[W_PLAYER_WEAPON].damage = currentGame.minPlasmaDamage;
weapon[0].reload[0] = rate2reload[currentGame.minPlasmaRate]; weapon[W_PLAYER_WEAPON].reload[0] = rate2reload[currentGame.minPlasmaRate];
} }
} }

View File

@ -109,7 +109,7 @@ void doExplosions()
{ {
prevExplosion->next = explosion->next; prevExplosion->next = explosion->next;
delete explosion; delete explosion;
explosion = prevExplosion; explosion = prevExplosion;
} }
} }
} }

View File

@ -159,7 +159,8 @@ void initSystem()
#endif #endif
/* Initialize the SDL library */ /* Initialize the SDL library */
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK) < 0) { if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK) < 0)
{
printf("Couldn't initialize SDL: %s\n", SDL_GetError()); printf("Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1); exit(1);
} }
@ -184,14 +185,16 @@ void initSystem()
screen = SDL_CreateRGBSurface(0, screenWidth, screenHeight, 32, 0xff0000, 0xff00, 0xff, 0xff000000); screen = SDL_CreateRGBSurface(0, screenWidth, screenHeight, 32, 0xff0000, 0xff00, 0xff, 0xff000000);
if (!screen) { if (!screen)
{
printf("Couldn't create %ix%ix32 surface: %s\n", screenWidth, screenHeight, SDL_GetError()); printf("Couldn't create %ix%ix32 surface: %s\n", screenWidth, screenHeight, SDL_GetError());
exit(1); exit(1);
} }
window = SDL_CreateWindow("Project: Starfighter", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen->w, screen->h, 0); window = SDL_CreateWindow("Project: Starfighter", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen->w, screen->h, 0);
if (window == NULL) { if (window == NULL)
{
printf("Could not create window: %s\n", SDL_GetError()); printf("Could not create window: %s\n", SDL_GetError());
exit(1); exit(1);
} }
@ -201,7 +204,8 @@ void initSystem()
renderer = SDL_CreateRenderer(window, -1, 0); renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) { if (!renderer)
{
printf("Could not create renderer: %s\n", SDL_GetError()); printf("Could not create renderer: %s\n", SDL_GetError());
exit(1); exit(1);
} }
@ -210,7 +214,8 @@ void initSystem()
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen->w, screen->h); texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen->w, screen->h);
if (!texture) { if (!texture)
{
printf("Couldn't create %ix%ix32 texture: %s\n", screen->w, screen->h, SDL_GetError()); printf("Couldn't create %ix%ix32 texture: %s\n", screen->w, screen->h, SDL_GetError());
exit(1); exit(1);
} }
@ -228,8 +233,8 @@ void initSystem()
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE); SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE);
SDL_JoystickEventState(SDL_ENABLE); SDL_JoystickEventState(SDL_ENABLE);
SDL_JoystickOpen(0); SDL_JoystickOpen(0);
} }
/* /*

View File

@ -481,10 +481,12 @@ int galaxyMap()
// Remove the Supercharge, if it is there // Remove the Supercharge, if it is there
if (currentGame.difficulty > DIFFICULTY_EASY) if (currentGame.difficulty > DIFFICULTY_EASY)
{ {
weapon[0].reload[0] = max(weapon[0].reload[0], weapon[W_PLAYER_WEAPON].reload[0] = max(weapon[W_PLAYER_WEAPON].reload[0],
rate2reload[currentGame.maxPlasmaRate]); rate2reload[currentGame.maxPlasmaRate]);
weapon[0].ammo[0] = min(weapon[0].ammo[0], currentGame.maxPlasmaOutput); weapon[W_PLAYER_WEAPON].ammo[0] = min(weapon[W_PLAYER_WEAPON].ammo[0],
weapon[0].damage = min(weapon[0].damage, currentGame.maxPlasmaDamage); currentGame.maxPlasmaOutput);
weapon[W_PLAYER_WEAPON].damage = min(weapon[W_PLAYER_WEAPON].damage,
currentGame.maxPlasmaDamage);
} }
clearScreen(black); clearScreen(black);

View File

@ -101,7 +101,7 @@ bool loadGame(int slot)
if (currentGame.saveFormat < 2) if (currentGame.saveFormat < 2)
currentGame.difficulty = DIFFICULTY_NORMAL; currentGame.difficulty = DIFFICULTY_NORMAL;
weapon[0] = currentGame.playerWeapon; weapon[W_PLAYER_WEAPON] = currentGame.playerWeapon;
player = currentGame.thePlayer; player = currentGame.thePlayer;
// Re-init all the planets in this system... // Re-init all the planets in this system...
@ -128,7 +128,7 @@ void saveGame(int slot)
fp = fopen(fileName, "wb"); fp = fopen(fileName, "wb");
currentGame.saveFormat = 2; currentGame.saveFormat = 2;
currentGame.playerWeapon = weapon[0]; currentGame.playerWeapon = weapon[W_PLAYER_WEAPON];
currentGame.thePlayer = player; currentGame.thePlayer = player;
for (int i = 0 ; i < 10 ; i++) for (int i = 0 ; i < 10 ; i++)
currentGame.missionCompleted[i] = systemPlanet[i].missionCompleted; currentGame.missionCompleted[i] = systemPlanet[i].missionCompleted;

View File

@ -331,7 +331,7 @@ void doInfo()
for (int i = 1 ; i <= 5 ; i++) for (int i = 1 ; i <= 5 ; i++)
{ {
if (weapon[0].damage >= i) { if (weapon[W_PLAYER_WEAPON].damage >= i) {
if(i <= currentGame.maxPlasmaDamage || (SDL_GetTicks() % 1000 > (unsigned)i * 100)) if(i <= currentGame.maxPlasmaDamage || (SDL_GetTicks() % 1000 > (unsigned)i * 100))
{ {
SDL_FillRect(screen, &bar, green); SDL_FillRect(screen, &bar, green);
@ -351,7 +351,7 @@ void doInfo()
for (int i = 1 ; i <= 5 ; i++) for (int i = 1 ; i <= 5 ; i++)
{ {
if (weapon[0].ammo[0] >= i) { if (weapon[W_PLAYER_WEAPON].ammo[0] >= i) {
if(i <= currentGame.maxPlasmaOutput || (SDL_GetTicks() % 1000 > (unsigned)i * 100)) if(i <= currentGame.maxPlasmaOutput || (SDL_GetTicks() % 1000 > (unsigned)i * 100))
{ {
SDL_FillRect(screen, &bar, yellow); SDL_FillRect(screen, &bar, yellow);
@ -371,7 +371,7 @@ void doInfo()
for (int i = 1 ; i <= 5 ; i++) for (int i = 1 ; i <= 5 ; i++)
{ {
if (weapon[0].reload[0] <= rate2reload[i]) { if (weapon[W_PLAYER_WEAPON].reload[0] <= rate2reload[i]) {
if(i <= currentGame.maxPlasmaRate || (SDL_GetTicks() % 1000 > (unsigned)i * 100)) if(i <= currentGame.maxPlasmaRate || (SDL_GetTicks() % 1000 > (unsigned)i * 100))
{ {
SDL_FillRect(screen, &bar, blue); SDL_FillRect(screen, &bar, blue);

View File

@ -552,7 +552,7 @@ bool allMissionsCompleted()
setInfoLine("*** Interception Destroyed ***", FONT_GREEN); setInfoLine("*** Interception Destroyed ***", FONT_GREEN);
currentMission.completed1[i] = OB_COMPLETED; currentMission.completed1[i] = OB_COMPLETED;
// do some area specific things // do some area specific things
if ((currentGame.area == 5) || (currentGame.area == 10) || (currentGame.area == 18) || (currentGame.area == 24)) if ((currentGame.area == 5) || (currentGame.area == 10) || (currentGame.area == 18) || (currentGame.area == 24))
{ {
if (currentMission.remainingObjectives2 == 0) if (currentMission.remainingObjectives2 == 0)

View File

@ -42,12 +42,12 @@ void initPlayer()
player.weaponType[0] = W_PLAYER_WEAPON; player.weaponType[0] = W_PLAYER_WEAPON;
if(weapon[0].ammo[0] < currentGame.minPlasmaOutput) if(weapon[W_PLAYER_WEAPON].ammo[0] < currentGame.minPlasmaOutput)
weapon[0].ammo[0] = currentGame.minPlasmaOutput; weapon[W_PLAYER_WEAPON].ammo[0] = currentGame.minPlasmaOutput;
if(weapon[0].damage < currentGame.minPlasmaDamage) if(weapon[W_PLAYER_WEAPON].damage < currentGame.minPlasmaDamage)
weapon[0].damage = currentGame.minPlasmaDamage; weapon[W_PLAYER_WEAPON].damage = currentGame.minPlasmaDamage;
if(weapon[0].reload[0] > rate2reload[currentGame.minPlasmaRate]) if(weapon[W_PLAYER_WEAPON].reload[0] > rate2reload[currentGame.minPlasmaRate])
weapon[0].reload[0] = rate2reload[currentGame.minPlasmaRate]; weapon[W_PLAYER_WEAPON].reload[0] = rate2reload[currentGame.minPlasmaRate];
player.hit = 0; player.hit = 0;
@ -130,11 +130,12 @@ void doPlayer()
if ((engine.keyState[KEY_SWITCH])) if ((engine.keyState[KEY_SWITCH]))
{ {
if(weapon[0].ammo[0] >= 3 && weapon[0].ammo[0] <= currentGame.maxPlasmaOutput) if ((weapon[W_PLAYER_WEAPON].ammo[0] >= 3) &&
(weapon[W_PLAYER_WEAPON].ammo[0] <= currentGame.maxPlasmaOutput))
{ {
weapon[0].flags ^= WF_SPREAD; weapon[W_PLAYER_WEAPON].flags ^= WF_SPREAD;
if(weapon[0].flags & WF_SPREAD) if (weapon[W_PLAYER_WEAPON].flags & WF_SPREAD)
{ {
setInfoLine("Weapon set to Spread", FONT_WHITE); setInfoLine("Weapon set to Spread", FONT_WHITE);
} }