protected override bool Satisfied(Pawn pawn)
        {
            if (!pawn.health.hediffSet.hediffs.Any())
            {
                return(false);
            }
            if (!pawn.RaceProps.Humanlike)
            {
                return(false);
            }
            if (pawn.Faction == Faction.OfPlayer)
            {
                return(false);
            }
            if (pawn.Faction != null && pawn.Faction.HostileTo(Faction.OfPlayer))
            {
                return(false);
            }
            if (pawn.HostFaction == Faction.OfPlayer && pawn.guest.IsPrisoner)
            {
                return(false);
            }
            if (pawn.InBed() && pawn.guest != null && pawn.Faction != pawn.guest.HostFaction && pawn.CurrentBed().Faction == pawn.guest.HostFaction)
            {
                return(false);
            }
            if (Find.TickManager.TicksGame < pawn.mindState.lastHarmTick + 300)
            {
                return(false);
            }
            if (Find.TickManager.TicksGame < pawn.mindState.lastEngageTargetTick + 300)
            {
                return(false);
            }
            if (Find.TickManager.TicksGame < pawn.mindState.lastSelfTendTick + 300)
            {
                return(false);
            }
            Lord lord = pawn.GetLord();

            if (lord != null && lord.CurLordToil != null && !lord.CurLordToil.AllowSelfTend)
            {
                return(false);
            }
            if (!pawn.health.HasHediffsNeedingTend())
            {
                return(false);
            }
            if (pawn.Faction != null)
            {
                bool foundActiveThreat = false;
                RegionTraverser.BreadthFirstTraverse(pawn.Position, pawn.Map, RegionTraverser.PassAll, delegate(Region x)
                {
                    List <Thing> list = x.ListerThings.ThingsInGroup(ThingRequestGroup.AttackTarget);
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (GenHostility.IsActiveThreatTo((IAttackTarget)list[i], pawn.Faction))
                        {
                            foundActiveThreat = true;
                            break;
                        }
                    }
                    return(foundActiveThreat);
                }, 5);
                if (foundActiveThreat)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        private static DiaOption RequestMilitaryAidOption(Map map, Faction faction, Pawn negotiator)
        {
            string text = "RequestMilitaryAid".Translate(25);

            if (faction.PlayerRelationKind != FactionRelationKind.Ally)
            {
                DiaOption diaOption = new DiaOption(text);
                diaOption.Disable("MustBeAlly".Translate());
                return(diaOption);
            }
            if (!faction.def.allowedArrivalTemperatureRange.ExpandedBy(-4f).Includes(map.mapTemperature.SeasonalTemp))
            {
                DiaOption diaOption2 = new DiaOption(text);
                diaOption2.Disable("BadTemperature".Translate());
                return(diaOption2);
            }
            int num = faction.lastMilitaryAidRequestTick + 60000 - Find.TickManager.TicksGame;

            if (num > 0)
            {
                DiaOption diaOption3 = new DiaOption(text);
                diaOption3.Disable("WaitTime".Translate(num.ToStringTicksToPeriod()));
                return(diaOption3);
            }
            if (NeutralGroupIncidentUtility.AnyBlockingHostileLord(map, faction))
            {
                DiaOption diaOption4 = new DiaOption(text);
                diaOption4.Disable("HostileVisitorsPresent".Translate());
                return(diaOption4);
            }
            DiaOption diaOption5 = new DiaOption(text);

            if ((int)faction.def.techLevel < 4)
            {
                diaOption5.link = CantMakeItInTime(faction, negotiator);
            }
            else
            {
                IEnumerable <Faction> source = (from x in map.attackTargetsCache.TargetsHostileToColony
                                                where GenHostility.IsActiveThreatToPlayer(x)
                                                select((Thing)x).Faction into x
                                                where x != null && !x.HostileTo(faction)
                                                select x).Distinct();
                if (source.Any())
                {
                    DiaNode   diaNode    = new DiaNode("MilitaryAidConfirmMutualEnemy".Translate(faction.Name, source.Select((Faction fa) => fa.Name).ToCommaList(useAnd: true)));
                    DiaOption diaOption6 = new DiaOption("CallConfirm".Translate());
                    diaOption6.action = delegate
                    {
                        CallForAid(map, faction);
                    };
                    diaOption6.link = FightersSent(faction, negotiator);
                    DiaOption diaOption7 = new DiaOption("CallCancel".Translate());
                    diaOption7.linkLateBind = ResetToRoot(faction, negotiator);
                    diaNode.options.Add(diaOption6);
                    diaNode.options.Add(diaOption7);
                    diaOption5.link = diaNode;
                }
                else
                {
                    diaOption5.action = delegate
                    {
                        CallForAid(map, faction);
                    };
                    diaOption5.link = FightersSent(faction, negotiator);
                }
            }
            return(diaOption5);
        }
Esempio n. 3
0
        public override StateGraph CreateGraph()
        {
            StateGraph      stateGraph      = new StateGraph();
            LordToil_Travel lordToil_Travel = (LordToil_Travel)(stateGraph.StartingToil = new LordToil_Travel(chillSpot));
            LordToil_DefendTraderCaravan lordToil_DefendTraderCaravan = new LordToil_DefendTraderCaravan();

            stateGraph.AddToil(lordToil_DefendTraderCaravan);
            LordToil_DefendTraderCaravan lordToil_DefendTraderCaravan2 = new LordToil_DefendTraderCaravan(chillSpot);

            stateGraph.AddToil(lordToil_DefendTraderCaravan2);
            LordToil_ExitMapAndEscortCarriers lordToil_ExitMapAndEscortCarriers = new LordToil_ExitMapAndEscortCarriers();

            stateGraph.AddToil(lordToil_ExitMapAndEscortCarriers);
            LordToil_ExitMap lordToil_ExitMap = new LordToil_ExitMap();

            stateGraph.AddToil(lordToil_ExitMap);
            LordToil_ExitMap lordToil_ExitMap2 = new LordToil_ExitMap(LocomotionUrgency.Walk, canDig: true);

            stateGraph.AddToil(lordToil_ExitMap2);
            LordToil_ExitMapTraderFighting lordToil_ExitMapTraderFighting = new LordToil_ExitMapTraderFighting();

            stateGraph.AddToil(lordToil_ExitMapTraderFighting);
            Transition transition = new Transition(lordToil_Travel, lordToil_ExitMapAndEscortCarriers);

            transition.AddSources(lordToil_DefendTraderCaravan, lordToil_DefendTraderCaravan2);
            transition.AddPreAction(new TransitionAction_Message("MessageVisitorsDangerousTemperature".Translate(faction.def.pawnsPlural.CapitalizeFirst(), faction.Name)));
            transition.AddPostAction(new TransitionAction_EndAllJobs());
            transition.AddTrigger(new Trigger_PawnExperiencingDangerousTemperatures());
            stateGraph.AddTransition(transition);
            Transition transition2 = new Transition(lordToil_Travel, lordToil_ExitMap2);

            transition2.AddSources(lordToil_DefendTraderCaravan, lordToil_DefendTraderCaravan2, lordToil_ExitMapAndEscortCarriers, lordToil_ExitMap, lordToil_ExitMapTraderFighting);
            transition2.AddTrigger(new Trigger_PawnCannotReachMapEdge());
            transition2.AddPostAction(new TransitionAction_Message("MessageVisitorsTrappedLeaving".Translate(faction.def.pawnsPlural.CapitalizeFirst(), faction.Name)));
            transition2.AddPostAction(new TransitionAction_WakeAll());
            transition2.AddPostAction(new TransitionAction_EndAllJobs());
            stateGraph.AddTransition(transition2);
            Transition transition3 = new Transition(lordToil_ExitMap2, lordToil_ExitMapTraderFighting);

            transition3.AddTrigger(new Trigger_PawnCanReachMapEdge());
            transition3.AddPostAction(new TransitionAction_EndAllJobs());
            stateGraph.AddTransition(transition3);
            Transition transition4 = new Transition(lordToil_Travel, lordToil_ExitMapTraderFighting);

            transition4.AddSources(lordToil_DefendTraderCaravan, lordToil_DefendTraderCaravan2, lordToil_ExitMapAndEscortCarriers, lordToil_ExitMap);
            transition4.AddTrigger(new Trigger_FractionPawnsLost(0.2f));
            transition4.AddPostAction(new TransitionAction_EndAllJobs());
            stateGraph.AddTransition(transition4);
            Transition transition5 = new Transition(lordToil_Travel, lordToil_DefendTraderCaravan);

            transition5.AddTrigger(new Trigger_PawnHarmed());
            transition5.AddPreAction(new TransitionAction_SetDefendTrader());
            transition5.AddPostAction(new TransitionAction_WakeAll());
            transition5.AddPostAction(new TransitionAction_EndAllJobs());
            stateGraph.AddTransition(transition5);
            Transition transition6 = new Transition(lordToil_DefendTraderCaravan, lordToil_Travel);

            transition6.AddTrigger(new Trigger_TicksPassedWithoutHarm(1200));
            stateGraph.AddTransition(transition6);
            Transition transition7 = new Transition(lordToil_Travel, lordToil_DefendTraderCaravan2);

            transition7.AddTrigger(new Trigger_Memo("TravelArrived"));
            stateGraph.AddTransition(transition7);
            Transition transition8 = new Transition(lordToil_DefendTraderCaravan2, lordToil_ExitMapAndEscortCarriers);

            transition8.AddTrigger(new Trigger_TicksPassed((!DebugSettings.instantVisitorsGift) ? Rand.Range(27000, 45000) : 0));
            transition8.AddPreAction(new TransitionAction_CheckGiveGift());
            transition8.AddPreAction(new TransitionAction_Message("MessageTraderCaravanLeaving".Translate(faction.Name)));
            transition8.AddPostAction(new TransitionAction_WakeAll());
            stateGraph.AddTransition(transition8);
            Transition transition9 = new Transition(lordToil_ExitMapAndEscortCarriers, lordToil_ExitMapAndEscortCarriers, canMoveToSameState: true);

            transition9.canMoveToSameState = true;
            transition9.AddTrigger(new Trigger_PawnLost());
            transition9.AddTrigger(new Trigger_TickCondition(() => LordToil_ExitMapAndEscortCarriers.IsAnyDefendingPosition(lord.ownedPawns) && !GenHostility.AnyHostileActiveThreatTo(base.Map, faction, countDormantPawnsAsHostile: true), 60));
            stateGraph.AddTransition(transition9);
            Transition transition10 = new Transition(lordToil_ExitMapAndEscortCarriers, lordToil_ExitMap);

            transition10.AddTrigger(new Trigger_TicksPassed(60000));
            transition10.AddPostAction(new TransitionAction_WakeAll());
            stateGraph.AddTransition(transition10);
            Transition transition11 = new Transition(lordToil_DefendTraderCaravan2, lordToil_ExitMapAndEscortCarriers);

            transition11.AddSources(lordToil_Travel, lordToil_DefendTraderCaravan);
            transition11.AddTrigger(new Trigger_ImportantTraderCaravanPeopleLost());
            transition11.AddTrigger(new Trigger_BecamePlayerEnemy());
            transition11.AddPostAction(new TransitionAction_WakeAll());
            transition11.AddPostAction(new TransitionAction_EndAllJobs());
            stateGraph.AddTransition(transition11);
            return(stateGraph);
        }
 protected override bool CanFireNowSub(IncidentParms parms)
 {
     if (!base.CanFireNowSub(parms))
     {
         return(false);
     }
     return(((Map)parms.target).attackTargetsCache.TargetsHostileToColony.Where((IAttackTarget p) => GenHostility.IsActiveThreatToPlayer(p)).Sum((IAttackTarget p) => (p as Pawn)?.kindDef.combatPower ?? 0f) > 120f);
 }