コード例 #1
0
ファイル: Lord.cs プロジェクト: Chillu1/RimWorldDecompiledWeb
        public void GotoToil(LordToil newLordToil)
        {
            LordToil previousToil = curLordToil;

            if (curLordToil != null)
            {
                curLordToil.Cleanup();
            }
            curLordToil = newLordToil;
            ticksInToil = 0;
            if (curLordToil.lord != this)
            {
                Log.Error("curLordToil lord is " + ((curLordToil.lord == null) ? "null (forgot to add toil to graph?)" : curLordToil.lord.ToString()));
                curLordToil.lord = this;
            }
            curLordToil.Init();
            for (int i = 0; i < graph.transitions.Count; i++)
            {
                if (graph.transitions[i].sources.Contains(curLordToil))
                {
                    graph.transitions[i].SourceToilBecameActive(graph.transitions[i], previousToil);
                }
            }
            curLordToil.UpdateAllDuties();
        }
コード例 #2
0
 public override void SourceToilBecameActive(Transition transition, LordToil previousToil)
 {
     if (!transition.sources.Contains(previousToil))
     {
         this.Data.ticksPassed = 0;
     }
 }
コード例 #3
0
 public void SourceToilBecameActive(Transition transition, LordToil previousToil)
 {
     for (int i = 0; i < this.triggers.Count; i++)
     {
         this.triggers[i].SourceToilBecameActive(transition, previousToil);
     }
 }
コード例 #4
0
ファイル: Lord.cs プロジェクト: ehtnnd/RW-Decompile
        public void GotoToil(LordToil newLordToil)
        {
            LordToil previousToil = this.curLordToil;

            if (this.curLordToil != null)
            {
                this.curLordToil.Cleanup();
            }
            this.curLordToil = newLordToil;
            this.ticksInToil = 0;
            if (this.curLordToil.lord != this)
            {
                Log.Error("curLordToil lord is " + ((this.curLordToil.lord != null) ? this.curLordToil.lord.ToString() : "null (forgot to add toil to graph?)"), false);
                this.curLordToil.lord = this;
            }
            this.curLordToil.Init();
            for (int i = 0; i < this.graph.transitions.Count; i++)
            {
                if (this.graph.transitions[i].sources.Contains(this.curLordToil))
                {
                    this.graph.transitions[i].SourceToilBecameActive(this.graph.transitions[i], previousToil);
                }
            }
            this.curLordToil.UpdateAllDuties();
        }
コード例 #5
0
ファイル: Transition.cs プロジェクト: KraigXu/GameProject
 public Transition(LordToil firstSource, LordToil target, bool canMoveToSameState = false, bool updateDutiesIfMovedToSameState = true)
 {
     this.canMoveToSameState             = canMoveToSameState;
     this.updateDutiesIfMovedToSameState = updateDutiesIfMovedToSameState;
     this.target = target;
     sources     = new List <LordToil>();
     AddSource(firstSource);
 }
コード例 #6
0
 public void ErrorCheck()
 {
     if (this.lordToils.Count == 0)
     {
         Log.Error("Graph has 0 lord toils.", false);
     }
     using (IEnumerator <LordToil> enumerator = this.lordToils.Distinct <LordToil>().GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             LordToil toil = enumerator.Current;
             int      num  = (from s in this.lordToils
                              where s == toil
                              select s).Count <LordToil>();
             if (num != 1)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Graph has lord toil ",
                     toil,
                     " registered ",
                     num,
                     " times."
                 }), false);
             }
         }
     }
     using (List <Transition> .Enumerator enumerator2 = this.transitions.GetEnumerator())
     {
         while (enumerator2.MoveNext())
         {
             Transition trans = enumerator2.Current;
             int        num2  = (from t in this.transitions
                                 where t == trans
                                 select t).Count <Transition>();
             if (num2 != 1)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Graph has transition ",
                     trans,
                     " registered ",
                     num2,
                     " times."
                 }), false);
             }
         }
     }
     StateGraph.checkedToils = new HashSet <LordToil>();
     this.CheckForUnregisteredLinkedToilsRecursive(this.StartingToil);
     StateGraph.checkedToils = null;
 }
