private bool SpawnGroup(IncidentParms parms, Map map) { var visitors = new List <Pawn>(); try { //Log.Message(string.Format("Spawning visitors from {0}, at {1}.", parms.faction, parms.spawnCenter)); SpawnPawns(parms, visitors); SpawnGroupUtility.CheckVisitorsValid(visitors); if (visitors == null || visitors.Count == 0) { return(false); } var area = visitors.First().GetGuestArea() ?? map.GetMapComponent().defaultAreaRestriction; var spot = GetSpot(map, area, visitors.First()); if (!spot.IsValid) { throw new Exception($"Visitors from {parms.faction.Name} failed to find a valid travel target from {visitors.First()?.Position} to guest area {area?.Label}."); } GiveItems(visitors); var stayDuration = (int)(Rand.Range(1f, 2.4f) * GenDate.TicksPerDay); CreateLord(parms.faction, spot, visitors, map, true, true, stayDuration); } catch (Exception e) { var faction = parms.faction?.Name; var factionType = parms.faction?.def.label; Log.Error($"Hospitality: Something failed when setting up visitors from faction {faction} ({factionType}):\n{e}"); foreach (var visitor in visitors) { if (visitor?.Spawned == true) { visitor.DeSpawn(); visitor.DestroyOrPassToWorld(); } } GenericUtility.PlanNewVisit(map, Rand.Range(1f, 3f), parms.faction); } return(true); // be gone, event }
protected override bool TryExecuteWorker(IncidentParms parms) { if (!TryResolveParms(parms)) { Log.ErrorOnce($"Trying to spawn visitors, but parms couldn't be resolved.", 84289426); return(false); } // Is map not available anymore? if (!(parms.target is Map map)) { Log.ErrorOnce("Trying to spawn visitors, but map does not exist anymore.", 43692862); return(true); } if (parms.points < 40) { Log.Error("Trying to spawn visitors, but points are too low."); return(false); } if (parms.faction == null) { Log.ErrorOnce("Trying to spawn visitors, but couldn't find valid faction.", 43638973); return(true); } if (!parms.spawnCenter.IsValid) { Log.ErrorOnce("Trying to spawn visitors, but could not find a valid spawn point.", 94839643); return(false); } if (parms.faction == Faction.OfPlayer) { Log.ErrorOnce("Trying to spawn visitors, but they are of Faction.OfPlayer.", 3464363); return(true); } if (parms.faction.RelationWith(Faction.OfPlayer).kind == FactionRelationKind.Hostile) { Log.Message($"Trying to spawn visitors of faction {parms.faction.Name}, but they are hostile to the player (now)."); return(true); } if (parms.faction.defeated) { Log.Message($"Trying to spawn visitors of faction {parms.faction.Name}, but they have been defeated."); return(true); } if (Settings.disableGuests || map.mapPawns.ColonistCount == 0) { if (Settings.disableGuests) { Log.Message($"Guest group arrived, but guests are disabled in the options."); } else if (map.mapPawns.ColonistCount == 0) { Log.Message($"Guest group arrived, but there are no remaining colonists on the map."); } GenericUtility.PlanNewVisit(map, Rand.Range(5f, 25f), parms.faction); } else { // Did the player refuse guests until beds are made and there are no beds yet? if (!BedCheck(map)) { Log.Message("Guest group arrived, but there are no guest beds and the player asked to wait until they are built."); GenericUtility.PlanNewVisit(map, Rand.Range(5f, 10f), parms.faction); return(true); } // We check here instead of CanFireNow, so we can reschedule the visit. // Any reasons not to come? if (CheckCanCome(map, parms.faction, out var reasons)) { // No, spawn return(SpawnGroup(parms, map)); } // Yes, ask the player for permission void Allow() => SpawnGroup(parms, map); void Refuse() => GenericUtility.PlanNewVisit(map, Rand.Range(2f, 5f), parms.faction); AskForPermission(parms, map, reasons, Allow, Refuse); } return(true); }