-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTechTree.cs
1793 lines (1420 loc) · 72.4 KB
/
TechTree.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
using System;
using System.Collections.Generic;
using System.Text;
using FreeAllegiance.IGCCore;
using FreeAllegiance.IGCCore.Modules;
using System.Diagnostics;
using System.Collections;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace CoreExporter
{
public class TechTree
{
private enum GlobalDefinitions
{
AllowExpansion = 5,
AllowShipyard = 6,
AllowSupremacy = 3,
AllowTacticalLab = 4
}
private readonly List<int> _globalDefinitions = new List<int>(new int[] { (int)GlobalDefinitions.AllowExpansion, (int)GlobalDefinitions.AllowShipyard, (int)GlobalDefinitions.AllowSupremacy, (int)GlobalDefinitions.AllowTacticalLab });
private Core _core;
private Node _rootNode = null;
public Node RootNode
{
get { return _rootNode; }
}
private List<Node> _factionNodes = new List<Node>();
public List<Node> FactionNodes
{
get { return _factionNodes; }
}
public void CreateSampleTree()
{
_rootNode = new Node(null, "Root");
Node child1 = new Node(_rootNode, "child 1");
Node child2 = new Node(_rootNode, "child 2");
//Node child3 = new Node(_rootNode, "child 3");
//Node child4 = new Node(_rootNode, "child 4");
Node child11 = new Node(child1, "child 1 1");
Node child111 = new Node(child11, "child 1 1 1");
Node child1111 = new Node(child111, "child 1 1 1 1");
Node child11111 = new Node(child1111, "child 1 1 1 1 1");
Node child21 = new Node(child2, "child 2 1");
Node child211 = new Node(child21, "child 2 1 1");
Node child2111 = new Node(child211, "child 2 1 1 1");
Node child21111 = new Node(child2111, "child 2 1 1 1 1");
child21111.SetParent(child11);
child21111.SetParent(child111);
//Node child12 = new Node(child1, "child 1 2");
//Node child13 = new Node(child1, "child 1 3");
//Node child111 = new Node(child11, "child 1 1 1");
//Node child112 = new Node(child11, "child 1 1 2");
//Node child1111 = new Node(child111, "child 1 1 1 1");
//Node child11111 = new Node(child1111, "child 1 1 1 1 1");
//Node child11112 = new Node(child1111, "child 1 1 1 1 2");
//Node child11113 = new Node(child1111, "child 1 1 1 1 3");
//Node child11114 = new Node(child1111, "child 1 1 1 1 4");
//Node child111141 = new Node(child11114, "child 1 1 1 1 4 1");
//Node child111142 = new Node(child11114, "child 1 1 1 1 4 2");
//Node child31 = new Node(child3, "child 3 1");
//Node child32 = new Node(child3, "child 3 2");
//Node child33 = new Node(child3, "child 3 3");
//Node child321 = new Node(child32, "child 3 2 1");
//Node child322 = new Node(child32, "child 3 2 2");
//Node child323 = new Node(child32, "child 3 2 3");
//Node child121 = new Node(child12, "child 1 2 1");
//Node child122 = new Node(child12, "child 1 2 2");
//Node child123 = new Node(child12, "child 1 2 3");
//Node child124 = new Node(child12, "child 1 2 4");
//child11112.SetParent(child122);
//child11113.SetParent(child123);
//child11114.SetParent(child124);
//child111.SetParent(child322);
//child112.SetParent(child322);
//Node child1211 = new Node(child121, "child 1 2 1 1");
//Node child12111 = new Node(child1211, "child 1 2 1 1 1");
//child11114.SetParent(child12111);
//Node child21 = new Node(child2, "child 2 1");
//Node child211 = new Node(child2, "child 2 1 1");
//child11.SetParent(child211);
//child12.SetParent(child211);
//child21.SetParent(child121);
//child32.SetParent(child21);
//child11.SetParent(child21);
//for (int i = 0; i < 1; i++)
//{
// Node child4x = new Node(child4, "Child 4 " + i);
// child1211.SetParent(child4x);
//}
}
public void LoadCoreFile(string filename)
{
_core = new Core(filename);
_rootNode = null;
_factionNodes.Clear();
foreach (IGCCoreCiv civ in _core.Factions)
{
//System.Diagnostics.Debug.WriteLine("civ: " + civ.Name + ", defs: " + civ.Techtree.GetDefs() + ", pres: " + civ.Techtree.GetPres());
//if (civ.Name == targetCivName)
//{
// _rootNode = new Node(civ);
//}
_factionNodes.Add(new Node(civ));
}
//if (_rootNode == null)
// throw new Exception("Couldn't find target civilization name with the name of: " + targetCivName);
//BuildNodeTreeFromCore(core, _rootNode);
}
private void ClearAllTreeConnections(Node nodeToClear)
{
if (nodeToClear == null)
return;
foreach (Node childNode in nodeToClear.Children)
{
ClearAllTreeConnections(childNode);
}
nodeToClear.Children.Clear();
nodeToClear.Parents.Clear();
}
public void BuildFactionNodeTreeFromCore(Node factionNode)
{
ClearAllTreeConnections(_rootNode);
_rootNode = factionNode;
List<Node> linearNodeList = new List<Node>();
linearNodeList.Add(factionNode);
foreach (IGCCoreStationType station in _core.StationTypes)
{
//Debug.WriteLine("station: " + station.Name + ", pres: " + station.Techtree.GetPres());
//Debug.WriteLine("station: " + station.Name + ", local: " + ParseLocalTechTreeToString(station.TechTreeLocal));
linearNodeList.Add(new Node(station));
}
foreach (IGCCoreShip ship in _core.Ships)
{
linearNodeList.Add(new Node(ship));
}
foreach (IGCCoreDevel devel in _core.Developments)
{
linearNodeList.Add(new Node(devel));
}
SatisfyAllPrerequisites(linearNodeList, factionNode);
Node[] temporaryNodeList = new Node[linearNodeList.Count];
linearNodeList.CopyTo(temporaryNodeList);
// Remove all nodes that are not available to the target faction.
foreach (Node node in temporaryNodeList)
{
if (node.CoreObject.UID == 37)
Debug.Write("");
if (node.HasSatisfiedAllPrerequisites == false && node != factionNode)
linearNodeList.Remove(node);
}
// Build a node list of all stations.
List<Node> stationNodes = new List<Node>();
List<Node> shipNodes = new List<Node>();
foreach (Node node in linearNodeList)
{
if (node.CoreObject is IGCCoreStationType)
stationNodes.Add(node);
if (node.CoreObject is IGCCoreShip)
shipNodes.Add(node);
}
// Build a list of stations that don't require any development.
List<Node> rootLevelStationNodes = FindRootLevelStationNodes(stationNodes, _core, (IGCCoreCiv)factionNode.CoreObject);
// Build a list of stations that require development.
List<Node> developedStationNodes = new List<Node>();
foreach (Node stationNode in stationNodes)
{
if (rootLevelStationNodes.Contains(stationNode) == false)
developedStationNodes.Add(stationNode);
}
// Add all the root level stations to the root node.
foreach (Node rootLevelStationNode in rootLevelStationNodes)
{
if (factionNode.AreNodesRelated(rootLevelStationNode) == false)
rootLevelStationNode.SetParent(factionNode);
}
List<Node> developmentNodes = new List<Node>();
foreach (Node node in linearNodeList)
{
if (node.CoreObject is IGCCoreDevel)
developmentNodes.Add(node);
}
// Anchor all the root level development tech into it's associated station branch.
// devel tech is not directly linked to stations, it must be mapped based to a
// station type based on it's tech tree path, and then assigned to a station level (standard, advanced, etc...)
// based on the prereqs for the station.
foreach (Node rootStation in rootLevelStationNodes)
{
foreach (Node development in developmentNodes)
{
if (IsDevelopmentInStationTechBranch(rootStation, development) == true)
{
bool isRootLevelDevelopment = true;
foreach (int prerequisiteID in development.Prerequisites)
{
if (development.CoreObject.UID == 47 && prerequisiteID == 138)
Debug.Write("");
if (rootStation.Definitions.Contains(prerequisiteID) == true)
continue;
// For factions, pre is def, and def is 'no devel' defaults.
if (factionNode.Prerequisites.Contains(prerequisiteID) == true)
continue;
if (_globalDefinitions.Contains(prerequisiteID) == true)
continue;
bool prerequisiteWasDefinedByAnotherRootStation = false;
foreach (Node otherRootStation in rootLevelStationNodes)
{
if (otherRootStation == rootStation)
continue;
if (otherRootStation.Definitions.Contains(prerequisiteID) == true)
{
prerequisiteWasDefinedByAnotherRootStation = true;
break;
}
}
if (prerequisiteWasDefinedByAnotherRootStation == true)
continue;
// If the prerequisite is defined by another development in this tech path, then
// this development is not a root development.
bool prerequisiteWasDefinedByAnotherDevelopmentInThisBranch = false;
foreach (Node nodeToTest in developmentNodes)
{
//if (development.CoreObject.UID == 73 && nodeToTest.CoreObject.UID == 74)
// Debugger.Break();
if (nodeToTest.Definitions.Contains(prerequisiteID) == true)
{
if (((IGCCoreDevel)nodeToTest.CoreObject).Root_Tree == ((IGCCoreDevel)development.CoreObject).Root_Tree)
{
prerequisiteWasDefinedByAnotherDevelopmentInThisBranch = true;
break;
}
}
}
if (prerequisiteWasDefinedByAnotherDevelopmentInThisBranch == true)
{
isRootLevelDevelopment = false;
break;
}
// If the prerequisite needs a non-root station, then it is not a root development.
bool prerequisiteWasDefinedByNonRootStation = false;
foreach (Node developedStation in developedStationNodes)
{
if (developedStation.Definitions.Contains(prerequisiteID) == true)
{
prerequisiteWasDefinedByNonRootStation = true;
break;
}
}
if (prerequisiteWasDefinedByNonRootStation == true)
{
isRootLevelDevelopment = false;
break;
}
isRootLevelDevelopment = false;
break;
}
if (isRootLevelDevelopment == true && development.AreNodesRelated(rootStation) == false)
development.SetParent(rootStation);
}
}
}
// Add stations that need development to the tree.
foreach (Node station in developedStationNodes)
{
List<Node> nodesThatDependOnStation = new List<Node>();
foreach (Node development in developmentNodes)
{
if (development.Defines(station, false) == true && development.AreNodesRelated(station) == false)
station.SetParent(development);
/*
// Attach all developments that need a developed station and are not attached to another development in
// this station's tech branch.
if (station.Defines(development, false) == true && station.AreNodesRelated(development) == false && development.Parents.Count == 0 && IsDevelopmentInStationTechBranch(station, development) == true)
{
bool isDevelopmentDefinedByRootLevelStation = false;
//foreach (Node rootStation in rootLevelStationNodes)
//{
// if (rootStation.Defines(development, false) == true && rootStation.AreNodesRelated(development) == false)
// {
// isDevelopmentDefinedByRootLevelStation = true;
// development.SetParent(rootStation);
// break;
// }
//}
if (isDevelopmentDefinedByRootLevelStation == false)
nodesThatDependOnStation.Add(development);
}
*/
//bool isDevelopmentDefinedByRootLevelStation = false;
//foreach (Node rootStation in rootLevelStationNodes)
//{
// if (rootStation.Defines(development, false) == true)
// {
// if (rootStation.AreNodesRelated(development) == false)
// development.SetParent(rootStation);
// isDevelopmentDefinedByRootLevelStation = true;
// break;
// }
//}
//if (isDevelopmentDefinedByRootLevelStation == false)
//{
// // Attach all developments that need a developed station and are not attached to another development in
// // this station's tech branch.
// if (station.Defines(development, false) == true && station.AreNodesRelated(development) == false && development.Parents.Count == 0 && IsDevelopmentInStationTechBranch(station, development) == true)
// {
// nodesThatDependOnStation.Add(development);
// }
//}
}
//foreach (Node parentNode in nodesThatDependOnStation)
//{
// foreach (Node childNode in nodesThatDependOnStation)
// {
// if (parentNode == childNode)
// continue;
// if (parentNode.Defines(childNode, false) && parentNode.AreNodesRelated(childNode) == false)
// {
// childNode.SetParent(parentNode);
// break;
// }
// }
//}
//foreach (Node node in nodesThatDependOnStation)
//{
// if (node.Parents.Count == 0)
// node.SetParent(station);
//}
}
// Find all developments that define stations.
List<Node> developmentsThatDefineStations = new List<Node>();
foreach (Node development in developmentNodes)
{
foreach (Node station in stationNodes)
{
if (development.Defines(station, false) == true)
developmentsThatDefineStations.Add(development);
}
}
// Determine proper linking for developments that define stations.
//foreach (Node parentDevelopment in developmentsThatDefineStations)
//{
// foreach (Node childDevelopment in developmentsThatDefineStations)
// {
// if (childDevelopment == parentDevelopment)
// continue;
// if (childDevelopment.Parents.Count == 0 && parentDevelopment.Defines(childDevelopment, false) == true && parentDevelopment.AreNodesRelated(childDevelopment) == false)
// childDevelopment.SetParent(parentDevelopment);
// }
//}
// Connect development nodes with stations as the primary parent.
foreach (Node development in developmentNodes)
{
if (development.CoreObject.UID == 47)
Debug.Write("");
if (development.Parents.Count == 0)
{
Node station = FindLowestLevelStationThatDefinesDevelopment(_rootNode, null, development);
// Does this development rely on any other development in this branch?
foreach (Node parentDevelopmentCandidate in developmentNodes)
{
if (parentDevelopmentCandidate == development)
continue;
// If the parent development defined this development, and the parent development is defined by the same station level that defines the development,
// then the proper parent development has been found.
if (parentDevelopmentCandidate.Defines(development, false) && FindLowestLevelStationThatDefinesDevelopment(_rootNode, null, parentDevelopmentCandidate) == station && parentDevelopmentCandidate.AreNodesRelated(development) == false)
{
development.SetParent(parentDevelopmentCandidate);
break;
}
}
// No parent developments were found in this branch, so add the development to the root station.
if (development.Parents.Count == 0 && station != null && station.AreNodesRelated(development) == false)
development.SetParent(station);
}
}
// Interconnect developments that are not connected to anything.
foreach (Node development in developmentNodes)
{
//if (development.CoreObject.UID == 224)
// Debug.Write("");
if (development.Parents.Count > 0)
continue;
foreach (Node parentDevelopment in developmentNodes)
{
if (parentDevelopment == development)
continue;
if (parentDevelopment.Defines(development, false) && parentDevelopment.AreNodesRelated(development) == false)
{
development.SetParent(parentDevelopment);
break;
}
}
}
// Cross Connect dependent developments
foreach (Node development in developmentNodes)
{
foreach (Node parentDevelopment in developmentNodes)
{
if (parentDevelopment == development)
continue;
if (parentDevelopment.Defines(development, false) == true && development.AreNodesRelated(parentDevelopment) == false)
development.SetParent(parentDevelopment);
}
}
// Attach Ships to the tech tree
foreach (Node ship in shipNodes)
{
if (ship.CoreObject.UID == 37)
Debug.Write("");
foreach (Node development in developmentNodes)
{
if (development.Defines(ship, false) == true && ship.AreNodesRelated(development) == false)
ship.SetParent(development);
}
foreach (int prerequisiteID in ship.Prerequisites)
{
Node lowestLevelStation = null;
foreach (Node station in stationNodes)
{
if (station.Definitions.Contains(prerequisiteID))
{
if (lowestLevelStation == null || station.Depth < lowestLevelStation.Depth)
lowestLevelStation = station;
}
}
if (lowestLevelStation != null && ship.AreNodesRelated(lowestLevelStation) == false)
ship.SetParent(lowestLevelStation);
}
/*
List<Node> usedDevelopedStationNodes = new List<Node>();
foreach (Node developedStation in developedStationNodes)
{
if (developedStation.Defines(ship, false) == true && developedStation.AreNodesRelated(ship) == false)
{
usedDevelopedStationNodes.Add(developedStation);
ship.SetParent(developedStation);
}
}
//List<Node> usedRootStationNodes = new List<Node>();
foreach (Node rootStation in rootLevelStationNodes)
{
if (rootStation.Defines(ship, false) == true && rootStation.AreNodesRelated(ship) == false)
{
bool isShipAlreadyAssignedToDevelopedStationUnderThisRoot = false;
foreach (Node developedStation in usedDevelopedStationNodes)
{
if (rootStation.IsNodeADecendant(developedStation) == true)
{
isShipAlreadyAssignedToDevelopedStationUnderThisRoot = true;
break;
}
}
if(isShipAlreadyAssignedToDevelopedStationUnderThisRoot == false)
ship.SetParent(rootStation);
}
}
*/
}
CombNodeAttachmentLevels(_rootNode);
ClearRedunantLinks(_rootNode);
}
/// <summary>
/// If any nodes are attached to development nodes that lower than another development node higher in the tree, move the node up to
/// to the proper level in the tree.
/// </summary>
/// <param name="_rootNode"></param>
private void CombNodeAttachmentLevels(Node nodeToComb)
{
if (nodeToComb.CoreObject.UID == 19)
Debug.Write("");
bool movedNode = false;
do
{
movedNode = false;
if (nodeToComb.Parents.Count > 0)
{
List<int> definingPrerequisites = GetDefiningPrerequisite(nodeToComb.Parents[0], nodeToComb);
// Find next available ancestor that also defines the attachment prerequisistes.
Node ancestorThatAlseDefinesPrerequistes = GetParentNodeThatDefinesPrerequisites(nodeToComb.Parents[0], definingPrerequisites);
if (ancestorThatAlseDefinesPrerequistes != null)
{
// Break the link to the node's primary parent.
nodeToComb.Parents[0].Children.Remove(nodeToComb);
nodeToComb.Parents.RemoveAt(0);
// Make a new link to the node's up level ancestor.
nodeToComb.Parents.Insert(0, ancestorThatAlseDefinesPrerequistes);
ancestorThatAlseDefinesPrerequistes.Children.Add(nodeToComb);
movedNode = true;
}
}
} while (movedNode == true);
List<Node> childNodes = new List<Node>(nodeToComb.Children);
foreach (Node childNode in childNodes)
CombNodeAttachmentLevels(childNode);
}
private List<int> GetDefiningPrerequisite(Node parentNode, Node childNode)
{
List<int> definingPrerequisites = new List<int>();
foreach (int prerequisiteID in childNode.Prerequisites)
{
foreach (int definitionID in parentNode.Definitions)
{
if (prerequisiteID == definitionID)
definingPrerequisites.Add(prerequisiteID);
}
foreach (int definitionID in parentNode.Locals)
{
if (prerequisiteID == definitionID)
definingPrerequisites.Add(prerequisiteID);
}
}
return definingPrerequisites;
}
private Node GetParentNodeThatDefinesPrerequisites(Node node, List<int> definingPrerequisites)
{
foreach (Node parentNode in node.Parents)
{
if (parentNode.Parents.Count == 0)
continue;
int matchCount = 0;
foreach (int definitionID in parentNode.Definitions)
{
if (definingPrerequisites.Contains(definitionID) == true)
matchCount++;
}
foreach (int definitionID in parentNode.Locals)
{
if (definingPrerequisites.Contains(definitionID) == true)
matchCount++;
}
if (matchCount >= definingPrerequisites.Count)
return parentNode;
}
Node nearestParentNode = null;
foreach (Node parentNode in node.Parents)
{
Node parentNodeCandidate = GetParentNodeThatDefinesPrerequisites(parentNode, definingPrerequisites);
if (nearestParentNode == null || (parentNodeCandidate != null && parentNodeCandidate.Depth > nearestParentNode.Depth))
nearestParentNode = parentNodeCandidate;
}
return nearestParentNode;
}
private Node FindLowestLevelStationThatDefinesDevelopment(Node nodeToTest, Node bestStationNode, Node development)
{
if (development.CoreObject.UID == 255 && nodeToTest.CoreObject.UID == 72)
Debug.Write("");
if (nodeToTest.CoreObject is IGCCoreStationType && nodeToTest.Defines(development, false) == true && IsDevelopmentInStationTechBranch(nodeToTest, development) == true)
{
if (bestStationNode == null)
{
bestStationNode = nodeToTest;
}
else
{
if (nodeToTest.Depth < bestStationNode.Depth)
bestStationNode = nodeToTest;
}
}
foreach (Node childNode in nodeToTest.Children)
bestStationNode = FindLowestLevelStationThatDefinesDevelopment(childNode, bestStationNode, development);
return bestStationNode;
}
//private bool IsDevelopmentLinkedToAnOrpanedDevelopment(Node development, List<Node> developmentNodes)
//{
// foreach (Node parentDevelopment in developmentNodes)
// {
// if (parentDevelopment == development)
// continue;
// if(development.Parents.Contains(parentDevelopment) == false
// }
//}
//private void BuildNodeTreeFromCoreTry2(Core core, Node rootNode)
//{
// // Build a node list of all stations.
// List<Node> stationNodes = new List<Node>();
// foreach (IGCCoreStationType station in core.StationTypes)
// {
// if(DoesFactionDefinePrerequisitesForObject(core, (IGCCoreCiv)rootNode.CoreObject, station) == true)
// stationNodes.Add(new Node(station));
// }
// // Build a list of stations that don't require any development.
// List<Node> rootLevelStationNodes = FindRootLevelStationNodes(stationNodes, core, (IGCCoreCiv)rootNode.CoreObject);
// // Build a list of stations that require development.
// List<Node> developedStationNodes = new List<Node>();
// foreach (Node stationNode in stationNodes)
// {
// if (rootLevelStationNodes.Contains(stationNode) == false)
// developedStationNodes.Add(stationNode);
// }
// // Add all the root level stations to the root node.
// foreach (Node rootLevelStationNode in rootLevelStationNodes)
// {
// if (rootNode.AreNodesRelated(rootLevelStationNode) == false)
// rootLevelStationNode.SetParent(rootNode);
// }
// List<Node> developmentNodes = new List<Node>();
// foreach (IGCCoreDevel development in core.Developments)
// {
// if (DoesFactionDefinePrerequisitesForObject(core, (IGCCoreCiv)rootNode.CoreObject, development) == true)
// developmentNodes.Add(new Node(development));
// }
// // Anchor all the root level development tech into it's associated station branch.
// // devel tech is not directly linked to stations, it must be mapped based to a
// // station type based on it's tech tree path, and then assigned to a station level (standard, advanced, etc...)
// // based on the prereqs for the station.
// foreach (Node rootStation in rootLevelStationNodes)
// {
// foreach (Node development in developmentNodes)
// {
// if (development.CoreObject.UID == 74)
// Debugger.Break();
// if (IsDevelopmentInStationTechBranch(rootStation, development) == true)
// {
// bool isRootLevelDevelopment = true;
// foreach (int prerequisiteID in development.Prerequisites)
// {
// if (rootStation.Definitions.Contains(prerequisiteID) == true)
// continue;
// // For factions, pre is def, and def is 'no devel' defaults.
// if (rootNode.Prerequisites.Contains(prerequisiteID) == true)
// continue;
// if (_globalDefinitions.Contains(prerequisiteID) == true)
// continue;
// bool prerequisiteWasDefinedByAnotherRootStation = false;
// foreach (Node otherRootStation in rootLevelStationNodes)
// {
// if (otherRootStation == rootStation)
// continue;
// if (otherRootStation.Definitions.Contains(prerequisiteID) == true)
// {
// prerequisiteWasDefinedByAnotherRootStation = true;
// break;
// }
// }
// if (prerequisiteWasDefinedByAnotherRootStation == true)
// continue;
// // If the prerequisite is defined by another development in this tech path, then
// // this development is not a root development.
// bool prerequisiteWasDefinedByAnotherDevelopmentInThisBranch = false;
// foreach (Node nodeToTest in developmentNodes)
// {
// if (development.CoreObject.UID == 73 && nodeToTest.CoreObject.UID == 74)
// Debugger.Break();
// if (nodeToTest.Definitions.Contains(prerequisiteID) == true)
// {
// if (((IGCCoreDevel)nodeToTest.CoreObject).Root_Tree == ((IGCCoreDevel)development.CoreObject).Root_Tree)
// {
// prerequisiteWasDefinedByAnotherDevelopmentInThisBranch = true;
// break;
// }
// }
// }
// if (prerequisiteWasDefinedByAnotherDevelopmentInThisBranch == false)
// continue;
// // If the prerequisite needs a non-root station, then it is not a root development.
// bool prerequisiteWasDefinedByNonRootStation = false;
// foreach (Node developedStation in developedStationNodes)
// {
// if (developedStation.Definitions.Contains(prerequisiteID) == true)
// {
// prerequisiteWasDefinedByNonRootStation = true;
// break;
// }
// }
// if (prerequisiteWasDefinedByNonRootStation == false)
// continue;
// isRootLevelDevelopment = false;
// break;
// }
// if (isRootLevelDevelopment == true)
// development.SetParent(rootStation);
// }
// }
// }
// //bool atLeaseOneNodeAssignmentOccurred;
// //do
// //{
// // atLeaseOneNodeAssignmentOccurred = false;
// //} while (atLeaseOneNodeAssignmentOccurred == true);
// /*
// // Assign all nodes with no development pre-reqs to the root.
// foreach (Node topLevelCandidateNode in developmentNodeList)
// {
// bool foundDevelopmentPrerequisite = false;
// foreach (Node node in developmentNodeList)
// {
// if (node == topLevelCandidateNode)
// continue;
// foreach (int prerequisiteID in topLevelCandidateNode.Prerequisites)
// {
// if (node.Definitions.Contains(prerequisiteID) == true)
// {
// foundDevelopmentPrerequisite = true;
// break;
// }
// }
// if (foundDevelopmentPrerequisite == true)
// break;
// }
// if (foundDevelopmentPrerequisite == false)
// {
// if (topLevelCandidateNode.CoreObject is IGCCoreDevel)
// {
// AttachNodeToStation(topLevelCandidateNode, rootLevelStationNodes);
// }
// else
// {
// if (rootNode.AreNodesRelated(topLevelCandidateNode) == false)
// topLevelCandidateNode.SetParent(rootNode);
// }
// }
// }
// */
// // Place all unassigned nodes into a list for assignment.
// //List<Node> unassignedNodes = new List<Node>();
// //foreach (Node node in developedStationNodes)
// //{
// // if (node.Parents.Count == 0)
// // unassignedNodes.Add(node);
// //}
// //foreach (Node node in developmentNodes)
// //{
// // if (node.Parents.Count == 0)
// // unassignedNodes.Add(node);
// //}
// //int lastCount = unassignedNodes.Count;
// //do
// //{
// // lastCount = unassignedNodes.Count;
// // foreach (Node node in unassignedNodes)
// // {
// // //if (parentNode.CoreObject.UID == 209)
// // // Debugger.Break();
// // // Only attached nodes can be parent nodes.
// // if (parentNode.Parents.Count == 0)
// // continue;
// // foreach (Node childNode in developmentNodes)
// // {
// // //if (parentNode.CoreObject.UID == 209 && childNode.CoreObject.UID == 210)
// // // Debugger.Break();
// // if (childNode == parentNode)
// // continue;
// // foreach (int prerequisiteID in childNode.Prerequisites)
// // {
// // if (parentNode.Definitions.Contains(prerequisiteID) == true)
// // {
// // if (parentNode.AreNodesRelated(childNode) == false)
// // {
// // childNode.SetParent(parentNode);
// // madeAtLeastOneAssignment = true;
// // break;
// // }
// // }
// // }
// // }
// // }
// //} while (unassignedNodes.Count > 0 && lastCount != unassignedNodes.Count);
// // Comb through the unassigned nodes until all are assigned.
// bool madeAtLeastOneAssignment = false;
// do
// {
// madeAtLeastOneAssignment = false;
// foreach (Node parentNode in developmentNodes)
// {
// //if (parentNode.CoreObject.UID == 209)
// // Debugger.Break();
// // Only attached nodes can be parent nodes.
// if (parentNode.Parents.Count == 0)
// continue;
// foreach (Node childNode in developmentNodes)
// {
// //if (parentNode.CoreObject.UID == 209 && childNode.CoreObject.UID == 210)
// // Debugger.Break();
// if (childNode == parentNode)
// continue;
// // The first parent must be in the item's root tree.
// if (childNode.Parents.Count == 0 && ((IGCCoreDevel)childNode.CoreObject).Root_Tree != ((IGCCoreDevel)parentNode.CoreObject).Root_Tree)
// continue;
// foreach (int prerequisiteID in childNode.Prerequisites)
// {
// if (parentNode.Definitions.Contains(prerequisiteID) == true)
// {
// if (parentNode.AreNodesRelated(childNode) == false)
// {
// childNode.SetParent(parentNode);
// madeAtLeastOneAssignment = true;
// break;
// }
// }
// }
// }
// }
// }
// while (madeAtLeastOneAssignment == true);