Files
@ r12911:f1cf8d886ea6
Branch filter:
Location: cpp/openttd-patchpack/source/src/train_gui.cpp - annotation
r12911:f1cf8d886ea6
9.2 KiB
text/x-c
(svn r17413) -Fix: assert when trying to build an invalid industry type it did
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 | r5584:545d748cc681 r5584:545d748cc681 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r6422:5983361e241a r5584:545d748cc681 r8107:82461791b7a2 r8224:194097dc7288 r8116:df67d3c5e4fd r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r8114:866ed489ed98 r8144:1432edd15267 r9070:e059c65164f3 r9297:6cd3e74fc38e r10960:e97ebf9cf99b r5584:545d748cc681 r8264:d493cb51fe8a r8264:d493cb51fe8a r8264:d493cb51fe8a r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r6422:5983361e241a r9344:f9f972b7b45d r12030:bf346482c342 r12030:bf346482c342 r12290:442d5d533a57 r12030:bf346482c342 r5584:545d748cc681 r12030:bf346482c342 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r6422:5983361e241a r5584:545d748cc681 r12450:fcc3ae606967 r6422:5983361e241a r10499:570896340d7a r9297:6cd3e74fc38e r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r11917:612c11f7ab47 r5584:545d748cc681 r5584:545d748cc681 r7653:8b8bc2df3a7d r5584:545d748cc681 r7486:610eee847f11 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12364:cbc66d4e5c75 r12364:cbc66d4e5c75 r12364:cbc66d4e5c75 r12364:cbc66d4e5c75 r12364:cbc66d4e5c75 r12364:cbc66d4e5c75 r12364:cbc66d4e5c75 r12364:cbc66d4e5c75 r12377:643da76b9d87 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12710:e1020cfc5c9b r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12377:643da76b9d87 r12378:e294ac78ad96 r12377:643da76b9d87 r12423:199e8b46a11b r12423:199e8b46a11b r12377:643da76b9d87 r12377:643da76b9d87 r12377:643da76b9d87 r12423:199e8b46a11b r12377:643da76b9d87 r5584:545d748cc681 r12378:e294ac78ad96 r12378:e294ac78ad96 r12377:643da76b9d87 r12377:643da76b9d87 r12377:643da76b9d87 r12377:643da76b9d87 r12378:e294ac78ad96 r12378:e294ac78ad96 r12377:643da76b9d87 r5584:545d748cc681 r5584:545d748cc681 r12377:643da76b9d87 r12377:643da76b9d87 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r9770:55a5aeabf960 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r5584:545d748cc681 r5584:545d748cc681 r11725:57bc99fdc1bc r5584:545d748cc681 r7010:fd8e3ec6f727 r5584:545d748cc681 r7010:fd8e3ec6f727 r7010:fd8e3ec6f727 r9413:fcf267325763 r11725:57bc99fdc1bc r5584:545d748cc681 r11765:7d9f5e4316b0 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r5584:545d748cc681 r5868:bc3e720ec5f7 r7059:0c2dc932a6ae r7002:201ff6832d3a r11767:eb8d525df68b r5584:545d748cc681 r7059:0c2dc932a6ae r5584:545d748cc681 r7002:201ff6832d3a r11767:eb8d525df68b r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r11709:0908d1040b1c r11709:0908d1040b1c r11765:7d9f5e4316b0 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r5584:545d748cc681 r7530:8eaeedf8b40c r5584:545d748cc681 r12069:84bc50fb033a r12253:9cc92893e2d0 r12253:9cc92893e2d0 r11917:612c11f7ab47 r7530:8eaeedf8b40c r7530:8eaeedf8b40c r7530:8eaeedf8b40c r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r6350:7a0fb15b3676 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12292:c3b6baef441a r12292:c3b6baef441a r7530:8eaeedf8b40c r5584:545d748cc681 r5584:545d748cc681 r7530:8eaeedf8b40c r7530:8eaeedf8b40c r5584:545d748cc681 r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r11443:81f75d8ddd0c r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r11443:81f75d8ddd0c r12292:c3b6baef441a r7530:8eaeedf8b40c r6422:5983361e241a r12069:84bc50fb033a r12292:c3b6baef441a r11443:81f75d8ddd0c r5584:545d748cc681 r7530:8eaeedf8b40c r12423:199e8b46a11b r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12423:199e8b46a11b r12423:199e8b46a11b r12379:f463555dd9bd r12592:01637fa5f463 r12423:199e8b46a11b r7492:75510449064b r12292:c3b6baef441a r5584:545d748cc681 r12423:199e8b46a11b r8850:e9956f61a4e6 r5584:545d748cc681 r5584:545d748cc681 r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r6422:5983361e241a r12292:c3b6baef441a r11443:81f75d8ddd0c r5584:545d748cc681 r5584:545d748cc681 r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r12069:84bc50fb033a r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r6422:5983361e241a r5584:545d748cc681 r7492:75510449064b r12292:c3b6baef441a r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12251:58d0d73149cb r12251:58d0d73149cb r12253:9cc92893e2d0 r7530:8eaeedf8b40c r7530:8eaeedf8b40c r7530:8eaeedf8b40c r7530:8eaeedf8b40c r9943:38700f276db2 r7530:8eaeedf8b40c r7530:8eaeedf8b40c r6422:5983361e241a r12622:202e83a6cee7 r6350:7a0fb15b3676 r7530:8eaeedf8b40c r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r9413:fcf267325763 r12622:202e83a6cee7 r5584:545d748cc681 r5584:545d748cc681 r9943:38700f276db2 r12622:202e83a6cee7 r5584:545d748cc681 r5584:545d748cc681 | /* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file train_gui.cpp GUI for trains. */
#include "stdafx.h"
#include "window_gui.h"
#include "gfx_func.h"
#include "command_func.h"
#include "vehicle_gui.h"
#include "train.h"
#include "newgrf_engine.h"
#include "strings_func.h"
#include "vehicle_func.h"
#include "engine_base.h"
#include "window_func.h"
#include "settings_type.h"
#include "table/sprites.h"
#include "table/strings.h"
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
{
if (!success) return;
/* find a locomotive in the depot. */
const Vehicle *found = NULL;
const Train *t;
FOR_ALL_TRAINS(t) {
if (t->IsFrontEngine() && t->tile == tile &&
t->track == TRACK_BIT_DEPOT) {
if (found != NULL) return; // must be exactly one.
found = t;
}
}
/* if we found a loco, */
if (found != NULL) {
found = found->Last();
/* put the new wagon at the end of the loco. */
DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, CMD_MOVE_RAIL_VEHICLE);
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
}
}
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
{
if (!success) return;
const Vehicle *v = Vehicle::Get(_new_vehicle_id);
if (tile == _backup_orders_tile) {
_backup_orders_tile = 0;
RestoreVehicleOrders(v);
}
ShowVehicleViewWindow(v);
}
/**
* Draws an image of a whole train
* @param v Front vehicle
+ @param x x Position to start at
* @param y y Position to draw at
* @param seletion Selected vehicle to draw a frame around
* @param max_width Number of pixels space for drawing
* @param skip Number of pixels to skip at the front (for scrolling)
*/
void DrawTrainImage(const Train *v, int x, int y, VehicleID selection, int max_width, int skip)
{
DrawPixelInfo tmp_dpi, *old_dpi;
/* Position of highlight box */
int highlight_l = 0;
int highlight_r = 0;
if (!FillDrawPixelInfo(&tmp_dpi, x, y, max_width, 14)) return;
old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
int px = -skip;
bool sel_articulated = false;
for (; v != NULL && px < max_width; v = v->Next()) {
Point offset;
int width = Train::From(v)->GetDisplayImageWidth(&offset);
if (px + width > 0) {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(v->GetImage(DIR_W), pal, px + offset.x, 7 + offset.y);
}
if (!v->IsArticulatedPart()) sel_articulated = false;
if (v->index == selection) {
/* Set the highlight position */
highlight_l = px + 1;
highlight_r = px + width + 1;
sel_articulated = true;
} else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) {
highlight_r += width;
}
px += width;
}
if (highlight_l != highlight_r) {
/* Draw the highlight. Now done after drawing all the engines, as
* the next engine after the highlight could overlap it. */
DrawFrameRect(highlight_l, 0, highlight_r, 13, COLOUR_WHITE, FR_BORDERONLY);
}
_cur_dpi = old_dpi;
}
/**
* Draw the details cargo tab for the given vehicle at the given position
*
* @param v current vehicle
* @param left The left most coordinate to draw
* @param right The right most coordinate to draw
* @param y The y coordinate
*/
static void TrainDetailsCargoTab(const Vehicle *v, int left, int right, int y)
{
if (v->cargo_cap != 0) {
StringID str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
if (!v->cargo.Empty()) {
SetDParam(0, v->cargo_type);
SetDParam(1, v->cargo.Count());
SetDParam(2, v->cargo.Source());
SetDParam(3, _settings_game.vehicle.freight_trains);
str = FreightWagonMult(v->cargo_type) > 1 ? STR_VEHICLE_DETAILS_CARGO_FROM_MULT : STR_VEHICLE_DETAILS_CARGO_FROM;
}
DrawString(left, right, y, str);
}
}
/**
* Draw the details info tab for the given vehicle at the given position
*
* @param v current vehicle
* @param left The left most coordinate to draw
* @param right The right most coordinate to draw
* @param y The y coordinate
*/
static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
{
if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) {
SetDParam(0, v->engine_type);
SetDParam(1, v->value);
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
} else {
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
}
}
/**
* Draw the details capacity tab for the given vehicle at the given position
*
* @param v current vehicle
* @param left The left most coordinate to draw
* @param right The right most coordinate to draw
* @param y The y coordinate
*/
static void TrainDetailsCapacityTab(const Vehicle *v, int left, int right, int y)
{
if (v->cargo_cap != 0) {
SetDParam(0, v->cargo_type);
SetDParam(1, v->cargo_cap);
SetDParam(4, GetCargoSubtypeText(v));
SetDParam(5, _settings_game.vehicle.freight_trains);
DrawString(left, right, y, FreightWagonMult(v->cargo_type) > 1 ? STR_VEHICLE_INFO_CAPACITY_MULT : STR_VEHICLE_INFO_CAPACITY);
}
}
/**
* Determines the number of lines in the train details window
* @param veh_id Train
* @param det_tab Selected details tab
* @return Number of line
*/
int GetTrainDetailsWndVScroll(VehicleID veh_id, TrainDetailsWindowTabs det_tab)
{
int num = 0;
if (det_tab == TDW_TAB_TOTALS) { // Total cargo tab
CargoArray act_cargo;
CargoArray max_cargo;
for (const Vehicle *v = Vehicle::Get(veh_id) ; v != NULL ; v = v->Next()) {
act_cargo[v->cargo_type] += v->cargo.Count();
max_cargo[v->cargo_type] += v->cargo_cap;
}
/* Set scroll-amount seperately from counting, as to not compute num double
* for more carriages of the same type
*/
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (max_cargo[i] > 0) num++; // only count carriages that the train has
}
num++; // needs one more because first line is description string
} else {
for (const Train *v = Train::Get(veh_id) ; v != NULL ; v = v->Next()) {
if (!v->IsArticulatedPart() || v->cargo_cap != 0) num++;
}
}
return num;
}
/**
* Draw the details for the given vehicle at the given position
*
* @param v current vehicle
* @param left The left most coordinate to draw
* @param right The right most coordinate to draw
* @param y The y coordinate
* @param vscroll_pos Position of scrollbar
* @param vscroll_cap Number of lines currently displayed
* @param det_tab Selected details tab
*/
void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
{
/* draw the first 3 details tabs */
if (det_tab != TDW_TAB_TOTALS) {
const Train *u = v;
int x = 1;
for (;;) {
if (--vscroll_pos < 0 && vscroll_pos >= -vscroll_cap) {
int px = x;
u = v;
do {
Point offset;
int width = u->GetDisplayImageWidth(&offset);
SpriteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
DrawSprite(u->GetImage(DIR_W), pal, px + offset.x, y + 6 + offset.y);
px += width;
u = u->Next();
} while (u != NULL && u->IsArticulatedPart() && u->cargo_cap == 0);
px += 2;
int py = y + 2;
switch (det_tab) {
default: NOT_REACHED();
case TDW_TAB_CARGO:
TrainDetailsCargoTab(v, px, right, py);
break;
case TDW_TAB_INFO:
/* Only show name and value for the 'real' part */
if (!v->IsArticulatedPart()) {
TrainDetailsInfoTab(v, px, right, py);
}
break;
case TDW_TAB_CAPACITY:
TrainDetailsCapacityTab(v, px, right, py);
break;
}
y += 14;
v = u;
} else {
/* Move to the next line */
do {
v = v->Next();
} while (v != NULL && v->IsArticulatedPart() && v->cargo_cap == 0);
}
if (v == NULL) return;
}
} else {
CargoArray act_cargo;
CargoArray max_cargo;
Money feeder_share = 0;
for (const Vehicle *u = v; u != NULL ; u = u->Next()) {
act_cargo[u->cargo_type] += u->cargo.Count();
max_cargo[u->cargo_type] += u->cargo_cap;
feeder_share += u->cargo.FeederShare();
}
/* draw total cargo tab */
DrawString(left, right, y + 2, STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_TEXT);
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) {
y += 14;
SetDParam(0, i); // {CARGO} #1
SetDParam(1, act_cargo[i]); // {CARGO} #2
SetDParam(2, i); // {SHORTCARGO} #1
SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2
SetDParam(4, _settings_game.vehicle.freight_trains);
DrawString(left, right, y + 2, FreightWagonMult(i) > 1 ? STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY_MULT : STR_VEHICLE_DETAILS_TRAIN_TOTAL_CAPACITY);
}
}
SetDParam(0, feeder_share);
DrawString(left, right, y + 15, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
}
}
|