public override bool CitizenCanGo(uint citizenID, ref Citizen person) { bool canGo = false; if (m_eventChances != null && m_eventData.m_registeredCitizens < GetCapacity()) { canGo = true; Citizen.Wealth _citizenWealth = person.WealthLevel; Citizen.Education _citizenEducation = person.EducationLevel; Citizen.Gender _citizenGender = Citizen.GetGender(citizenID); Citizen.Happiness _citizenHappiness = Citizen.GetHappinessLevel(Citizen.GetHappiness(person.m_health, person.m_wellbeing)); Citizen.Wellbeing _citizenWellbeing = Citizen.GetWellbeingLevel(_citizenEducation, person.m_wellbeing); Citizen.AgeGroup _citizenAgeGroup = Citizen.GetAgeGroup(person.Age); float percentageChange = GetAdjustedChancePercentage(); int randomPercentage = Singleton <SimulationManager> .instance.m_randomizer.Int32(100U); switch (_citizenWealth) { case Citizen.Wealth.Low: canGo = canGo && randomPercentage < Adjust(m_eventChances._lowWealth, percentageChange); break; case Citizen.Wealth.Medium: canGo = canGo && randomPercentage < Adjust(m_eventChances._mediumWealth, percentageChange); break; case Citizen.Wealth.High: canGo = canGo && randomPercentage < Adjust(m_eventChances._highWealth, percentageChange); break; } randomPercentage = Singleton <SimulationManager> .instance.m_randomizer.Int32(100U); switch (_citizenEducation) { case Citizen.Education.Uneducated: canGo = canGo && randomPercentage < Adjust(m_eventChances._uneducated, percentageChange); break; case Citizen.Education.OneSchool: canGo = canGo && randomPercentage < Adjust(m_eventChances._oneSchool, percentageChange); break; case Citizen.Education.TwoSchools: canGo = canGo && randomPercentage < Adjust(m_eventChances._twoSchools, percentageChange); break; case Citizen.Education.ThreeSchools: canGo = canGo && randomPercentage < Adjust(m_eventChances._threeSchools, percentageChange); break; } randomPercentage = Singleton <SimulationManager> .instance.m_randomizer.Int32(100U); switch (_citizenGender) { case Citizen.Gender.Female: canGo = canGo && randomPercentage < Adjust(m_eventChances._females, percentageChange); break; case Citizen.Gender.Male: canGo = canGo && randomPercentage < Adjust(m_eventChances._males, percentageChange); break; } randomPercentage = Singleton <SimulationManager> .instance.m_randomizer.Int32(100U); switch (_citizenHappiness) { case Citizen.Happiness.Bad: canGo = canGo && randomPercentage < Adjust(m_eventChances._badHappiness, percentageChange); break; case Citizen.Happiness.Poor: canGo = canGo && randomPercentage < Adjust(m_eventChances._poorHappiness, percentageChange); break; case Citizen.Happiness.Good: canGo = canGo && randomPercentage < Adjust(m_eventChances._goodHappiness, percentageChange); break; case Citizen.Happiness.Excellent: canGo = canGo && randomPercentage < Adjust(m_eventChances._excellentHappiness, percentageChange); break; case Citizen.Happiness.Suberb: canGo = canGo && randomPercentage < Adjust(m_eventChances._superbHappiness, percentageChange); break; } randomPercentage = Singleton <SimulationManager> .instance.m_randomizer.Int32(100U); switch (_citizenWellbeing) { case Citizen.Wellbeing.VeryUnhappy: canGo = canGo && randomPercentage < Adjust(m_eventChances._veryUnhappyWellbeing, percentageChange); break; case Citizen.Wellbeing.Unhappy: canGo = canGo && randomPercentage < Adjust(m_eventChances._unhappyWellbeing, percentageChange); break; case Citizen.Wellbeing.Satisfied: canGo = canGo && randomPercentage < Adjust(m_eventChances._satisfiedWellbeing, percentageChange); break; case Citizen.Wellbeing.Happy: canGo = canGo && randomPercentage < Adjust(m_eventChances._happyWellbeing, percentageChange); break; case Citizen.Wellbeing.VeryHappy: canGo = canGo && randomPercentage < Adjust(m_eventChances._veryHappyWellbeing, percentageChange); break; } randomPercentage = Singleton <SimulationManager> .instance.m_randomizer.Int32(100U); switch (_citizenAgeGroup) { case Citizen.AgeGroup.Child: canGo = canGo && randomPercentage < Adjust(m_eventChances._children, percentageChange); break; case Citizen.AgeGroup.Teen: canGo = canGo && randomPercentage < Adjust(m_eventChances._teens, percentageChange); break; case Citizen.AgeGroup.Young: canGo = canGo && randomPercentage < Adjust(m_eventChances._youngAdults, percentageChange); break; case Citizen.AgeGroup.Adult: canGo = canGo && randomPercentage < Adjust(m_eventChances._adults, percentageChange); break; case Citizen.AgeGroup.Senior: canGo = canGo && randomPercentage < Adjust(m_eventChances._seniors, percentageChange); break; } CimTools.CimToolsHandler.CimToolBase.DetailedLogger.Log( (canGo ? "[Can Go]" : "[Ignoring]") + " Citizen " + citizenID + " for " + m_eventData.m_eventName + "\n\t" + _citizenWealth.ToString() + ", " + _citizenEducation.ToString() + ", " + _citizenGender.ToString() + ", " + _citizenHappiness.ToString() + ", " + _citizenWellbeing.ToString() + ", " + _citizenAgeGroup.ToString()); } return(canGo); }
/// <summary> /// Method called by OutsideConnectionAI.StartConnectionTransferImpl Transpiler insertion. /// Randomises (within parameters) age and education levels of immigrants. /// All variables are local variables within OutsideConnectionAI.StartConnectionTransferImpl. /// </summary> /// <param name="i">Loop counter (for loop containing method call)</param> /// <param name="education">Education level input (StartConnectionTransferImpl local variable)</param> /// <param name="ageArray">Array of acceptible ages (from mod DataStore); placed on stack in advance via Transpiler insertion</param> /// <param name="childrenAgeMax">Maximum child immigrant age; placed on stack in advance via Transpiler insertion </param> /// <param name="childrenAgeMin">Minimum child immigrant age; placed on stack in advance via Transpiler insertion</param> /// <param name="minAdultAge">Minimum adult immigrant age; placed on stack in advance via Transpiler insertion</param> /// <param name="resultEducation">Resultant education level for immigrant after mod calculations (StartConnectionTransferImpl local variable 'education2')</param> /// <param name="resultAge">Resultant age level for immigrant after mod calculations (StartConnectionTransferImpl local variable 'age')</param> public static void RandomizeImmigrants(int i, Citizen.Education education, int[] ageArray, ref int childrenAgeMax, ref int childrenAgeMin, ref int minAdultAge, out Citizen.Education resultEducation, out int resultAge) { // Minimum and maximum ages. int min = ageArray[0]; int max = ageArray[1]; // We start inside an i loop. // i is is the family member number for this incoming family. 0 is primary adult, 1 is secondary adults, and after that are children. if (i == 1) { // Age of second adult - shouldn't be too far from the first. Just because. min = Math.Max(minAdultAge - 20, DataStore.incomingAdultAge[0]); max = Math.Min(minAdultAge + 20, DataStore.incomingAdultAge[1]); } else if (i >= 2) { // Children. min = childrenAgeMin; max = childrenAgeMax; } // Calculate actual age randomly between minumum and maxiumum. resultAge = Singleton <SimulationManager> .instance.m_randomizer.Int32(min, max); // Adust age brackets for subsequent family members. if (i == 0) { minAdultAge = resultAge; } else if (i == 1) { // Restrict to adult age. Young adult is 18 according to National Institutes of Health... even if the young adult section in a library isn't that range. minAdultAge = Math.Min(resultAge, minAdultAge); // Children should be between 80 and 180 younger than the youngest adult. childrenAgeMax = Math.Max(minAdultAge - 80, 0); // Allow people 10 ticks from 'adulthood' to have kids childrenAgeMin = Math.Max(minAdultAge - 178, 0); // Accounting gestation, which isn't simulated yet (2 ticks) } // Set default eductation output to what the game has already determined. resultEducation = education; // Apply education level randomisation if that option is selected. if (ModSettings.randomImmigrantEd) { if (i < 2) { // Adults. // 24% different education levels int eduModifier = Singleton <SimulationManager> .instance.m_randomizer.Int32(-12, 12) / 10; resultEducation += eduModifier; if (resultEducation < Citizen.Education.Uneducated) { resultEducation = Citizen.Education.Uneducated; } else if (resultEducation > Citizen.Education.ThreeSchools) { resultEducation = Citizen.Education.ThreeSchools; } } else { // Children. switch (Citizen.GetAgeGroup(resultAge)) { case Citizen.AgeGroup.Child: resultEducation = Citizen.Education.Uneducated; break; case Citizen.AgeGroup.Teen: resultEducation = Citizen.Education.OneSchool; break; default: // Make it that 80% graduate from high school resultEducation = (Singleton <SimulationManager> .instance.m_randomizer.Int32(0, 100) < 80) ? Citizen.Education.TwoSchools : Citizen.Education.OneSchool; break; } } } // Apply education boost, if enabled, and if we're not already at the max. if (ModSettings.immiEduBoost && resultEducation < Citizen.Education.ThreeSchools) { ++resultEducation; } // Apply education suppression, if enabled, and if we're not already at the min. if (ModSettings.immiEduDrag && resultEducation > Citizen.Education.Uneducated) { --resultEducation; } // Write to immigration log if that option is selected. if (Logging.UseImmigrationLog) { Logging.WriteToLog(Logging.ImmigrationLogName, "Family member ", i.ToString(), " immigrating with age ", resultAge.ToString(), " (" + (int)(resultAge / 3.5), " years old) and education level ", education.ToString()); } }