@@ -459,7 +459,9 @@ public int GetAdjustedOptimalCityNumber(GameData gameData) {
459459 // civilizations, the formula is: 1 (2 for Conquests) + random number
460460 // between 1-4 + number between 0-3 depending on size of your empire.
461461 public int GetTurnsOfAnarchyForTransition ( GameData gameData ) {
462- // TODO: if religious, return 2.
462+ if ( civilization . traits . Contains ( Civilization . Trait . Religious ) ) {
463+ return 2 ;
464+ }
463465
464466 // We add Next(3)+Next(3) to roughly approximate a normal
465467 // distribution. With the base of 2, this gets us a random value
@@ -617,12 +619,19 @@ private bool CanAdvanceToNextEra(GameData gameData) {
617619 public ( int , int , int ) TotalUnitsAllowedUnitsAndSupportCost ( ) {
618620 int freeUnits = 0 ;
619621
622+ Difficulty difficulty = EngineStorage . gameData . gameDifficulty ;
623+ if ( ! isHuman ) {
624+ freeUnits += difficulty . AdditionalFreeUnitSupport ;
625+ }
626+
620627 foreach ( City city in cities ) {
621- // TODO: Import these sizes from Rule.cs in the biq. Maybe have
622- // them live in the city class?
623- if ( city . residents . Count <= 6 ) {
628+ if ( ! isHuman ) {
629+ freeUnits += difficulty . UnitSupportBonusForEachSettlement ;
630+ }
631+
632+ if ( city . residents . Count <= rules . MaximumLevel1CitySize ) {
624633 freeUnits += government . freeUnitsPerTown ;
625- } else if ( city . residents . Count <= 12 ) {
634+ } else if ( city . residents . Count <= rules . MaximumLevel2CitySize ) {
626635 freeUnits += government . freeUnitsPerCity ;
627636 } else {
628637 freeUnits += government . freeUnitsPerMetropolis ;
@@ -745,6 +754,43 @@ public List<Tuple<City, CityBuilding>> GetActiveWonders() {
745754 return result ;
746755 }
747756
757+ public void MaybeSpawnBonusUnits ( GameData gD ) {
758+ // Bonus units only spawn on the first turn, if we have a city and
759+ // are a non-barbarian AI player.
760+ if ( gD . turn != 1 || cities . Count != 1 || isHuman || isBarbarians ) {
761+ return ;
762+ }
763+
764+ for ( int i = 0 ; i < gD . gameDifficulty . ExtraStartUnit1 ; ++ i ) {
765+ cities [ 0 ] . AddUnit ( gD . unitPrototypes . Find ( x => x . name == gD . rules . StartUnitType1 ) , gD ) ;
766+ }
767+ for ( int i = 0 ; i < gD . gameDifficulty . ExtraStartUnit2 ; ++ i ) {
768+ cities [ 0 ] . AddUnit ( gD . unitPrototypes . Find ( x => x . name == gD . rules . StartUnitType2 ) , gD ) ;
769+ }
770+ for ( int i = 0 ; i < gD . gameDifficulty . NumberOfAIDefensiveStartingUnits ; ++ i ) {
771+ UnitPrototype unit = ( UnitPrototype ) cities [ 0 ] . ListProductionOptions ( gD ) . MaxBy (
772+ x => {
773+ if ( x is UnitPrototype u ) {
774+ return u . defense ;
775+ }
776+ return - 1 ;
777+ }
778+ ) ;
779+ cities [ 0 ] . AddUnit ( unit , gD ) ;
780+ }
781+ for ( int i = 0 ; i < gD . gameDifficulty . NumberOfAIOffensiveStartingUnits ; ++ i ) {
782+ UnitPrototype unit = ( UnitPrototype ) cities [ 0 ] . ListProductionOptions ( gD ) . MaxBy (
783+ x => {
784+ if ( x is UnitPrototype u ) {
785+ return u . attack ;
786+ }
787+ return - 1 ;
788+ }
789+ ) ;
790+ cities [ 0 ] . AddUnit ( unit , gD ) ;
791+ }
792+ }
793+
748794 public void UpdateResourcesInBorders ( IEnumerable < Tile > ownedTiles ) {
749795 resourcesInBorders = ownedTiles
750796 . Where ( t => t . Resource != Resource . NONE )
@@ -758,7 +804,11 @@ public bool HasRequiredTechnology(IProducible producible) {
758804 }
759805
760806 public int ShieldCost ( IProducible producible ) {
761- return producible . ShieldCost ( civilization . traits ) ;
807+ // At higher difficulties, AI players get a cost discount.
808+ Difficulty difficulty = EngineStorage . gameData . gameDifficulty ;
809+ float costFactor = isHuman ? 1.0f : difficulty . AiCostFactor / ( float ) ( difficulty . HumanCostFactor ) ;
810+
811+ return producible . ShieldCost ( civilization . traits , costFactor ) ;
762812 }
763813 }
764814
0 commit comments