public override void DoAction(Transition trans)
        {
            Lord    lord = trans.target.lord;
            IntVec3 targetDestination = (lord.LordJob as LordJob_MiningCoBase).targetDestination;
            bool    needNewExitSpot   = false;
            bool    isEdgeCell        = targetDestination.InBounds(lord.Map) &&
                                        ((targetDestination.x == 0) ||
                                         (targetDestination.x == lord.Map.Size.x - 1) ||
                                         (targetDestination.z == 0) ||
                                         (targetDestination.z == lord.Map.Size.z - 1));

            if (isEdgeCell == false)
            {
                needNewExitSpot = true;
            }
            else
            {
                foreach (Pawn pawn in lord.ownedPawns)
                {
                    if (pawn.CanReach(targetDestination, PathEndMode.OnCell, Danger.Some) == false)
                    {
                        needNewExitSpot = true;
                        break;
                    }
                }
            }

            IntVec3 newTargetDestination = targetDestination;

            if (needNewExitSpot)
            {
                if (Expedition.TryFindRandomExitSpot(lord.Map, lord.ownedPawns.RandomElement().Position, out newTargetDestination) == false)
                {
                    newTargetDestination = CellFinder.RandomEdgeCell(lord.Map);
                }
            }
            (lord.LordJob as LordJob_MiningCoBase).targetDestination = newTargetDestination;
            // Refresh lord toil destination anyway as it may have been initialized with an invalid vector (case of a fallback).
            LordToil_Travel travelToil = trans.target as LordToil_Travel;

            if (travelToil != null)
            {
                travelToil.SetDestination(newTargetDestination);
            }
            LordToil_EscortDownedPawn escortToil = trans.target as LordToil_EscortDownedPawn;

            if (escortToil != null)
            {
                escortToil.SetDestination(newTargetDestination);
            }
        }
Exemplo n.º 2
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            LordToil_EscortDownedPawn toil = pawn.GetLord().CurLordToil as LordToil_EscortDownedPawn;

            Pawn pawnToRescue = Util_DownedPawn.GetNearestReachableDownedPawn(pawn);

            if (pawnToRescue != null)
            {
                return(new Job(Util_JobDefOf.CarryDownedPawn, pawnToRescue, toil.Data.targetDestination)
                {
                    count = 1
                });
            }
            else
            {
                toil.Notify_RescuedEnded();
            }
            return(null);
        }
