Ejemplo n.º 1
0
        /*
         * For resources (including work) that are part of the cost of both the road to build and the best existing road,
         * grant CostUpgradeRebate% (default 30%) of the best existing road build costs as a rebate on the costs of the road to be built
         * i.e. the exisitng road cost 300 stones, the new road cost 600 stones, the rebate is 300*30% = 90 stones
         */
        public static void GetUpgradeModifiers(int fromTile_int, int toTile_int, RoadDef roadToBuild, out Dictionary <string, int> rebate)
        {
            rebate = new Dictionary <string, int>();
            RoadDef bestExistingRoad = RoadsOfTheRim.BestExistingRoad(fromTile_int, toTile_int);

            if (bestExistingRoad != null)
            {
                DefModExtension_RotR_RoadDef bestExistingRoadDefModExtension = bestExistingRoad.GetModExtension <DefModExtension_RotR_RoadDef>();
                DefModExtension_RotR_RoadDef roadToBuildRoadDefModExtension  = roadToBuild.GetModExtension <DefModExtension_RotR_RoadDef>();
                if (bestExistingRoadDefModExtension != null && roadToBuildRoadDefModExtension != null && RoadsOfTheRim.isRoadBetter(roadToBuild, bestExistingRoad))
                {
                    foreach (string resourceName in DefModExtension_RotR_RoadDef.allResourcesAndWork)
                    {
                        int existingCost = bestExistingRoadDefModExtension.GetCost(resourceName);
                        int toBuildCost  = roadToBuildRoadDefModExtension.GetCost(resourceName);
                        if (existingCost != 0 && toBuildCost != 0)
                        {
                            if ((int)(existingCost * (float)RoadsOfTheRim.settings.CostUpgradeRebate / 100) > toBuildCost)
                            {
                                rebate[resourceName] = toBuildCost;
                            }
                            else
                            {
                                rebate[resourceName] = (int)(existingCost * (float)RoadsOfTheRim.settings.CostUpgradeRebate / 100);
                            }
                        }
                    }
                }
            }
        }
        public static void PostFix(ref float __result, int tile, bool perceivedStatic, int?ticksAbs,
                                   StringBuilder explanation)
        {
            if (__result <= 999f || !Find.WorldGrid.InBounds(tile))
            {
                return;
            }

            try
            {
                var tile2 = Find.WorldGrid[tile];
                if (tile2.Roads == null)
                {
                    return;
                }

                RoadDef BestRoad = null;
                foreach (var roadLink in tile2.Roads)
                {
                    var currentRoad = roadLink.road;
                    if (currentRoad == null)
                    {
                        continue;
                    }

                    if (BestRoad == null)
                    {
                        BestRoad = currentRoad;
                        continue;
                    }

                    if (BestRoad.movementCostMultiplier < currentRoad.movementCostMultiplier)
                    {
                        BestRoad = roadLink.road;
                    }
                }

                var roadDefExtension = BestRoad?.GetModExtension <DefModExtension_RotR_RoadDef>();
                if (roadDefExtension == null)
                {
                    return;
                }

                if ((!tile2.biome.impassable || !(roadDefExtension.biomeModifier > 0)) &&
                    tile2.hilliness != Hilliness.Impassable)
                {
                    return;
                }

                __result = 12f;
                RoadsOfTheRim.DebugLog(
                    $"[RotR] - Impassable Tile {tile} of biome {tile2.biome.label} movement difficulty patched to 12");
            }
            catch (Exception e)
            {
                RoadsOfTheRim.DebugLog(
                    $"[RotR] - CalculatedMovementDifficultyAt Patch - Catastrophic failure for tile {Find.WorldGrid[tile]}",
                    e);
            }
        }
Ejemplo n.º 3
0
        public static float calculateRoadModifier(RoadDef roadDef, float BiomeMovementDifficulty, float HillinessOffset, float WinterOffset, out float BiomeModifier, out float HillModifier, out float WinterModifier)
        {
            BiomeModifier  = 0f;
            HillModifier   = 0f;
            WinterModifier = 0f;
            if (roadDef.HasModExtension <DefModExtension_RotR_RoadDef>())
            {
                BiomeModifier  = roadDef.GetModExtension <DefModExtension_RotR_RoadDef>().biomeModifier;
                HillModifier   = roadDef.GetModExtension <DefModExtension_RotR_RoadDef>().hillinessModifier;
                WinterModifier = roadDef.GetModExtension <DefModExtension_RotR_RoadDef>().winterModifier;
            }
            float BiomeCoef = (1 + (BiomeMovementDifficulty - 1) * (1 - BiomeModifier)) / BiomeMovementDifficulty;

            //RoadsOfTheRim.DebugLog("calculateRoadModifier: BiomeCoef=" +BiomeCoef+ ", BiomeMovementDifficulty="+ BiomeMovementDifficulty+ ", HillModifier"+ HillModifier+ ", HillinessOffset="+ HillinessOffset+ ", WinterModifier="+ WinterModifier+ ", WinterOffset="+ WinterOffset);
            return(((BiomeCoef * BiomeMovementDifficulty) + ((1 - HillModifier) * HillinessOffset) + ((1 - WinterModifier) * WinterOffset)) / (BiomeMovementDifficulty + HillinessOffset + WinterOffset));
        }
