Skip to content

Commit c0e224a

Browse files
committed
run_autostory with checkpoints instead of segments, when in advanced mode
1 parent def76b9 commit c0e224a

File tree

3 files changed

+149
-35
lines changed

3 files changed

+149
-35
lines changed

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,29 +1086,29 @@ std::string AutoStory::end_checkpoint_description(){
10861086
return " End: " + ALL_AUTO_STORY_CHECKPOINT_LIST()[checkpoint_index]->end_text();
10871087
}
10881088

1089-
// size_t AutoStory::get_start_checkpoint_index(){
1090-
// size_t start = 0;
1091-
1092-
// if (STORY_SECTION == StorySection::TUTORIAL){
1093-
// start = START_CHECKPOINT_TUTORIAL.index();
1094-
// }else if (STORY_SECTION == StorySection::MAIN_STORY){
1095-
// start = (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1) + START_CHECKPOINT_MAINSTORY.index();
1096-
// }
1089+
size_t AutoStory::get_start_checkpoint_index(){
1090+
size_t start = 0;
1091+
1092+
if (STORY_SECTION == StorySection::TUTORIAL){
1093+
start = START_CHECKPOINT_TUTORIAL.index();
1094+
}else if (STORY_SECTION == StorySection::MAIN_STORY){
1095+
start = (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1) + START_CHECKPOINT_MAINSTORY.index();
1096+
}
10971097

1098-
// return start;
1099-
// }
1098+
return start;
1099+
}
11001100

1101-
// size_t AutoStory::get_end_checkpoint_index(){
1102-
// size_t end = 0;
1101+
size_t AutoStory::get_end_checkpoint_index(){
1102+
size_t end = 0;
11031103

1104-
// if (STORY_SECTION == StorySection::TUTORIAL){
1105-
// end = END_CHECKPOINT_TUTORIAL.index();
1106-
// }else if (STORY_SECTION == StorySection::MAIN_STORY){
1107-
// end = (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1) + END_CHECKPOINT_MAINSTORY.index();
1108-
// }
1104+
if (STORY_SECTION == StorySection::TUTORIAL){
1105+
end = END_CHECKPOINT_TUTORIAL.index();
1106+
}else if (STORY_SECTION == StorySection::MAIN_STORY){
1107+
end = (INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1) + END_CHECKPOINT_MAINSTORY.index();
1108+
}
11091109

1110-
// return end;
1111-
// }
1110+
return end;
1111+
}
11121112

11131113

11141114
void AutoStory::run_autostory(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
@@ -1119,12 +1119,19 @@ void AutoStory::run_autostory(SingleSwitchProgramEnvironment& env, ProController
11191119
};
11201120

11211121
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
1122-
if (get_start_segment_index() > get_end_segment_index()){
1123-
throw UserSetupError(env.logger(), "The start segment cannot be later than the end segment.");
1124-
}
1125-
1126-
for (size_t segment_index = get_start_segment_index(); segment_index <= get_end_segment_index(); segment_index++){
1127-
ALL_AUTO_STORY_SEGMENT_LIST()[segment_index]->run_segment(env, context, options, stats);
1122+
context.wait_for_all_requests();
1123+
1124+
if (ENABLE_ADVANCED_MODE){
1125+
for (size_t checkpoint_index = get_start_checkpoint_index(); checkpoint_index <= get_end_checkpoint_index(); checkpoint_index++){
1126+
env.console.log("Start Checkpoint " + ALL_AUTO_STORY_CHECKPOINT_LIST()[checkpoint_index]->name(), COLOR_ORANGE);
1127+
ALL_AUTO_STORY_CHECKPOINT_LIST()[checkpoint_index]->run_checkpoint(env, context, options, stats);
1128+
}
1129+
1130+
}else{
1131+
for (size_t segment_index = get_start_segment_index(); segment_index <= get_end_segment_index(); segment_index++){
1132+
ALL_AUTO_STORY_SEGMENT_LIST()[segment_index]->run_segment(env, context, options, stats);
1133+
}
1134+
11281135
}
11291136
}
11301137

@@ -1213,14 +1220,33 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex
12131220
return;
12141221
}
12151222

1223+
if (ENABLE_ADVANCED_MODE){
1224+
if (get_start_checkpoint_index() > get_end_checkpoint_index()){
1225+
throw UserSetupError(env.logger(), "The start checkpoint cannot be later than the end segment.");
1226+
}
1227+
1228+
}else{
1229+
if (get_start_segment_index() > get_end_segment_index()){
1230+
throw UserSetupError(env.logger(), "The start segment cannot be later than the end segment.");
1231+
}
1232+
}
1233+
12161234
// Connect controller
12171235
pbf_press_button(context, BUTTON_L, 20, 20);
12181236

1219-
env.console.log("Start Segment " + ALL_AUTO_STORY_SEGMENT_LIST()[get_start_segment_index()]->name(), COLOR_ORANGE);
1237+
if (ENABLE_ADVANCED_MODE){
1238+
env.console.log("Start Checkpoint " + ALL_AUTO_STORY_CHECKPOINT_LIST()[get_start_checkpoint_index()]->name(), COLOR_ORANGE);
1239+
}else{
1240+
env.console.log("Start Segment " + ALL_AUTO_STORY_SEGMENT_LIST()[get_start_segment_index()]->name(), COLOR_ORANGE);
1241+
}
12201242

