src/train_gui.cpp
branchNewGRF_ports
changeset 10184 fcf5fb2548eb
parent 6877 889301acc299
child 10242 52b4a9006029
equal deleted inserted replaced
10179:eec5a7dcbf61 10184:fcf5fb2548eb
    14 #include "train.h"
    14 #include "train.h"
    15 #include "newgrf_engine.h"
    15 #include "newgrf_engine.h"
    16 #include "strings_func.h"
    16 #include "strings_func.h"
    17 #include "vehicle_func.h"
    17 #include "vehicle_func.h"
    18 #include "settings_type.h"
    18 #include "settings_type.h"
       
    19 #include "order_func.h"
       
    20 #include "engine_func.h"
    19 
    21 
    20 #include "table/sprites.h"
    22 #include "table/sprites.h"
    21 #include "table/strings.h"
    23 #include "table/strings.h"
    22 
    24 
    23 void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
    25 void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
    24 {
    26 {
    25 	Vehicle *v, *found;
       
    26 
       
    27 	if (!success) return;
    27 	if (!success) return;
    28 
    28 
    29 	/* find a locomotive in the depot. */
    29 	/* find a locomotive in the depot. */
    30 	found = NULL;
    30 	Vehicle *found = NULL;
       
    31 	Vehicle *v;
    31 	FOR_ALL_VEHICLES(v) {
    32 	FOR_ALL_VEHICLES(v) {
    32 		if (v->type == VEH_TRAIN && IsFrontEngine(v) &&
    33 		if (v->type == VEH_TRAIN && IsFrontEngine(v) &&
    33 				v->tile == tile &&
    34 				v->tile == tile &&
    34 				v->u.rail.track == TRACK_BIT_DEPOT) {
    35 				v->u.rail.track == TRACK_BIT_DEPOT) {
    35 			if (found != NULL) return; // must be exactly one.
    36 			if (found != NULL) return; // must be exactly one.
    46 	}
    47 	}
    47 }
    48 }
    48 
    49 
    49 void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
    50 void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
    50 {
    51 {
    51 	const Vehicle *v;
       
    52 
       
    53 	if (!success) return;
    52 	if (!success) return;
    54 
    53 
    55 	v = GetVehicle(_new_vehicle_id);
    54 	const Vehicle *v = GetVehicle(_new_vehicle_id);
    56 	if (tile == _backup_orders_tile) {
    55 	if (tile == _backup_orders_tile) {
    57 		_backup_orders_tile = 0;
    56 		_backup_orders_tile = 0;
    58 		RestoreVehicleOrders(v);
    57 		RestoreVehicleOrders(v);
    59 	}
    58 	}
    60 	ShowVehicleViewWindow(v);
    59 	ShowVehicleViewWindow(v);
    94 				DrawSprite(v->GetImage(DIR_W), pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
    93 				DrawSprite(v->GetImage(DIR_W), pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
    95 				if (v->index == selection) {
    94 				if (v->index == selection) {
    96 					/* Set the highlight position */
    95 					/* Set the highlight position */
    97 					highlight_l = WagonLengthToPixels(dx) + 1;
    96 					highlight_l = WagonLengthToPixels(dx) + 1;
    98 					highlight_r = WagonLengthToPixels(dx + width) + 1;
    97 					highlight_r = WagonLengthToPixels(dx + width) + 1;
       
    98 				} else if (_cursor.vehchain && highlight_r != 0) {
       
    99 					highlight_r += WagonLengthToPixels(width);
    99 				}
   100 				}
   100 			}
   101 			}
   101 		}
   102 		}
   102 		dx += width;
   103 		dx += width;
   103 
   104 
   191 		const Vehicle *u = v;
   192 		const Vehicle *u = v;
   192 		x = 1;
   193 		x = 1;
   193 		for (;;) {
   194 		for (;;) {
   194 			if (--vscroll_pos < 0 && vscroll_pos >= -vscroll_cap) {
   195 			if (--vscroll_pos < 0 && vscroll_pos >= -vscroll_cap) {
   195 				int dx = 0;
   196 				int dx = 0;
   196 				int px;
       
   197 				int py;
       
   198 
   197 
   199 				u = v;
   198 				u = v;
   200 				do {
   199 				do {
   201 					SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
   200 					SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
   202 					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));
   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));
   203 					dx += u->u.rail.cached_veh_length;
   202 					dx += u->u.rail.cached_veh_length;
   204 					u = u->Next();
   203 					u = u->Next();
   205 				} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
   204 				} while (u != NULL && IsArticulatedPart(u) && u->cargo_cap == 0);
   206 
   205 
   207 				px = x + WagonLengthToPixels(dx) + 2;
   206 				int px = x + WagonLengthToPixels(dx) + 2;
   208 				py = y + 2;
   207 				int py = y + 2;
   209 				switch (det_tab) {
   208 				switch (det_tab) {
   210 					default: NOT_REACHED();
   209 					default: NOT_REACHED();
   211 					case 0: TrainDetailsCargoTab(   v, px, py); break;
   210 					case 0: TrainDetailsCargoTab(   v, px, py); break;
   212 					case 1:
   211 					case 1:
   213 						/* Only show name and value for the 'real' part */
   212 						/* Only show name and value for the 'real' part */