widelands
widelands copied to clipboard
Coding Question
Hi, i'm trying to extract som logs out of the game and I have a question to the code structure: A request is created and destroyed by the building that needs the ware, so I can easily get that building from inside the Request class. but is there a way to get the building that fulfils that request(I mean the building that will send the requested ware to the requesting building). I tried to get the last flag of the last route since a request has more than one route. But I don't know if this is always correct. Is there a better way to get the building that will send the wares to the requesting building? Thanks in advance.
No, the unit that fulfils a request is not in any way linked to the building it came from. You could try giving WareInstance
a member variable Building* creator_
which you then set while a building or worker creates the instance. Note that a ware doesn't always have to come from a building: it can also be created by a worker during a program (in which case you additionally need to check which building the worker works at), or even just dropped on a flag by scripting.
thanks for the answer.
so in this suggested approach , I would only have to check if WareInstance::ObjectPointer location_
is pointing to a building or worker right ?
I also need to understand something about the transfers_
in the Request class:
what does the list of transfers exactly mean? is it the sub roads? or does it mean that the requested ware should be collected from different sources so for each source a separated transfer? I mean the request is supposed to ask for only one ware/worker so why does it need more than one transfer?
and the last question is the same about the route.
a transfer has instead of one route a list of routes (I suppose because there are different kinds of routes see/road) but the I made the assumption that the last flag of the last route is where the ware/worker come originally from. is this assumption right?
thanks for the answer. so in this suggested approach , I would only have to check if
WareInstance::ObjectPointer location_
is pointing to a building or worker right ?
location_
should always point to the ware's current location, but the location when a transfer starts should always be the starting building, worker, or flag, yes.
I also need to understand something about the
transfers_
in the Request class: what does the list of transfers exactly mean? is it the sub roads? or does it mean that the requested ware should be collected from different sources so for each source a separated transfer? I mean the request is supposed to ask for only one ware/worker so why does it need more than one transfer?
No. A Transfer is a wrapper around one ware or worker being moved from A to B. A request asks for only one type of ware or worker, but for a variable amount of it (see get_count
and get_open_count
). Each item being transferred to fulfil one request has an associated entry in the request's list of transfers.
and the last question is the same about the route. a transfer has instead of one route a list of routes (I suppose because there are different kinds of routes see/road) but the I made the assumption that the last flag of the last route is where the ware/worker come originally from. is this assumption right?
A Transfer object has only one route, Route route_
. The starting and ending points of this route are where the item being transferred came from and is headed to, respectively.