Skip to content

Commit 1869b00

Browse files
authored
Merge pull request scp-fs2open#7242 from Goober5000/props_missionsave
mission save compatibility
2 parents e1d67ce + 0666749 commit 1869b00

4 files changed

Lines changed: 47 additions & 18 deletions

File tree

code/globalincs/utility.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ int count_items_with_field(const ITEM_T* item_array, int num_items, FIELD_T ITEM
307307
return count;
308308
}
309309

310+
template <typename VECTOR_T>
311+
size_t count_items_with_value(const VECTOR_T& item_vector)
312+
{
313+
return std::count_if(item_vector.begin(), item_vector.end(),
314+
[](const typename VECTOR_T::value_type& element) { return element.has_value(); });
315+
}
316+
310317
template <typename VECTOR_T, typename ITEM_T, typename FIELD_T>
311318
int find_item_with_string(const VECTOR_T& item_vector, FIELD_T* ITEM_T::* field, const char* str)
312319
{

code/mission/missionparse.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9440,3 +9440,8 @@ bool check_for_24_3_data()
94409440
}
94419441
return false;
94429442
}
9443+
9444+
bool check_for_25_1_data()
9445+
{
9446+
return (count_items_with_value(Props) > 0);
9447+
}

code/mission/missionparse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern const gameversion::version LEGACY_MISSION_VERSION;
6262
extern bool check_for_23_3_data();
6363
extern bool check_for_24_1_data();
6464
extern bool check_for_24_3_data();
65+
extern bool check_for_25_1_data();
6566

6667
#define WING_PLAYER_BASE 0x80000 // used by Fred to tell ship_index in a wing points to a player
6768

code/missioneditor/missionsave.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,10 +3032,16 @@ void Fred_mission_save::save_mission_internal(const char* pathname)
30323032
auto version_23_3 = gameversion::version(23, 3);
30333033
auto version_24_1 = gameversion::version(24, 1);
30343034
auto version_24_3 = gameversion::version(24, 3);
3035-
if (MISSION_VERSION >= version_24_3) {
3035+
auto version_25_1 = gameversion::version(25, 1);
3036+
if (MISSION_VERSION >= version_25_1) {
30363037
Warning(LOCATION,
3037-
"Notify an SCP coder: now that the required mission version is at least 24.3, the check_for_24_3_data(), "
3038-
"the check_for_24_1_data() and check_for_23_3_data() code can be removed");
3038+
"Notify an SCP coder: now that the required mission version is at least 25.1, the check_for_25_1_data(), "
3039+
"check_for_24_3_data(), check_for_24_1_data(), and check_for_23_3_data() code can be removed");
3040+
} else if (check_for_25_1_data()) {
3041+
The_mission.required_fso_version = version_25_1;
3042+
} else if (MISSION_VERSION >= version_24_3) {
3043+
Warning(LOCATION, "Notify an SCP coder: now that the required mission version is at least 24.3, the "
3044+
"check_for_24_3_data(), check_for_24_1_data(), and check_for_23_3_data() code can be removed");
30393045
} else if (check_for_24_3_data()) {
30403046
The_mission.required_fso_version = version_24_3;
30413047
} else if (MISSION_VERSION >= version_24_1) {
@@ -3382,7 +3388,7 @@ int Fred_mission_save::save_warp_params(WarpDirection direction, ship* shipp)
33823388
int Fred_mission_save::save_objects()
33833389
{
33843390
SCP_string sexp_out;
3385-
int i, z;
3391+
int i, z, count;
33863392
object* objp;
33873393
ship* shipp;
33883394
ship_info* sip;
@@ -3391,7 +3397,7 @@ int Fred_mission_save::save_objects()
33913397
parse_comments(2);
33923398
fout("\t\t;! %d total\n", ship_get_num_ships());
33933399

3394-
for (i = z = 0; i < MAX_SHIPS; i++) {
3400+
for (i = count = 0; i < MAX_SHIPS; i++) {
33953401
if (Ships[i].objnum < 0) {
33963402
continue;
33973403
}
@@ -3406,9 +3412,11 @@ int Fred_mission_save::save_objects()
34063412
sip = &Ship_info[shipp->ship_info_index];
34073413
required_string_either_fred("$Name:", "#Wings");
34083414
required_string_fred("$Name:");
3409-
parse_comments(z ? 2 : 1);
3415+
parse_comments(count ? 2 : 1);
34103416
fout(" %s\t\t;! Object #%d", shipp->ship_name, i);
34113417

3418+
count++;
3419+
34123420
// Display name
34133421
// The display name is only written if there was one at the start to avoid introducing inconsistencies
34143422
if (save_config.save_format != MissionFormat::RETAIL && ((save_config.always_save_display_names && shipp->wingnum < 0) || shipp->has_display_name())) {
@@ -4155,8 +4163,6 @@ int Fred_mission_save::save_objects()
41554163

41564164
// end of texture replacement -------------------------------
41574165

4158-
z++;
4159-
41604166
fso_comment_pop();
41614167
}
41624168

@@ -4857,18 +4863,19 @@ int Fred_mission_save::save_wings()
48574863
fred_parse_flag = 0;
48584864
required_string_fred("#Wings");
48594865
parse_comments(2);
4860-
fout("\t\t;! %d total", Num_wings);
4866+
fout("\t\t;! %d total\n", Num_wings);
48614867

48624868
for (auto& w : Wings) {
48634869
if (!w.wave_count)
48644870
continue;
48654871

4866-
count++;
48674872
required_string_one_of_fred(3, "$Name:", "#Events", "#Props");
48684873
required_string_fred("$Name:");
4869-
parse_comments(2);
4874+
parse_comments(count ? 2 : 1);
48704875
fout(" %s", w.name);
48714876

4877+
count++;
4878+
48724879
// squad logo - Goober5000
48734880
if (save_config.save_format != MissionFormat::RETAIL) {
48744881
if (strlen(w.wing_squad_filename) > 0) //-V805
@@ -5126,21 +5133,30 @@ int Fred_mission_save::save_wings()
51265133

51275134
int Fred_mission_save::save_props()
51285135
{
5129-
if (save_config.save_format != MissionFormat::RETAIL) {
5136+
auto num_props = count_items_with_value(Props);
5137+
5138+
if ((save_config.save_format != MissionFormat::RETAIL) && (num_props > 0)) {
51305139
fred_parse_flag = 0;
5131-
required_string_fred("#Props");
5132-
parse_comments(2);
5133-
fout("\t\t;! %d total", static_cast<int>(Props.size()));
5140+
size_t count = 0;
5141+
5142+
if (optional_string_fred("#Props", "#End")) {
5143+
parse_comments(2);
5144+
} else {
5145+
fout("\n\n#Props");
5146+
}
5147+
fout("\t\t;! " SIZE_T_ARG " total\n", num_props);
51345148

51355149
for (const auto& p : Props) {
51365150
if (p.has_value()) {
51375151
required_string_either_fred("$Name:", "#Events");
51385152
required_string_fred("$Name:");
5139-
parse_comments(2);
5153+
parse_comments(count ? 2 : 1);
51405154
fout(" %s", p->prop_name);
51415155

5142-
required_string_fred("$Class:");
5143-
parse_comments(2);
5156+
count++;
5157+
5158+
required_string_fred("\n$Class:");
5159+
parse_comments(0);
51445160
fout(" %s", Prop_info[p->prop_info_index].name.c_str());
51455161

51465162
required_string_fred("$Location:");

0 commit comments

Comments
 (0)