Smarter Agricultural Tower Planting/Harvesting Order
Posted: Tue Sep 01, 2026 10:59 pm
TL;DR
Currently, ag. towers plant and harvest in a seemingly random order, thus wasting a ton of time moving the arm from spot to spot. Instead, they should go to the closest valid spot.What?
Currently, if an ag. tower is looking to plant a seed and there are multiple valid, empty planting spots in range, or if it is looking to harvest a plant and there are multiple fully-grown plants in range, it picks one seemingly at random. This means that it often will select a cell which is on the other side of its area and sloooowly swing its arm all the way over there - only for the next selected location to be back near where it started.Instead of this, the tower should use some sort of efficient algorithm to select which spot to go for next in order to minimize travel time. Now, a fully optimized algorithm would require solving the Travelling Salesman Problem, not to mention accurately predicting at what future times cells would become eligible for planting or harvesting. But there are a couple solutions which would be Good Enough:
- First, we can safely assume the arm will always be starting from one of the 48 planting locations in a tower's range, and its destination will be another one of these locations. The only time this would not be the case is when it is first built and is cleaning up naturally-grown plants in its area of operation, or if it is harvesting trees which were planted manually or by another tower with a misaligned grid; these are all rare enough that we don't care if they aren't done very efficiently, so we can simply approximate to the nearest planting location.
- Thus the simplest solution would be to assign all 48 planting locations a fixed order based on a space-filling curve. In order to pick a destination, the tower simply scans through this list, starting from its current location and cycling to the top if it hits the end, until it finds a location that is valid, and picks that. The nature of space-filling curves means that locations that are nearby in the list will also tend to be nearby in 2D space, so this will be reasonably efficient, especially for towers where most of their planting spots are useable. (It will be less efficient for towers where only some of the spots are useable; while items that are close on the list tend to be close in 2D space, items that are close in 2D space are not necessarily all that close in the list, so a tower might end up picking a destination halfway across its area while ignoring one right next to where it currently is.)
- Alternately, use a greedy algorithm which looks at all currently valid destinations and picks whichever one will take the least time to get to from its current location. This will be more efficient than a fixed list, especially for towers where the set of valid destinations is sparse.
- You can even optimise this further: for each possible starting square, you can have pre-generated list of the other 47 squares from nearest to furthest; the tower then just picks the list corresponding to its current location, and scans it until it finds a destination which is valid. This avoids having to compute distances every time a tower needs to pick a destination. You also only need one copy of these lists, which can be shared between all towers in the game.
Why?
Currently, if a given tower has lots of valid growth spots, it can potentially spend more time travelling than it does actually doing its job. This materially affects the rate at which fruits are produced on Gleba, since the delay between a tree reaching 100% maturity and it actually being harvested and replaced by a new seed effectively adds to the 5 minute growth time of the tree itself.Also, it just offends my sensibilities to watch the towers being so bloody inefficient about things.