Skip to content

Commit 578a43a

Browse files
committed
save/parse mission prop classes by name
1 parent ec1bee0 commit 578a43a

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

@@ -4974,7 +4975,29 @@ void parse_prop(mission* /*pm*/)
49744975

49754976
// Maybe do this by name instead?
49764977
required_string("$Class:");
4977-
stuff_int(&p.prop_info_index);
4978+
SCP_string class_name;
4979+
stuff_string(class_name, F_NAME);
4980+
int idx = prop_info_lookup(class_name.c_str());
4981+
if (idx < 0) {
4982+
SCP_string text;
4983+
sprintf(text, "Prop \"%s\" has an invalid prop type (props.tbl probably changed).", p.name);
4984+
4985+
if (Prop_info.empty()) {
4986+
text += " No props.tbl is loaded. Prop will not be added to the mission!";
4987+
} else {
4988+
text += " Prop will be added to the mission with type 0.";
4989+
idx = 0;
4990+
}
4991+
4992+
if (Fred_running) {
4993+
Warning(LOCATION, text.c_str());
4994+
} else {
4995+
mprintf(("MISSIONS: %s", text.c_str()));
4996+
}
4997+
4998+
Num_unknown_prop_classes++;
4999+
}
5000+
p.prop_info_index = idx;
49785001

49795002
required_string("$Location:");
49805003
stuff_vec3d(&p.position);
@@ -4993,6 +5016,12 @@ void parse_prop(mission* /*pm*/)
49935016
}
49945017
}
49955018

5019+
// if idx is still -1 then we have an empty props.tbl so we parse
5020+
// everything here and just discard it. A warning has already been generated above.
5021+
if (idx < 0) {
5022+
return;
5023+
}
5024+
49965025
Parse_props.emplace_back(p);
49975026
}
49985027

@@ -6361,6 +6390,7 @@ bool parse_mission(mission *pm, int flags)
63616390

63626391
// reset parse error stuff
63636392
Num_unknown_ship_classes = 0;
6393+
Num_unknown_prop_classes = 0;
63646394
Num_unknown_weapon_classes = 0;
63656395
Num_unknown_loadout_classes = 0;
63666396

@@ -6400,7 +6430,7 @@ bool parse_mission(mission *pm, int flags)
64006430
parse_custom_data(pm);
64016431

64026432
// if we couldn't load some mod data
6403-
if ((Num_unknown_ship_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
6433+
if ((Num_unknown_ship_classes > 0) || (Num_unknown_prop_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
64046434
// if running on standalone server, just print to the log
64056435
if (Game_mode & GM_STANDALONE_SERVER) {
64066436
mprintf(("Warning! Could not load %d ship classes!\n", Num_unknown_ship_classes));
@@ -6414,7 +6444,10 @@ bool parse_mission(mission *pm, int flags)
64146444
if (Num_unknown_ship_classes > 0) {
64156445
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");
64166446
}
6417-
else {
6447+
else if (Num_unknown_prop_classes > 0) {
6448+
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");
6449+
}
6450+
else if (Num_unknown_loadout_classes > 0) {
64186451
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");
64196452
}
64206453

code/mission/missionparse.h

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

325325
extern int Num_unknown_ship_classes;
326+
extern int Num_unknown_prop_classes;
326327
extern int Num_unknown_weapon_classes;
327328
extern int Num_unknown_loadout_classes;
328329

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

52795279
required_string_fred("$Class:");
52805280
parse_comments(2);
5281-
fout(" %d", p->prop_info_index);
5281+
fout(" %s", Prop_info[p->prop_info_index].name);
52825282

52835283
required_string_fred("$Location:");
52845284
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
@@ -5460,7 +5460,7 @@ int CFred_mission_save::save_props()
54605460

54615461
required_string_fred("$Class:");
54625462
parse_comments(2);
5463-
fout(" %d", p->prop_info_index);
5463+
fout(" %s", Prop_info[p->prop_info_index].name);
54645464

54655465
required_string_fred("$Location:");
54665466
parse_comments();

0 commit comments

Comments
 (0)