Skip to content

Commit 7611512

Browse files
authored
Merge pull request scp-fs2open#2003 from Goober5000/abort_processing_missions_which_failed_to_parse
cancel mission load when a syntax error is found
2 parents b4cb602 + 1d744d3 commit 7611512

12 files changed

Lines changed: 53 additions & 50 deletions

File tree

code/mission/missionload.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ bool mission_is_ignored(const char *filename)
9797
// Mission_load takes no parameters.
9898
// It sets the following global variables
9999
// Game_current_mission_filename
100-
101-
// returns -1 if failed, 0 if successful
102-
int mission_load(const char* filename_ext)
100+
// returns true successful, false if failed
101+
bool mission_load(const char* filename_ext)
103102
{
104103
TRACE_SCOPE(tracing::LoadMissionLoad);
105104

@@ -120,7 +119,7 @@ int mission_load(const char* filename_ext)
120119

121120
if (mission_is_ignored(filename)) {
122121
mprintf(("MISSION LOAD: Tried to load an ignored mission! Aborting..."));
123-
return -1;
122+
return false;
124123
}
125124

126125
strcat_s(filename, FS_MISSION_FILE_EXT);
@@ -131,8 +130,8 @@ int mission_load(const char* filename_ext)
131130
// to choose the type of ship that he is to fly
132131
// return value of 0 indicates success, other is failure.
133132

134-
if ( parse_main(filename) )
135-
return -1;
133+
if ( !parse_main(filename) )
134+
return false;
136135

137136
if (Select_default_ship) {
138137
int ret;
@@ -143,7 +142,8 @@ int mission_load(const char* filename_ext)
143142
ml_update_recent_missions(filename_ext); // update recently played missions list (save the csg later)
144143

145144
init_hud();
146-
return 0;
145+
146+
return true;
147147
}
148148

149149
//====================================

code/mission/missionload.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern SCP_vector<SCP_string> Ignored_missions;
2727
// It sets the following global variables:
2828
// Game_current_mission_filename
2929

30-
int mission_load(const char* filename_ext);
30+
bool mission_load(const char* filename_ext);
3131

3232
bool mission_is_ignored(const char *filename);
3333

code/mission/missionparse.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ extern fix game_get_overall_frametime(); // for texture animation
374374

375375
// local prototypes
376376
void parse_player_info2(mission *pm);
377-
void post_process_mission();
377+
bool post_process_mission();
378378
int allocate_subsys_status();
379379
void parse_common_object_data(p_object *objp);
380380
void parse_asteroid_fields(mission *pm);
@@ -5598,7 +5598,7 @@ void parse_variables()
55985598
}
55995599
}
56005600

5601-
int parse_mission(mission *pm, int flags)
5601+
bool parse_mission(mission *pm, int flags)
56025602
{
56035603
int saved_warning_count = Global_warning_count;
56045604
int saved_error_count = Global_error_count;
@@ -5639,7 +5639,7 @@ int parse_mission(mission *pm, int flags)
56395639
Current_file_checksum = netmisc_calc_checksum(pm,MISSION_CHECKSUM_SIZE);
56405640

56415641
if (flags & MPF_ONLY_MISSION_INFO)
5642-
return 0;
5642+
return true;
56435643

56445644
parse_plot_info(pm);
56455645
parse_variables();
@@ -5666,7 +5666,7 @@ int parse_mission(mission *pm, int flags)
56665666
// if running on standalone server, just print to the log
56675667
if (Game_mode & GM_STANDALONE_SERVER) {
56685668
mprintf(("Warning! Could not load %d ship classes!", Num_unknown_ship_classes));
5669-
return -2;
5669+
return false;
56705670
}
56715671
// don't do this in FRED; we will display a separate popup
56725672
else if (!Fred_running) {
@@ -5708,12 +5708,14 @@ int parse_mission(mission *pm, int flags)
57085708
// now display the popup
57095709
int popup_rval = popup(PF_TITLE_BIG | PF_TITLE_RED, 2, POPUP_NO, POPUP_YES, text);
57105710
if (popup_rval == 0) {
5711-
return -2;
5711+
return false;
57125712
}
57135713
}
57145714
}
57155715

5716-
post_process_mission();
5716+
if (!post_process_mission()) {
5717+
return false;
5718+
}
57175719

57185720
if ((saved_warning_count - Global_warning_count) > 10 || (saved_error_count - Global_error_count) > 0) {
57195721
char text[512];
@@ -5724,10 +5726,10 @@ int parse_mission(mission *pm, int flags)
57245726
log_printf(LOGFILE_EVENT_LOG, "Mission %s loaded.\n", pm->name);
57255727

57265728
// success
5727-
return 0;
5729+
return true;
57285730
}
57295731

