Пример #1
0
 public ActWrapperTask(Act act)
 {
     ReassignOnDeath = false;
     WrappedAct      = act;
     Name            = WrappedAct.Name;
 }
Пример #2
0
        public override string GetDescription()
        {
            string desc = Stats.FullName + ", level " + Stats.LevelIndex +
                          " " +
                          Stats.CurrentClass.Name + ", " + Stats.Gender.ToString() + "\n    " +
                          "Happiness: " + GetHappinessDescription(Stats.Happiness) + ". Health: " + Stats.Health.Percentage +
                          ". Hunger: " + (100 - Stats.Hunger.Percentage) + ". Energy: " + Stats.Energy.Percentage +
                          "\n";

            if (CurrentTask.HasValue(out var currentTask))
            {
                desc += "    Task: " + currentTask.Name;
            }

            if (CurrentAct.HasValue(out Act currentAct))
            {
                desc += "\n   Action: ";

                var act = currentAct;
                while (act != null && act.LastTickedChild != null)
                {
                    Act prevAct = act;
                    act = act.LastTickedChild;
                    if (act == null)
                    {
                        act = prevAct;
                        break;
                    }

                    if (act == act.LastTickedChild)
                    {
                        break;
                    }
                }
                desc += act.Name;
            }

            if (LastFailedAct != null)
            {
                desc += "\n    Last failed: " + LastFailedAct;
            }

            if (Stats.IsAsleep)
            {
                desc += "\n UNCONSCIOUS";
            }

            if (Creature.IsPregnant)
            {
                desc += "\n Pregnant";
            }

            if (Creature.IsCloaked)
            {
                desc += "\n CLOAKED";
            }

            if (Stats.IsOnStrike)
            {
                desc += "\n ON STRIKE";
            }

            if (!String.IsNullOrEmpty(LastTaskFailureReason))
            {
                desc += "\n" + LastTaskFailureReason;
            }

            return(desc);
        }
