Skip to content

Commit d5f8269

Browse files
committed
save/parse mission prop classes by name
1 parent fa07a29 commit d5f8269

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

@@ -5131,7 +5132,29 @@ void parse_prop(mission* /*pm*/)
51315132

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

51365159
required_string("$Location:");
51375160
stuff_vec3d(&p.position);
@@ -5150,6 +5173,12 @@ void parse_prop(mission* /*pm*/)
51505173
}
51515174
}
51525175

5176+
// if idx is still -1 then we have an empty props.tbl so we parse
5177+
// everything here and just discard it. A warning has already been generated above.
5178+
if (idx < 0) {
5179+
return;
5180+
}
5181+
51535182
Parse_props.emplace_back(p);
51545183
}
51555184

@@ -6518,6 +6547,7 @@ bool parse_mission(mission *pm, int flags)
65186547

65196548
// reset parse error stuff
65206549
Num_unknown_ship_classes = 0;
6550+
Num_unknown_prop_classes = 0;
65216551
Num_unknown_weapon_classes = 0;
65226552
Num_unknown_loadout_classes = 0;
65236553

@@ -6557,7 +6587,7 @@ bool parse_mission(mission *pm, int flags)
65576587
parse_custom_data(pm);
65586588

65596589
// if we couldn't load some mod data
6560-
if ((Num_unknown_ship_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
6590+
if ((Num_unknown_ship_classes > 0) || (Num_unknown_prop_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
65616591
// if running on standalone server, just print to the log
65626592
if (Game_mode & GM_STANDALONE_SERVER) {
65636593
mprintf(("Warning! Could not load %d ship classes!\n", Num_unknown_ship_classes));
@@ -6571,7 +6601,10 @@ bool parse_mission(mission *pm, int flags)
65716601
if (Num_unknown_ship_classes > 0) {
65726602
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");
65736603
}
6574-
else {
6604+
else if (Num_unknown_prop_classes > 0) {
6605+
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");
6606+
}
6607+
else if (Num_unknown_loadout_classes > 0) {
65756608
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");
65766609
}
65776610

code/mission/missionparse.h

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

353353
extern int Num_unknown_ship_classes;
354+
extern int Num_unknown_prop_classes;
354355
extern int Num_unknown_weapon_classes;
355356
extern int Num_unknown_loadout_classes;
356357

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)