|
10 | 10 |
|
11 | 11 | // Bodies copied from the old implementations in missionsave.cpp, |
12 | 12 | // unchanged except for the new class name and include. |
13 | | -int Fred_campaign_save::save_campaign_file(const char* pathname) |
| 13 | +int Fred_campaign_save::save_campaign_file(const char* pathname, const SCP_vector<campaign_link>& links) |
14 | 14 | { |
15 | 15 | // This is original FRED code. These were moved to the call sites as the data should be fully |
16 | 16 | // prepared before calling this function. |
@@ -162,55 +162,100 @@ int Fred_campaign_save::save_campaign_file(const char* pathname) |
162 | 162 | bypass_comment(";;FSO 3.6.8;; +Debriefing Persona Index:"); |
163 | 163 | } |
164 | 164 |
|
165 | | - // new save cmission sexps |
166 | | - if (optional_string_fred("+Formula:", "$Mission:")) { |
167 | | - parse_comments(); |
168 | | - } else { |
169 | | - fout("\n+Formula:"); |
| 165 | + // save campaign link sexp |
| 166 | + bool mission_loop = false; |
| 167 | + bool mission_fork = false; |
| 168 | + int flag = 0; |
| 169 | + for (auto& link : links) { |
| 170 | + if (link.from == i) { |
| 171 | + if (!flag) { |
| 172 | + if (optional_string_fred("+Formula:", "$Mission:")) |
| 173 | + parse_comments(); |
| 174 | + else |
| 175 | + fout("\n+Formula:"); |
| 176 | + |
| 177 | + fout(" ( cond\n"); |
| 178 | + flag = 1; |
| 179 | + } |
| 180 | + |
| 181 | + // save_campaign_sexp(Links[j].sexp, Campaign.missions[Links[j].to].name); |
| 182 | + if (link.is_mission_loop) { |
| 183 | + mission_loop = true; |
| 184 | + } else if (link.is_mission_fork && (save_config.save_format != MissionFormat::RETAIL)) { |
| 185 | + mission_fork = true; |
| 186 | + } else { |
| 187 | + save_campaign_sexp(link.sexp, link.to); |
| 188 | + } |
| 189 | + } |
170 | 190 | } |
171 | 191 |
|
172 | | - { |
173 | | - SCP_string sexp_out{}; |
174 | | - convert_sexp_to_string(sexp_out, cm.formula, SEXP_SAVE_MODE); |
175 | | - fout(" %s", sexp_out.c_str()); |
| 192 | + if (flag) { |
| 193 | + fout(")"); |
176 | 194 | } |
177 | 195 |
|
178 | | - bool mission_loop = cm.flags & CMISSION_FLAG_HAS_LOOP; |
179 | | - |
180 | | - Assertion(cm.flags ^ CMISSION_FLAG_HAS_FORK, |
181 | | - "scpFork campaigns cannot be saved, use axemFork.\n Should be detected on load."); |
182 | | - |
183 | | - if (mission_loop) { |
184 | | - required_string_fred("\n+Mission Loop:"); |
| 196 | + // now save campaign loop sexp |
| 197 | + if (mission_loop || mission_fork) { |
| 198 | + if (mission_loop) |
| 199 | + required_string_fred("\n+Mission Loop:"); |
| 200 | + else |
| 201 | + required_string_fred("\n+Mission Fork:"); |
185 | 202 | parse_comments(); |
186 | 203 |
|
187 | | - if (cm.mission_branch_desc) { |
188 | | - required_string_fred("+Mission Loop Text:"); |
189 | | - parse_comments(); |
190 | | - fout_ext("\n", "%s", cm.mission_branch_desc); |
191 | | - fout("\n$end_multi_text"); |
192 | | - } |
193 | | - |
194 | | - if (cm.mission_branch_brief_anim) { |
195 | | - required_string_fred("+Mission Loop Brief Anim:"); |
196 | | - parse_comments(); |
197 | | - fout_ext("\n", "%s", cm.mission_branch_brief_anim); |
198 | | - fout("\n$end_multi_text"); |
| 204 | + int num_mission_special = 0; |
| 205 | + for (auto& link : links) { |
| 206 | + if ((link.from == i) && (link.is_mission_loop || link.is_mission_fork)) { |
| 207 | + |
| 208 | + num_mission_special++; |
| 209 | + |
| 210 | + if ((num_mission_special == 1) && link.mission_branch_txt) { |
| 211 | + if (mission_loop) |
| 212 | + required_string_fred("+Mission Loop Text:"); |
| 213 | + else |
| 214 | + required_string_fred("+Mission Fork Text:"); |
| 215 | + parse_comments(); |
| 216 | + fout_ext("\n", "%s", link.mission_branch_txt); |
| 217 | + fout("\n$end_multi_text"); |
| 218 | + } |
| 219 | + |
| 220 | + if ((num_mission_special == 1) && link.mission_branch_brief_anim) { |
| 221 | + if (mission_loop) |
| 222 | + required_string_fred("+Mission Loop Brief Anim:"); |
| 223 | + else |
| 224 | + required_string_fred("+Mission Fork Brief Anim:"); |
| 225 | + parse_comments(); |
| 226 | + fout_ext("\n", "%s", link.mission_branch_brief_anim); |
| 227 | + fout("\n$end_multi_text"); |
| 228 | + } |
| 229 | + |
| 230 | + if ((num_mission_special == 1) && link.mission_branch_brief_sound) { |
| 231 | + if (mission_loop) |
| 232 | + required_string_fred("+Mission Loop Brief Sound:"); |
| 233 | + else |
| 234 | + required_string_fred("+Mission Fork Brief Sound:"); |
| 235 | + parse_comments(); |
| 236 | + fout_ext("\n", "%s", link.mission_branch_brief_sound); |
| 237 | + fout("\n$end_multi_text"); |
| 238 | + } |
| 239 | + |
| 240 | + if (num_mission_special == 1) { |
| 241 | + // write out mission loop formula |
| 242 | + fout("\n+Formula:"); |
| 243 | + fout(" ( cond\n"); |
| 244 | + save_campaign_sexp(link.sexp, link.to); |
| 245 | + fout(")"); |
| 246 | + } |
| 247 | + if (mission_fork) { |
| 248 | + fout("Option: ", Campaign.missions[link.to].name); |
| 249 | + } |
| 250 | + } |
199 | 251 | } |
200 | | - |
201 | | - if (cm.mission_branch_brief_sound) { |
202 | | - required_string_fred("+Mission Loop Brief Sound:"); |
203 | | - parse_comments(); |
204 | | - fout_ext("\n", "%s", cm.mission_branch_brief_sound); |
205 | | - fout("\n$end_multi_text"); |
206 | | - } |
207 | | - |
208 | | - // write out mission loop formula |
209 | | - fout("\n+Formula:"); |
210 | | - { |
211 | | - SCP_string sexp_out{}; |
212 | | - convert_sexp_to_string(sexp_out, cm.mission_loop_formula, SEXP_SAVE_MODE); |
213 | | - fout(" %s", sexp_out.c_str()); |
| 252 | + if (mission_loop && num_mission_special > 1) { |
| 253 | + char buffer[1024]; |
| 254 | + sprintf(buffer, |
| 255 | + "Multiple branching loop error from mission %s\nEdit campaign for *at most* 1 loop from each " |
| 256 | + "mission.", |
| 257 | + cm.name); |
| 258 | + Message(os::dialogs::MESSAGEBOX_ERROR, buffer); |
214 | 259 | } |
215 | 260 | } |
216 | 261 |
|
|
0 commit comments