Weather framework

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Is weather a good/interesting feature?

Yes
152
87%
No
23
13%
 
Total votes: 175

borax
Engineer
Engineer
Posts: 17
Joined: 03 Jan 2006 18:35
Contact:

Weather framework

Post by borax »

Hi,

I took the liberty to create a framework for some weather behaviour. My main thought around this is that it would be interesting to get some additional complexity in the game with weather. Some thoughts I had was depending on wind bridges etc could be shut down. If snowing then vehicle speed should be slowed down. Loads of rain could cause landslides etc. Well, the framework itself gives a quite large number of different states / combinations. Take a look at the attached source and give me your thoughts.

The system was based on OpenTTD 0.6b3 but was written in a generic was so should easily integrate with most versions. You will need to add hooks into the standard game-engine to get the framework up n running.

Currently there are NO VISUAL EFFECTS. This is just a framework that should give more possibilities to the project. It was built with a bit of memory / performance thinking in mind (which should make it easy to integrate with network play aswell). I do have a more complex / more performance and memory hungry (standalone) terrain/weather engine written in C# but I don't think this would be applicable in OTTD as that would increase the performance demands too much (tilebased calculations on wind movement with vectors etc etc).

Please take a look at the source (I've added comments to the code according to http://wiki.openttd.org/index.php/Coding_style). Any (constructive) feedback is appreciated.

Regards,
Ola
Attachments
Based on SVN 12066
Based on SVN 12066
weather3.jpg (227.8 KiB) Viewed 1999 times
weather3.patch
Based on SVN 12066
(54.88 KiB) Downloaded 542 times
Last edited by borax on 05 Feb 2008 09:29, edited 7 times in total.
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Weather framework

Post by Bilbo »

Ok, some comments:
Lines with width of 200-260 characters are ... way too long. Not everybody have 2560 pixels wide displays :) Especially the wind table is very wide and some comments that are curently at end of line could be moved before the line:

Code: Select all

 some_code();    //Very longish comment
should become rather:

Code: Select all

  /* Very longish
   * comment */
   some_code();
GetCurrentWindTypeAsString : what about using translatable strings? :)
Also, using switch + case is preferred in favor of cascade of if/then/else :)

Also, things like "Pointer should point to buffer of atleast 40 chars" are quite prone to error. Better is to allocate static buffer of enough and return pointer to it. Whoever call your function can copy the result elsewhere to appropriately sized buffer.

Well, the coding style still needs to be improved, but ok, it is first preview :)

So, take coding style aside and look at the functionality:

No effect (currently) at the game whatsoever. These should be listed more precisley than "perhaps we will close bridges and slow down vehicles". There are many possible other effects that could be applied - wind could affect plane speeds (flying with wind in back would result in faster planespeeds, although if you consider realism, wind speed and direction varies with height :) Extreme wind/fog could lead even to forbidding takeoffs and landing (though modern airliners can land even in strong crosswind and zero visibility), extreme snow leading to slowing down trains and vehicles (and again, closing runways :), etc ...

No graphics are a bit of disadvantage (well, you are coder, not artist :), but at least some preliminary list what would have to be drawn would be nice- then some artist can perhaps do that.

So, what could/should be added/improved:
Chance for scenario authors to set some weather parameters. For example in temperate climate weather can be more wet or more dry, hotter or colder according to country
List of all possible effects on gameplay - people will then weed out bad ideas and keep the rest.
List of graphics to be drawn.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
borax
Engineer
Engineer
Posts: 17
Joined: 03 Jan 2006 18:35
Contact:

Re: Weather framework

Post by borax »

Hi,

Did a quick update to fix the comments issue.

Regarding the "AsString" functions: I made mainly for debugging purposes (and yes, there's a big chance that there will be errors, just made them as quick/dirty debugging functions ;-). Perhaps I should remove them completley.

My thought was that the guy/girl making UI implementation would add (localize able) strings / content graphics to show the current status. As you say, the code could be cleaned up but as this is only a first release,

Regarding effect, please come with suggestions here (as you did). As stated, this is just a framework to get the basis in place for weather effects on the game. Another thought I had was with the base framework in place, people could work in parallel with development of disasters / effect on transports / UI presentation. Anyone feeling up to create some widgets and get some graphics up n running are most welcome :).

-
EDIT, something I do think the framework will need is support for save/load game though. Currently there's no way to restore the current values. Also, as you say, add possibility for scenario makers to affect the values would be great.
-

Regards,
Ola
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Weather framework

Post by Bilbo »

borax wrote:Regarding effect, please come with suggestions here (as you did). As stated, this is just a framework to get the basis in place for weather effects on the game. Another thought I had was with the base framework in place, people could work in parallel with development of disasters / effect on transports / UI presentation. Anyone feeling up to create some widgets and get some graphics up n running are most welcome :).
Well, i thought you could come with some effect :)

