You must be logged in to post messages.
Please login or register

Caesar III: Game Help
Moderated by Granite Q, Gweilo

Hop to:    
loginhomeregisterhelprules
Bottom
Topic Subject: Cartpushers, traders, etc. - which building is nearest?
posted 11-30-08 11:47 ET (US)   
Quotes from the 'Coming Out in Tarsus' thread:
Didn't someone post some years back about deleting trees or something that 'fixed' a wayward cartpusher who was intent on ignoring the obvious nearest destination? ... I don't think it ever got explained.

That sounds familiar (including the lack of explanation).
Testing by deleting the temporary buildings, I found that the cart pusher went back to "correct" behavior when an actor colony (to the NNE of the troublesome granary) was built.
I think I might be close to shedding some light on this. I've been studying the Buildings List (to aid a restful night's sleep) and while some of the data is fairly easy to suss out I had great difficulty in making sense of certain parts of it. As is usually the case with these puzzles, you get a wild thought, test it out and voila - problem resolved.

Almost every building on the map is given a value at offset 26 (decimal) which I could not for the life of me make sense of. Almost every building on the map is also given coordinates at offet 32/33 which represent the building's access tile. The access tile is often, but not always, the tile on which walkers spawn. It appears to be determined as the first road tile encountered when circling the building clockwise starting NE of the northern tile.

If no road tile is encountered the access tile is the nearest unoccupied tile to the map entry point. Note that this applies to all buildings regardless of whether they have workers, require road access, etc. except that native huts access on the first available tile whether or not road tiles are involved and native fields have no access tile if they are not within 2 tiles of a road. Where a valid access tile cannot be identified (either because there are no unoccupied tiles or they are 'boxed in') the coordinates are set to zero. Curiously, no access tile is stored in the Buildings List for housing, which is apparently computed at need.

