static bool Prefix(IndustrialBuildingAI __instance, ItemClass.Level level, Randomizer r, int productionRate, out int electricityConsumption, out int waterConsumption, out int sewageAccumulation, out int garbageAccumulation, out int incomeAccumulation, out int mailAccumulation) { ItemClass item = __instance.m_info.m_class; int[] array = IndustrialBuildingAIMod.GetArray(__instance.m_info, (int)level); electricityConsumption = array[DataStore.POWER]; waterConsumption = array[DataStore.WATER]; sewageAccumulation = array[DataStore.SEWAGE]; garbageAccumulation = array[DataStore.GARBAGE]; mailAccumulation = array[DataStore.MAIL]; int landVal = AI_Utils.GetLandValueIncomeComponent(r.seed); incomeAccumulation = array[DataStore.INCOME] + landVal; electricityConsumption = Mathf.Max(100, productionRate * electricityConsumption) / 100; waterConsumption = Mathf.Max(100, productionRate * waterConsumption) / 100; sewageAccumulation = Mathf.Max(100, productionRate * sewageAccumulation) / 100; garbageAccumulation = Mathf.Max(100, productionRate * garbageAccumulation) / 100; incomeAccumulation = productionRate * incomeAccumulation; mailAccumulation = Mathf.Max(100, productionRate * mailAccumulation) / 100; // Don't execute base method after this. return(false); }
/// <summary> /// Pre-emptive Harmony Prefix patch for IndustrialBuildingAI.GetConsumptionRates, to implement the mod's consumption calculations. /// </summary> /// <param name="__instance">AI instance reference</param> /// <param name="level">Building level</param> /// <param name="r">Randomizer</param> /// <param name="productionRate">Building production rate</param> /// <param name="electricityConsumption">Building electricity consumption</param> /// <param name="waterConsumption">Building water consumption</param> /// <param name="sewageAccumulation">Building sewage accumulation</param> /// <param name="garbageAccumulation">Building garbage accumulation</param> /// <param name="incomeAccumulation">Building income accumulation</param> /// <param name="mailAccumulation">Building mail accumulation</param> /// <returns>Always false (never execute original method)</returns> public static bool Prefix(IndustrialBuildingAI __instance, ItemClass.Level level, Randomizer r, int productionRate, out int electricityConsumption, out int waterConsumption, out int sewageAccumulation, out int garbageAccumulation, out int incomeAccumulation, out int mailAccumulation) { // Get relevant array from datastore. int[] array = LegacyAIUtils.GetIndustryArray(__instance.m_info, (int)level); // Get consumption rates from array. electricityConsumption = array[DataStore.POWER]; waterConsumption = array[DataStore.WATER]; sewageAccumulation = array[DataStore.SEWAGE]; garbageAccumulation = array[DataStore.GARBAGE]; mailAccumulation = array[DataStore.MAIL]; // Calculate land value. int landValue = LegacyAIUtils.GetLandValueIncomeComponent(r.seed); incomeAccumulation = array[DataStore.INCOME] + landValue; // Apply consumption rates. electricityConsumption = Mathf.Max(100, productionRate * electricityConsumption) / 100; waterConsumption = Mathf.Max(100, productionRate * waterConsumption) / 100; sewageAccumulation = Mathf.Max(100, productionRate * sewageAccumulation) / 100; garbageAccumulation = Mathf.Max(100, productionRate * garbageAccumulation) / 100; incomeAccumulation = productionRate * incomeAccumulation; mailAccumulation = Mathf.Max(100, productionRate * mailAccumulation) / 100; // Don't execute base method after this. return(false); }
/// <summary> /// Harmony Prefix patch to IndustrialBuildingAI.CalculateProductionCapacity to implement mod production calculations. /// </summary> /// <param name="__result">Original method result</param> /// <param name="__instance">Original AI instance reference</param> /// <param name="level">Building level</param> /// <returns>False (don't execute base game method after this)</returns> public static bool Prefix(ref int __result, IndustrialBuildingAI __instance, ItemClass.Level level, int width, int length) { // Get builidng info. BuildingInfo info = __instance.m_info; ItemClass.SubService subService = info.GetSubService(); // Array index. int arrayIndex = GetIndex(subService); // New or old method? if (prodModes[arrayIndex] == (int)ProdModes.popCalcs) { // New settings, based on population. float multiplier; switch (info.GetClassLevel()) { case ItemClass.Level.Level1: multiplier = 1f; break; case ItemClass.Level.Level2: multiplier = 0.933333f; break; default: multiplier = 0.8f; break; } // Get cached workplace count and calculate total workplaces. int[] workplaces = PopData.instance.WorkplaceCache(info, (int)level); float totalWorkers = workplaces[0] + workplaces[1] + workplaces[2] + workplaces[3]; // Multiply total workers by multipler and overall multiplier (from settings) to get result. __result = (int)((totalWorkers * multiplier * prodMults[arrayIndex]) / 100f); } else { // Legacy calcs. int[] array = LegacyAIUtils.GetIndustryArray(__instance.m_info, (int)level); // Original method return value. __result = Mathf.Max(100, width * length * array[DataStore.PRODUCTION]) / 100; } // Always set at least one. if (__result < 1) { Logging.Error("invalid production result ", __result.ToString(), " for ", __instance.m_info.name, "; setting to 1"); __result = 1; } // Don't execute base method after this. return(false); }
public static bool Prefix(IndustrialBuildingAI __instance, ItemClass.Level level, int productionRate, out int groundPollution, out int noisePollution) { int[] array = LegacyAIUtils.GetIndustryArray(__instance.m_info, (int)level); groundPollution = (productionRate * array[DataStore.GROUND_POLLUTION]) / 100; noisePollution = (productionRate * array[DataStore.NOISE_POLLUTION]) / 100; // Don't execute base method after this. return(false); }
static bool Prefix(ref int __result, IndustrialBuildingAI __instance, ItemClass.Level level, Randomizer r, int width, int length) { ItemClass @class = __instance.m_info.m_class; int[] array = IndustrialBuildingAIMod.GetArray(__instance.m_info, (int)level); // Original method return value. __result = Mathf.Max(100, width * length * array[DataStore.PRODUCTION]) / 100; // Don't execute base method after this. return(false); }
static bool Prefix(IndustrialBuildingAI __instance, ItemClass.Level level, int productionRate, DistrictPolicies.CityPlanning cityPlanningPolicies, out int groundPollution, out int noisePollution) { ItemClass @class = __instance.m_info.m_class; groundPollution = 0; noisePollution = 0; int[] array = IndustrialBuildingAIMod.GetArray(__instance.m_info, (int)level); groundPollution = (productionRate * array[DataStore.GROUND_POLLUTION]) / 100; noisePollution = (productionRate * array[DataStore.NOISE_POLLUTION]) / 100; // Don't execute base method after this. return(false); }
static bool Prefix(IndustrialBuildingAI __instance, ItemClass.Level level, Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3) { ulong seed = r.seed; BuildingInfo item = __instance.m_info; PrefabEmployStruct output; // If not seen prefab, calculate if (!DataStore.prefabWorkerVisit.TryGetValue(item.gameObject.GetHashCode(), out output)) { int[] array = IndustrialBuildingAIMod.GetArray(item, (int)level); AI_Utils.CalculateprefabWorkerVisit(width, length, ref item, 4, ref array, out output); DataStore.prefabWorkerVisit.Add(item.gameObject.GetHashCode(), output); } level0 = output.level0; level1 = output.level1; level2 = output.level2; level3 = output.level3; // Don't execute base method after this. return(false); }