From 5982fcc0d854ca8db4c5932e9993fdcd91ad56e7 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Fri, 24 Apr 2015 16:27:07 -0400 Subject: [PATCH] Some reorganization. --- Makefile | 2 +- src/alien.cpp | 8 ++-- src/bullet.cpp | 7 +++ src/bullet.h | 1 + src/cargo.cpp | 10 ++--- src/cargo.h | 4 +- src/collectable.cpp | 54 +---------------------- src/collectable.h | 5 +-- src/game.cpp | 105 ++++++++++++++++++++++++++++++-------------- 9 files changed, 97 insertions(+), 99 deletions(-) diff --git a/Makefile b/Makefile index 9194b30..a4bce90 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CXXFLAGS += `pkg-config --cflags 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 -VERSION = 1.3.1 +VERSION = 1.3.2-dev PROG = starfighter DOCS = docs/* DATA = data gfx sound music diff --git a/src/alien.cpp b/src/alien.cpp index 4395892..55aa664 100644 --- a/src/alien.cpp +++ b/src/alien.cpp @@ -736,9 +736,9 @@ void aliens_init() } if (currentGame.area == MISN_CERADSE) - addCargo(&aliens[index], P_CARGO); + cargo_add(&aliens[index], P_CARGO); else if (currentGame.area == MISN_NEROD) - addCargo(&aliens[index], P_PHOEBE); + cargo_add(&aliens[index], P_PHOEBE); if (index == ALIEN_KLINE) { @@ -1005,7 +1005,7 @@ bool alien_add() } if (aliens[index].classDef == CD_CARGOSHIP) - addCargo(&aliens[index], P_CARGO); + cargo_add(&aliens[index], P_CARGO); if (aliens[index].classDef == CD_MOBILE_RAY) aliens[index].shield = 25; @@ -1605,7 +1605,7 @@ void alien_destroy(object *alien, object *attacker) value = (10 + (rand() % alien->collectValue)); if (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; } } diff --git a/src/bullet.cpp b/src/bullet.cpp index 4cfcf9b..6e4cf15 100644 --- a/src/bullet.cpp +++ b/src/bullet.cpp @@ -177,3 +177,10 @@ object *bullet_getTarget(object *bullet) return &aliens[i]; } + +void bullet_checkMineCollisions(object *bullet) +{ + + + +} diff --git a/src/bullet.h b/src/bullet.h index 9489383..1931a5b 100644 --- a/src/bullet.h +++ b/src/bullet.h @@ -22,5 +22,6 @@ along with this program. If not, see . void bullet_add(object *theWeapon, object *attacker, int y, int dy); object *bullet_getTarget(object *bullet); +void bullet_checkMineCollisions(object *bullet); #endif diff --git a/src/cargo.cpp b/src/cargo.cpp index 4756721..b754ae6 100644 --- a/src/cargo.cpp +++ b/src/cargo.cpp @@ -21,7 +21,7 @@ along with this program. If not, see . object cargo[MAX_CARGO]; -void initCargo() +void cargo_init() { for (int i = 0 ; i < MAX_CARGO ; i++) { @@ -33,7 +33,7 @@ void initCargo() /* * 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++) { @@ -44,9 +44,9 @@ static int getCargo() 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) return NULL; @@ -69,7 +69,7 @@ void cargo_becomeCollectable(int i) { 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 { diff --git a/src/cargo.h b/src/cargo.h index 07550ae..5d1c3bf 100644 --- a/src/cargo.h +++ b/src/cargo.h @@ -22,8 +22,8 @@ along with this program. If not, see . extern object cargo[MAX_CARGO]; -extern void initCargo(); -extern object *addCargo(object *owner, int cargoType); +void cargo_init(); +object *cargo_add(object *owner, int cargoType); void cargo_becomeCollectable(int i); #endif diff --git a/src/collectable.cpp b/src/collectable.cpp index df24b8e..1e67c76 100644 --- a/src/collectable.cpp +++ b/src/collectable.cpp @@ -22,7 +22,7 @@ along with this program. If not, see . /* 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; @@ -206,7 +206,7 @@ void addCollectable(float x, float y, int type, int value, int life) engine.collectableTail = collectable; } -void explodeMine(collectables *collectable) +void collectable_explode(collectables *collectable) { if ((collectable->x >= 0) && (collectable->x <= screen->w) && (collectable->y >= 0) && (collectable->y <= screen->h)) @@ -219,53 +219,3 @@ void explodeMine(collectables *collectable) if (player_checkShockDamage(collectable->x, collectable->y)) 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; - } - } -} diff --git a/src/collectable.h b/src/collectable.h index 2166ae6..343ae1a 100644 --- a/src/collectable.h +++ b/src/collectable.h @@ -20,8 +20,7 @@ along with this program. If not, see . #ifndef COLLECTABLE_H #define COLLECTABLE_H -extern void addCollectable(float x, float y, int type, int value, int life); -void explodeMine(collectables *collectable); -extern void checkMineBulletCollisions(object *bullet); +void collectable_add(float x, float y, int type, int value, int life); +void collectable_explode(collectables *collectable); #endif diff --git a/src/game.cpp b/src/game.cpp index b9d67cc..9a3222f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -407,7 +407,7 @@ static void game_doCollectables() else { if (collectable->type == P_MINE) - explodeMine(collectable); + collectable_explode(collectable); prevCollectable->next = collectable->next; delete collectable; collectable = prevCollectable; @@ -429,14 +429,16 @@ static void game_doBullets() { object *bullet = engine.bulletHead; object *prevBullet = engine.bulletHead; - engine.bulletTail = engine.bulletHead; - object *alien, *theCargo; + collectables *collectable = engine.collectableHead; + collectables *prevCollectable = engine.collectableHead; bool okayToHit = false; int old_shield; float homingMissileSpeed = 0; + engine.bulletTail = engine.bulletHead; + while (bullet->next != NULL) { bullet = bullet->next; @@ -510,44 +512,42 @@ static void game_doBullets() for (int i = 0 ; i < ALIEN_MAX ; i++) { - alien = &aliens[i]; - - if ((alien->shield < 1) || (!alien->active)) + if ((aliens[i].shield < 1) || (!aliens[i].active)) continue; okayToHit = false; - if ((bullet->flags & WF_FRIEND) && (alien->flags & FL_WEAPCO)) + if ((bullet->flags & WF_FRIEND) && (aliens[i].flags & FL_WEAPCO)) okayToHit = true; - if ((bullet->flags & WF_WEAPCO) && (alien->flags & FL_FRIEND)) + if ((bullet->flags & WF_WEAPCO) && (aliens[i].flags & FL_FRIEND)) okayToHit = true; if ((bullet->id == WT_ROCKET) || (bullet->id == WT_LASER) || (bullet->id == WT_CHARGER)) okayToHit = true; - if (bullet->owner == alien->owner) + if (bullet->owner == aliens[i].owner) okayToHit = false; 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) { currentGame.hits++; - if ((alien->classDef == CD_PHOEBE) || - (alien->classDef == CD_URSULA)) - getMissFireMessage(alien); + if ((aliens[i].classDef == CD_PHOEBE) || + (aliens[i].classDef == CD_URSULA)) + getMissFireMessage(&aliens[i]); } - if (!(alien->flags & FL_IMMORTAL)) + if (!(aliens[i].flags & FL_IMMORTAL)) { - alien_hurt(alien, bullet->owner, bullet->damage, - (bullet->flags & WF_DISABLE)); + alien_hurt(&aliens[i], bullet->owner, + bullet->damage, (bullet->flags & WF_DISABLE)); - alien->hit = 5; + aliens[i].hit = 5; } if (bullet->id == WT_CHARGER) @@ -636,21 +636,20 @@ static void game_doBullets() { for (int j = 0 ; j < 20 ; j++) { - theCargo = &cargo[j]; - if (theCargo->active) + if (cargo[j].active) { - if (collision(bullet, theCargo)) + if (collision(bullet, &cargo[j])) { bullet->active = false; addExplosion(bullet->x, bullet->y, E_SMALL_EXPLOSION); - audio_playSound(SFX_HIT, theCargo->x); - if (theCargo->collectType != P_PHOEBE) + audio_playSound(SFX_HIT, cargo[j].x); + if (cargo[j].collectType != P_PHOEBE) { - theCargo->active = false; - audio_playSound(SFX_EXPLOSION, theCargo->x); + cargo[j].active = false; + audio_playSound(SFX_EXPLOSION, cargo[j].x); for (int i = 0 ; i < 10 ; i++) - addExplosion(theCargo->x + RANDRANGE(-15, 15), - theCargo->y + RANDRANGE(-15, 15), + addExplosion(cargo[j].x + RANDRANGE(-15, 15), + cargo[j].y + RANDRANGE(-15, 15), E_BIG_EXPLOSION); updateMissionRequirements(M_PROTECT_PICKUP, P_CARGO, 1); @@ -661,7 +660,49 @@ static void game_doBullets() } // 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--; @@ -938,14 +979,14 @@ static void game_doAliens() if (aliens[i].flags & FL_DROPMINES) { 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); // Kline drops mines a lot more often if ((&aliens[i] == &aliens[ALIEN_KLINE])) { 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); } } @@ -1397,7 +1438,7 @@ int mainGameLoop() setMission(currentGame.area); missionBriefScreen(); - initCargo(); + cargo_init(); initPlayer(); aliens_init(); @@ -1693,7 +1734,7 @@ int mainGameLoop() // but I'm not entirely sure what the original intention was. // For now, I've set the range to [800, 1500], which // 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, 180 + rand() % 60); }