예제 #1
0
        public override void Do(Entity entity)
        {
            moveTime++;
            moveAction.Do(entity); // GotoAction checks collision with destination and hitting walls.
            bool result = moveAction.IsActive;

            if (moveTime == changeCount) // Change directions after a set time.
            {
                moveTime = 0;
                double d = Utilities.Rng.NextDouble();
                if (d < changeProbability)
                {
                    // Applies goto to set direction to (x, y). Goto applies Move(). False means the entity hit a wall and needs to head to another square.
                    destination = Utilities.GetRandomPoint();
                    moveAction  = new GotoAction(destination.X, destination.Y, entitySize);
                }
                else if (d > 0.75)
                {
                    entity.Stop();
                }
            }
            // The entity has hit a wall or reached the destination.
            else if (!result && entity.CollisionDirection != Direction.None)
            {
                destination = Utilities.GetDirectionalPoint(entity.CollisionDirection, entity.Position);
                moveAction  = new GotoAction(destination.X, destination.Y, entitySize);
            }

            //entity.ApplyNeedDeltas(UtilityDeltas);
            // Advertise needs deltas to entities but don't actually give them the reward. This is for a default action.
        }
예제 #2
0
        public override void Do(Entity entity)
        {
            if (!moveActionSet)
            {
                // Cannot set the move action in the constructor because the pickup's position might change after creating the pickup.
                // The PickupAction is created when the Item is constructed to avoid creating a new object every time a pickup advertises an action.
                moveAction    = new GotoAction(target.Position.X, target.Position.Y, entitySize);
                moveActionSet = true;
            }
            else
            {
                if (entity is Person person)
                {
                    // Once an entity decides to pickup an item, it must pick it up if it is still available.
                    // This is forced to make the food gathering behavior more aggressive. I should be able to fix this with the action utilities though.
                    if (!person.ActionLocked)
                    {
                        person.SetActionLockState(true);
                    }

                    if (target.IsPickedUp)
                    {
                        End();
                        return;
                    }

                    moveAction.Do(entity);

                    if (!moveAction.IsActive) // If the entity has reached the item and picked it up.
                    {
                        person.Pickup(target);
                        entity.ApplyNeedDeltas(UtilityDeltas);
                        End();
                    }
                }
                else
                {
                    End();
                }
            }
        }
예제 #3
0
 public ConsumeAction(Item pickup) : base(true)
 {
     this.pickup = pickup;
     moveAction  = new GotoAction(pickup.Position.X, pickup.Position.Y, pickup.Size);
 }
예제 #4
0
 public EatAction() : base(true)
 {
     gotoAction = new GotoAction(Entity.HomePosition.X, Entity.HomePosition.Y, entitySize);
 }
예제 #5
0
 public WanderAction() : base(true)
 {
     destination = Utilities.GetRandomPoint();
     moveAction  = new GotoAction(destination.X, destination.Y, entitySize);
 }
예제 #6
0
 public WanderAction(int x, int y) : base(true)
 {
     destination = new OrderedPair <int>(x, y);
     moveAction  = new GotoAction(destination.X, destination.Y, entitySize);
 }
예제 #7
0
 public DeliverFoodAction(RectangleF home) : base(true)
 {
     this.home  = home;
     moveAction = new GotoAction(home.X + home.Width / 2, home.Y + home.Height / 2, entitySize);
 }