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];
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))
{
@ -1088,12 +1089,14 @@ void doAliens()
limitCharAdd(&theEnemy->reload[0], -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))
canFire = traceTarget(theEnemy);
if (((theEnemy->thinktime % 2) == 0) && (theEnemy->flags & FL_FRIEND))
if (((theEnemy->thinktime % 2) == 0) &&
(theEnemy->flags & FL_FRIEND))
canFire = traceView(theEnemy);
}
else
@ -1103,13 +1106,18 @@ void doAliens()
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);
}
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)
theEnemy->ammo[1] = 50 + rand() % 150;
@ -1119,7 +1127,8 @@ void doAliens()
{
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;
playSound(SFX_ENERGYRAY, theEnemy->x);
@ -1151,12 +1160,14 @@ void doAliens()
if (theEnemy->flags & FL_DROPMINES)
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
if ((theEnemy->flags & FL_DROPMINES) && (theEnemy == &enemy[WC_KLINE]))
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)
{
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))
addDebris((int)theEnemy->x, (int)theEnemy->y, theEnemy->maxShield);
if ((theEnemy->classDef == CD_BOSS) ||
(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)
{
@ -1207,10 +1223,9 @@ void doAliens()
}
// 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);
}
if ((currentGame.area != 18) || (theEnemy->shield < 0))
theEnemy->x += engine.ssx + engine.smx;

View File

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

View File

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

View File

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

View File

@ -159,7 +159,8 @@ void initSystem()
#endif
/* 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());
exit(1);
}
@ -184,14 +185,16 @@ void initSystem()
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());
exit(1);
}
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());
exit(1);
}
@ -201,7 +204,8 @@ void initSystem()
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
if (!renderer)
{
printf("Could not create renderer: %s\n", SDL_GetError());
exit(1);
}
@ -210,7 +214,8 @@ void initSystem()
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());
exit(1);
}
@ -228,8 +233,8 @@ void initSystem()
SDL_ShowCursor(SDL_DISABLE);
SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE);
SDL_JoystickEventState(SDL_ENABLE);
SDL_JoystickOpen(0);
SDL_JoystickEventState(SDL_ENABLE);
SDL_JoystickOpen(0);
}
/*

View File

@ -481,10 +481,12 @@ int galaxyMap()
// Remove the Supercharge, if it is there
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]);
weapon[0].ammo[0] = min(weapon[0].ammo[0], currentGame.maxPlasmaOutput);
weapon[0].damage = min(weapon[0].damage, currentGame.maxPlasmaDamage);
weapon[W_PLAYER_WEAPON].ammo[0] = min(weapon[W_PLAYER_WEAPON].ammo[0],
currentGame.maxPlasmaOutput);
weapon[W_PLAYER_WEAPON].damage = min(weapon[W_PLAYER_WEAPON].damage,
currentGame.maxPlasmaDamage);
}
clearScreen(black);

View File

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

View File

@ -331,7 +331,7 @@ void doInfo()
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))
{
SDL_FillRect(screen, &bar, green);
@ -351,7 +351,7 @@ void doInfo()
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))
{
SDL_FillRect(screen, &bar, yellow);
@ -371,7 +371,7 @@ void doInfo()
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))
{
SDL_FillRect(screen, &bar, blue);

View File

@ -552,7 +552,7 @@ bool allMissionsCompleted()
setInfoLine("*** Interception Destroyed ***", FONT_GREEN);
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 (currentMission.remainingObjectives2 == 0)

View File

@ -42,12 +42,12 @@ void initPlayer()
player.weaponType[0] = W_PLAYER_WEAPON;
if(weapon[0].ammo[0] < currentGame.minPlasmaOutput)
weapon[0].ammo[0] = currentGame.minPlasmaOutput;
if(weapon[0].damage < currentGame.minPlasmaDamage)
weapon[0].damage = currentGame.minPlasmaDamage;
if(weapon[0].reload[0] > rate2reload[currentGame.minPlasmaRate])
weapon[0].reload[0] = rate2reload[currentGame.minPlasmaRate];
if(weapon[W_PLAYER_WEAPON].ammo[0] < currentGame.minPlasmaOutput)
weapon[W_PLAYER_WEAPON].ammo[0] = currentGame.minPlasmaOutput;
if(weapon[W_PLAYER_WEAPON].damage < currentGame.minPlasmaDamage)
weapon[W_PLAYER_WEAPON].damage = currentGame.minPlasmaDamage;
if(weapon[W_PLAYER_WEAPON].reload[0] > rate2reload[currentGame.minPlasmaRate])
weapon[W_PLAYER_WEAPON].reload[0] = rate2reload[currentGame.minPlasmaRate];
player.hit = 0;
@ -130,11 +130,12 @@ void doPlayer()
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);
}