public bool IsSupported(ushort buildingID) { Building building = Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingID]; ItemClass.Service service = building.Info.GetService(); // ignore prisons if (service.Equals(ItemClass.Service.PoliceDepartment) && building.Info.m_class.m_level >= ItemClass.Level.Level4) { return(false); } if (service.Equals(ItemClass.Service.FireDepartment) || service.Equals(ItemClass.Service.Garbage) || service.Equals(ItemClass.Service.HealthCare) || service.Equals(ItemClass.Service.PoliceDepartment) || service.Equals(ItemClass.Service.Road) || (service.Equals(ItemClass.Service.PublicTransport) && building.Info.GetSubService().Equals(ItemClass.SubService.PublicTransportTaxi)) || //allow Taxi (service.Equals(ItemClass.Service.Education) && Settings.RestrictCitizenEducationalAccess) || //allow for schools if citizen access restricted (service.Equals(ItemClass.Service.Beautification) && Settings.RestrictCitizenParkAccess) //allow for parks if citizen access restricted ) { DistrictManager districtManager = Singleton <DistrictManager> .instance; byte districtID = districtManager.GetDistrict(building.m_position); Utils.LogGeneral($"Checking buildingID {buildingID}, District {districtID}:'{districtManager.GetDistrictName(districtID)}' active... {DistrictChecker.IsActive(districtID)}"); return(DistrictChecker.IsActive(districtID)); } return(false); }
static bool Prefix(ushort vehicleID, ref Vehicle data, TransferManager.TransferReason material, TransferManager.TransferOffer offer) { if (DistrictChecker.IsVehicleTransferAllowed(vehicleID, ref data, material, offer)) { return(true); } return(false); }
static bool Prefix(uint citizenID, ref Citizen data, TransferManager.TransferReason reason, TransferManager.TransferOffer offer) { if (DistrictChecker.IsCitizenTransferAllowed(citizenID, ref data, reason, offer)) { return(true); } return(false); }
static bool Prefix(ushort buildingID, ref Building data, TransferManager.TransferReason material, TransferManager.TransferOffer offer) { if (DistrictChecker.IsBuildingTransferAllowed(buildingID, ref data, material, offer)) { return(true); } BuildingHelper.delegateToAnotherBuilding(buildingID, ref data, material, offer); return(false); }
/// <summary> /// Building Service requests wrapper /// </summary> public static bool IsBuildingTransferAllowed(ushort buildingID, ref Building data, TransferManager.TransferReason reason, TransferManager.TransferOffer offer, bool summarizedLog = false) { DistrictManager districtManager = Singleton <DistrictManager> .instance; BuildingManager buildingManager = Singleton <BuildingManager> .instance; CitizenManager citizenManager = Singleton <CitizenManager> .instance; Building srcBuilding = buildingManager.m_buildings.m_buffer[(int)buildingID]; Building dstBuilding = buildingManager.m_buildings.m_buffer[(int)offer.Building]; ushort dstBuildingId = offer.Building; //fix for services based on resident instead of building: if (offer.Building == 0 && offer.Citizen != 0) { dstBuildingId = citizenManager.m_citizens.m_buffer[offer.Citizen].GetBuildingByLocation(); dstBuilding = buildingManager.m_buildings.m_buffer[dstBuildingId]; //still no building -> citizen out in the wild (e.g. waiting for taxi) if (dstBuildingId == 0) { var instid = citizenManager.m_citizens.m_buffer[offer.Citizen].m_instance; dstBuilding.m_position = citizenManager.m_instances.m_buffer[instid].GetLastFramePosition(); //pass by value, overwrite OK } } string srcBuildingName = buildingManager.GetBuildingName(buildingID, InstanceID.Empty); string dstBuildingName = buildingManager.GetBuildingName(dstBuildingId, InstanceID.Empty); string dstCitizenName = citizenManager.GetCitizenName(offer.Citizen); string srcDistrictName = FindDistrictName(srcBuilding.m_position); string dstDistrictName = FindDistrictName(dstBuilding.m_position); bool allowed = DistrictChecker.IsTransferAllowed(data.m_position, dstBuilding.m_position, buildingID, dstBuildingId, reason, false); if (summarizedLog) { Utils.LogBuilding(String.Format(" - Building #{0} queried (allowed: {1})", buildingID, allowed)); } else { Utils.LogBuilding("------------------------------------------------------------" + String.Format("\nBuilding #{0} queried (allowed: {1})", buildingID, allowed) + String.Format("\n - Transfer: reason={0}, offer={1}", reason, Utils.ToString(offer)) + String.Format("\n - Origin: {0}", srcBuildingName) + String.Format("\n - Destination: building='{0}', citizen='{1}'", dstBuildingName, dstCitizenName) + String.Format("\n - District: {0} -> {1}", srcDistrictName, dstDistrictName)); } return(allowed); }
public override void StartTransfer(ushort buildingID, ref Building data, TransferManager.TransferReason material, TransferManager.TransferOffer offer) { if (triggered) { return; } else if (DistrictChecker.IsBuildingTransferAllowed(buildingID, ref data, material, offer)) { base.StartTransfer(buildingID, ref data, material, offer); //triggered = true; } else { if (BuildingHelper.delegateToAnotherBuilding(buildingID, ref data, material, offer)) { //triggered = true; } } }
private void RefreshData(ushort selectedBuildingID) { fastList.Clear(); fastList.rowsData.Add(new object[] { (byte)0, ALL_DISTRICTS }); DistrictManager districtManager = Singleton <DistrictManager> .instance; Building building = Singleton <BuildingManager> .instance.m_buildings.m_buffer[selectedBuildingID]; byte selectedBuildingDistrictID = districtManager.GetDistrict(building.m_position); int index; for (index = 1; index < 128; ++index) { if (index != selectedBuildingDistrictID && DistrictChecker.IsActive((byte)index)) { string name = districtManager.GetDistrictName(index); fastList.rowsData.Add(new object[] { (byte)index, name }); } } fastList.DisplayAt(0); Utils.LogGeneral($"[DistrictSelectionPanel]: {fastList.rowsData.m_size} available Districts for building: "); }
/** * Workaround a scenario where there is another building closer to the offer's position * that doesn't belong to the same district, causing the offer never to be handled. */ internal static bool delegateToAnotherBuilding(ushort buildingID, ref Building data, TransferManager.TransferReason material, TransferManager.TransferOffer offer) { Utils.LogBuilding(" - Searching another building to delegate"); Type aiType = data.Info.m_buildingAI.GetType().BaseType; BuildingManager buildingManager = Singleton <BuildingManager> .instance; ItemClass.Service service = data.Info.GetService(); FastList <ushort> buildings = buildingManager.GetServiceBuildings(service); bool delegateMode = (material == TransferManager.TransferReason.Fire || material == TransferManager.TransferReason.Crime || material == TransferManager.TransferReason.Dead || material == TransferManager.TransferReason.Fire2 || material == TransferManager.TransferReason.Garbage || material == TransferManager.TransferReason.RoadMaintenance || material == TransferManager.TransferReason.Snow || material == TransferManager.TransferReason.Sick || material == TransferManager.TransferReason.Sick2 || material == TransferManager.TransferReason.Taxi); if (buildings == null) { return(false); } for (int index = 0; index < buildings.m_size; index++) { ushort otherBuildingID = buildings.m_buffer[index]; if (buildingID == otherBuildingID) { continue; } Building otherBuilding = buildingManager.m_buildings.m_buffer[otherBuildingID]; if ((otherBuilding.m_flags & Building.Flags.Active) == Building.Flags.None) { continue; } if ((otherBuilding.m_problems & Notification.Problem.Emptying) != Notification.Problem.None) { continue; } if ((otherBuilding.m_problems & Notification.Problem.EmptyingFinished) != Notification.Problem.None) { continue; } BuildingAI otherBuildingAI = (BuildingAI)otherBuilding.Info.m_buildingAI; if (!aiType.IsAssignableFrom(otherBuildingAI.GetType())) { continue; } if (otherBuildingAI.IsFull(otherBuildingID, ref otherBuilding)) { continue; } if (delegateMode && !hasSpareVehicles(otherBuildingID, ref otherBuilding, otherBuildingAI)) { continue; //target delegation does not need vehicle from target! } if (delegateMode) { if (DistrictChecker.IsBuildingTransferAllowed(otherBuildingID, ref otherBuilding, material, offer, true)) { // let other building handle the offer Utils.LogBuilding(" - delegation success, starting transfer (origin delegated)"); otherBuildingAI.StartTransfer(otherBuildingID, ref otherBuilding, material, offer); return(true); } } else { offer.Building = otherBuildingID; offer.Position = otherBuilding.m_position; if (DistrictChecker.IsBuildingTransferAllowed(buildingID, ref data, material, offer, true)) { // change the target to other building Utils.LogBuilding(" - delegation success, starting transfer (target changed)"); data.Info.m_buildingAI.StartTransfer(buildingID, ref data, material, offer); return(true); } } } Utils.LogBuilding(" - delegation finally failed, request NOT handled!"); return(false); }