Exemple #1
0
        public override bool Tick(Actor self)
        {
            if (harv.IsTraitDisabled)
            {
                Cancel(self, true);
            }

            if (IsCanceling || harv.IsFull)
            {
                return(true);
            }

            // Move towards the target cell
            if (self.Location != targetCell)
            {
                foreach (var n in notifyHarvesterActions)
                {
                    n.MovingToResources(self, targetCell);
                }

                QueueChild(move.MoveTo(targetCell, 0));
                return(false);
            }

            if (!harv.CanHarvestCell(self, self.Location))
            {
                return(true);
            }

            // Turn to one of the harvestable facings
            if (harvInfo.HarvestFacings != 0)
            {
                var current = facing.Facing;
                var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
                if (desired != current)
                {
                    QueueChild(new Turn(self, desired));
                    return(false);
                }
            }

            var resource = resourceLayer.GetResource(self.Location);

            if (resource.Type == null || resourceLayer.RemoveResource(resource.Type, self.Location) != 1)
            {
                return(true);
            }

            harv.AcceptResource(self, resource.Type);

            foreach (var t in notifyHarvesterActions)
            {
                t.Harvested(self, resource.Type);
            }

            QueueChild(new Wait(harvInfo.BaleLoadDelay));
            return(false);
        }
Exemple #2
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled)
            {
                if (territory != null)
                {
                    territory.UnclaimByActor(self);
                }
                return(NextActivity);
            }

            harv.LastHarvestedCell = self.Location;

            if (harv.IsFull)
            {
                if (territory != null)
                {
                    territory.UnclaimByActor(self);
                }
                return(NextActivity);
            }

            // Turn to one of the harvestable facings
            if (harvInfo.HarvestFacings != 0)
            {
                var current = facing.Facing;
                var desired = Util.QuantizeFacing(current, harvInfo.HarvestFacings) * (256 / harvInfo.HarvestFacings);
                if (desired != current)
                {
                    return(Util.SequenceActivities(new Turn(self, desired), this));
                }
            }

            var resource = resLayer.Harvest(self.Location);

            if (resource == null)
            {
                if (territory != null)
                {
                    territory.UnclaimByActor(self);
                }
                return(NextActivity);
            }

            harv.AcceptResource(resource);

            foreach (var t in self.TraitsImplementing <INotifyHarvesterAction>())
            {
                t.Harvested(self, resource);
            }

            return(Util.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this));
        }
Exemple #3
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled)
            {
                claimLayer.RemoveClaim(self);
                return NextActivity;
            }

            harv.LastHarvestedCell = self.Location;

            if (harv.IsFull)
            {
                claimLayer.RemoveClaim(self);
                return NextActivity;

            }

            if(harvInfo.HarvestFacings != 0)
            {
                var current = facing.Facing;
                var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
                if (desired != current)
                    return ActivityUtils.SequenceActivities(new Turn(self, desired), this);
            }

            var resource = resLayer.Harvest(self.Location);
            if(resource == null)
            {
                claimLayer.RemoveClaim(self);
                return NextActivity;
            }

            harv.AcceptResource(resource);

            foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>())
                t.Harvested(self, resource);

            return ActivityUtils.SequenceActivities(new Wait(harvInfo.BaleLoadDelay), this);
        }
Exemple #4
0
        public override Activity Tick(Actor self)
        {
            if (ChildActivity != null)
            {
                ChildActivity = ActivityUtils.RunActivityTick(self, ChildActivity);
                if (ChildActivity != null)
                {
                    return(this);
                }
            }

            if (IsCanceling || harv.IsFull)
            {
                return(NextActivity);
            }

            // Move towards the target cell
            if (self.Location != targetCell)
            {
                foreach (var n in self.TraitsImplementing <INotifyHarvesterAction>())
                {
                    n.MovingToResources(self, targetCell, new FindAndDeliverResources(self));
                }

                self.SetTargetLine(Target.FromCell(self.World, targetCell), Color.Red, false);
                QueueChild(self, move.MoveTo(targetCell, 2), true);
                return(this);
            }

            if (!harv.CanHarvestCell(self, self.Location))
            {
                return(NextActivity);
            }

            // Turn to one of the harvestable facings
            if (harvInfo.HarvestFacings != 0)
            {
                var current = facing.Facing;
                var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
                if (desired != current)
                {
                    QueueChild(self, new Turn(self, desired), true);
                    return(this);
                }
            }

            var resource = resLayer.Harvest(self.Location);

            if (resource == null)
            {
                return(NextActivity);
            }

            harv.AcceptResource(self, resource);

            foreach (var t in self.TraitsImplementing <INotifyHarvesterAction>())
            {
                t.Harvested(self, resource);
            }

            QueueChild(self, new Wait(harvInfo.BaleLoadDelay), true);
            return(this);
        }