The Forum Rules and Guidelines
Our forum has Rules and Guidelines. Please, be kind and read them ;).

[patch] new goods ai using the network to pass on goods (incomplete)

Started by TimWintle, February 22, 2009, 11:40:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


This suffers from one major flaw, but since I probably won't find any time to improve it for quite a while I thought I would post it and see if anyone else could find a work-around.

This patch adds a new goods ai (and adds it to the makefile, player menu etc.), heavily based on the existing one, but with the following changes:

* Looks at the time it will take to make an ROI when deciding to use rail or road
* changed calculation of ships required to be slightly lower
* When deciding on a route, it looks to see if there is a factory nearby that is already transporting that type of good to the target. If there is then it will attempt to connect to that factory instead so that the original connection can be used to transport goods for part of the route. This can significantly reduce the cost of building a new route, and reduce congestion etc.

The issue is that it assumes that when it connects to the factory in between, it will end up building a station that is part of the one where goods are transported to the final destination from. I assume this should be easy enough to fix by ensuring that the station is built next to the existing one, or by building some form of station tiles in between before building the final station.

It does work correctly roughly 1/3 of the time, but the other 2/3 need to be ironed out.

I will attach some screenshots to show what I mean.


The attached screenshots show two examples of the problem.

(1) Screenshot.jpg
the stations on the left were already there (except the one with the right arrow on it) when the ai decided to build the one with the arrow on the right.

The left arrow shows a connection from boxed goods from a windmill to a market.

On the right there is a brewery, and the ai decided to ship boxed goods from there to the market, via the windmill. Unfortunately it build the target station (on the left of the right arrow) next to the incorrect station, and so the connection was incomplete.

(2) Screenshot-1.jpg
The road connection on the right was already built (shipping bulk goods to the iron foundary from the ore mine).
Instead of shipping goods from the coal mine to the iron factory directly, it decided to ship them to the ore mine, so that the trucks could take them the rest of the way. Unfortunately the station that it built did not connect with the existing station.

As I said, I am sure that it should be quite fixable, and I am not likely to get any more time to spend on this for a few weeks, so I thought someone else might like to have a go at finishing it.



Parsley, sage, rosemary, and maggikraut.


Checking for connection should be not too difficult anyway. Great to see somebody is working on a new AI!


It currently checks for a connection from the factory - the issue is that it has to choose the end-point for the station to be next to the station that serves the factory and has that connection.

I'm still only just getting to know the code, so I wasn't sure how to do that, but I think it should be fairly easy for someone who knows the code.


halt->suche_route() [with a good package that has the correct destination] will give you an answer. You can find a similar way in, where the goods are actually put en route.


Right I've found an hour or two and I'm almost done (I hope),

But I'm getting the error

player/ error: no matching function for call to 'haltestelle_t::suche_route(const ware_besch_t*&, koord*)'
player/../simhalt.h:355: note: candidates are: void haltestelle_t::suche_route(ware_t&, koord*)

when calling "welt->lookup_kartenboden(platz)->get_halt()->suche_route(freight,&target)". Haven't really used C++ much, but I'm assuming that's because I need a ware_t object. How can I get that from "freight" (which is a ware_besch_t) ?


(edit - switched around ware_t and ware_besch_t in my question)


(Sorry for the tripple post)
I think I just realised something  when I was testing it (now I've got it compiling and kind of working),

Does suche_route() only work if the good I look with is one there is already a line for?

i.e. if I have

       iron ore
A<---------->B                       C

and C produces coal then I am testing the connection between A and B for coal. Will suche_route() only find a route between A and B for iron ore, not for other bulk goods?

If so, is there an easy way to iterate through all the bulk goods so I can check them one by one?



imho suche_route() only looks for the ware categories (ie bulk) and not for a certain good. All vehicles, convois etc are made to transport _all_ goods from a certain category.
Parsley, sage, rosemary, and maggikraut.