Beispiel #1
0
 public GoToVoxelAct(string voxel, PlanAct.PlanType planType, CreatureAI creature, float radius = 0.0f)
     : base(creature)
 {
     Name = "Go to Voxel " + voxel;
     Tree = new Sequence(
             new ForLoop(
                 new Sequence(
                               new PlanAct(Agent, "PathToVoxel", voxel, planType) { Radius = radius},
                               new FollowPathAnimationAct(Agent, "PathToVoxel")
                              )
                                , 3, true),
                               new StopAct(Agent));
 }
Beispiel #2
0
        public GuardVoxelAct(CreatureAI agent, Voxel voxel)
            : base(agent)
        {
            Voxel = voxel;
            Name = "Guard Voxel " + voxel;

            Tree = new Sequence
                (
                    new GoToVoxelAct(voxel, PlanAct.PlanType.Adjacent, agent),
                    new StopAct(Agent),
                    new WhileLoop(new WanderAct(Agent, 1.0f, 0.5f, 0.1f), new Condition(LoopCondition)),
                    new Condition(ExitCondition)
                );
        }
Beispiel #3
0
 public override void Initialize()
 {
     Act unreserveAct = new Wrap(() => Creature.Unreserve("Train"));
     Tree = new Sequence(
         new Wrap(() => Creature.FindAndReserve("Train", "Train")),
         new Sequence
             (
                 new GoToTaggedObjectAct(Agent) { Tag = "Train", Teleport = false, TeleportOffset = new Vector3(1, 0, 0), ObjectName = "Train" },
                 new MeleeAct(Agent, "Train") {Training = true, Timeout = new Timer(10.0f, false)},
                 unreserveAct
             ) | new Sequence(unreserveAct, false)
             ) | new Sequence(unreserveAct, false);
     base.Initialize();
 }
Beispiel #4
0
 public GoToVoxelAct(Voxel voxel, PlanAct.PlanType planType, CreatureAI creature, float radius = 0.0f)
     : base(creature)
 {
     Voxel = voxel;
     Name = "Go to Voxel";
     if(Voxel != null)
     {
         Tree = new Sequence(
                               new SetBlackboardData<Voxel>(Agent, "TargetVoxel", Voxel),
                               new PlanAct(Agent, "PathToVoxel", "TargetVoxel", planType) { Radius = radius},
                               new FollowPathAnimationAct(Agent, "PathToVoxel"),
                               new StopAct(Agent));
     }
 }
Beispiel #5
0
 public KillVoxelAct(Voxel voxel, CreatureAI creature)
     : base(creature)
 {
     Voxel = voxel;
     Name = "Kill Voxel " + voxel.Position;
     Tree = new Sequence(
         new SetBlackboardData<Voxel>(creature, "DigVoxel", voxel),
         new Sequence(
                       new Wrap(() => IncrementAssignment(creature, "DigVoxel", 1)),
                       new GoToVoxelAct(voxel, PlanAct.PlanType.Adjacent, creature),
                       new Wrap(() => CheckIsDigDesignation(creature, "DigVoxel")),
                       new DigAct(Agent, "DigVoxel"),
                       new ClearBlackboardData(creature, "DigVoxel")
                     )
                     | new Wrap(() => IncrementAssignment(creature, "DigVoxel", -1)) & false);
 }
Beispiel #6
0
        public BuildRoomAct(CreatureAI agent, BuildRoomOrder buildRoom)
            : base(agent)
        {
            Name = "Build BuildRoom " + buildRoom.ToString();
            Resources = buildRoom.ListRequiredResources();

            Tree = new Sequence(new GetResourcesAct(Agent, Resources),
                new Sequence(
                    new Wrap(() => IsRoomBuildOrder(buildRoom)),
                    SetTargetVoxelFromRoomAct(buildRoom, "TargetVoxel"),
                    new Wrap(() => IsRoomBuildOrder(buildRoom)),
                    new GoToVoxelAct("TargetVoxel", PlanAct.PlanType.Adjacent, Agent),
                    new Wrap(() => IsRoomBuildOrder(buildRoom)),
                    new Wrap(() => Creature.HitAndWait(buildRoom.VoxelOrders.Count * 0.5f / agent.Stats.BuildSpeed, true)),
                    new Wrap(() => IsRoomBuildOrder(buildRoom)),
                    new PlaceRoomResourcesAct(Agent, buildRoom, Resources)
                    , new Wrap(Creature.RestockAll)) | new Wrap(Creature.RestockAll)
                );
        }