Exemplo n.º 3
0
        public override StateGraph CreateGraph()
        {
            StateGraph      stateGraph = new StateGraph();
            LordToil_Travel travelToil = new LordToil_Travel(this.targetDestination);

            stateGraph.StartingToil = travelToil;
            LordToil_DefendPoint defendPointToil = new LordToil_DefendPoint(false);

            stateGraph.AddToil(defendPointToil);
            LordToil_BoardSpaceship boardSpaceshipToil = new LordToil_BoardSpaceship(this.targetDestination, LocomotionUrgency.Walk);

            stateGraph.AddToil(boardSpaceshipToil);
            LordToil_EscortDownedPawn escortDownedPawnPeacefullyToil = new LordToil_EscortDownedPawn(this.targetDestination, LocomotionUrgency.Walk);

            stateGraph.AddToil(escortDownedPawnPeacefullyToil);
            LordToil exitMap = stateGraph.AttachSubgraph(new LordJob_ExitMap(IntVec3.Invalid).CreateGraph()).StartingToil;

            // Defend.
            stateGraph.AddTransition(new Transition(travelToil, defendPointToil)
            {
                triggers =
                {
                    new Trigger_PawnHarmed(1f, false)
                },
                preActions =
                {
                    new TransitionAction_SetDefendLocalGroup()
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Back to travel after defending.
            stateGraph.AddTransition(new Transition(defendPointToil, travelToil)
            {
                triggers =
                {
                    new Trigger_TicksPassedWithoutHarm(1200)
                }
            });
            // Escort downed pawn peacefully.
            stateGraph.AddTransition(new Transition(travelToil, escortDownedPawnPeacefullyToil)
            {
                triggers =
                {
                    new Trigger_ReachableDownedPawn()
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Back to travel after escorting pawn peacefully.
            stateGraph.AddTransition(new Transition(escortDownedPawnPeacefullyToil, travelToil)
            {
                triggers =
                {
                    new Trigger_Memo("RescueEnded")
                }
            });
            // Board dispatcher.
            stateGraph.AddTransition(new Transition(travelToil, boardSpaceshipToil)
            {
                triggers =
                {
                    new Trigger_Memo("TravelArrived")
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Exit map.
            stateGraph.AddTransition(new Transition(travelToil, exitMap)
            {
                sources =
                {
                    escortDownedPawnPeacefullyToil,
                    boardSpaceshipToil
                },
                triggers =
                {
                    new Trigger_PawnCannotReachTargetDestination()
                },
                postActions =
                {
                    new TransitionAction_CancelDispatcherPick(),
                    new TransitionAction_EndAllJobs()
                }
            });
            // Exit map. This transition does not include travelToil as the dispatcher is not landed when the team begins travelling.
            stateGraph.AddTransition(new Transition(escortDownedPawnPeacefullyToil, exitMap)
            {
                sources =
                {
                    boardSpaceshipToil
                },
                triggers =
                {
                    new Trigger_SpaceshipNotFound()
                },
                postActions =
                {
                    new TransitionAction_CancelDispatcherPick(),
                    new TransitionAction_EndAllJobs()
                }
            });
            return(stateGraph);
        }
Exemplo n.º 4
0
        public override StateGraph CreateGraph()
        {
            StateGraph           stateGraph = new StateGraph();
            LordToil_DefendPoint dropToil   = new LordToil_DefendPoint(true);

            stateGraph.StartingToil = dropToil; // Just used to verify the exit spot is valid.
            LordToil_Travel travelToil = new LordToil_Travel(this.targetDestination);

            stateGraph.AddToil(travelToil);
            LordToil_DefendPoint defendPointToil = new LordToil_DefendPoint(false);

            stateGraph.AddToil(defendPointToil);
            LordToil_ExitMap exitMapPeacefullyToil = new LordToil_ExitMap(LocomotionUrgency.Walk, false);

            stateGraph.AddToil(exitMapPeacefullyToil);
            LordToil_EscortDownedPawn escortDownedPawnPeacefullyToil = new LordToil_EscortDownedPawn(this.targetDestination, LocomotionUrgency.Walk);

            stateGraph.AddToil(escortDownedPawnPeacefullyToil);
            LordToil_ExitMap exitMapHurryToil = new LordToil_ExitMap(LocomotionUrgency.Jog, true);

            stateGraph.AddToil(exitMapHurryToil);
            LordToil_DefendPoint defendPointHurryToil = new LordToil_DefendPoint(false);

            stateGraph.AddToil(defendPointHurryToil);
            LordToil_EscortDownedPawn escortDownedPawnHurryToil = new LordToil_EscortDownedPawn(this.targetDestination, LocomotionUrgency.Jog);

            stateGraph.AddToil(escortDownedPawnHurryToil);

            // Begin travel.
            stateGraph.AddTransition(new Transition(dropToil, travelToil)
            {
                triggers =
                {
                    new Trigger_TicksPassedWithoutHarm(1)
                },
                preActions =
                {
                    new TransitionAction_CheckExitSpotIsValid()
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Defend.
            stateGraph.AddTransition(new Transition(travelToil, defendPointToil)
            {
                triggers =
                {
                    new Trigger_PawnHarmed(1f, false)
                },
                preActions =
                {
                    new TransitionAction_SetDefendLocalGroup()
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Back to travel after defending.
            stateGraph.AddTransition(new Transition(defendPointToil, travelToil)
            {
                triggers =
                {
                    new Trigger_TicksPassedWithoutHarm(1200)
                },
                preActions =
                {
                    new TransitionAction_EnsureHaveExitDestination()
                }
            });
            // Escort downed pawn peacefully.
            stateGraph.AddTransition(new Transition(travelToil, escortDownedPawnPeacefullyToil)
            {
                sources =
                {
                    exitMapPeacefullyToil
                },
                triggers =
                {
                    new Trigger_ReachableDownedPawn()
                },
                preActions =
                {
                    new TransitionAction_CheckExitSpotIsValid()
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Back to travel after escorting pawn peacefully.
            stateGraph.AddTransition(new Transition(escortDownedPawnPeacefullyToil, travelToil)
            {
                triggers =
                {
                    new Trigger_Memo("RescueEnded")
                }
            });
            // Exit peacefully.
            stateGraph.AddTransition(new Transition(travelToil, exitMapPeacefullyToil)
            {
                triggers =
                {
                    new Trigger_Memo("TravelArrived")
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Exit in hurry.
            stateGraph.AddTransition(new Transition(travelToil, exitMapHurryToil)
            {
                sources =
                {
                    exitMapPeacefullyToil,
                    escortDownedPawnPeacefullyToil
                },
                triggers =
                {
                    new Trigger_PawnCannotReachTargetDestination(),
                    new Trigger_HostileToColony()
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Defend in hurry.
            stateGraph.AddTransition(new Transition(exitMapHurryToil, defendPointHurryToil)
            {
                triggers =
                {
                    new Trigger_PawnHarmed(1f, false)
                },
                preActions =
                {
                    new TransitionAction_SetDefendLocalGroup()
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Back to exit in hurry after defending.
            stateGraph.AddTransition(new Transition(defendPointHurryToil, exitMapHurryToil)
            {
                triggers =
                {
                    new Trigger_TicksPassedWithoutHarm(1200)
                }
            });
            // Escort downed pawn in hurry.
            stateGraph.AddTransition(new Transition(exitMapHurryToil, escortDownedPawnHurryToil)
            {
                triggers =
                {
                    new Trigger_ReachableDownedPawn()
                },
                preActions =
                {
                    new TransitionAction_CheckExitSpotIsValid()
                },
                postActions =
                {
                    new TransitionAction_EndAllJobs()
                }
            });
            // Back to exit in hurry after escorting pawn in hurry.
            stateGraph.AddTransition(new Transition(escortDownedPawnHurryToil, exitMapHurryToil)
            {
                triggers =
                {
                    new Trigger_Memo("RescueEnded")
                }
            });
            return(stateGraph);
        }