예제 #1
0
        public override void UpdateAllDuties()
        {
            foreach (Pawn pawn in this.lord.ownedPawns)
            {
                CarnivalRole role = pawn.GetCarnivalRole();

                // can't use switch case because some roles have multiple bit-flags
                if (role.Is(CarnivalRole.Worker))
                {
                    DutyUtility.BuildCarnival(pawn, Info.setupCentre, Info.baseRadius);
                }
                else if (role.Is(CarnivalRole.Guard))
                {
                    DutyUtility.GuardCircuit(pawn);
                }
                else if (role.Is(CarnivalRole.Carrier))
                {
                    IntVec3 pos;

                    if (Info.rememberedPositions.TryGetValue(pawn, out pos))
                    {
                        DutyUtility.HitchToSpot(pawn, pos);
                    }
                    else
                    {
                        DutyUtility.HitchToSpot(pawn, pawn.Position);
                    }
                }
                else
                {
                    DutyUtility.MeanderAndHelp(pawn, Info.setupCentre, Info.baseRadius);
                }
            }
        }
예제 #2
0
        public override void UpdateAllDuties()
        {
            var     wanderRect      = CellRect.CenteredOn(Info.setupCentre, 8);
            int     numActiveGuards = Mathf.RoundToInt(Info.pawnsWithRole[CarnivalRole.Guard].Count / 2f);
            IntVec3 pos;

            foreach (var pawn in this.lord.ownedPawns)
            {
                CarnivalRole pawnRole = pawn.GetCarnivalRole();

                if (pawnRole.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 (pawnRole.IsAny(CarnivalRole.Vendor, CarnivalRole.Carrier))
                {
                    if (Info.rememberedPositions.TryGetValue(pawn, out pos))
                    {
                        DutyUtility.HitchToSpot(pawn, pos);
                    }
                    else
                    {
                        DutyUtility.HitchToSpot(pawn, pawn.Position);
                    }
                }
                else if (pawnRole.Is(CarnivalRole.Entertainer))
                {
                    if (Info.rememberedPositions.TryGetValue(pawn, out pos))
                    {
                        DutyUtility.HitchToSpot(pawn, pos);
                    }
                }
                else if (pawnRole.Is(CarnivalRole.Worker))
                {
                    DutyUtility.MeanderAndHelp(pawn, Info.AverageLodgeTentPos, 10f);
                }
                else
                {
                    DutyUtility.MeanderAndHelp(pawn, wanderRect.RandomCell, Info.baseRadius);
                }
            }
        }
예제 #3
0
        // 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);
                }
            }
        }
예제 #4
0
        public override void UpdateAllDuties()
        {
            DutyUtility.EntertainShow(Data.entertainer, Data.entertainerSpot, Data.audienceRect.CenterCell);

            foreach (var pawn in lord.ownedPawns)
            {
                var spectateSpot = IntVec3.Invalid;

                if (!Data.audienceRect.Cells.Where((IntVec3 c) => pawn.CanReserve(c)).TryRandomElement(out spectateSpot))
                {
                    Log.Warning("[Carnivale] " + pawn + " tried to attend a show, but could not reserve any spot to go to.");
                    continue;
                }

                pawn.Reserve(spectateSpot);

                DutyUtility.AttendShow(pawn, spectateSpot, Data.entertainerSpot);
            }
        }
예제 #5
0
        private Toil FindTicketTaker()
        {
            return(new Toil
            {
                initAction = delegate
                {
                    var ticketTaker = Info.GetBestEntertainer(false);

                    if (ticketTaker == null)
                    {
                        Log.Error("[Carnivale] Found no ticket taker to give silver to.");
                        base.EndJobWith(JobCondition.Errored);
                    }

                    DutyUtility.HitchToSpot(ticketTaker, ticketTaker.Position);

                    CurJob.SetTarget(TargetIndex.B, ticketTaker);
                }
            });
        }
예제 #6
0
        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);
                }
            }
        }
예제 #7
0
        // 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);
                }
            }
        }
예제 #8
0
        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
                    };
                }
            }
        }
예제 #9
0
 public override void Cleanup()
 {
     CarnUtils.Info.showingNow = false;
     DutyUtility.MeanderAndHelp(Data.entertainer, Data.entertainerSpot, 20);
 }