5730-
void post_process_mission()
5732+
bool post_process_mission()
57315733
{
57325734
int i;
57335735
int indices[MAX_SHIPS], objnum;
@@ -5840,21 +5842,18 @@ void post_process_mission()
58405842

58415843
// entering this if statement will result in program termination!!!!!
58425844
// print out an error based on the return value from check_sexp_syntax()
5845+
// G5K: now entering this statement simply aborts the mission load
58435846
if ( result ) {
58445847
SCP_string sexp_str;
58455848
SCP_string error_msg;
58465849

58475850
convert_sexp_to_string(sexp_str, i, SEXP_ERROR_CHECK_MODE);
58485851
truncate_message_lines(sexp_str, 30);
58495852
sprintf(error_msg, "%s.\n\nIn sexpression: %s\n(Error appears to be: %s)", sexp_error_message(result), sexp_str.c_str(), Sexp_nodes[bad_node].text);
5853+
Warning(LOCATION, "%s", error_msg.c_str());
58505854

5851-
if (!Fred_running) {
5852-
nprintf(("Error", "%s", error_msg.c_str()));
5853-
Error(LOCATION, "%s", error_msg.c_str());
5854-
} else {
5855-
nprintf(("Warning", "%s", error_msg.c_str()));
5856-
Warning(LOCATION, "%s", error_msg.c_str());
5857-
}
5855+
// syntax errors are unrecoverable, so abort
5856+
return false;
58585857
}
58595858
}
58605859
}
@@ -5958,6 +5957,9 @@ void post_process_mission()
59585957
mission_hotkey_reset_saved();
59595958
}
59605959
Last_file_checksum = Current_file_checksum;
5960+
5961+
// success
5962+
return true;
59615963
}
59625964

59635965
int get_mission_info(const char *filename, mission *mission_p, bool basic)
@@ -6026,9 +6028,10 @@ void parse_init(bool basic)
60266028
// mai parse routine for parsing a mission. The default parameter flags tells us which information
60276029
// to get when parsing the mission. 0 means get everything (default). Other flags just gets us basic
60286030
// info such as game type, number of players etc.
6029-
int parse_main(const char *mission_name, int flags)
6031+
bool parse_main(const char *mission_name, int flags)
60306032
{
6031-
int rval, i;
6033+
int i;
6034+
bool rval;
60326035

60336036
// reset parse error stuff
60346037
Num_unknown_ship_classes = 0;
@@ -6057,7 +6060,7 @@ int parse_main(const char *mission_name, int flags)
60576060
Current_file_length = -1;
60586061
Current_file_checksum = 0;
60596062

6060-
rval = -1;
6063+
rval = false;
60616064
break;
60626065
}
60636066

@@ -6083,7 +6086,7 @@ int parse_main(const char *mission_name, int flags)
60836086
catch (const parse::ParseException& e)
60846087
{
60856088
mprintf(("MISSIONS: Unable to parse '%s'! Error message = %s.\n", mission_name, e.what()));
6086-
rval = 1;
6089+
rval = false;
60876090
break;
60886091
}
60896092
} while (0);

code/mission/missionparse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ extern p_object *Arriving_support_ship;
479479
extern char Neb2_texture_name[MAX_FILENAME_LEN];
480480

481481

482-
int parse_main(const char *mission_name, int flags = 0);
482+
bool parse_main(const char *mission_name, int flags = 0);
483483
p_object *mission_parse_get_arrival_ship(ushort net_signature);
484484
p_object *mission_parse_get_arrival_ship(const char *name);
485485
p_object *mission_parse_get_parse_object(ushort net_signature);

