Skip to content

Commit 35bc478

Browse files
committed
save/parse mission prop classes by name
1 parent 9f19f2d commit 35bc478

File tree

6 files changed

+47
-13
lines changed

6 files changed

+47
-13
lines changed

code/mission/missionparse.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ int Num_teams;
115115
fix Entry_delay_time = 0;
116116

117117
int Num_unknown_ship_classes;
118+
int Num_unknown_prop_classes;
118119
int Num_unknown_weapon_classes;
119120
int Num_unknown_loadout_classes;
120121

@@ -4956,7 +4957,29 @@ void parse_prop(mission* /*pm*/)
49564957

49574958
// Maybe do this by name instead?
49584959
required_string("$Class:");
4959-
stuff_int(&p.prop_info_index);
4960+
SCP_string class_name;
4961+
stuff_string(class_name, F_NAME);
4962+
int idx = prop_info_lookup(class_name.c_str());
4963+
if (idx < 0) {
4964+
SCP_string text;
4965+
sprintf(text, "Prop \"%s\" has an invalid prop type (props.tbl probably changed).", p.name);
4966+
4967+
if (Prop_info.empty()) {
4968+
text += " No props.tbl is loaded. Prop will not be added to the mission!";
4969+
} else {
4970+
text += " Prop will be added to the mission with type 0.";
4971+
idx = 0;
4972+
}
4973+
4974+
if (Fred_running) {
4975+
Warning(LOCATION, text.c_str());
4976+
} else {
4977+
mprintf(("MISSIONS: %s", text.c_str()));
4978+
}
4979+
4980+
Num_unknown_prop_classes++;
4981+
}
4982+
p.prop_info_index = idx;
49604983

49614984
required_string("$Location:");
49624985
stuff_vec3d(&p.position);
@@ -4975,6 +4998,12 @@ void parse_prop(mission* /*pm*/)
49754998
}
49764999
}
49775000

5001+
// if idx is still -1 then we have an empty props.tbl so we parse
5002+
// everything here and just discard it. A warning has already been generated above.
5003+
if (idx < 0) {
5004+
return;
5005+
}
5006+
49785007
Parse_props.emplace_back(p);
49795008
}
49805009

@@ -6343,6 +6372,7 @@ bool parse_mission(mission *pm, int flags)
63436372

63446373
// reset parse error stuff
63456374
Num_unknown_ship_classes = 0;
6375+
Num_unknown_prop_classes = 0;
63466376
Num_unknown_weapon_classes = 0;
63476377
Num_unknown_loadout_classes = 0;
63486378

@@ -6382,7 +6412,7 @@ bool parse_mission(mission *pm, int flags)
63826412
parse_custom_data(pm);
63836413

