public static Type GetRaidClassByEnum(RaidGoalType e) { if (e == RaidGoalType.Conquer) { return(typeof(RaidingGoal_Conquer)); } if (e == RaidGoalType.Enslave) { return(typeof(RaidingGoal_Enslave)); } if (e == RaidGoalType.Extortion) { return(typeof(RaidingGoal_Extortion)); } if (e == RaidGoalType.Rescue) { return(typeof(RaidingGoal_Rescue)); } if (e == RaidGoalType.Smite) { return(typeof(RaidingGoal_Smite)); } if (e == RaidGoalType.Extermination) { return(typeof(RaidingGoal_Extermination)); } throw new Exception("Try to get an unimplemented RaidingGoal Class!"); }
public static void ResolveRaidGoal(InterceptedIncident_HumanCrowd_RaidEnemy incident) { if (incident.SourceFaction == Faction.OfMechanoids) { new RaidingGoal_Extermination().ApplyToIncident(incident); if (PES_Settings.DebugModeOn) { Log.Message("Figure out raid goal: " + RaidGoalType.Extermination.ToString()); } return; } Map map = incident.parms.target as Map; Dictionary <RaidGoalType, float> weightDic = new Dictionary <RaidGoalType, float>() { [RaidGoalType.Conquer] = 1f, [RaidGoalType.Extortion] = 1f, [RaidGoalType.Enslave] = 1f, [RaidGoalType.Rescue] = 1f }; float ConquerWeight = 0f; if (incident.parms.points < 1000f) { ConquerWeight = 0f; } else if (incident.parms.points < 3000f) { ConquerWeight = 1f; } else { ConquerWeight = 2f; } weightDic[RaidGoalType.Conquer] = ConquerWeight; float EnslaveWeight = 0f; if (map.mapPawns.FreeColonistsSpawnedCount <= 1) { EnslaveWeight = 0f; } else { EnslaveWeight = Mathf.Clamp01(map.mapPawns.FreeColonistsSpawnedCount / 10f) * 0.8f; } weightDic[RaidGoalType.Enslave] = EnslaveWeight; float RescueWeight = 0f; if (map.mapPawns.PrisonersOfColonySpawnedCount < 1) { RescueWeight = 0f; } else { int factionPrisonerSum = map.mapPawns.PrisonersOfColonySpawned.Sum(p => !p.Dead && p.Faction == incident.SourceFaction ? 1 : 0); if (factionPrisonerSum == 0) { RescueWeight = 0f; } else if (factionPrisonerSum <= 3) { RescueWeight = 1f; } else { RescueWeight = 2f; } } weightDic[RaidGoalType.Rescue] = RescueWeight; RaidGoalType theChosenOne = weightDic.Keys.ToList().RandomElementByWeight(t => weightDic[t]); if (PES_Settings.DebugModeOn) { Log.Message("Figure out raid goal: " + theChosenOne.ToString()); } RaidingGoal goal = Activator.CreateInstance(RaidingGoal.GetRaidClassByEnum(theChosenOne)) as RaidingGoal; goal.ApplyToIncident(incident); }