コード例 #7
0
ファイル: Transition.cs プロジェクト: KraigXu/GameProject
 public void AddSource(LordToil source)
 {
     if (sources.Contains(source))
     {
         Log.Error("Double-added source to Transition: " + source);
         return;
     }
     if (!canMoveToSameState && target == source)
     {
         Log.Error("Transition !canMoveToSameState and target is source: " + source);
     }
     sources.Add(source);
 }
コード例 #8
0
ファイル: LordManager.cs プロジェクト: potsh/RimWorld
 public void LordManagerTick()
 {
     for (int i = 0; i < lords.Count; i++)
     {
         lords[i].LordTick();
     }
     for (int num = lords.Count - 1; num >= 0; num--)
     {
         LordToil curLordToil = lords[num].CurLordToil;
         if (curLordToil.ShouldFail)
         {
             RemoveLord(lords[num]);
         }
     }
 }
コード例 #9
0
 public void AddSource(LordToil source)
 {
     if (this.sources.Contains(source))
     {
         Log.Error("Double-added source to Transition: " + source);
     }
     else
     {
         if (!this.canMoveToSameState && this.target == source)
         {
             Log.Error("Transition canMoveToSameState and target is source: " + source);
         }
         this.sources.Add(source);
     }
 }
コード例 #10
0
 public void LordManagerTick()
 {
     for (int i = 0; i < this.lords.Count; i++)
     {
         this.lords[i].LordTick();
     }
     for (int j = this.lords.Count - 1; j >= 0; j--)
     {
         LordToil curLordToil = this.lords[j].CurLordToil;
         if (curLordToil.ShouldFail)
         {
             this.RemoveLord(this.lords[j]);
         }
     }
 }
コード例 #11
0
 private void CheckForUnregisteredLinkedToilsRecursive(LordToil toil)
 {
     if (!lordToils.Contains(toil))
     {
         Log.Error("Unregistered linked lord toil: " + toil);
     }
     checkedToils.Add(toil);
     for (int i = 0; i < transitions.Count; i++)
     {
         Transition transition = transitions[i];
         if (transition.sources.Contains(toil) && !checkedToils.Contains(toil))
         {
             CheckForUnregisteredLinkedToilsRecursive(transition.target);
         }
     }
 }
コード例 #12
0
 private void CheckForUnregisteredLinkedToilsRecursive(LordToil toil)
 {
     if (!this.lordToils.Contains(toil))
     {
         Log.Error("Unregistered linked lord toil: " + toil, false);
     }
     StateGraph.checkedToils.Add(toil);
     for (int i = 0; i < this.transitions.Count; i++)
     {
         Transition transition = this.transitions[i];
         if (transition.sources.Contains(toil) && !StateGraph.checkedToils.Contains(toil))
         {
             this.CheckForUnregisteredLinkedToilsRecursive(transition.target);
         }
     }
 }
コード例 #13
0
        public override StateGraph CreateGraph()
        {
            StateGraph stateGraph   = new StateGraph();
            LordToil   startingToil = stateGraph.AttachSubgraph(new LordJob_Travel(this.travelDest).CreateGraph()).StartingToil;

            stateGraph.StartingToil = startingToil;
            LordToil_ExitMap lordToil_ExitMap = new LordToil_ExitMap(LocomotionUrgency.None, false);

            stateGraph.AddToil(lordToil_ExitMap);
            stateGraph.AddTransition(new Transition(startingToil, lordToil_ExitMap, false, true)
            {
                triggers =
                {
                    new Trigger_Memo("TravelArrived")
                }
            }, false);
            return(stateGraph);
        }
