private static void EnsureCitizenUnits(ushort vehicleID, ref Vehicle data, int passengerCount) { CitizenManager instance = Singleton <CitizenManager> .instance; uint num = 0; for (uint firstUnit = data.m_citizenUnits; (int)firstUnit != 0; firstUnit = instance.m_units.m_buffer[(int)firstUnit].m_nextUnit) { if ((instance.m_units.m_buffer[(int)firstUnit].m_flags & CitizenUnit.Flags.Vehicle) != CitizenUnit.Flags.None) { passengerCount -= 5; } if (passengerCount < 0) { Utils.LogToTxt((object)string.Format("ReleaseUnits for #{0}", (object)vehicleID)); instance.m_units.m_buffer[(int)num].m_nextUnit = 0U; instance.ReleaseUnits(firstUnit); return; } num = firstUnit; } if (passengerCount <= 0) { return; } Utils.LogToTxt((object)string.Format("CreateUnits for #{0}", (object)vehicleID)); uint firstUnit1 = 0; if (!instance.CreateUnits(out firstUnit1, ref Singleton <SimulationManager> .instance.m_randomizer, (ushort)0, vehicleID, 0, 0, 0, passengerCount, 0)) { return; } if ((int)num != 0) { instance.m_units.m_buffer[(int)num].m_nextUnit = firstUnit1; } else { data.m_citizenUnits = firstUnit1; } }
internal static void EnsureCitizenUnits(ref PrivateBuildingAI __instance, ushort buildingID, ref Building data, int homeCount, int workCount, int visitCount, int studentCount) { int totalWorkCount = (workCount + 4) / 5; int totalVisitCount = (visitCount + 4) / 5; int totalHomeCount = homeCount; int[] workersRequired = new int[] { 0, 0, 0, 0 }; if ((data.m_flags & (Building.Flags.Abandoned | Building.Flags.BurnedDown)) == Building.Flags.None) { Citizen.Wealth wealthLevel = Citizen.GetWealthLevel(__instance.m_info.m_class.m_level); uint num = 0u; uint num2 = data.m_citizenUnits; int num3 = 0; while (num2 != 0u) { CitizenUnit.Flags flags = citizenUnitArray[(int)((UIntPtr)num2)].m_flags; if ((ushort)(flags & CitizenUnit.Flags.Home) != 0) { citizenUnitArray[(int)((UIntPtr)num2)].SetWealthLevel(wealthLevel); homeCount--; } if ((ushort)(flags & CitizenUnit.Flags.Work) != 0) { workCount -= 5; for (int i = 0; i < 5; i++) { uint citizen = citizenUnitArray[(int)((UIntPtr)num2)].GetCitizen(i); if (citizen != 0u) { // Tick off education to see what is there workersRequired[(int)citizenArray[(int)((UIntPtr)citizen)].EducationLevel]--; } } } if ((ushort)(flags & CitizenUnit.Flags.Visit) != 0) { visitCount -= 5; } if ((ushort)(flags & CitizenUnit.Flags.Student) != 0) { studentCount -= 5; } num = num2; num2 = citizenUnitArray[(int)((UIntPtr)num2)].m_nextUnit; if (++num3 > 524288) { CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + Environment.StackTrace); break; } } // end while /* * homeCount = Mathf.Max(0, homeCount); * workCount = Mathf.Max(0, workCount); */ visitCount = Mathf.Max(0, visitCount); studentCount = Mathf.Max(0, studentCount); if (homeCount > 0 || workCount > 0 || visitCount > 0 || studentCount > 0) { uint num4 = 0u; if (citizenManager.CreateUnits(out num4, ref Singleton <SimulationManager> .instance.m_randomizer, buildingID, 0, homeCount, workCount, visitCount, 0, studentCount)) { if (num != 0u) { citizenUnitArray[(int)((UIntPtr)num)].m_nextUnit = num4; } else { data.m_citizenUnits = num4; } } } // Stop incoming offers to get HandleWorkers() to start fresh TransferManager.TransferOffer offer = default(TransferManager.TransferOffer); offer.Building = buildingID; Singleton <TransferManager> .instance.RemoveIncomingOffer(TransferManager.TransferReason.Worker0, offer); Singleton <TransferManager> .instance.RemoveIncomingOffer(TransferManager.TransferReason.Worker1, offer); Singleton <TransferManager> .instance.RemoveIncomingOffer(TransferManager.TransferReason.Worker2, offer); Singleton <TransferManager> .instance.RemoveIncomingOffer(TransferManager.TransferReason.Worker3, offer); int worker0 = 0; int worker1 = 0; int worker2 = 0; int worker3 = 0; ItemClass.Level level = ((PrivateBuildingAI)data.Info.GetAI()).m_info.m_class.m_level; ((PrivateBuildingAI)data.Info.GetAI()).CalculateWorkplaceCount(level, new Randomizer((int)buildingID), data.Width, data.Length, out worker0, out worker1, out worker2, out worker3); // Update the workers required once figuring out how many are needed by the new building workersRequired[0] += worker0; workersRequired[1] += worker1; workersRequired[2] += worker2; workersRequired[3] += worker3; if (workCount < 0) { RemoveWorkerBuilding(buildingID, ref data, totalWorkCount); } else if (homeCount < 0) { RemoveHouseHold(buildingID, ref data, totalHomeCount); } /* * if (visitCount < 0) * { * RemoveVisitorsBuilding(buildingID, ref data, totalVisitCount); * } */ PromoteWorkers(buildingID, ref data, ref workersRequired); // Do nothing for students } // end if good building } // end EnsureCitizenUnits