@@ -16,6 +16,9 @@ public static class Main
1616 internal static readonly Stopwatch stopwatch = new ( ) ;
1717 internal static bool fullyInitialized ;
1818 internal static bool dependencyCycle ;
19+ internal static Dictionary < string , string > embarkNames = new ( ) ;
20+ internal static Dictionary < UnitData . Type , UnitData . Type > embarkOverrides = new ( ) ;
21+ internal static bool currentlyEmbarking = false ;
1922
2023
2124 [ HarmonyPrefix ]
@@ -30,6 +33,20 @@ private static void GameLogicData_Parse(GameLogicData __instance, JObject rootOb
3033 if ( skin . skinData != null )
3134 __instance . skinData [ ( SkinType ) skin . idx ] = skin . skinData ;
3235 }
36+ foreach ( KeyValuePair < string , string > entry in embarkNames )
37+ {
38+ try
39+ {
40+ UnitData . Type unit = EnumCache < UnitData . Type > . GetType ( entry . Key ) ;
41+ UnitData . Type newUnit = EnumCache < UnitData . Type > . GetType ( entry . Value ) ;
42+ embarkOverrides [ unit ] = newUnit ;
43+ Plugin . logger . LogInfo ( $ "Embark unit type for { entry . Key } is now { entry . Value } ") ;
44+ }
45+ catch
46+ {
47+ Plugin . logger . LogError ( $ "Embark unit type for { entry . Key } is not valid: { entry . Value } ") ;
48+ }
49+ }
3350 fullyInitialized = true ;
3451 }
3552 }
@@ -131,7 +148,7 @@ private static void GameModeScreen_Init(GameModeScreen __instance)
131148
132149 [ HarmonyPrefix ]
133150 [ HarmonyPatch ( typeof ( TechView ) , nameof ( TechView . CreateNode ) ) ]
134- public static bool TechView_CreateNode ( TechView __instance , TechData data , TechItem parentItem , float angle ) {
151+ private static bool TechView_CreateNode ( TechView __instance , TechData data , TechItem parentItem , float angle ) {
135152 float baseAngle = 360 / GameManager . GameState . GameLogicData . GetTechData ( TechData . Type . Basic ) . techUnlocks . Count ;
136153 float childAngle = 0f ;
137154 if ( parentItem != null )
@@ -163,6 +180,37 @@ public static bool TechView_CreateNode(TechView __instance, TechData data, TechI
163180 return false ;
164181 }
165182
183+ [ HarmonyPrefix ]
184+ [ HarmonyPatch ( typeof ( EmbarkAction ) , nameof ( EmbarkAction . Execute ) ) ]
185+ private static bool EmbarkAction_Execute_Prefix ( EmbarkAction __instance , GameState gameState )
186+ {
187+ currentlyEmbarking = true ;
188+ return true ;
189+ }
190+
191+ [ HarmonyPrefix ]
192+ [ HarmonyPatch ( typeof ( ActionUtils ) , nameof ( ActionUtils . TrainUnit ) ) ]
193+ private static bool ActionUtils_TrainUnit ( ref UnitState __result , GameState gameState , PlayerState playerState , TileData tile , ref UnitData unitData )
194+ {
195+ if ( tile == null )
196+ {
197+ return true ;
198+ }
199+ if ( tile . unit == null )
200+ {
201+ return true ;
202+ }
203+ if ( currentlyEmbarking )
204+ {
205+ if ( embarkOverrides . TryGetValue ( tile . unit . type , out UnitData . Type newType ) )
206+ {
207+ gameState . GameLogicData . TryGetData ( newType , out unitData ) ;
208+ }
209+ currentlyEmbarking = false ;
210+ }
211+ return true ;
212+ }
213+
166214 internal static void Init ( )
167215 {
168216 stopwatch . Start ( ) ;
0 commit comments