forked from MikeG621/Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converter.cs
2370 lines (2259 loc) · 145 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-2021 Michael Gaisser ([email protected])
* Licensed under the MPL v2.0 or later
*
* Full notice in ../help/Idmr.Platform.chm
* Version: 5.4
*/
/* CHANGELOG
* 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>Primarily handles downgrading of platforms, due to existing utilities for upgrading<br/>
/// 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). 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 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(4, i, Xwa.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(1, i, Xwa.Strings.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].FormLeaderDist = miss.FlightGroups[i].FormLeaderDist;
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].AT1AndOrAT2 = 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(2, i, Xwa.Strings.Abort[miss.FlightGroups[i].AbortTrigger]);
else tie.FlightGroups[i].AbortTrigger = miss.FlightGroups[i].AbortTrigger;
tie.FlightGroups[i].ArrivalCraft1 = miss.FlightGroups[i].ArrivalCraft1;
tie.FlightGroups[i].ArrivalMethod1 = miss.FlightGroups[i].ArrivalMethod1;
tie.FlightGroups[i].ArrivalCraft2 = miss.FlightGroups[i].ArrivalCraft2;
tie.FlightGroups[i].ArrivalMethod2 = miss.FlightGroups[i].ArrivalMethod2;
tie.FlightGroups[i].DepartureCraft1 = miss.FlightGroups[i].DepartureCraft1;
tie.FlightGroups[i].DepartureMethod1 = miss.FlightGroups[i].DepartureMethod1;
tie.FlightGroups[i].DepartureCraft2 = miss.FlightGroups[i].DepartureCraft2;
tie.FlightGroups[i].DepartureMethod2 = miss.FlightGroups[i].DepartureMethod2;
#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[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[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;
}
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].Delay = miss.Messages[i].Delay;
tie.Messages[i].Short = miss.Messages[i].Note;
tie.Messages[i].Trig1AndOrTrig2 = miss.Messages[i].T1AndOrT2;
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.Unknown1 = miss.Briefings[0].Unknown1;
tie.Briefing.Length = (short)(miss.Briefings[0].Length * Tie.Briefing.TicksPerSecond / Xvt.Briefing.TicksPerSecond);
for (int i = 0; i < tie.Briefing.Events.Length;)
{
short time = miss.Briefings[0].Events[i];
short evnt = miss.Briefings[0].Events[i + 1];
tie.Briefing.Events[i + 1] = evnt;
if (time == 9999 && evnt == 0x22)
{
tie.Briefing.Events[i] = time;
break;
}
tie.Briefing.Events[i] = (short)(time * Tie.Briefing.TicksPerSecond / Xvt.Briefing.TicksPerSecond);
i += 2;
for (int j = 0; j < tie.Briefing.EventParameterCount(evnt); j++, i++)
tie.Briefing.Events[i] = miss.Briefings[0].Events[i];
}
#endregion Briefing
#region Globals
tie.GlobalGoals.Goals[0].T1AndOrT2 = miss.Globals[0].Goals[0].T1AndOrT2; // Primary
tie.GlobalGoals.Goals[2].T1AndOrT2 = miss.Globals[0].Goals[2].T1AndOrT2; // 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] = 4;
tie.BriefingQuestions.PostTrigType[0] = 1;
}
if (miss.MissionFailed != "")
{
tie.BriefingQuestions.PostMissQuestions[1] = "Any suggestions?";
tie.BriefingQuestions.PostMissAnswers[1] = miss.MissionFailed; // again, line breaks
tie.BriefingQuestions.PostTrigger[1] = 5;
tie.BriefingQuestions.PostTrigType[1] = 1;
}
#endregion Questions
tie.MissionPath = miss.MissionPath.ToUpper().Replace(".TIE", "_TIE.tie");
return tie;
}
/// <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/>
/// 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)
{
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;
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(4, i, Xwa.Strings.CraftType[miss.FlightGroups[i].CraftType]);
xvt.FlightGroups[i].NumberOfCraft = miss.FlightGroups[i].NumberOfCraft;
if (xvt.FlightGroups[i].Status1 > 21) throw flightException(0, i, Xwa.Strings.Status[miss.FlightGroups[i].Status1]);
xvt.FlightGroups[i].Status1 = miss.FlightGroups[i].Status1;
if (xvt.FlightGroups[i].Status2 > 21) throw flightException(0, 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 = 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].FormLeaderDist = miss.FlightGroups[i].FormLeaderDist;
xvt.FlightGroups[i].NumberOfWaves = miss.FlightGroups[i].NumberOfWaves;
xvt.FlightGroups[i].Unknowns.Unknown1 = miss.FlightGroups[i].Unknowns.Unknown3;
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].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].ArrivalCraft1 = miss.FlightGroups[i].ArrivalCraft1;
xvt.FlightGroups[i].ArrivalMethod1 = miss.FlightGroups[i].ArrivalMethod1;
xvt.FlightGroups[i].ArrivalCraft2 = miss.FlightGroups[i].ArrivalCraft2;
xvt.FlightGroups[i].ArrivalMethod2 = miss.FlightGroups[i].ArrivalMethod2;
xvt.FlightGroups[i].DepartureCraft1 = miss.FlightGroups[i].DepartureCraft1;
xvt.FlightGroups[i].DepartureMethod1 = miss.FlightGroups[i].DepartureMethod1;
xvt.FlightGroups[i].DepartureCraft2 = miss.FlightGroups[i].DepartureCraft2;
xvt.FlightGroups[i].DepartureMethod2 = miss.FlightGroups[i].DepartureMethod2;
#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(0, "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;
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); }
}
xvt.FlightGroups[i].SkipToO4T1AndOrT2 = miss.FlightGroups[i].Orders[0, 3].SkipT1AndOrT2;
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] = (Xvt.FlightGroup.Waypoint)miss.FlightGroups[i].Waypoints[j];
xvt.FlightGroups[i].Waypoints[13] = (Xvt.FlightGroup.Waypoint)miss.FlightGroups[i].Waypoints[3];
}
#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 sec = miss.Messages[i].Delay;
if (sec > 20) sec = 20 + ((sec - 20) * 5);
if (sec > 1275) sec = 1275; //[JB] Maximum seconds in XvT when delay is 255.
xvt.Messages[i].Delay = (byte)(sec / 5); // should throw if delay > 21:15
xvt.Messages[i].Note = miss.Messages[i].Note;
xvt.Messages[i].T1AndOrT2 = miss.Messages[i].TrigAndOr[0];
xvt.Messages[i].T3AndOrT4 = miss.Messages[i].TrigAndOr[1];
xvt.Messages[i].T12AndOrT34 = 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].Unknown1 = miss.Briefings[i].Unknown1;
xvt.Briefings[i].Length = (short)(miss.Briefings[i].Length * Xvt.Briefing.TicksPerSecond / Xwa.Briefing.TicksPerSecond);
}
#endregion Briefing
#region Globals
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 3; j++)
{
xvt.Globals[i].Goals[j].T1AndOrT2 = miss.Globals[i].Goals[j].T1AndOrT2;
xvt.Globals[i].Goals[j].T3AndOrT4 = miss.Globals[i].Goals[j].T3AndOrT4;
xvt.Globals[i].Goals[j].T12AndOrT34 = 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>Downgrades XWA 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 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 Region 1 Orders used, max index of 38.<br/>
/// Only Start and Hyp WPs converted, manual placement for WP1-8 required.<br/>
/// For Messages, first two triggers used.<br/>
/// For the Briefing, first 16 strings and text tags are copied, events are ignored (due to using icons instead of Craft)<br/>
/// Primary Global goals used, XWA 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">XWA 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 XwaToTie(Xwa.Mission miss)
{
Tie.Mission tie = new Tie.Mission();
if (miss.FlightGroups.Count > Tie.Mission.FlightGroupLimit) throw maxException(true, true, Tie.Mission.FlightGroupLimit);
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(4, i, Xwa.Strings.CraftType[miss.FlightGroups[i].CraftType]);
tie.FlightGroups[i].NumberOfCraft = miss.FlightGroups[i].NumberOfCraft;
tie.FlightGroups[i].Status1 = miss.FlightGroups[i].Status1;
if (tie.FlightGroups[i].Status1 > 19) throw flightException(0, i, Xwa.Strings.Status[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] Super Ace in XWA should be Top Ace in TIE, not invul.
tie.FlightGroups[i].Markings = miss.FlightGroups[i].Markings;
if (miss.FlightGroups[i].Formation > 12) throw flightException(1, i, Xwa.Strings.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].FormLeaderDist = miss.FlightGroups[i].FormLeaderDist;
tie.FlightGroups[i].NumberOfWaves = miss.FlightGroups[i].NumberOfWaves;
tie.FlightGroups[i].PlayerCraft = (byte)(miss.FlightGroups[i].PlayerCraft + (miss.FlightGroups[i].PlayerNumber == 1 ? 1 : 0));
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 == 2 ? 4 : j)]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] ArrDep[" + j + "]: " + x.Message, x); }
}
tie.FlightGroups[i].AT1AndOrAT2 = miss.FlightGroups[i].ArrDepAndOr[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(2, i, Xwa.Strings.Abort[miss.FlightGroups[i].AbortTrigger]);
else tie.FlightGroups[i].AbortTrigger = miss.FlightGroups[i].AbortTrigger;
tie.FlightGroups[i].ArrivalCraft1 = miss.FlightGroups[i].ArrivalCraft1;
tie.FlightGroups[i].ArrivalMethod1 = miss.FlightGroups[i].ArrivalMethod1;
tie.FlightGroups[i].ArrivalCraft2 = miss.FlightGroups[i].ArrivalCraft2;
tie.FlightGroups[i].ArrivalMethod2 = miss.FlightGroups[i].ArrivalMethod2;
tie.FlightGroups[i].DepartureCraft1 = miss.FlightGroups[i].DepartureCraft1;
tie.FlightGroups[i].DepartureMethod1 = miss.FlightGroups[i].DepartureMethod1;
tie.FlightGroups[i].DepartureCraft2 = miss.FlightGroups[i].DepartureCraft2;
tie.FlightGroups[i].DepartureMethod2 = miss.FlightGroups[i].DepartureMethod2;
#endregion ArrDep
#region Goals
if (miss.FlightGroups[i].Goals[0].Enabled && miss.FlightGroups[i].Goals[0].Team == 0)
{
tie.FlightGroups[i].Goals[0] = miss.FlightGroups[i].Goals[0][1];
tie.FlightGroups[i].Goals[1] = miss.FlightGroups[i].Goals[0][2];
}
if (miss.FlightGroups[i].Goals[1].Enabled && miss.FlightGroups[i].Goals[1].Team == 0)
{
tie.FlightGroups[i].Goals[2] = miss.FlightGroups[i].Goals[1][1];
tie.FlightGroups[i].Goals[3] = miss.FlightGroups[i].Goals[1][2];
}
if (miss.FlightGroups[i].Goals[2].Enabled && miss.FlightGroups[i].Goals[2].Team == 0)
{
tie.FlightGroups[i].Goals[6] = miss.FlightGroups[i].Goals[2][1];
tie.FlightGroups[i].Goals[7] = miss.FlightGroups[i].Goals[2][2];
tie.FlightGroups[i].Goals[8] = miss.FlightGroups[i].Goals[2][3];
}
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[0, j]; }
catch (Exception x) { throw new ArgumentException("FG[" + i + "] Order[" + j + "]: " + x.Message, x); }
}
for (int j = 0; j < 3; j++)
tie.FlightGroups[i].Waypoints[j] = (Tie.FlightGroup.Waypoint)miss.FlightGroups[i].Waypoints[j];
tie.FlightGroups[i].Waypoints[13] = (Tie.FlightGroup.Waypoint)miss.FlightGroups[i].Waypoints[3];
}
#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;
int sec = miss.GetDelaySeconds(miss.Messages[i].Delay);
if (sec > 1275) sec = 1275; //[JB] Maximum seconds in TIE when delay is 255.
tie.Messages[i].Delay = (byte)(sec / 5); // should throw if delay > 21:15
tie.Messages[i].Short = miss.Messages[i].Note;
tie.Messages[i].Trig1AndOrTrig2 = miss.Messages[i].TrigAndOr[0];
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.Unknown1 = miss.Briefings[0].Unknown1;
tie.Briefing.Length = (short)(miss.Briefings[0].Length * Tie.Briefing.TicksPerSecond / Xwa.Briefing.TicksPerSecond);
#endregion Briefing
#region Globals
tie.GlobalGoals.Goals[0].T1AndOrT2 = miss.Globals[0].Goals[0].T1AndOrT2; // Primary
tie.GlobalGoals.Goals[2].T1AndOrT2 = miss.Globals[0].Goals[2].T1AndOrT2; // 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]; }
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] = ((int)miss.Teams[0].Allies[i] == 0);
}
#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] = 4;
tie.BriefingQuestions.PostTrigType[0] = 1;
}
if (miss.MissionFailed != "")
{
tie.BriefingQuestions.PostMissQuestions[1] = "Any suggestions?";
tie.BriefingQuestions.PostMissAnswers[1] = miss.MissionFailed; // again, line breaks
tie.BriefingQuestions.PostTrigger[1] = 5;
tie.BriefingQuestions.PostTrigType[1] = 1;
}
#endregion Questions
tie.MissionPath = miss.MissionPath.ToUpper().Replace(".TIE", "_TIE.tie");
return tie;
}
/// <summary>Upgrades XWING95 missions to TIE95</summary>
/// <remarks>Attempts to convert Name, Cargo, and SpecialCargo strings from uppercase to initial-case only.<br/>
/// Maximum FG.Formation value of 12 allowed.<br/>
/// XWING95 has 3 EndOfMissionMessages, but TIE95 only supports 2. The last is converted into a Message.<br/>
/// XWING95's TIE Bombers have both torpedoes and missiles. Its targets are examined to give it missiles or torpedoes as appropriate.<br/>
/// XWING95's arrival condition "must be Destroyed" does not actually require all 100% to be destroyed (requires at least one, the rest come and go). For TIE Fighter it uses 100%, as it lacks XvT's "come and go" condition.<br/>
/// Some orders perform "autotargeting" based on craft type. This aspect isn't easily replicated, but is simulated as best it can with additional target slots, plus additional order slots.<br/>
/// SS Hold Position does not have an equivalent, since it autotargets and does not wait to return fire. Tries to simulate as best it can with SS Await Launch (works for capital ships) and follows up with two SS Wait orders (with maximum time).<br/>
/// SS orders in TIE95 don't seem to use Target3 or Target4. Attempts to work around this by moving the autotargets into Target1 and Target2 if primary or secondary target is not used, but may not always be reliable.<br/>
/// Attempts to allow converting of custom missions, does not assume the player is IFF Rebel.<br/>
/// Radio is automatically assigned to same-IFF fighters, transports, shuttles, and tugs.<br/>
/// BriefingQuestions generated from text-only pages in the briefing. Flight Officer will have pre-mission questions, and post-mission Fail questions based off the briefing's hint pages.<br/>
/// Briefing waypoints are estimated by scanning the separate "Briefing FG" list for the most likely match. If none are found, dummy FGs are inserted to provide icons for the briefing map.<br/>
/// Briefing text tags do not have colors. Converted to white since it's the closest match to light blue.<br/>
/// Filename will end in "_TIE.tie"</remarks>
/// <param name="miss">XWING95 mission to convert</param>
/// <returns>Upgraded mission</returns>
/// <exception cref="ArgumentException">Properties incompatable with TIE95 were detected in <paramref name="miss"/></exception>
public static Tie.Mission XwingToTie(Xwing.Mission miss)
{
Tie.Mission tie = new Tie.Mission
{
FlightGroups = new Tie.FlightGroupCollection(miss.FlightGroups.Count)
};
#region Mission
int playerIFF = 0; //Need to find the player to determine how to set up radio orders. We'll do it this way if for some reason a custom mission is set up otherwise.
foreach (var fg in miss.FlightGroups)
{
if (fg.PlayerCraft > 0)
{
playerIFF = fg.GetTIEIFF();
break;
}
}
byte color = (byte)playerIFF;
if (color == 0) color = 1; //In TIE, IFF Rebel is 0 but Color 0 is Red.
else if (color == 1) color = 0;
tie.EndOfMissionMessages[0] = (color > 0 ? color.ToString() : "") + miss.EndOfMissionMessages[0]; //X-wing has 3 messages, XvT has two. Prefix with color codes.
tie.EndOfMissionMessages[1] = (color > 0 ? color.ToString() : "") + miss.EndOfMissionMessages[1];
if (miss.EndOfMissionMessages[2] != "")
{
Tie.Message msg = new Tie.Message
{
MessageString = miss.EndOfMissionMessages[2],
Color = color,
Delay = 1 // 5 sec
};
msg.Triggers[0].Amount = 0;
msg.Triggers[0].VariableType = 5; //IFF
msg.Triggers[0].Variable = 0;
msg.Triggers[0].Condition = 13; //complete primary mission
tie.Messages.Add(msg);
}
//Not doing mission time.
#endregion Mission
#region FGs
//List<XwingGlobalGroup> ggList = new List<XwingGlobalGroup>();
for (int i = 0; i < miss.FlightGroups.Count; i++)
{
#region Craft
tie.FlightGroups[i].Name = xwingCaseConversion(miss.FlightGroups[i].Name);
tie.FlightGroups[i].Cargo = xwingCaseConversion(miss.FlightGroups[i].Cargo);
tie.FlightGroups[i].SpecialCargo = xwingCaseConversion(miss.FlightGroups[i].SpecialCargo);
int spec = miss.FlightGroups[i].SpecialCargoCraft + 1; //X-wing special craft number is zero-based. Out of bounds indicating no craft.
if (spec < 0 || tie.FlightGroups[i].SpecialCargo == "") spec = 0;
else if (spec > miss.FlightGroups[i].NumberOfCraft)
spec = 0;
tie.FlightGroups[i].SpecialCargoCraft = (byte)spec;
tie.FlightGroups[i].RandSpecCargo = miss.FlightGroups[i].RandSpecCargo;
tie.FlightGroups[i].CraftType = (byte)miss.FlightGroups[i].GetTIECraftType();
if (tie.FlightGroups[i].CraftType == 255) throw flightException(4, i, Xwing.Strings.CraftType[miss.FlightGroups[i].CraftType]);
if (miss.FlightGroups[i].IsObjectGroup())
{
tie.FlightGroups[i].Pitch = miss.FlightGroups[i].Pitch;
tie.FlightGroups[i].Yaw = miss.FlightGroups[i].Yaw;
tie.FlightGroups[i].Roll = miss.FlightGroups[i].Roll;
}
tie.FlightGroups[i].NumberOfCraft = miss.FlightGroups[i].NumberOfCraft;
if (tie.FlightGroups[i].NumberOfCraft > 9)
tie.FlightGroups[i].NumberOfCraft = 9;
tie.FlightGroups[i].FollowsOrders = (xwingPlayerCommand(miss.FlightGroups[i].CraftType) && miss.FlightGroups[i].GetTIEIFF() == playerIFF);
byte warhead = 0;
switch (miss.FlightGroups[i].CraftType)
{
case 1: //X-W
case 2: //Y-W/B-W
case 6: //T/B
case 8: //TRN
warhead = 4; //Torpedo
break;
case 3: //A-W
case 7: //GUN
warhead = 3; //Missile
break;
}
//Special case for the T/B. In X-wing they carry both missiles and torpedoes. We need to check their orders and targets to see if they'll be attacking fighters or larger craft, and choose accordingly.
if (miss.FlightGroups[i].CraftType == 6)
{
int tPri = miss.FlightGroups[i].TargetPrimary;
int tSec = miss.FlightGroups[i].TargetSecondary;
int tcPri = (tPri >= 0 && tPri < miss.FlightGroups.Count) ? miss.FlightGroups[tPri].CraftType : 0;
int tcSec = (tSec >= 0 && tSec < miss.FlightGroups.Count) ? miss.FlightGroups[tSec].CraftType : 0;
bool tfPri = (tcPri >= 0 && tcPri <= 7) || (tcPri == 17); //Include None as a fighter for the sake of simplicity
bool tfSec = (tcSec >= 0 && tcSec <= 7) || (tcSec == 17);
if (!tfPri || !tfSec)
warhead = 4;
else
{
int orders = miss.FlightGroups[i].Order;
if (orders >= 0x14 && orders <= 0x19) //Attack Transports, Freighters, Starship, Disable Transports, Freighters, Starship
warhead = 4;
else //Everything else, assuming fighters as default targets since no non-fighters specifically targeted
warhead = 3;
}
}
tie.FlightGroups[i].Missile = warhead;
byte status = (byte)(miss.FlightGroups[i].Status1 % 10); //Get the actual status, just in case it's a Y-wing turned B-wing.
if (status == 1)
{
status = 0; //In X-wing this is for No Warheads, but in TIE it double's warheads. Take away warheads instead.
tie.FlightGroups[i].Missile = 0;
}
tie.FlightGroups[i].Status1 = status;
if (tie.FlightGroups[i].Status1 >= 5) tie.FlightGroups[i].Status1 = 0; //Replace unknown/unused with default status.
tie.FlightGroups[i].IFF = miss.FlightGroups[i].GetTIEIFF();
tie.FlightGroups[i].AI = miss.FlightGroups[i].AI;
tie.FlightGroups[i].Markings = miss.FlightGroups[i].Markings;
if (miss.FlightGroups[i].IsFlightGroup())
{
if (miss.FlightGroups[i].Formation > 12) throw flightException(1, i, Xwing.Strings.Formation[miss.FlightGroups[i].Formation]);
else tie.FlightGroups[i].Formation = miss.FlightGroups[i].Formation;
}
else
{
tie.FlightGroups[i].Formation = (byte)(miss.FlightGroups[i].Formation & 0x3); //Bits 1 and 2 are formation.
}
tie.FlightGroups[i].NumberOfWaves = Convert.ToByte(miss.FlightGroups[i].NumberOfWaves + 1); //XWING95 editor was modified to use raw data, TIE editor does not
tie.FlightGroups[i].PlayerCraft = miss.FlightGroups[i].PlayerCraft;
//tie.FlightGroups[i].Yaw = miss.FlightGroups[i].Yaw; //Handled with objects
//tie.FlightGroups[i].Pitch = miss.FlightGroups[i].Pitch;
//tie.FlightGroups[i].Roll = miss.FlightGroups[i].Roll;
#endregion Craft
#region ArrDep
tie.FlightGroups[i].Difficulty = 0; //All
Tie.Mission.Trigger arr = tie.FlightGroups[i].ArrDepTriggers[0];
arr.Amount = 0;
arr.Condition = Convert.ToByte(miss.FlightGroups[i].ArrivalEvent);
if (arr.Condition == 6) //"Disabled" condition has a different ID in TIE
arr.Condition = 8;
if (miss.FlightGroups[i].ArrivalFG >= 0)
{
arr.VariableType = 1;
arr.Variable = (byte)miss.FlightGroups[i].ArrivalFG;
}
else
{
arr.VariableType = 0;
arr.Variable = 0;
arr.Condition = 0;
}
if (arr.VariableType == 1 && arr.Condition == 0 && arr.Variable == 0) //Replace with always (TRUE)
arr.VariableType = 0;
if (arr.Condition != 2) //All conditions except Destroyed trigger when "at least one" fulfills the condition. Destroyed requires at least one, and the rest to "come and go" (like XvT and XWA) but TIE doesn't have that.
{
arr.Amount = 4; //At least one
int fg = miss.FlightGroups[i].ArrivalFG;
if (arr.VariableType == 1 && fg >= 0 && fg < miss.FlightGroups.Count)
if (miss.FlightGroups[fg].NumberOfWaves == 0 && miss.FlightGroups[fg].NumberOfCraft == 1)
arr.Amount = 0; //But if the craft only has 1 wave of 1 ship, go ahead and call it 100% to make it more intuitive.
}
tie.FlightGroups[i].ArrivalDelayMinutes = (byte)miss.FlightGroups[i].GetArrivalMinutes();
tie.FlightGroups[i].ArrivalDelaySeconds = (byte)miss.FlightGroups[i].GetArrivalSeconds();
tie.FlightGroups[i].DepartureTimerMinutes = 0;
tie.FlightGroups[i].DepartureTimerSeconds = 0;
tie.FlightGroups[i].AbortTrigger = 0;
tie.FlightGroups[i].ArrivalCraft1 = (byte)(miss.FlightGroups[i].Mothership >= 0 ? miss.FlightGroups[i].Mothership : 0);
tie.FlightGroups[i].ArrivalMethod1 = !(miss.FlightGroups[i].ArrivalHyperspace == 1); //Note: X-wing uses true to arrive from hyperspace, TIE uses false
tie.FlightGroups[i].ArrivalCraft2 = 0;
tie.FlightGroups[i].ArrivalMethod2 = false;
tie.FlightGroups[i].DepartureCraft1 = (byte)(miss.FlightGroups[i].Mothership >= 0 ? miss.FlightGroups[i].Mothership : 0);
tie.FlightGroups[i].DepartureMethod1 = !(miss.FlightGroups[i].DepartureHyperspace == 1);
tie.FlightGroups[i].DepartureCraft2 = 0;
tie.FlightGroups[i].DepartureMethod2 = false;
if (miss.FlightGroups[i].Mothership == -1) //Set defaults to Hyperspace if no mothership is set
{
tie.FlightGroups[i].ArrivalMethod1 = false;
tie.FlightGroups[i].DepartureMethod1 = false;
}
//Fighters in TIE will auto abort at 25% hull, like X-wing.
#endregion ArrDep
#region Goals
if (miss.FlightGroups[i].IsFlightGroup())
{
if (miss.FlightGroups[i].Objective != 0)
{
byte cond = 0;
byte amount = 0;
switch (miss.FlightGroups[i].Objective)
{
// Reminder: Goal amounts for TIE doesn't use normal trigger values
case 0: cond = 0; amount = 0; break; //none (XWING95 goal conditions)
case 1: cond = 2; amount = 0; break; //100% destroyed
case 2: cond = 12; amount = 0; break; //100% complete mission
case 3: cond = 4; amount = 0; break; //100% captured
case 4: cond = 6; amount = 0; break; //100% be boarded
case 5: cond = 2; amount = 4; break; //special craft destroyed
case 6: cond = 12; amount = 4; break; //special craft complete mission
case 7: cond = 4; amount = 4; break; //special craft captured
case 8: cond = 6; amount = 4; break; //special craft be boarded
case 9: cond = 2; amount = 1; break; //50% destroyed
case 10: cond = 12; amount = 1; break; //50% complete mission
case 11: cond = 4; amount = 1; break; //50% captured
case 12: cond = 6; amount = 1; break; //50% be boarded
case 13: cond = 5; amount = 0; break; //100% inspected
case 14: cond = 5; amount = 4; break; //special craft inspected
case 15: cond = 5; amount = 1; break; //50% inspected
case 16: cond = 1; amount = 0; break; //100% arrive
}
tie.FlightGroups[i].Goals.PrimaryCondition = cond;
tie.FlightGroups[i].Goals.PrimaryAmount = amount;
}
}
else //For objects...
{
if (!miss.FlightGroups[i].IsTrainingPlatform())
{
byte cond = 0;
if ((miss.FlightGroups[i].Formation & 0x4) > 0) cond = 2; //must be destroyed
else if ((miss.FlightGroups[i].Formation & 0x8) > 0) cond = 9; //must survive
tie.FlightGroups[i].Goals.PrimaryCondition = cond;
tie.FlightGroups[i].Goals.PrimaryAmount = 0; //100%
}
}
#endregion Goals
#region Orders
int thisIFF = tie.FlightGroups[i].IFF;
byte oppositeIFF = (byte)((thisIFF % 2 == 0) ? thisIFF + 1 : thisIFF - 1);
if (miss.FlightGroups[i].IsFlightGroup())
{
int targPri = miss.FlightGroups[i].TargetPrimary;
int targSec = miss.FlightGroups[i].TargetSecondary;
convertXwingOrderToTIE(miss.FlightGroups[i].Order, targPri, targSec, oppositeIFF, tie.FlightGroups[i].Orders[0], tie.FlightGroups[i].Orders[1]);
moveOrderUp(tie.FlightGroups[i].Orders[0]);
if (miss.FlightGroups[i].Order >= 13 && miss.FlightGroups[i].Order <= 17) //The X-wing boarding commands (Give, Take, Exchange, Capture, Destroy)
{
int time = miss.FlightGroups[i].DockTimeThrottle * 60 / 5; //Convert minutes to increments of 5 seconds.
if (time < 0) time = 0;
else if (time > 255) time = 255;
tie.FlightGroups[i].Orders[0].Throttle = 10; //Full throttle
tie.FlightGroups[i].Orders[0].Variable1 = (byte)time;
tie.FlightGroups[i].Orders[0].Variable2 = 1; //Docking count
}
else if (miss.FlightGroups[i].Order == 26) //More for SS Hold Position
{
tie.FlightGroups[i].Orders[0].Throttle = 0;
BaseFlightGroup.BaseOrder order3 = tie.FlightGroups[i].Orders[2];
order3.Command = 20; //Set an additional SS Wait order. TIE orders don't have an equivalent command that sits still and autotargets.
order3.Target1Type = 0x5; order3.Target1 = oppositeIFF; order3.T1AndOrT2 = true;
order3.Variable1 = 255; //Maximum wait time, 21:15
order3.Throttle = 0;
}
else
{
int throttle = miss.FlightGroups[i].DockTimeThrottle;
if (throttle == 0) throttle = 10; //100%
else if (throttle >= 1 && throttle <= 9) throttle += 1; //20% to 100%
else if (throttle == 10) throttle = 0; //0%
else throttle = 10; //Unrecognized, full throttle for anything else.
tie.FlightGroups[i].Orders[0].Throttle = (byte)throttle;
}
}
else //For objects...
{
if (tie.FlightGroups[i].CraftType == 0x4B) //Special case for mine.
{
Tie.FlightGroup.Order order = new Tie.FlightGroup.Order
{
Command = 7, //Attack targets
Target1Type = 0x5, //IFF
Target1 = oppositeIFF,
T1AndOrT2 = true //OR (none)
};
tie.FlightGroups[i].Orders[0] = order;
}
}
#endregion Orders
//XWING95 waypoints: 0=Start1, 1=WayPt1, 2=WayPt2, 3=WayPt3, 4=Start2, 5=Start3, 6=Hyper
tie.FlightGroups[i].Waypoints[0] = miss.FlightGroups[i].Waypoints[0]; //Start1
tie.FlightGroups[i].Waypoints[1] = miss.FlightGroups[i].Waypoints[4]; //Start2
tie.FlightGroups[i].Waypoints[2] = miss.FlightGroups[i].Waypoints[5]; //Start3
tie.FlightGroups[i].Waypoints[4] = miss.FlightGroups[i].Waypoints[1]; //WayPt1
tie.FlightGroups[i].Waypoints[5] = miss.FlightGroups[i].Waypoints[2]; //WayPt2
tie.FlightGroups[i].Waypoints[6] = miss.FlightGroups[i].Waypoints[3]; //WayPt3
tie.FlightGroups[i].Waypoints[13] = miss.FlightGroups[i].Waypoints[6]; //Hyper
}
#endregion FGs
#region Briefing
//Briefing flightgroups are separate from normal flightgroups. They aren't necessarily the same, nor do they share the same indexes. Try to detect if the FG exists by craft and position. If the craft doesn't exist, create new briefing-only FGs if there's space to function as icons.
Dictionary<int, int> BRFtoReal = new Dictionary<int, int>(); //Maps BRF FlightGroups to their actual XWI FlightGroup, or a new dummy FG to be used as a briefing icon.
Xwing.BriefingPage pg = miss.Briefing.GetBriefingPage(0);
int cs = pg.CoordSet;
int wpIndex = 0; //Default to Start1
if (cs >= 1 && cs <= 3) //If not Start1, transform into the waypoint index of the virtualized coordinate
wpIndex = 7 + cs - 1;
for (int i = 0; i < miss.FlightGroupsBriefing.Count; i++)
{
Xwing.FlightGroup bfg = miss.FlightGroupsBriefing[i];
int found = miss.GetMatchingXWIFlightGroup(i);
if (found >= 0)
{
tie.FlightGroups[found].Waypoints[14] = bfg.Waypoints[wpIndex];
tie.FlightGroups[found].Waypoints[14].RawY *= -1; //Axis inversion?
tie.FlightGroups[found].Waypoints[14].Enabled = true;
}
else if (tie.FlightGroups.Count < Tie.Mission.FlightGroupLimit) //Create a new FG solely for a briefing icon, if there's space.
{
Tie.FlightGroup newFG = new Tie.FlightGroup
{
Name = bfg.Name,
Cargo = "BRIEF_ICON",
CraftType = (byte)bfg.GetTIECraftType(),
NumberOfCraft = 1,
NumberOfWaves = 1,
IFF = bfg.GetTIEIFF(),
Difficulty = 0
};
newFG.ArrDepTriggers[0].Condition = 10; //False so it never arrives.
newFG.ArrDepTriggers[1].Condition = 10; //False
newFG.Waypoints[14] = bfg.Waypoints[wpIndex];
newFG.Waypoints[14].RawY *= -1; //Axis inversion?
newFG.Waypoints[14].Enabled = true;
tie.FlightGroups.Add(newFG);
found = tie.FlightGroups.Count - 1;
}
BRFtoReal[i] = found;
}
for (int i = 0; i < miss.Briefing.BriefingTag.Length; i++)
{
string t = miss.Briefing.BriefingTag[i];
if (t.Length >= 40) t = t.Substring(0, 38) + "|"; //Limit tag length. Attempting to render a text tag >= 40 characters long will crash the game.
tie.Briefing.BriefingTag[i] = t;
}
for (int i = 0; i < miss.Briefing.BriefingString.Length; i++)
{
string t = miss.Briefing.BriefingString[i];
if (t.Length >= 158) t = t.Substring(0, 157) + "|"; //Limit strings in TIE Fighter and prevent sporadic crashes when loading the briefing.
tie.Briefing.BriefingString[i] = t;
}
//tie.Briefing.Unknown1 = miss.Briefings[0].Unknown1;
tie.Briefing.Length = (short)(((float)pg.Length / Xwing.Briefing.TicksPerSecond) * Tie.Briefing.TicksPerSecond);
int rpos = 0;
int wpos = 0;
int length = miss.Briefing.GetEventsLength(0);
while (rpos < length)
{
short[] xwevt = miss.Briefing.ReadBriefingEvent(0, rpos);
/*if (rpos > 0 && xwevt[1] == (short)Xwing.Briefing.EventType.ClearText) //Insert a PageBreak before the text (Title/Caption) is cleared, if it's not the first event in the list.
{
tie.Briefing.Events[wpos++] = (short)(((float)xwevt[0] / Xwing.Briefing.TicksPerSecond) * Tie.Briefing.TicksPerSecond);
tie.Briefing.Events[wpos++] = (short)BaseBriefing.EventType.PageBreak;
}*/
short[] tieevt = miss.Briefing.TranslateBriefingEvent(xwevt);
if (tieevt[1] >= (short)BaseBriefing.EventType.FGTag1 && tieevt[1] <= (short)BaseBriefing.EventType.FGTag8)
tieevt[2] = (short)(BRFtoReal.ContainsKey(tieevt[2]) ? BRFtoReal[tieevt[2]] : 0); //Replace the BRF FlightGroup with the mapped FlightGroup as detected, or replace with zero.
else if (tieevt[1] >= (short)BaseBriefing.EventType.TextTag1 && tieevt[1] <= (short)BaseBriefing.EventType.TextTag8)
tieevt[5] = 7; //Color White
if (tieevt.Length < 2)
break;
tieevt[0] = (short)(((float)tieevt[0] / Xwing.Briefing.TicksPerSecond) * Tie.Briefing.TicksPerSecond);
if (tieevt[1] != (short)BaseBriefing.EventType.None)
for (int i = 0; i < tieevt.Length; i++)
tie.Briefing.Events[wpos++] = tieevt[i];
rpos += xwevt.Length;
}
tie.Briefing.Events[wpos++] = 9999;
tie.Briefing.Events[wpos++] = 0x22;
#endregion Briefing
#region Description
//Extract the mission description from the briefing's text pages. Anything before the hints page goes into the pre-mission questions. The hints pages go into the post-mission failure questions.
List<string> preText = new List<string>();
List<string> failText = new List<string>();
List<string> captionText;
bool hintPage = false;
for (int i = 0; i < miss.Briefing.Pages.Count; i++)
{
if (!miss.Briefing.IsMapPage(i))
{
miss.Briefing.GetCaptionText(i, out captionText);
foreach (string s in captionText)
{
if (s == "") continue;
bool isHintMsg = miss.Briefing.ContainsHintText(s);
hintPage |= isHintMsg; //All of the hint pages are in order.
if (isHintMsg || s.StartsWith(">")) continue;