What comes on my mind:

Wind affects airspeed of planes (flying in direction of wind is faster).
Too much wind/snow -> closure of airports.
Too much rain -> roads are wet, vehicles slowdown (but how to calculate it?)
Too much snow -> more slowdown of road vehicles, perhaps slight slowdown of trains
Too cold -> sea freezes, blocking ship transport except for icebrak capable ships and submarines :)
Too hot/cold -> vehicle reliability drops down (engine freezing/overheating)
Bad weather -> increase construction costs.

Hmm ... also, what about seasons? Summer, winter, these have different weather ... especially with daylength patch, seasons may become well usable.
borax wrote: EDIT, something I do think the framework will need is support for save/load game though. Currently there's no way to restore the current values. Also, as you say, add possibility for scenario makers to affect the values would be great.
Saving/loading few extra variables is quite trivial once the framework is in place :)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
borax
Engineer
Engineer
Posts: 17
Joined: 03 Jan 2006 18:35
Contact:

Re: Weather framework

Post by borax »

Bilbo wrote:
borax wrote:Regarding effect, please come with suggestions here (as you did). As stated, this is just a framework to get the basis in place for weather effects on the game. Another thought I had was with the base framework in place, people could work in parallel with development of disasters / effect on transports / UI presentation. Anyone feeling up to create some widgets and get some graphics up n running are most welcome :).
Well, i thought you could come with some effect :)

What comes on my mind:

Wind affects airspeed of planes (flying in direction of wind is faster).
Too much wind/snow -> closure of airports.
Too much rain -> roads are wet, vehicles slowdown (but how to calculate it?)
Too much snow -> more slowdown of road vehicles, perhaps slight slowdown of trains
Too cold -> sea freezes, blocking ship transport except for icebrak capable ships and submarines :)
Too hot/cold -> vehicle reliability drops down (engine freezing/overheating)
Bad weather -> increase construction costs.

Hmm ... also, what about seasons? Summer, winter, these have different weather ... especially with daylength patch, seasons may become well usable.
borax wrote: EDIT, something I do think the framework will need is support for save/load game though. Currently there's no way to restore the current values. Also, as you say, add possibility for scenario makers to affect the values would be great.
Saving/loading few extra variables is quite trivial once the framework is in place :)
Currently I don't have wind direction but that should be quite easy to add :).

I've would like to add some effects to your list:
High wind affects ships (aswell as planes).
Much rain results in landslides.
Very cold = more expensive to change terrain.

With the daylength patch perhaps adding temp variations per hour basis would make sense, aswell as seasons.

How good are you with making widgets / UI changes? I've been trying to get a grip of how they work but the wiki / source don't make too much sense. I've managed to expand the status widget to get an additional tab next to the current money. My idea was to get some indicators of current temp / weather there. Perhaps making a bigger widget to show some temp graph from the last month?

Br,
Ola
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Weather framework

Post by Bilbo »

borax wrote: With the daylength patch perhaps adding temp variations per hour basis would make sense, aswell as seasons.
Even with quite high daylength the day is too short for the variations to have any significant effect. Standard is I think 2 seconds per game day, using daylength 30 is quite high setting (= 1 minute/day). Changing daily temp every 10 seconds during day (say temp got changed 6 times per 24 hours) could be a bit fast for players. Even faster with faster days
borax wrote: How good are you with making widgets / UI changes? I've been trying to get a grip of how they work but the wiki / source don't make too much sense. I've managed to expand the status widget to get an additional tab next to the current money. My idea was to get some indicators of current temp / weather there. Perhaps making a bigger widget to show some temp graph from the last month?
I am not very good at widgets. Best would be to look at existing code and perhaps you'll find how to do it. For graph, you can salvage existing graph code to show also wind, temperature, amount of rain/snow, etc ..
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Weather framework

Post by Zephyris »

I really like this idea, it is one of the not-just-eyecandy eycandy patches I would like to see. I would gladly produce a lot of graphics, mostly because I already have the terrain and infrastructure graphics drawn for the grapics replacement project, and it would be quite easy to alter these appropriately...

Some serious questions...

Graphics
Where will the graphics appear? What will their purpose be? Do you want:
Icons?
Full-screen special effects?
Redrawn in-game sprites?

Will there be palette shifting/sprite recolouring? This is the easiest way to represent rain, cloudy weather, lightning, etc.

Sound
Will this support custom sound effects for weather conditions?

Technical
Will there be "terrain tile" specific weather, ie. different weather for snowy or desert terrain compared to grassy.
Don't forget toyland!