Beispiel #7
0
        public override void Initialize()
        {
            Body closestItem = Agent.Faction.FindNearestItemWithTags("Bed", Agent.Position, true);

            if (Agent.Status.Energy.IsUnhappy() && closestItem != null)
            {
                closestItem.ReservedFor = Agent;
                Creature.AI.Blackboard.SetData("Bed", closestItem);
                Act unreserveAct = new Wrap(() => Creature.Unreserve("Bed"));
                Tree =
                    new Sequence
                    (
                        new GoToEntityAct(closestItem, Creature.AI),
                        new TeleportAct(Creature.AI) {Location = closestItem.GetRotatedBoundingBox().Center() + new Vector3(-0.0f, 0.75f, -0.0f)},
                        new SleepAct(Creature.AI) { RechargeRate = 1.0f, Teleport = true, TeleportLocation = closestItem.GetRotatedBoundingBox().Center() + new Vector3(-0.0f, 0.75f, -0.0f) },
                        unreserveAct
                    ) | unreserveAct;
            }
            else if(Agent.Status.Energy.IsUnhappy() && closestItem == null)
            {
                Creature.AI.AddThought(Thought.ThoughtType.SleptOnGround);

                Tree = new SleepAct(Creature.AI)
                {
                    RechargeRate = 1.0f
                };
            }
            else
            {
                Tree = null;
            }
            base.Initialize();
        }
Beispiel #8
0
        public override void Initialize()
        {
            bool hasAllResources = true;

            foreach(ResourceAmount resource in Resources)
            {

                if (!Creature.Inventory.Resources.HasResource(resource))
                {
                    hasAllResources = false;
                }
            }

            if(!hasAllResources)
            {
                Stockpile nearestStockpile = Agent.Faction.GetNearestStockpile(Agent.Position);

                if(nearestStockpile == null)
                {
                    Tree = null;
                    return;
                }
                else
                {
                    Tree = new Sequence(new GoToZoneAct(Agent, nearestStockpile),
                                        new StashResourcesAct(Agent, Resources)
                                        );
                }
            }
            else
            {
                Tree = new Wrap(AlwaysTrue);
            }

            base.Initialize();
        }
Beispiel #9
0
        public override void Initialize()
        {
            Creature.OverrideCharacterMode = false;

            Tree = new Sequence(new ClearBlackboardData(Creature.AI, "Chair"),
                                new Wrap(() => Creature.FindAndReserve("Chair", "Chair")),
                                new GoToTaggedObjectAct(Creature.AI) {Tag = "Chair", Teleport = true, TeleportOffset = new Vector3(0, 0.1f, 0), ObjectName = "Chair"},
                                new Wrap(WaitUntilBored),
                                new Wrap(() => Creature.Unreserve("Chair"))) | new Wrap(() => Creature.Unreserve("Chair"));
            base.Initialize();
        }
Beispiel #10
0
        public override IEnumerable<Status> Run()
        {
            if(Tree == null)
            {
                if(ItemToGather == null)
                {
                    ItemToGather = Agent.Blackboard.GetData<Body>(ItemID);
                }

                if(ItemToGather != null)
                {
                    Tree = new Sequence(
                        new SetBlackboardData<Body>(Agent, "GatherItem", ItemToGather),
                        EntityIsGatherable(),
                        new Wrap(AddItemToGatherManager),
                        new GoToEntityAct(ItemToGather, Agent),
                        EntityIsGatherable(),
                        new StashAct(Agent, StashAct.PickUpType.None, null, "GatherItem", "GatheredResource"),
                        new Wrap(RemoveItemFromGatherManager),
                        new Wrap(AddStockOrder)
                        ) | (new Wrap(RemoveItemFromGatherManager) & new Wrap(Finally) & false);

                    Tree.Initialize();
                }
            }

            if(Tree == null)
            {
                yield return Status.Fail;
            }
            else
            {
                foreach(Status s in base.Run())
                {
                    yield return s;
                }
            }
        }
Beispiel #11
0
        public override void Initialize()
        {
            List<ResourceAmount> resources = Voxels.Select(pair => new ResourceAmount(ResourceLibrary.Resources[pair.Value.ResourceToRelease], 1)).ToList();

            List<Act> children = new List<Act>()
            {
                new GetResourcesAct(Agent, resources)
            };

            int i = 0;
            foreach (KeyValuePair<Voxel, VoxelType> pair in Voxels)
            {
                children.Add(new GoToVoxelAct(pair.Key, PlanAct.PlanType.Radius, Agent, 3.0f));
                children.Add(new PlaceVoxelAct(pair.Key, Creature.AI, resources[i]));
                i++;
            }

            children.Add(new Wrap(Creature.RestockAll));

            Tree = new Sequence(children);
            base.Initialize();
        }
