@@ -542,9 +542,23 @@ private void ImportSavUnits() {
542
542
}
543
543
544
544
private void ImportBicUnits ( ) {
545
- // TODO: This doesn't account for default starting units.
546
545
BiqData theBiq = biq . Unit is null ? defaultBiq : biq ;
547
546
547
+ var createUnitAtLocation = ( SavePlayer player , int unitType , string experienceLevel , int hitPoints , int x , int y ) => {
548
+ PRTO prototype = theBiq . Prto [ unitType ] ;
549
+ SaveUnit saveUnit = new SaveUnit {
550
+ id = ids . CreateID ( prototype . Name ) ,
551
+ owner = player . id ,
552
+ prototype = prototype . Name ,
553
+ currentLocation = new TileLocation ( x , y ) ,
554
+ previousLocation = new TileLocation ( x , y ) ,
555
+ experience = experienceLevel ,
556
+ hitPointsRemaining = hitPoints , // TODO: include bonus hitpoints from unit type
557
+ movePointsRemaining = ( float ) prototype . Movement ,
558
+ } ;
559
+ return saveUnit ;
560
+ } ;
561
+
548
562
foreach ( UNIT unit in theBiq . Unit ) {
549
563
if ( unit . Owner >= save . Players . Count ) {
550
564
continue ;
@@ -553,20 +567,27 @@ private void ImportBicUnits() {
553
567
// The owner index is into the list of civs, and we have a 1:1
554
568
// mapping of players and civs.
555
569
SavePlayer player = save . Players [ unit . Owner ] ;
556
-
557
- PRTO prototype = theBiq . Prto [ unit . UnitType ] ;
558
570
ExperienceLevel experience = save . ExperienceLevels [ unit . ExperienceLevel ] ;
559
- SaveUnit saveUnit = new SaveUnit {
560
- id = ids . CreateID ( prototype . Name ) ,
561
- owner = player . id ,
562
- prototype = prototype . Name ,
563
- currentLocation = new TileLocation ( unit . X , unit . Y ) ,
564
- previousLocation = new TileLocation ( unit . X , unit . Y ) ,
565
- experience = experience . key ,
566
- hitPointsRemaining = experience . baseHitPoints , // TODO: include bonus hitpoints from unit type
567
- movePointsRemaining = ( float ) prototype . Movement ,
568
- } ;
569
- save . Units . Add ( saveUnit ) ;
571
+ save . Units . Add ( createUnitAtLocation ( player , unit . UnitType , experience . key , experience . baseHitPoints , unit . X , unit . Y ) ) ;
572
+ }
573
+
574
+ RULE rule = theBiq . Rule [ 0 ] ;
575
+ foreach ( SLOC starting_location in theBiq . Sloc ) {
576
+ // Skip barbarians
577
+ if ( starting_location . OwnerType <= 1 ) {
578
+ continue ;
579
+ }
580
+
581
+ // The owner index is into the list of civs, and we have a 1:1
582
+ // mapping of players and civs.
583
+ SavePlayer player = save . Players [ starting_location . Owner ] ;
584
+ int baseHitPoints = 3 ;
585
+ if ( rule . StartUnitType1 >= 0 ) {
586
+ save . Units . Add ( createUnitAtLocation ( player , rule . StartUnitType1 , "Regular" , baseHitPoints , starting_location . X , starting_location . Y ) ) ;
587
+ }
588
+ if ( rule . StartUnitType2 >= 0 ) {
589
+ save . Units . Add ( createUnitAtLocation ( player , rule . StartUnitType2 , "Regular" , baseHitPoints , starting_location . X , starting_location . Y ) ) ;
590
+ }
570
591
}
571
592
}
572
593
0 commit comments