Skip to content

Commit

Permalink
Added Embark ability which lets land units to embark when moving on w…
Browse files Browse the repository at this point in the history
…ater, without using a port.
  • Loading branch information
johnklipi committed Jun 23, 2024
1 parent f5ca312 commit 3fd597b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
42 changes: 38 additions & 4 deletions PolyPlusPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace PolyPlus {
public class PolyPlusPatcher
{
private static string version = "0.0.8";
private static string branch = "main";
private static string version = "0.0.9";
private static string branch = "waterembark";
private static int _polyplusAutoidx = 480;
private static Dictionary<string, int> _polyplusDict = new Dictionary<string, int>();
public static void Load()
Expand All @@ -21,8 +21,8 @@ public static void Load()

internal static void CreateEnumCaches()
{
//EnumCache<PlayerAbility.Type>.AddMapping("waterembarking", (PlayerAbility.Type)750);
//EnumCache<PlayerAbility.Type>.AddMapping("waterembarking", (PlayerAbility.Type)750);
EnumCache<PlayerAbility.Type>.AddMapping("waterembark", (PlayerAbility.Type)750);
EnumCache<PlayerAbility.Type>.AddMapping("waterembark", (PlayerAbility.Type)750);
EnumCache<UnitAbility.Type>.AddMapping("polyplusstatic", (UnitAbility.Type)_polyplusAutoidx);
EnumCache<UnitAbility.Type>.AddMapping("polyplusstatic", (UnitAbility.Type)_polyplusAutoidx);
_polyplusDict.Add("polyplusstatic", _polyplusAutoidx);
Expand Down Expand Up @@ -66,6 +66,40 @@ private static void UnitPopup_UnitData_Set(UnitPopup __instance)
}
}

[HarmonyPostfix]
[HarmonyPatch(typeof(PathFinder), nameof(PathFinder.IsTileAccessible))]
private static void PathFinder_IsTileAccessible(ref bool __result, TileData tile, TileData origin, PathFinderSettings settings)
{
if(PlayerExtensions.HasAbility(settings.playerState, (PlayerAbility.Type)750, settings.gameState) && tile.IsWater && (!origin.IsWater || settings.unit != null)){
if(settings.allowedTerrain.Contains(tile.terrain) && tile.GetExplored(settings.playerState.Id)){
__result = true;
}
else{
__result = false;
}
}
}

[HarmonyPostfix]
[HarmonyPatch(typeof(MoveAction), nameof(MoveAction.ExecuteDefault))]
private static void MoveAction_ExecuteDefault(MoveAction __instance, GameState gameState)
{
UnitState unitState;
PlayerState playerState;
UnitData unitData;
if (gameState.TryGetUnit(__instance.UnitId, out unitState) && gameState.TryGetPlayer(__instance.PlayerId, out playerState) && gameState.GameLogicData.TryGetData(unitState.type, out unitData))
{
WorldCoordinates worldCoordinates = __instance.Path[0];
TileData tile2 = gameState.Map.GetTile(worldCoordinates);
tile2.SetUnit(unitState);
unitState.coordinates = worldCoordinates;
if (!unitData.IsAquatic() && !unitState.HasAbility(UnitAbility.Type.Fly, gameState) && tile2.IsWater && PlayerExtensions.HasAbility(playerState, (PlayerAbility.Type)750, gameState))
{
gameState.ActionStack.Add(new EmbarkAction(__instance.PlayerId, worldCoordinates));
}
}
}

internal static string GetJTokenName(JToken token, int n = 1)
{
return token.Path.Split('.')[^n];
Expand Down
10 changes: 8 additions & 2 deletions patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@
"techUnlocks": [
"navigation"
],
"improvementUnlocks": [
"port"
"abilityUnlocks": [
"waterembark"
],
"unitUnlocks": [
"scoutship"
Expand Down Expand Up @@ -703,6 +703,12 @@
],
"technology_names_aquanavigation": [
"Navigation"
],
"player_abilities_waterembark": [
"Embark"
],
"tooltip_ability_waterembark": [
"Allows land units to move on water and to turn into boats."
]
}
}

0 comments on commit 3fd597b

Please sign in to comment.