Limit number of fighters that can appear in battle at once, during an epic battle. Add remaining fighters as room on field becomes available.
This commit is contained in:
parent
443723f6b7
commit
3783a0833e
|
@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
static void drawEntity(Entity *e);
|
||||
static void doEntity(void);
|
||||
static void activateEpicFighters(int n, int side);
|
||||
|
||||
Entity *spawnEntity(void)
|
||||
{
|
||||
|
@ -39,11 +40,12 @@ Entity *spawnEntity(void)
|
|||
void doEntities(void)
|
||||
{
|
||||
int numAllies, numEnemies;
|
||||
int numActiveAllies, numActiveEnemies;
|
||||
Entity *e, *prev;
|
||||
|
||||
prev = &battle.entityHead;
|
||||
|
||||
numAllies = numEnemies = 0;
|
||||
numAllies = numEnemies = numActiveAllies = numActiveEnemies = 0;
|
||||
|
||||
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||
{
|
||||
|
@ -76,11 +78,11 @@ void doEntities(void)
|
|||
|
||||
if (self->side == SIDE_ALLIES)
|
||||
{
|
||||
numAllies++;
|
||||
numActiveAllies++;
|
||||
}
|
||||
else
|
||||
{
|
||||
numEnemies++;
|
||||
numActiveEnemies++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -115,11 +117,36 @@ void doEntities(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (e->type == ET_FIGHTER && (battle.epic || e->active))
|
||||
{
|
||||
if (self->side == SIDE_ALLIES)
|
||||
{
|
||||
numAllies++;
|
||||
}
|
||||
else
|
||||
{
|
||||
numEnemies++;
|
||||
}
|
||||
}
|
||||
|
||||
prev = e;
|
||||
}
|
||||
|
||||
battle.numAllies = numAllies;
|
||||
battle.numEnemies = numEnemies;
|
||||
|
||||
if (battle.epic && battle.stats[STAT_TIME] % FPS == 0)
|
||||
{
|
||||
if (numAllies > battle.epicFighterLimit)
|
||||
{
|
||||
activateEpicFighters(battle.epicFighterLimit - numActiveAllies, SIDE_ALLIES);
|
||||
}
|
||||
|
||||
if (numEnemies > battle.epicFighterLimit)
|
||||
{
|
||||
activateEpicFighters(battle.epicFighterLimit - numActiveEnemies, SIDE_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void doEntity(void)
|
||||
|
@ -169,3 +196,24 @@ void activateEntities(char *name)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void activateEpicFighters(int n, int side)
|
||||
{
|
||||
Entity *e;
|
||||
|
||||
if (n > 0)
|
||||
{
|
||||
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||
{
|
||||
if (!e->active && e->type == ET_FIGHTER && ((side == SIDE_ALLIES && e->side == SIDE_ALLIES) || (side != SIDE_ALLIES && e->side != SIDE_ALLIES)))
|
||||
{
|
||||
e->active = 1;
|
||||
|
||||
if (--n <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,8 @@ enum
|
|||
SIDE_PIRATE,
|
||||
SIDE_CSN,
|
||||
SIDE_INF,
|
||||
SIDE_UNF
|
||||
SIDE_UNF,
|
||||
SIDE_MAX
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
|
@ -29,6 +29,7 @@ static void loadEntities(cJSON *node);
|
|||
static void loadEntityGroups(cJSON *node);
|
||||
static unsigned long hashcode(const char *str);
|
||||
static char **toFighterTypeArray(char *types, int *numTypes);
|
||||
static void loadEpicData(cJSON *node);
|
||||
|
||||
void loadMission(char *filename)
|
||||
{
|
||||
|
@ -50,11 +51,6 @@ 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"));
|
||||
|
@ -71,6 +67,11 @@ void loadMission(char *filename)
|
|||
|
||||
STRNCPY(music, cJSON_GetObjectItem(root, "music")->valuestring, MAX_NAME_LENGTH);
|
||||
|
||||
if (cJSON_GetObjectItem(root, "epic"))
|
||||
{
|
||||
loadEpicData(cJSON_GetObjectItem(root, "epic"));
|
||||
}
|
||||
|
||||
cJSON_Delete(root);
|
||||
free(text);
|
||||
|
||||
|
@ -408,6 +409,25 @@ static char **toFighterTypeArray(char *types, int *numTypes)
|
|||
return typeArray;
|
||||
}
|
||||
|
||||
static void loadEpicData(cJSON *node)
|
||||
{
|
||||
Entity *e;
|
||||
int numFighters[SIDE_MAX];
|
||||
memset(numFighters, 0, sizeof(int) * SIDE_MAX);
|
||||
|
||||
battle.epic = 1;
|
||||
|
||||
battle.epicFighterLimit = cJSON_GetObjectItem(node, "fighterLimit")->valueint;
|
||||
|
||||
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
|
||||
{
|
||||
if (e->active && e->type == ET_FIGHTER && numFighters[e->side]++ >= battle.epicFighterLimit)
|
||||
{
|
||||
e->active = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mission *getMission(char *filename)
|
||||
{
|
||||
StarSystem *starSystem;
|
||||
|
|
|
@ -223,6 +223,7 @@ typedef struct {
|
|||
int numEnemies;
|
||||
int status;
|
||||
int epic;
|
||||
int epicFighterLimit;
|
||||
int playerSelect;
|
||||
int missionFinishedTimer;
|
||||
int numObjectivesComplete, numObjectivesTotal;
|
||||
|
|
Loading…
Reference in New Issue