public static void ProcessCityResourceDepartmentBuildingGoods(ushort buildingID, ref Building buildingData) { int reduceCargoDiv = 1; if (Loader.isRealCityRunning) { RealCityUtil.InitDelegate(); reduceCargoDiv = RealCityUtil.GetReduceCargoDiv(); } int materialConsumption = 40 / reduceCargoDiv; if (buildingData.m_fireIntensity == 0 && buildingData.m_flags.IsFlagSet(Building.Flags.Completed)) { if (MainDataStore.lumberBuffer[buildingID] > materialConsumption && MainDataStore.coalBuffer[buildingID] > materialConsumption && MainDataStore.constructionResourceBuffer[buildingID] < 64000) { if (MainDataStore.resourceCategory[buildingID] == 1 || MainDataStore.resourceCategory[buildingID] == 2) { MainDataStore.lumberBuffer[buildingID] -= (ushort)materialConsumption; MainDataStore.coalBuffer[buildingID] -= (ushort)materialConsumption; MainDataStore.constructionResourceBuffer[buildingID] += 800; } } if (MainDataStore.petrolBuffer[buildingID] > materialConsumption && MainDataStore.foodBuffer[buildingID] > materialConsumption && MainDataStore.operationResourceBuffer[buildingID] < 64000) { if (MainDataStore.resourceCategory[buildingID] == 1 || MainDataStore.resourceCategory[buildingID] == 3) { MainDataStore.petrolBuffer[buildingID] -= (ushort)materialConsumption; MainDataStore.foodBuffer[buildingID] -= (ushort)materialConsumption; MainDataStore.operationResourceBuffer[buildingID] += 800; } } } }
public static void ProcessDeadmoveIncomeArriveAtTarget(ref Vehicle data, int num) { BuildingManager instance = Singleton <BuildingManager> .instance; Building building = instance.m_buildings.m_buffer[(int)data.m_sourceBuilding]; if ((data.m_flags & Vehicle.Flags.TransferToTarget) != (Vehicle.Flags) 0) { if (building.m_flags.IsFlagSet(Building.Flags.Untouchable)) { if ((data.m_flags & Vehicle.Flags.Importing) != (Vehicle.Flags) 0) { if (Loader.isRealCityRunning) { double x = instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_position.x - instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].m_position.x; double z = instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_position.z - instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].m_position.z; x = (x > 0) ? x : -x; z = (z > 0) ? z : -z; double distance = (x + z); int money = (int)(num * distance); Singleton <EconomyManager> .instance.AddPrivateIncome(money, ItemClass.Service.HealthCare, ItemClass.SubService.None, ItemClass.Level.Level3, 115333); if (Loader.isRealCityV10) { RealCityUtil.InitDelegate(); if (RealCityUtil.GetRealCityV10()) { RealCityUtil.SetOutsideGovermentMoney(RealCityUtil.GetOutsideGovermentMoney() - money); } } } } } } }
public static void Prefix(ushort vehicleID, ref Vehicle vehicleData) { bool canAddCargoOffer = true; bool canAddCarOffer = true; if (Loader.isRealCityV10) { RealCityUtil.InitDelegate(); if (RealCityUtil.GetRealCityV10()) { if (RealCityUtil.GetOutsideGovermentMoney() < 0) { canAddCargoOffer = false; } if (RealCityUtil.GetOutsideTouristMoney() < 0) { canAddCarOffer = false; } } } VehicleStatus(vehicleID, ref vehicleData, canAddCargoOffer, canAddCarOffer); }
public static void Postfix(ushort buildingID, ref Building data) { if (data.Info.m_class.m_service == ItemClass.Service.Road) { bool canAddOffer = true; if (Loader.isRealCityV10) { RealCityUtil.InitDelegate(); if (RealCityUtil.GetRealCityV10()) { if (RealCityUtil.GetOutsideGovermentMoney() < 0) { canAddOffer = false; } } } if (canAddOffer) { ProcessOutsideDemand(buildingID, ref data); AddOffers(buildingID, ref data); } } }
public static void CargoTruckAIArriveAtTargetForRealGasStationPost(ref Vehicle vehicleData) { BuildingManager instance = Singleton <BuildingManager> .instance; if (vehicleData.m_targetBuilding != 0) { Building buildingData = instance.m_buildings.m_buffer[vehicleData.m_targetBuilding]; if (!(buildingData.Info.m_buildingAI is OutsideConnectionAI)) { if (GasStationAI.IsGasBuilding(vehicleData.m_targetBuilding) == true) { switch ((TransferManager.TransferReason)vehicleData.m_transferType) { case TransferManager.TransferReason.Petrol: if (MainDataStore.petrolBuffer[vehicleData.m_targetBuilding] <= 57000) { MainDataStore.petrolBuffer[vehicleData.m_targetBuilding] += vehicleData.m_transferSize; } if (Loader.isRealCityRunning) { RealCityUtil.InitDelegate(); float productionValue = vehicleData.m_transferSize * RealCityUtil.GetResourcePrice((TransferManager.TransferReason)vehicleData.m_transferType); Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.ResourcePrice, (int)productionValue, ItemClass.Service.PlayerIndustry, ItemClass.SubService.PlayerIndustryOil, ItemClass.Level.Level1); } vehicleData.m_transferSize = 0; break; default: DebugLog.LogToFileOnly("Error: Find a import trade m_transferType = " + vehicleData.m_transferType.ToString()); break; } } } } }
public static bool Prefix(ref AmbulanceAI __instance, ushort vehicleID, ref Vehicle data, ref bool __result) { if (Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_flags.IsFlagSet(Building.Flags.Untouchable)) { if (data.m_targetBuilding == 0) { Singleton <VehicleManager> .instance.ReleaseVehicle(vehicleID); __result = true; } int num = Mathf.Min(0, (int)data.m_transferSize - __instance.m_patientCapacity); BuildingInfo info = Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)data.m_targetBuilding].Info; info.m_buildingAI.ModifyMaterialBuffer(data.m_targetBuilding, ref Singleton <BuildingManager> .instance.m_buildings.m_buffer[(int)data.m_targetBuilding], (TransferManager.TransferReason)data.m_transferType, ref num); var instance = Singleton <BuildingManager> .instance; if (instance.m_buildings.m_buffer[(int)data.m_targetBuilding].Info.m_buildingAI is OutsideConnectionAI) { if (Loader.isRealCityRunning) { double x = instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_position.x - instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].m_position.x; double z = instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_position.z - instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].m_position.z; x = (x > 0) ? x : -x; z = (z > 0) ? z : -z; double distance = (x + z); int money = (int)(-num * distance * 2f); Singleton <EconomyManager> .instance.AddPrivateIncome(money, ItemClass.Service.HealthCare, ItemClass.SubService.None, ItemClass.Level.Level3, 115333); CustomPlayerBuildingAI.canReturn[vehicleID] = true; if (Loader.isRealCityV10) { RealCityUtil.InitDelegate(); if (RealCityUtil.GetRealCityV10()) { RealCityUtil.SetOutsideGovermentMoney(RealCityUtil.GetOutsideGovermentMoney() - money); } } } } if ((instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_flags & Building.Flags.IncomingOutgoing) == Building.Flags.Incoming) { ushort num3 = instance.FindBuilding(instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_position, 200f, info.m_class.m_service, ItemClass.SubService.None, Building.Flags.Outgoing, Building.Flags.Incoming); if (num3 != 0) { BuildingInfo info3 = instance.m_buildings.m_buffer[(int)num3].Info; Randomizer randomizer = new Randomizer((int)vehicleID); Vector3 vector; Vector3 vector2; info3.m_buildingAI.CalculateSpawnPosition(num3, ref instance.m_buildings.m_buffer[(int)num3], ref randomizer, __instance.m_info, out vector, out vector2); Quaternion rotation = Quaternion.identity; Vector3 forward = vector2 - vector; if (forward.sqrMagnitude > 0.01f) { rotation = Quaternion.LookRotation(forward); } data.m_frame0 = new Vehicle.Frame(vector, rotation); data.m_frame1 = data.m_frame0; data.m_frame2 = data.m_frame0; data.m_frame3 = data.m_frame0; data.m_targetPos0 = vector; data.m_targetPos0.w = 2f; data.m_targetPos1 = vector2; data.m_targetPos1.w = 2f; data.m_targetPos2 = data.m_targetPos1; data.m_targetPos3 = data.m_targetPos1; __instance.FrameDataUpdated(vehicleID, ref data, ref data.m_frame0); __instance.SetTarget(vehicleID, ref data, 0); __result = false; } } return(false); } return(true); }
public static bool Prefix(ref GarbageTruckAI __instance, ushort vehicleID, ref Vehicle data, ref bool __result) { if (data.m_targetBuilding == 0) { __result = true; return(false); } int num = 0; if ((data.m_flags & Vehicle.Flags.TransferToTarget) != (Vehicle.Flags) 0) { num = (int)data.m_transferSize; } if ((data.m_flags & Vehicle.Flags.TransferToSource) != (Vehicle.Flags) 0) { num = Mathf.Min(0, (int)data.m_transferSize - __instance.m_cargoCapacity); } BuildingManager instance = Singleton <BuildingManager> .instance; BuildingInfo info = instance.m_buildings.m_buffer[(int)data.m_targetBuilding].Info; info.m_buildingAI.ModifyMaterialBuffer(data.m_targetBuilding, ref instance.m_buildings.m_buffer[(int)data.m_targetBuilding], (TransferManager.TransferReason)data.m_transferType, ref num); ProcessGarbageIncomeArriveAtTarget(vehicleID, ref data, num); if ((data.m_flags & Vehicle.Flags.TransferToTarget) != (Vehicle.Flags) 0) { data.m_transferSize = (ushort)Mathf.Clamp((int)data.m_transferSize - num, 0, (int)data.m_transferSize); } if ((data.m_flags & Vehicle.Flags.TransferToSource) != (Vehicle.Flags) 0) { data.m_transferSize += (ushort)Mathf.Max(0, -num); } // NON-STOCK CODE START //Go back if (data.m_sourceBuilding != 0 && (instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].m_flags & Building.Flags.IncomingOutgoing) == Building.Flags.Outgoing) { BuildingInfo info2 = instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].Info; ushort num2 = instance.FindBuilding(instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].m_position, 200f, info2.m_class.m_service, ItemClass.SubService.None, Building.Flags.Incoming, Building.Flags.Outgoing); if (num2 != 0) { instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].RemoveOwnVehicle(vehicleID, ref data); data.m_sourceBuilding = num2; instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].AddOwnVehicle(vehicleID, ref data); } } //Turn around if ((instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_flags & Building.Flags.IncomingOutgoing) == Building.Flags.Incoming) { if (Loader.isRealCityRunning) { double x = instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_position.x - instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].m_position.x; double z = instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_position.z - instance.m_buildings.m_buffer[(int)data.m_sourceBuilding].m_position.z; x = (x > 0) ? x : -x; z = (z > 0) ? z : -z; double distance = (x + z); int money = (int)(-num * (distance / 4000f)); Singleton <EconomyManager> .instance.AddPrivateIncome(money, ItemClass.Service.Garbage, ItemClass.SubService.None, ItemClass.Level.Level3, 115333); CustomPlayerBuildingAI.canReturn[vehicleID] = true; if (Loader.isRealCityV10) { RealCityUtil.InitDelegate(); if (RealCityUtil.GetRealCityV10()) { RealCityUtil.SetOutsideGovermentMoney(RealCityUtil.GetOutsideGovermentMoney() - money); } } } ushort num3 = instance.FindBuilding(instance.m_buildings.m_buffer[(int)data.m_targetBuilding].m_position, 200f, info.m_class.m_service, ItemClass.SubService.None, Building.Flags.Outgoing, Building.Flags.Incoming); if (num3 != 0) { BuildingInfo info3 = instance.m_buildings.m_buffer[(int)num3].Info; Randomizer randomizer = new Randomizer((int)vehicleID); Vector3 vector; Vector3 vector2; info3.m_buildingAI.CalculateSpawnPosition(num3, ref instance.m_buildings.m_buffer[(int)num3], ref randomizer, __instance.m_info, out vector, out vector2); Quaternion rotation = Quaternion.identity; Vector3 forward = vector2 - vector; if (forward.sqrMagnitude > 0.01f) { rotation = Quaternion.LookRotation(forward); } data.m_frame0 = new Vehicle.Frame(vector, rotation); data.m_frame1 = data.m_frame0; data.m_frame2 = data.m_frame0; data.m_frame3 = data.m_frame0; data.m_targetPos0 = vector; data.m_targetPos0.w = 2f; data.m_targetPos1 = vector2; data.m_targetPos1.w = 2f; data.m_targetPos2 = data.m_targetPos1; data.m_targetPos3 = data.m_targetPos1; __instance.FrameDataUpdated(vehicleID, ref data, ref data.m_frame0); __instance.SetTarget(vehicleID, ref data, 0); __result = false; return(false); } } /// NON-STOCK CODE END /// __instance.SetTarget(vehicleID, ref data, 0); __result = false; return(false); }
public static void CargoTruckAIArriveAtTargetForRealConstruction(ushort vehicleID, ref Vehicle vehicleData) { BuildingManager instance = Singleton <BuildingManager> .instance; if (vehicleData.m_targetBuilding != 0) { Building buildingData = instance.m_buildings.m_buffer[vehicleData.m_targetBuilding]; if (!(buildingData.Info.m_buildingAI is OutsideConnectionAI)) { if (buildingData.m_flags.IsFlagSet(Building.Flags.Created) && (!buildingData.m_flags.IsFlagSet(Building.Flags.Completed)) && (!buildingData.m_flags.IsFlagSet(Building.Flags.Deleted))) { if (vehicleData.m_transferType == 124) { vehicleData.m_transferSize = 0; MainDataStore.constructionResourceBuffer[vehicleData.m_targetBuilding] = 8000; } } else { if (ResourceBuildingAI.IsSpecialBuilding(vehicleData.m_targetBuilding) == true) { switch ((TransferManager.TransferReason)vehicleData.m_transferType) { case TransferManager.TransferReason.Food: if (MainDataStore.foodBuffer[vehicleData.m_targetBuilding] < 57000) { MainDataStore.foodBuffer[vehicleData.m_targetBuilding] += vehicleData.m_transferSize; } if (Loader.isRealCityRunning) { RealCityUtil.InitDelegate(); float productionValue1 = vehicleData.m_transferSize * RealCityUtil.GetResourcePrice((TransferManager.TransferReason)vehicleData.m_transferType); Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.ResourcePrice, (int)productionValue1, ItemClass.Service.PlayerIndustry, ItemClass.SubService.PlayerIndustryFarming, ItemClass.Level.Level1); } vehicleData.m_transferSize = 0; break; case TransferManager.TransferReason.Lumber: if (MainDataStore.lumberBuffer[vehicleData.m_targetBuilding] < 57000) { MainDataStore.lumberBuffer[vehicleData.m_targetBuilding] += vehicleData.m_transferSize; } if (Loader.isRealCityRunning) { RealCityUtil.InitDelegate(); float productionValue1 = vehicleData.m_transferSize * RealCityUtil.GetResourcePrice((TransferManager.TransferReason)vehicleData.m_transferType); Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.ResourcePrice, (int)productionValue1, ItemClass.Service.PlayerIndustry, ItemClass.SubService.PlayerIndustryForestry, ItemClass.Level.Level1); } vehicleData.m_transferSize = 0; break; case TransferManager.TransferReason.Coal: if (MainDataStore.coalBuffer[vehicleData.m_targetBuilding] < 57000) { MainDataStore.coalBuffer[vehicleData.m_targetBuilding] += vehicleData.m_transferSize; } if (Loader.isRealCityRunning) { RealCityUtil.InitDelegate(); float productionValue1 = vehicleData.m_transferSize * RealCityUtil.GetResourcePrice((TransferManager.TransferReason)vehicleData.m_transferType); Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.ResourcePrice, (int)productionValue1, ItemClass.Service.PlayerIndustry, ItemClass.SubService.PlayerIndustryOre, ItemClass.Level.Level1); } vehicleData.m_transferSize = 0; break; case TransferManager.TransferReason.Petrol: if (MainDataStore.petrolBuffer[vehicleData.m_targetBuilding] < 57000) { MainDataStore.petrolBuffer[vehicleData.m_targetBuilding] += vehicleData.m_transferSize; } if (Loader.isRealCityRunning) { RealCityUtil.InitDelegate(); float productionValue1 = vehicleData.m_transferSize * RealCityUtil.GetResourcePrice((TransferManager.TransferReason)vehicleData.m_transferType); Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.ResourcePrice, (int)productionValue1, ItemClass.Service.PlayerIndustry, ItemClass.SubService.PlayerIndustryOil, ItemClass.Level.Level1); } vehicleData.m_transferSize = 0; break; default: //DebugLog.LogToFileOnly("Error: Unknow m_transferType in realconstruction = " + vehicleData.m_transferType.ToString()); break; } } else { if (vehicleData.m_transferType == 125) { vehicleData.m_transferSize = 0; MainDataStore.operationResourceBuffer[vehicleData.m_targetBuilding] += 8000; } } } } } }