Allow player to switch fighters upon death, during an epic battle.
This commit is contained in:
parent
596069cebf
commit
4f47cd0bc6
|
@ -86,7 +86,14 @@ static void logic(void)
|
||||||
|
|
||||||
if (show == SHOW_BATTLE)
|
if (show == SHOW_BATTLE)
|
||||||
{
|
{
|
||||||
doBattle();
|
if (!battle.epic || (battle.epic && player != NULL))
|
||||||
|
{
|
||||||
|
doBattle();
|
||||||
|
}
|
||||||
|
else if (battle.epic && player == NULL)
|
||||||
|
{
|
||||||
|
doPlayerSelect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ extern void drawOptions(void);
|
||||||
extern void playSound(int id);
|
extern void playSound(int id);
|
||||||
extern void checkTrigger(char *name, int type);
|
extern void checkTrigger(char *name, int type);
|
||||||
extern void resetWaypoints(void);
|
extern void resetWaypoints(void);
|
||||||
|
extern void doPlayerSelect(void);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
|
|
|
@ -23,8 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
static void selectTarget(void);
|
static void selectTarget(void);
|
||||||
static void switchGuns(void);
|
static void switchGuns(void);
|
||||||
static void selectMissionTarget(void);
|
static void selectMissionTarget(void);
|
||||||
|
static void selectNewPlayer(int dir);
|
||||||
|
static void initPlayerSelect(void);
|
||||||
|
|
||||||
|
static int selectedPlayerIndex;
|
||||||
static int availableGuns[BT_MAX];
|
static int availableGuns[BT_MAX];
|
||||||
|
static Entity *availablePlayerUnits[MAX_SELECTABLE_PLAYERS];
|
||||||
|
|
||||||
void initPlayer(void)
|
void initPlayer(void)
|
||||||
{
|
{
|
||||||
|
@ -126,12 +130,76 @@ void doPlayer(void)
|
||||||
|
|
||||||
if (player->health <= 0 && battle.status == MS_IN_PROGRESS)
|
if (player->health <= 0 && battle.status == MS_IN_PROGRESS)
|
||||||
{
|
{
|
||||||
failIncompleteObjectives();
|
if (!battle.epic || (battle.epic && battle.numAllies <= 1))
|
||||||
|
{
|
||||||
battle.status = MS_FAILED;
|
failIncompleteObjectives();
|
||||||
battle.missionFinishedTimer = FPS;
|
|
||||||
|
battle.status = MS_FAILED;
|
||||||
|
battle.missionFinishedTimer = FPS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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)
|
static void switchGuns(void)
|
||||||
|
|
|
@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
#include "../structs.h"
|
#include "../structs.h"
|
||||||
|
|
||||||
|
#define MAX_SELECTABLE_PLAYERS 8
|
||||||
|
|
||||||
extern void fireGuns(Entity *owner);
|
extern void fireGuns(Entity *owner);
|
||||||
extern void fireMissile(Entity *owner);
|
extern void fireMissile(Entity *owner);
|
||||||
extern void applyFighterThrust(void);
|
extern void applyFighterThrust(void);
|
||||||
|
@ -30,6 +32,7 @@ extern void applyFighterBrakes(void);
|
||||||
extern int getDistance(int x1, int y1, int x2, int y2);
|
extern int getDistance(int x1, int y1, int x2, int y2);
|
||||||
extern void failIncompleteObjectives(void);
|
extern void failIncompleteObjectives(void);
|
||||||
extern void addHudMessage(SDL_Color c, char *format, ...);
|
extern void addHudMessage(SDL_Color c, char *format, ...);
|
||||||
|
extern int mod(int n, int x);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Battle battle;
|
extern Battle battle;
|
||||||
|
|
|
@ -50,6 +50,11 @@ void loadMission(char *filename)
|
||||||
battle.planet.x = rand() % SCREEN_WIDTH - rand() % SCREEN_WIDTH;
|
battle.planet.x = rand() % SCREEN_WIDTH - rand() % SCREEN_WIDTH;
|
||||||
battle.planet.y = rand() % SCREEN_HEIGHT - rand() % SCREEN_HEIGHT;
|
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"));
|
loadObjectives(cJSON_GetObjectItem(root, "objectives"));
|
||||||
|
|
||||||
loadTriggers(cJSON_GetObjectItem(root, "triggers"));
|
loadTriggers(cJSON_GetObjectItem(root, "triggers"));
|
||||||
|
|
|
@ -223,6 +223,7 @@ typedef struct {
|
||||||
int numAllies;
|
int numAllies;
|
||||||
int numEnemies;
|
int numEnemies;
|
||||||
int status;
|
int status;
|
||||||
|
int epic;
|
||||||
int missionFinishedTimer;
|
int missionFinishedTimer;
|
||||||
int numObjectivesComplete, numObjectivesTotal;
|
int numObjectivesComplete, numObjectivesTotal;
|
||||||
Entity *missionTarget;
|
Entity *missionTarget;
|
||||||
|
|
Loading…
Reference in New Issue