Пример #3
0
        public override void Initialize()
        {
            Act   unreserveAct        = new Wrap(UnReserve);
            float time                = 3 * (Item.ItemType.BaseCraftTime / Creature.AI.Stats.BuffedInt);
            bool  factionHasResources = Item.SelectedResources != null && Item.SelectedResources.Count > 0 && Creature.AI.Faction.HasResources(Item.SelectedResources);
            Act   getResources        = null;

            if (Item.ExistingResource != null)
            {
                getResources = new Select(new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true),
                                          new Domain(() => !Item.HasResources &&
                                                     (Item.ResourcesReservedFor == Agent || Item.ResourcesReservedFor == null),
                                                     new Select(
                                                         new Sequence(new Wrap(ReserveResources),
                                                                      new GetResourcesAct(Agent, new List <ResourceAmount>()
                {
                    new ResourceAmount(Item.ExistingResource)
                }),
                                                                      new Wrap(SetSelectedResources)),
                                                         new Sequence(new Wrap(UnReserve), Act.Status.Fail)
                                                         )
                                                     ),
                                          new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true));
            }
            else if (!factionHasResources)
            {
                getResources = new Select(new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true),
                                          new Domain(() => !Item.HasResources &&
                                                     (Item.ResourcesReservedFor == Agent || Item.ResourcesReservedFor == null),
                                                     new Select(
                                                         new Sequence(new Wrap(ReserveResources),
                                                                      new GetResourcesAct(Agent, Item.ItemType.RequiredResources),
                                                                      new Wrap(SetSelectedResources)),
                                                         new Sequence(new Wrap(UnReserve), Act.Status.Fail)
                                                         )
                                                     ),
                                          new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true));
            }
            else
            {
                getResources = new Select(new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true),
                                          new Domain(() => !Item.HasResources && (Item.ResourcesReservedFor == Agent || Item.ResourcesReservedFor == null),
                                                     new Sequence(new Wrap(ReserveResources), new GetResourcesAct(Agent, Item.SelectedResources))),
                                          new Domain(() => Item.HasResources || Item.ResourcesReservedFor != null, true));
            }

            if (Item.ItemType.Type == CraftItem.CraftType.Object)
            {
                Act buildAct = null;

                if (Item.ExistingResource != null)
                {
                    buildAct = new Always(Status.Success);
                }
                else
                {
                    buildAct = new Wrap(() => Creature.HitAndWait(true, () => 1.0f,
                                                                  () => Item.Progress, () => Item.Progress += Creature.Stats.BuildSpeed / Item.ItemType.BaseCraftTime,
                                                                  () => Item.Location.WorldPosition + Vector3.One * 0.5f, "Craft"))
                    {
                        Name = "Construct object."
                    };
                }

                Tree = new Domain(IsNotCancelled, new Sequence(
                                      new ClearBlackboardData(Agent, "ResourcesStashed"),
                                      getResources,
                                      new Sequence(new Domain(ResourceStateValid,
                                                              new Sequence(
                                                                  new GoToVoxelAct(Voxel, PlanAct.PlanType.Adjacent, Agent),
                                                                  new Wrap(() => DestroyResources(() => Item.Location.WorldPosition)),
                                                                  new Wrap(WaitForResources)
                {
                    Name = "Wait for resources."
                },
                                                                  buildAct,
                                                                  new CreateCraftItemAct(Voxel, Creature.AI, Item)
                                                                  )
                                                              ))
                                      )) |
                       new Sequence(new Wrap(Creature.RestockAll), unreserveAct, false);
            }
            else
            {
                if (!String.IsNullOrEmpty(Item.ItemType.CraftLocation))
                {
                    Tree = new Sequence(
                        new Wrap(() => Creature.FindAndReserve(Item.ItemType.CraftLocation, Item.ItemType.CraftLocation)),
                        new ClearBlackboardData(Agent, "ResourcesStashed"),
                        getResources,
                        new Domain(ResourceStateValid, new Sequence
                                   (
                                       new GoToTaggedObjectAct(Agent)
                    {
                        Tag               = Item.ItemType.CraftLocation,
                        Teleport          = true,
                        TeleportOffset    = new Vector3(0.5f, 0.0f, 0),
                        ObjectName        = Item.ItemType.CraftLocation,
                        CheckForOcclusion = true
                    },
                                       new Wrap(() => DestroyResources(() => Agent.Position + MathFunctions.RandVector3Cube() * 0.5f)),
                                       new Wrap(WaitForResources)
                    {
                        Name = "Wait for resources."
                    },
                                       new Wrap(() => Creature.HitAndWait(true, () => 1.0f,
                                                                          () => Item.Progress, () => Item.Progress += Creature.Stats.BuildSpeed / Item.ItemType.BaseCraftTime,
                                                                          () => Agent.Position, Noise))
                    {
                        Name = "Construct object."
                    },
                                       unreserveAct,
                                       new Wrap(() => CreateResources(Item.SelectedResources)),
                                       new Wrap(Creature.RestockAll)
                                   )) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false)
                        ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false);
                }
                else
                {
                    Tree = new Sequence(
                        new ClearBlackboardData(Agent, "ResourcesStashed"),
                        getResources,
                        new Domain(ResourceStateValid, new Sequence(
                                       new Wrap(() => DestroyResources(() => Creature.Physics.Position + MathFunctions.RandVector3Cube() * 0.5f)),
                                       new Wrap(WaitForResources)
                    {
                        Name = "Wait for resources."
                    },
                                       new Wrap(() => Creature.HitAndWait(time, true, () => Creature.Physics.Position))
                    {
                        Name = "Construct object."
                    },
                                       new Wrap(() => CreateResources(Item.SelectedResources)))
                                   )
                        ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false);
                }
            }
            base.Initialize();
        }
