forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclimates.cc
335 lines (290 loc) · 11.6 KB
/
climates.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* dialog for setting the climate border and other map related parameters
*
* prissi
*
* August 2006
*/
#include "climates.h"
#include "karte.h"
#include "../besch/grund_besch.h"
#include "../simdebug.h"
#include "../simworld.h"
#include "../dataobj/einstellungen.h"
#include "../dataobj/umgebung.h"
#include "../dataobj/translator.h"
// just for their structure size ...
#include "../simgraph.h"
#include "../utils/simstring.h"
#include "components/list_button.h"
#define START_HEIGHT (28)
#define LEFT_ARROW (130)
#define RIGHT_ARROW (170)
#define TEXT_RIGHT (155) // 10 are offset in routine ..
#include <sys/stat.h>
#include <time.h>
/**
* set the climate borders
* @author prissi
*/
climate_gui_t::climate_gui_t(welt_gui_t* welt_gui, einstellungen_t* sets) :
gui_frame_t("Climate Control")
{
DBG_MESSAGE("","sizeof(stat)=%d, sizeof(tm)=%d",sizeof(struct stat),sizeof(struct tm) );
this->sets = sets;
this->welt_gui = welt_gui;
// select map stuff ..
int intTopOfButton = 16;
// mountian/water stuff
water_level[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
water_level[0].add_listener( this );
add_komponente( water_level+0 );
water_level[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
water_level[1].add_listener( this );
add_komponente( water_level+1 );
intTopOfButton += 12;
mountain_height[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
mountain_height[0].add_listener( this );
add_komponente( mountain_height+0 );
mountain_height[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
mountain_height[1].add_listener( this );
add_komponente( mountain_height+1 );
intTopOfButton += 12;
mountain_roughness[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
mountain_roughness[0].add_listener( this );
add_komponente( mountain_roughness+0 );
mountain_roughness[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
mountain_roughness[1].add_listener( this );
add_komponente( mountain_roughness+1 );
intTopOfButton += 12+5;
// summer snowline alsway startig above highest climate
intTopOfButton += 12;
snowline_winter[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
snowline_winter[0].add_listener( this );
add_komponente( snowline_winter+0 );
snowline_winter[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
snowline_winter[1].add_listener( this );
add_komponente( snowline_winter+1 );
intTopOfButton += 12+5;
// other climate borders ...
end_desert[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
end_desert[0].add_listener( this );
add_komponente( end_desert+0 );
end_desert[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
end_desert[1].add_listener( this );
add_komponente( end_desert+1 );
intTopOfButton += 12;
end_tropic[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
end_tropic[0].add_listener( this );
add_komponente( end_tropic+0 );
end_tropic[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
end_tropic[1].add_listener( this );
add_komponente( end_tropic+1 );
intTopOfButton += 12;
end_mediterran[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
end_mediterran[0].add_listener( this );
add_komponente( end_mediterran+0 );
end_mediterran[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
end_mediterran[1].add_listener( this );
add_komponente( end_mediterran+1 );
intTopOfButton += 12;
end_temperate[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
end_temperate[0].add_listener( this );
add_komponente( end_temperate+0 );
end_temperate[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
end_temperate[1].add_listener( this );
add_komponente( end_temperate+1 );
intTopOfButton += 12;
end_tundra[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
end_tundra[0].add_listener( this );
add_komponente( end_tundra+0 );
end_tundra[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
end_tundra[1].add_listener( this );
add_komponente( end_tundra+1 );
intTopOfButton += 12;
end_rocky[0].init( button_t::repeatarrowleft, NULL, koord(LEFT_ARROW,intTopOfButton) );
end_rocky[0].add_listener( this );
add_komponente( end_rocky+0 );
end_rocky[1].init( button_t::repeatarrowright, NULL, koord(RIGHT_ARROW,intTopOfButton) );
end_rocky[1].add_listener( this );
add_komponente( end_rocky+1 );
intTopOfButton += 12;
// the rocky will be alway below the snow line; no need to set this explicitely
setze_fenstergroesse( koord(RIGHT_ARROW+16, intTopOfButton+14+8+16) );
no_tree.init(button_t::square, translator::translate("no tree"), koord(14,intTopOfButton+7), koord(BUTTON_WIDTH,BUTTON_HEIGHT)); // right align
no_tree.pressed=umgebung_t::no_tree;
no_tree.add_listener( this );
add_komponente( &no_tree );
intTopOfButton += 12;
}
/**
* This method is called if an action is triggered
* @author Hj. Malthaner
*/
bool
climate_gui_t::action_triggered(gui_komponente_t *komp,value_t /* */)
{
if(komp==&no_tree) {
umgebung_t::no_tree ^= 1;
no_tree.pressed ^= 1;
welt_gui->update_preview();
}
else if(komp==water_level+0) {
if(sets->gib_grundwasser() > -10*Z_TILE_STEP ) {
sets->setze_grundwasser( sets->gib_grundwasser() - 2*Z_TILE_STEP );
welt_gui->update_preview();
}
}
else if(komp==water_level+1) {
if(sets->gib_grundwasser() < 0 ) {
sets->setze_grundwasser( sets->gib_grundwasser() + 2*Z_TILE_STEP );
welt_gui->update_preview();
}
}
else if(komp==mountain_height+0) {
if(sets->gib_max_mountain_height() > 0.0 ) {
sets->setze_max_mountain_height( sets->gib_max_mountain_height() - 10 );
welt_gui->update_preview();
}
}
else if(komp==mountain_height+1) {
if(sets->gib_max_mountain_height() < 320.0 ) {
sets->setze_max_mountain_height( sets->gib_max_mountain_height() + 10 );
welt_gui->update_preview();
}
}
else if(komp==mountain_roughness+0) {
if(sets->gib_map_roughness() > 0.4 ) {
sets->setze_map_roughness( sets->gib_map_roughness() - 0.05 );
welt_gui->update_preview();
}
}
else if(komp==mountain_roughness+1) {
#ifndef DOUBLE_GROUNDS
if(sets->gib_map_roughness() < 0.7 ) {
#else
if(sets->gib_map_roughness() < 1.00) {
#endif
sets->setze_map_roughness( sets->gib_map_roughness() + 0.05 );
welt_gui->update_preview();
}
}
else {
// all climate borders from here on
sint16 *climate_borders = (sint16 *)sets->gib_climate_borders();
if(komp==snowline_winter+0) {
if(sets->gib_winter_snowline()>0) {
sets->setze_winter_snowline( sets->gib_winter_snowline()-1 );
}
}
else if(komp==snowline_winter+1) {
sets->setze_winter_snowline( sets->gib_winter_snowline()+1 );
}
else if(komp==end_desert+0) {
if(climate_borders[desert_climate]>0) {
climate_borders[desert_climate]--;
}
}
else if(komp==end_desert+1) {
climate_borders[desert_climate]++;
}
else if(komp==end_tropic+0) {
if(climate_borders[tropic_climate]>0) {
climate_borders[tropic_climate]--;
}
}
else if(komp==end_tropic+1) {
climate_borders[tropic_climate]++;
}
else if(komp==end_mediterran+0) {
if(climate_borders[mediterran_climate]>0) {
climate_borders[mediterran_climate]--;
}
}
else if(komp==end_mediterran+1) {
climate_borders[mediterran_climate]++;
}
else if(komp==end_temperate+0) {
if(climate_borders[temperate_climate]>0) {
climate_borders[temperate_climate]--;
}
}
else if(komp==end_temperate+1) {
climate_borders[temperate_climate]++;
}
else if(komp==end_tundra+0) {
if(climate_borders[tundra_climate]>0) {
climate_borders[tundra_climate]--;
}
}
else if(komp==end_tundra+1) {
climate_borders[tundra_climate]++;
}
else if(komp==end_rocky+0) {
if(climate_borders[rocky_climate]>0) {
climate_borders[rocky_climate]--;
}
}
else if(komp==end_rocky+1) {
climate_borders[rocky_climate]++;
}
// artic starts at maximum end of climate
sint16 arctic = 0;
for( int i=0; i<MAX_CLIMATES-1; i++ ) {
if(climate_borders[i]>arctic) {
arctic = climate_borders[i];
}
}
climate_borders[arctic_climate] = arctic;
// correct summer snowline too
if(arctic<sets->gib_winter_snowline()) {
sets->setze_winter_snowline( arctic );
}
}
return true;
}
void climate_gui_t::zeichnen(koord pos, koord gr)
{
no_tree.pressed=umgebung_t::no_tree;
gui_frame_t::zeichnen(pos, gr);
const int x = pos.x+10;
int y = pos.y+16+16;
const sint16 water_level = sets->gib_grundwasser()/(Z_TILE_STEP*2)+5;
const sint16 *climate_borders = sets->gib_climate_borders();
// water level 18-Nov-01 Markus W. Added
display_proportional_clip(x, y, translator::translate("Water level"), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(water_level,0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
display_proportional_clip(x, y, translator::translate("Mountain height"), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos((int)(sets->gib_max_mountain_height()), 0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
display_proportional_clip(x, y, translator::translate("Map roughness"), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos((int)(sets->gib_map_roughness()*20.0 + 0.5)-8 , 0) , ALIGN_RIGHT, COL_WHITE, true); // x = round(roughness * 10)-4 // 0.6 * 10 - 4 = 2 //29-Nov-01 Markus W. Added
y += 12+5;
// seaon stuff
display_proportional_clip(x, y, translator::translate("Summer snowline"), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(climate_borders[arctic_climate], 0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
display_proportional_clip(x, y, translator::translate("Winter snowline"), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(sets->gib_winter_snowline(),0),ALIGN_RIGHT, COL_WHITE, true);
y += 12+5;
// climate borders
display_proportional_clip(x, y, translator::translate(grund_besch_t::get_climate_name_from_bit(desert_climate)), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(climate_borders[desert_climate], 0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
display_proportional_clip(x, y, translator::translate(grund_besch_t::get_climate_name_from_bit(tropic_climate)), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(climate_borders[tropic_climate], 0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
display_proportional_clip(x, y, translator::translate(grund_besch_t::get_climate_name_from_bit(mediterran_climate)), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(climate_borders[mediterran_climate], 0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
display_proportional_clip(x, y, translator::translate(grund_besch_t::get_climate_name_from_bit(temperate_climate)), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(climate_borders[temperate_climate], 0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
display_proportional_clip(x, y, translator::translate(grund_besch_t::get_climate_name_from_bit(tundra_climate)), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(climate_borders[tundra_climate], 0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
display_proportional_clip(x, y, translator::translate(grund_besch_t::get_climate_name_from_bit(rocky_climate)), ALIGN_LEFT, COL_BLACK, true);
display_proportional_clip(x+TEXT_RIGHT, y, ntos(climate_borders[rocky_climate], 0), ALIGN_RIGHT, COL_WHITE, true);
y += 12;
}