Skip to content

Commit d8fbcad

Browse files
committed
save/parse mission prop classes by name
1 parent d7c73c3 commit d8fbcad

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

@@ -5045,7 +5046,29 @@ void parse_prop(mission* /*pm*/)
50455046

50465047
// Maybe do this by name instead?
50475048
required_string("$Class:");
5048-
stuff_int(&p.prop_info_index);
5049+
SCP_string class_name;
5050+
stuff_string(class_name, F_NAME);
5051+
int idx = prop_info_lookup(class_name.c_str());
5052+
if (idx < 0) {
5053+
SCP_string text;
5054+
sprintf(text, "Prop \"%s\" has an invalid prop type (props.tbl probably changed).", p.name);
5055+
5056+
if (Prop_info.empty()) {
5057+
text += " No props.tbl is loaded. Prop will not be added to the mission!";
5058+
} else {
5059+
text += " Prop will be added to the mission with type 0.";
5060+
idx = 0;
5061+
}
5062+
5063+
if (Fred_running) {
5064+
Warning(LOCATION, text.c_str());
5065+
} else {
5066+
mprintf(("MISSIONS: %s", text.c_str()));
5067+
}
5068+
5069+
Num_unknown_prop_classes++;
5070+
}
5071+
p.prop_info_index = idx;
50495072

50505073
required_string("$Location:");
50515074
stuff_vec3d(&p.position);
@@ -5064,6 +5087,12 @@ void parse_prop(mission* /*pm*/)
50645087
}
50655088
}
50665089

5090+
// if idx is still -1 then we have an empty props.tbl so we parse
5091+
// everything here and just discard it. A warning has already been generated above.
5092+
if (idx < 0) {
5093+
return;
5094+
}
5095+
50675096
Parse_props.emplace_back(p);
50685097
}
50695098

@@ -6432,6 +6461,7 @@ bool parse_mission(mission *pm, int flags)
64326461

64336462
// reset parse error stuff
64346463
Num_unknown_ship_classes = 0;
6464+
Num_unknown_prop_classes = 0;
64356465
Num_unknown_weapon_classes = 0;
64366466
Num_unknown_loadout_classes = 0;
64376467

@@ -6471,7 +6501,7 @@ bool parse_mission(mission *pm, int flags)
64716501
parse_custom_data(pm);
64726502

64736503
// if we couldn't load some mod data
6474-
if ((Num_unknown_ship_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
6504+
if ((Num_unknown_ship_classes > 0) || (Num_unknown_prop_classes > 0) || ( Num_unknown_loadout_classes > 0 )) {
64756505
// if running on standalone server, just print to the log
64766506
if (Game_mode & GM_STANDALONE_SERVER) {
64776507
mprintf(("Warning! Could not load %d ship classes!\n", Num_unknown_ship_classes));
@@ -6485,7 +6515,10 @@ bool parse_mission(mission *pm, int flags)
64856515
if (Num_unknown_ship_classes > 0) {
64866516
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");
64876517
}
6488-
else {
6518+
else if (Num_unknown_prop_classes > 0) {
6519+
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");
6520+
}
6521+
else if (Num_unknown_loadout_classes > 0) {
64896522
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");
64906523
}
64916524

code/mission/missionparse.h

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

347347
extern int Num_unknown_ship_classes;
348+
extern int Num_unknown_prop_classes;
348349
extern int Num_unknown_weapon_classes;
349350
extern int Num_unknown_loadout_classes;
350351

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)