How do I do Animation in a Multi-Tile Station?

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

How do I do Animation in a Multi-Tile Station?

Post by richk67 »

I am currently coding the NewGRF_ports system within OpenTTD, and have got a bit stuck around getting animation to work for spinning the radars, flapping the windsock, etc.

In general, the spec is similar to NewStations, and to work with as much code re-use as possible I would like to use Prop 16, 17, 18 of Action0Stations, in conjunction with callback 140.

However... that is about as far as I can get. I can see the basic components should be these, but I cant see how I glue them together into a working newgrf. Ive read, re-read, and puzzled over the wiki, but since there does not seem to be one animation example (at least none in the places Ive looked... but it could be well hidden...).

Can anyone help me? I want to animate the radar; a simple loop of 12 positions. However, I cant simply switch graphic sets, because my graphic sets are often VERY large due to the large number of tiles defined in the Prop09. (e.g. some Prop09 airports have 25+ tiles, drawing on graphics from a 95sprite set). Most of what I see is geared around animating a single tile, and the graphic set for a single tile, rather than one that defines multiple tiles. I havent found any example that shows how to use callback 140, or define an animation sequence.

So any help would be appreciated; detailed examples of actual NFO would help even more. eg. "Define the radar frame set with.... then use callback 140 like this to reference into it... thus..." etc.
Attachments
A new asymmetrical NewGRF airport.
A new asymmetrical NewGRF airport.
Praningbury Transport, 23rd Feb 2013.png (42.53 KiB) Viewed 1573 times
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Re: How do I do Animation in a Multi-Tile Station?

Post by minime »

Well, it would work basically in the same manner as animating houses. You would use callbacks 140/141 to control your frame counter (or even just rely on properties 16-18). You would then use callback 14 to select a station tile layout (those defined in property 09) based on the current value of the frame counter (variable 4A).

Mind that you only have one frame counter for the entire station, so if you want to have several different animations going with different lengths, you will have to be a little creative (say, use a common multiple for total frame count and divide appropriately for each tile...).

Is this enough to point you in the right direction?
Last edited by minime on 04 Sep 2007 21:15, edited 1 time in total.
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. --Albert Einstein
Image Image Image
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Re: How do I do Animation in a Multi-Tile Station?

Post by richk67 »

Thanks - a bit. Its the NFO examples I need, so some hex would be handy of something with a working example would be great. eg. an animated crane on a station.

Newhouses are handled differently to newstations (certainly in the OTTD world), and I think examples of Action0Stations animations would be most helpful.
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Re: How do I do Animation in a Multi-Tile Station?

Post by minime »

Unfortunately I haven't done any station animations yet (I've got no graphics for it), so I can't give you any concrete examples. However I've coded stations and I've used animation in houses (to divide up each construction phase into several steps with variations etc.) and from what I've seen in the documentation, the way you code it and the way it behaves is almost identical between houses and stations.

I assume you already use callback 14 to select tile layouts for the different pieces of the airport.
Let's say that in your action 2 chain, you've arrived to the point where you have determined, that you want to draw a radar tile. In the non-animated case, you would now return the tile layout number as a result from the callback, and the corresponding tile would get drawn.

Now let's say you want to have that radar rotating continuously, with 12 different steps. You would set properties 16 and 17 to the appropriate frame count and speed, and define 12 instead of 1 layout for the radar tile (each layout representing one animation frame).
Now, in your action 2 chain, once you've detemined you're drawing a radar tile, you would go on to another action 2, which would check variable 4A, and depending on its value (0 - 11) return the appropriate layout number.
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. --Albert Einstein
Image Image Image
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Re: How do I do Animation in a Multi-Tile Station?

Post by richk67 »

OK, that seems a reasonable enough explanation. I will have another think about how to implement this tomorrow. My layouts are placed more directly than that, not on a tile-by-tile basis via callbacks, but as a simple layout using a modified Prop 0E-like prop.

I will have to see if I can easily query the location of a tile from the 0,0 origin of the layout. This would mean I could simply limit the animation to the specified tiles, and return FD to the callback 140 as desired by the specs.

Effectively I want to code:

Code: Select all

If tile is at X,Y from origin
  Mod frame count by the number of frames in this tile
  Select new tiletype as BaseTileType for this tile + Frame Count (modded)
Workable maybe.
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
User avatar
minime
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 18 Jan 2004 10:02
Skype: dan.masek
Location: Prague, Czech Republic
Contact:

Re: How do I do Animation in a Multi-Tile Station?

Post by minime »

richk67 wrote:My layouts are placed more directly than that, not on a tile-by-tile basis via callbacks, but as a simple layout using a modified Prop 0E-like prop.
Well, in that case it should be possible to query which layout that particular tile is set to in your property 0E. For stations you could obtain that from variables 40, 41 or 49 (the T field). However, I don't think that will work for you, since there are only 4 bits allocated for this field (since stations can only have 00-07 in there - would be handy if there were more). I've only seen newports specification for Action 0, so I don't know if there is anything like that provided there. If not, it should be added, since this is quite a useful thing to know.

Then you'd use callback 14 and do your animation only for the specific tile types.

Alternately, just use those same variables (this time the P/C or p/c fields) to figure out the position of the tile being drawn and decide upon that.

However I find that the combination of property 0E (or callback 24) layouts together with callback 14 used to pick graphics based on the "tile type" is an ideal solution, since it decouples layout and drawing. You could then reuse a single action 2 chain for several different airports/layouts without needing to modify the drawing logic.

In this case the numbers you set using property 0E do not even have to correspond to IDs of tile layouts you set up using property 09. You can use action 2 to look up the correct tile layout to draw there.

I use this technique for parking lots - there are 3 basic types of tiles - 00 - left end, 02 - right end, 04 - middle. Then there are 3 chains of actions 2, which get used depending on the tile type, select from a large number of variations based on several variables (random bits, cargo amount, etc.). Nice thing about it is that it lets the player erase parts of the parking lot without affecting the rest (unlike in cases when look up based on position of the tile).
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. --Albert Einstein
Image Image Image
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Google [Bot] and 20 guests