12211243
// Set settings. to ensure autosave is off.
12221244
if (CHANGE_SETTINGS){
1223-
change_settings_prior_to_autostory(env, context, get_start_segment_index(), LANGUAGE);
1245+
if (ENABLE_ADVANCED_MODE){
1246+
change_settings_prior_to_autostory_checkpoint_mode(env, context, get_start_checkpoint_index(), LANGUAGE);
1247+
}else{
1248+
change_settings_prior_to_autostory_segment_mode(env, context, get_start_segment_index(), LANGUAGE);
1249+
}
12241250
}
12251251

12261252
run_autostory(env, context);

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,7 @@ void swap_starter_moves(SingleSwitchProgramEnvironment& env, ProControllerContex
486486

487487
}
488488

489-
490-
void change_settings_prior_to_autostory(
491-
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
492-
size_t current_segment_num,
493-
Language language
494-
){
495-
489+
void change_settings_prior_to_autostory_segment_mode(SingleSwitchProgramEnvironment& env, ProControllerContext& context, size_t current_segment_num, Language language){
496490
// get index of `Options` in the Main Menu, which depends on where you are in Autostory
497491
int8_t options_index;
498492
std::string assumption_text = "";
@@ -555,6 +549,97 @@ void change_settings_prior_to_autostory(
555549
env.console.log("change_settings_prior_to_autostory: " + assumption_text + " The index of \"Options\" in the Menu is " + std::to_string(options_index) + ".");
556550

557551
bool has_minimap = current_segment_num >= 2; // the minimap only shows up in segment 2 and beyond
552+
change_settings_prior_to_autostory(env, context, options_index, has_minimap, language);
553+
}
554+
555+
void change_settings_prior_to_autostory_checkpoint_mode(SingleSwitchProgramEnvironment& env, ProControllerContext& context, size_t current_checkpoint_num, Language language){
556+
// get index of `Options` in the Main Menu, which depends on where you are in Autostory
557+
int8_t options_index;
558+
std::string assumption_text = "";
559+
switch(current_checkpoint_num){
560+
case 0:
561+
return; // can't change settings in the intro cutscene
562+
case 1:
563+
case 2:
564+
// after Intro cutscene done, in room
565+
// Menu
566+
// - Options
567+
// - Save
568+
options_index = 0;
569+
assumption_text = "We assume 'Bag' is not yet unlocked.";
570+
break;
571+
case 3:
572+
case 4:
573+
// Menu
574+
// - Bag --> unlocked after picked up bag/hat in room. Segment 01, checkpoint 02
575+
// - Options
576+
// - Save
577+
options_index = 1;
578+
assumption_text = "We assume 'Boxes' is not yet unlocked.";
579+
break;
580+
case 5:
581+
case 6:
582+
case 7:
583+
case 8:
584+
case 9:
585+
case 10:
586+
case 11:
587+
// Menu
588+
// - Bag
589+
// - Boxes --> unlocked after battling Nemona and receiving Pokedex app. Segment 02, checkpoint 04
590+
// - Options
591+
// - Save
592+
options_index = 2;
593+
assumption_text = "We assume 'Poke Portal' is not yet unlocked.";
594+
break;
595+
case 12:
596+
case 13:
597+
case 14:
598+
case 15:
599+
case 16:
600+
case 17:
601+
case 18:
602+
case 19:
603+
case 20:
604+
// Menu
605+
// - Bag
606+
// - Boxes
607+
// - Poke Portal --> unlocked after arriving at Los Platos and talking to Nemona. Segment 06, checkpoint 11
608+
// - Options
609+
// - Save
610+
options_index = 3;
611+
assumption_text = "We assume 'Picnic' is not yet unlocked.";
612+
break;
613+
default:
614+
if(current_checkpoint_num <= 20){
615+
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "change_settings_prior_to_autostory_checkpoint_mode: current_checkpoint_num should be greater than 20.");
616+
}
617+
618+
// Menu
619+
// - Bag
620+
// - Boxes
621+
// - Picnic --> unlocked after finishing tutorial. Segment 09, checkpoint 20
622+
// - Poke Portal
623+
// - Options
624+
// - Save
625+
options_index = 4;
626+
assumption_text = "We assume that the tutorial is done, and all menu items are unlocked.";
627+
break;
628+
}
629+
630+
env.console.log("change_settings_prior_to_autostory: " + assumption_text + " The index of \"Options\" in the Menu is " + std::to_string(options_index) + ".");
631+
632+
bool has_minimap = current_checkpoint_num >= 3; // the minimap only shows up in checkpoint 3 and beyond
633+
change_settings_prior_to_autostory(env, context, options_index, has_minimap, language);
634+
}
635+
636+
637+
void change_settings_prior_to_autostory(
638+
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
639+
int options_index,
640+
bool has_minimap,
641+
Language language
642+
){
558643

559644
enter_menu_from_overworld(env.program_info(), env.console, context, options_index, MenuSide::RIGHT, has_minimap);
560645
change_settings(env, context, language);

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,15 @@ void get_off_ride(const ProgramInfo& info, VideoStream& stream, ProControllerCon
275275

276276
void get_on_or_off_ride(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, bool get_on);
277277

278+
void change_settings_prior_to_autostory_segment_mode(SingleSwitchProgramEnvironment& env, ProControllerContext& context, size_t current_segment_num, Language language);
279+
void change_settings_prior_to_autostory_checkpoint_mode(SingleSwitchProgramEnvironment& env, ProControllerContext& context, size_t current_checkpoint_num, Language language);
278280

279281
// change the settings prior to Autostory
280282
// Assumes that `current_segment` represents where we currently are in the story.
281283
void change_settings_prior_to_autostory(
282284
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
283-
size_t current_segment_num,
285+
int options_index,
286+
bool has_minimap,
284287
Language language
285288
);
286289

0 commit comments

Comments
 (0)