author | dominik |
Mon, 16 Aug 2004 13:31:18 +0000 | |
changeset 63 | 53cc59601b3c |
parent 22 | fe6f35cc987b |
child 156 | 8fef5e5752d6 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
||
4 |
#include "window.h" |
|
5 |
#include "gui.h" |
|
6 |
#include "gfx.h" |
|
7 |
#include "vehicle.h" |
|
8 |
#include "viewport.h" |
|
9 |
#include "station.h" |
|
10 |
#include "command.h" |
|
11 |
#include "player.h" |
|
12 |
//#include "town.h" |
|
13 |
#include "engine.h" |
|
14 |
||
15 |
static Engine * const _rail_engines[3] = { |
|
16 |
&_engines[0], |
|
17 |
&_engines[NUM_NORMAL_RAIL_ENGINES], |
|
18 |
&_engines[NUM_MONORAIL_ENGINES + NUM_NORMAL_RAIL_ENGINES], |
|
19 |
}; |
|
20 |
||
21 |
const byte _rail_engines_count[3] = { |
|
22 |
NUM_NORMAL_RAIL_ENGINES, |
|
23 |
NUM_MONORAIL_ENGINES, |
|
24 |
NUM_MAGLEV_ENGINES, |
|
25 |
}; |
|
26 |
||
27 |
const byte _rail_engines_start[3] = { |
|
28 |
0, |
|
29 |
NUM_NORMAL_RAIL_ENGINES, |
|
30 |
NUM_MONORAIL_ENGINES + NUM_NORMAL_RAIL_ENGINES, |
|
31 |
}; |
|
32 |
||
33 |
static void CcBuildWagon(bool success, uint tile, uint32 p1, uint32 p2) |
|
34 |
{ |
|
35 |
Vehicle *v,*found; |
|
36 |
||
37 |
if (!success) |
|
38 |
return; |
|
39 |
||
40 |
// find a locomotive in the depot. |
|
41 |
found = NULL; |
|
42 |
FOR_ALL_VEHICLES(v) { |
|
43 |
if (v->type == VEH_Train && v->subtype==0 && |
|
44 |
v->tile == tile && |
|
45 |
v->u.rail.track == 0x80) { |
|
46 |
if (found != NULL) // must be exactly one. |
|
47 |
return; |
|
48 |
found = v; |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
// if we found a loco, |
|
53 |
if (found != NULL) { |
|
54 |
found = GetLastVehicleInChain(found); |
|
55 |
// put the new wagon at the end of the loco. |
|
56 |
DoCommandP(0, _new_wagon_id | (found->index<<16), 0, NULL, CMD_MOVE_RAIL_VEHICLE); |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
static void CcBuildLoco(bool success, uint tile, uint32 p1, uint32 p2) |
|
61 |
{ |
|
62 |
Vehicle *v; |
|
63 |
||
64 |
if (!success) |
|
65 |
return; |
|
66 |
||
67 |
v = &_vehicles[_new_train_id]; |
|
68 |
if (tile == _backup_orders_tile) { |
|
69 |
_backup_orders_tile = 0; |
|
70 |
RestoreVehicleOrders(v, _backup_orders_data); |
|
71 |
} |
|
72 |
ShowTrainViewWindow(v); |
|
73 |
} |
|
74 |
||
75 |
static void NewRailVehicleWndProc(Window *w, WindowEvent *e) |
|
76 |
{ |
|
77 |
switch(e->event) { |
|
78 |
case WE_PAINT: |
|
79 |
||
80 |
if (w->window_number == 0) |
|
81 |
SETBIT(w->disabled_state, 5); |
|
82 |
||
83 |
{ |
|
84 |
int count = 0; |
|
85 |
int num = _rail_engines_count[WP(w,buildtrain_d).railtype]; |
|
86 |
Engine *e = _rail_engines[WP(w,buildtrain_d).railtype]; |
|
87 |
do { |
|
88 |
if (HASBIT(e->player_avail, _local_player)) |
|
89 |
count++; |
|
90 |
} while (++e,--num); |
|
91 |
SetVScrollCount(w, count); |
|
92 |
} |
|
93 |
||
94 |
SET_DPARAM16(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES); |
|
95 |
DrawWindowWidgets(w); |
|
96 |
||
97 |
{ |
|
98 |
int num = _rail_engines_count[WP(w,buildtrain_d).railtype]; |
|
99 |
Engine *e = _rail_engines[WP(w,buildtrain_d).railtype]; |
|
100 |
int sel = WP(w,buildtrain_d).sel_index; |
|
101 |
int pos = w->vscroll.pos; |
|
102 |
int x = 1; |
|
103 |
int y = 15; |
|
104 |
int engine_id = _rail_engines_start[WP(w,buildtrain_d).railtype]; |
|
105 |
int selected_id = -1; |
|
106 |
||
107 |
do { |
|
108 |
if (HASBIT(e->player_avail, _local_player)) { |
|
109 |
if (sel==0) selected_id = engine_id; |
|
110 |
if (IS_INT_INSIDE(--pos, -8, 0)) { |
|
111 |
DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10); |
|
112 |
DrawTrainEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); |
|
113 |
y += 14; |
|
114 |
} |
|
115 |
sel--; |
|
116 |
} |
|
117 |
} while (++engine_id, ++e,--num); |
|
118 |
||
119 |
WP(w,buildtrain_d).sel_engine = selected_id; |
|
120 |
||
121 |
if (selected_id != -1) { |
|
122 |
const RailVehicleInfo *rvi = &_rail_vehicle_info[selected_id]; |
|
123 |
Engine *e; |
|
124 |
YearMonthDay ymd; |
|
125 |
||
126 |
if (!(rvi->flags & RVI_WAGON)) { |
|
127 |
/* it's an engine */ |
|
128 |
int multihead = (rvi->flags&RVI_MULTIHEAD?1:0); |
|
129 |
||
130 |
SET_DPARAM32(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5); |
|
131 |
SET_DPARAM16(2, rvi->max_speed * 10 >> 4); |
|
132 |
SET_DPARAM16(3, rvi->power << multihead); |
|
133 |
SET_DPARAM16(1, rvi->weight << multihead); |
|
134 |
SET_DPARAM32(4, (rvi->running_cost_base * _price.running_rail[rvi->engclass] >> 8) << multihead); |
|
135 |
||
136 |
SET_DPARAM16(5, STR_8838_N_A); |
|
137 |
if (rvi->capacity != 0) { |
|
138 |
SET_DPARAM16(6, rvi->capacity << multihead); |
|
139 |
SET_DPARAM16(5, _cargoc.names_long_p[rvi->cargo_type]); |
|
140 |
} |
|
141 |
||
142 |
e = &_engines[selected_id]; |
|
143 |
||
144 |
SET_DPARAM16(8, e->lifelength); |
|
145 |
SET_DPARAM8(9, e->reliability * 100 >> 16); |
|
146 |
ConvertDayToYMD(&ymd, e->intro_date); |
|
147 |
SET_DPARAM16(7, ymd.year + 1920); |
|
148 |
||
149 |
DrawString(2, 0x7F, STR_8817_COST_WEIGHT_T_SPEED_POWER, 0); |
|
150 |
} else { |
|
151 |
/* it's a wagon */ |
|
152 |
||
153 |
SET_DPARAM32(0, |
|
154 |
DoCommandByTile(w->window_number, selected_id, 0, DC_QUERY_COST, CMD_BUILD_RAIL_VEHICLE) |
|
155 |
); |
|
156 |
SET_DPARAM16(4, rvi->capacity); |
|
157 |
SET_DPARAM16(1, rvi->weight); |
|
158 |
SET_DPARAM16(3, _cargoc.names_long_p[rvi->cargo_type]); |
|
159 |
SET_DPARAM16(2, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight); |
|
160 |
DrawString(2, 0x7F, STR_8821_COST_WEIGHT_T_T_CAPACITY, 0); |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
break; |
|
165 |
||
166 |
case WE_CLICK: { |
|
167 |
switch(e->click.widget) { |
|
168 |
case 2: { |
|
169 |
uint i = (e->click.pt.y - 14) / 14; |
|
170 |
if (i < 8) { |
|
171 |
WP(w,buildtrain_d).sel_index = i + w->vscroll.pos; |
|
172 |
SetWindowDirty(w); |
|
173 |
} |
|
174 |
} break; |
|
175 |
case 5: { |
|
176 |
int sel_eng; |
|
177 |
sel_eng = WP(w,buildtrain_d).sel_engine; |
|
178 |
if (sel_eng != -1) |
|
179 |
DoCommandP(w->window_number, sel_eng, 0, (_rail_vehicle_info[sel_eng].flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)); |
|
180 |
} break; |
|
181 |
case 6: |
|
182 |
WP(w,buildtrain_d).rename_engine = WP(w,buildtrain_d).sel_engine; |
|
183 |
ShowQueryString( |
|
184 |
GetCustomEngineName(WP(w,buildtrain_d).sel_engine), |
|
185 |
STR_886A_RENAME_TRAIN_VEHICLE_TYPE, |
|
186 |
31, |
|
187 |
160, |
|
188 |
w->window_class, |
|
189 |
w->window_number); |
|
190 |
break; |
|
191 |
} |
|
192 |
} break; |
|
193 |
||
194 |
case WE_4: |
|
195 |
if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) { |
|
196 |
DeleteWindow(w); |
|
197 |
} |
|
198 |
break; |
|
199 |
||
200 |
case WE_ON_EDIT_TEXT: { |
|
201 |
byte *b = e->edittext.str; |
|
202 |
if (*b == 0) |
|
203 |
return; |
|
204 |
||
205 |
memcpy(_decode_parameters, b, 32); |
|
206 |
DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE)); |
|
207 |
} break; |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
static const Widget _new_rail_vehicle_widgets[] = { |
|
212 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
213 |
{ WWT_CAPTION, 14, 11, 227, 0, 13, STR_0315, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
214 |
{ WWT_MATRIX, 14, 0, 216, 14, 125, 0x801, STR_8843_TRAIN_VEHICLE_SELECTION}, |
|
215 |
{ WWT_SCROLLBAR, 14, 217, 227, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
216 |
{ WWT_PANEL, 14, 0, 227, 126, 187, 0x0, 0}, |
|
217 |
{ WWT_PUSHTXTBTN, 14, 0, 113, 188, 199, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN}, |
|
218 |
{ WWT_PUSHTXTBTN, 14, 114, 227, 188, 199, STR_8820_RENAME, STR_8845_RENAME_TRAIN_VEHICLE_TYPE}, |
|
219 |
{ WWT_LAST}, |
|
220 |
}; |
|
221 |
||
222 |
static const WindowDesc _new_rail_vehicle_desc = { |
|
223 |
-1, -1, 228, 200, |
|
224 |
WC_BUILD_VEHICLE,0, |
|
225 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
226 |
_new_rail_vehicle_widgets, |
|
227 |
NewRailVehicleWndProc |
|
228 |
}; |
|
229 |
||
230 |
static void ShowBuildTrainWindow(uint tile) |
|
231 |
{ |
|
232 |
Window *w; |
|
233 |
||
234 |
DeleteWindowById(WC_BUILD_VEHICLE, tile); |
|
235 |
||
236 |
w = AllocateWindowDesc(&_new_rail_vehicle_desc); |
|
237 |
w->window_number = tile; |
|
238 |
w->vscroll.cap = 8; |
|
239 |
||
240 |
if (tile != 0) { |
|
241 |
w->caption_color = _map_owner[tile]; |
|
242 |
WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF; |
|
243 |
} else { |
|
244 |
w->caption_color = _local_player; |
|
245 |
WP(w,buildtrain_d).railtype = DEREF_PLAYER(_local_player)->max_railtype - 1; |
|
246 |
} |
|
247 |
} |
|
248 |
||
249 |
static void DrawTrainImage(Vehicle *v, int x, int y, int count, int skip, VehicleID selection) |
|
250 |
{ |
|
251 |
do { |
|
252 |
if (--skip < 0) { |
|
253 |
int image = GetTrainImage(v, 6); |
|
254 |
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); |
|
255 |
if (v->vehstatus & VS_CRASHED) ormod = 0x3248000; |
|
256 |
DrawSprite(image | ormod, x+14, y+6); |
|
257 |
if (v->index == selection) DrawFrameRect(x-1, y-1, x+28, y+12, 15, 0x10); |
|
258 |
x += 29; |
|
259 |
count--; |
|
260 |
} |
|
261 |
||
262 |
if (!(v = v->next)) |
|
263 |
break; |
|
264 |
} while (count); |
|
265 |
} |
|
266 |
||
267 |
static void DrawTrainDepotWindow(Window *w) |
|
268 |
{ |
|
269 |
uint tile; |
|
270 |
Vehicle *v, *u; |
|
271 |
int num,x,y,i, hnum; |
|
272 |
Depot *d; |
|
273 |
||
274 |
tile = w->window_number; |
|
275 |
||
276 |
/* setup disabled buttons */ |
|
277 |
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<3)|(1<<4)|(1<<6)); |
|
278 |
||
279 |
/* determine amount of items for scroller */ |
|
280 |
num = 1; |
|
281 |
hnum = 0; |
|
282 |
FOR_ALL_VEHICLES(v) { |
|
283 |
if (v->type == VEH_Train && |
|
284 |
(v->subtype == 0 || v->subtype == 4) && |
|
285 |
v->tile == (TileIndex)tile && |
|
286 |
v->u.rail.track == 0x80) { |
|
287 |
num++; |
|
288 |
// determine number of items in the X direction. |
|
289 |
if (v->subtype == 0) { |
|
290 |
i = -1; |
|
291 |
u = v; |
|
292 |
do i++; while ( (u=u->next) != NULL); |
|
293 |
if (i > hnum) hnum = i; |
|
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
SetVScrollCount(w, num); |
|
298 |
SetHScrollCount(w, hnum); |
|
299 |
||
300 |
/* locate the depot struct */ |
|
301 |
for(d=_depots; d->xy != (TileIndex)tile; d++) {} |
|
302 |
||
303 |
SET_DPARAM16(0,d->town_index); |
|
304 |
DrawWindowWidgets(w); |
|
305 |
||
306 |
x = 2; |
|
307 |
y = 15; |
|
308 |
num = w->vscroll.pos; |
|
309 |
||
310 |
// draw all trains |
|
311 |
FOR_ALL_VEHICLES(v) { |
|
312 |
if (v->type == VEH_Train && |
|
313 |
v->subtype == 0 && |
|
314 |
v->tile == (TileIndex)tile && |
|
315 |
v->u.rail.track == 0x80 && |
|
316 |
--num < 0 && num >= -6) { |
|
317 |
||
318 |
DrawTrainImage(v, x+21, y, 10, w->hscroll.pos, WP(w,traindepot_d).sel); |
|
22 | 319 |
/* Draw the train number */ |
0 | 320 |
SET_DPARAM16(0, v->unitnumber); |
321 |
DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0); |
|
22 | 322 |
/* Draw the pretty flag */ |
0 | 323 |
DrawSprite(v->vehstatus&VS_STOPPED ? 0xC12 : 0xC13, x+15, y); |
324 |
||
325 |
y += 14; |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
// draw all remaining vehicles |
|
330 |
FOR_ALL_VEHICLES(v) { |
|
331 |
if (v->type == VEH_Train && |
|
332 |
v->subtype == 4 && |
|
333 |
v->tile == (TileIndex)tile && |
|
334 |
v->u.rail.track == 0x80 && |
|
335 |
--num < 0 && num >= -6) { |
|
336 |
||
337 |
DrawTrainImage(v, x+50, y, 9, 0, WP(w,traindepot_d).sel); |
|
338 |
DrawString(x, y+2, STR_8816, 0); |
|
339 |
y += 14; |
|
340 |
} |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
typedef struct GetDepotVehiclePtData { |
|
345 |
Vehicle *head; |
|
346 |
Vehicle *wagon; |
|
347 |
} GetDepotVehiclePtData; |
|
348 |
||
349 |
static int GetVehicleFromTrainDepotWndPt(Window *w, int x, int y, GetDepotVehiclePtData *d) |
|
350 |
{ |
|
351 |
int area_x; |
|
352 |
int row; |
|
353 |
Vehicle *v; |
|
354 |
||
355 |
x = x - 23; |
|
356 |
if (x < 0) { |
|
357 |
area_x = (x >= -10) ? -2 : -1; |
|
358 |
} else { |
|
359 |
area_x = x / 29; |
|
360 |
} |
|
361 |
||
362 |
row = (y - 14) / 14; |
|
363 |
if ( (uint) row >= 6) |
|
364 |
return 1; /* means err */ |
|
365 |
||
366 |
row += w->vscroll.pos; |
|
367 |
||
368 |
/* go through all the locomotives */ |
|
369 |
FOR_ALL_VEHICLES(v) { |
|
370 |
if (v->type == VEH_Train && |
|
371 |
v->subtype == 0 && |
|
372 |
v->tile == w->window_number && |
|
373 |
v->u.rail.track == 0x80 && |
|
374 |
--row < 0) { |
|
375 |
area_x += w->hscroll.pos; |
|
376 |
goto found_it; |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
area_x--; /* free wagons don't have an initial loco. */ |
|
381 |
||
382 |
/* and then the list of free wagons */ |
|
383 |
FOR_ALL_VEHICLES(v) { |
|
384 |
if (v->type == VEH_Train && |
|
385 |
v->subtype == 4 && |
|
386 |
v->tile == w->window_number && |
|
387 |
v->u.rail.track == 0x80 && |
|
388 |
--row < 0) |
|
389 |
goto found_it; |
|
390 |
} |
|
391 |
||
392 |
d->head = NULL; |
|
393 |
d->wagon = NULL; |
|
394 |
||
395 |
/* didn't find anything, get out */ |
|
396 |
return 0; |
|
397 |
||
398 |
found_it: |
|
399 |
d->head = d->wagon = v; |
|
400 |
||
401 |
/* either pressed the flag or the number, but only when it's a loco */ |
|
402 |
if (area_x < 0 && v->subtype==0) |
|
403 |
return area_x; |
|
404 |
||
405 |
/* find the vehicle in this row that was clicked */ |
|
406 |
while (--area_x >= 0) { |
|
407 |
v = v->next; |
|
408 |
if (v == NULL) break; |
|
409 |
} |
|
410 |
||
411 |
d->wagon = v; |
|
412 |
||
413 |
return 0; |
|
414 |
} |
|
415 |
||
416 |
static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head) |
|
417 |
{ |
|
418 |
Vehicle *v; |
|
419 |
||
420 |
v = &_vehicles[sel]; |
|
421 |
||
422 |
if (/*v->subtype == 0 ||*/ v == wagon) |
|
423 |
return; |
|
424 |
||
425 |
if (wagon == NULL) { |
|
426 |
if (head != NULL) |
|
427 |
wagon = GetLastVehicleInChain(head); |
|
428 |
} else { |
|
429 |
wagon = GetPrevVehicleInChain(wagon); |
|
430 |
if (wagon == NULL) |
|
431 |
return; |
|
432 |
} |
|
433 |
||
434 |
if (wagon == v) |
|
435 |
return; |
|
436 |
||
437 |
DoCommandP(v->tile, v->index + ((wagon==NULL ? (uint32)-1 : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); |
|
438 |
} |
|
439 |
||
440 |
static void TrainDepotClickTrain(Window *w, int x, int y) |
|
441 |
{ |
|
442 |
GetDepotVehiclePtData gdvp; |
|
443 |
int mode, sel; |
|
444 |
Vehicle *v; |
|
445 |
||
446 |
mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp); |
|
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
447 |
|
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
448 |
// share / copy orders |
0 | 449 |
if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = gdvp.head; return; } |
450 |
||
451 |
v = gdvp.wagon; |
|
452 |
||
453 |
switch(mode) { |
|
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
454 |
case 0: // start dragging of vehicle |
0 | 455 |
sel = (int16)WP(w,traindepot_d).sel; |
456 |
if (sel != -1) { |
|
457 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
458 |
TrainDepotMoveVehicle(v, sel, gdvp.head); |
|
459 |
} else if (v != NULL) { |
|
460 |
WP(w,traindepot_d).sel = v->index; |
|
461 |
SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetTrainImage(v, 6), 4, w); |
|
462 |
SetWindowDirty(w); |
|
463 |
} |
|
464 |
break; |
|
465 |
||
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
466 |
case -1: // show info window |
0 | 467 |
ShowTrainViewWindow(v); |
468 |
break; |
|
469 |
||
10
c35ab8426202
(svn r11) Feature: Copy/share orders now works from ship depot window for ships and hangar window for aircraft
dominik
parents:
0
diff
changeset
|
470 |
case -2: // click start/stop flag |
0 | 471 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); |
472 |
break; |
|
473 |
} |
|
474 |
} |
|
475 |
||
476 |
static void TrainDepotWndProc(Window *w, WindowEvent *e) |
|
477 |
{ |
|
478 |
switch(e->event) { |
|
479 |
case WE_PAINT: |
|
480 |
DrawTrainDepotWindow(w); |
|
481 |
break; |
|
482 |
||
483 |
case WE_CLICK: { |
|
484 |
switch(e->click.widget) { |
|
485 |
case 6: |
|
486 |
ShowBuildTrainWindow(w->window_number); |
|
487 |
break; |
|
488 |
case 7: |
|
489 |
ScrollMainWindowToTile(w->window_number); |
|
490 |
break; |
|
491 |
case 2: |
|
492 |
TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y); |
|
493 |
break; |
|
494 |
} |
|
495 |
} break; |
|
496 |
||
497 |
case WE_DESTROY: |
|
498 |
DeleteWindowById(WC_BUILD_VEHICLE, w->window_number); |
|
499 |
break; |
|
500 |
||
501 |
case WE_DRAGDROP: { |
|
502 |
switch(e->click.widget) { |
|
503 |
case 4: |
|
504 |
case 3: { |
|
505 |
Vehicle *v; |
|
506 |
int sell_cmd; |
|
507 |
||
508 |
/* sell vehicle */ |
|
509 |
if (w->disabled_state & (1 << e->click.widget)) |
|
510 |
return; |
|
511 |
||
512 |
if (WP(w,traindepot_d).sel == INVALID_VEHICLE) |
|
513 |
return; |
|
514 |
||
515 |
v = &_vehicles[WP(w,traindepot_d).sel]; |
|
516 |
||
517 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
518 |
SetWindowDirty(w); |
|
519 |
||
520 |
HandleButtonClick(w, e->click.widget); |
|
521 |
||
522 |
sell_cmd = (e->click.widget == 4 || _ctrl_pressed) ? 1 : 0; |
|
523 |
||
524 |
if (v->subtype != 0) { |
|
525 |
DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE)); |
|
526 |
} else { |
|
527 |
_backup_orders_tile = v->tile; |
|
528 |
BackupVehicleOrders(v, _backup_orders_data); |
|
529 |
if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE))) |
|
530 |
_backup_orders_tile = 0; |
|
531 |
} |
|
532 |
} break; |
|
533 |
||
534 |
case 2: { |
|
535 |
GetDepotVehiclePtData gdvp; |
|
536 |
VehicleID sel = WP(w,traindepot_d).sel; |
|
537 |
||
538 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
539 |
SetWindowDirty(w); |
|
540 |
||
541 |
if (GetVehicleFromTrainDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &gdvp) == 0 && |
|
542 |
sel != INVALID_VEHICLE) { |
|
543 |
if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { |
|
544 |
TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); |
|
545 |
} else if (gdvp.head != NULL && gdvp.head->subtype==0) { |
|
546 |
ShowTrainViewWindow(gdvp.head); |
|
547 |
} |
|
548 |
} |
|
549 |
} break; |
|
550 |
||
551 |
default: |
|
552 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
553 |
SetWindowDirty(w); |
|
554 |
break; |
|
555 |
} |
|
556 |
} break; |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
||
561 |
static const Widget _train_depot_widgets[] = { |
|
562 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
563 |
{ WWT_CAPTION, 14, 11, 348, 0, 13, STR_8800_TRAIN_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
564 |
{ WWT_MATRIX, 14, 0, 313, 14, 97, 0x601, STR_883F_TRAINS_CLICK_ON_TRAIN_FOR}, |
|
565 |
//{ WWT_PANEL, 14, 314, 337, 14, 108, 0x2A9, STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE}, |
|
566 |
{ WWT_PANEL, 14, 314, 337, 14, 54, 0x2A9, STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE}, |
|
567 |
{ WWT_PANEL, 14, 314, 337, 55, 108, 0x2BF, STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, |
|
568 |
||
569 |
{ WWT_SCROLLBAR, 14, 338, 348, 14, 108, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
570 |
{ WWT_PUSHTXTBTN, 14, 0, 173, 109, 120, STR_8815_NEW_VEHICLES, STR_8840_BUILD_NEW_TRAIN_VEHICLE}, |
|
571 |
{ WWT_PUSHTXTBTN, 14, 174, 348, 109, 120, STR_00E4_LOCATION, STR_8842_CENTER_MAIN_VIEW_ON_TRAIN}, |
|
572 |
{ WWT_HSCROLLBAR, 14, 0, 313, 98, 108, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
573 |
{ WWT_LAST}, |
|
574 |
}; |
|
575 |
||
576 |
static const WindowDesc _train_depot_desc = { |
|
577 |
-1, -1, 349, 121, |
|
578 |
WC_VEHICLE_DEPOT,0, |
|
579 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
580 |
_train_depot_widgets, |
|
581 |
TrainDepotWndProc |
|
582 |
}; |
|
583 |
||
584 |
||
585 |
void ShowTrainDepotWindow(uint tile) |
|
586 |
{ |
|
587 |
Window *w; |
|
588 |
||
589 |
w = AllocateWindowDescFront(&_train_depot_desc, tile); |
|
590 |
if (w) { |
|
591 |
w->caption_color = _map_owner[w->window_number]; |
|
592 |
w->vscroll.cap = 6; |
|
593 |
w->hscroll.cap = 9; |
|
594 |
WP(w,traindepot_d).sel = INVALID_VEHICLE; |
|
595 |
_backup_orders_tile = 0; |
|
596 |
} |
|
597 |
} |
|
598 |
||
599 |
const byte _rail_vehicle_refit_types[4][16] = { |
|
600 |
{ 0,1,2,4,5,6,7,8,9,10,0xFF }, // normal |
|
601 |
{ 0,1,4,5,6,7,9,11,10,0xFF }, // arctic |
|
602 |
{ 0,4,5,8,6,7,9,10,0xFF }, // desert |
|
603 |
{ 0,1,3,5,7,8,9,6,4,10,11,0xFF }// candy |
|
604 |
}; |
|
605 |
||
606 |
static void RailVehicleRefitWndProc(Window *w, WindowEvent *e) |
|
607 |
{ |
|
608 |
switch(e->event) { |
|
609 |
case WE_PAINT: { |
|
610 |
Vehicle *v = &_vehicles[w->window_number]; |
|
611 |
const byte *b; |
|
612 |
int sel; |
|
613 |
int x,y; |
|
614 |
byte color; |
|
615 |
int cargo; |
|
616 |
||
617 |
SET_DPARAM16(0, v->string_id); |
|
618 |
SET_DPARAM16(1, v->unitnumber); |
|
619 |
DrawWindowWidgets(w); |
|
620 |
||
621 |
DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0); |
|
622 |
||
623 |
cargo = -1; |
|
624 |
x = 6; |
|
625 |
y = 25; |
|
626 |
sel = WP(w,refit_d).sel; |
|
627 |
b = _rail_vehicle_refit_types[_opt.landscape]; |
|
628 |
do { |
|
629 |
color = 16; |
|
630 |
if (sel == 0) { |
|
631 |
cargo = *b; |
|
632 |
color = 12; |
|
633 |
} |
|
634 |
sel--; |
|
635 |
DrawString(x,y,_cargoc.names_s[*b], color); |
|
636 |
y += 10; |
|
637 |
} while (*++b != 255); |
|
638 |
||
639 |
WP(w,refit_d).cargo = cargo; |
|
640 |
||
641 |
if (cargo != -1) { |
|
642 |
int32 cost = DoCommandByTile(v->tile, v->index, cargo, 0, CMD_REFIT_RAIL_VEHICLE); |
|
643 |
if (cost != CMD_ERROR) { |
|
644 |
SET_DPARAM32(2, cost); |
|
645 |
SET_DPARAM16(0, _cargoc.names_long_p[cargo]); |
|
646 |
SET_DPARAM16(1, _returned_refit_amount); |
|
647 |
DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0); |
|
648 |
} |
|
649 |
} |
|
650 |
break; |
|
651 |
} |
|
652 |
||
653 |
case WE_CLICK: |
|
654 |
switch(e->click.widget) { |
|
655 |
case 2: { /* listbox */ |
|
656 |
int y = e->click.pt.y - 25; |
|
657 |
if (y >= 0) { |
|
658 |
WP(w,refit_d).sel = y / 10; |
|
659 |
SetWindowDirty(w); |
|
660 |
} |
|
661 |
} break; |
|
662 |
case 4: /* refit button */ |
|
663 |
if (WP(w,refit_d).cargo != 0xFF) { |
|
664 |
Vehicle *v = &_vehicles[w->window_number]; |
|
665 |
if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE))) |
|
666 |
DeleteWindow(w); |
|
667 |
} |
|
668 |
break; |
|
669 |
} |
|
670 |
break; |
|
671 |
} |
|
672 |
} |
|
673 |
||
674 |
||
675 |
static const Widget _rail_vehicle_refit_widgets[] = { |
|
676 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
677 |
{ WWT_CAPTION, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
678 |
{ WWT_IMGBTN, 14, 0, 239, 14, 135, 0x0, STR_RAIL_SELECT_TYPE_OF_CARGO_FOR}, |
|
679 |
{ WWT_IMGBTN, 14, 0, 239, 136, 157, 0x0}, |
|
680 |
{ WWT_PUSHTXTBTN, 14, 0, 239, 158, 169, STR_RAIL_REFIT_VEHICLE, STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED}, |
|
681 |
{ WWT_LAST}, |
|
682 |
}; |
|
683 |
||
684 |
static const WindowDesc _rail_vehicle_refit_desc = { |
|
685 |
-1,-1, 240, 170, |
|
686 |
WC_VEHICLE_REFIT,WC_VEHICLE_VIEW, |
|
687 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
688 |
_rail_vehicle_refit_widgets, |
|
689 |
RailVehicleRefitWndProc, |
|
690 |
}; |
|
691 |
||
692 |
static void ShowRailVehicleRefitWindow(Vehicle *v) |
|
693 |
{ |
|
694 |
Window *w; |
|
695 |
DeleteWindowById(WC_VEHICLE_REFIT, v->index); |
|
696 |
_alloc_wnd_parent_num = v->index; |
|
697 |
w = AllocateWindowDesc(&_rail_vehicle_refit_desc); |
|
698 |
w->window_number = v->index; |
|
699 |
w->caption_color = v->owner; |
|
700 |
WP(w,refit_d).sel = -1; |
|
701 |
} |
|
702 |
||
703 |
||
704 |
||
705 |
||
706 |
static Widget _train_view_widgets[] = { |
|
707 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
708 |
{ WWT_CAPTION, 14, 11, 249, 0, 13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
709 |
{ WWT_PANEL, 14, 0, 231, 14, 121, 0x0, 0}, |
|
710 |
{ WWT_6, 14, 2, 229, 16, 119, 0, 0}, |
|
711 |
{ WWT_PUSHIMGBTN, 14, 0, 249, 122, 133, 0x0, STR_8846_CURRENT_TRAIN_ACTION_CLICK}, |
|
712 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 14, 31, 0x2AB, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN}, |
|
713 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 32, 49, 0x2AD, STR_8849_SEND_TRAIN_TO_DEPOT}, |
|
714 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 50, 67, 0x2B1, STR_884A_FORCE_TRAIN_TO_PROCEED}, |
|
715 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 68, 85, 0x2CB, STR_884B_REVERSE_DIRECTION_OF_TRAIN}, |
|
716 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 86, 103, 0x2B2, STR_8847_SHOW_TRAIN_S_ORDERS}, |
|
717 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 104, 121, 0x2B3, STR_884C_SHOW_TRAIN_DETAILS}, |
|
718 |
{ WWT_PUSHIMGBTN, 14, 232, 249, 68, 85, 0x2B4, STR_RAIL_REFIT_VEHICLE_TO_CARRY}, |
|
719 |
{ WWT_LAST}, |
|
720 |
}; |
|
721 |
||
722 |
static void TrainViewWndProc(Window *w, WindowEvent *e) |
|
723 |
{ |
|
724 |
switch(e->event) { |
|
725 |
case WE_PAINT: { |
|
726 |
Vehicle *v; |
|
727 |
StringID str; |
|
728 |
||
729 |
v = &_vehicles[w->window_number]; |
|
730 |
||
731 |
w->disabled_state = (v->owner == _local_player) ? 0 : 0x1C0; |
|
732 |
||
733 |
||
734 |
/* draw widgets & caption */ |
|
735 |
SET_DPARAM16(0, v->string_id); |
|
736 |
SET_DPARAM16(1, v->unitnumber); |
|
737 |
DrawWindowWidgets(w); |
|
738 |
||
739 |
/* draw the flag */ |
|
740 |
DrawSprite( (v->vehstatus&VS_STOPPED) ? 0xC12 : 0xC13, 2, 123); |
|
741 |
||
742 |
if (v->u.rail.crash_anim_pos != 0) { |
|
743 |
str = STR_8863_CRASHED; |
|
744 |
} else if (v->breakdown_ctr == 1) { |
|
745 |
str = STR_885C_BROKEN_DOWN; |
|
746 |
} else if (v->vehstatus & VS_STOPPED) { |
|
747 |
if (v->u.rail.last_speed == 0) { |
|
748 |
str = STR_8861_STOPPED; |
|
749 |
} else { |
|
750 |
SET_DPARAM16(0, v->u.rail.last_speed * 10 >> 4); |
|
751 |
str = STR_TRAIN_STOPPING + _patches.vehicle_speed; |
|
752 |
} |
|
753 |
} else { |
|
754 |
switch(v->next_order & OT_MASK) { |
|
755 |
case OT_GOTO_STATION: { |
|
756 |
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed; |
|
757 |
SET_DPARAM16(0, v->next_order_param); |
|
758 |
SET_DPARAM16(1, v->u.rail.last_speed * 10 >> 4); |
|
759 |
} break; |
|
760 |
||
761 |
case OT_GOTO_DEPOT: { |
|
762 |
Depot *dep = &_depots[v->next_order_param]; |
|
763 |
SET_DPARAM16(0, dep->town_index); |
|
764 |
str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed; |
|
765 |
SET_DPARAM16(1, v->u.rail.last_speed * 10 >> 4); |
|
766 |
} break; |
|
767 |
||
768 |
case OT_LOADING: |
|
769 |
case OT_LEAVESTATION: |
|
770 |
str = STR_882F_LOADING_UNLOADING; |
|
771 |
break; |
|
772 |
||
773 |
case OT_GOTO_CHECKPOINT: { |
|
774 |
SET_DPARAM16(0, v->next_order_param); |
|
775 |
str = STR_HEADING_FOR_CHECKPOINT + _patches.vehicle_speed; |
|
776 |
SET_DPARAM16(1, v->u.rail.last_speed * 10 >> 4); |
|
777 |
break; |
|
778 |
} |
|
779 |
||
780 |
default: |
|
781 |
if (v->num_orders == 0) { |
|
782 |
str = STR_NO_ORDERS + _patches.vehicle_speed; |
|
783 |
SET_DPARAM16(0, v->u.rail.last_speed * 10 >> 4); |
|
784 |
} else |
|
785 |
str = STR_EMPTY; |
|
786 |
break; |
|
787 |
} |
|
788 |
} |
|
789 |
||
790 |
DrawStringCentered(125, 123, str, 0); |
|
791 |
DrawWindowViewport(w); |
|
792 |
} break; |
|
793 |
||
794 |
case WE_CLICK: { |
|
795 |
int wid = e->click.widget; |
|
796 |
Vehicle *v = &_vehicles[w->window_number]; |
|
797 |
||
798 |
switch(wid) { |
|
799 |
case 4: /* start/stop train */ |
|
800 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); |
|
801 |
break; |
|
802 |
case 5: /* center main view */ |
|
803 |
ScrollMainWindowTo(v->x_pos, v->y_pos); |
|
804 |
break; |
|
805 |
case 6: /* goto depot */ |
|
806 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_TRAIN_GOTO_DEPOT | CMD_MSG(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT)); |
|
807 |
break; |
|
808 |
case 7: /* force proceed */ |
|
809 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL)); |
|
810 |
break; |
|
811 |
case 8: /* reverse direction */ |
|
812 |
DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION)); |
|
813 |
break; |
|
814 |
case 9: /* show train orders */ |
|
815 |
ShowOrdersWindow(v); |
|
816 |
break; |
|
817 |
case 10: /* show train details */ |
|
818 |
ShowTrainDetailsWindow(v); |
|
819 |
break; |
|
820 |
case 11: |
|
821 |
ShowRailVehicleRefitWindow(v); |
|
822 |
break; |
|
823 |
} |
|
824 |
} break; |
|
825 |
||
826 |
case WE_DESTROY: |
|
827 |
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number); |
|
828 |
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number); |
|
829 |
break; |
|
830 |
||
831 |
case WE_MOUSELOOP: { |
|
832 |
Vehicle *v; |
|
833 |
uint32 h; |
|
834 |
||
835 |
v = &_vehicles[w->window_number]; |
|
836 |
assert(v->type == VEH_Train); |
|
837 |
h = CheckStoppedInDepot(v) >= 0 ? (1 << 8) : (1 << 11); |
|
838 |
if (h != w->hidden_state) { |
|
839 |
w->hidden_state = h; |
|
840 |
SetWindowDirty(w); |
|
841 |
} |
|
842 |
break; |
|
843 |
} |
|
844 |
||
845 |
} |
|
846 |
} |
|
847 |
||
848 |
static const WindowDesc _train_view_desc = { |
|
849 |
-1,-1, 250, 134, |
|
850 |
WC_VEHICLE_VIEW,0, |
|
851 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
852 |
_train_view_widgets, |
|
853 |
TrainViewWndProc |
|
854 |
}; |
|
855 |
||
856 |
void ShowTrainViewWindow(Vehicle *v) |
|
857 |
{ |
|
858 |
Window *w; |
|
859 |
||
860 |
w = AllocateWindowDescFront(&_train_view_desc,v->index); |
|
861 |
if (w) { |
|
862 |
w->caption_color = v->owner; |
|
863 |
AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0); |
|
864 |
} |
|
865 |
} |
|
866 |
||
867 |
static void TrainDetailsCargoTab(Vehicle *v, int x, int y) |
|
868 |
{ |
|
869 |
int num; |
|
870 |
StringID str; |
|
871 |
||
872 |
if (v->cargo_cap != 0) { |
|
873 |
num = v->cargo_count; |
|
874 |
str = STR_8812_EMPTY; |
|
875 |
if (num != 0) { |
|
876 |
SET_DPARAM8(0, v->cargo_type); |
|
877 |
SET_DPARAM16(1, num); |
|
878 |
SET_DPARAM16(2, v->cargo_source); |
|
879 |
str = STR_8813_FROM; |
|
880 |
} |
|
881 |
DrawString(x, y, str, 0); |
|
882 |
} |
|
883 |
} |
|
884 |
||
885 |
static void TrainDetailsInfoTab(Vehicle *v, int x, int y) |
|
886 |
{ |
|
887 |
const RailVehicleInfo *rvi; |
|
888 |
||
889 |
rvi = &_rail_vehicle_info[v->engine_type]; |
|
890 |
||
891 |
if (!(rvi->flags & RVI_WAGON)) { |
|
892 |
SET_DPARAM16(0, GetCustomEngineName(v->engine_type)); |
|
893 |
SET_DPARAM16(1, v->build_year + 1920); |
|
894 |
SET_DPARAM32(2, v->value); |
|
895 |
DrawString(x, y, STR_882C_BUILT_VALUE, 0x10); |
|
896 |
} else { |
|
897 |
SET_DPARAM16(0, GetCustomEngineName(v->engine_type)); |
|
898 |
SET_DPARAM32(1, v->value); |
|
899 |
DrawString(x, y, STR_882D_VALUE, 0x10); |
|
900 |
} |
|
901 |
} |
|
902 |
||
903 |
static void TrainDetailsCapacityTab(Vehicle *v, int x, int y) |
|
904 |
{ |
|
905 |
if (v->cargo_cap != 0) { |
|
906 |
SET_DPARAM16(1, v->cargo_cap); |
|
907 |
SET_DPARAM16(0, _cargoc.names_long_p[v->cargo_type]); |
|
908 |
DrawString(x, y, STR_013F_CAPACITY, 0); |
|
909 |
} |
|
910 |
} |
|
911 |
||
912 |
typedef void TrainDetailsDrawerProc(Vehicle *v, int x, int y); |
|
913 |
||
914 |
static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = { |
|
915 |
TrainDetailsCargoTab, |
|
916 |
TrainDetailsInfoTab, |
|
917 |
TrainDetailsCapacityTab, |
|
918 |
}; |
|
919 |
||
920 |
static void DrawTrainDetailsWindow(Window *w) |
|
921 |
{ |
|
922 |
Vehicle *v, *u; |
|
923 |
uint16 tot_cargo[NUM_CARGO][2]; // count total cargo ([0]-actual cargo, [1]-total cargo) |
|
924 |
int i,num,x,y,sel; |
|
925 |
StringID str; |
|
926 |
byte det_tab = WP(w, traindetails_d).tab; |
|
927 |
||
928 |
/* Count number of vehicles */ |
|
929 |
num = 0; |
|
930 |
||
931 |
// det_tab == 3 <-- Total Cargo tab |
|
932 |
if (det_tab == 3) // reset tot_cargo array to 0 values |
|
933 |
memset(tot_cargo, 0, sizeof(tot_cargo)); |
|
934 |
||
935 |
u = v = &_vehicles[w->window_number]; |
|
936 |
do { |
|
937 |
if (det_tab != 3) |
|
938 |
num++; |
|
939 |
else { |
|
940 |
tot_cargo[u->cargo_type][0] += u->cargo_count; |
|
941 |
tot_cargo[u->cargo_type][1] += u->cargo_cap; |
|
942 |
} |
|
943 |
} while ( (u = u->next) != NULL); |
|
944 |
||
945 |
/* set scroll-amount seperately from counting, as to not |
|
946 |
compute num double for more carriages of the same type |
|
947 |
*/ |
|
948 |
if (det_tab == 3) { |
|
949 |
for (i = 0; i != NUM_CARGO; i++) { |
|
950 |
if (tot_cargo[i][1] > 0) // only count carriages that the train has |
|
951 |
num++; |
|
952 |
} |
|
953 |
num++; // needs one more because first line is description string |
|
954 |
} |
|
955 |
||
956 |
SetVScrollCount(w, num); |
|
957 |
||
958 |
w->disabled_state = 1 << (det_tab + 9); |
|
959 |
if (v->owner != _local_player) |
|
960 |
w->disabled_state |= (1 << 2); |
|
961 |
||
962 |
SET_DPARAM16(0, v->string_id); |
|
963 |
SET_DPARAM16(1, v->unitnumber); |
|
964 |
DrawWindowWidgets(w); |
|
965 |
||
966 |
num = v->age / 366; |
|
967 |
SET_DPARAM16(1, num); |
|
968 |
||
969 |
x = 2; |
|
970 |
||
971 |
str = STR_0199_YEAR; |
|
972 |
if (num != 1) { |
|
973 |
str += STR_019A_YEARS - STR_0199_YEAR; |
|
974 |
if ((uint16)(v->max_age - 366) < v->age) |
|
975 |
str += STR_019B_YEARS - STR_019A_YEARS; |
|
976 |
} |
|
977 |
SET_DPARAM16(0, str); |
|
978 |
SET_DPARAM16(2, v->max_age / 366); |
|
979 |
SET_DPARAM32(3, GetTrainRunningCost(v) >> 8); |
|
980 |
DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0); |
|
981 |
||
982 |
SET_DPARAM16(2, v->max_speed * 10 >> 4); |
|
983 |
SET_DPARAM32(1, v->u.rail.cached_power); |
|
984 |
SET_DPARAM16(0, v->u.rail.cached_weight); |
|
985 |
DrawString(x, 25, STR_885E_WEIGHT_T_POWER_HP_MAX_SPEED, 0); |
|
986 |
||
987 |
SET_DPARAM32(0, v->profit_this_year); |
|
988 |
SET_DPARAM32(1, v->profit_last_year); |
|
989 |
DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
|
990 |
||
991 |
SET_DPARAM8(0, 100 * (v->reliability>>8) >> 8); |
|
992 |
SET_DPARAM16(1, v->breakdowns_since_last_service); |
|
993 |
DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0); |
|
994 |
||
995 |
SET_DPARAM16(0, v->service_interval); |
|
996 |
SET_DPARAM16(1, v->date_of_last_service); |
|
997 |
DrawString(x + 11, 141, STR_883C_SERVICING_INTERVAL_DAYS, 0); |
|
998 |
||
999 |
x = 1; |
|
1000 |
y = 57; |
|
1001 |
sel = w->vscroll.pos; |
|
1002 |
||
1003 |
// draw the first 3 details tabs |
|
1004 |
if (det_tab != 3) { |
|
1005 |
for(;;) { |
|
1006 |
if (--sel < 0 && sel >= -6) { |
|
1007 |
DrawTrainImage(v, x, y, 1, 0, INVALID_VEHICLE); |
|
1008 |
_train_details_drawer_proc[WP(w,traindetails_d).tab](v, x + 30, y + 2); |
|
1009 |
y += 14; |
|
1010 |
} |
|
1011 |
if ( (v=v->next) == NULL) |
|
1012 |
return; |
|
1013 |
} |
|
1014 |
} |
|
1015 |
else { // draw total cargo tab |
|
1016 |
i = 0; |
|
1017 |
DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0); |
|
1018 |
do { |
|
1019 |
if (tot_cargo[i][1] > 0 && --sel < 0 && sel >= -5) { |
|
1020 |
y += 14; |
|
1021 |
// STR_013F_TOTAL_CAPACITY :{LTBLUE}- {CARGO} ({SHORTCARGO}) |
|
1022 |
SET_DPARAM8(0, i); // {CARGO} #1 |
|
1023 |
SET_DPARAM16(1, tot_cargo[i][0]); // {CARGO} #2 |
|
1024 |
SET_DPARAM8(2, i); // {SHORTCARGO} #1 |
|
1025 |
SET_DPARAM16(3, tot_cargo[i][1]); // {SHORTCARGO} #2 |
|
1026 |
DrawString(x, y, STR_013F_TOTAL_CAPACITY, 0); |
|
1027 |
} |
|
1028 |
} while (++i != NUM_CARGO); |
|
1029 |
} |
|
1030 |
} |
|
1031 |
||
1032 |
static void TrainDetailsWndProc(Window *w, WindowEvent *e) |
|
1033 |
{ |
|
1034 |
switch(e->event) { |
|
1035 |
case WE_PAINT: |
|
1036 |
DrawTrainDetailsWindow(w); |
|
1037 |
break; |
|
1038 |
case WE_CLICK: { |
|
1039 |
int mod; |
|
1040 |
Vehicle *v; |
|
1041 |
switch(e->click.widget) { |
|
1042 |
case 2: /* name train */ |
|
1043 |
v = &_vehicles[w->window_number]; |
|
1044 |
SET_DPARAM16(0, v->unitnumber); |
|
1045 |
ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number); |
|
1046 |
break; |
|
1047 |
case 6: /* inc serv interval */ |
|
1048 |
mod = 10; |
|
1049 |
goto do_change_service_int; |
|
1050 |
||
1051 |
case 7: /* dec serv interval */ |
|
1052 |
mod = -10; |
|
1053 |
do_change_service_int: |
|
1054 |
v = &_vehicles[w->window_number]; |
|
1055 |
mod += v->service_interval; |
|
1056 |
if (!IS_INT_INSIDE(mod, 30, 800+1)) |
|
1057 |
return; |
|
1058 |
||
1059 |
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); |
|
1060 |
break; |
|
1061 |
/* details buttons*/ |
|
1062 |
case 9: // Cargo |
|
1063 |
case 10: // Information |
|
1064 |
case 11: // Capacities |
|
1065 |
case 12: // Total cargo |
|
1066 |
CLRBIT(w->disabled_state, 9); |
|
1067 |
CLRBIT(w->disabled_state, 10); |
|
1068 |
CLRBIT(w->disabled_state, 11); |
|
1069 |
CLRBIT(w->disabled_state, 12); |
|
1070 |
SETBIT(w->disabled_state, e->click.widget); |
|
1071 |
WP(w,traindetails_d).tab = e->click.widget - 9; |
|
1072 |
SetWindowDirty(w); |
|
1073 |
break; |
|
1074 |
} |
|
1075 |
} break; |
|
1076 |
||
1077 |
case WE_4: |
|
1078 |
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL) |
|
1079 |
DeleteWindow(w); |
|
1080 |
break; |
|
1081 |
||
1082 |
case WE_ON_EDIT_TEXT: { |
|
1083 |
byte *b = e->edittext.str; |
|
1084 |
if (*b == 0) |
|
1085 |
return; |
|
1086 |
memcpy(_decode_parameters, b, 32); |
|
1087 |
DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN)); |
|
1088 |
} break; |
|
1089 |
} |
|
1090 |
} |
|
1091 |
||
1092 |
static const Widget _train_details_widgets[] = { |
|
1093 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
1094 |
{ WWT_CAPTION, 14, 11, 329, 0, 13, STR_8802_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
1095 |
{ WWT_PUSHTXTBTN, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN}, |
|
1096 |
{ WWT_PANEL, 14, 0, 369, 14, 55, 0x0, 0}, |
|
1097 |
{ WWT_MATRIX, 14, 0, 358, 56, 139, 0x601, 0}, |
|
1098 |
{ WWT_SCROLLBAR, 14, 359, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
1099 |
{ WWT_PUSHTXTBTN, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, |
|
1100 |
{ WWT_PUSHTXTBTN, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, |
|
1101 |
{ WWT_PANEL, 14, 11, 369, 140, 151, 0x0, 0}, |
|
1102 |
{ WWT_PUSHTXTBTN, 14, 0, 92, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED}, |
|
1103 |
{ WWT_PUSHTXTBTN, 14, 93, 184, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES}, |
|
1104 |
{ WWT_PUSHTXTBTN, 14, 185, 277, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH}, |
|
1105 |
{ WWT_PUSHTXTBTN, 14, 278, 369, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO}, |
|
1106 |
{ WWT_LAST}, |
|
1107 |
}; |
|
1108 |
||
1109 |
||
1110 |
static const WindowDesc _train_details_desc = { |
|
1111 |
-1,-1, 370, 164, |
|
1112 |
WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW, |
|
1113 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
1114 |
_train_details_widgets, |
|
1115 |
TrainDetailsWndProc |
|
1116 |
}; |
|
1117 |
||
1118 |
||
1119 |
void ShowTrainDetailsWindow(Vehicle *v) |
|
1120 |
{ |
|
1121 |
Window *w; |
|
1122 |
VehicleID veh = v->index; |
|
1123 |
||
1124 |
DeleteWindowById(WC_VEHICLE_ORDERS, veh); |
|
1125 |
DeleteWindowById(WC_VEHICLE_DETAILS, veh); |
|
1126 |
||
1127 |
_alloc_wnd_parent_num = veh; |
|
1128 |
w = AllocateWindowDesc(&_train_details_desc); |
|
1129 |
||
1130 |
w->window_number = veh; |
|
1131 |
w->caption_color = v->owner; |
|
1132 |
w->vscroll.cap = 6; |
|
1133 |
WP(w,traindetails_d).tab = 0; |
|
1134 |
} |
|
1135 |
||
1136 |
// draw the vehicle profit button in the vehicle list window. |
|
1137 |
void DrawVehicleProfitButton(Vehicle *v, int x, int y) |
|
1138 |
{ |
|
1139 |
uint32 ormod; |
|
1140 |
||
1141 |
// draw profit-based colored icons |
|
1142 |
if(v->age <= 365 * 2) |
|
1143 |
ormod = 0x3158000; // grey |
|
1144 |
else if(v->profit_last_year < 0) |
|
1145 |
ormod = 0x30b8000; //red |
|
1146 |
else if(v->profit_last_year < 10000) |
|
1147 |
ormod = 0x30a8000; // yellow |
|
1148 |
else |
|
1149 |
ormod = 0x30d8000; // green |
|
1150 |
DrawSprite((SPR_OPENTTD_BASE + 10) | ormod, x, y); |
|
1151 |
} |
|
1152 |
||
1153 |
||
1154 |
static const StringID _player_trains_tooltips[] = { |
|
1155 |
STR_018B_CLOSE_WINDOW, |
|
1156 |
STR_018C_WINDOW_TITLE_DRAG_THIS, |
|
1157 |
STR_883D_TRAINS_CLICK_ON_TRAIN_FOR, |
|
1158 |
STR_0190_SCROLL_BAR_SCROLLS_LIST, |
|
1159 |
STR_883E_BUILD_NEW_TRAINS_REQUIRES, |
|
1160 |
0, |
|
1161 |
}; |
|
1162 |
||
1163 |
static void PlayerTrainsWndProc(Window *w, WindowEvent *e) |
|
1164 |
{ |
|
1165 |
switch(e->event) { |
|
1166 |
case WE_PAINT: |
|
1167 |
/* determine amount of items for scroller */ |
|
1168 |
{ |
|
1169 |
Vehicle *v; |
|
1170 |
int num = 0; |
|
1171 |
byte owner = (byte)w->window_number; |
|
1172 |
||
1173 |
FOR_ALL_VEHICLES(v) { |
|
1174 |
if (v->type == VEH_Train && v->subtype == 0 && v->owner == owner) |
|
1175 |
num++; |
|
1176 |
} |
|
1177 |
||
1178 |
SetVScrollCount(w, num); |
|
1179 |
} |
|
1180 |
||
1181 |
/* draw the widgets */ |
|
1182 |
{ |
|
1183 |
Player *p = DEREF_PLAYER(w->window_number); |
|
1184 |
SET_DPARAM16(0, p->name_1); |
|
1185 |
SET_DPARAM32(1, p->name_2); |
|
1186 |
DrawWindowWidgets(w); |
|
1187 |
} |
|
1188 |
||
1189 |
/* draw the trains */ |
|
1190 |
{ |
|
1191 |
Vehicle *v; |
|
1192 |
int pos = w->vscroll.pos; |
|
1193 |
byte owner = (byte)w->window_number; |
|
1194 |
int x = 2; |
|
1195 |
int y = 15; |
|
1196 |
||
1197 |
FOR_ALL_VEHICLES(v) { |
|
1198 |
if (v->type == VEH_Train && v->subtype == 0 && v->owner == owner && |
|
1199 |
--pos < 0 && pos >= -7) { |
|
1200 |
StringID str; |
|
1201 |
||
1202 |
DrawTrainImage(v, x + 21, y + 6, 10, 0, INVALID_VEHICLE); |
|
1203 |
DrawVehicleProfitButton(v, x, y+13); |
|
1204 |
||
1205 |
SET_DPARAM16(0, v->unitnumber); |
|
1206 |
if (IsTrainDepotTile(v->tile)) { |
|
1207 |
str = STR_021F; |
|
1208 |
} else { |
|
1209 |
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; |
|
1210 |
} |
|
1211 |
DrawString(x, y+2, str, 0); |
|
1212 |
||
1213 |
SET_DPARAM32(0, v->profit_this_year); |
|
1214 |
SET_DPARAM32(1, v->profit_last_year); |
|
1215 |
DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
|
1216 |
||
1217 |
if (v->string_id != STR_SV_TRAIN_NAME) { |
|
1218 |
SET_DPARAM16(0, v->string_id); |
|
1219 |
DrawString(x+21, y, STR_01AB, 0); |
|
1220 |
} |
|
1221 |
||
1222 |
y += 26; |
|
1223 |
} |
|
1224 |
} |
|
1225 |
} |
|
1226 |
break; |
|
1227 |
||
1228 |
case WE_CLICK: { |
|
1229 |
switch(e->click.widget) { |
|
1230 |
case 2: { |
|
1231 |
int idx = (e->click.pt.y - 0xE) / 26; |
|
1232 |
Vehicle *v; |
|
1233 |
byte owner; |
|
1234 |
||
1235 |
if ((uint)idx >= 7) |
|
1236 |
break; |
|
1237 |
||
1238 |
idx += w->vscroll.pos; |
|
1239 |
||
1240 |
owner = (byte)w->window_number; |
|
1241 |
||
1242 |
FOR_ALL_VEHICLES(v) { |
|
1243 |
if (v->type == VEH_Train && v->subtype == 0 && v->owner == owner && |
|
1244 |
--idx < 0) { |
|
1245 |
ShowTrainViewWindow(v); |
|
1246 |
break; |
|
1247 |
} |
|
1248 |
} |
|
1249 |
} break; |
|
1250 |
||
1251 |
case 4: { |
|
1252 |
uint tile; |
|
1253 |
||
1254 |
tile = _last_built_train_depot_tile; |
|
1255 |
do { |
|
1256 |
if (_map_owner[tile] == _local_player && |
|
1257 |
IsTrainDepotTile(tile)) { |
|
1258 |
||
1259 |
ShowTrainDepotWindow(tile); |
|
1260 |
ShowBuildTrainWindow(tile); |
|
1261 |
return; |
|
1262 |
} |
|
1263 |
||
1264 |
tile = TILE_MASK(tile + 1); |
|
1265 |
} while(tile != _last_built_train_depot_tile); |
|
1266 |
||
1267 |
ShowBuildTrainWindow(0); |
|
1268 |
} break; |
|
1269 |
} |
|
1270 |
} break; |
|
1271 |
||
1272 |
} |
|
1273 |
} |
|
1274 |
||
1275 |
static const Widget _player_trains_widgets[] = { |
|
1276 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
1277 |
{ WWT_CAPTION, 14, 11, 324, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
1278 |
{ WWT_MATRIX, 14, 0, 313, 14, 195, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, |
|
1279 |
{ WWT_SCROLLBAR, 14, 314, 324, 14, 195, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
1280 |
{ WWT_PUSHTXTBTN, 14, 0, 161, 196, 207, STR_8815_NEW_VEHICLES, STR_883E_BUILD_NEW_TRAINS_REQUIRES}, |
|
1281 |
{ WWT_PANEL, 14, 162, 324, 196, 207, 0x0, 0}, |
|
1282 |
{ WWT_LAST}, |
|
1283 |
}; |
|
1284 |
||
1285 |
static const WindowDesc _player_trains_desc = { |
|
1286 |
-1, -1, 325, 208, |
|
1287 |
WC_TRAINS_LIST,0, |
|
1288 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
1289 |
_player_trains_widgets, |
|
1290 |
PlayerTrainsWndProc |
|
1291 |
}; |
|
1292 |
||
1293 |
static const Widget _other_player_trains_widgets[] = { |
|
1294 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
1295 |
{ WWT_CAPTION, 14, 11, 324, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
1296 |
{ WWT_MATRIX, 14, 0, 313, 14, 195, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, |
|
1297 |
{ WWT_SCROLLBAR, 14, 314, 324, 14, 195, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
1298 |
{ WWT_LAST}, |
|
1299 |
}; |
|
1300 |
||
1301 |
static const WindowDesc _other_player_trains_desc = { |
|
1302 |
-1, -1, 325, 196, |
|
1303 |
WC_TRAINS_LIST,0, |
|
1304 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
1305 |
_other_player_trains_widgets, |
|
1306 |
PlayerTrainsWndProc |
|
1307 |
}; |
|
1308 |
||
1309 |
void ShowPlayerTrains(int player) |
|
1310 |
{ |
|
1311 |
Window *w; |
|
1312 |
||
1313 |
if ( player == _local_player) { |
|
1314 |
w = AllocateWindowDescFront(&_player_trains_desc, player); |
|
1315 |
} else { |
|
1316 |
w = AllocateWindowDescFront(&_other_player_trains_desc, player); |
|
1317 |
} |
|
1318 |
if (w) { |
|
1319 |
w->caption_color = w->window_number; |
|
1320 |
w->vscroll.cap = 7; |
|
1321 |
} |
|
1322 |
} |