63846414
// if we couldn't load some mod data
6385-
if ((Num_unknown_ship_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
6415+
if ((Num_unknown_ship_classes > 0) || (Num_unknown_prop_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
63866416
// if running on standalone server, just print to the log
63876417
if (Game_mode & GM_STANDALONE_SERVER) {
63886418
mprintf(("Warning! Could not load %d ship classes!\n", Num_unknown_ship_classes));
@@ -6396,7 +6426,10 @@ bool parse_mission(mission *pm, int flags)
63966426
if (Num_unknown_ship_classes > 0) {
63976427
sprintf(text, "Warning!\n\nFreeSpace was unable to find %d ship class%s while loading this mission. This can happen if you try to play a %s that is incompatible with the current mod.\n\n", Num_unknown_ship_classes, (Num_unknown_ship_classes > 1) ? "es" : "", (Game_mode & GM_CAMPAIGN_MODE) ? "campaign" : "mission");
63986428
}
6399-
else {
6429+
else if (Num_unknown_prop_classes > 0) {
6430+
sprintf(text, "Warning!\n\nFreeSpace was unable to find %d prop class%s while loading this mission. This can happen if you try to play a %s that is incompatible with the current mod.\n\n", Num_unknown_prop_classes, (Num_unknown_prop_classes > 1) ? "es" : "", (Game_mode & GM_CAMPAIGN_MODE) ? "campaign" : "mission");
6431+
}
6432+
else if (Num_unknown_loadout_classes > 0) {
64006433
sprintf(text, "Warning!\n\nFreeSpace was unable to find %d weapon class%s while loading this mission. This can happen if you try to play a %s that is incompatible with the current mod.\n\n", Num_unknown_loadout_classes, (Num_unknown_loadout_classes > 1) ? "es" : "", (Game_mode & GM_CAMPAIGN_MODE) ? "campaign" : "mission");
64016434
}
64026435

code/mission/missionparse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ extern fix Entry_delay_time;
301301
extern int Loading_screen_bm_index;
302302

303303
extern int Num_unknown_ship_classes;
304+
extern int Num_unknown_prop_classes;
304305
extern int Num_unknown_weapon_classes;
305306
extern int Num_unknown_loadout_classes;
306307

fred2/freddoc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,13 @@ bool CFREDDoc::load_mission(const char *pathname, int flags) {
246246
}
247247

248248
// message 2: unknown classes
249-
if ((Num_unknown_ship_classes > 0) || (Num_unknown_weapon_classes > 0) || (Num_unknown_loadout_classes > 0)) {
249+
if ((Num_unknown_ship_classes > 0) || (Num_unknown_prop_classes > 0) || (Num_unknown_weapon_classes > 0) || (Num_unknown_loadout_classes > 0)) {
250250
if (flags & MPF_IMPORT_FSM) {
251251
char msg[256];
252-
sprintf(msg, "Fred encountered unknown ship/weapon classes when importing \"%s\" (path \"%s\"). You will have to manually edit the converted mission to correct this.", The_mission.name, pathname);
252+
sprintf(msg, "Fred encountered unknown ship/prop/weapon classes when importing \"%s\" (path \"%s\"). You will have to manually edit the converted mission to correct this.", The_mission.name, pathname);
253253
Fred_view_wnd->MessageBox(msg);
254254
} else {
255-
Fred_view_wnd->MessageBox("Fred encountered unknown ship/weapon classes when parsing the mission file. This may be due to mission disk data you do not have.");
255+
Fred_view_wnd->MessageBox("Fred encountered unknown ship/prop/weapon classes when parsing the mission file. This may be due to mission disk data you do not have.");
256256
}
257257
}
258258

fred2/missionsave.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5247,7 +5247,7 @@ int CFred_mission_save::save_props()
52475247

52485248
required_string_fred("$Class:");
52495249
parse_comments(2);
5250-
fout(" %d", p->prop_info_index);
5250+
fout(" %s", Prop_info[p->prop_info_index].name);
52515251

52525252
required_string_fred("$Location:");
52535253
parse_comments();

qtfred/src/mission/Editor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,22 @@ bool Editor::loadMission(const std::string& mission_name, int flags) {
239239
}
240240

241241
// message 2: unknown classes
242-
if ((Num_unknown_ship_classes > 0) || (Num_unknown_weapon_classes > 0) || (Num_unknown_loadout_classes > 0)) {
242+
if ((Num_unknown_ship_classes > 0) || (Num_unknown_prop_classes > 0) || (Num_unknown_weapon_classes > 0) || (Num_unknown_loadout_classes > 0)) {
243243
if (flags & MPF_IMPORT_FSM) {
244244
SCP_string msg;
245245
sprintf(msg,
246-
"Fred encountered unknown ship/weapon classes when importing \"%s\" (path \"%s\"). You will have to manually edit the converted mission to correct this.",
246+
"Fred encountered unknown ship/prop/weapon classes when importing \"%s\" (path \"%s\"). You will have to manually edit the converted mission to correct this.",
247247
The_mission.name,
248248
filepath.c_str());
249249

250250
_lastActiveViewport->dialogProvider->showButtonDialog(DialogType::Warning,
251-
"Unknown Ship classes",
251+
"Unknown object classes",
252252
msg,
253253
{ DialogButton::Ok });
254254
} else {
255255
_lastActiveViewport->dialogProvider->showButtonDialog(DialogType::Warning,
256-
"Unknown Ship classes",
257-
"Fred encountered unknown ship/weapon classes when parsing the mission file. This may be due to mission disk data you do not have.",
256+
"Unknown object classes",
257+
"Fred encountered unknown ship/prop/weapon classes when parsing the mission file. This may be due to mission disk data you do not have.",
258258
{ DialogButton::Ok });
259259
}
260260
}

qtfred/src/mission/missionsave.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5429,7 +5429,7 @@ int CFred_mission_save::save_props()
54295429

54305430
required_string_fred("$Class:");
54315431
parse_comments(2);
5432-
fout(" %d", p->prop_info_index);
5432+
fout(" %s", Prop_info[p->prop_info_index].name);
54335433

54345434
required_string_fred("$Location:");
54355435
parse_comments();

0 commit comments

Comments
 (0)