Пример #4
0
 public FailMessage(CreatureAI Creature, Act SubAct, String Message)
     : base(Creature)
 {
     this.SubAct  = SubAct;
     this.Message = Message;
 }
Пример #5
0
 public Not(Act behavior)
 {
     Name  = "Not";
     Child = behavior;
 }
Пример #6
0
 public Domain(bool condition, Act child)
 {
     Name     = "Domain";
     Function = () => condition;
     Child    = child;
 }
Пример #7
0
 public Domain(Func <bool> condition, Act child)
 {
     Name     = "Domain: " + condition.Method.Name;
     Function = condition;
     Child    = child;
 }
Пример #8
0
 public CompoundCreatureAct(CreatureAI creature) :
     base(creature)
 {
     Name = "CompoundCreatureAct";
     Tree = null;
 }
Пример #9
0
        public static void RunTests()
        {
            Act       seq       = SimpleSequence();
            Act       select    = SimpleSelect();
            Act       par       = SimpleParallel();
            Act       forLoop   = SimpleFor();
            Act       whileLoop = SimpleWhile();
            Wait      wait      = new Wait(5.0f);
            Condition cond      = new Condition(() => { return(1 > 2 || 5 == 3 || 1 + 1 == 2); });

            Act complex    = ComplexBehavior();
            Act overloader = OverloaderTest();
            Act converter  = Convertor();

            seq.Initialize();
            foreach (Act.Status status in seq.Run())
            {
                Console.Out.WriteLine("Seq status: " + status.ToString());
            }

            select.Initialize();
            foreach (Act.Status status in select.Run())
            {
                Console.Out.WriteLine("select status: " + status.ToString());
            }

            par.Initialize();
            foreach (Act.Status status in par.Run())
            {
                Console.Out.WriteLine("par status: " + status.ToString());
            }

            forLoop.Initialize();
            foreach (Act.Status status in forLoop.Run())
            {
                Console.Out.WriteLine("for status: " + status.ToString());
            }

            whileLoop.Initialize();
            foreach (Act.Status status in whileLoop.Run())
            {
                Console.Out.WriteLine("while status: " + status.ToString());
            }

            cond.Initialize();

            foreach (Act.Status status in cond.Run())
            {
                Console.Out.WriteLine("cond status: " + status.ToString());
            }

            DateTime first = DateTime.Now;

            wait.Initialize();
            DwarfTime.LastTime = new DwarfTime(DateTime.Now - first, DateTime.Now - DateTime.Now);
            DateTime last = DateTime.Now;

            foreach (Act.Status status in wait.Run())
            {
                DwarfTime.LastTime = new DwarfTime(DateTime.Now - first, DateTime.Now - last);
                Console.Out.WriteLine("Wait status: " + status.ToString() + "," + wait.Time.CurrentTimeSeconds);
                last = DateTime.Now;
                global::System.Threading.Thread.Sleep(10);
            }

            complex.Initialize();
            foreach (Act.Status status in complex.Run())
            {
                DwarfTime.LastTime = new DwarfTime(DateTime.Now - first, DateTime.Now - last);
                Console.Out.WriteLine("Complex status: " + status.ToString());
                last = DateTime.Now;
                global::System.Threading.Thread.Sleep(10);
            }

            overloader.Initialize();
            foreach (Act.Status status in overloader.Run())
            {
                DwarfTime.LastTime = new DwarfTime(DateTime.Now - first, DateTime.Now - last);
                Console.Out.WriteLine("Overloader status: " + status.ToString());
                last = DateTime.Now;
                global::System.Threading.Thread.Sleep(10);
            }

            converter.Initialize();
            foreach (Act.Status status in converter.Run())
            {
                DwarfTime.LastTime = new DwarfTime(DateTime.Now - first, DateTime.Now - last);
                Console.Out.WriteLine("converter status: " + status.ToString());
                last = DateTime.Now;
                global::System.Threading.Thread.Sleep(10);
            }
        }