public void setCosts() { try { RoadsOfTheRimSettings settings = LoadedModManager.GetMod <RoadsOfTheRim>().GetSettings <RoadsOfTheRimSettings>(); RoadConstructionSite parentSite = this.parent as RoadConstructionSite; float elevationModifier = 0f; float hillinessModifier = 0f; float swampinessModifier = 0f; float bridgeModifier = 0f; GetCostsModifiers(parentSite.Tile, parentSite.GetNextLeg().Tile, ref elevationModifier, ref hillinessModifier, ref swampinessModifier, ref bridgeModifier); // Total cost modifier float totalCostModifier = (1 + elevationModifier + hillinessModifier + swampinessModifier + bridgeModifier) * ((float)settings.BaseEffort / 10); DefModExtension_RotR_RoadDef roadDefExtension = parentSite.roadDef.GetModExtension <DefModExtension_RotR_RoadDef>(); // Check existing roads for potential rebates when upgrading GetUpgradeModifiers(parentSite.Tile, parentSite.GetNextLeg().Tile, parentSite.roadDef, out Dictionary <string, int> rebate); List <string> s = new List <string>(); foreach (string resourceName in DefModExtension_RotR_RoadDef.allResourcesAndWork) { if (roadDefExtension.GetCost(resourceName) > 0) { int thisRebate = 0; // The cost modifier doesn't affect some advanced resources, as defined in static DefModExtension_RotR_RoadDef.allResourcesWithoutModifiers float costModifierForThisResource = ((DefModExtension_RotR_RoadDef.allResourcesWithoutModifiers.Contains(resourceName)) ? 1 : totalCostModifier); rebate.TryGetValue(resourceName, out thisRebate); // Minimum cost of anything that's needed is 1 costs[resourceName] = Math.Max((int)((roadDefExtension.GetCost(resourceName) - thisRebate) * costModifierForThisResource), 1); left[resourceName] = Math.Max(costs[resourceName], 1f); if (thisRebate > 0) { s.Add("RoadsOfTheRim_UpgradeRebateDetail".Translate((int)(thisRebate * costModifierForThisResource), resourceName)); } } } if (s.Count > 0) { Messages.Message("RoadsOfTheRim_UpgradeRebate".Translate(parentSite.roadDef.label, string.Join(", ", s.ToArray())), MessageTypeDefOf.PositiveEvent); } parentSite.UpdateProgressBarMaterial(); } catch (Exception e) { Log.Error("[RotR] : Exception when setting constructionSite costs = " + e); } }
/* return a string describing modifiers to road costs building between two tiles, and sets totalCostModifer */ public static string CostModifersDescription(int fromTile_int, int toTile_int, ref float totalCostModifier) { StringBuilder result = new StringBuilder(); RoadsOfTheRimSettings settings = LoadedModManager.GetMod <RoadsOfTheRim>().GetSettings <RoadsOfTheRimSettings>(); // Show total cost modifiers float elevationModifier = 0f; float hillinessModifier = 0f; float swampinessModifier = 0f; float bridgeModifier = 0f; WorldObjectComp_ConstructionSite.GetCostsModifiers(fromTile_int, toTile_int, ref elevationModifier, ref hillinessModifier, ref swampinessModifier, ref bridgeModifier); result.Append("RoadsOfTheRim_ConstructionSiteDescription_CostModifiers".Translate( String.Format("{0:P0}", elevationModifier + hillinessModifier + swampinessModifier + bridgeModifier), String.Format("{0:P0}", elevationModifier), String.Format("{0:P0}", hillinessModifier), String.Format("{0:P0}", swampinessModifier), String.Format("{0:P0}", bridgeModifier) )); totalCostModifier = (1 + elevationModifier + hillinessModifier + swampinessModifier + bridgeModifier) * ((float)settings.BaseEffort / 10); return(result.ToString()); }
/* * Returns the cost modifiers for building a road from one tile to another, based on Elevation, Hilliness, Swampiness & river crossing */ public static void GetCostsModifiers(int fromTile_int, int toTile_int, ref float elevationModifier, ref float hillinessModifier, ref float swampinessModifier, ref float bridgeModifier) { try { RoadsOfTheRimSettings settings = LoadedModManager.GetMod <RoadsOfTheRim>().GetSettings <RoadsOfTheRimSettings>(); Tile fromTile = Find.WorldGrid[fromTile_int]; Tile toTile = Find.WorldGrid[toTile_int]; // Cost increase from elevation : if elevation is above {CostIncreaseElevationThreshold} (default 1000m), cost is doubled every {ElevationCostDouble} (default 2000m) elevationModifier = ((fromTile.elevation <= settings.CostIncreaseElevationThreshold) ? 0 : (fromTile.elevation - settings.CostIncreaseElevationThreshold) / RoadsOfTheRimSettings.ElevationCostDouble); elevationModifier += ((toTile.elevation <= settings.CostIncreaseElevationThreshold) ? 0 : (toTile.elevation - settings.CostIncreaseElevationThreshold) / RoadsOfTheRimSettings.ElevationCostDouble); // Hilliness and swampiness are the average between that of the from & to tiles // Hilliness is 0 on flat terrain, never negative. It's between 0 (flat) and 5(Impassable) float hilliness = Math.Max((((float)fromTile.hilliness + (float)toTile.hilliness) / 2) - 1, 0); float swampiness = (fromTile.swampiness + toTile.swampiness) / 2; // Hilliness and swampiness double the costs when they equal {HillinessCostDouble} (default 4) and {SwampinessCostDouble} (default 0.5) hillinessModifier = hilliness / RoadsOfTheRimSettings.HillinessCostDouble; swampinessModifier = swampiness / RoadsOfTheRimSettings.SwampinessCostDouble; bridgeModifier = 0f; /* TO DO : River crossing * List<int> fromTileNeighbors = new List<int>(); * Find.WorldGrid.GetTileNeighbors(parent.Tile, fromTileNeighbors); * foreach (Tile.RiverLink aRiver in fromTile.Rivers ) * { * Log.Message("River in FROM tile : neighbor="+aRiver.neighbor+", river="+aRiver.river.ToString()); * } */ } catch (Exception e) { RoadsOfTheRim.DebugLog(null, e); } }
public int useISR2G() { int result = 0; RoadsOfTheRimSettings settings = LoadedModManager.GetMod <RoadsOfTheRim>().GetSettings <RoadsOfTheRimSettings>(); // Setting the caravan to use ISR2G or AISR2G if present and settings allow it // TO DO : I can do better than hardcode if (settings.useISR2G) { foreach (Thing aThing in CaravanInventoryUtility.AllInventoryItems(this.GetCaravan())) { if (result < 1 && aThing.GetInnerIfMinified().def.defName == "RotR_ISR2GNew") { result = 1; } if (result < 2 && aThing.GetInnerIfMinified().def.defName == "RotR_AISR2GNew") { result = 2; return(result); } } } return(result); }
public RoadsOfTheRim(ModContentPack content) : base(content) { settings = GetSettings <RoadsOfTheRimSettings>(); }