Show and apply challenge restrictions.
This commit is contained in:
parent
f9880354db
commit
2c71b16e17
|
@ -15,7 +15,6 @@
|
|||
"challenge" : {
|
||||
"timeLimit" : 120,
|
||||
"killLimit" : 5,
|
||||
"noMissiles" : 1,
|
||||
"challenges" : [
|
||||
{
|
||||
"type" : "CHALLENGE_TIME",
|
||||
|
|
|
@ -33,6 +33,7 @@ static void handleKeyboard(void);
|
|||
static void faceMouse(void);
|
||||
static void handleMouse(void);
|
||||
static void preFireMissile(void);
|
||||
static void applyRestrictions(void);
|
||||
|
||||
static int selectedPlayerIndex;
|
||||
static int availableGuns[BT_MAX];
|
||||
|
@ -96,6 +97,11 @@ void doPlayer(void)
|
|||
{
|
||||
self = player;
|
||||
|
||||
if (game.currentMission->challengeData.isChallenge)
|
||||
{
|
||||
applyRestrictions();
|
||||
}
|
||||
|
||||
if (player->alive == ALIVE_ALIVE)
|
||||
{
|
||||
handleKeyboard();
|
||||
|
@ -139,6 +145,29 @@ void doPlayer(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void applyRestrictions(void)
|
||||
{
|
||||
if (game.currentMission->challengeData.noMissiles)
|
||||
{
|
||||
player->missiles = 0;
|
||||
}
|
||||
|
||||
if (game.currentMission->challengeData.noBoost)
|
||||
{
|
||||
battle.boostTimer = 0;
|
||||
}
|
||||
|
||||
if (game.currentMission->challengeData.noECM)
|
||||
{
|
||||
battle.ecmTimer = 0;
|
||||
}
|
||||
|
||||
if (game.currentMission->challengeData.noGuns)
|
||||
{
|
||||
player->reload = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void handleKeyboard(void)
|
||||
{
|
||||
if (battle.status == MS_IN_PROGRESS)
|
||||
|
@ -235,7 +264,7 @@ static void handleMouse(void)
|
|||
|
||||
if (app.mouse.button[SDL_BUTTON_RIGHT])
|
||||
{
|
||||
if (battle.boostTimer > BOOST_FINISHED_TIME)
|
||||
if (battle.boostTimer > BOOST_FINISHED_TIME || game.currentMission->challengeData.noBoost)
|
||||
{
|
||||
applyFighterThrust();
|
||||
}
|
||||
|
|
|
@ -45,10 +45,10 @@ static SDL_Texture *planetTexture;
|
|||
static PointF planet;
|
||||
static int totalChallenges;
|
||||
static int show;
|
||||
static char challenge[3][MAX_DESCRIPTION_LENGTH];
|
||||
static int passed[3];
|
||||
static Challenge *challenge[3];
|
||||
static char timeLimit[MAX_DESCRIPTION_LENGTH];
|
||||
static char restrictions[MAX_DESCRIPTION_LENGTH];
|
||||
static int hasRestrictions;
|
||||
|
||||
void initChallengeHome(void)
|
||||
{
|
||||
|
@ -109,6 +109,8 @@ static void unlockChallenges(void)
|
|||
{
|
||||
m->available = i <= completedChallenges;
|
||||
|
||||
m->available = 1;
|
||||
|
||||
completedChallenges += m->completedChallenges;
|
||||
totalChallenges += m->totalChallenges;
|
||||
|
||||
|
@ -180,28 +182,45 @@ static void updateChallengeMissionData(void)
|
|||
STRNCPY(timeLimit, timeToString(game.currentMission->challengeData.timeLimit, 0), MAX_DESCRIPTION_LENGTH);
|
||||
sprintf(restrictions, "%s", listRestrictions());
|
||||
|
||||
i = 0;
|
||||
|
||||
for (i = 0 ; i < 3 ; i++)
|
||||
{
|
||||
strcpy(challenge[i], "");
|
||||
passed[i] = 0;
|
||||
}
|
||||
memset(challenge, 0, sizeof(Challenge*) * 3);
|
||||
|
||||
i = 0;
|
||||
|
||||
for (c = game.currentMission->challengeData.challengeHead.next ; c != NULL ; c = c->next)
|
||||
{
|
||||
STRNCPY(challenge[i], getChallengeDescription(c), MAX_DESCRIPTION_LENGTH);
|
||||
passed[i] = c->passed;
|
||||
challenge[i++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
static void addRestriction(char *buffer, int restricted, char *description)
|
||||
{
|
||||
if (restricted)
|
||||
{
|
||||
if (strlen(buffer) > 0)
|
||||
{
|
||||
strcat(buffer, ". ");
|
||||
}
|
||||
|
||||
i++;
|
||||
strcat(buffer, description);
|
||||
|
||||
hasRestrictions = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static char *listRestrictions(void)
|
||||
{
|
||||
return _("None");
|
||||
static char textBuffer[MAX_DESCRIPTION_LENGTH];
|
||||
|
||||
memset(textBuffer, '\0', MAX_DESCRIPTION_LENGTH);
|
||||
|
||||
hasRestrictions = 0;
|
||||
|
||||
addRestriction(textBuffer, game.currentMission->challengeData.noMissiles, _("No Missiles"));
|
||||
addRestriction(textBuffer, game.currentMission->challengeData.noECM, _("No ECM"));
|
||||
addRestriction(textBuffer, game.currentMission->challengeData.noBoost, _("No Boost"));
|
||||
addRestriction(textBuffer, game.currentMission->challengeData.noGuns, _("No Guns"));
|
||||
|
||||
return strlen(textBuffer) > 0 ? textBuffer : "-";
|
||||
}
|
||||
|
||||
static void draw(void)
|
||||
|
@ -316,15 +335,23 @@ static void drawChallenges(void)
|
|||
|
||||
r.y -= 50;
|
||||
drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, _("Craft: %s"), game.currentMission->craft);
|
||||
drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (passed[0]) ? colors.green : colors.white, challenge[0]);
|
||||
drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (challenge[0]->passed) ? colors.green : colors.white, "1. %s", getChallengeDescription(challenge[0]));
|
||||
|
||||
r.y -= 30;
|
||||
drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, _("Time Limit: %s"), timeLimit);
|
||||
drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (passed[0]) ? colors.green : colors.white, challenge[1]);
|
||||
|
||||
if (challenge[1])
|
||||
{
|
||||
drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (challenge[1]->passed) ? colors.green : colors.white, "2. %s", getChallengeDescription(challenge[1]));
|
||||
}
|
||||
|
||||
r.y -= 30;
|
||||
drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, _("Restrictions: %s"), restrictions);
|
||||
drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (passed[0]) ? colors.green : colors.white, challenge[2]);
|
||||
drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, hasRestrictions ? colors.red : colors.white, _("Restrictions: %s"), restrictions);
|
||||
|
||||
if (challenge[2])
|
||||
{
|
||||
drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (challenge[2]->passed) ? colors.green : colors.white, "3. %s", getChallengeDescription(challenge[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,10 @@ Mission *loadMissionMeta(char *filename)
|
|||
mission->challengeData.isChallenge = 1;
|
||||
mission->challengeData.timeLimit = cJSON_GetObjectItem(node, "timeLimit")->valueint * FPS;
|
||||
mission->challengeData.killLimit = cJSON_GetObjectItem(node, "killLimit")->valueint;
|
||||
mission->challengeData.noMissiles = cJSON_GetObjectItem(node, "noMissiles") ? 1 : 0;
|
||||
mission->challengeData.noECM = cJSON_GetObjectItem(node, "noECM") ? 1 : 0;
|
||||
mission->challengeData.noBoost = cJSON_GetObjectItem(node, "noBoost") ? 1 : 0;
|
||||
mission->challengeData.noGuns = cJSON_GetObjectItem(node, "noGuns") ? 1 : 0;
|
||||
|
||||
node = cJSON_GetObjectItem(node, "challenges");
|
||||
|
||||
|
|
|
@ -246,6 +246,10 @@ typedef struct {
|
|||
int killLimit;
|
||||
int lossLimit;
|
||||
int itemLimit;
|
||||
int noMissiles;
|
||||
int noBoost;
|
||||
int noECM;
|
||||
int noGuns;
|
||||
Challenge challengeHead;
|
||||
} ChallengeData;
|
||||
|
||||
|
|
Loading…
Reference in New Issue