@@ -142,7 +142,7 @@ public void SetCurrentlyResearchedTech(ID id) {
142142
143143 Tech tech = EngineStorage . gameData . techs . Find ( x => x . id == id ) ;
144144 log . Information ( $ "Awarding { tech . Name } to player { this } ") ;
145- CompleteResearchingTech ( EngineStorage . gameData , tech ) ;
145+ CompleteResearchAndBeginNew ( EngineStorage . gameData , tech ) ;
146146 return ;
147147 }
148148
@@ -363,13 +363,8 @@ public void ExecuteDeal(GameData gameData, Player other, TradeOffer theirOffer,
363363 other . gold -= theirOffer . gold . Value ;
364364 }
365365
366- foreach ( Tech t in ourOffer . techs ) {
367- other . knownTechs . Add ( t . id ) ;
368- }
369-
370- foreach ( Tech t in theirOffer . techs ) {
371- this . knownTechs . Add ( t . id ) ;
372- }
366+ other . CompleteResearchAndBeginNew ( gameData , ourOffer . techs ) ;
367+ this . CompleteResearchAndBeginNew ( gameData , theirOffer . techs ) ;
373368 }
374369
375370 public int EstimateTurnsToResearch ( GameData gameData , Tech tech ) {
@@ -444,9 +439,7 @@ private Queue<Tech> GetResearchQueueFor(Tech tech, Queue<Tech> tempQueue) {
444439 return new Queue < Tech > ( ) ;
445440 }
446441
447- // TODO: maybe sort these on some other score, perhaps the order the AI would have picked them
448- // Right now the tech with the highest cost comes first
449- List < Tech > requiredTechs = tech . Prerequisites . OrderBy ( t => t . Cost ) . ToList ( ) ;
442+ List < Tech > requiredTechs = OrderTechs ( tech . Prerequisites ) . ToList ( ) ;
450443
451444 // first, add the tech the user clicked
452445 if ( ! tempQueue . Contains ( tech ) ) {
@@ -473,9 +466,14 @@ private Queue<Tech> GetResearchQueueFor(Tech tech, Queue<Tech> tempQueue) {
473466 return tempQueue ;
474467 }
475468
476- public HashSet < Tech > GetAvailableTechsToResearch ( GameData gameData ) {
469+ /// <summary>
470+ /// Takes all the techs in the game and keeps only what could be researched next at a particular point in the game.
471+ /// </summary>
472+ /// <param name="allTechs"></param>
473+ /// <returns></returns>
474+ public HashSet < Tech > GetAvailableTechsToResearch ( List < Tech > allTechs ) {
477475 HashSet < Tech > result = new ( ) ;
478- foreach ( Tech tech in gameData . techs ) {
476+ foreach ( Tech tech in allTechs ) {
479477 if ( knownTechs . Contains ( tech . id ) ) {
480478 continue ;
481479 }
@@ -494,7 +492,17 @@ public HashSet<Tech> GetAvailableTechsToResearch(GameData gameData) {
494492 result . Add ( tech ) ;
495493 }
496494 }
497- return result ;
495+ return OrderTechs ( result . ToList ( ) ) ;
496+ }
497+
498+ // Placeholder ordering of techs
499+ private HashSet < Tech > OrderTechs ( List < Tech > techs ) {
500+ if ( techs == null || techs . Count == 0 ) {
501+ return new HashSet < Tech > ( ) ;
502+ }
503+ // TODO: We would want to eventually order them based on how the AI would do it
504+ // Details on how Civ3 does it: https://forums.civfanatics.com/threads/what-will-the-ai-research-next.45559/
505+ return techs . OrderBy ( t => t . Cost ) . ToHashSet ( ) ;
498506 }
499507
500508 public List < Government > GetAvailableGovernments ( GameData gameData ) {
@@ -679,7 +687,18 @@ public void DoPerTurnScienceUpdates(GameData gameData) {
679687 return ;
680688 }
681689
690+ CompleteResearchAndBeginNew ( gameData , tech ) ;
691+ }
692+
693+ private void CompleteResearchAndBeginNew ( GameData gameData , IEnumerable < Tech > techs ) {
694+ foreach ( Tech tech in techs ) {
695+ CompleteResearchingTech ( gameData , tech ) ;
696+ }
697+ PlayerAI . MaybePickTechToResearch ( this , gameData . techs ) ;
698+ }
699+ private void CompleteResearchAndBeginNew ( GameData gameData , Tech tech ) {
682700 CompleteResearchingTech ( gameData , tech ) ;
701+ PlayerAI . MaybePickTechToResearch ( this , gameData . techs ) ;
683702 }
684703
685704 private void CompleteResearchingTech ( GameData gameData , Tech tech ) {
0 commit comments