Unlock spellcards on story mode encounter

But only when not using continues!
This commit is contained in:
Andrei "Akari" Alexeyev 2017-02-11 14:22:14 +02:00 committed by Martin Herkt
parent b900263611
commit 347f143a54
5 changed files with 34 additions and 13 deletions

View file

@ -178,12 +178,24 @@ void free_attack(Attack *a) {
void start_attack(Boss *b, Attack *a) {
#if DEBUG
printf("BOSS start_attack(): %s\n", a->name);
StageInfo *i = stage_get_by_spellcard(a->info, global.diff);
if(i) {
printf("This attack has a spell stage: %u\n", i->id);
}
#endif
if(global.replaymode == REPLAY_RECORD && global.stage->type == STAGE_STORY && !global.plr.continues) {
StageInfo *i = stage_get_by_spellcard(a->info, global.diff);
if(i) {
StageProgress *p = stage_get_progress_from_info(i, global.diff, true);
if(p && !p->unlocked) {
printf("Spellcard unlocked! %s: %s\n", i->title, i->subtitle);
p->unlocked = true;
}
}
#if DEBUG
else if(a->type == AT_Spellcard) {
warnx("FIXME: spellcard '%s' is not available in spell practice mode!", a->name);
}
#endif
}
a->starttime = global.frames + ATTACK_START_DELAY;
a->rule(b, EVENT_BIRTH);
if(a->type == AT_Spellcard || a->type == AT_SurvivalSpell)

View file

@ -38,6 +38,8 @@
#include "random.h"
#include "events.h"
#include "taisei_err.h"
#define FILE_PREFIX PREFIX "/share/taisei/"
#define CONFIG_FILE "config"

View file

@ -122,7 +122,7 @@ static void progress_read(SDL_RWops *file) {
case PCMD_UNLOCK_STAGES:
warnx("progress_read(): %i %i", cmd, cmdsize);
while(cur < cmdsize) {
StageProgress *p = stage_get_progress(SDL_ReadLE16(vfile), D_Any);
StageProgress *p = stage_get_progress(SDL_ReadLE16(vfile), D_Any, true);
if(p) {
p->unlocked = true;
}
@ -149,7 +149,7 @@ static void progress_write(SDL_RWops *file) {
StageInfo *stg;
for(stg = stages; stg->loop; ++stg) {
StageProgress *p = stage_get_progress_from_info(stg, D_Any);
StageProgress *p = stage_get_progress_from_info(stg, D_Any, false);
if(p && p->unlocked) {
++num_unlocked;
}
@ -170,7 +170,7 @@ static void progress_write(SDL_RWops *file) {
SDL_WriteLE16(vfile, num_unlocked * 2);
for(stg = stages; stg->loop; ++stg) {
StageProgress *p = stage_get_progress_from_info(stg, D_Any);
StageProgress *p = stage_get_progress_from_info(stg, D_Any, false);
if(p && p->unlocked) {
SDL_WriteLE16(vfile, stg->id);
}
@ -194,7 +194,7 @@ static void progress_unlock_all(void) {
StageInfo *stg;
for(stg = stages; stg->loop; ++stg) {
StageProgress *p = stage_get_progress_from_info(stg, D_Any);
StageProgress *p = stage_get_progress_from_info(stg, D_Any, false);
if(p) {
p->unlocked = true;
}

View file

@ -255,7 +255,7 @@ StageInfo* stage_get_by_spellcard(AttackInfo *spell, Difficulty diff) {
return NULL;
}
StageProgress* stage_get_progress_from_info(StageInfo *stage, Difficulty diff) {
StageProgress* stage_get_progress_from_info(StageInfo *stage, Difficulty diff, bool allocate) {
// D_Any stages will have a separate StageProgress for every selectable difficulty.
// Stages with a fixed difficulty setting (spellpractice, extra stage...) obviously get just one and the diff parameter is ignored.
@ -274,6 +274,10 @@ StageProgress* stage_get_progress_from_info(StageInfo *stage, Difficulty diff) {
}
if(!stage->progress) {
if(!allocate) {
return NULL;
}
size_t allocsize = sizeof(StageProgress) * (fixed_diff ? 1 : NUM_SELECTABLE_DIFFICULTIES);
stage->progress = malloc(allocsize);
memset(stage->progress, 0, allocsize);
@ -285,8 +289,8 @@ StageProgress* stage_get_progress_from_info(StageInfo *stage, Difficulty diff) {
return stage->progress + (fixed_diff ? 0 : diff - D_Easy);
}
StageProgress* stage_get_progress(uint16_t id, Difficulty diff) {
return stage_get_progress_from_info(stage_get(id), diff);
StageProgress* stage_get_progress(uint16_t id, Difficulty diff, bool allocate) {
return stage_get_progress_from_info(stage_get(id), diff, allocate);
}
void stage_start(void) {

View file

@ -76,10 +76,13 @@ typedef struct StageInfo {
} StageInfo;
extern StageInfo stages[];
StageInfo* stage_get(uint16_t);
StageInfo* stage_get_by_spellcard(AttackInfo *spell, Difficulty diff);
StageProgress* stage_get_progress(uint16_t id, Difficulty diff);
StageProgress* stage_get_progress_from_info(StageInfo *stage, Difficulty diff);
StageProgress* stage_get_progress(uint16_t id, Difficulty diff, bool allocate);
StageProgress* stage_get_progress_from_info(StageInfo *stage, Difficulty diff, bool allocate);
void stage_init_array(void);
void stage_loop(StageRule start, StageRule end, StageRule draw, StageRule event, ShaderRule *shaderrules, int endtime);