public static bool IsAny(this CarnivalRole pawnRole, params CarnivalRole[] roles) { foreach (var role in roles) { if (pawnRole.Is(role)) { return(true); } } return(false); }
public override void UpdateAllDuties() { LocomotionUrgency urg = CarnUtils.Info.leavingUrgency; foreach (var pawn in this.lord.ownedPawns) { CarnivalRole role = pawn.GetCarnivalRole(); if (role.Is(CarnivalRole.Carrier)) { var vendor = Info.pawnsWithRole[CarnivalRole.Vendor].RandomElementOrNull(); DutyUtility.LeaveMap(pawn, vendor, urg); } else if (role.Is(CarnivalRole.Guard)) { DutyUtility.LeaveMapAndEscort(pawn, GetClosestCarrier(pawn), urg); } else { DutyUtility.LeaveMap(pawn, null, urg); } } }
// OVERRIDE METHODS // public override void UpdateAllDuties() { int curHour = GenLocalDate.HourInteger(Map); int numActiveGuards = Mathf.RoundToInt(Info.pawnsWithRole[CarnivalRole.Guard].Count / 2f); foreach (var pawn in lord.ownedPawns) { CarnivalRole role = pawn.GetCarnivalRole(); if (role.Is(CarnivalRole.Guard)) { if (numActiveGuards > 0 && pawn.needs.rest.CurCategory == RestCategory.Rested) { DutyUtility.GuardCircuit(pawn); numActiveGuards--; } else { // rest on the off shift if not assigned a position DutyUtility.ForceRest(pawn); } } else if (role.IsAny(CarnivalRole.Entertainer, CarnivalRole.Vendor) && curHour >= 22) { DutyUtility.ForceRest(pawn); } else if (role.Is(CarnivalRole.Worker)) { DutyUtility.MeanderAndHelp(pawn, Info.setupCentre, Info.baseRadius); } else if (!role.Is(CarnivalRole.Carrier)) { DutyUtility.Meander(pawn, Info.setupCentre, Info.baseRadius); } } }
// OVERRIDE METHODS // public override void UpdateAllDuties() { var guard = Info.pawnsWithRole[CarnivalRole.Guard].MinBy(p => p.skills.GetSkill(SkillDefOf.Construction).Level); DutyUtility.GuardCircuit(guard); foreach (var pawn in lord.ownedPawns) { CarnivalRole role = pawn.GetCarnivalRole(); if (!role.Is(CarnivalRole.Carrier) && pawn != guard) { DutyUtility.StrikeBuildings(pawn); } } }
public override void UpdateAllDuties() { var nearHostiles = Map.attackTargetsCache.TargetsHostileToFaction(lord.faction) .Where(targ => !targ.ThreatDisabled()) .Select(targ => targ.Thing); var aveHostilesPos = nearHostiles.Select(t => t.Position).Average(); IntVec3 closestGuardSpot; IntVec3 bestGatherSpot; if (aveHostilesPos.IsValid && Info.guardPositions.Any()) { closestGuardSpot = Info.guardPositions.MinBy(c => c.DistanceToSquared(aveHostilesPos)); } else { closestGuardSpot = Info.bannerCell; } if (Info.Chapiteaux != null) { bestGatherSpot = Info.Chapiteaux.Position; } else { bestGatherSpot = Info.setupCentre; } foreach (var pawn in lord.ownedPawns) { if (pawn.Dead || pawn.Downed) { continue; } var distressedCarny = RandomExposedCarnyByHealth(pawn); var nearHost = nearHostiles.MinBy(t => pawn.Position.DistanceToSquared(t.Position)); CarnivalRole role = pawn.GetCarnivalRole(); if (role.Is(CarnivalRole.Manager)) { var guard = Info.GetBestGuard(false); if (Rand.Chance(0.4f) && guard != null && !guard.Dead && !guard.Downed) { pawn.mindState.duty = new PawnDuty(DutyDefOf.Escort, guard, 7f) { locomotion = LocomotionUrgency.Jog }; } else { if (distressedCarny != null) { DutyUtility.DefendPoint(pawn, distressedCarny, null, 5f); } else { DutyUtility.DefendPoint(pawn, closestGuardSpot, nearHost); } } } else if (role.Is(CarnivalRole.Guard)) { if (numChargers > 0) { DutyUtility.ChargeHostiles(pawn); numChargers--; } else if (distressedCarny != null && (Rand.Chance(0.33f) || pawn.mindState.enemyTarget == null)) { DutyUtility.DefendPoint(pawn, distressedCarny, null, 5f); } else { DutyUtility.DefendPoint(pawn, closestGuardSpot, nearHost); } } else if (pawn.equipment != null && pawn.equipment.Primary != null) { if (numChargers > 0) { DutyUtility.ChargeHostiles(pawn); numChargers--; } else if (pawn.health.summaryHealth.SummaryHealthPercent > 0.85f) { IntVec3 tentDoor; if (pawnsKilled > 3 && distressedCarny != null) { DutyUtility.DefendPoint(pawn, distressedCarny, null, 5f); } else if (Rand.Bool && (tentDoor = Info.GetRandomTentDoor(true, CarnBuildingType.Attraction).Cell).IsValid) { DutyUtility.DefendPoint(pawn, tentDoor, null); } else { DutyUtility.DefendPoint(pawn, closestGuardSpot, nearHost); } } else { DutyUtility.DefendPoint(pawn, bestGatherSpot, null, 5f); } } else { // TODO pawn.mindState.duty = new PawnDuty(DutyDefOf.Travel, bestGatherSpot) { locomotion = LocomotionUrgency.Sprint }; } } }