static bool Prefix(CommercialBuildingAI __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 = CommercialBuildingAIMod.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); }
static bool Prefix(ref int __result, CommercialBuildingAI __instance, ItemClass.Level level, Randomizer r, int width, int length) { PrefabEmployStruct visitors; // All commercial places will need visitors. CalcWorkplaces is normally called first, redirected above to include a calculation of worker visits (CalculateprefabWorkerVisit). // However, there is a problem with some converted assets that don't come through the "front door" (i.e. Ploppable RICO - see below). // Try to retrieve previously calculated value. if (!DataStore.prefabWorkerVisit.TryGetValue(__instance.m_info.gameObject.GetHashCode(), out visitors)) { // If we didn't get a value, most likely it was because the prefab wasn't properly initialised. // This can happen with Ploppable RICO when the underlying asset class isn't 'Default' (for example, where Ploppable RICO assets are originally Parks, Plazas or Monuments). // When that happens, the above line returns zero, which sets the building to 'Not Operating Properly'. // So, if the call returns false, we force a recalculation of workplace visits to make sure. // If it's still zero after this, then we'll just return a "legitimate" zero. visitors.visitors = 0; int[] array = CommercialBuildingAIMod.GetArray(__instance.m_info, (int)level); AI_Utils.CalculateprefabWorkerVisit(width, length, ref __instance.m_info, 4, ref array, out visitors); DataStore.prefabWorkerVisit.Add(__instance.m_info.gameObject.GetHashCode(), visitors); // Log this to help identify specific issues. Should only occur once per prefab. Debugging.Message("CalculateprefabWorkerVisit redux: " + __instance.m_info.name); } // Original method return value. __result = visitors.visitors; // Don't execute base method after this. return(false); }
static bool Prefix(ref int __result, ResidentialBuildingAI __instance, ItemClass.Level level, Randomizer r, int width, int length) { BuildingInfo item = __instance.m_info; int returnValue = 0; if (!DataStore.prefabHouseHolds.TryGetValue(item.gameObject.GetHashCode(), out returnValue)) { int[] array = ResidentialBuildingAIMod.GetArray(__instance.m_info, (int)level); returnValue = AI_Utils.CalculatePrefabHousehold(width, length, ref item, ref array, (int)level); DataStore.prefabHouseHolds.Add(item.gameObject.GetHashCode(), returnValue); } // Original method return value. __result = returnValue; // Don't execute base method after this. return(false); }
static bool Prefix(IndustrialExtractorAI __instance, ItemClass.Level level, Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3) { BuildingInfo item = __instance.m_info; PrefabEmployStruct output; // If not seen prefab, calculate if (!DataStore.prefabWorkerVisit.TryGetValue(item.gameObject.GetHashCode(), out output)) { int[] array = IndustrialExtractorAIMod.GetArray(item, IndustrialExtractorAIMod.EXTRACT_LEVEL); AI_Utils.CalculateprefabWorkerVisit(width, length, ref item, 3, 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); }
/// <summary> /// Sets the customised number of workers for a given prefab. /// If a record doesn't already exist, a new one will be created. /// </summary> /// <param name="prefab">The prefab (BuildingInfo) to set</param> /// <param name="workers">The updated worker count</param> public static void SetWorker(BuildingInfo prefab, int workers) { // Update or add entry to configuration file cache. if (DataStore.workerCache.ContainsKey(prefab.name)) { // Prefab already has a record; update. DataStore.workerCache[prefab.name] = workers; } else { // Prefab doesn't already have a record; create. DataStore.workerCache.Add(prefab.name, workers); } // Save the updated configuration file. XMLUtilsWG.WriteToXML(); // Get current building hash (for updating prefab dictionary). var prefabHash = prefab.gameObject.GetHashCode(); // Calculate employment breakdown. int[] array = CommercialBuildingAIMod.GetArray(prefab, (int)prefab.GetClassLevel()); PrefabEmployStruct output = new PrefabEmployStruct(); AI_Utils.CalculateprefabWorkerVisit(prefab.GetWidth(), prefab.GetLength(), ref prefab, 4, ref array, out output); // Update entry in 'live' settings. if (DataStore.prefabWorkerVisit.ContainsKey(prefabHash)) { // Prefab already has a record; update. DataStore.prefabWorkerVisit[prefabHash] = output; } else { // Prefab doesn't already have a record; create. DataStore.prefabWorkerVisit.Add(prefabHash, output); } }
static bool Prefix(OfficeBuildingAI __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; int[] array = OfficeBuildingAIMod.GetArray(__instance.m_info, (int)level); PrefabEmployStruct output; // If not seen prefab, calculate if (!DataStore.prefabWorkerVisit.TryGetValue(item.gameObject.GetHashCode(), out output)) { AI_Utils.CalculateprefabWorkerVisit(width, length, ref item, 10, 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); }