Ejemplo n.º 4
0
        public static bool ImpassableAllowed(int tile, RoadDef roadDef)
        {
            DefModExtension_RotR_RoadDef RoadDefMod = roadDef.GetModExtension <DefModExtension_RotR_RoadDef>();
            Hilliness hillinnessHere = Find.WorldGrid.tiles[tile].hilliness;

            if (RoadDefMod.canBuildOnImpassable && hillinnessHere == Hilliness.Impassable)
            {
                return(true);
            }
            return(hillinnessHere != Hilliness.Impassable);
        }
Ejemplo n.º 5
0
        public static bool BiomeAllowed(int tile, RoadDef roadDef, out BiomeDef biomeHere)
        {
            DefModExtension_RotR_RoadDef RoadDefMod = roadDef.GetModExtension <DefModExtension_RotR_RoadDef>();

            biomeHere = Find.WorldGrid.tiles[tile].biome;
            if (RoadDefMod.canBuildOnWater && (biomeHere.defName == "Ocean" || biomeHere.defName == "Lake"))
            {
                return(true);
            }
            return(biomeHere.allowRoads);
        }
Ejemplo n.º 6
0
 public static void PostFix(ref float __result, int tile, bool perceivedStatic, int?ticksAbs, StringBuilder explanation)
 {
     if (__result > 999f)
     {
         try
         {
             if (Find.WorldGrid.InBounds(tile))
             {
                 Tile tile2 = Find.WorldGrid.tiles[tile];
                 List <Tile.RoadLink> roads = tile2.Roads;
                 if (roads?.Count > 0)
                 {
                     RoadDef BestRoad = null;
                     for (int i = 0; i < roads.Count; i++)
                     {
                         if (BestRoad == null)
                         {
                             BestRoad = roads[i].road;
                         }
                         else
                         {
                             if (BestRoad.movementCostMultiplier < roads[i].road.movementCostMultiplier)
                             {
                                 BestRoad = roads[i].road;
                             }
                         }
                     }
                     if (BestRoad != null)
                     {
                         DefModExtension_RotR_RoadDef roadDefExtension = BestRoad.GetModExtension <DefModExtension_RotR_RoadDef>();
                         if (roadDefExtension != null && ((tile2.biome.impassable && roadDefExtension.biomeModifier > 0) || (tile2.hilliness == Hilliness.Impassable)))
                         {
                             __result = 12f;
                             //RoadsOfTheRim.DebugLog(String.Format("[RotR] - Impassable Tile {0} of biome {1} movement difficulty patched to 12", tile , tile2.biome.label));
                         }
                     }
                 }
             }
             else
             {
                 RoadsOfTheRim.DebugLog("[RotR] - CalculatedMovementDifficultyAt Patch - Tile out of bounds");
             }
         }
         catch (Exception e)
         {
             RoadsOfTheRim.DebugLog("[RotR] - CalculatedMovementDifficultyAt Patch - Catastrophic failure", e);
             return;
         }
     }
 }
        /*
         * For resources (including work) that are part of the cost of both the road to build and the best existing road,
         * grant CostUpgradeRebate% (default 30%) of the best existing road build costs as a rebate on the costs of the road to be built
         * i.e. the exisitng road cost 300 stones, the new road cost 600 stones, the rebate is 300*30% = 90 stones
         */
        private static void GetUpgradeModifiers(int fromTile_int, int toTile_int, RoadDef roadToBuild,
                                                out Dictionary <string, int> rebate)
        {
            rebate = new Dictionary <string, int>();
            var bestExistingRoad = RoadsOfTheRim.BestExistingRoad(fromTile_int, toTile_int);

            if (bestExistingRoad == null)
            {
                return;
            }

            var bestExistingRoadDefModExtension = bestExistingRoad.GetModExtension <DefModExtension_RotR_RoadDef>();
            var roadToBuildRoadDefModExtension  = roadToBuild.GetModExtension <DefModExtension_RotR_RoadDef>();

            if (bestExistingRoadDefModExtension == null || roadToBuildRoadDefModExtension == null ||
                !RoadsOfTheRim.IsRoadBetter(roadToBuild, bestExistingRoad))
            {
                return;
            }

            foreach (var resourceName in DefModExtension_RotR_RoadDef.allResourcesAndWork)
            {
                var existingCost = bestExistingRoadDefModExtension.GetCost(resourceName);
                var toBuildCost  = roadToBuildRoadDefModExtension.GetCost(resourceName);
                if (existingCost == 0 || toBuildCost == 0)
                {
                    continue;
                }

                if ((int)(existingCost * (float)RoadsOfTheRim.settings.CostUpgradeRebate / 100) > toBuildCost)
                {
                    rebate[resourceName] = toBuildCost;
                }
                else
                {
                    rebate[resourceName] =
                        (int)(existingCost * (float)RoadsOfTheRim.settings.CostUpgradeRebate / 100);
                }
            }
        }