Beispiel #12
0
        public override IEnumerable<Status> Run()
        {
            if (Tree == null)
            {
                if (ItemToStock == null)
                {
                    ItemToStock = Agent.Blackboard.GetData<ResourceAmount>(ItemID);
                }

                if (ItemToStock != null)
                {

                    Tree = new Sequence(
                        new SetBlackboardData<ResourceAmount>(Agent, "GatheredResource", ItemToStock.CloneResource()),
                        new SearchFreeStockpileAct(Agent, "TargetStockpile", "FreeVoxel"),

                                        new Select(
                                                    new Sequence(
                                                                    new GoToVoxelAct("FreeVoxel", PlanAct.PlanType.Adjacent, Agent),
                                                                    new PutResourceInZone(Agent, "TargetStockpile", "FreeVoxel", "GatheredResource")
                                                                )
                                                  )

                        ) | new Wrap(OnFail)
                     ;

                    Tree.Initialize();
                }
            }

            return base.Run();
        }
Beispiel #13
0
 public override void Initialize()
 {
     if (Teleport)
     {
         Tree =
             new Sequence
                 (
                 new GoToEntityAct(ObjectName, Creature.AI),
                 new Wrap(TeleportFunction)
                 );
     }
     else
     {
         Tree =
             new Sequence
                 (
                 new GoToEntityAct(ObjectName, Creature.AI)
                 );
     }
     base.Initialize();
 }
Beispiel #14
0
 public override void Initialize()
 {
     Act unreserveAct = new Wrap(() => Creature.Unreserve("Anvil"));
     float time = CraftLibrary.CraftItems[ItemType].BaseCraftTime / Creature.AI.Stats.BuffedInt;
     Tree = new Sequence(
         new Wrap(() => Creature.FindAndReserve("Anvil", "Anvil")),
         new GetResourcesAct(Agent, CraftLibrary.CraftItems[ItemType].RequiredResources),
         new Sequence
             (
                 new GoToTaggedObjectAct(Agent) { Tag = "Anvil", Teleport = false, TeleportOffset = new Vector3(1, 0, 0), ObjectName = "Anvil"},
                 new Wrap(() => WaitAndHit(time)),
                 new Wrap(DestroyResources),
                 unreserveAct,
                 new GoToVoxelAct(Voxel, PlanAct.PlanType.Adjacent, Agent),
                 new CreateCraftItemAct(Voxel, Creature.AI, ItemType)
             ) | new Sequence(unreserveAct, new Wrap(Creature.RestockAll), false)
             ) | new Sequence(unreserveAct, false);
     base.Initialize();
 }
Beispiel #15
0
 public override void Initialize()
 {
     Act unreserveAct = new Wrap(() => Creature.Unreserve("Research"));
     Tree = new Sequence(
         new Wrap(() => Creature.FindAndReserve("Research", "Research")),
         new Sequence
             (
                 new GoToTaggedObjectAct(Agent) { Tag = "Research", Teleport = false, TeleportOffset = new Vector3(1, 0, 0), ObjectName = "Research" },
                 new ResearchSpellAct( Agent, Spell),
                 unreserveAct
             ) | new Sequence(unreserveAct, false)
             ) | new Sequence(unreserveAct, false);
     base.Initialize();
 }
Beispiel #16
0
        public override void Initialize()
        {
            if (FarmToWork != null)
            {
                Farm.FarmTile closestTile = FarmToWork.GetNearestFreeFarmTile(Creature.AI.Position);
                if (closestTile != null)
                {
                    Tree = new Sequence(
                        new Wrap(GetClosestTile),
                        new GoToVoxelAct("ClosestVoxel", PlanAct.PlanType.Adjacent, Creature.AI),
                        new StopAct(Creature.AI),
                        new Wrap(() => FarmATile("ClosestTile")));
                }
            }

            base.Initialize();
        }
Beispiel #17
0
 public override void Initialize()
 {
     Creature.AI.Blackboard.Erase("PathToEntity");
     Creature.AI.Blackboard.Erase("EntityVoxel");
     Tree = new Sequence(
         new Wrap(() => Creature.ClearBlackboardData("PathToEntity")),
         new Wrap(() => Creature.ClearBlackboardData("EntityVoxel")),
         InHands() |
          new Sequence(
             new ForLoop(
                 new SetTargetVoxelFromEntityAct(Agent, EntityName, "EntityVoxel") &
                 new PlanAct(Agent, "PathToEntity", "EntityVoxel", PlanAct.PlanType.Adjacent) &
                 new Parallel(new FollowPathAnimationAct(Agent, "PathToEntity") * new Wrap(() => TargetMoved("PathToEntity")), new Wrap(CollidesWithTarget)) { ReturnOnAllSucces = false }, 5, true),
             new StopAct(Agent)));
     Tree.Initialize();
     base.Initialize();
 }