code/scripting/api/libs/mission.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ ADE_FUNC(loadMission, l_Mission, "Mission name", "Loads a mission", "boolean", "
995995
get_mission_info(s, &The_mission, false);
996996
game_level_init();
997997

998-
if(mission_load(s) == -1)
998+
if(!mission_load(s))
999999
return ADE_RETURN_FALSE;
10001000

10011001
game_post_level_init();

fred2/freddoc.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ void CFREDDoc::AssertValid() const {
100100
}
101101
#endif //_DEBUG
102102

103-
int CFREDDoc::autoload() {
103+
bool CFREDDoc::autoload() {
104104
char name[256], backup_name[256];
105-
int i, r;
105+
int i;
106+
bool r;
106107
FILE *fp;
107108

108109
cf_create_default_path_string(name, sizeof(name) - 1, CF_TYPE_MISSIONS);
@@ -217,7 +218,7 @@ void CFREDDoc::editor_init_mission() {
217218
recreate_dialogs();
218219
}
219220

220-
int CFREDDoc::load_mission(char *pathname, int flags) {
221+
bool CFREDDoc::load_mission(char *pathname, int flags) {
221222
// make sure we're in the correct working directory!!!!!!
222223
chdir(Fred_base_dir);
223224

@@ -234,7 +235,7 @@ int CFREDDoc::load_mission(char *pathname, int flags) {
234235

235236
clear_mission();
236237

237-
if (parse_main(pathname, flags)) {
238+
if (!parse_main(pathname, flags)) {
238239
if (flags & MPF_IMPORT_FSM) {
239240
sprintf(name, "Unable to import the file \"%s\".", pathname);
240241
Fred_view_wnd->MessageBox(name);
@@ -243,7 +244,7 @@ int CFREDDoc::load_mission(char *pathname, int flags) {
243244
Fred_view_wnd->MessageBox(name);
244245
}
245246
create_new_mission();
246-
return -1;
247+
return false;
247248
}
248249

249250
if ((Num_unknown_ship_classes > 0) || (Num_unknown_weapon_classes > 0) || (Num_unknown_loadout_classes > 0)) {
@@ -360,7 +361,7 @@ int CFREDDoc::load_mission(char *pathname, int flags) {
360361

361362
recreate_dialogs();
362363

363-
return 0;
364+
return true;
364365
}
365366

366367
void CFREDDoc::OnDuplicate() {
@@ -514,7 +515,7 @@ void CFREDDoc::OnFileImportFSM() {
514515
strcpy_s(fs1_path, fs1_path_mfc);
515516

516517
// load mission into memory
517-
if (load_mission(fs1_path, MPF_IMPORT_FSM))
518+
if (!load_mission(fs1_path, MPF_IMPORT_FSM))
518519
continue;
519520

520521
// get filename
@@ -597,7 +598,7 @@ BOOL CFREDDoc::OnOpenDocument(LPCTSTR pathname) {
597598
// unlink(name);
598599
// }
599600

600-
if (load_mission(mission_pathname)) {
601+
if (!load_mission(mission_pathname)) {
601602
*Mission_filename = 0;
602603
return FALSE;
603604
}
@@ -653,7 +654,7 @@ BOOL CFREDDoc::OnSaveDocument(LPCTSTR pathname) {
653654
}
654655

655656
SetModifiedFlag(FALSE);
656-
if (load_mission((char *) pathname))
657+
if (!load_mission((char *) pathname))
657658
Error(LOCATION, "Failed attempting to reload mission after saving. Report this bug now!");
658659

659660
if (Briefing_dialog) {

fred2/freddoc.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@ class CFREDDoc : public CDocument
3838
*
3939
* @returns The file index of the loaded Undo item
4040
*/
41-
int autoload();
41+
bool autoload();
4242

4343
/**
4444
* @brief Read in a new mission file from disk
4545
*
4646
* @param[in] pathname The full filepath name of the file to open
4747
* @param[in] flags
4848
*
49-
* @returns File index of the loaded file, or
50-
* @returns 0 if unable to load
49+
* @returns true on success, false on failure
5150
*/
52-
int load_mission(char *pathname, int flags = 0);
51+
bool load_mission(char *pathname, int flags = 0);
5352

5453
/**
5554
* @brief Pushes an Undo item onto the stack

fred2/fredstubs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void game_set_view_clip(){}
178178
int Warpout_forced = 0;
179179
float Warpout_time;
180180
vec3d Dead_player_last_vel;
181-
int game_start_mission(){return 0;}
181+
bool game_start_mission() {return false;}
182182
int Game_weapons_tbl_valid;
183183
int Game_ships_tbl_valid;
184184
void game_level_close(){}

freespace2/freespace.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ void game_post_level_init()
13991399
/**
14001400
* Tells the server to load the mission and initialize structures
14011401
*/
1402-
int game_start_mission()
1402+
bool game_start_mission()
14031403
{
14041404
mprintf(( "=================== STARTING LEVEL LOAD ==================\n" ));
14051405

@@ -1424,7 +1424,7 @@ int game_start_mission()
14241424

14251425
game_busy( NOX("** starting mission_load() **") );
14261426
load_mission_load = (uint) time(NULL);
1427-
if (mission_load(Game_current_mission_filename)) {
1427+
if ( !mission_load(Game_current_mission_filename) ) {
14281428
if ( !(Game_mode & GM_MULTIPLAYER) ) {
14291429
popup(PF_BODY_BIG | PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "Attempt to load the mission failed", 169));
14301430
gameseq_post_event(GS_EVENT_MAIN_MENU);
@@ -1438,7 +1438,7 @@ int game_start_mission()
14381438

14391439
game_level_close();
14401440

1441-
return 0;
1441+
return false;
14421442
}
14431443
load_mission_load = (uint) (time(NULL) - load_mission_load);
14441444

@@ -1463,7 +1463,7 @@ int game_start_mission()
14631463
int e1 __UNUSED = timer_get_milliseconds();
14641464

14651465
mprintf(("Level load took %f seconds.\n", (e1 - s1) / 1000.0f ));
1466-
return 1;
1466+
return true;
14671467
}
14681468

14691469
int Interface_framerate = 0;

freespace2/freespace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef struct fs_builtin_mission {
9393
// mission management -------------------------------------------------
9494

9595
// loads in the currently selected mission
96-
int game_start_mission();
96+
bool game_start_mission();
9797

9898
// shutdown a mission
9999
void game_level_close();

0 commit comments

Comments
 (0)