-
Notifications
You must be signed in to change notification settings - Fork 5
/
Converter.cs
2980 lines (2847 loc) · 160 KB
/
Converter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Idmr.Platform.dll, X-wing series mission library file, XW95-XWA
* Copyright (C) 2009-2024 Michael Gaisser ([email protected])
* Licensed under the MPL v2.0 or later
*
* Full notice in ../help/Idmr.Platform.chm
* Version: 7.0
*
* CHANGELOG
* v7.0, 241006
* [NEW] XWA format spec implemented
* [UPD] XwaToXvT Roles convert now
* [UPD] XwaToTie does the Radio now
* [UPD] Briefing event conversions
* [UPD] Xwing ArrDep method fix
* v6.1, 231208
* [NEW] TieToXvt, TieToXvtBop, XvtBopToXwa, TieToXwa
* [FIX] XvT to TIE FG goals convert "must NOT be destroyed" to "exist/survive" and throws on other uses of "must NOT"
* [UPD] Added Countermeasures, ExplosionTime, GlobalUnit, and Optionals to XwaToXvt Flightgroups
* v6.0, 231027
* [UPD] Changes due to XWA Arr/Dep Method1
* v5.4, 210404
* [FIX] TIE goal check exception type
* [FIX YOGEME#55] FG goal amounts when converting XW [JB]
* v5.3, 210328
* [FIX YOGEME#53] removed zoom multiplier in XW-XWA BRF MoveMap event
* [FIX] Strip out Title strings from XW Description conversion
* [FIX YOGEME#51] Removed auto-add of Page Break event when XW ClearText detected
* [FIX YOGEME#51] in XW BRF conversion, skip over "None" events
* v4.0, 200809
* [UPD] cleanup
* v3.0, 180309
* [UPD] capped TIE AI [JB]
* [FIX] TIE PlayerCraft [JB]
* [FIX] loop error in TIE Briefing.Events [JB]
* [FIX] Message.Delay from XWA [JB]
* [NEW] XWing upgrade conversions with various helper functions [JB]
* v2.6, 160606
* [FIX] XWA to TIE player craft
* v2.3, 150405
* [UPD] XvT.Globals.Goal.Trigger implementation
* v2.1, 141214
* [UPD] change to MPL
* v2.0, 120525
* - rewrote Trigger and Waypoint conversions
* - rewrote for Waypoint interface removal
* - removed craftCheck() to use *.Mission.CraftCheck
* - XvtBopToTie: Briefing.Events to short[]
*/
using System;
using System.Collections.Generic;
namespace Idmr.Platform
{
/// <summary>Object for Mission Platform conversions.</summary>
/// <remarks>Converted files will use same MissionPath with platform included ("test.tie" to "test_Xvt.tie").</remarks>
public static class Converter
{
/// <summary>Downgrades XvT and BoP missions to TIE95.</summary>
/// <remarks>G/PLT, SHPYD, REPYD and M/SC craft will have their indexes changed to reflect IDMR TIE95 Ships patch numbering. Triggers and orders will update.<br/>
/// FG.Radio is not converted, since TIE behaviour is different.<br/>
/// Maximum FG.Formation value of 12 allowed.<br/>
/// AI level capped at Top Ace.<br/>
/// For Triggers, maximum Trigger index of 24, maximum VariableType of 9, Amounts will be adjusted as 66% to 75%, 33% to 50% and "each" to 100%.<br/>
/// Maximum Abort index of 5.<br/>
/// Maximum FG.Goal Amount index of 6, 75% converted to 100%, 25% to 50%. First three XvT Goals will be used as Primary, Secondary and Bonus goals. Bonus points will be scaled appropriately. Goals only used if set for Team[0] and Enabled.<br/>
/// First two Arrival triggers used, first Departure trigger used. First three Orders used. All standard WPs and first Briefing WP used.<br/>
/// For Messages, first two triggers used.<br/>
/// For the Briefing, entire thing should be able to be used unless the original actually uses close to 200 commands (yikes).<br/>
/// Primary Global goals used, XvT Secondary goals converted to Bonus goals. Prevent goals ignored.<br/>
/// Team[0] EndOfMissionMessages used, Teams[2-6] Name and Hostility towards Team[0] used for IFF.<br/>
/// BriefingQuestions generated using MissionSucc/Fail/Desc strings. Flight Officer has a single pre-mission entry for the Description, two post-mission entries for the Success and Fail. Line breaks must be entered manually.<br/>
/// Filename will end in "_TIE.tie".</remarks>
/// <param name="miss">XvT/BoP mission to convert.</param>
/// <returns>Downgraded mission.</returns>
/// <exception cref="ArgumentException">Properties incompatable with TIE95 were detected in <paramref name="miss"/>.</exception>
public static Tie.Mission XvtBopToTie(Xvt.Mission miss)
{
Tie.Mission tie = new Tie.Mission();
// FG limit is okay, since XvT < TIE for some reason
if (miss.Messages.Count > Tie.Mission.MessageLimit) throw maxException(true, false, Tie.Mission.MessageLimit);
tie.FlightGroups = new Tie.FlightGroupCollection(miss.FlightGroups.Count);
if (miss.Messages.Count > 0) tie.Messages = new Tie.MessageCollection(miss.Messages.Count);
#region FGs
for (int i = 0; i < tie.FlightGroups.Count; i++)
{
#region Craft
// Radio is omitted intentionally
tie.FlightGroups[i].Name = miss.FlightGroups[i].Name;
tie.FlightGroups[i].Cargo = miss.FlightGroups[i].Cargo;
tie.FlightGroups[i].SpecialCargo = miss.FlightGroups[i].SpecialCargo;
tie.FlightGroups[i].SpecialCargoCraft = miss.FlightGroups[i].SpecialCargoCraft;
tie.FlightGroups[i].RandSpecCargo = miss.FlightGroups[i].RandSpecCargo;
tie.FlightGroups[i].CraftType = Tie.Mission.CraftCheck(miss.FlightGroups[i].CraftType);
if (tie.FlightGroups[i].CraftType == 255) throw flightException(FlightExceptionMode.CraftType, i, Xvt.Strings.CraftType[miss.FlightGroups[i].CraftType]);
tie.FlightGroups[i].NumberOfCraft = miss.FlightGroups[i].NumberOfCraft;
tie.FlightGroups[i].Status1 = miss.FlightGroups[i].Status1;
tie.FlightGroups[i].Missile = miss.FlightGroups[i].Missile;
tie.FlightGroups[i].Beam = miss.FlightGroups[i].Beam;
tie.FlightGroups[i].IFF = miss.FlightGroups[i].IFF;
tie.FlightGroups[i].AI = miss.FlightGroups[i].AI;
if (tie.FlightGroups[i].AI > 4) tie.FlightGroups[i].AI = 4; //[JB] Jedi in XvT should be Top Ace in TIE, not invul.
tie.FlightGroups[i].Markings = miss.FlightGroups[i].Markings;
if (miss.FlightGroups[i].Formation > 12) throw flightException(FlightExceptionMode.Formation, i, BaseStrings.Formation[miss.FlightGroups[i].Formation]);
else tie.FlightGroups[i].Formation = miss.FlightGroups[i].Formation;
tie.FlightGroups[i].FormDistance = miss.FlightGroups[i].FormDistance;
tie.FlightGroups[i].GlobalGroup = miss.FlightGroups[i].GlobalGroup;
tie.FlightGroups[i].NumberOfWaves = miss.FlightGroups[i].NumberOfWaves;
tie.FlightGroups[i].PlayerCraft = (byte)(miss.FlightGroups[i].PlayerNumber == 1 ? miss.FlightGroups[i].PlayerCraft + 1 : 0); //[JB] Fixed player craft assignment. Check for XvT player slot #1 (not the craft slot). Then make sure the craft slot is non-zero (since XvT default is zero)
tie.FlightGroups[i].Yaw = miss.FlightGroups[i].Yaw;
tie.FlightGroups[i].Pitch = miss.FlightGroups[i].Pitch;
tie.FlightGroups[i].Roll = miss.FlightGroups[i].Roll;
#endregion Craft
#region ArrDep
tie.FlightGroups[i].Difficulty = miss.FlightGroups[i].Difficulty;
for (int j = 0; j < 3; j++)
{
try { tie.FlightGroups[i].ArrDepTriggers[j] = (Tie.Mission.Trigger)miss.FlightGroups[i].ArrDepTriggers[j]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] ArrDep[" + j + "]: " + x.Message, x); }
}
tie.FlightGroups[i].AT1OrAT2 = miss.FlightGroups[i].ArrDepAO[0];
tie.FlightGroups[i].ArrivalDelayMinutes = miss.FlightGroups[i].ArrivalDelayMinutes;
tie.FlightGroups[i].ArrivalDelaySeconds = miss.FlightGroups[i].ArrivalDelaySeconds;
tie.FlightGroups[i].DepartureTimerMinutes = miss.FlightGroups[i].DepartureTimerMinutes;
tie.FlightGroups[i].DepartureTimerSeconds = miss.FlightGroups[i].DepartureTimerSeconds;
if (miss.FlightGroups[i].AbortTrigger > 5) throw flightException(FlightExceptionMode.Abort, i, Xvt.Strings.Abort[miss.FlightGroups[i].AbortTrigger]);
else tie.FlightGroups[i].AbortTrigger = miss.FlightGroups[i].AbortTrigger;
tie.FlightGroups[i].ArrivalMothership = miss.FlightGroups[i].ArrivalMothership;
tie.FlightGroups[i].ArriveViaMothership = miss.FlightGroups[i].ArriveViaMothership;
tie.FlightGroups[i].AlternateMothership = miss.FlightGroups[i].AlternateMothership;
tie.FlightGroups[i].AlternateMothershipUsed = miss.FlightGroups[i].AlternateMothershipUsed;
tie.FlightGroups[i].DepartureMothership = miss.FlightGroups[i].DepartureMothership;
tie.FlightGroups[i].DepartViaMothership = miss.FlightGroups[i].DepartViaMothership;
tie.FlightGroups[i].CapturedDepartureMothership = miss.FlightGroups[i].CapturedDepartureMothership;
tie.FlightGroups[i].CapturedDepartViaMothership = miss.FlightGroups[i].CapturedDepartViaMothership;
#endregion ArrDep
#region Goals
if (miss.FlightGroups[i].Goals[0].GetEnabledForTeam(0))
{
tie.FlightGroups[i].Goals.PrimaryCondition = miss.FlightGroups[i].Goals[0].Condition;
tie.FlightGroups[i].Goals.PrimaryAmount = miss.FlightGroups[i].Goals[0].Amount;
if (miss.FlightGroups[i].Goals[0].Argument == 1 || miss.FlightGroups[i].Goals[0].Argument == 3) // must NOT or BONUS must NOT
{
if (miss.FlightGroups[i].Goals[0].Condition == (byte)Xvt.Mission.Trigger.ConditionList.Destroyed) tie.FlightGroups[i].Goals.PrimaryCondition = (byte)Tie.Mission.Trigger.ConditionList.Exist;
else throw new ArgumentException("Cannot convert \"must NOT\" Flightgroup Goal (FG: " + i + ")");
}
}
if (miss.FlightGroups[i].Goals[1].GetEnabledForTeam(0))
{
tie.FlightGroups[i].Goals.SecondaryCondition = miss.FlightGroups[i].Goals[1].Condition;
tie.FlightGroups[i].Goals.SecondaryAmount = miss.FlightGroups[i].Goals[1].Amount;
if (miss.FlightGroups[i].Goals[1].Argument == 1 || miss.FlightGroups[i].Goals[1].Argument == 3)
{
if (miss.FlightGroups[i].Goals[1].Condition == (byte)Xvt.Mission.Trigger.ConditionList.Destroyed) tie.FlightGroups[i].Goals.SecondaryCondition = (byte)Tie.Mission.Trigger.ConditionList.Exist;
else throw new ArgumentException("Cannot convert \"must NOT\" Flightgroup Goal (FG: " + i + ")");
}
}
if (miss.FlightGroups[i].Goals[2].GetEnabledForTeam(0))
{
tie.FlightGroups[i].Goals.BonusCondition = miss.FlightGroups[i].Goals[2].Condition;
tie.FlightGroups[i].Goals.BonusAmount = miss.FlightGroups[i].Goals[2].Amount;
tie.FlightGroups[i].Goals.RawBonusPoints = miss.FlightGroups[i].Goals[2].RawPoints;
if (miss.FlightGroups[i].Goals[2].Argument == 1 || miss.FlightGroups[i].Goals[2].Argument == 3)
{
if (miss.FlightGroups[i].Goals[2].Condition == (byte)Xvt.Mission.Trigger.ConditionList.Destroyed) tie.FlightGroups[i].Goals.BonusCondition = (byte)Tie.Mission.Trigger.ConditionList.Exist;
else throw new ArgumentException("Cannot convert \"must NOT\" Flightgroup Goal (FG: " + i + ")");
}
}
tieGoalsCheck("FlightGroup " + i, tie.FlightGroups[i].Goals);
#endregion Goals
for (int j = 0; j < 3; j++)
{
try { tie.FlightGroups[i].Orders[j] = (Tie.FlightGroup.Order)miss.FlightGroups[i].Orders[j]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] Order[" + j + "]: " + x.Message, x); }
}
for (int j = 0; j < 15; j++)
tie.FlightGroups[i].Waypoints[j] = miss.FlightGroups[i].Waypoints[j];
}
#endregion FGs
#region Messages
for (int i = 0; i < tie.Messages.Count; i++)
{
tie.Messages[i].MessageString = miss.Messages[i].MessageString;
tie.Messages[i].Color = miss.Messages[i].Color;
tie.Messages[i].RawDelay = miss.Messages[i].RawDelay;
tie.Messages[i].Short = miss.Messages[i].Note;
tie.Messages[i].Trig1OrTrig2 = miss.Messages[i].T1OrT2;
for (int j = 0; j < 2; j++)
{
try { tie.Messages[i].Triggers[j] = (Tie.Mission.Trigger)miss.Messages[i].Triggers[j]; }
catch (Exception x) { throw new ArgumentException("Mess[" + i + "] T[" + j + "]: " + x.Message, x); }
}
}
#endregion Messages
#region Briefing
for (int i = 0; i < tie.Briefing.BriefingTag.Length; i++) tie.Briefing.BriefingTag[i] = miss.Briefings[0].BriefingTag[i];
for (int i = 0; i < tie.Briefing.BriefingString.Length; i++) tie.Briefing.BriefingString[i] = miss.Briefings[0].BriefingString[i];
tie.Briefing.CurrentTime = miss.Briefings[0].CurrentTime;
tie.Briefing.Tile = miss.Briefings[0].Tile;
tie.Briefing.Length = tie.Briefing.ConvertSecondsToTicks(miss.Briefings[0].ConvertTicksToSeconds(miss.Briefings[0].Length));
for (int i = 0; i < miss.Briefings[0].Events.Count;)
{
var evt = miss.Briefings[0].Events[i];
if (evt.IsEndEvent) break;
short time = tie.Briefing.ConvertSecondsToTicks(miss.Briefings[0].ConvertTicksToSeconds(evt.Time));
var type = evt.Type;
tie.Briefing.Events.Add(new BaseBriefing.Event(type) { Time = time, Variables = (short[])evt.Variables.Clone() });
}
#endregion Briefing
#region Globals
tie.GlobalGoals.Goals[0].T1AndOrT2 = miss.Globals[0].Goals[0].T1OrT2; // Primary
tie.GlobalGoals.Goals[2].T1AndOrT2 = miss.Globals[0].Goals[2].T1OrT2; // Secondary to Bonus, Prevent will be ignored
for (int j = 0; j < 4; j++)
{
try { tie.GlobalGoals.Goals[j / 2 * 2].Triggers[j % 2] = (Tie.Mission.Trigger)miss.Globals[0].Goals[j / 2 * 2].Triggers[j % 2].GoalTrigger; }
catch (Exception x) { throw new ArgumentException("Goal[" + (j / 2 * 2) + "] T[" + (j % 2) + "]: " + x.Message, x); }
}
#endregion Globals
#region IFF/Team
for (int i = 0; i < 6; i++) tie.EndOfMissionMessages[i] = miss.Teams[0].EndOfMissionMessages[i];
for (int i = 2; i < 6; i++)
{
tie.IFFs[i] = miss.Teams[i].Name;
tie.IffHostile[i] = !miss.Teams[0].AlliedWithTeam[i];
}
#endregion IFF/Team
#region Questions
if (miss.MissionDescription != "")
{
tie.BriefingQuestions.PreMissQuestions[0] = "What are the mission objectives?";
tie.BriefingQuestions.PreMissAnswers[0] = miss.MissionDescription; // line breaks will have to be manually placed
}
if (miss.MissionSuccessful != "")
{
tie.BriefingQuestions.PostMissQuestions[0] = "What have I accomplished?";
tie.BriefingQuestions.PostMissAnswers[0] = miss.MissionSuccessful; // again, line breaks
tie.BriefingQuestions.PostTrigger[0] = Tie.Questions.QuestionCondition.Completed;
tie.BriefingQuestions.PostTrigType[0] = Tie.Questions.QuestionType.Primary;
}
if (miss.MissionFailed != "")
{
tie.BriefingQuestions.PostMissQuestions[1] = "Any suggestions?";
tie.BriefingQuestions.PostMissAnswers[1] = miss.MissionFailed; // again, line breaks
tie.BriefingQuestions.PostTrigger[1] = Tie.Questions.QuestionCondition.Failed;
tie.BriefingQuestions.PostTrigType[1] = Tie.Questions.QuestionType.Primary;
}
#endregion Questions
tie.MissionPath = miss.MissionPath.ToUpper().Replace(".TIE", "_TIE.tie");
return tie;
}
/// <summary>Upgrades TIE missions to XvT/BoP.</summary>
/// <remarks> FG.Radio is not converted, since TIE behaviour is different.<br/>
/// FG Primary and Bonus are used, Secondary Goal treated as Bonus. "must survive/exist" converted to "must NOT be destroyed". Bonus points will be scaled appropriately, 250 points assigned to Prim/Sec goals.<br/>
/// For the Briefing, entire thing should be able to be used. There is a conversion on the Zoom factor, this is a legacy factor from my old Converter program, I don't remember why.<br/>
/// Primary and Secondary Global goals used, Bonus goals converted to Secondary 3 and 4, T12AndOr34 left as default "And".<br/>
/// MissionSucc/Fail/Desc generated using Pre- and Post-briefing Questions.<br/>
/// Filename will end in "_XvT.tie" or "_BoP.tie", depending on <paramref name="bop"/>.</remarks>
/// <param name="miss">TIE mission to convert.</param>
/// <param name="bop">Determines if mission is to be converted to BoP instead of XvT.</param>
/// <returns>Upgraded mission.</returns>
public static Xvt.Mission TieToXvtBop(Tie.Mission miss, bool bop)
{
Xvt.Mission xvt = new Xvt.Mission { IsBop = bop };
if (miss.FlightGroups.Count > Xvt.Mission.FlightGroupLimit) throw maxException(false, true, Xvt.Mission.FlightGroupLimit);
xvt.FlightGroups = new Xvt.FlightGroupCollection(miss.FlightGroups.Count);
if (miss.Messages.Count > 0) xvt.Messages = new Xvt.MessageCollection(miss.Messages.Count);
#region FGs
// Before we can start processing FGs, we need to first determine if the player craft is Imperial or Rebel (probably Imp, but still)
bool playerIsImperial = true;
for (int i = 0; i < xvt.FlightGroups.Count; i++)
{
if (miss.FlightGroups[i].PlayerCraft != 0)
{
playerIsImperial = (miss.FlightGroups[i].IFF == 1);
break;
}
}
for (int i = 0; i < xvt.FlightGroups.Count; i++)
{
#region Craft
xvt.FlightGroups[i].Name = miss.FlightGroups[i].Name;
xvt.FlightGroups[i].Cargo = miss.FlightGroups[i].Cargo;
xvt.FlightGroups[i].SpecialCargo = miss.FlightGroups[i].SpecialCargo;
xvt.FlightGroups[i].RandSpecCargo = miss.FlightGroups[i].RandSpecCargo;
xvt.FlightGroups[i].CraftType = miss.FlightGroups[i].CraftType;
xvt.FlightGroups[i].NumberOfCraft = miss.FlightGroups[i].NumberOfCraft;
xvt.FlightGroups[i].Status1 = miss.FlightGroups[i].Status1;
xvt.FlightGroups[i].Missile = miss.FlightGroups[i].Missile;
xvt.FlightGroups[i].Beam = miss.FlightGroups[i].Beam;
xvt.FlightGroups[i].IFF = miss.FlightGroups[i].IFF;
switch (miss.FlightGroups[i].IFF)
{
// if player is Imperial, have to switch Team/IFF values, since Imps have to be Team 1 (0) and Rebs are Team 2 (1)
case 0:
if (playerIsImperial) xvt.FlightGroups[i].Team = 1;
else xvt.FlightGroups[i].Team = 0;
break;
case 1:
if (playerIsImperial) xvt.FlightGroups[i].Team = 0;
else xvt.FlightGroups[i].Team = 1;
break;
default:
xvt.FlightGroups[i].Team = miss.FlightGroups[i].IFF;
break;
}
xvt.FlightGroups[i].AI = miss.FlightGroups[i].AI;
xvt.FlightGroups[i].Markings = miss.FlightGroups[i].Markings;
xvt.FlightGroups[i].Formation = miss.FlightGroups[i].Formation;
xvt.FlightGroups[i].FormDistance = miss.FlightGroups[i].FormDistance;
xvt.FlightGroups[i].GlobalGroup = miss.FlightGroups[i].GlobalGroup;
xvt.FlightGroups[i].NumberOfWaves = miss.FlightGroups[i].NumberOfWaves;
if (miss.FlightGroups[i].PlayerCraft != 0)
{
xvt.FlightGroups[i].PlayerNumber = 1;
xvt.FlightGroups[i].PlayerCraft = (byte)(miss.FlightGroups[i].PlayerCraft - 1);
}
xvt.FlightGroups[i].Yaw = miss.FlightGroups[i].Yaw;
xvt.FlightGroups[i].Pitch = miss.FlightGroups[i].Pitch;
xvt.FlightGroups[i].Roll = miss.FlightGroups[i].Roll;
#endregion
#region ArrDep
xvt.FlightGroups[i].Difficulty = miss.FlightGroups[i].Difficulty;
for (int j = 0; j < 3; j++)
{
try { xvt.FlightGroups[i].ArrDepTriggers[j] = (Xvt.Mission.Trigger)miss.FlightGroups[i].ArrDepTriggers[j]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] ArrDep[" + j + "]: " + x.Message, x); }
}
xvt.FlightGroups[i].ArrDepAO[0] = miss.FlightGroups[i].AT1OrAT2;
xvt.FlightGroups[i].ArrivalDelayMinutes = miss.FlightGroups[i].ArrivalDelayMinutes;
xvt.FlightGroups[i].ArrivalDelaySeconds = miss.FlightGroups[i].ArrivalDelaySeconds;
xvt.FlightGroups[i].DepartureTimerMinutes = miss.FlightGroups[i].DepartureTimerMinutes;
xvt.FlightGroups[i].DepartureTimerSeconds = miss.FlightGroups[i].DepartureTimerSeconds;
xvt.FlightGroups[i].AbortTrigger = miss.FlightGroups[i].AbortTrigger;
xvt.FlightGroups[i].ArrivalMothership = miss.FlightGroups[i].ArrivalMothership;
xvt.FlightGroups[i].ArriveViaMothership = miss.FlightGroups[i].ArriveViaMothership;
xvt.FlightGroups[i].AlternateMothership = miss.FlightGroups[i].AlternateMothership;
xvt.FlightGroups[i].AlternateMothershipUsed = miss.FlightGroups[i].AlternateMothershipUsed;
xvt.FlightGroups[i].DepartureMothership = miss.FlightGroups[i].DepartureMothership;
xvt.FlightGroups[i].DepartViaMothership = miss.FlightGroups[i].DepartViaMothership;
xvt.FlightGroups[i].CapturedDepartureMothership = miss.FlightGroups[i].CapturedDepartureMothership;
xvt.FlightGroups[i].CapturedDepartViaMothership = miss.FlightGroups[i].CapturedDepartViaMothership;
#endregion
for (int j = 0; j < 3; j++)
{
try { xvt.FlightGroups[i].Orders[j] = (Xvt.FlightGroup.Order)miss.FlightGroups[i].Orders[j]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] Order[" + j + "]: " + x.Message, x); }
}
#region Goals
if (miss.FlightGroups[i].Goals.PrimaryCondition == (byte)Tie.Mission.Trigger.ConditionList.Exist)
{
xvt.FlightGroups[i].Goals[0].Argument = 1; // must NOT
xvt.FlightGroups[i].Goals[0].Condition = (byte)Xvt.Mission.Trigger.ConditionList.Destroyed;
}
else xvt.FlightGroups[i].Goals[0].Condition = miss.FlightGroups[i].Goals.PrimaryCondition;
if (miss.FlightGroups[i].Goals.PrimaryAmount == 1)
xvt.FlightGroups[i].Goals[0].Amount = (byte)Xvt.Mission.Trigger.AmountList.Percent50;
else if (miss.FlightGroups[i].Goals.PrimaryAmount >= 2)
xvt.FlightGroups[i].Goals[0].Amount = (byte)(miss.FlightGroups[i].Goals.PrimaryAmount + 2); // at least 1...
if (miss.FlightGroups[i].Goals.PrimaryCondition != (byte)Tie.Mission.Trigger.ConditionList.False && miss.FlightGroups[i].Goals.PrimaryCondition != (byte)Tie.Mission.Trigger.ConditionList.Exist)
xvt.FlightGroups[i].Goals[0].Points = 250;
if (miss.FlightGroups[i].Goals.PrimaryCondition != (byte)Tie.Mission.Trigger.ConditionList.False)
xvt.FlightGroups[i].Goals[0].SetEnabledForTeam(0, true);
if (miss.FlightGroups[i].Goals.SecondaryCondition == (byte)Tie.Mission.Trigger.ConditionList.Exist)
{
xvt.FlightGroups[i].Goals[1].Argument = 3; // BONUS must NOT
xvt.FlightGroups[i].Goals[1].Condition = (byte)Xvt.Mission.Trigger.ConditionList.Destroyed;
}
else
{
xvt.FlightGroups[i].Goals[1].Argument = 2; // BONUS must
xvt.FlightGroups[i].Goals[1].Condition = miss.FlightGroups[i].Goals.SecondaryCondition;
}
if (miss.FlightGroups[i].Goals.SecondaryAmount == 1)
xvt.FlightGroups[i].Goals[1].Amount = (byte)Xvt.Mission.Trigger.AmountList.Percent50;
else if (miss.FlightGroups[i].Goals.SecondaryAmount >= 2)
xvt.FlightGroups[i].Goals[1].Amount = (byte)(miss.FlightGroups[i].Goals.SecondaryAmount + 2); // at least 1...
if (miss.FlightGroups[i].Goals.SecondaryCondition != (byte)Tie.Mission.Trigger.ConditionList.False && miss.FlightGroups[i].Goals.SecondaryCondition != (byte)Tie.Mission.Trigger.ConditionList.Exist)
xvt.FlightGroups[i].Goals[1].Points = 250;
if (miss.FlightGroups[i].Goals.SecondaryCondition != (byte)Tie.Mission.Trigger.ConditionList.False)
xvt.FlightGroups[i].Goals[1].SetEnabledForTeam(0, true);
if (miss.FlightGroups[i].Goals.BonusCondition == (byte)Tie.Mission.Trigger.ConditionList.Exist)
{
xvt.FlightGroups[i].Goals[2].Argument = 3; // BONUS must NOT
xvt.FlightGroups[i].Goals[2].Condition = (byte)Xvt.Mission.Trigger.ConditionList.Destroyed;
}
else
{
xvt.FlightGroups[i].Goals[2].Argument = 2; // BONUS must
xvt.FlightGroups[i].Goals[2].Condition = miss.FlightGroups[i].Goals.BonusCondition;
}
if (miss.FlightGroups[i].Goals.BonusAmount == 1)
xvt.FlightGroups[i].Goals[2].Amount = (byte)Xvt.Mission.Trigger.AmountList.Percent50;
else if (miss.FlightGroups[i].Goals.BonusAmount >= 2)
xvt.FlightGroups[i].Goals[2].Amount = (byte)(miss.FlightGroups[i].Goals.BonusAmount + 2); // at least 1...
if (miss.FlightGroups[i].Goals.BonusCondition != (byte)Tie.Mission.Trigger.ConditionList.False && miss.FlightGroups[i].Goals.BonusCondition != (byte)Tie.Mission.Trigger.ConditionList.Exist)
xvt.FlightGroups[i].Goals[2].RawPoints = miss.FlightGroups[i].Goals.RawBonusPoints;
if (miss.FlightGroups[i].Goals.BonusCondition != (byte)Tie.Mission.Trigger.ConditionList.False)
xvt.FlightGroups[i].Goals[2].SetEnabledForTeam(0, true);
#endregion
for (int j = 0; j < 15; j++)
xvt.FlightGroups[i].Waypoints[j] = miss.FlightGroups[i].Waypoints[j];
}
#endregion
#region Messages
for (int i = 0; i < xvt.Messages.Count; i++)
{
xvt.Messages[i].MessageString = miss.Messages[i].MessageString;
xvt.Messages[i].Color = miss.Messages[i].Color;
xvt.Messages[i].RawDelay = miss.Messages[i].RawDelay;
xvt.Messages[i].Note = miss.Messages[i].Short;
xvt.Messages[i].T1OrT2 = miss.Messages[i].Trig1OrTrig2;
for (int j = 0; j < 2; j++)
{
try { xvt.Messages[i].Triggers[j] = (Xvt.Mission.Trigger)miss.Messages[i].Triggers[j]; }
catch (Exception x) { throw new ArgumentException("Mess[" + i + "] T[" + j + "]: " + x.Message, x); }
}
}
#endregion
#region Globals
xvt.Globals[0].Goals[0].Triggers[0].GoalTrigger = (Xvt.Mission.Trigger)miss.GlobalGoals.Goals[0].Triggers[0];
xvt.Globals[0].Goals[0].Triggers[1].GoalTrigger = (Xvt.Mission.Trigger)miss.GlobalGoals.Goals[0].Triggers[1];
xvt.Globals[0].Goals[0].T1OrT2 = miss.GlobalGoals.Goals[0].T1AndOrT2; // Primary
xvt.Globals[0].Goals[2].Triggers[0].GoalTrigger = (Xvt.Mission.Trigger)miss.GlobalGoals.Goals[1].Triggers[0];
xvt.Globals[0].Goals[2].Triggers[1].GoalTrigger = (Xvt.Mission.Trigger)miss.GlobalGoals.Goals[1].Triggers[1];
xvt.Globals[0].Goals[2].T1OrT2 = miss.GlobalGoals.Goals[1].T1AndOrT2; // Secondary
xvt.Globals[0].Goals[2].Triggers[2].GoalTrigger = (Xvt.Mission.Trigger)miss.GlobalGoals.Goals[2].Triggers[0];
xvt.Globals[0].Goals[2].Triggers[3].GoalTrigger = (Xvt.Mission.Trigger)miss.GlobalGoals.Goals[2].Triggers[1];
xvt.Globals[0].Goals[2].T3OrT4 = miss.GlobalGoals.Goals[2].T1AndOrT2; // Bonus as additional Secondary
#endregion
#region IFF/Team
xvt.Teams[0].Name = (playerIsImperial ? "Imperial" : "Rebel");
xvt.Teams[1].Name = (playerIsImperial ? "Rebel" : "Imperial");
for (int i = 2; i < 6; i++)
{
xvt.Teams[i].Name = miss.IFFs[i];
xvt.Teams[0].AlliedWithTeam[i] = !miss.IffHostile[i];
}
for (int i = 0; i < 6; i++) xvt.Teams[0].EndOfMissionMessages[i] = miss.EndOfMissionMessages[i];
#endregion
#region Briefing
for (int i = 0; i < xvt.Briefings[0].BriefingTag.Length; i++) xvt.Briefings[0].BriefingTag[i] = miss.Briefing.BriefingTag[i];
for (int i = 0; i < xvt.Briefings[0].BriefingString.Length; i++) xvt.Briefings[0].BriefingString[i] = miss.Briefing.BriefingString[i];
xvt.Briefings[0].CurrentTime = miss.Briefing.CurrentTime;
xvt.Briefings[0].Tile = miss.Briefing.Tile;
xvt.Briefings[0].Length = xvt.Briefings[0].ConvertSecondsToTicks(miss.Briefing.ConvertTicksToSeconds(miss.Briefing.Length));
for (int i = 0; i < miss.Briefing.Events.Count;)
{
var evt = miss.Briefing.Events[i];
if (evt.IsEndEvent) break;
short time = xvt.Briefings[0].ConvertSecondsToTicks(miss.Briefing.ConvertTicksToSeconds(evt.Time));
var type = evt.Type;
xvt.Briefings[0].Events.Add(new BaseBriefing.Event(type) { Time = time, Variables = (short[])evt.Variables.Clone() });
if (evt.Type == BaseBriefing.EventType.ZoomMap)
{
xvt.Briefings[0].Events[i].Variables[0] = (short)(xvt.Briefings[0].Events[i].Variables[0] * 58 / 47); // X
xvt.Briefings[0].Events[i].Variables[1] = (short)(xvt.Briefings[0].Events[i].Variables[1] * 88 / 47); // Y
}
}
#endregion
#region Questions
for (int i = 0; i < 10; i++)
{
if (miss.BriefingQuestions.PreMissQuestions[i].Length != 0)
{
if (xvt.MissionDescription != "") xvt.MissionDescription += "\r\n\r\n";
xvt.MissionDescription += miss.BriefingQuestions.PreMissQuestions[i] + "\r\n\r\n" + miss.BriefingQuestions.PreMissAnswers[i];
}
if (miss.BriefingQuestions.PostMissQuestions[i].Length != 0)
{
if (miss.BriefingQuestions.PostTrigger[i] == Tie.Questions.QuestionCondition.Completed)
{
if (xvt.MissionSuccessful != "") xvt.MissionSuccessful += "\r\n\r\n";
xvt.MissionSuccessful += miss.BriefingQuestions.PostMissQuestions[i] + "\r\n\r\n" + miss.BriefingQuestions.PostMissAnswers[i];
}
else if (miss.BriefingQuestions.PostTrigger[i] == Tie.Questions.QuestionCondition.Failed)
{
if (xvt.MissionFailed != "") xvt.MissionFailed += "\r\n\r\n";
xvt.MissionFailed += miss.BriefingQuestions.PostMissQuestions[i] + "\r\n\r\n" + miss.BriefingQuestions.PostMissAnswers[i];
}
}
}
#endregion
xvt.MissionPath = miss.MissionPath.ToUpper().Replace(".TIE", (bop ? "_BoP.tie" : "_XvT.tie"));
return xvt;
}
/// <summary>Upgrades TIE missions to XvT.</summary>
/// <remarks> FG.Radio is not converted, since TIE behaviour is different.<br/>
/// FG Primary and Bonus are used, Secondary Goal treated as Bonus. "must survive/exist" converted to "must NOT be destroyed". Bonus points will be scaled appropriately, 250 points assigned to Prim/Sec goals.<br/>
/// For the Briefing, entire thing should be able to be used. There is a conversion on the Zoom factor, this is a legacy factor from my old Converter program, I don't remember why.<br/>
/// Primary and Secondary Global goals used, Bonus goals converted to Secondary 3 and 4, T12AndOr34 left as default "And".<br/>
/// MissionDesc generated using Pre-briefing Questions.<br/>
/// Filename will end in "_XvT.tie".</remarks>
/// <param name="miss">TIE mission to convert.</param>
/// <returns>Upgraded mission.</returns>
public static Xvt.Mission TieToXvt(Tie.Mission miss) => TieToXvtBop(miss, false);
/// <summary>Upgrades TIE missions to BoP.</summary>
/// <remarks> FG.Radio is not converted, since TIE behaviour is different.<br/>
/// FG Primary and Bonus are used, Secondary Goal treated as Bonus. "must survive/exist" converted to "must NOT be destroyed". Bonus points will be scaled appropriately, 250 points assigned to Prim/Sec goals.<br/>
/// For the Briefing, entire thing should be able to be used. There is a conversion on the Zoom factor, this is a legacy factor from my old Converter program, I don't remember why.<br/>
/// Primary and Secondary Global goals used, Bonus goals converted to Secondary 3 and 4, T12AndOr34 left as default "And".<br/>
/// MissionSucc/Fail/Desc generated using Pre- and Post-briefing Questions.<br/>
/// Filename will end in "_BoP.tie".</remarks>
/// <param name="miss">TIE mission to convert.</param>
/// <returns>Upgraded mission.</returns>
public static Xvt.Mission TieToBop(Tie.Mission miss) => TieToXvtBop(miss, true);
/// <summary>Downgrades XWA missions to XvT and BoP.</summary>
/// <remarks>Maximum CraftType of 91. Triggers will update.<br/>
/// For Triggers, maximum Trigger index of 46, maximum VariableType of 23, Amounts will be adjusted as "each special" to "100% special".<br/>
/// Only Start and Hyp WPs converted, manual placement for WP1-8 required.<br/>
/// Arr/Dep Method1 type 2 (HYP to region of motherhsip) replaced with HYP.<br/>
/// For the Briefing, first 32 strings and text tags are copied, events are ignored (due to using icons instead of Craft).<br/>
/// Filename will end in "_XvT.tie" or "_.BoP.tie".</remarks>
/// <param name="miss">XWA mission to convert.</param>
/// <param name="bop">Determines if mission is to be converted to BoP instead of XvT.</param>
/// <returns>Downgraded mission.</returns>
/// <exception cref="ArgumentException">Properties incompatable with XvT/BoP were detected in <paramref name="miss"/>.</exception>
public static Xvt.Mission XwaToXvtBop(Xwa.Mission miss, bool bop)
{
Dictionary<byte, string> roleMap = new Dictionary<byte, string>
{
{0, "COM"},
{1, "BAS"},
{2, "STA"},
{3, "MIS"},
{4, "CON"},
{5, "STR"},
{6, "REL"},
{7, "PRI"},
{8, "SEC"},
{9, "TER"},
{10, "RES"},
{11, "MAN"},
{0xFF, "NON"}
};
Dictionary<byte, char> roleTeam = new Dictionary<byte, char>
{
{0, '1'},
{1, '2'},
{2, '3'},
{3, '4'},
{4, '5'},
{5, '6'},
{6, '7'},
{7, '8'},
{8, 'A'},
{9, 'O'},
{10, 'H'},
{11, 'F'}
};
Xvt.Mission xvt = new Xvt.Mission { IsBop = bop };
if (miss.FlightGroups.Count > Xvt.Mission.FlightGroupLimit) throw maxException(false, true, Xvt.Mission.FlightGroupLimit);
if (miss.Messages.Count > Xvt.Mission.MessageLimit) throw maxException(false, false, Xvt.Mission.MessageLimit);
xvt.FlightGroups = new Xvt.FlightGroupCollection(miss.FlightGroups.Count);
if (miss.Messages.Count > 0) xvt.Messages = new Xvt.MessageCollection(miss.Messages.Count);
xvt.MissionDescription = miss.MissionDescription;
xvt.MissionFailed = miss.MissionFailed;
xvt.MissionSuccessful = miss.MissionSuccessful;
#region FGs
for (int i = 0; i < xvt.FlightGroups.Count; i++)
{
#region craft
xvt.FlightGroups[i].Name = miss.FlightGroups[i].Name;
// default to team 1, overwrite if necessary
if (roleMap.TryGetValue(miss.FlightGroups[i].Designation1, out string role)) xvt.FlightGroups[i].Roles[0] = '1' + role;
else xvt.FlightGroups[i].Roles[0] = "1NON";
if (roleTeam.TryGetValue(miss.FlightGroups[i].EnableDesignation1, out char team)) xvt.FlightGroups[i].Roles[0] = team + xvt.FlightGroups[i].Roles[0].Substring(1);
if (roleMap.TryGetValue(miss.FlightGroups[i].Designation2, out role)) xvt.FlightGroups[i].Roles[1] = '1' + role;
else xvt.FlightGroups[i].Roles[1] = "1NON";
if (roleTeam.TryGetValue(miss.FlightGroups[i].EnableDesignation2, out team)) xvt.FlightGroups[i].Roles[1] = team + xvt.FlightGroups[i].Roles[1].Substring(1);
xvt.FlightGroups[i].Cargo = miss.FlightGroups[i].Cargo;
xvt.FlightGroups[i].SpecialCargo = miss.FlightGroups[i].SpecialCargo;
xvt.FlightGroups[i].SpecialCargoCraft = miss.FlightGroups[i].SpecialCargoCraft;
xvt.FlightGroups[i].RandSpecCargo = miss.FlightGroups[i].RandSpecCargo;
xvt.FlightGroups[i].CraftType = Xvt.Mission.CraftCheck(miss.FlightGroups[i].CraftType);
if (xvt.FlightGroups[i].CraftType == 255) throw flightException(FlightExceptionMode.CraftType, i, Xwa.Strings.CraftType[miss.FlightGroups[i].CraftType]);
xvt.FlightGroups[i].NumberOfCraft = miss.FlightGroups[i].NumberOfCraft;
if (xvt.FlightGroups[i].Status1 > 21) throw flightException(FlightExceptionMode.Status, i, Xwa.Strings.Status[miss.FlightGroups[i].Status1]);
xvt.FlightGroups[i].Status1 = miss.FlightGroups[i].Status1;
if (xvt.FlightGroups[i].Status2 > 21) throw flightException(FlightExceptionMode.Status, i, Xwa.Strings.Status[miss.FlightGroups[i].Status2]);
xvt.FlightGroups[i].Status2 = miss.FlightGroups[i].Status2;
xvt.FlightGroups[i].Missile = miss.FlightGroups[i].Missile;
xvt.FlightGroups[i].Beam = miss.FlightGroups[i].Beam;
xvt.FlightGroups[i].IFF = miss.FlightGroups[i].IFF;
xvt.FlightGroups[i].Team = miss.FlightGroups[i].Team;
xvt.FlightGroups[i].AI = miss.FlightGroups[i].AI;
xvt.FlightGroups[i].Markings = miss.FlightGroups[i].Markings;
xvt.FlightGroups[i].Radio = (Xvt.FlightGroup.RadioChannel)miss.FlightGroups[i].Radio;
xvt.FlightGroups[i].Formation = miss.FlightGroups[i].Formation;
xvt.FlightGroups[i].FormDistance = miss.FlightGroups[i].FormDistance;
xvt.FlightGroups[i].GlobalGroup = miss.FlightGroups[i].GlobalGroup;
xvt.FlightGroups[i].GlobalUnit = miss.FlightGroups[i].GlobalUnit;
xvt.FlightGroups[i].NumberOfWaves = miss.FlightGroups[i].NumberOfWaves;
xvt.FlightGroups[i].WavesDelay = miss.FlightGroups[i].WavesDelay;
xvt.FlightGroups[i].PlayerNumber = miss.FlightGroups[i].PlayerNumber;
xvt.FlightGroups[i].ArriveOnlyIfHuman = miss.FlightGroups[i].ArriveOnlyIfHuman;
xvt.FlightGroups[i].PlayerCraft = miss.FlightGroups[i].PlayerCraft;
xvt.FlightGroups[i].Countermeasures = (Xvt.FlightGroup.CounterTypes)miss.FlightGroups[i].Countermeasures;
xvt.FlightGroups[i].ExplosionTime = miss.FlightGroups[i].ExplosionTime;
xvt.FlightGroups[i].Yaw = miss.FlightGroups[i].Yaw;
xvt.FlightGroups[i].Pitch = miss.FlightGroups[i].Pitch;
xvt.FlightGroups[i].Roll = miss.FlightGroups[i].Roll;
#endregion craft
#region ArrDep
xvt.FlightGroups[i].Difficulty = miss.FlightGroups[i].Difficulty;
for (int j = 0; j < 6; j++)
{
try { xvt.FlightGroups[i].ArrDepTriggers[j] = (Xvt.Mission.Trigger)miss.FlightGroups[i].ArrDepTriggers[j]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] ArrDep[" + j + "]: " + x.Message, x); }
}
for (int j = 0; j < 4; j++) xvt.FlightGroups[i].ArrDepAO[j] = miss.FlightGroups[i].ArrDepAndOr[j];
xvt.FlightGroups[i].ArrivalDelayMinutes = miss.FlightGroups[i].ArrivalDelayMinutes;
xvt.FlightGroups[i].ArrivalDelaySeconds = miss.FlightGroups[i].ArrivalDelaySeconds;
xvt.FlightGroups[i].DepartureTimerMinutes = miss.FlightGroups[i].DepartureTimerMinutes;
xvt.FlightGroups[i].DepartureTimerSeconds = miss.FlightGroups[i].DepartureTimerSeconds;
xvt.FlightGroups[i].AbortTrigger = miss.FlightGroups[i].AbortTrigger;
xvt.FlightGroups[i].ArrivalMothership = miss.FlightGroups[i].ArrivalMothership;
xvt.FlightGroups[i].ArriveViaMothership = (miss.FlightGroups[i].ArriveViaMothership == 1);
xvt.FlightGroups[i].AlternateMothership = miss.FlightGroups[i].AlternateMothership;
xvt.FlightGroups[i].AlternateMothershipUsed = miss.FlightGroups[i].AlternateMothershipUsed;
xvt.FlightGroups[i].DepartureMothership = miss.FlightGroups[i].DepartureMothership;
xvt.FlightGroups[i].DepartViaMothership = (miss.FlightGroups[i].DepartViaMothership == 1);
xvt.FlightGroups[i].CapturedDepartureMothership = miss.FlightGroups[i].CapturedDepartureMothership;
xvt.FlightGroups[i].CapturedDepartViaMothership = miss.FlightGroups[i].CapturedDepartViaMothership;
#endregion ArrDep
#region Goals
for (int j = 0; j < 8; j++)
{
for (int k = 0; k < 6; k++) xvt.FlightGroups[i].Goals[j][k] = miss.FlightGroups[i].Goals[j][k];
if (xvt.FlightGroups[i].Goals[j].Condition > 46)
throw triggerException(BaseTrigger.TriggerIndex.Condition, "FG " + i + " Goal " + j, Xwa.Strings.Trigger[xvt.FlightGroups[i].Goals[j].Condition]);
if (xvt.FlightGroups[i].Goals[j].Amount == 19) xvt.FlightGroups[i].Goals[j].Amount = 6; // Each special craft -> Special craft
xvt.FlightGroups[i].Goals[j].IncompleteText = miss.FlightGroups[i].Goals[j].IncompleteText;
xvt.FlightGroups[i].Goals[j].CompleteText = miss.FlightGroups[i].Goals[j].CompleteText;
xvt.FlightGroups[i].Goals[j].FailedText = miss.FlightGroups[i].Goals[j].FailedText;
}
#endregion Goals
for (int j = 0; j < 4; j++)
{
try { xvt.FlightGroups[i].Orders[j] = (Xvt.FlightGroup.Order)miss.FlightGroups[i].Orders[0, j]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] Order[" + j + "]: " + x.Message, x); }
// need to adjust order times
}
xvt.FlightGroups[i].SkipToO4T1OrT2 = miss.FlightGroups[i].Orders[0, 3].SkipT1OrT2;
for (int j = 0; j < 2; j++)
{
try { xvt.FlightGroups[i].SkipToOrder4Trigger[j] = (Xvt.Mission.Trigger)miss.FlightGroups[i].Orders[0, 3].SkipTriggers[j]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] SkipT[" + j + "]: " + x.Message, x); }
}
for (int j = 0; j < 3; j++)
xvt.FlightGroups[i].Waypoints[j] = miss.FlightGroups[i].Waypoints[j].Clone();
xvt.FlightGroups[i].Waypoints[13] = miss.FlightGroups[i].Waypoints[3].Clone();
for (int j = 1; j < 9; j++) xvt.FlightGroups[i].OptLoadout[j] = miss.FlightGroups[i].OptLoadout[j];
for (int j = 10; j < 14; j++) xvt.FlightGroups[i].OptLoadout[j] = miss.FlightGroups[i].OptLoadout[j];
for (int j = 15; j < 18; j++) xvt.FlightGroups[i].OptLoadout[j] = miss.FlightGroups[i].OptLoadout[j];
xvt.FlightGroups[i].OptCraftCategory = (Xvt.FlightGroup.OptionalCraftCategory)miss.FlightGroups[i].OptCraftCategory;
for (int j = 0; j < 10; j++)
{
xvt.FlightGroups[i].OptCraft[j].CraftType = miss.FlightGroups[i].OptCraft[j].CraftType;
xvt.FlightGroups[i].OptCraft[j].NumberOfCraft = miss.FlightGroups[i].OptCraft[j].NumberOfCraft;
xvt.FlightGroups[i].OptCraft[j].NumberOfWaves = miss.FlightGroups[i].OptCraft[j].NumberOfWaves;
}
}
#endregion FGs
#region Messages
for (int i = 0; i < xvt.Messages.Count; i++)
{
xvt.Messages[i].MessageString = miss.Messages[i].MessageString;
xvt.Messages[i].Color = miss.Messages[i].Color;
int delay = Xwa.Mission.GetDelaySeconds(miss.Messages[i].RawDelay) / 5;
if (delay > 255) delay = 255;
xvt.Messages[i].RawDelay = (byte)delay;
xvt.Messages[i].Note = miss.Messages[i].Note;
xvt.Messages[i].T1OrT2 = miss.Messages[i].TrigAndOr[0];
xvt.Messages[i].T3OrT4 = miss.Messages[i].TrigAndOr[1];
xvt.Messages[i].T12OrT34 = miss.Messages[i].TrigAndOr[2];
for (int j = 0; j < 10; j++) xvt.Messages[i].SentToTeam[j] = miss.Messages[i].SentTo[j];
for (int j = 0; j < 4; j++)
{
try { xvt.Messages[i].Triggers[j] = (Xvt.Mission.Trigger)miss.Messages[i].Triggers[j]; }
catch (Exception x) { throw new ArgumentException("Mess[" + i + "] T[" + j + "]: " + x.Message, x); }
}
}
#endregion Messages
#region Briefing
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < xvt.Briefings[i].BriefingTag.Length; j++) xvt.Briefings[i].BriefingTag[j] = miss.Briefings[i].BriefingTag[j];
for (int j = 0; j < xvt.Briefings[i].BriefingString.Length; j++) xvt.Briefings[i].BriefingString[j] = miss.Briefings[i].BriefingString[j];
xvt.Briefings[i].CurrentTime = miss.Briefings[i].CurrentTime;
xvt.Briefings[i].Tile = miss.Briefings[i].Tile;
xvt.Briefings[i].Length = xvt.Briefings[i].ConvertSecondsToTicks(miss.Briefings[i].ConvertTicksToSeconds(miss.Briefings[i].Length));
}
#endregion Briefing
#region Globals
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 3; j++)
{
xvt.Globals[i].Goals[j].T1OrT2 = miss.Globals[i].Goals[j].T1AndOrT2;
xvt.Globals[i].Goals[j].T3OrT4 = miss.Globals[i].Goals[j].T3AndOrT4;
xvt.Globals[i].Goals[j].T12OrT34 = miss.Globals[i].Goals[j].T12AndOrT34;
for (int k = 0; k < 12; k++) xvt.Globals[i].Goals[j].Triggers[k / 3].GoalStrings[k % 3] = miss.Globals[i].Goals[j].GoalStrings[k / 3, k % 3];
xvt.Globals[i].Goals[j].RawPoints = miss.Globals[i].Goals[j].RawPoints;
for (int h = 0; h < 4; h++)
{
try { xvt.Globals[i].Goals[j].Triggers[h].GoalTrigger = (Xvt.Mission.Trigger)miss.Globals[i].Goals[j].Triggers[h]; }
catch (Exception x) { throw new ArgumentException("Team[" + i + "] Goal[" + j + "] T[" + h + "]: " + x.Message, x); }
}
}
}
#endregion Globals
#region Team
for (int i = 0; i < 10; i++)
{
xvt.Teams[i].Name = miss.Teams[i].Name;
for (int j = 0; j < 6; j++)
xvt.Teams[i].EndOfMissionMessages[j] = miss.Teams[i].EndOfMissionMessages[j];
for (int j = 0; j < 10; j++)
xvt.Teams[i].AlliedWithTeam[j] = (miss.Teams[i].Allies[j] == Xwa.Team.Allegeance.Friendly);
}
#endregion Team
xvt.MissionPath = miss.MissionPath.ToUpper().Replace(".TIE", "_XVT.tie");
return xvt;
}
/// <summary>Upgrades XvT and BoP missions to XWA.</summary>
/// <remarks>Defaults to <see cref="Xwa.Mission.HangarEnum.MonCalCruiser"/> hangar, if <paramref name="toSkirmish"/> and multiple player craft are detected then will use <see cref="Xwa.Mission.HangarEnum.Skirmish"/>.<br/>
/// If <paramref name="toSkirmish"/> is <b>false</b>, only converts first Briefing, Player craft is PlayerNumber 1.<br/>
/// Adds two Backdrops for lighting with random graphics.<br/>
/// Briefing creates icons for each FG used, should carry over fine. There is a conversion on the Zoom factor, this is a legacy factor from my old Converter program, I don't remember why.</remarks>
/// <param name="miss">XvT or BoP mission to convert.</param>
/// <param name="toSkirmish">If the converted mission is for a multiplayer skirmish.</param>
/// <returns>Upgraded mission.</returns>
public static Xwa.Mission XvtBopToXwa(Xvt.Mission miss, bool toSkirmish)
{
Dictionary<string, byte> roleMap = new Dictionary<string, byte> {
{"NON", 0xFF},
{"BAS", 1},
{"COM", 0},
{"CON", 4},
{"MAN", 11},
{"MIS", 3},
{"PRI", 7},
{"REL", 6},
{"RES", 10},
{"SEC", 8},
{"STA", 2},
{"STR", 5},
{"TER", 9}
};
Dictionary<char, byte> roleTeam = new Dictionary<char, byte>
{
{'1', 0},
{'2', 1},
{'3', 2},
{'4', 3},
{'5', 4},
{'6', 5},
{'7', 6},
{'8', 7},
{'A', 8},
{'F', 11},
{'H', 10},
{'O', 9},
};
Xwa.Mission xwa = new Xwa.Mission();
if (miss.Messages.Count > 0) xwa.Messages = new Xwa.MessageCollection(miss.Messages.Count);
xwa.FlightGroups = new Xwa.FlightGroupCollection(miss.FlightGroups.Count);
xwa.MissionDescription = miss.MissionDescription;
xwa.MissionFailed = miss.MissionFailed;
xwa.MissionSuccessful = miss.MissionSuccessful;
xwa.TimeLimitMin = miss.TimeLimitMin;
for (int i = 2; i < 6; i++) xwa.IFFs[i] = miss.IFFs[i];
#region Flightgroups
short[] briefShipCount = new short[2];
short[] fgIcons = new short[xwa.FlightGroups.Count];
int playerCount = 0;
for (int i = 0; i < xwa.FlightGroups.Count; i++)
{
#region craft
xwa.FlightGroups[i].Name = miss.FlightGroups[i].Name;
if (miss.FlightGroups[i].Roles[0].Length == 4)
{
if (roleMap.TryGetValue(miss.FlightGroups[i].Roles[0].Substring(1, 3), out byte role)) xwa.FlightGroups[i].Designation1 = role;
else xwa.FlightGroups[i].Designation1 = 255;
if (roleTeam.TryGetValue(miss.FlightGroups[i].Roles[0][0], out byte team)) xwa.FlightGroups[i].EnableDesignation1 = team;
else xwa.FlightGroups[i].EnableDesignation1 = 255;
}
if (miss.FlightGroups[i].Roles[1].Length == 4)
{
if (roleMap.TryGetValue(miss.FlightGroups[i].Roles[1].Substring(1, 3), out byte role)) xwa.FlightGroups[i].Designation2 = role;
else xwa.FlightGroups[i].Designation2 = 255;
if (roleTeam.TryGetValue(miss.FlightGroups[i].Roles[1][0], out byte team)) xwa.FlightGroups[i].EnableDesignation2 = team;
else xwa.FlightGroups[i].EnableDesignation2 = 255;
}
xwa.FlightGroups[i].Cargo = miss.FlightGroups[i].Cargo;
xwa.FlightGroups[i].SpecialCargo = miss.FlightGroups[i].SpecialCargo;
xwa.FlightGroups[i].SpecialCargoCraft = miss.FlightGroups[i].SpecialCargoCraft;
xwa.FlightGroups[i].RandSpecCargo = miss.FlightGroups[i].RandSpecCargo;
xwa.FlightGroups[i].CraftType = miss.FlightGroups[i].CraftType;
xwa.FlightGroups[i].NumberOfCraft = miss.FlightGroups[i].NumberOfCraft;
xwa.FlightGroups[i].Status1 = miss.FlightGroups[i].Status1;
xwa.FlightGroups[i].Status2 = miss.FlightGroups[i].Status2;
xwa.FlightGroups[i].Missile = miss.FlightGroups[i].Missile;
xwa.FlightGroups[i].Beam = miss.FlightGroups[i].Beam;
xwa.FlightGroups[i].IFF = miss.FlightGroups[i].IFF;
xwa.FlightGroups[i].Team = miss.FlightGroups[i].Team;
xwa.FlightGroups[i].AI = miss.FlightGroups[i].AI;
xwa.FlightGroups[i].Markings = miss.FlightGroups[i].Markings;
xwa.FlightGroups[i].Radio = (Xwa.FlightGroup.RadioChannel)miss.FlightGroups[i].Radio;
xwa.FlightGroups[i].Formation = miss.FlightGroups[i].Formation;
xwa.FlightGroups[i].FormDistance = miss.FlightGroups[i].FormDistance;
xwa.FlightGroups[i].GlobalGroup = miss.FlightGroups[i].GlobalGroup;
xwa.FlightGroups[i].GlobalUnit = miss.FlightGroups[i].GlobalUnit;
xwa.FlightGroups[i].NumberOfWaves = miss.FlightGroups[i].NumberOfWaves;
xwa.FlightGroups[i].WavesDelay = miss.FlightGroups[i].WavesDelay;
xwa.FlightGroups[i].PlayerNumber = miss.FlightGroups[i].PlayerNumber;
if (!toSkirmish && xwa.FlightGroups[i].PlayerNumber > 1) xwa.FlightGroups[i].PlayerNumber = 0;
if (xwa.FlightGroups[i].PlayerNumber > 0) playerCount++;
xwa.FlightGroups[i].ArriveOnlyIfHuman = miss.FlightGroups[i].ArriveOnlyIfHuman;
xwa.FlightGroups[i].PlayerCraft = miss.FlightGroups[i].PlayerCraft;
xwa.FlightGroups[i].Countermeasures = (Xwa.FlightGroup.CounterTypes)miss.FlightGroups[i].Countermeasures;
xwa.FlightGroups[i].ExplosionTime = miss.FlightGroups[i].ExplosionTime;
xwa.FlightGroups[i].Yaw = miss.FlightGroups[i].Yaw;
xwa.FlightGroups[i].Pitch = miss.FlightGroups[i].Pitch;
xwa.FlightGroups[i].Roll = miss.FlightGroups[i].Roll;
#endregion
#region Arr/Dep
xwa.FlightGroups[i].Difficulty = miss.FlightGroups[i].Difficulty;
for (int j = 0; j < 6; j++) xwa.FlightGroups[i].ArrDepTriggers[j] = miss.FlightGroups[i].ArrDepTriggers[j];
for (int j = 0; j < 4; j++) xwa.FlightGroups[i].ArrDepAndOr[j] = miss.FlightGroups[i].ArrDepAO[j];
xwa.FlightGroups[i].ArrivalDelayMinutes = miss.FlightGroups[i].ArrivalDelayMinutes;
xwa.FlightGroups[i].ArrivalDelaySeconds = miss.FlightGroups[i].ArrivalDelaySeconds;
xwa.FlightGroups[i].DepartureTimerMinutes = miss.FlightGroups[i].DepartureTimerMinutes;
xwa.FlightGroups[i].DepartureTimerSeconds = miss.FlightGroups[i].DepartureTimerSeconds;
xwa.FlightGroups[i].AbortTrigger = miss.FlightGroups[i].AbortTrigger;
xwa.FlightGroups[i].ArrivalMothership = miss.FlightGroups[i].ArrivalMothership;
xwa.FlightGroups[i].ArriveViaMothership = Convert.ToByte(miss.FlightGroups[i].ArriveViaMothership);
xwa.FlightGroups[i].AlternateMothership = miss.FlightGroups[i].AlternateMothership;
xwa.FlightGroups[i].AlternateMothershipUsed = miss.FlightGroups[i].AlternateMothershipUsed;
xwa.FlightGroups[i].DepartureMothership = miss.FlightGroups[i].DepartureMothership;
xwa.FlightGroups[i].DepartViaMothership = Convert.ToByte(miss.FlightGroups[i].DepartViaMothership);
xwa.FlightGroups[i].CapturedDepartureMothership = miss.FlightGroups[i].CapturedDepartureMothership;
xwa.FlightGroups[i].CapturedDepartViaMothership = miss.FlightGroups[i].CapturedDepartViaMothership;
#endregion
#region Orders
for (int j = 0; j < 4; j++)
{
xwa.FlightGroups[i].Orders[0, j] = miss.FlightGroups[i].Orders[j];
for (int k = 0; k < 8; k++) xwa.FlightGroups[i].Orders[0, j].Waypoints[k] = new Xwa.FlightGroup.XwaWaypoint(miss.FlightGroups[i].Waypoints[k + 4]);
}
xwa.FlightGroups[i].Orders[0, 3].SkipT1OrT2 = miss.FlightGroups[i].SkipToO4T1OrT2;
for (int j = 0; j < 2; j++) xwa.FlightGroups[i].Orders[0, 3].SkipTriggers[j] = miss.FlightGroups[i].SkipToOrder4Trigger[j];
#endregion
#region Goals
for (int j = 0; j < 8; j++)
{
for (int k = 0; k < 6; k++) xwa.FlightGroups[i].Goals[j][k] = miss.FlightGroups[i].Goals[j][k];
xwa.FlightGroups[i].Goals[j].IncompleteText = miss.FlightGroups[i].Goals[j].IncompleteText;
xwa.FlightGroups[i].Goals[j].CompleteText = miss.FlightGroups[i].Goals[j].CompleteText;
xwa.FlightGroups[i].Goals[j].FailedText = miss.FlightGroups[i].Goals[j].FailedText;
}
#endregion
for (int j = 0; j < 3; j++)
xwa.FlightGroups[i].Waypoints[j] = new Xwa.FlightGroup.XwaWaypoint(miss.FlightGroups[i].Waypoints[j]);
xwa.FlightGroups[i].Waypoints[3] = new Xwa.FlightGroup.XwaWaypoint(miss.FlightGroups[i].Waypoints[13]);
if (miss.FlightGroups[i].Waypoints[(int)Xvt.FlightGroup.WaypointIndex.Briefing1].Enabled)
{
xwa.Briefings[0].Events.Add(new BaseBriefing.Event(BaseBriefing.EventType.XwaSetIcon){ Variables = new short[] { briefShipCount[0], xwa.FlightGroups[i].CraftType, xwa.FlightGroups[i].IFF } });
xwa.Briefings[0].Events.Add(new BaseBriefing.Event(BaseBriefing.EventType.XwaSetIcon) { Variables = new short[] { briefShipCount[0], miss.FlightGroups[i].Waypoints[(int)Xvt.FlightGroup.WaypointIndex.Briefing1].RawX, (short)(miss.FlightGroups[i].Waypoints[(int)Xvt.FlightGroup.WaypointIndex.Briefing1].RawY * -1) } });
fgIcons[i] = briefShipCount[0]; // store the Icon# for the FG
briefShipCount[0]++;
}
if (toSkirmish && miss.FlightGroups[i].Waypoints[(int)Xvt.FlightGroup.WaypointIndex.Briefing2].Enabled)
{
xwa.Briefings[1].Events.Add(new BaseBriefing.Event(BaseBriefing.EventType.XwaSetIcon) { Variables = new short[] { briefShipCount[1], xwa.FlightGroups[i].CraftType, xwa.FlightGroups[i].IFF } });
xwa.Briefings[1].Events.Add(new BaseBriefing.Event(BaseBriefing.EventType.XwaSetIcon) { Variables = new short[] { briefShipCount[1], miss.FlightGroups[i].Waypoints[(int)Xvt.FlightGroup.WaypointIndex.Briefing2].RawX, (short)(miss.FlightGroups[i].Waypoints[(int)Xvt.FlightGroup.WaypointIndex.Briefing2].RawY * -1) } });
fgIcons[i] = briefShipCount[1]; // store the Icon# for the FG
briefShipCount[1]++;
}
for (int j = 1; j < 9; j++) xwa.FlightGroups[i].OptLoadout[j] = miss.FlightGroups[i].OptLoadout[j];
for (int j = 10; j < 14; j++) xwa.FlightGroups[i].OptLoadout[j] = miss.FlightGroups[i].OptLoadout[j];
for (int j = 15; j < 18; j++) xwa.FlightGroups[i].OptLoadout[j] = miss.FlightGroups[i].OptLoadout[j];
xwa.FlightGroups[i].OptCraftCategory = (Xwa.FlightGroup.OptionalCraftCategory)miss.FlightGroups[i].OptCraftCategory;
for (int j = 0; j < 10; j++)
{
xwa.FlightGroups[i].OptCraft[j].CraftType = miss.FlightGroups[i].OptCraft[j].CraftType;
xwa.FlightGroups[i].OptCraft[j].NumberOfCraft = miss.FlightGroups[i].OptCraft[j].NumberOfCraft;
xwa.FlightGroups[i].OptCraft[j].NumberOfWaves = miss.FlightGroups[i].OptCraft[j].NumberOfWaves;
}
}
xwa.FlightGroups.Add(new Xwa.FlightGroup());
xwa.FlightGroups[xwa.FlightGroups.Count - 1].CraftType = 0xB7;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Name = "1.0 1.0 1.0";
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Brightness = "1.0";
xwa.FlightGroups[xwa.FlightGroups.Count - 1].BackdropSize = "1.9";
xwa.FlightGroups[xwa.FlightGroups.Count - 1].IFF = 4;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Team = 9;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].GlobalGroup = 31;
Random rnd = new Random();
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Waypoints[0][rnd.Next(0, 2)] = 1;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Backdrop = (byte)rnd.Next(1, 59);
xwa.FlightGroups.Add(new Xwa.FlightGroup());
xwa.FlightGroups[xwa.FlightGroups.Count - 1].CraftType = 0xB7;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Name = "1.0 1.0 1.0";
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Brightness = "1.0";
xwa.FlightGroups[xwa.FlightGroups.Count - 1].BackdropSize = "1.0";
xwa.FlightGroups[xwa.FlightGroups.Count - 1].IFF = 4;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Team = 9;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].GlobalGroup = 31;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Waypoints[0][rnd.Next(0, 2)] = -1;
xwa.FlightGroups[xwa.FlightGroups.Count - 1].Backdrop = (byte)rnd.Next(63, 102);
#endregion
if (toSkirmish && playerCount > 1) xwa.MissionType = Xwa.Mission.HangarEnum.Skirmish;
#region Messages
for (int i = 0; i < xwa.Messages.Count; i++)
{
xwa.Messages[i].Color = miss.Messages[i].Color;
xwa.Messages[i].MessageString = miss.Messages[i].MessageString;
for (int j = 0; j < 10; j++) xwa.Messages[i].SentTo[j] = miss.Messages[i].SentToTeam[j];
for (int j = 0; j < 4; j++) xwa.Messages[i].Triggers[j] = miss.Messages[i].Triggers[j];
xwa.Messages[i].TrigAndOr[0] = miss.Messages[i].T1OrT2;
xwa.Messages[i].TrigAndOr[1] = miss.Messages[i].T3OrT4;
xwa.Messages[i].TrigAndOr[2] = miss.Messages[i].T12OrT34;
xwa.Messages[i].OriginatingFG = (byte)(xwa.FlightGroups.Count - 1);
int delay = miss.Messages[i].RawDelay * 5;
if (delay <= 20) xwa.Messages[i].RawDelay = (byte)delay;
else if (delay <= 15 * 60) xwa.Messages[i].RawDelay = (byte)(20 + (delay - 20) / 5);
else xwa.Messages[i].RawDelay = (byte)(((delay - 20) / 5 + 216) / 2);
}
#endregion
#region Globals
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 3; j++)
{
xwa.Globals[i].Goals[j].T1AndOrT2 = miss.Globals[i].Goals[j].T1OrT2;
xwa.Globals[i].Goals[j].T3AndOrT4 = miss.Globals[i].Goals[j].T3OrT4;
xwa.Globals[i].Goals[j].T12AndOrT34 = miss.Globals[i].Goals[j].T12OrT34;
for (int k = 0; k < 12; k++) xwa.Globals[i].Goals[j].GoalStrings[k / 3, k % 3] = miss.Globals[i].Goals[j].Triggers[k / 3].GoalStrings[k % 3];
xwa.Globals[i].Goals[j].RawPoints = miss.Globals[i].Goals[j].RawPoints;
for (int h = 0; h < 4; h++) xwa.Globals[i].Goals[j].Triggers[h] = miss.Globals[i].Goals[j].Triggers[h].GoalTrigger;
}
}
#endregion
#region Teams
for (int i = 0; i < 10; i++)
{
xwa.Teams[i].Name = miss.Teams[i].Name;
for (int j = 0; j < 6; j++)
xwa.Teams[i].EndOfMissionMessages[j] = miss.Teams[i].EndOfMissionMessages[j];
for (int j = 0; j < 10; j++)
xwa.Teams[i].Allies[j] = (miss.Teams[i].AlliedWithTeam[j] ? Xwa.Team.Allegeance.Friendly : Xwa.Team.Allegeance.Hostile);
}
#endregion
#region Briefing
for (int i = 0; i < 2; i++)
{
xwa.Briefings[i].Length = xwa.Briefings[i].ConvertSecondsToTicks(miss.Briefings[i].ConvertTicksToSeconds(miss.Briefings[i].Length));
xwa.Briefings[i].CurrentTime = miss.Briefings[i].CurrentTime;
xwa.Briefings[i].Tile = miss.Briefings[i].Tile;
for (int j = 0; j < miss.Briefings[i].Events.Count; j++)
{
var evt = miss.Briefings[i].Events[i];
if (evt.IsEndEvent) break;
short time = xwa.Briefings[0].ConvertSecondsToTicks(miss.Briefings[i].ConvertTicksToSeconds(evt.Time));
var type = evt.Type;
xwa.Briefings[0].Events.Add(new BaseBriefing.Event(type) { Time = time, Variables = (short[])evt.Variables.Clone() });
if (evt.Type == BaseBriefing.EventType.ZoomMap)
{
xwa.Briefings[0].Events[i].Variables[0] = (short)(xwa.Briefings[0].Events[i].Variables[0] * 124 / 88); // X
xwa.Briefings[0].Events[i].Variables[1] = (short)(xwa.Briefings[0].Events[i].Variables[1] * 124 / 88); // Y
}
else if (evt.IsFGTag) xwa.Briefings[i].Events[j].Variables[0] = fgIcons[xwa.Briefings[i].Events[j].Variables[0]];
}
for (int j = 0; j < 10; j++) xwa.Briefings[i].Team[j] = miss.Briefings[i].Team[j];
for (int j = 0; j < miss.Briefings[i].BriefingTag.Length; j++) xwa.Briefings[i].BriefingTag[j] = miss.Briefings[i].BriefingTag[j];
for (int j = 0; j < miss.Briefings[i].BriefingString.Length; j++) xwa.Briefings[i].BriefingString[j] = miss.Briefings[i].BriefingString[j];
if (!toSkirmish) break;
}