コード例 #14
0
 public void Notify_SignalReceived(Signal signal)
 {
     if (signal.tag == inSignalLeave)
     {
         if (ownedPawns.Any() && faction != null)
         {
             Messages.Message("MessagePawnsLeaving".Translate(faction.def.pawnsPlural), ownedPawns, MessageTypeDefOf.NeutralEvent);
         }
         LordToil lordToil = Graph.lordToils.Find((LordToil st) => st is LordToil_PanicFlee);
         if (lordToil != null)
         {
             GotoToil(lordToil);
         }
         else
         {
             lordManager.RemoveLord(this);
         }
     }
 }
コード例 #15
0
ファイル: Lord.cs プロジェクト: ehtnnd/RW-Decompile
 public void SetJob(LordJob lordJob)
 {
     if (this.curJob != null)
     {
         this.curJob.Cleanup();
     }
     this.curJob      = lordJob;
     this.curLordToil = null;
     lordJob.lord     = this;
     Rand.PushState();
     Rand.Seed  = this.loadID * 193;
     this.graph = lordJob.CreateGraph();
     Rand.PopState();
     this.graph.ErrorCheck();
     if (this.faction != null && !this.faction.IsPlayer && this.faction.def.autoFlee && lordJob.AddFleeToil)
     {
         LordToil_PanicFlee lordToil_PanicFlee = new LordToil_PanicFlee();
         lordToil_PanicFlee.avoidGridMode = AvoidGridMode.Smart;
         for (int i = 0; i < this.graph.lordToils.Count; i++)
         {
             Transition transition = new Transition(this.graph.lordToils[i], lordToil_PanicFlee, false, true);
             transition.AddPreAction(new TransitionAction_Message("MessageFightersFleeing".Translate(new object[]
             {
                 this.faction.def.pawnsPlural.CapitalizeFirst(),
                 this.faction.Name
             }), null, 1f));
             transition.AddTrigger(new Trigger_FractionPawnsLost(0.5f));
             this.graph.AddTransition(transition, true);
         }
         this.graph.AddToil(lordToil_PanicFlee);
     }
     for (int j = 0; j < this.graph.lordToils.Count; j++)
     {
         this.graph.lordToils[j].lord = this;
     }
     for (int k = 0; k < this.ownedPawns.Count; k++)
     {
         this.Map.attackTargetsCache.UpdateTarget(this.ownedPawns[k]);
     }
 }
コード例 #16
0
ファイル: LordManager.cs プロジェクト: KraigXu/GameProject
 public void LordManagerTick()
 {
     for (int i = 0; i < lords.Count; i++)
     {
         try
         {
             lords[i].LordTick();
         }
         catch (Exception ex)
         {
             Lord lord = lords[i];
             Log.Error(string.Format("Exception while ticking lord with job {0}: \r\n{1}", (lord == null) ? "NULL" : lord.LordJob.ToString(), ex.ToString()));
         }
     }
     for (int num = lords.Count - 1; num >= 0; num--)
     {
         LordToil curLordToil = lords[num].CurLordToil;
         if (curLordToil == null || curLordToil.ShouldFail)
         {
             RemoveLord(lords[num]);
         }
     }
 }
コード例 #17
0
ファイル: Lord.cs プロジェクト: Chillu1/RimWorldDecompiledWeb
 public void SetJob(LordJob lordJob)
 {
     if (curJob != null)
     {
         curJob.Cleanup();
     }
     curJob       = lordJob;
     curLordToil  = null;
     lordJob.lord = this;
     Rand.PushState();
     Rand.Seed = loadID * 193;
     graph     = lordJob.CreateGraph();
     Rand.PopState();
     graph.ErrorCheck();
     if (faction != null && !faction.IsPlayer && faction.def.autoFlee && lordJob.AddFleeToil)
     {
         LordToil_PanicFlee lordToil_PanicFlee = new LordToil_PanicFlee();
         lordToil_PanicFlee.useAvoidGrid = true;
         for (int i = 0; i < graph.lordToils.Count; i++)
         {
             Transition transition = new Transition(graph.lordToils[i], lordToil_PanicFlee);
             transition.AddPreAction(new TransitionAction_Message("MessageFightersFleeing".Translate(faction.def.pawnsPlural.CapitalizeFirst(), faction.Name)));
             transition.AddTrigger(new Trigger_FractionPawnsLost(faction.def.attackersDownPercentageRangeForAutoFlee.RandomInRangeSeeded(loadID)));
             graph.AddTransition(transition, highPriority: true);
         }
         graph.AddToil(lordToil_PanicFlee);
     }
     for (int j = 0; j < graph.lordToils.Count; j++)
     {
         graph.lordToils[j].lord = this;
     }
     for (int k = 0; k < ownedPawns.Count; k++)
     {
         Map.attackTargetsCache.UpdateTarget(ownedPawns[k]);
     }
 }