Fesability
Seriously consider how fesable different graphical effects would be, for example:
Freezing the sea in arctic = easy (17 sprites - sea and shores)
Snow in temperate = ridiculous (hundreds of sprites - all buildings and trees)
Snow in arctic = easy (16 sprites - sea shores)
Icy roads in temperate/arctic = ok (57 sprites - roads)
Fog = tricky (no partial transparency)
Rain/snow full screen overlay = easyish (problems with repeating patterns)

I think the most important feature would be a full screen palette shift to represent cloud, rain, lightning and even fog...

Related features
If a full screen palette shift is implemented then basic day/night cycles would be possible.
Seasons are inherently due to weather, so could this support seasonal cycles? The most challenging thing would be deciduous trees...

*edit*
Timescale
1 year = a year
~1 weather effect a month? On average of course...
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Weather framework

Post by michael blunck »

Zephyris wrote:Snow in temperate = ridiculous (hundreds of sprites - all buildings and trees)
Specifically easy: AlpineClimate exists.

In general: an over-ambitious project, IMO.

regards
Michael
Image
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Weather framework

Post by Bilbo »

Well, I guess the climate should be tunred off in toyland - toyland is some .. idealized toyland, so I expect no weather there. Same with mars (toyland replacement) - the weather there would be way too different from earth (no rain and perhaps sandstorms? Well, there is almost no atmosphere at all, so any "weather" effects would be very weak to have any effect on game ...)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
Benjamin
Engineer
Engineer
Posts: 54
Joined: 10 Aug 2007 20:35
Location: Wales, on a hill, near some sheep.

Re: Weather framework

Post by Benjamin »

A quick question. At the moment, I take it you want to implement the rain/cloud across the entire map at once. With large maps would it ever be possible to code "patches" of rain/cloud/fog, moving across the map with the wind, so some areas could be sunny, while in other parts of the map it's raining?
You ain't seen me. Right?
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Weather framework

Post by Bilbo »

Benjamin wrote:A quick question. At the moment, I take it you want to implement the rain/cloud across the entire map at once. With large maps would it ever be possible to code "patches" of rain/cloud/fog, moving across the map with the wind, so some areas could be sunny, while in other parts of the map it's raining?
That would be quite difficult, both from developer point of view (complicated weather calculation) and from player point of view (what weather woiuld be indicated to player? some global average? The current spot? I guess players can get confused a bit...)

Although the weather & temperature may differ slightly with height - like snow at higher heights, rain at lower heights ...
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
borax
Engineer
Engineer
Posts: 17
Joined: 03 Jan 2006 18:35
Contact:

Re: Weather framework

Post by borax »

Benjamin wrote:A quick question. At the moment, I take it you want to implement the rain/cloud across the entire map at once. With large maps would it ever be possible to code "patches" of rain/cloud/fog, moving across the map with the wind, so some areas could be sunny, while in other parts of the map it's raining?
Hi Benjamin,

The smaller "patches" of weather to calculate the more cpu / memory intensive it will be. As I've stated further up I already created a generic (not OTTD) per tile weather calculation. This however would not be beneficial since it would "break" the low demand properties of OTTD. My intention is just to give the game a bit more properties / possible events / complexity. It's not to make full scale weather simulations.

Br,
Ola
borax
Engineer
Engineer
Posts: 17
Joined: 03 Jan 2006 18:35
Contact:

Re: Weather framework

Post by borax »

Zephyris wrote:I really like this idea, it is one of the not-just-eyecandy eycandy patches I would like to see. I would gladly produce a lot of graphics, mostly because I already have the terrain and infrastructure graphics drawn for the grapics replacement project, and it would be quite easy to alter these appropriately...
Thanks, thought it would be nice with some new "real"/not-just-eyecandy features.
Zephyris wrote: Some serious questions...

Graphics
Where will the graphics appear? What will their purpose be? Do you want:
Icons?
Full-screen special effects?
Redrawn in-game sprites?

Will there be palette shifting/sprite recolouring? This is the easiest way to represent rain, cloudy weather, lightning, etc.
I've tried adding a panel next to the currency panel(down in the statusbar) to get some easy accessed hint of the current weather. The issue I got while trying to do some quick tests in photoshop was that icons small enough to fit the panel would be barley understandable / visible + if they where colored they broke the current UI style. I think the UI integration should be transparent for the user and it should definitely not break the current UI "look".

Fullscreen effects for rain / snow would perhaps be the easiest way of getting a feel of the current weather (without changing the tiles). The more extreme conditions could also be shown in the news (i.e. thunder strikes, hurricanes, monsoon etc.). The important thing here is that it should be doable.
Zephyris wrote: Sound
Will this support custom sound effects for weather conditions?
Yet again it would be nice for rain, extreme wind, thunder etc. Snow doesn't sound that much ;-).
Zephyris wrote: Technical
Will there be "terrain tile" specific weather, ie. different weather for snowy or desert terrain compared to grassy.
Don't forget toyland!