Where there is no access tile there is no value stored at offset 26. Clue number one. It transpires that the value stored at offset 26 is derived from the access tile coordinates relative to the map entry point. To illustrate, the career 'Tarsus' has its entry point at x=0, y=78. In my Tarsus, I have a weapons workshop at 28,29 which has access at 29,31. We take the difference in 'x' (29 - 0 = 29) and the difference in 'y' (78 - 31 = 47). Add them together and add 1 (don't ask me why plus one, it just is, okay?) - result 77. This, we find, is the value stored at offset 26. So the value is essentially the sum of the distances along each axis - not just as the crow flies.

Another example - a fountain at 25,70 has access at 25,71. Applying the same formula results in a value of 33, but when we look at offset 26 we find a value of 55. What's gone wrong?

If you have my Tarsus to hand you can see that because of obstructions, to get to the entry point from the fountain you have to go around the wheat warehouses. This means going 11 tiles along the Y axis in the opposite direction to that in which you need to go, so you need to go 11 tiles back again. Those 22 tiles of displacement, added to the 33 we calculated, gives the correct figure of 55. So we can modify our statement to say that the value is the sum of the total tiles traversed in either direction along each axis.

It's easy to imagine that a donkey caravan might use that number to identify the neasrest warehouses - just pick the one with the lowest number (assuming it stocks/accepts the appropriate goods). I'm fairly sure that these numbers are used for other distance assessments too - the gane does not necessarily actually compute the distance between say, an iron mine and all the weapons workshops it could deliver to. It probably simply picks the one whose value at offset 26 is closest to its own (all other things being equal).

If that is the case - and I mean if - it might explain some anomalies observed where farms deliver to the 'wrong' granary, pushers 'get' from the 'wrong' warehouse, etc (though I'm sure stock levels account for some of these anomalies too since a getter may prefer a distant warehouse with more stock to a closer one with less stock). It might also explain why apparently irrelevant changes to a map (such as deleting trees or building actor colonies) might interfere with decisions made. If additions/deletions increase or decrease displacement of routes to the entry point along either axis the numbers will change.

It's also clear, if the foregoing does indeed account for how proximity is determined, that it is the access tile that is relevant and not the northern tile. I'd already observed that in earlier experiments with an olive farm surrounded by oil workshops, noting the order in which deliveries were made. Changing the road acces points (while leaving the buildings in the same relative positions) changed the order. So did building a statue nearby

Edited to correct description of how 'access tile' is determined

[This message has been edited by Trium3 (edited 07-22-2012 @ 06:10 PM).]

Replies:
posted 11-30-08 14:07 ET (US)     1 / 7  
Are the "access point" and "offset 26" values for each of the 9 sections of a warehouse calculated as you describe? If each section is considered as a 1x1 building, some of the sections (even the main section) might not have an access point.

By the way, off-topic: do you have a comment on my observation in your "Labor Access" thread?

[This message has been edited by Brugle (edited 11-30-2008 @ 02:08 PM).]

posted 11-30-08 15:19 ET (US)     2 / 7  
Are the "access point" and "offset 26" values for each of the 9 sections of a warehouse calculated as you describe? If each section is considered as a 1x1 building, some of the sections (even the main section) might not have an access point.
I understand what you are questioning here and yes, the 9 sections of a warehouse all share the access point of the building as a whole. So a warehouse with a road along its SE edge has its access tile set three tiles SE of the northern tile and this is repeated in all 9 elements. This tile is used to determine the value in offset 26 (which, of course, results in the same value for all 9 tiles).

Interestingly, there is an additional field in the Buildings List entry for a warehouse which, so far as I can determine (ie this holds true for every example I have looked at) appears to indicate by value 01 that the northern tile of the warehouse is accessible by road and by value 02 that it is not. This, too, is repeated throughout the entries for the 9 sections, which are linked together by storing a pair of offsets indicating the locations of the 'previous' and 'next' elements (since the 9 elements are not necessarily stored contiguously). As you know, the northern tile will commonly be the one used for deliveries but the access tile computed as I described appears nevertheless to be the one used for determining the value of offset 26 (I need a name for that!)

As a further aside, the warehouse itself does not seem to know what it contains (at least as far as the Buildings List is concerned). The storage bays record the goods ID (wheat = 1, pottery = 15, in the sequence which appears in the 'show prices' screen of the Trade advisor) and the amount - up to 4 units. Nothing seems to indicate what orders are set, but each warehouse appears to have its own unique consecutive number (in addition to the consecutive building number stored in every entry in the list). This suggests that elsewhere in the game file there is a list of warehouses which this number cross-references.
By the way, off-topic: do you have a comment on my observation in your "Labor Access" thread?
Sorry, I've not logged on for a week, but your observation shot a hole in my theories to which I could only react with 'Hmmmm...' I'll post a bit more over there.
posted 01-15-11 22:52 ET (US)     3 / 7  
I'd quite forgotten this one. I was reminded while playing around with docks in the trade centre thread. Is it really over two years ago?

I've found it virtually impossible to devise an algorithm which can always be relied upon to predict which of several buildings a cartpusher might go to, but I'm closer than I was. Sometimes when A should be marginally preferred over B it is B that gets the cookie - most often, investigation reveals a tile-counting error somewhere but on occasions I can only shrug. An algorithm that isn't always right is obviously the wrong algorithm, but in most practical situations the 'close fit' is good enough. Certainly in the near-chaos of a large oil industry few players are going to be bothered to work out which workshop will receive olives next, but I find it useful information on occasions. And its nice to be able to explain some of those weird things we've all encountered.

The algorithm appears to take at least the following parameters:

(i) the distance from the supplier's 'access tile' to the recipient's 'access tile', measured 'as the crow flies' where (eg) 3 tiles NE and 6 tiles SE counts as 6
(ii) the distance between the entry point and the supplier's 'access tile' measured as the (random) walker walks where (eg) 3 tiles NE and 6 tiles SE counts as 9. This is measured along the shortest walkable path (avoiding rocks, trees, buildings, etc. but including gardens, rubble, granary pathways and gatehouses) which is a much simpler way of describing it than my previous effort. The entry tile itself is included in the tile count.
(iii) the distance between the entry point and the recipient's access tile measured similarly
(iv) the quantity of stock the recipient already has
(v) (tie-breaker) the position of the recipient's entry in the building list

I've learned not to rely too much on what the game file says is the value of (ii) and (iii) since it is sometimes incorrect. My feeling is that the game calculates fresh values each time they are needed and ignores the stored values (which are perhaps a legacy from development). Sometimes the 'access tile' recorded in the save is not the one actually used - for example a warehouse on the SE of a road has its access tile recorded as the first road tile clockwise from north, but the cartpusher actually spawns against the northern tile (2 tiles to the NE) and all computations seem to be based on that tile rather than the tile recorded in the game file.

Taking the example of a raw material producer (or a warehouse with raw material) supplying a number of workshops (assuming for now that all connected workshops have no stock), we take the difference between (ii) and (iii) and add it to (i). The workshop for which this produces the lowest number will be supplied. If two or more workshops rank equally, then usually the one first encountered when scanning the building table is chosen (more on this later).

Where a workshop already has a unit of raw material its 'score' is increased by around 20 and put back in the queue, meaning that it will get a second unit when the supplier works its way through all other lower scores, even if some workshops have yet to receive a unit. I'd expect this number to be exactly 20 rather than 'around', but sometimes I see a first unit to a 25 go before a second unit to a 5 while sometimes it's the other way around. My head hurts trying to explain these things, so 'around' it is

Warehouses can be induced to overstock workshops if a disconnected workshop is demanding elsewhere in the city. Once all workshops have 2 units (however distant they may be) a third delivery is made to each in the same order as the first units were distributed. Once again, delivery of a unit puts the workshop back in the queue for more, this time with 10 points added. If you have workshops with initial scores of 5, 15, 25 and 35 points you can end up with 5 units in the first shop and still only two in the last.

The following illustration shows a warehouse supplying vines to a number of wine workshops, which were built in order from the southernmost (numbered 1) in an anticlockwise direction. You'd not be too surprised that the workshops in front of the warehouse are showing grapes, but those couple on the other side might raise some eyebrows.



The garden tile is 50 tiles from the entry point, which lies to the NW. Using that as a starting point, the warehouse access (spawn) tile is determined to be 63 tiles away. The following table shows workshops in building list order and details (a) workshop number (anti-clockwise from south), (b) distance from entry point, (c) difference between that and 63, (d) distance from warehouse, (e) total of c and d, (f) expected supply order


(a)(b) (c) (d) (e) (f)
1 75 12 11 23 17
2 77 14 9 23 18
3 79 16 9 25 20
4 77 14 9 23 19
5 75 12 9 21 16
6 70 7 7 14 7
7 68 5 5 10 5
8 66 3 3 6 3
9 64 1 1 2 1
10 62 1 1 2 2
11 60 3 3 6 4
12 55 8 4 12 6
13 53 10 6 16 10
14 55 8 8 16 11
15 57 6 10 16 12
16 62 1 13 14 8
17 64 1 13 14 9
18 66 3 13 16 13
19 68 5 13 18 14
20 70 7 13 20 15

In practice, there were three minor departures from schedule: the two 14-scores at workshop numbers 16 and 17 were supplied before the one at #6, the 16-score at #18 was supplied before the three at 13, 14 and 15, and the 23-score at #4 was supplied before those at 1 and 2. These results might suggest that the tie-breaker theory is wrong, or that the algorithm is inexact and showing a tie where none actually exists. It is possible that another tie-breaker is used before resorting to building-table order and I have yet to discover it, but the building-table tie-breaker is evident if, for example, workshops 1 and 2 are deleted and rebuilt in reverse order, resulting in a reversal of the delivery order. This is not apparent if any of the errant workshops are swapped with another of apparently equal ranking.

I've conducted many tests, some with baffling results. The same basic layout illustrated above can be manipulated (by positioning the warehouse and/or placing obstacles on the path to the entry point) to produce a wide variety of delivery patterns. Some are very bizarre indeed, but they can usually be at least approximately explained.

This post is now quite long enough so I'll wrap up. The correct algorithm still eludes, but I'm reasonably pleased with the degree of correspondence manifest in my approximation (though this is admittedly a particularly well-behaved example), particularly as it is able to explain eccentricities like why 16 and 17 are showing grapes well ahead of others nearby and why the apparently distant #1 gets served before either of the two to its north-east. Not to mention why a deleted tree halfway across the map can change everything

[This message has been edited by Trium (edited 01-15-2011 @ 11:04 PM).]

posted 01-17-11 14:42 ET (US)     4 / 7  
Perhaps more useful to know is to which out of a choice of warehouses a cartpusher will take his stuff. An algorithm for that too has been elusive, but has now proven much easier to establish after the work described in my last post.

The destination for a unit of goods is determined by prioritizing individual storage bays. It makes no difference at all what else is on the warehouse. It matters not whether the warehouse is nearly full or completely empty, whether it has different types of goods in stock or just one. If the algorithm selects a particular bay he will deliver to it without taking any account of the status of the other bays. You may have noticed that when a workshop delivers to a warehouse there is a tendency for the graphic to show the goods turning up in a bay closer to the workshop. Or maybe you haven't - I do understand that not everybody likes to set the slowest possible speed and stare at the screen for hours on end

In fact, the algorithm doesn't even select a warehouse at all. It is exclusively selecting a bay.
It is the same as it was for workshops, except that the parameter at (i) is the distance from the supplier's access tile to the bay, and the parameter at (iv) is not used. Note Brugle's question and my answer in replies #1 and #2 - the access tile for all bays belonging to the same warehouse is the same, and it is the first road tile encountered when circling the building clockwise from north. It is not necessarily the same thing as the delivery (or spawning) tile.

Again, building table order is the tie-breaker. I cannot conceive any way it is possible to have bays belonging to the same warehouse in any order other than: (north is left-up)

1 2
3 4 5
6 7 8

and this is how I shall refer to them.





Taking the layout pictured in the last post, I deleted the workshops and replaced them with 12 warehouses. I built them starting in the western corner and working clockwise, which is different from how I built the workshops, but no matter. The table once again shows (a) warehouse number, (b) distance from entry point, and (c) difference between that and 63, but this time column (d) is the distance from the supplying warehouse's spawning tile and the nearest bay with space belonging to the receiving warehouse. (e) is the total of (c) and (d) (I haven't used (f) this time)

(a) (b) (c) (d) (e)
1 63 0 10 10
2 56 7 7 14
3 53 10 4 14
4 60 3 1 4
5 63 0 1 1
6 66 3 3 6
7 69 6 6 12
8 76 13 4 17
9 79 16 7 23
10 76 13 10 23
11 69 6 10 16
12 66 3 10 13


Warehouse 5 is where we start, though remember it's the bay not the warehouse we're looking for. Warehouse 5 has bays 1, 2 and 3 tiles from the supplier's spawn point. The table shows the score for the nearest bay, but there are others which score 2 and 3. Those are still better than the next lowest in the table, so the entire warehouse is filled.

Filling of W4 begins with bay 2, since this is the bay which scores the 4. Bays 1, 4 and 5 score 5 and so are filled next. Finally the remaining bays, which score 6 (and so rank equally with bays from W6) and are filled because they come first in the building table. If we delete W4 and W6, rebuilding them in reverse order, we find that we still get bays 1,2,4 and 5 of W4 filled first, but we then fill the 6-scores from W6 (bays 3 and 6) because we've changed the build order before continuing with W4.

Once W4 and W6 are done, we readily see that W1 is next, even though there are closer warehouses. It contains bays which score 10, 11 and 12, all of which out-rank anything else, so that warehouse is completely filled.

W7 has bays scoring 12, 13 and 14. W12 also has bays of 13 and 14, so once W7's 13s are done we break off to fill W12's 13s before we return to finish off W7. We are now at the position shown in the illustration - filling of W7 to the east has been suspended while W12 has just received 2 bays.

Continuing, W2, W3 and W12 now all have bays scoring 14, so we fill three bays from each. Now they all score 15, so another three from each are filled. W12 is full, W2 and W3 take 3 more bays each. W11 takes just 2 bays before W8 outranks it on build order. Those two are filled in alternating 3-bay ranks, leaving W9 and W10 to take turns for the remainder.

I've made several attempts at describing all that so that it is clear - I realise that it isn't. Setting it all out has, however, clarified something in my own mind and I think I might know what is wrong with my workshop algorithm. Hmmm. Back in a couple of hours.....

[This message has been edited by Trium (edited 01-17-2011 @ 10:12 PM).]

posted 01-17-11 19:09 ET (US)     5 / 7  
Yes, I thought so. Now it all fits

I had expected that distance, however measured, would be from like to like, eg northern tile to northern tile or access tile to access tile. I had not considered the possibility of a mixture. For workshops, the distance between the supplier and the recipient should be measured from the supplier's spawn tile to the recipient's northern tile. The figures shown in column (d) in the table I posted in reply #3 are incorrect. All we need do is substitute the corrected table...

(a)(b) (c)  (d) (e) (f)
1 75 12 11 23 18
2 77 14 9 23 19
3 79 16 7 23 20
4 77 14 7 21 17
5 75 12 7 19 16
6 70 7 7 14 9
7 68 5 5 10 5
8 66 3 3 6 3
9 64 1 1 2 1
10 62 1 1 2 2
11 60 3 3 6 4
12 55 8 3 11 6
13 53 10 5 15 11
14 55 8 7 15 12
15 57 6 9 15 13
16 62 1 11 12 7
17 64 1 11 12 8
18 66 3 11 14 10
19 68 5 11 16 14
20 70 7 11 18 15

...and we have a completely accurate prediction of behaviour. Including the expectation that a second unit will be delivered to #9 and #10 (by then scoring 22) just before delivering the first to #1. So simple!

Now that I have that straightened out I can re-assess all my test data. To my considerable relief the algorithm now appears to be infallible. I am able to correct a couple more things - I can remove my guarded 'around 20' from reply #3 and state confidently that a workshop's score is increased by 20 points if it has 1 unit of raw material. Over-stocked workshops score 10 points for each unit over the second. Also, in the case of delivering warehouses, the tile to use for counting distance to the entry point is the tile stored in the game file (ie the first road tile clockwise from north) but the tile to use for counting distance to the destination is the tile on which the cartpusher spawns (which may be, but isn't necessarily, the same).

I'll just round off by saying that the algorithm for choosing a destination granary is exactly the same, except that no account is taken of stock levels. Once a granary is preferred, it will remain preferred until it is full (or changes to the map affect the algorithm). Also, none of this applies to importing dockers, whose behaviour is still under investigation.
posted 01-17-11 21:21 ET (US)     6 / 7  
For the second time in a few days, you have explained a C3 phenomenon which has puzzled players for years. Well done!
posted 06-07-23 08:00 ET (US)     7 / 7  
If two unconnected road networks touch a building, the access tile is selected from the larger of the road networks.
Caesar IV Heaven » Forums » Caesar III: Game Help » Cartpushers, traders, etc. - which building is nearest?
Top
You must be logged in to post messages.
Please login or register
Hop to:    
Caesar IV Heaven | HeavenGames