Allow player to switch fighters upon death, during an epic battle.

This commit is contained in:
Steve 2015-10-31 10:00:46 +00:00
parent 596069cebf
commit 4f47cd0bc6
6 changed files with 90 additions and 5 deletions

View File

@ -85,9 +85,16 @@ static void logic(void)
handleKeyboard();
if (show == SHOW_BATTLE)
{
if (!battle.epic || (battle.epic && player != NULL))
{
doBattle();
}
else if (battle.epic && player == NULL)
{
doPlayerSelect();
}
}
}
doWidgets();

View File

@ -62,6 +62,7 @@ extern void drawOptions(void);
extern void playSound(int id);
extern void checkTrigger(char *name, int type);
extern void resetWaypoints(void);
extern void doPlayerSelect(void);
extern App app;
extern Battle battle;

View File

@ -23,8 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void selectTarget(void);
static void switchGuns(void);
static void selectMissionTarget(void);
static void selectNewPlayer(int dir);
static void initPlayerSelect(void);
static int selectedPlayerIndex;
static int availableGuns[BT_MAX];
static Entity *availablePlayerUnits[MAX_SELECTABLE_PLAYERS];
void initPlayer(void)
{
@ -125,6 +129,8 @@ void doPlayer(void)
player->y = SCREEN_HEIGHT / 2;
if (player->health <= 0 && battle.status == MS_IN_PROGRESS)
{
if (!battle.epic || (battle.epic && battle.numAllies <= 1))
{
failIncompleteObjectives();
@ -133,6 +139,68 @@ void doPlayer(void)
}
}
}
else
{
initPlayerSelect();
}
}
void initPlayerSelect(void)
{
Entity *e;
memset(&availablePlayerUnits, 0, sizeof(Entity*) * MAX_SELECTABLE_PLAYERS);
selectedPlayerIndex = 0;
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
{
if (e->type == ET_FIGHTER && e->health > 0 && e->side == SIDE_ALLIES && selectedPlayerIndex < MAX_SELECTABLE_PLAYERS)
{
availablePlayerUnits[selectedPlayerIndex++] = e;
}
}
selectedPlayerIndex = 0;
memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
}
void doPlayerSelect(void)
{
if (app.keyboard[SDL_SCANCODE_LEFT])
{
selectNewPlayer(-1);
app.keyboard[SDL_SCANCODE_LEFT] = 0;
}
if (app.keyboard[SDL_SCANCODE_RIGHT])
{
selectNewPlayer(1);
app.keyboard[SDL_SCANCODE_RIGHT] = 0;
}
if (app.keyboard[SDL_SCANCODE_RETURN])
{
player = availablePlayerUnits[selectedPlayerIndex];
player->action = NULL;
player->defaultAction = NULL;
}
}
static void selectNewPlayer(int dir)
{
do
{
selectedPlayerIndex += dir;
selectedPlayerIndex = mod(selectedPlayerIndex, MAX_SELECTABLE_PLAYERS);
}
while (availablePlayerUnits[selectedPlayerIndex] == NULL);
}
static void switchGuns(void)
{

View File

@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../defs.h"
#include "../structs.h"
#define MAX_SELECTABLE_PLAYERS 8
extern void fireGuns(Entity *owner);
extern void fireMissile(Entity *owner);
extern void applyFighterThrust(void);
@ -30,6 +32,7 @@ extern void applyFighterBrakes(void);
extern int getDistance(int x1, int y1, int x2, int y2);
extern void failIncompleteObjectives(void);
extern void addHudMessage(SDL_Color c, char *format, ...);
extern int mod(int n, int x);
extern App app;
extern Battle battle;

View File

@ -50,6 +50,11 @@ void loadMission(char *filename)
battle.planet.x = rand() % SCREEN_WIDTH - rand() % SCREEN_WIDTH;
battle.planet.y = rand() % SCREEN_HEIGHT - rand() % SCREEN_HEIGHT;
if (cJSON_GetObjectItem(root, "epic"))
{
battle.epic = cJSON_GetObjectItem(root, "epic")->valueint;
}
loadObjectives(cJSON_GetObjectItem(root, "objectives"));
loadTriggers(cJSON_GetObjectItem(root, "triggers"));

View File

@ -223,6 +223,7 @@ typedef struct {
int numAllies;
int numEnemies;
int status;
int epic;
int missionFinishedTimer;
int numObjectivesComplete, numObjectivesTotal;
Entity *missionTarget;