Page 1 of 1

checking cargo delivery to stations

Posted: 11 Aug 2013 09:42
by michael blunck
Andrew350 wrote: Is there any way for a house to check if a certain cargo has been delivered to a nearby station? The only variables I see seem to be just for checking cargo acceptance.
At least in TTDPatch/nfo/m4nfo there´s CB148 ("watched cargo accepted") for this task:
CB148 wrote: Called when a cargo type specified in property 20 is accepted by a house tile, or to be more specific, in a station that has the house tile in its acceptance area. [...]
But I´m not sure if CB148 has been implemented into OTTD at all.

regards
Michael

Re: NML - a Newgrf Meta Language

Posted: 11 Aug 2013 16:15
by Andrew350
That is available in NML/OpenTTD, but it sounds like that only checks if a cargo is accepted at a station and not whether anything has actually been delivered to it. Or am I misunderstanding the meaning of 'acceptance' here?

Re: NML - a Newgrf Meta Language

Posted: 11 Aug 2013 17:19
by michael blunck
Andrew350 wrote: [...] it sounds like that only checks if a cargo is accepted at a station and not whether anything has actually been delivered to it
Well, the CB is triggered when a cargo specified in house prop20/cargowatch() is delivered to a station that has the house tile in its acceptance area.

So, you need to set prop20/cargowatch() (cargo acceptance watch list) of the house in question with a list of cargo types to check for, and request house var64/cargohist() (cargo acceptance history of nearby stations) to get info about the cargo(s) having been delivered to the appropriate stations(s).

At least that´s the way it works in TTDPatch, I have a newGRF where this is implemented.

Seems that Michi_cc had already implemented prop20 and house var64 in OTTD, so it should work there too.

regards
Michael

Re: checking cargo delivery to stations

Posted: 11 Aug 2013 22:43
by Andrew350
michael blunck wrote:Well, the CB is triggered when a cargo specified in house prop20/cargowatch() is delivered to a station that has the house tile in its acceptance area.
Ah, this is more clear, and it does do what I want then. :) The wording used in the specs doesn't quite elaborate that the watched cargo has to be delivered to trigger the callback, hence why I was confused.

Thank you Michael :)

Re: checking cargo delivery to stations

Posted: 06 Jul 2022 21:31
by Wahazar
Sorry for necromancy, but I didn't found any other thread about watched_cargo_accepted callback.
I want to display different layout of house, if passengers were delivered, but I'm not sure, how to use this callback properly.
Here is, simplified, my code:

Code: Select all

switch (FEAT_HOUSES, SELF, switch_PARKING_LOT_FLAT_animation, animation_frame) {
	0:  layout_PARKING_LOT_FLAT_terrainaware;
	1:  layout_PARKING_LOT_FLAT_terrainaware_cars;
layout_PARKING_LOT_FLAT_terrainaware;
}

item (FEAT_HOUSES, bld_PARKING_LOT_FLAT, 231, HOUSE_SIZE_1X1) { 
 property { 
  animation_info:     [ANIMATION_NON_LOOPING, 2];
  animation_speed:    8;
  watched_cargo_types: [PASS];
 }
 graphics {
   default: switch_PARKING_LOT_FLAT_animation;
   anim_next_frame: 0;
   watched_cargo_accepted : 1;
 }
}
and it is doing something, but not sure if I coded it properly?

Re: checking cargo delivery to stations

Posted: 07 Jul 2022 09:58
by jfs
One thing to keep in mind with the watched_cargo_accepted callback is that it only gets triggered in the tile loop, not instantly when cargo is delivered. So the effect can be up to 255 ticks (around 3.4 days) delayed, and might not be simultaneous for all houses using the callback in the station area.

You can consider using more animation frames all displaying the same graphics if you want the effect to last for longer.
Then in the regular animation callback you'd check for current frame being zero, in which case you'd stay on the frame, or otherwise choose the next frame.

Another way to have the effect last longer is using the cargo_accepted_nearby_* variables on houses.

Re: checking cargo delivery to stations

Posted: 07 Jul 2022 10:38
by Wahazar
Thanks for anwer.
What is a meaning of cargo_accepted_nearby_... coordinates? They should point directly at the station, or just at the tile within station range (so they can be 0,0)?

EDIT: finally I added more frames and random switch to choose by watched_cargo_accepted callback - now I'm satisfied, animation last longer and not all parking lots flick of/on simultaneously.