author | rubidium |
Wed, 07 May 2008 21:09:51 +0000 | |
branch | noai |
changeset 10455 | 22c441f5adf9 |
parent 10249 | 58810805030e |
child 10645 | 8cbdb511a674 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
3 |
/** @file train_gui.cpp GUI for trains. */ |
9574 | 4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1820
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1294
diff
changeset
|
7 |
#include "debug.h" |
0 | 8 |
#include "gui.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
9 |
#include "window_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
10 |
#include "gfx_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
11 |
#include "command_func.h" |
588 | 12 |
#include "vehicle_gui.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2639
diff
changeset
|
13 |
#include "train.h" |
2962
dbd168a4703a
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2959
diff
changeset
|
14 |
#include "newgrf_engine.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
15 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
16 |
#include "vehicle_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "settings_type.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9724
diff
changeset
|
18 |
#include "order_func.h" |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9724
diff
changeset
|
19 |
#include "engine_func.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
10249
diff
changeset
|
20 |
#include "engine_base.h" |
0 | 21 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
22 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
23 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
24 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
25 |
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 26 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4049
diff
changeset
|
27 |
if (!success) return; |
0 | 28 |
|
9574 | 29 |
/* find a locomotive in the depot. */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
30 |
Vehicle *found = NULL; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
31 |
Vehicle *v; |
0 | 32 |
FOR_ALL_VEHICLES(v) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6524
diff
changeset
|
33 |
if (v->type == VEH_TRAIN && IsFrontEngine(v) && |
0 | 34 |
v->tile == tile && |
6319
27e68b914d3d
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents:
6144
diff
changeset
|
35 |
v->u.rail.track == TRACK_BIT_DEPOT) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4049
diff
changeset
|
36 |
if (found != NULL) return; // must be exactly one. |
0 | 37 |
found = v; |
38 |
} |
|
39 |
} |
|
40 |
||
9574 | 41 |
/* if we found a loco, */ |
0 | 42 |
if (found != NULL) { |
43 |
found = GetLastVehicleInChain(found); |
|
9574 | 44 |
/* put the new wagon at the end of the loco. */ |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3919
diff
changeset
|
45 |
DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, NULL, CMD_MOVE_RAIL_VEHICLE); |
588 | 46 |
RebuildVehicleLists(); |
0 | 47 |
} |
48 |
} |
|
49 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
50 |
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 51 |
{ |
2639 | 52 |
if (!success) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
53 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
54 |
const Vehicle *v = GetVehicle(_new_vehicle_id); |
0 | 55 |
if (tile == _backup_orders_tile) { |
56 |
_backup_orders_tile = 0; |
|
9704 | 57 |
RestoreVehicleOrders(v); |
0 | 58 |
} |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
59 |
ShowVehicleViewWindow(v); |
2244 | 60 |
} |
5187
d1f4e447a7eb
(svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents:
5163
diff
changeset
|
61 |
|
2593
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
62 |
/** |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
63 |
* Get the number of pixels for the given wagon length. |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
64 |
* @param len Length measured in 1/8ths of a standard wagon. |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
65 |
* @return Number of pixels across. |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
66 |
*/ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
67 |
int WagonLengthToPixels(int len) |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9686
diff
changeset
|
68 |
{ |
3845
c3cd4b825c2f
(svn r4869) - NewGRF: support setting train list vehicle width to 32 instead of 29 pixels, for sets which use 32 pixel long engines/wagons.
peter1138
parents:
3844
diff
changeset
|
69 |
return (len * _traininfo_vehicle_width) / 8; |
2593
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
70 |
} |
a9f7d3d70639
(svn r3130) Calculate shorter wagon lengths more precisely in train depot window. This affects wagon position, the scroll bar, and the train length counter. No trial and error is required to get the correct length now.
peter1138
parents:
2570
diff
changeset
|
71 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
72 |
void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int count, int skip) |
0 | 73 |
{ |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
74 |
DrawPixelInfo tmp_dpi, *old_dpi; |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
75 |
int dx = -(skip * 8) / _traininfo_vehicle_width; |
4049
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
76 |
/* Position of highlight box */ |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
77 |
int highlight_l = 0; |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
78 |
int highlight_r = 0; |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
79 |
|
4429
1bb01569940c
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4426
diff
changeset
|
80 |
if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, count + 1, 14)) return; |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
81 |
|
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
82 |
count = (count * 8) / _traininfo_vehicle_width; |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
83 |
|
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
84 |
old_dpi = _cur_dpi; |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
85 |
_cur_dpi = &tmp_dpi; |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
86 |
|
0 | 87 |
do { |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
88 |
int width = v->u.rail.cached_veh_length; |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
89 |
|
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
90 |
if (dx + width > 0) { |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
91 |
if (dx <= count) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5852
diff
changeset
|
92 |
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
93 |
DrawSprite(v->GetImage(DIR_W), pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); |
4049
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
94 |
if (v->index == selection) { |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
95 |
/* Set the highlight position */ |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
96 |
highlight_l = WagonLengthToPixels(dx) + 1; |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
97 |
highlight_r = WagonLengthToPixels(dx + width) + 1; |
9869
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
98 |
} else if (_cursor.vehchain && highlight_r != 0) { |
6404afe43575
(svn r12597) [NoAI] -Sync: with trunk r12501:12596.
rubidium
parents:
9837
diff
changeset
|
99 |
highlight_r += WagonLengthToPixels(width); |
4049
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
100 |
} |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1908
diff
changeset
|
101 |
} |
0 | 102 |
} |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
103 |
dx += width; |
0 | 104 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
105 |
v = v->Next(); |
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
106 |
} while (dx < count && v != NULL); |
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
107 |
|
4049
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
108 |
if (highlight_l != highlight_r) { |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
109 |
/* Draw the highlight. Now done after drawing all the engines, as |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
110 |
* the next engine after the highlight could overlap it. */ |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
111 |
DrawFrameRect(highlight_l, 0, highlight_r, 13, 15, FR_BORDERONLY); |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
112 |
} |
dd384acac472
(svn r5318) - Allow room for a single pixel overflow on the first engine when drawing a train's image.
peter1138
parents:
4041
diff
changeset
|
113 |
|
3919
1ba6c2e9b46d
(svn r5046) - Implement smooth horizontal depot scrolling by setting up a clipping area to draw the train image. This fixes a couple of usability issues when shorter wagons are used in the depot; shorter wagons scrolled at a different speed, and not all wagons were visible sometimes.
peter1138
parents:
3887
diff
changeset
|
114 |
_cur_dpi = old_dpi; |
0 | 115 |
} |
116 |
||
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
117 |
static void TrainDetailsCargoTab(const Vehicle *v, int x, int y) |
0 | 118 |
{ |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
119 |
if (v->cargo_cap != 0) { |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
120 |
StringID str = STR_8812_EMPTY; |
0 | 121 |
|
9629 | 122 |
if (!v->cargo.Empty()) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
123 |
SetDParam(0, v->cargo_type); |
9629 | 124 |
SetDParam(1, v->cargo.Count()); |
125 |
SetDParam(2, v->cargo.Source()); |
|
5163
83acad83bbdd
(svn r7269) -Feature: Add freight trains patch option. This option is a multiplier for the weight of cargo on freight trains, to simulate longer heavier trains. The default value of 1 behaves as before.
peter1138
parents:
5124
diff
changeset
|
126 |
SetDParam(3, _patches.freight_trains); |
5316
b04421921eae
(svn r7473) -Fix (r7269): Pass a cargo type to determine the freight weight
peter1138
parents:
5273
diff
changeset
|
127 |
str = FreightWagonMult(v->cargo_type) > 1 ? STR_FROM_MULT : STR_8813_FROM; |
0 | 128 |
} |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9704
diff
changeset
|
129 |
DrawString(x, y, str, TC_FROMSTRING); |
0 | 130 |
} |
131 |
} |
|
132 |
||
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
133 |
static void TrainDetailsInfoTab(const Vehicle *v, int x, int y) |
0 | 134 |
{ |
6119
b47985557d1e
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents:
6075
diff
changeset
|
135 |
if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) { |
9629 | 136 |
SetDParam(0, v->engine_type); |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
137 |
SetDParam(1, v->value); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9704
diff
changeset
|
138 |
DrawString(x, y, STR_882D_VALUE, TC_BLACK); |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
139 |
} else { |
9629 | 140 |
SetDParam(0, v->engine_type); |
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4299
diff
changeset
|
141 |
SetDParam(1, v->build_year); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
142 |
SetDParam(2, v->value); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9704
diff
changeset
|
143 |
DrawString(x, y, STR_882C_BUILT_VALUE, TC_BLACK); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
144 |
} |
0 | 145 |
} |
146 |
||
1790
4afb4b4e4278
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1658
diff
changeset
|
147 |
static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y) |
0 | 148 |
{ |
149 |
if (v->cargo_cap != 0) { |
|
4896
72d7a8614580
(svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents:
4871
diff
changeset
|
150 |
SetDParam(0, v->cargo_type); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
524
diff
changeset
|
151 |
SetDParam(1, v->cargo_cap); |
5163
83acad83bbdd
(svn r7269) -Feature: Add freight trains patch option. This option is a multiplier for the weight of cargo on freight trains, to simulate longer heavier trains. The default value of 1 behaves as before.
peter1138
parents:
5124
diff
changeset
|
152 |
SetDParam(2, _patches.freight_trains); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9704
diff
changeset
|
153 |
DrawString(x, y, FreightWagonMult(v->cargo_type) > 1 ? STR_CAPACITY_MULT : STR_013F_CAPACITY, TC_FROMSTRING); |
0 | 154 |
} |
155 |
} |
|
156 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
157 |
int GetTrainDetailsWndVScroll(VehicleID veh_id, byte det_tab) |
0 | 158 |
{ |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
159 |
AcceptedCargo act_cargo; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
160 |
AcceptedCargo max_cargo; |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
161 |
int num = 0; |
0 | 162 |
|
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
163 |
if (det_tab == 3) { // Total cargo tab |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
164 |
memset(max_cargo, 0, sizeof(max_cargo)); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
165 |
memset(act_cargo, 0, sizeof(act_cargo)); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
166 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
167 |
for (const Vehicle *v = GetVehicle(veh_id) ; v != NULL ; v = v->Next()) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
168 |
act_cargo[v->cargo_type] += v->cargo.Count(); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
169 |
max_cargo[v->cargo_type] += v->cargo_cap; |
0 | 170 |
} |
171 |
||
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
172 |
/* Set scroll-amount seperately from counting, as to not compute num double |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
173 |
* for more carriages of the same type |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
174 |
*/ |
9505 | 175 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
176 |
if (max_cargo[i] > 0) num++; // only count carriages that the train has |
0 | 177 |
} |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4429
diff
changeset
|
178 |
num++; // needs one more because first line is description string |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
179 |
} else { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
180 |
for (const Vehicle *v = GetVehicle(veh_id) ; v != NULL ; v = v->Next()) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
181 |
if (!IsArticulatedPart(v) || v->cargo_cap != 0) num++; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
182 |
} |
0 | 183 |
} |
184 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
185 |
return num; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
186 |
} |
0 | 187 |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
188 |
void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab) |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
189 |
{ |
9574 | 190 |
/* draw the first 3 details tabs */ |
0 | 191 |
if (det_tab != 3) { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
192 |
const Vehicle *u = v; |
2822
ff15d6f947ed
(svn r3370) Improve alignment of text within total cargo tab of train view window
peter1138
parents:
2819
diff
changeset
|
193 |
x = 1; |
2952 | 194 |
for (;;) { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
195 |
if (--vscroll_pos < 0 && vscroll_pos >= -vscroll_cap) { |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
196 |
int dx = 0; |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
197 |
|
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
198 |
u = v; |
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
199 |
do { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5852
diff
changeset
|
200 |
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
9631
8a2d1c2ceb88
(svn r10461) [NoAI] -Sync with trunk r10349:r10460.
rubidium
parents:
9629
diff
changeset
|
201 |
DrawSprite(u->GetImage(DIR_W), pal, x + WagonLengthToPixels(4 + dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2593
diff
changeset
|
202 |
dx += u->u.rail.cached_veh_length; |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
203 |
u = u->Next(); |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
204 |
} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0); |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
205 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
206 |
int px = x + WagonLengthToPixels(dx) + 2; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9869
diff
changeset
|
207 |
int py = y + 2; |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
208 |
switch (det_tab) { |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
209 |
default: NOT_REACHED(); |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
210 |
case 0: TrainDetailsCargoTab( v, px, py); break; |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
211 |
case 1: |
9574 | 212 |
/* Only show name and value for the 'real' part */ |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
213 |
if (!IsArticulatedPart(v)) { |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
214 |
TrainDetailsInfoTab(v, px, py); |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
215 |
} |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
216 |
break; |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
217 |
case 2: TrainDetailsCapacityTab(v, px, py); break; |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
218 |
} |
0 | 219 |
y += 14; |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
220 |
|
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
221 |
v = u; |
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
222 |
} else { |
9574 | 223 |
/* Move to the next line */ |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
224 |
do { |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
225 |
v = v->Next(); |
4868
e9478d949505
(svn r6794) - Fix: In the train detail window, split up articulated parts if they can contain cargo. This allows us to show the full cargo contents.
peter1138
parents:
4836
diff
changeset
|
226 |
} while (v != NULL && IsArticulatedPart(v) && v->cargo_cap == 0); |
0 | 227 |
} |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
228 |
if (v == NULL) return; |
0 | 229 |
} |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
230 |
} else { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
231 |
AcceptedCargo act_cargo; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
232 |
AcceptedCargo max_cargo; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
233 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
234 |
memset(max_cargo, 0, sizeof(max_cargo)); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
235 |
memset(act_cargo, 0, sizeof(act_cargo)); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
236 |
|
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
237 |
for (const Vehicle *u = v; u != NULL ; u = u->Next()) { |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
238 |
act_cargo[u->cargo_type] += u->cargo.Count(); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
239 |
max_cargo[u->cargo_type] += u->cargo_cap; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
240 |
} |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
241 |
|
9574 | 242 |
/* draw total cargo tab */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
243 |
DrawString(x, y + 2, STR_TOTAL_CAPACITY_TEXT, TC_FROMSTRING); |
9505 | 244 |
for (CargoID i = 0; i < NUM_CARGO; i++) { |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9701
diff
changeset
|
245 |
if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) { |
0 | 246 |
y += 14; |
4492
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
247 |
SetDParam(0, i); // {CARGO} #1 |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
248 |
SetDParam(1, act_cargo[i]); // {CARGO} #2 |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
249 |
SetDParam(2, i); // {SHORTCARGO} #1 |
f73138c71092
(svn r6277) Clean up the train details drawing routine
tron
parents:
4456
diff
changeset
|
250 |
SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2 |
5163
83acad83bbdd
(svn r7269) -Feature: Add freight trains patch option. This option is a multiplier for the weight of cargo on freight trains, to simulate longer heavier trains. The default value of 1 behaves as before.
peter1138
parents:
5124
diff
changeset
|
251 |
SetDParam(4, _patches.freight_trains); |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
252 |
DrawString(x, y + 2, FreightWagonMult(i) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_TOTAL_CAPACITY, TC_FROMSTRING); |
0 | 253 |
} |
2959
940962dab788
(svn r3521) - Feature: Allow trains details view to be resized.
peter1138
parents:
2958
diff
changeset
|
254 |
} |
9629 | 255 |
SetDParam(0, v->cargo.FeederShare()); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9704
diff
changeset
|
256 |
DrawString(x, y + 15, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); |
0 | 257 |
} |
258 |
} |