protected override void OnFirstRun(Actor self) { // We can safely assume the claim is successful, since this is only called in the // same actor-tick as the targetCell is selected. Therefore no other harvester // would have been able to claim. claimLayer.TryClaimCell(self, targetCell); }
void IBotTick.BotTick(IBot bot) { if (world.WorldTick % tickEvery != 0) { return; } var miners = world.ActorsHavingTrait <Transforms>() .Where(a => a.Owner == player && a.IsIdle && Info.MinerTypes.Contains(a.Info.Name)); foreach (var miner in miners) { var closestMine = ClosestHarvestablePos(miner); if (!closestMine.HasValue) { continue; } var claimedOk = claimLayer.TryClaimCell(miner, closestMine.Value); if (!claimedOk) { continue; } bot.QueueOrder(new Order("Move", miner, Target.FromCell(world, closestMine.Value), true)); bot.QueueOrder(new Order("DeployTransform", miner, true)); } }
public override Activity Tick(Actor self) { if (IsCanceled) { return(NextActivity); } if (NextInQueue != null) { return(NextInQueue); } var deliver = new DeliverResources(self); if (harv.IsFull) { return(ActivityUtils.SequenceActivities(deliver, NextActivity)); } var closestHarvestablePosition = ClosestHarvestablePos(self); // If no harvestable position could be found, either deliver the remaining resources // or get out of the way and do not disturb. if (!closestHarvestablePosition.HasValue) { if (!harv.IsEmpty) { return(deliver); } harv.LastSearchFailed = true; var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell); var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5); self.QueueActivity(mobile.MoveTo(moveTo, 1)); self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); // TODO: The harvest-deliver-return sequence is a horrible mess of duplicated code and edge-cases var notify = self.TraitsImplementing <INotifyHarvesterAction>(); foreach (var n in notify) { n.MovingToResources(self, moveTo, this); } var randFrames = self.World.SharedRandom.Next(100, 175); // Avoid creating an activity cycle var next = NextInQueue; NextInQueue = null; return(ActivityUtils.SequenceActivities(next, new Wait(randFrames), this)); } else { // Attempt to claim the target cell if (!claimLayer.TryClaimCell(self, closestHarvestablePosition.Value)) { return(ActivityUtils.SequenceActivities(new Wait(25), this)); } harv.LastSearchFailed = false; // If not given a direct order, assume ordered to the first resource location we find: if (!harv.LastOrderLocation.HasValue) { harv.LastOrderLocation = closestHarvestablePosition; } self.SetTargetLine(Target.FromCell(self.World, closestHarvestablePosition.Value), Color.Red, false); // TODO: The harvest-deliver-return sequence is a horrible mess of duplicated code and edge-cases var notify = self.TraitsImplementing <INotifyHarvesterAction>(); foreach (var n in notify) { n.MovingToResources(self, closestHarvestablePosition.Value, this); } return(ActivityUtils.SequenceActivities(mobile.MoveTo(closestHarvestablePosition.Value, 1), new HarvestResource(self), this)); } }
public override Activity Tick(Actor self) { if (IsCanceled) { return(NextActivity); } if (NextInQueue != null) { return(NextInQueue); } var deliver = new DeliverResources(self); if (harv.IsFull) { return(ActivityUtils.SequenceActivities(deliver, NextActivity)); } var closestHarvestablePosition = ClosestHarvestablePos(self); //If no harvestable position could be found,either deliver the remaining resources or get out of the way and do not disturb. //如果没有找到可以获取的位置,可以交付剩余的资源,也可以避开干扰。 if (!closestHarvestablePosition.HasValue) { if (!harv.IsEmpty) { return(deliver); } harv.LastSearchFailed = true; var unblockCell = harv.LastHarvestedCell ?? (self.Location + harvInfo.UnblockCell); var moveTo = mobile.NearestMoveableCell(unblockCell, 2, 5); self.QueueActivity(mobile.MoveTo(moveTo, 1)); self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false); var randFrames = self.World.SharedRandom.Next(100, 175); //Avoid creating an activity cycle var next = NextInQueue; NextInQueue = null; return(ActivityUtils.SequenceActivities(next, new Wait(randFrames), this)); } else { //Attempt to claim the target cell if (!claimLayer.TryClaimCell(self, closestHarvestablePosition.Value)) { return(ActivityUtils.SequenceActivities(new Wait(25), this)); } harv.LastSearchFailed = false; if (!harv.LastOrderLocation.HasValue) { harv.LastOrderLocation = closestHarvestablePosition; } self.SetTargetLine(Target.FromCell(self.World, closestHarvestablePosition.Value), Color.Red, false); return(ActivityUtils.SequenceActivities(mobile.MoveTo(closestHarvestablePosition.Value, 1), new HarvestResource(self), this)); } }