Prototyping stats trophies.

This commit is contained in:
Steve 2016-03-09 12:31:33 +00:00
parent f867e793bd
commit 93dd00c785
7 changed files with 254 additions and 208 deletions

View File

@ -58,13 +58,17 @@
"id" : "FIRE_100000",
"title" : "Your name's on one of these!",
"description" : "Fire 100,000 shots",
"value" : "TROPHY_SILVER"
"value" : "TROPHY_SILVER",
"stat" : "STAT_SHOTS_FIRED",
"statValue" : 10000
},
{
"id" : "MISSILE_1000",
"title" : "Dodge this!",
"description" : "Launch 1,000 missiles",
"value" : "TROPHY_SILVER"
"value" : "TROPHY_SILVER",
"stat" : "STAT_MISSILES_FIRED",
"statValue" : 1000
},
{
"id" : "ATAF_DESTROYED",

View File

@ -59,6 +59,8 @@ void initChallengeHome(void)
unlockChallenges();
checkStatTrophies();
saveGame();
app.delegate.logic = &logic;
@ -150,6 +152,8 @@ static void logic(void)
break;
}
doTrophies();
doWidgets();
}
@ -246,6 +250,8 @@ static void draw(void)
drawOptions();
break;
}
doTrophyAlert();
}
static void drawChallenges(void)

View File

@ -60,6 +60,9 @@ extern void playMusic(char *filename);
extern char *timeToString(long millis, int showHours);
extern char *getChallengeDescription(Challenge *c);
extern void clearInput(void);
extern void doTrophies(void);
extern void drawTrophyAlert(void);
extern void checkStatTrophies(void);
extern App app;
extern Battle battle;

View File

@ -88,6 +88,8 @@ void initGalacticMap(void)
updatePandoranAdvance();
checkStatTrophies();
saveGame();
pulseTimer = 0;
@ -170,6 +172,8 @@ static void logic(void)
arrowPulse += 0.1;
doTrophies();
doWidgets();
}
@ -359,6 +363,8 @@ static void draw(void)
drawOptions();
break;
}
drawTrophyAlerts();
}
static void drawPulses(void)

View File

@ -60,6 +60,9 @@ extern StarSystem *getStarSystem(char *name);
extern void showOKDialog(void (*callback)(void), const char *format, ...);
extern char *getTranslatedString(char *string);
extern void clearInput(void);
extern void doTrophies(void);
extern void drawTrophyAlert(void);
extern void checkStatTrophies(void);
extern App app;
extern Colors colors;

View File

@ -159,6 +159,13 @@ static void loadTrophyData(char *filename)
t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring);
t->hidden = getJSONValue(node, "hidden", 0);
/* can't use the getJSONValue here, as it could lead to false positives */
if (cJSON_GetObjectItem(node, "stat"))
{
t->stat = lookup(cJSON_GetObjectItem(node, "stat")->valuestring));
t->statValue = cJSON_GetObjectItem(node, "statValue")->valueint;
}
tail->next = t;
tail = t;
}
@ -166,3 +173,18 @@ static void loadTrophyData(char *filename)
cJSON_Delete(root);
free(text);
}
void checkStatTrophies(void)
{
Trophy *t;
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{
if (!t->awarded && game.stats[t->stat] >= t->statValue)
{
t->awarded = 1;
t->awardDate = time(NULL);
t->notify = 1;
}
}
}

View File

@ -349,6 +349,8 @@ struct Trophy {
char description[MAX_DESCRIPTION_LENGTH];
int value;
int hidden;
int stat;
int statValue;
int awarded;
unsigned long awardDate;
int notify;