checking cargo delivery to stations

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

checking cargo delivery to stations

Post 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
Last edited by planetmaker on 11 Aug 2013 18:51, edited 2 times in total.
Reason: split as the answer has nothing to do with NML at all. Please stay on-topic
Image
User avatar
Andrew350
Chairman
Chairman
Posts: 768
Joined: 19 Dec 2011 07:54
Location: Washington State, USA
Contact:

Re: NML - a Newgrf Meta Language

Post 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?
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: NML - a Newgrf Meta Language

Post 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
Image
User avatar
Andrew350
Chairman
Chairman
Posts: 768
Joined: 19 Dec 2011 07:54
Location: Washington State, USA
Contact:

Re: checking cargo delivery to stations

Post 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 :)
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: checking cargo delivery to stations

Post 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?
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
User avatar
jfs
Tycoon
Tycoon
Posts: 1750
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: checking cargo delivery to stations

Post 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.
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Re: checking cargo delivery to stations

Post 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.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 5 guests