Skip to content

Commit ac64cc5

Browse files
jw098Mysticial
authored andcommitted
Autostory: Team Star Poison (#718)
* checkpoint 58 and 59. * update realign_player_from_landmark() and move_cursor_towards_flypoint_and_go_there() to re-try with different push_scale on different attempts. * checkpoint 60 * minor UI updates
1 parent d938c87 commit ac64cc5

File tree

8 files changed

+515
-278
lines changed

8 files changed

+515
-278
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
9595
segment_list.emplace_back(std::make_unique<AutoStory_Segment_22>());
9696
segment_list.emplace_back(std::make_unique<AutoStory_Segment_23>());
9797
segment_list.emplace_back(std::make_unique<AutoStory_Segment_24>());
98-
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_25>());
98+
segment_list.emplace_back(std::make_unique<AutoStory_Segment_25>());
9999
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_26>());
100100
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_27>());
101101
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_28>());
@@ -210,25 +210,25 @@ AutoStory::AutoStory()
210210
StorySection::TUTORIAL
211211
)
212212
, STARTPOINT_TUTORIAL(
213-
"<b>Start Point:</b><br>Program will start with this segment.",
213+
"<b>Start Point:</b>", //<br>Program will start with this segment.
214214
TUTORIAL_SEGMENTS_SELECT_DATABASE(),
215215
LockMode::LOCK_WHILE_RUNNING,
216216
"0"
217217
)
218218
, ENDPOINT_TUTORIAL(
219-
"<b>End Point:</b><br>Program will stop after completing this segment.",
219+
"<b>End Point:</b>", //<br>Program will stop after completing this segment.
220220
TUTORIAL_SEGMENTS_SELECT_DATABASE(),
221221
LockMode::UNLOCK_WHILE_RUNNING,
222222
"9"
223223
)
224224
, STARTPOINT_MAINSTORY(
225-
"<b>Start Point:</b><br>Program will start with this segment.",
225+
"<b>Start Point:</b>", //<br>Program will start with this segment.
226226
MAINSTORY_SEGMENTS_SELECT_DATABASE(),
227227
LockMode::UNLOCK_WHILE_RUNNING,
228228
"10"
229229
)
230230
, ENDPOINT_MAINSTORY(
231-
"<b>End Point:</b><br>Program will stop after completing this segment.",
231+
"<b>End Point:</b>", //<br>Program will stop after completing this segment.
232232
MAINSTORY_SEGMENTS_SELECT_DATABASE(),
233233
LockMode::UNLOCK_WHILE_RUNNING,
234234
"10"
@@ -237,7 +237,7 @@ AutoStory::AutoStory()
237237
"NOTE: Make sure you have selected the correct Start Point. "
238238
"Make sure your player character is in the exact correct start position for that Start Point, "
239239
"especially if your start point is NOT at the beginning of the Tutorial/Main Story. "
240-
"Read the Start Point's description to help with finding the correct start position."
240+
"Read the Start Point's description to help with finding the correct start position. "
241241
"For Start Points that are at Pokecenters, ensure that you fly there so that your character is in the exactly correct start position."
242242
}
243243
, MAINSTORY_NOTE{
@@ -846,6 +846,7 @@ void AutoStory::test_code(SingleSwitchProgramEnvironment& env, ProControllerCont
846846
if (ENABLE_TEST_CHECKPOINTS){
847847
// test individual checkpoints
848848
test_checkpoints(env, env.console, context, START_CHECKPOINT, END_CHECKPOINT, LOOP_CHECKPOINT, START_LOOP, END_LOOP);
849+
GO_HOME_WHEN_DONE.run_end_of_program(context);
849850
return;
850851
}
851852

@@ -882,7 +883,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex
882883

883884

884885
// test code
885-
if (ENABLE_TEST_CHECKPOINTS || ENABLE_TEST_REALIGN || ENABLE_MISC_TEST || TEST_PBF_LEFT_JOYSTICK || TEST_PBF_LEFT_JOYSTICK2 || TEST_CHANGE_DIRECTION || TEST_CURRENT_DIRECTION){
886+
if (TEST_FLYPOINT_LOCATIONS || TEST_MOVE_CURSOR_OFFSET_FROM_FLYPOINT || ENABLE_TEST_CHECKPOINTS || ENABLE_TEST_REALIGN || ENABLE_MISC_TEST || TEST_PBF_LEFT_JOYSTICK || TEST_PBF_LEFT_JOYSTICK2 || TEST_CHANGE_DIRECTION || TEST_CURRENT_DIRECTION){
886887
test_code(env, context);
887888
return;
888889
}

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

Lines changed: 36 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,12 @@ void realign_player_from_landmark(
851851
stream.log("Realigning player direction, using a landmark...");
852852
WallClock start = current_time();
853853

854+
const int MAX_TRY_COUNT = 17;
855+
int try_count = 0;
856+
857+
// failures to fly to pokecenter are often when the Switch lags. from my testing, a 1.4-1.5 adjustment factor seems to work
858+
const std::array<double, MAX_TRY_COUNT> adjustment_table = {1, 1.4, 1, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 0.9, 0.8, 1.4}; // {1, 1.4, 1.5};
859+
854860
while (true){
855861
if (current_time() - start > std::chrono::minutes(5)){
856862
OperationFailedException::fire(
@@ -888,7 +894,8 @@ void realign_player_from_landmark(
888894
pbf_move_left_joystick(context, move_x1, move_y1, move_duration1, 1 * TICKS_PER_SECOND);
889895

890896
// move cursor to pokecenter
891-
if (!detect_closest_flypoint_and_move_map_cursor_there(info, stream, context, FlyPoint::POKECENTER, 0.29)){
897+
double push_scale = 0.29 * adjustment_table[try_count];
898+
if (!detect_closest_flypoint_and_move_map_cursor_there(info, stream, context, FlyPoint::POKECENTER, push_scale)){
892899
OperationFailedException::fire(
893900
ErrorReport::SEND_ERROR_REPORT,
894901
"realign_player_from_landmark(): No visible pokecenter found on map.",
@@ -932,8 +939,16 @@ void realign_player_from_landmark(
932939
}catch (UnexpectedBattleException&){
933940
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
934941
}catch (OperationFailedException&){
935-
// reset to overworld if failed to center on the pokecenter, and re-try
936-
leave_phone_to_overworld(info, stream, context);
942+
try_count++;
943+
if (try_count >= MAX_TRY_COUNT){
944+
OperationFailedException::fire(
945+
ErrorReport::SEND_ERROR_REPORT,
946+
"fly_to_closest_pokecenter_on_map(): At min warpable map level, pokecenter was detected, but failed to fly there.",
947+
stream
948+
);
949+
}
950+
stream.log("Failed to find the fly menu item. Restart the closest Pokecenter travel process.");
951+
press_Bs_to_back_to_overworld(info, stream, context);
937952
}
938953
}
939954

@@ -966,6 +981,12 @@ void move_cursor_towards_flypoint_and_go_there(
966981
){
967982
WallClock start = current_time();
968983

984+
const int MAX_TRY_COUNT = 17;
985+
int try_count = 0;
986+
987+
// failures to fly to pokecenter are often when the Switch lags. from my testing, a 1.4-1.5 adjustment factor seems to work
988+
const std::array<double, MAX_TRY_COUNT> adjustment_table = {1, 1.4, 1, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 0.9, 0.8, 1.4}; // {1, 1.4, 1.5};
989+
969990
while (true){
970991
if (current_time() - start > std::chrono::minutes(5)){
971992
OperationFailedException::fire(
@@ -1002,7 +1023,8 @@ void move_cursor_towards_flypoint_and_go_there(
10021023
uint16_t move_duration1 = move_cursor_near_flypoint.move_duration;
10031024
pbf_move_left_joystick(context, move_x1, move_y1, move_duration1, 1 * TICKS_PER_SECOND);
10041025

1005-
if (!fly_to_visible_closest_flypoint_cur_zoom_level(info, stream, context, fly_point)){
1026+
double push_scale = 0.29 * adjustment_table[try_count];
1027+
if (!fly_to_visible_closest_flypoint_cur_zoom_level(info, stream, context, fly_point, push_scale)){
10061028
OperationFailedException::fire(
10071029
ErrorReport::SEND_ERROR_REPORT,
10081030
"move_cursor_towards_flypoint_and_go_there(): No visible pokecenter found on map.",
@@ -1015,8 +1037,16 @@ void move_cursor_towards_flypoint_and_go_there(
10151037
}catch (UnexpectedBattleException&){
10161038
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
10171039
}catch (OperationFailedException&){
1018-
// reset to overworld if failed to center on the pokecenter, and re-try
1019-
leave_phone_to_overworld(info, stream, context);
1040+
try_count++;
1041+
if (try_count >= MAX_TRY_COUNT){
1042+
OperationFailedException::fire(
1043+
ErrorReport::SEND_ERROR_REPORT,
1044+
"move_cursor_towards_flypoint_and_go_there(): At given zoom level, pokecenter was detected, but failed to fly there.",
1045+
stream
1046+
);
1047+
}
1048+
stream.log("Failed to find the fly menu item. Restart the closest Pokecenter travel process.");
1049+
press_Bs_to_back_to_overworld(info, stream, context);
10201050
}
10211051
}
10221052

@@ -1122,197 +1152,6 @@ void checkpoint_reattempt_loop_tutorial(
11221152
}
11231153
}
11241154

1125-
void move_from_porto_marinada_to_medali(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
1126-
context.wait_for_all_requests();
1127-
1128-
// marker 1
1129-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 110, 75);
1130-
1131-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1132-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1133-
overworld_navigation(env.program_info(), env.console, context,
1134-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1135-
128, 0, 40, 10, false);
1136-
},
1137-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1138-
pbf_move_left_joystick(context, 255, 255, 40, 50);
1139-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1140-
}
1141-
);
1142-
1143-
// marker 2. x=0.3875, y=0.60463
1144-
place_marker_offset_from_flypoint(env.program_info(), env.console, context,
1145-
{ZoomChange::ZOOM_OUT, 0, 0, 0},
1146-
FlyPoint::POKECENTER,
1147-
{0.3875, 0.60463}
1148-
);
1149-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1150-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1151-
overworld_navigation(env.program_info(), env.console, context,
1152-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1153-
128, 0, 40, 10, false);
1154-
},
1155-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1156-
pbf_move_left_joystick(context, 0, 255, 40, 50);
1157-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1158-
}
1159-
);
1160-
1161-
1162-
// marker 3. : x=0.316146, y=0.623148
1163-
place_marker_offset_from_flypoint(env.program_info(), env.console, context,
1164-
{ZoomChange::ZOOM_OUT, 0, 0, 0},
1165-
FlyPoint::POKECENTER,
1166-
{0.316146, 0.623148}
1167-
);
1168-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1169-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1170-
overworld_navigation(env.program_info(), env.console, context,
1171-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1172-
128, 0, 40, 10, false);
1173-
},
1174-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1175-
pbf_move_left_joystick(context, 0, 255, 40, 50);
1176-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1177-
}
1178-
);
1179-
1180-
get_on_ride(env.program_info(), env.console, context);
1181-
1182-
// marker 4. cross bridge 1 x=0.310417, y=0.712963.
1183-
place_marker_offset_from_flypoint(env.program_info(), env.console, context,
1184-
{ZoomChange::ZOOM_OUT, 0, 0, 0},
1185-
FlyPoint::POKECENTER,
1186-
{0.310417, 0.712963}
1187-
);
1188-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1189-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1190-
overworld_navigation(env.program_info(), env.console, context,
1191-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1192-
128, 0, 20, 10, false);
1193-
},
1194-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1195-
pbf_move_left_joystick(context, 128, 0, 500ms, 0ms);
1196-
pbf_controller_state(context, BUTTON_B, DPAD_NONE, 128, 0, 128, 128, 1000ms);
1197-
pbf_move_left_joystick(context, 128, 0, 500ms, 0ms);
1198-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1199-
}
1200-
);
1201-
1202-
get_off_ride(env.program_info(), env.console, context);
1203-
1204-
1205-
// marker 5. : x=0.582292, y=0.692593
1206-
place_marker_offset_from_flypoint(env.program_info(), env.console, context,
1207-
{ZoomChange::ZOOM_OUT, 0, 0, 0},
1208-
FlyPoint::POKECENTER,
1209-
{0.582292, 0.692593}
1210-
);
1211-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1212-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1213-
overworld_navigation(env.program_info(), env.console, context,
1214-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1215-
128, 0, 60, 10, false);
1216-
},
1217-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1218-
pbf_move_left_joystick(context, 0, 255, 40, 50);
1219-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1220-
}
1221-
);
1222-
1223-
get_on_ride(env.program_info(), env.console, context);
1224-
1225-
// marker 6. cross bridge 2 : x=0.555208, y=0.627778
1226-
place_marker_offset_from_flypoint(env.program_info(), env.console, context,
1227-
{ZoomChange::ZOOM_OUT, 0, 0, 0},
1228-
FlyPoint::POKECENTER,
1229-
{0.555208, 0.627778}
1230-
);
1231-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1232-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1233-
overworld_navigation(env.program_info(), env.console, context,
1234-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1235-
128, 0, 20, 10, false);
1236-
},
1237-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1238-
pbf_move_left_joystick(context, 128, 0, 500ms, 0ms);
1239-
pbf_controller_state(context, BUTTON_B, DPAD_NONE, 128, 0, 128, 128, 1000ms);
1240-
pbf_move_left_joystick(context, 128, 0, 500ms, 0ms);
1241-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1242-
}
1243-
);
1244-
1245-
get_off_ride(env.program_info(), env.console, context);
1246-
1247-
// marker 7. : x=0.678646, y=0.669444
1248-
place_marker_offset_from_flypoint(env.program_info(), env.console, context,
1249-
{ZoomChange::KEEP_ZOOM, 255, 255, 30},
1250-
FlyPoint::POKECENTER,
1251-
{0.678646, 0.669444}
1252-
);
1253-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1254-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1255-
overworld_navigation(env.program_info(), env.console, context,
1256-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1257-
128, 0, 40, 10, false);
1258-
},
1259-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1260-
pbf_move_left_joystick(context, 0, 255, 40, 50);
1261-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1262-
}
1263-
);
1264-
1265-
// marker 8. : x=0.533333, y=0.640741
1266-
place_marker_offset_from_flypoint(env.program_info(), env.console, context,
1267-
{ZoomChange::KEEP_ZOOM, 255, 255, 50},
1268-
FlyPoint::POKECENTER,
1269-
{0.533333, 0.640741}
1270-
);
1271-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1272-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1273-
overworld_navigation(env.program_info(), env.console, context,
1274-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1275-
128, 0, 40, 10, false);
1276-
},
1277-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1278-
pbf_move_left_joystick(context, 0, 255, 40, 50);
1279-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1280-
}
1281-
);
1282-
1283-
1284-
// marker 9. set marker to pokecenter
1285-
realign_player_from_landmark(
1286-
env.program_info(), env.console, context,
1287-
{ZoomChange::ZOOM_IN, 128, 255, 50},
1288-
{ZoomChange::KEEP_ZOOM, 0, 0, 0}
1289-
);
1290-
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
1291-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1292-
overworld_navigation(env.program_info(), env.console, context,
1293-
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
1294-
128, 0, 30, 10, false);
1295-
},
1296-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1297-
pbf_move_left_joystick(context, 0, 255, 40, 50);
1298-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
1299-
}
1300-
);
1301-
1302-
// marker 10. set marker past pokecenter
1303-
handle_unexpected_battles(env.program_info(), env.console, context,
1304-
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
1305-
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 180, 255, 50);
1306-
});
1307-
overworld_navigation(env.program_info(), env.console, context,
1308-
NavigationStopCondition::STOP_TIME, NavigationMovementMode::DIRECTIONAL_ONLY,
1309-
128, 15, 12, 12, false); // can't wrap in handle_when_stationary_in_overworld(), since we expect to be stationary when walking into the pokecenter
1310-
1311-
1312-
fly_to_overlapping_flypoint(env.program_info(), env.console, context);
1313-
1314-
}
1315-
13161155

13171156
void move_from_medali_to_glaseado_mountain(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
13181157
context.wait_for_all_requests();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ void checkpoint_reattempt_loop_tutorial(
296296
std::function<void(size_t attempt_number)>&& action
297297
);
298298

299-
// moves player from Porto Marinada Pokecenter to Medali West Pokecenter
300-
void move_from_porto_marinada_to_medali(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
301299

302300
// moves player from Medali West Pokecenter to Glaseado Mountain Pokecenter
303301
void move_from_medali_to_glaseado_mountain(SingleSwitchProgramEnvironment& env, ProControllerContext& context);

0 commit comments

Comments
 (0)