コード例 #18
0
ファイル: Trigger.cs プロジェクト: wensincai/RW-Decompile
 public virtual void SourceToilBecameActive(Transition transition, LordToil previousToil)
 {
 }
コード例 #19
0
ファイル: Lord.cs プロジェクト: ehtnnd/RW-Decompile
 private void ExposeData_StateGraph()
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         this.tmpLordToilData.Clear();
         for (int i = 0; i < this.graph.lordToils.Count; i++)
         {
             if (this.graph.lordToils[i].data != null)
             {
                 this.tmpLordToilData.Add(i, this.graph.lordToils[i].data);
             }
         }
         this.tmpTriggerData.Clear();
         int num = 0;
         for (int j = 0; j < this.graph.transitions.Count; j++)
         {
             for (int k = 0; k < this.graph.transitions[j].triggers.Count; k++)
             {
                 if (this.graph.transitions[j].triggers[k].data != null)
                 {
                     this.tmpTriggerData.Add(num, this.graph.transitions[j].triggers[k].data);
                 }
                 num++;
             }
         }
         this.tmpCurLordToilIdx = this.graph.lordToils.IndexOf(this.curLordToil);
     }
     Scribe_Collections.Look <int, LordToilData>(ref this.tmpLordToilData, "lordToilData", LookMode.Value, LookMode.Deep);
     Scribe_Collections.Look <int, TriggerData>(ref this.tmpTriggerData, "triggerData", LookMode.Value, LookMode.Deep);
     Scribe_Values.Look <int>(ref this.tmpCurLordToilIdx, "curLordToilIdx", -1, false);
     if (Scribe.mode == LoadSaveMode.PostLoadInit)
     {
         if (this.curJob.LostImportantReferenceDuringLoading)
         {
             this.lordManager.RemoveLord(this);
         }
         else
         {
             LordJob job = this.curJob;
             this.curJob = null;
             this.SetJob(job);
             foreach (KeyValuePair <int, LordToilData> current in this.tmpLordToilData)
             {
                 if (current.Key < 0 || current.Key >= this.graph.lordToils.Count)
                 {
                     Log.Error(string.Concat(new object[]
                     {
                         "Could not find lord toil for lord toil data of type \"",
                         current.Value.GetType(),
                         "\" (lord job: \"",
                         this.curJob.GetType(),
                         "\"), because lord toil index is out of bounds: ",
                         current.Key
                     }), false);
                 }
                 else
                 {
                     this.graph.lordToils[current.Key].data = current.Value;
                 }
             }
             this.tmpLordToilData.Clear();
             foreach (KeyValuePair <int, TriggerData> current2 in this.tmpTriggerData)
             {
                 Trigger triggerByIndex = this.GetTriggerByIndex(current2.Key);
                 if (triggerByIndex == null)
                 {
                     Log.Error(string.Concat(new object[]
                     {
                         "Could not find trigger for trigger data of type \"",
                         current2.Value.GetType(),
                         "\" (lord job: \"",
                         this.curJob.GetType(),
                         "\"), because trigger index is out of bounds: ",
                         current2.Key
                     }), false);
                 }
                 else
                 {
                     triggerByIndex.data = current2.Value;
                 }
             }
             this.tmpTriggerData.Clear();
             if (this.tmpCurLordToilIdx < 0 || this.tmpCurLordToilIdx >= this.graph.lordToils.Count)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Current lord toil index out of bounds (lord job: \"",
                     this.curJob.GetType(),
                     "\"): ",
                     this.tmpCurLordToilIdx
                 }), false);
             }
             else
             {
                 this.curLordToil = this.graph.lordToils[this.tmpCurLordToilIdx];
             }
         }
     }
 }
