Skip to content

Commit 3bbcee0

Browse files
committed
save/parse mission prop classes by name
1 parent a335931 commit 3bbcee0

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

@@ -5128,7 +5129,29 @@ void parse_prop(mission* /*pm*/)
51285129

51295130
// Maybe do this by name instead?
51305131
required_string("$Class:");
5131-
stuff_int(&p.prop_info_index);
5132+
SCP_string class_name;
5133+
stuff_string(class_name, F_NAME);
5134+
int idx = prop_info_lookup(class_name.c_str());
5135+
if (idx < 0) {
5136+
SCP_string text;
5137+
sprintf(text, "Prop \"%s\" has an invalid prop type (props.tbl probably changed).", p.name);
5138+
5139+
if (Prop_info.empty()) {
5140+
text += " No props.tbl is loaded. Prop will not be added to the mission!";
5141+
} else {
5142+
text += " Prop will be added to the mission with type 0.";
5143+
idx = 0;
5144+
}
5145+
5146+
if (Fred_running) {
5147+
Warning(LOCATION, text.c_str());
5148+
} else {
5149+
mprintf(("MISSIONS: %s", text.c_str()));
5150+
}
5151+
5152+
Num_unknown_prop_classes++;
5153+
}
5154+
p.prop_info_index = idx;
51325155

51335156
required_string("$Location:");
51345157
stuff_vec3d(&p.position);
@@ -5147,6 +5170,12 @@ void parse_prop(mission* /*pm*/)
51475170
}
51485171
}
51495172

5173+
// if idx is still -1 then we have an empty props.tbl so we parse
5174+
// everything here and just discard it. A warning has already been generated above.
5175+
if (idx < 0) {
5176+
return;
5177+
}
5178+
51505179
Parse_props.emplace_back(p);
51515180
}
51525181

@@ -6515,6 +6544,7 @@ bool parse_mission(mission *pm, int flags)
65156544

65166545
// reset parse error stuff
65176546
Num_unknown_ship_classes = 0;
6547+
Num_unknown_prop_classes = 0;
65186548
Num_unknown_weapon_classes = 0;
65196549
Num_unknown_loadout_classes = 0;
65206550

@@ -6554,7 +6584,7 @@ bool parse_mission(mission *pm, int flags)
65546584
parse_custom_data(pm);
65556585

65566586
// if we couldn't load some mod data
6557-
if ((Num_unknown_ship_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
6587+
if ((Num_unknown_ship_classes > 0) || (Num_unknown_prop_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
65586588
// if running on standalone server, just print to the log
65596589
if (Game_mode & GM_STANDALONE_SERVER) {
65606590
mprintf(("Warning! Could not load %d ship classes!\n", Num_unknown_ship_classes));
@@ -6568,7 +6598,10 @@ bool parse_mission(mission *pm, int flags)
65686598
if (Num_unknown_ship_classes > 0) {
65696599
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");
65706600
}
6571-
else {
6601+
else if (Num_unknown_prop_classes > 0) {
6602+
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");
6603+
}
6604+
else if (Num_unknown_loadout_classes > 0) {
65726605
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");
65736606
}
65746607

code/mission/missionparse.h

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

354354
extern int Num_unknown_ship_classes;
355+
extern int Num_unknown_prop_classes;
355356
extern int Num_unknown_weapon_classes;
356357
extern int Num_unknown_loadout_classes;
357358

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
@@ -5288,7 +5288,7 @@ int CFred_mission_save::save_props()
52885288

52895289
required_string_fred("$Class:");
52905290
parse_comments(2);
5291-
fout(" %d", p->prop_info_index);
5291+
fout(" %s", Prop_info[p->prop_info_index].name);
52925292

52935293
required_string_fred("$Location:");
52945294
parse_comments();

qtfred/src/mission/Editor.cpp

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

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

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

qtfred/src/mission/missionsave.cpp

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

54825482
required_string_fred("$Class:");
54835483
parse_comments(2);
5484-
fout(" %d", p->prop_info_index);
5484+
fout(" %s", Prop_info[p->prop_info_index].name);
54855485

54865486
required_string_fred("$Location:");
54875487
parse_comments();

0 commit comments

Comments
 (0)