Example #1
0
        static void CalcCrimeForHome(IResidence residence)
        {
            int happiness = residence.GetHappiness();
            int severity  = (crimeHappinessThreshold - happiness);

            if (severity > 0)
            {
                float severityNormalized = (float)severity / (float)crimeHappinessThreshold;
                Mod.helper.Log("found home with potential crime: " + severityNormalized.ToString());
                foreach (Villager resident in residence.GetResidents())
                {
                    bool flaggedCriminal = SRand.Range(0f, 1f) < severityNormalized;

                    if (flaggedCriminal)
                    {
                        Mod.helper.Log("trying create criminal");
                        Criminal bestCriminal = GetBestCriminalForSeverity(severityNormalized);

                        if (bestCriminal)
                        {
                            CreateCriminal(bestCriminal, resident);
                        }
                    }
                }
            }
        }
Example #2
0
        public static void CreateCriminal(Criminal criminalType, Villager host)
        {
            if (trackedCriminals.ContainsKey(host.guid))
            {
                return;
            }

            Criminal instance = criminalType.CreateInHost(host);

            trackedCriminals.Add(host.guid, instance);

            Mod.helper.Log("created criminal: " + criminalType.c_name);
        }
Example #3
0
        public static Criminal GetBestCriminalForSeverity(float severity)
        {
            Criminal best = null;

            foreach (Criminal criminalType in CriminalTypes)
            {
                Mod.helper.Log(criminalType.c_name + ", " + criminalType.c_severity.ToString());
                Debug.LogError("asdf");
                if (criminalType.c_severity < severity)
                {
                    bool flagSelected = SRand.Range(0f, 1f) < (1f + criminalPickBuffer) - criminalType.c_severity;

                    if (flagSelected)
                    {
                        if (best == null)
                        {
                            best = criminalType;
                        }
                        else
                        {
                            if (
                                Settings.criminalAssignmentPriority == Settings.CriminalAssignmentPriority.PrioritizeDangerousCriminals &&
                                criminalType.c_severity > best.c_severity
                                )
                            {
                                best = criminalType;
                            }
                            if (
                                Settings.criminalAssignmentPriority == Settings.CriminalAssignmentPriority.PrioritizeHarmlessCriminals &&
                                criminalType.c_severity < best.c_severity
                                )
                            {
                                best = criminalType;
                            }
                        }
                    }
                }
            }

            return(best);
        }