コード例 #20
0
ファイル: Lord.cs プロジェクト: Chillu1/RimWorldDecompiledWeb
        private void ExposeData_StateGraph()
        {
            if (Scribe.mode == LoadSaveMode.Saving)
            {
                tmpLordToilData.Clear();
                for (int i = 0; i < graph.lordToils.Count; i++)
                {
                    if (graph.lordToils[i].data != null)
                    {
                        tmpLordToilData.Add(i, graph.lordToils[i].data);
                    }
                }
                tmpTriggerData.Clear();
                int num = 0;
                for (int j = 0; j < graph.transitions.Count; j++)
                {
                    for (int k = 0; k < graph.transitions[j].triggers.Count; k++)
                    {
                        if (graph.transitions[j].triggers[k].data != null)
                        {
                            tmpTriggerData.Add(num, graph.transitions[j].triggers[k].data);
                        }
                        num++;
                    }
                }
                tmpCurLordToilIdx = graph.lordToils.IndexOf(curLordToil);
            }
            Scribe_Collections.Look(ref tmpLordToilData, "lordToilData", LookMode.Value, LookMode.Deep);
            Scribe_Collections.Look(ref tmpTriggerData, "triggerData", LookMode.Value, LookMode.Deep);
            Scribe_Values.Look(ref tmpCurLordToilIdx, "curLordToilIdx", -1);
            if (Scribe.mode != LoadSaveMode.PostLoadInit)
            {
                return;
            }
            if (curJob.LostImportantReferenceDuringLoading)
            {
                lordManager.RemoveLord(this);
                return;
            }
            LordJob job = curJob;

            curJob = null;
            SetJob(job);
            foreach (KeyValuePair <int, LordToilData> tmpLordToilDatum in tmpLordToilData)
            {
                if (tmpLordToilDatum.Key < 0 || tmpLordToilDatum.Key >= graph.lordToils.Count)
                {
                    Log.Error(string.Concat("Could not find lord toil for lord toil data of type \"", tmpLordToilDatum.Value.GetType(), "\" (lord job: \"", curJob.GetType(), "\"), because lord toil index is out of bounds: ", tmpLordToilDatum.Key));
                }
                else
                {
                    graph.lordToils[tmpLordToilDatum.Key].data = tmpLordToilDatum.Value;
                }
            }
            tmpLordToilData.Clear();
            foreach (KeyValuePair <int, TriggerData> tmpTriggerDatum in tmpTriggerData)
            {
                Trigger triggerByIndex = GetTriggerByIndex(tmpTriggerDatum.Key);
                if (triggerByIndex == null)
                {
                    Log.Error(string.Concat("Could not find trigger for trigger data of type \"", tmpTriggerDatum.Value.GetType(), "\" (lord job: \"", curJob.GetType(), "\"), because trigger index is out of bounds: ", tmpTriggerDatum.Key));
                }
                else
                {
                    triggerByIndex.data = tmpTriggerDatum.Value;
                }
            }
            tmpTriggerData.Clear();
            if (tmpCurLordToilIdx < 0 || tmpCurLordToilIdx >= graph.lordToils.Count)
            {
                Log.Error(string.Concat("Current lord toil index out of bounds (lord job: \"", curJob.GetType(), "\"): ", tmpCurLordToilIdx));
            }
            else
            {
                curLordToil = graph.lordToils[tmpCurLordToilIdx];
            }
        }
コード例 #21
0
 public Transition(LordToil firstSource, LordToil target)
 {
     this.sources = new List <LordToil>();
     this.AddSource(firstSource);
     this.target = target;
 }
コード例 #22
0
 public void AddToil(LordToil toil)
 {
     this.lordToils.Add(toil);
 }
コード例 #23
0
 internal bool <> m__0(LordToil s)
 {
     return(s == this.toil);
 }