Feasibility
Seriously consider how feasible different graphical effects would be, for example:
Freezing the sea in arctic = easy (17 sprites - sea and shores)
Snow in temperate = ridiculous (hundreds of sprites - all buildings and trees)
Snow in arctic = easy (16 sprites - sea shores)
Icy roads in temperate/arctic = ok (57 sprites - roads)
Fog = tricky (no partial transparency)
Rain/snow full screen overlay = easyish (problems with repeating patterns)

I think the most important feature would be a full screen palette shift to represent cloud, rain, lightning and even fog...
At a more general point it would be nice with transitions between all arctic - temperate - dessert tiles (especially as map sizes grow). Just think about making a large Asia map. There you will need to be able to vary between all of them if the size is large enough :-). That's another issue. I've just started to look at how the code works / looks about 6 days ago so would be nice with input from someone used to work with tile changes!
Zephyris wrote: Related features
If a full screen palette shift is implemented then basic day/night cycles would be possible.
Seasons are inherently due to weather, so could this support seasonal cycles? The most challenging thing would be deciduous trees...
Well, day / night would be too fast I think. Seasons would be nice though but that would increase the tile count in massive ways I guess.
Zephyris wrote: *edit*
Timescale
1 year = a year
~1 weather effect a month? On average of course...
The more that helps out the more we can get done. The basic framework is in place with accessors etc so it should be fairly easy to help out. Just grab the source, add some hooks and start interacting with the weather framework :-).

Regards,
Ola
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Weather framework

Post by Zephyris »

Unfortunately I have absolutely no coding ability whatsoever...
But I can draw stuff :)
borax
Engineer
Engineer
Posts: 17
Joined: 03 Jan 2006 18:35
Contact:

Re: Weather framework

Post by borax »

Zephyris wrote:Unfortunately I have absolutely no coding ability whatsoever...
But I can draw stuff :)
I was thinking about showing temperature formatted i.e. -10.3C, 40.6C etc. so, maximum 6 chars. Beside this I would like there to be an icon representing the weather. Any thoughts around how to design this so that it melts in with the rest of the UI?

/ Ola
User avatar
Expresso
Tycoon
Tycoon
Posts: 1760
Joined: 09 Aug 2004 00:14
Location: Gouda, the Netherlands

Re: Weather framework

Post by Expresso »

borax wrote:I was thinking about showing temperature formatted i.e. -10.3C, 40.6C etc. so, maximum 6 chars. Beside this I would like there to be an icon representing the weather. Any thoughts around how to design this so that it melts in with the rest of the UI?
Well, the bar at the bottom (don't know what it's called), seems like a nice place to me.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Weather framework

Post by Zephyris »

You would need temperature, wind speed and wind direction displayed as text. Sunnyness/cloudyness/rain, etc can then be displayed by a 12x12 icon. The internationally recognised weather forecast symbols are clear down to very small sizes, so should be possible in that toolbar.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Weather framework

Post by Zephyris »

Sorry for the slow progress, real life strikes again!
Here are some icons for different weather conditions...
11x11px, suitable for use in the bottom toolbar.

I would suggest a format of:
Temp [temp]°C, Wind [strength] [direction], [icon]

*edit* you may have noticed a thread in the suggestions forum about new special effect colours for shadows/transparency etc., it may be worth helping with that to get the full screen darkening for cloudy/rainy conditions going...

*edit (again)* and how should these sprites be coded into a grf? Action5 with a new type?
Attachments
Weather Icons.png
Weather Icons.png (783 Bytes) Viewed 9109 times
User avatar
athanasios
Tycoon
Tycoon
Posts: 3138
Joined: 23 Jun 2005 00:09
Contact:

Re: Weather framework

Post by athanasios »

You already do a lot, do not feel sorry. Nice weather icons. :D
http://members.fortunecity.com/gamesart
"If no one is a fool I am also a fool." -The TTD maniac.


I prefer to be contacted through PMs. Thanks.
borax
Engineer
Engineer
Posts: 17
Joined: 03 Jan 2006 18:35
Contact:

Re: Weather framework

Post by borax »

Zephyris wrote:Sorry for the slow progress, real life strikes again!
Here are some icons for different weather conditions...
11x11px, suitable for use in the bottom toolbar.

I would suggest a format of:
Temp [temp]°C, Wind [strength] [direction], [icon]

*edit* you may have noticed a thread in the suggestions forum about new special effect colours for shadows/transparency etc., it may be worth helping with that to get the full screen darkening for cloudy/rainy conditions going...

*edit (again)* and how should these sprites be coded into a grf? Action5 with a new type?
Same here, real life tends to take more time than you think ;-). Thanks for the icons! I've fixed the widgets now so temp, windspeed and direction is visible next to the currency. Just tuning it a bit so it appears more "real". Hopefully I can post a diff/patch here during the day.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 9 guests