Some reorganization.

This commit is contained in:
onpon4 2015-04-24 16:27:07 -04:00
parent f4bd2f2abe
commit 5982fcc0d8
9 changed files with 97 additions and 99 deletions

View File

@ -3,7 +3,7 @@ CXXFLAGS += `pkg-config --cflags sdl2 SDL2_image SDL2_mixer`
LIBS = `pkg-config --libs sdl2 SDL2_image SDL2_mixer` LIBS = `pkg-config --libs sdl2 SDL2_image SDL2_mixer`
OBJS = alien.o audio.o bullet.o cargo.o collectable.o comms.o debris.o events.o explosions.o game.o globals.o graphics.o init.o intermission.o loadSave.o messages.o misc.o missions.o player.o resources.o script.o ship.o shop.o Starfighter.o title.o weapons.o OBJS = alien.o audio.o bullet.o cargo.o collectable.o comms.o debris.o events.o explosions.o game.o globals.o graphics.o init.o intermission.o loadSave.o messages.o misc.o missions.o player.o resources.o script.o ship.o shop.o Starfighter.o title.o weapons.o
VERSION = 1.3.1 VERSION = 1.3.2-dev
PROG = starfighter PROG = starfighter
DOCS = docs/* DOCS = docs/*
DATA = data gfx sound music DATA = data gfx sound music

View File

@ -736,9 +736,9 @@ void aliens_init()
} }
if (currentGame.area == MISN_CERADSE) if (currentGame.area == MISN_CERADSE)
addCargo(&aliens[index], P_CARGO); cargo_add(&aliens[index], P_CARGO);
else if (currentGame.area == MISN_NEROD) else if (currentGame.area == MISN_NEROD)
addCargo(&aliens[index], P_PHOEBE); cargo_add(&aliens[index], P_PHOEBE);
if (index == ALIEN_KLINE) if (index == ALIEN_KLINE)
{ {
@ -1005,7 +1005,7 @@ bool alien_add()
} }
if (aliens[index].classDef == CD_CARGOSHIP) if (aliens[index].classDef == CD_CARGOSHIP)
addCargo(&aliens[index], P_CARGO); cargo_add(&aliens[index], P_CARGO);
if (aliens[index].classDef == CD_MOBILE_RAY) if (aliens[index].classDef == CD_MOBILE_RAY)
aliens[index].shield = 25; aliens[index].shield = 25;
@ -1605,7 +1605,7 @@ void alien_destroy(object *alien, object *attacker)
value = (10 + (rand() % alien->collectValue)); value = (10 + (rand() % alien->collectValue));
if (value > alien->collectValue) if (value > alien->collectValue)
value = alien->collectValue; value = alien->collectValue;
addCollectable(alien->x, alien->y, alien->collectType, value, 600); collectable_add(alien->x, alien->y, alien->collectType, value, 600);
alien->collectValue -= value; alien->collectValue -= value;
} }
} }

View File

@ -177,3 +177,10 @@ object *bullet_getTarget(object *bullet)
return &aliens[i]; return &aliens[i];
} }
void bullet_checkMineCollisions(object *bullet)
{
}

View File

@ -22,5 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void bullet_add(object *theWeapon, object *attacker, int y, int dy); void bullet_add(object *theWeapon, object *attacker, int y, int dy);
object *bullet_getTarget(object *bullet); object *bullet_getTarget(object *bullet);
void bullet_checkMineCollisions(object *bullet);
#endif #endif

View File

@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
object cargo[MAX_CARGO]; object cargo[MAX_CARGO];
void initCargo() void cargo_init()
{ {
for (int i = 0 ; i < MAX_CARGO ; i++) for (int i = 0 ; i < MAX_CARGO ; i++)
{ {
@ -33,7 +33,7 @@ void initCargo()
/* /*
* I think you all know what this does by now! ;) * I think you all know what this does by now! ;)
*/ */
static int getCargo() static int cargo_get()
{ {
for (int i = 0 ; i < MAX_CARGO ; i++) for (int i = 0 ; i < MAX_CARGO ; i++)
{ {
@ -44,9 +44,9 @@ static int getCargo()
return -1; return -1;
} }
object *addCargo(object *owner, int cargoType) object *cargo_add(object *owner, int cargoType)
{ {
int index = getCargo(); int index = cargo_get();
if (index == -1) if (index == -1)
return NULL; return NULL;
@ -69,7 +69,7 @@ void cargo_becomeCollectable(int i)
{ {
if (cargo[i].collectType != P_PHOEBE) if (cargo[i].collectType != P_PHOEBE)
{ {
addCollectable(cargo[i].x, cargo[i].y, cargo[i].collectType, 1, 600); collectable_add(cargo[i].x, cargo[i].y, cargo[i].collectType, 1, 600);
} }
else else
{ {

View File

@ -22,8 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern object cargo[MAX_CARGO]; extern object cargo[MAX_CARGO];
extern void initCargo(); void cargo_init();
extern object *addCargo(object *owner, int cargoType); object *cargo_add(object *owner, int cargoType);
void cargo_becomeCollectable(int i); void cargo_becomeCollectable(int i);
#endif #endif

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* /*
Create a new collectable item based on supplied arguments. Create a new collectable item based on supplied arguments.
*/ */
void addCollectable(float x, float y, int type, int value, int life) void collectable_add(float x, float y, int type, int value, int life)
{ {
int r; int r;
@ -206,7 +206,7 @@ void addCollectable(float x, float y, int type, int value, int life)
engine.collectableTail = collectable; engine.collectableTail = collectable;
} }
void explodeMine(collectables *collectable) void collectable_explode(collectables *collectable)
{ {
if ((collectable->x >= 0) && (collectable->x <= screen->w) && if ((collectable->x >= 0) && (collectable->x <= screen->w) &&
(collectable->y >= 0) && (collectable->y <= screen->h)) (collectable->y >= 0) && (collectable->y <= screen->h))
@ -219,53 +219,3 @@ void explodeMine(collectables *collectable)
if (player_checkShockDamage(collectable->x, collectable->y)) if (player_checkShockDamage(collectable->x, collectable->y))
setInfoLine("Warning: Mine damage to shield!!", FONT_RED); setInfoLine("Warning: Mine damage to shield!!", FONT_RED);
} }
void checkMineBulletCollisions(object *bullet)
{
collectables *collectable = engine.collectableHead;
collectables *prevCollectable = engine.collectableHead;
engine.collectableTail = engine.collectableHead;
while (collectable->next != NULL)
{
collectable = collectable->next;
if (collectable->type == P_MINE)
{
if (collision(collectable, bullet))
{
collectable->active = false;
if (bullet->id != WT_CHARGER)
{
bullet->active = false;
}
else
{
bullet->shield--;
if (bullet->shield < 0)
bullet->active = false;
}
if (bullet->owner == &player)
{
currentGame.minesKilled++;
currentGame.hits++;
}
}
}
if (collectable->active)
{
prevCollectable = collectable;
engine.collectableTail = collectable;
}
else
{
explodeMine(collectable);
prevCollectable->next = collectable->next;
delete collectable;
collectable = prevCollectable;
}
}
}

View File

@ -20,8 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef COLLECTABLE_H #ifndef COLLECTABLE_H
#define COLLECTABLE_H #define COLLECTABLE_H
extern void addCollectable(float x, float y, int type, int value, int life); void collectable_add(float x, float y, int type, int value, int life);
void explodeMine(collectables *collectable); void collectable_explode(collectables *collectable);
extern void checkMineBulletCollisions(object *bullet);
#endif #endif

View File

@ -407,7 +407,7 @@ static void game_doCollectables()
else else
{ {
if (collectable->type == P_MINE) if (collectable->type == P_MINE)
explodeMine(collectable); collectable_explode(collectable);
prevCollectable->next = collectable->next; prevCollectable->next = collectable->next;
delete collectable; delete collectable;
collectable = prevCollectable; collectable = prevCollectable;
@ -429,14 +429,16 @@ static void game_doBullets()
{ {
object *bullet = engine.bulletHead; object *bullet = engine.bulletHead;
object *prevBullet = engine.bulletHead; object *prevBullet = engine.bulletHead;
engine.bulletTail = engine.bulletHead;
object *alien, *theCargo; collectables *collectable = engine.collectableHead;
collectables *prevCollectable = engine.collectableHead;
bool okayToHit = false; bool okayToHit = false;
int old_shield; int old_shield;
float homingMissileSpeed = 0; float homingMissileSpeed = 0;
engine.bulletTail = engine.bulletHead;
while (bullet->next != NULL) while (bullet->next != NULL)
{ {
bullet = bullet->next; bullet = bullet->next;
@ -510,44 +512,42 @@ static void game_doBullets()
for (int i = 0 ; i < ALIEN_MAX ; i++) for (int i = 0 ; i < ALIEN_MAX ; i++)
{ {
alien = &aliens[i]; if ((aliens[i].shield < 1) || (!aliens[i].active))
if ((alien->shield < 1) || (!alien->active))
continue; continue;
okayToHit = false; okayToHit = false;
if ((bullet->flags & WF_FRIEND) && (alien->flags & FL_WEAPCO)) if ((bullet->flags & WF_FRIEND) && (aliens[i].flags & FL_WEAPCO))
okayToHit = true; okayToHit = true;
if ((bullet->flags & WF_WEAPCO) && (alien->flags & FL_FRIEND)) if ((bullet->flags & WF_WEAPCO) && (aliens[i].flags & FL_FRIEND))
okayToHit = true; okayToHit = true;
if ((bullet->id == WT_ROCKET) || (bullet->id == WT_LASER) || if ((bullet->id == WT_ROCKET) || (bullet->id == WT_LASER) ||
(bullet->id == WT_CHARGER)) (bullet->id == WT_CHARGER))
okayToHit = true; okayToHit = true;
if (bullet->owner == alien->owner) if (bullet->owner == aliens[i].owner)
okayToHit = false; okayToHit = false;
if (okayToHit) if (okayToHit)
{ {
if ((bullet->active) && (collision(bullet, alien))) if ((bullet->active) && (collision(bullet, &aliens[i])))
{ {
old_shield = alien->shield; old_shield = aliens[i].shield;
if (bullet->owner == &player) if (bullet->owner == &player)
{ {
currentGame.hits++; currentGame.hits++;
if ((alien->classDef == CD_PHOEBE) || if ((aliens[i].classDef == CD_PHOEBE) ||
(alien->classDef == CD_URSULA)) (aliens[i].classDef == CD_URSULA))
getMissFireMessage(alien); getMissFireMessage(&aliens[i]);
} }
if (!(alien->flags & FL_IMMORTAL)) if (!(aliens[i].flags & FL_IMMORTAL))
{ {
alien_hurt(alien, bullet->owner, bullet->damage, alien_hurt(&aliens[i], bullet->owner,
(bullet->flags & WF_DISABLE)); bullet->damage, (bullet->flags & WF_DISABLE));
alien->hit = 5; aliens[i].hit = 5;
} }
if (bullet->id == WT_CHARGER) if (bullet->id == WT_CHARGER)
@ -636,21 +636,20 @@ static void game_doBullets()
{ {
for (int j = 0 ; j < 20 ; j++) for (int j = 0 ; j < 20 ; j++)
{ {
theCargo = &cargo[j]; if (cargo[j].active)
if (theCargo->active)
{ {
if (collision(bullet, theCargo)) if (collision(bullet, &cargo[j]))
{ {
bullet->active = false; bullet->active = false;
addExplosion(bullet->x, bullet->y, E_SMALL_EXPLOSION); addExplosion(bullet->x, bullet->y, E_SMALL_EXPLOSION);
audio_playSound(SFX_HIT, theCargo->x); audio_playSound(SFX_HIT, cargo[j].x);
if (theCargo->collectType != P_PHOEBE) if (cargo[j].collectType != P_PHOEBE)
{ {
theCargo->active = false; cargo[j].active = false;
audio_playSound(SFX_EXPLOSION, theCargo->x); audio_playSound(SFX_EXPLOSION, cargo[j].x);
for (int i = 0 ; i < 10 ; i++) for (int i = 0 ; i < 10 ; i++)
addExplosion(theCargo->x + RANDRANGE(-15, 15), addExplosion(cargo[j].x + RANDRANGE(-15, 15),
theCargo->y + RANDRANGE(-15, 15), cargo[j].y + RANDRANGE(-15, 15),
E_BIG_EXPLOSION); E_BIG_EXPLOSION);
updateMissionRequirements(M_PROTECT_PICKUP, updateMissionRequirements(M_PROTECT_PICKUP,
P_CARGO, 1); P_CARGO, 1);
@ -661,7 +660,49 @@ static void game_doBullets()
} }
// check to see if a bullet (on any side) hits a mine // check to see if a bullet (on any side) hits a mine
checkMineBulletCollisions(bullet); engine.collectableTail = engine.collectableHead;
while (collectable->next != NULL)
{
collectable = collectable->next;
if (collectable->type == P_MINE)
{
if (collision(collectable, bullet))
{
collectable->active = false;
if (bullet->id != WT_CHARGER)
{
bullet->active = false;
}
else
{
bullet->shield--;
if (bullet->shield < 0)
bullet->active = false;
}
if (bullet->owner == &player)
{
currentGame.minesKilled++;
currentGame.hits++;
}
}
}
if (collectable->active)
{
prevCollectable = collectable;
engine.collectableTail = collectable;
}
else
{
collectable_explode(collectable);
prevCollectable->next = collectable->next;
delete collectable;
collectable = prevCollectable;
}
}
bullet->shield--; bullet->shield--;
@ -938,14 +979,14 @@ static void game_doAliens()
if (aliens[i].flags & FL_DROPMINES) if (aliens[i].flags & FL_DROPMINES)
{ {
if ((rand() % 150) == 0) if ((rand() % 150) == 0)
addCollectable(aliens[i].x, aliens[i].y, P_MINE, 25, collectable_add(aliens[i].x, aliens[i].y, P_MINE, 25,
600 + rand() % 2400); 600 + rand() % 2400);
// Kline drops mines a lot more often // Kline drops mines a lot more often
if ((&aliens[i] == &aliens[ALIEN_KLINE])) if ((&aliens[i] == &aliens[ALIEN_KLINE]))
{ {
if ((rand() % 10) == 0) if ((rand() % 10) == 0)
addCollectable(aliens[i].x, aliens[i].y, P_MINE, 25, collectable_add(aliens[i].x, aliens[i].y, P_MINE, 25,
600 + rand() % 2400); 600 + rand() % 2400);
} }
} }
@ -1397,7 +1438,7 @@ int mainGameLoop()
setMission(currentGame.area); setMission(currentGame.area);
missionBriefScreen(); missionBriefScreen();
initCargo(); cargo_init();
initPlayer(); initPlayer();
aliens_init(); aliens_init();
@ -1693,7 +1734,7 @@ int mainGameLoop()
// but I'm not entirely sure what the original intention was. // but I'm not entirely sure what the original intention was.
// For now, I've set the range to [800, 1500], which // For now, I've set the range to [800, 1500], which
// approximately replicates the original's results. // approximately replicates the original's results.
addCollectable(RANDRANGE(800, 1500), collectable_add(RANDRANGE(800, 1500),
RANDRANGE(-screen->h / 3, (4 * screen->h) / 3), P_MINE, 25, RANDRANGE(-screen->h / 3, (4 * screen->h) / 3), P_MINE, 25,
180 + rand() % 60); 180 + rand() % 60);
} }