truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" truelight@0: truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "gfx.h" truelight@0: #include "vehicle.h" truelight@0: #include "viewport.h" truelight@0: #include "station.h" truelight@0: #include "command.h" truelight@0: #include "player.h" truelight@0: //#include "town.h" truelight@0: #include "engine.h" truelight@0: truelight@0: static Engine * const _rail_engines[3] = { truelight@0: &_engines[0], truelight@0: &_engines[NUM_NORMAL_RAIL_ENGINES], truelight@0: &_engines[NUM_MONORAIL_ENGINES + NUM_NORMAL_RAIL_ENGINES], truelight@0: }; truelight@0: truelight@0: const byte _rail_engines_count[3] = { truelight@0: NUM_NORMAL_RAIL_ENGINES, truelight@0: NUM_MONORAIL_ENGINES, truelight@0: NUM_MAGLEV_ENGINES, truelight@0: }; truelight@0: truelight@0: const byte _rail_engines_start[3] = { truelight@0: 0, truelight@0: NUM_NORMAL_RAIL_ENGINES, truelight@0: NUM_MONORAIL_ENGINES + NUM_NORMAL_RAIL_ENGINES, truelight@0: }; truelight@0: truelight@0: static void CcBuildWagon(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: Vehicle *v,*found; truelight@0: truelight@0: if (!success) truelight@0: return; truelight@0: truelight@0: // find a locomotive in the depot. truelight@0: found = NULL; truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && v->subtype==0 && truelight@0: v->tile == tile && truelight@0: v->u.rail.track == 0x80) { truelight@0: if (found != NULL) // must be exactly one. truelight@0: return; truelight@0: found = v; truelight@0: } truelight@0: } truelight@0: truelight@0: // if we found a loco, truelight@0: if (found != NULL) { truelight@0: found = GetLastVehicleInChain(found); truelight@0: // put the new wagon at the end of the loco. truelight@0: DoCommandP(0, _new_wagon_id | (found->index<<16), 0, NULL, CMD_MOVE_RAIL_VEHICLE); truelight@0: } truelight@0: } truelight@0: truelight@0: static void CcBuildLoco(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: Vehicle *v; truelight@0: truelight@0: if (!success) truelight@0: return; truelight@0: truelight@0: v = &_vehicles[_new_train_id]; truelight@0: if (tile == _backup_orders_tile) { truelight@0: _backup_orders_tile = 0; truelight@0: RestoreVehicleOrders(v, _backup_orders_data); truelight@0: } truelight@0: ShowTrainViewWindow(v); truelight@0: } truelight@0: truelight@0: static void NewRailVehicleWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: truelight@0: if (w->window_number == 0) truelight@0: SETBIT(w->disabled_state, 5); truelight@0: truelight@0: { truelight@0: int count = 0; truelight@0: int num = _rail_engines_count[WP(w,buildtrain_d).railtype]; truelight@0: Engine *e = _rail_engines[WP(w,buildtrain_d).railtype]; truelight@0: do { truelight@0: if (HASBIT(e->player_avail, _local_player)) truelight@0: count++; truelight@0: } while (++e,--num); truelight@0: SetVScrollCount(w, count); truelight@0: } truelight@0: truelight@0: SET_DPARAM16(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: { truelight@0: int num = _rail_engines_count[WP(w,buildtrain_d).railtype]; truelight@0: Engine *e = _rail_engines[WP(w,buildtrain_d).railtype]; truelight@0: int sel = WP(w,buildtrain_d).sel_index; truelight@0: int pos = w->vscroll.pos; truelight@0: int x = 1; truelight@0: int y = 15; truelight@0: int engine_id = _rail_engines_start[WP(w,buildtrain_d).railtype]; truelight@0: int selected_id = -1; truelight@0: truelight@0: do { truelight@0: if (HASBIT(e->player_avail, _local_player)) { truelight@0: if (sel==0) selected_id = engine_id; truelight@0: if (IS_INT_INSIDE(--pos, -8, 0)) { truelight@0: DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10); truelight@0: DrawTrainEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player))); truelight@0: y += 14; truelight@0: } truelight@0: sel--; truelight@0: } truelight@0: } while (++engine_id, ++e,--num); truelight@0: truelight@0: WP(w,buildtrain_d).sel_engine = selected_id; truelight@0: truelight@0: if (selected_id != -1) { truelight@0: const RailVehicleInfo *rvi = &_rail_vehicle_info[selected_id]; truelight@0: Engine *e; truelight@0: YearMonthDay ymd; truelight@0: truelight@0: if (!(rvi->flags & RVI_WAGON)) { truelight@0: /* it's an engine */ truelight@0: int multihead = (rvi->flags&RVI_MULTIHEAD?1:0); truelight@0: truelight@0: SET_DPARAM32(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5); truelight@0: SET_DPARAM16(2, rvi->max_speed * 10 >> 4); truelight@0: SET_DPARAM16(3, rvi->power << multihead); truelight@0: SET_DPARAM16(1, rvi->weight << multihead); truelight@0: SET_DPARAM32(4, (rvi->running_cost_base * _price.running_rail[rvi->engclass] >> 8) << multihead); truelight@0: truelight@0: SET_DPARAM16(5, STR_8838_N_A); truelight@0: if (rvi->capacity != 0) { truelight@0: SET_DPARAM16(6, rvi->capacity << multihead); truelight@0: SET_DPARAM16(5, _cargoc.names_long_p[rvi->cargo_type]); truelight@0: } truelight@0: truelight@0: e = &_engines[selected_id]; truelight@0: truelight@0: SET_DPARAM16(8, e->lifelength); truelight@0: SET_DPARAM8(9, e->reliability * 100 >> 16); truelight@0: ConvertDayToYMD(&ymd, e->intro_date); truelight@0: SET_DPARAM16(7, ymd.year + 1920); truelight@0: truelight@0: DrawString(2, 0x7F, STR_8817_COST_WEIGHT_T_SPEED_POWER, 0); truelight@0: } else { truelight@0: /* it's a wagon */ truelight@0: truelight@0: SET_DPARAM32(0, truelight@0: DoCommandByTile(w->window_number, selected_id, 0, DC_QUERY_COST, CMD_BUILD_RAIL_VEHICLE) truelight@0: ); truelight@0: SET_DPARAM16(4, rvi->capacity); truelight@0: SET_DPARAM16(1, rvi->weight); truelight@0: SET_DPARAM16(3, _cargoc.names_long_p[rvi->cargo_type]); truelight@0: SET_DPARAM16(2, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight); truelight@0: DrawString(2, 0x7F, STR_8821_COST_WEIGHT_T_T_CAPACITY, 0); truelight@0: } truelight@0: } truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@0: case 2: { truelight@0: uint i = (e->click.pt.y - 14) / 14; truelight@0: if (i < 8) { truelight@0: WP(w,buildtrain_d).sel_index = i + w->vscroll.pos; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } break; truelight@0: case 5: { truelight@0: int sel_eng; truelight@0: sel_eng = WP(w,buildtrain_d).sel_engine; truelight@0: if (sel_eng != -1) truelight@0: 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)); truelight@0: } break; truelight@0: case 6: truelight@0: WP(w,buildtrain_d).rename_engine = WP(w,buildtrain_d).sel_engine; truelight@0: ShowQueryString( truelight@0: GetCustomEngineName(WP(w,buildtrain_d).sel_engine), truelight@0: STR_886A_RENAME_TRAIN_VEHICLE_TYPE, truelight@0: 31, truelight@0: 160, truelight@0: w->window_class, truelight@0: w->window_number); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_4: truelight@0: if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) { truelight@0: DeleteWindow(w); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_ON_EDIT_TEXT: { truelight@0: byte *b = e->edittext.str; truelight@0: if (*b == 0) truelight@0: return; truelight@0: truelight@0: memcpy(_decode_parameters, b, 32); truelight@0: DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE)); truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _new_rail_vehicle_widgets[] = { truelight@0: { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 14, 11, 227, 0, 13, STR_0315, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_MATRIX, 14, 0, 216, 14, 125, 0x801, STR_8843_TRAIN_VEHICLE_SELECTION}, truelight@0: { WWT_SCROLLBAR, 14, 217, 227, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@0: { WWT_PANEL, 14, 0, 227, 126, 187, 0x0, 0}, truelight@0: { WWT_PUSHTXTBTN, 14, 0, 113, 188, 199, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN}, truelight@0: { WWT_PUSHTXTBTN, 14, 114, 227, 188, 199, STR_8820_RENAME, STR_8845_RENAME_TRAIN_VEHICLE_TYPE}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _new_rail_vehicle_desc = { truelight@0: -1, -1, 228, 200, truelight@0: WC_BUILD_VEHICLE,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _new_rail_vehicle_widgets, truelight@0: NewRailVehicleWndProc truelight@0: }; truelight@0: truelight@0: static void ShowBuildTrainWindow(uint tile) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: DeleteWindowById(WC_BUILD_VEHICLE, tile); truelight@0: truelight@0: w = AllocateWindowDesc(&_new_rail_vehicle_desc); truelight@0: w->window_number = tile; truelight@0: w->vscroll.cap = 8; truelight@0: truelight@0: if (tile != 0) { truelight@0: w->caption_color = _map_owner[tile]; truelight@0: WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF; truelight@0: } else { truelight@0: w->caption_color = _local_player; truelight@0: WP(w,buildtrain_d).railtype = DEREF_PLAYER(_local_player)->max_railtype - 1; truelight@0: } truelight@0: } truelight@0: truelight@0: static void DrawTrainImage(Vehicle *v, int x, int y, int count, int skip, VehicleID selection) truelight@0: { truelight@0: do { truelight@0: if (--skip < 0) { truelight@0: int image = GetTrainImage(v, 6); truelight@0: uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); truelight@0: if (v->vehstatus & VS_CRASHED) ormod = 0x3248000; truelight@0: DrawSprite(image | ormod, x+14, y+6); truelight@0: if (v->index == selection) DrawFrameRect(x-1, y-1, x+28, y+12, 15, 0x10); truelight@0: x += 29; truelight@0: count--; truelight@0: } truelight@0: truelight@0: if (!(v = v->next)) truelight@0: break; truelight@0: } while (count); truelight@0: } truelight@0: truelight@0: static void DrawTrainDepotWindow(Window *w) truelight@0: { truelight@0: uint tile; truelight@0: Vehicle *v, *u; truelight@0: int num,x,y,i, hnum; truelight@0: Depot *d; truelight@0: truelight@0: tile = w->window_number; truelight@0: truelight@0: /* setup disabled buttons */ truelight@0: w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<3)|(1<<4)|(1<<6)); truelight@0: truelight@0: /* determine amount of items for scroller */ truelight@0: num = 1; truelight@0: hnum = 0; truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && truelight@0: (v->subtype == 0 || v->subtype == 4) && truelight@0: v->tile == (TileIndex)tile && truelight@0: v->u.rail.track == 0x80) { truelight@0: num++; truelight@0: // determine number of items in the X direction. truelight@0: if (v->subtype == 0) { truelight@0: i = -1; truelight@0: u = v; truelight@0: do i++; while ( (u=u->next) != NULL); truelight@0: if (i > hnum) hnum = i; truelight@0: } truelight@0: } truelight@0: } truelight@0: SetVScrollCount(w, num); truelight@0: SetHScrollCount(w, hnum); truelight@0: truelight@0: /* locate the depot struct */ truelight@0: for(d=_depots; d->xy != (TileIndex)tile; d++) {} truelight@0: truelight@0: SET_DPARAM16(0,d->town_index); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: x = 2; truelight@0: y = 15; truelight@0: num = w->vscroll.pos; truelight@0: truelight@0: // draw all trains truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && truelight@0: v->subtype == 0 && truelight@0: v->tile == (TileIndex)tile && truelight@0: v->u.rail.track == 0x80 && truelight@0: --num < 0 && num >= -6) { truelight@0: truelight@0: DrawTrainImage(v, x+21, y, 10, w->hscroll.pos, WP(w,traindepot_d).sel); darkvater@22: /* Draw the train number */ truelight@0: SET_DPARAM16(0, v->unitnumber); truelight@0: DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0); darkvater@22: /* Draw the pretty flag */ truelight@0: DrawSprite(v->vehstatus&VS_STOPPED ? 0xC12 : 0xC13, x+15, y); truelight@0: truelight@0: y += 14; truelight@0: } truelight@0: } truelight@0: truelight@0: // draw all remaining vehicles truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && truelight@0: v->subtype == 4 && truelight@0: v->tile == (TileIndex)tile && truelight@0: v->u.rail.track == 0x80 && truelight@0: --num < 0 && num >= -6) { truelight@0: truelight@0: DrawTrainImage(v, x+50, y, 9, 0, WP(w,traindepot_d).sel); truelight@0: DrawString(x, y+2, STR_8816, 0); truelight@0: y += 14; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: typedef struct GetDepotVehiclePtData { truelight@0: Vehicle *head; truelight@0: Vehicle *wagon; truelight@0: } GetDepotVehiclePtData; truelight@0: truelight@0: static int GetVehicleFromTrainDepotWndPt(Window *w, int x, int y, GetDepotVehiclePtData *d) truelight@0: { truelight@0: int area_x; truelight@0: int row; truelight@0: Vehicle *v; truelight@0: truelight@0: x = x - 23; truelight@0: if (x < 0) { truelight@0: area_x = (x >= -10) ? -2 : -1; truelight@0: } else { truelight@0: area_x = x / 29; truelight@0: } truelight@0: truelight@0: row = (y - 14) / 14; truelight@0: if ( (uint) row >= 6) truelight@0: return 1; /* means err */ truelight@0: truelight@0: row += w->vscroll.pos; truelight@0: truelight@0: /* go through all the locomotives */ truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && truelight@0: v->subtype == 0 && truelight@0: v->tile == w->window_number && truelight@0: v->u.rail.track == 0x80 && truelight@0: --row < 0) { truelight@0: area_x += w->hscroll.pos; truelight@0: goto found_it; truelight@0: } truelight@0: } truelight@0: truelight@0: area_x--; /* free wagons don't have an initial loco. */ truelight@0: truelight@0: /* and then the list of free wagons */ truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && truelight@0: v->subtype == 4 && truelight@0: v->tile == w->window_number && truelight@0: v->u.rail.track == 0x80 && truelight@0: --row < 0) truelight@0: goto found_it; truelight@0: } truelight@0: truelight@0: d->head = NULL; truelight@0: d->wagon = NULL; truelight@0: truelight@0: /* didn't find anything, get out */ truelight@0: return 0; truelight@0: truelight@0: found_it: truelight@0: d->head = d->wagon = v; truelight@0: truelight@0: /* either pressed the flag or the number, but only when it's a loco */ truelight@0: if (area_x < 0 && v->subtype==0) truelight@0: return area_x; truelight@0: truelight@0: /* find the vehicle in this row that was clicked */ truelight@0: while (--area_x >= 0) { truelight@0: v = v->next; truelight@0: if (v == NULL) break; truelight@0: } truelight@0: truelight@0: d->wagon = v; truelight@0: truelight@0: return 0; truelight@0: } truelight@0: truelight@0: static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head) truelight@0: { truelight@0: Vehicle *v; truelight@0: truelight@0: v = &_vehicles[sel]; truelight@0: truelight@0: if (/*v->subtype == 0 ||*/ v == wagon) truelight@0: return; truelight@0: truelight@0: if (wagon == NULL) { truelight@0: if (head != NULL) truelight@0: wagon = GetLastVehicleInChain(head); truelight@0: } else { truelight@0: wagon = GetPrevVehicleInChain(wagon); truelight@0: if (wagon == NULL) truelight@0: return; truelight@0: } truelight@0: truelight@0: if (wagon == v) truelight@0: return; truelight@0: truelight@0: 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)); truelight@0: } truelight@0: truelight@0: static void TrainDepotClickTrain(Window *w, int x, int y) truelight@0: { truelight@0: GetDepotVehiclePtData gdvp; truelight@0: int mode, sel; truelight@0: Vehicle *v; truelight@0: truelight@0: mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp); dominik@10: dominik@10: // share / copy orders truelight@0: if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = gdvp.head; return; } truelight@0: truelight@0: v = gdvp.wagon; truelight@0: truelight@0: switch(mode) { dominik@10: case 0: // start dragging of vehicle truelight@0: sel = (int16)WP(w,traindepot_d).sel; truelight@0: if (sel != -1) { truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: TrainDepotMoveVehicle(v, sel, gdvp.head); truelight@0: } else if (v != NULL) { truelight@0: WP(w,traindepot_d).sel = v->index; truelight@0: SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetTrainImage(v, 6), 4, w); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; truelight@0: dominik@10: case -1: // show info window truelight@0: ShowTrainViewWindow(v); truelight@0: break; truelight@0: dominik@10: case -2: // click start/stop flag truelight@0: DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static void TrainDepotWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawTrainDepotWindow(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@0: case 6: truelight@0: ShowBuildTrainWindow(w->window_number); truelight@0: break; truelight@0: case 7: truelight@0: ScrollMainWindowToTile(w->window_number); truelight@0: break; truelight@0: case 2: truelight@0: TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_DESTROY: truelight@0: DeleteWindowById(WC_BUILD_VEHICLE, w->window_number); truelight@0: break; truelight@0: truelight@0: case WE_DRAGDROP: { truelight@0: switch(e->click.widget) { truelight@0: case 4: truelight@0: case 3: { truelight@0: Vehicle *v; truelight@0: int sell_cmd; truelight@0: truelight@0: /* sell vehicle */ truelight@0: if (w->disabled_state & (1 << e->click.widget)) truelight@0: return; truelight@0: truelight@0: if (WP(w,traindepot_d).sel == INVALID_VEHICLE) truelight@0: return; truelight@0: truelight@0: v = &_vehicles[WP(w,traindepot_d).sel]; truelight@0: truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: SetWindowDirty(w); truelight@0: truelight@0: HandleButtonClick(w, e->click.widget); truelight@0: truelight@0: sell_cmd = (e->click.widget == 4 || _ctrl_pressed) ? 1 : 0; truelight@0: truelight@0: if (v->subtype != 0) { truelight@0: DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE)); truelight@0: } else { truelight@0: _backup_orders_tile = v->tile; truelight@0: BackupVehicleOrders(v, _backup_orders_data); truelight@0: if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE))) truelight@0: _backup_orders_tile = 0; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case 2: { truelight@0: GetDepotVehiclePtData gdvp; truelight@0: VehicleID sel = WP(w,traindepot_d).sel; truelight@0: truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: SetWindowDirty(w); truelight@0: truelight@0: if (GetVehicleFromTrainDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &gdvp) == 0 && truelight@0: sel != INVALID_VEHICLE) { truelight@0: if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { truelight@0: TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); truelight@0: } else if (gdvp.head != NULL && gdvp.head->subtype==0) { truelight@0: ShowTrainViewWindow(gdvp.head); truelight@0: } truelight@0: } truelight@0: } break; truelight@0: truelight@0: default: truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: static const Widget _train_depot_widgets[] = { truelight@0: { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 14, 11, 348, 0, 13, STR_8800_TRAIN_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_MATRIX, 14, 0, 313, 14, 97, 0x601, STR_883F_TRAINS_CLICK_ON_TRAIN_FOR}, truelight@0: //{ WWT_PANEL, 14, 314, 337, 14, 108, 0x2A9, STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE}, truelight@0: { WWT_PANEL, 14, 314, 337, 14, 54, 0x2A9, STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE}, truelight@0: { WWT_PANEL, 14, 314, 337, 55, 108, 0x2BF, STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, truelight@0: truelight@0: { WWT_SCROLLBAR, 14, 338, 348, 14, 108, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@0: { WWT_PUSHTXTBTN, 14, 0, 173, 109, 120, STR_8815_NEW_VEHICLES, STR_8840_BUILD_NEW_TRAIN_VEHICLE}, truelight@0: { WWT_PUSHTXTBTN, 14, 174, 348, 109, 120, STR_00E4_LOCATION, STR_8842_CENTER_MAIN_VIEW_ON_TRAIN}, truelight@0: { WWT_HSCROLLBAR, 14, 0, 313, 98, 108, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _train_depot_desc = { truelight@0: -1, -1, 349, 121, truelight@0: WC_VEHICLE_DEPOT,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _train_depot_widgets, truelight@0: TrainDepotWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: void ShowTrainDepotWindow(uint tile) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: w = AllocateWindowDescFront(&_train_depot_desc, tile); truelight@0: if (w) { truelight@0: w->caption_color = _map_owner[w->window_number]; truelight@0: w->vscroll.cap = 6; truelight@0: w->hscroll.cap = 9; truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: _backup_orders_tile = 0; truelight@0: } truelight@0: } truelight@0: truelight@0: const byte _rail_vehicle_refit_types[4][16] = { truelight@0: { 0,1,2,4,5,6,7,8,9,10,0xFF }, // normal truelight@0: { 0,1,4,5,6,7,9,11,10,0xFF }, // arctic truelight@0: { 0,4,5,8,6,7,9,10,0xFF }, // desert truelight@0: { 0,1,3,5,7,8,9,6,4,10,11,0xFF }// candy truelight@0: }; truelight@0: truelight@0: static void RailVehicleRefitWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: Vehicle *v = &_vehicles[w->window_number]; truelight@0: const byte *b; truelight@0: int sel; truelight@0: int x,y; truelight@0: byte color; truelight@0: int cargo; truelight@0: truelight@0: SET_DPARAM16(0, v->string_id); truelight@0: SET_DPARAM16(1, v->unitnumber); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0); truelight@0: truelight@0: cargo = -1; truelight@0: x = 6; truelight@0: y = 25; truelight@0: sel = WP(w,refit_d).sel; truelight@0: b = _rail_vehicle_refit_types[_opt.landscape]; truelight@0: do { truelight@0: color = 16; truelight@0: if (sel == 0) { truelight@0: cargo = *b; truelight@0: color = 12; truelight@0: } truelight@0: sel--; truelight@0: DrawString(x,y,_cargoc.names_s[*b], color); truelight@0: y += 10; truelight@0: } while (*++b != 255); truelight@0: truelight@0: WP(w,refit_d).cargo = cargo; truelight@0: truelight@0: if (cargo != -1) { truelight@0: int32 cost = DoCommandByTile(v->tile, v->index, cargo, 0, CMD_REFIT_RAIL_VEHICLE); truelight@0: if (cost != CMD_ERROR) { truelight@0: SET_DPARAM32(2, cost); truelight@0: SET_DPARAM16(0, _cargoc.names_long_p[cargo]); truelight@0: SET_DPARAM16(1, _returned_refit_amount); truelight@0: DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0); truelight@0: } truelight@0: } truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_CLICK: truelight@0: switch(e->click.widget) { truelight@0: case 2: { /* listbox */ truelight@0: int y = e->click.pt.y - 25; truelight@0: if (y >= 0) { truelight@0: WP(w,refit_d).sel = y / 10; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } break; truelight@0: case 4: /* refit button */ truelight@0: if (WP(w,refit_d).cargo != 0xFF) { truelight@0: Vehicle *v = &_vehicles[w->window_number]; truelight@0: if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE))) truelight@0: DeleteWindow(w); truelight@0: } truelight@0: break; truelight@0: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: static const Widget _rail_vehicle_refit_widgets[] = { truelight@0: { WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_IMGBTN, 14, 0, 239, 14, 135, 0x0, STR_RAIL_SELECT_TYPE_OF_CARGO_FOR}, truelight@0: { WWT_IMGBTN, 14, 0, 239, 136, 157, 0x0}, truelight@0: { WWT_PUSHTXTBTN, 14, 0, 239, 158, 169, STR_RAIL_REFIT_VEHICLE, STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _rail_vehicle_refit_desc = { truelight@0: -1,-1, 240, 170, truelight@0: WC_VEHICLE_REFIT,WC_VEHICLE_VIEW, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _rail_vehicle_refit_widgets, truelight@0: RailVehicleRefitWndProc, truelight@0: }; truelight@0: truelight@0: static void ShowRailVehicleRefitWindow(Vehicle *v) truelight@0: { truelight@0: Window *w; truelight@0: DeleteWindowById(WC_VEHICLE_REFIT, v->index); truelight@0: _alloc_wnd_parent_num = v->index; truelight@0: w = AllocateWindowDesc(&_rail_vehicle_refit_desc); truelight@0: w->window_number = v->index; truelight@0: w->caption_color = v->owner; truelight@0: WP(w,refit_d).sel = -1; truelight@0: } truelight@0: truelight@0: truelight@0: truelight@0: truelight@0: static Widget _train_view_widgets[] = { truelight@0: { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 14, 11, 249, 0, 13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PANEL, 14, 0, 231, 14, 121, 0x0, 0}, truelight@0: { WWT_6, 14, 2, 229, 16, 119, 0, 0}, truelight@0: { WWT_PUSHIMGBTN, 14, 0, 249, 122, 133, 0x0, STR_8846_CURRENT_TRAIN_ACTION_CLICK}, truelight@0: { WWT_PUSHIMGBTN, 14, 232, 249, 14, 31, 0x2AB, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN}, truelight@0: { WWT_PUSHIMGBTN, 14, 232, 249, 32, 49, 0x2AD, STR_8849_SEND_TRAIN_TO_DEPOT}, truelight@0: { WWT_PUSHIMGBTN, 14, 232, 249, 50, 67, 0x2B1, STR_884A_FORCE_TRAIN_TO_PROCEED}, truelight@0: { WWT_PUSHIMGBTN, 14, 232, 249, 68, 85, 0x2CB, STR_884B_REVERSE_DIRECTION_OF_TRAIN}, truelight@0: { WWT_PUSHIMGBTN, 14, 232, 249, 86, 103, 0x2B2, STR_8847_SHOW_TRAIN_S_ORDERS}, truelight@0: { WWT_PUSHIMGBTN, 14, 232, 249, 104, 121, 0x2B3, STR_884C_SHOW_TRAIN_DETAILS}, truelight@0: { WWT_PUSHIMGBTN, 14, 232, 249, 68, 85, 0x2B4, STR_RAIL_REFIT_VEHICLE_TO_CARRY}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static void TrainViewWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: Vehicle *v; truelight@0: StringID str; truelight@0: truelight@0: v = &_vehicles[w->window_number]; truelight@0: truelight@0: w->disabled_state = (v->owner == _local_player) ? 0 : 0x1C0; truelight@0: truelight@0: truelight@0: /* draw widgets & caption */ truelight@0: SET_DPARAM16(0, v->string_id); truelight@0: SET_DPARAM16(1, v->unitnumber); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: /* draw the flag */ truelight@0: DrawSprite( (v->vehstatus&VS_STOPPED) ? 0xC12 : 0xC13, 2, 123); truelight@0: truelight@0: if (v->u.rail.crash_anim_pos != 0) { truelight@0: str = STR_8863_CRASHED; truelight@0: } else if (v->breakdown_ctr == 1) { truelight@0: str = STR_885C_BROKEN_DOWN; truelight@0: } else if (v->vehstatus & VS_STOPPED) { truelight@0: if (v->u.rail.last_speed == 0) { truelight@0: str = STR_8861_STOPPED; truelight@0: } else { truelight@0: SET_DPARAM16(0, v->u.rail.last_speed * 10 >> 4); truelight@0: str = STR_TRAIN_STOPPING + _patches.vehicle_speed; truelight@0: } truelight@0: } else { truelight@0: switch(v->next_order & OT_MASK) { truelight@0: case OT_GOTO_STATION: { truelight@0: str = STR_HEADING_FOR_STATION + _patches.vehicle_speed; truelight@0: SET_DPARAM16(0, v->next_order_param); truelight@0: SET_DPARAM16(1, v->u.rail.last_speed * 10 >> 4); truelight@0: } break; truelight@0: truelight@0: case OT_GOTO_DEPOT: { truelight@0: Depot *dep = &_depots[v->next_order_param]; truelight@0: SET_DPARAM16(0, dep->town_index); truelight@0: str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed; truelight@0: SET_DPARAM16(1, v->u.rail.last_speed * 10 >> 4); truelight@0: } break; truelight@0: truelight@0: case OT_LOADING: truelight@0: case OT_LEAVESTATION: truelight@0: str = STR_882F_LOADING_UNLOADING; truelight@0: break; truelight@0: truelight@0: case OT_GOTO_CHECKPOINT: { truelight@0: SET_DPARAM16(0, v->next_order_param); truelight@0: str = STR_HEADING_FOR_CHECKPOINT + _patches.vehicle_speed; truelight@0: SET_DPARAM16(1, v->u.rail.last_speed * 10 >> 4); truelight@0: break; truelight@0: } truelight@0: truelight@0: default: truelight@0: if (v->num_orders == 0) { truelight@0: str = STR_NO_ORDERS + _patches.vehicle_speed; truelight@0: SET_DPARAM16(0, v->u.rail.last_speed * 10 >> 4); truelight@0: } else truelight@0: str = STR_EMPTY; truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: DrawStringCentered(125, 123, str, 0); truelight@0: DrawWindowViewport(w); truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: int wid = e->click.widget; truelight@0: Vehicle *v = &_vehicles[w->window_number]; truelight@0: truelight@0: switch(wid) { truelight@0: case 4: /* start/stop train */ truelight@0: DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); truelight@0: break; truelight@0: case 5: /* center main view */ truelight@0: ScrollMainWindowTo(v->x_pos, v->y_pos); truelight@0: break; truelight@0: case 6: /* goto depot */ truelight@0: DoCommandP(v->tile, v->index, 0, NULL, CMD_TRAIN_GOTO_DEPOT | CMD_MSG(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT)); truelight@0: break; truelight@0: case 7: /* force proceed */ truelight@0: DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL)); truelight@0: break; truelight@0: case 8: /* reverse direction */ truelight@0: DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION)); truelight@0: break; truelight@0: case 9: /* show train orders */ truelight@0: ShowOrdersWindow(v); truelight@0: break; truelight@0: case 10: /* show train details */ truelight@0: ShowTrainDetailsWindow(v); truelight@0: break; truelight@0: case 11: truelight@0: ShowRailVehicleRefitWindow(v); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_DESTROY: truelight@0: DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number); truelight@0: DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number); truelight@0: break; truelight@0: truelight@0: case WE_MOUSELOOP: { truelight@0: Vehicle *v; truelight@0: uint32 h; truelight@0: truelight@0: v = &_vehicles[w->window_number]; truelight@0: assert(v->type == VEH_Train); truelight@0: h = CheckStoppedInDepot(v) >= 0 ? (1 << 8) : (1 << 11); truelight@0: if (h != w->hidden_state) { truelight@0: w->hidden_state = h; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; truelight@0: } truelight@0: truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _train_view_desc = { truelight@0: -1,-1, 250, 134, truelight@0: WC_VEHICLE_VIEW,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _train_view_widgets, truelight@0: TrainViewWndProc truelight@0: }; truelight@0: truelight@0: void ShowTrainViewWindow(Vehicle *v) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: w = AllocateWindowDescFront(&_train_view_desc,v->index); truelight@0: if (w) { truelight@0: w->caption_color = v->owner; truelight@0: AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0); truelight@0: } truelight@0: } truelight@0: truelight@0: static void TrainDetailsCargoTab(Vehicle *v, int x, int y) truelight@0: { truelight@0: int num; truelight@0: StringID str; truelight@0: truelight@0: if (v->cargo_cap != 0) { truelight@0: num = v->cargo_count; truelight@0: str = STR_8812_EMPTY; truelight@0: if (num != 0) { truelight@0: SET_DPARAM8(0, v->cargo_type); truelight@0: SET_DPARAM16(1, num); truelight@0: SET_DPARAM16(2, v->cargo_source); truelight@0: str = STR_8813_FROM; truelight@0: } truelight@0: DrawString(x, y, str, 0); truelight@0: } truelight@0: } truelight@0: truelight@0: static void TrainDetailsInfoTab(Vehicle *v, int x, int y) truelight@0: { truelight@0: const RailVehicleInfo *rvi; truelight@0: truelight@0: rvi = &_rail_vehicle_info[v->engine_type]; truelight@0: truelight@0: if (!(rvi->flags & RVI_WAGON)) { truelight@0: SET_DPARAM16(0, GetCustomEngineName(v->engine_type)); truelight@0: SET_DPARAM16(1, v->build_year + 1920); truelight@0: SET_DPARAM32(2, v->value); truelight@0: DrawString(x, y, STR_882C_BUILT_VALUE, 0x10); truelight@0: } else { truelight@0: SET_DPARAM16(0, GetCustomEngineName(v->engine_type)); truelight@0: SET_DPARAM32(1, v->value); truelight@0: DrawString(x, y, STR_882D_VALUE, 0x10); truelight@0: } truelight@0: } truelight@0: truelight@0: static void TrainDetailsCapacityTab(Vehicle *v, int x, int y) truelight@0: { truelight@0: if (v->cargo_cap != 0) { truelight@0: SET_DPARAM16(1, v->cargo_cap); truelight@0: SET_DPARAM16(0, _cargoc.names_long_p[v->cargo_type]); truelight@0: DrawString(x, y, STR_013F_CAPACITY, 0); truelight@0: } truelight@0: } truelight@0: truelight@0: typedef void TrainDetailsDrawerProc(Vehicle *v, int x, int y); truelight@0: truelight@0: static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = { truelight@0: TrainDetailsCargoTab, truelight@0: TrainDetailsInfoTab, truelight@0: TrainDetailsCapacityTab, truelight@0: }; truelight@0: truelight@0: static void DrawTrainDetailsWindow(Window *w) truelight@0: { truelight@0: Vehicle *v, *u; truelight@0: uint16 tot_cargo[NUM_CARGO][2]; // count total cargo ([0]-actual cargo, [1]-total cargo) truelight@0: int i,num,x,y,sel; truelight@0: StringID str; truelight@0: byte det_tab = WP(w, traindetails_d).tab; truelight@0: truelight@0: /* Count number of vehicles */ truelight@0: num = 0; truelight@0: truelight@0: // det_tab == 3 <-- Total Cargo tab truelight@0: if (det_tab == 3) // reset tot_cargo array to 0 values truelight@0: memset(tot_cargo, 0, sizeof(tot_cargo)); truelight@0: truelight@0: u = v = &_vehicles[w->window_number]; truelight@0: do { truelight@0: if (det_tab != 3) truelight@0: num++; truelight@0: else { truelight@0: tot_cargo[u->cargo_type][0] += u->cargo_count; truelight@0: tot_cargo[u->cargo_type][1] += u->cargo_cap; truelight@0: } truelight@0: } while ( (u = u->next) != NULL); truelight@0: truelight@0: /* set scroll-amount seperately from counting, as to not truelight@0: compute num double for more carriages of the same type truelight@0: */ truelight@0: if (det_tab == 3) { truelight@0: for (i = 0; i != NUM_CARGO; i++) { truelight@0: if (tot_cargo[i][1] > 0) // only count carriages that the train has truelight@0: num++; truelight@0: } truelight@0: num++; // needs one more because first line is description string truelight@0: } truelight@0: truelight@0: SetVScrollCount(w, num); truelight@0: truelight@0: w->disabled_state = 1 << (det_tab + 9); truelight@0: if (v->owner != _local_player) truelight@0: w->disabled_state |= (1 << 2); truelight@0: truelight@0: SET_DPARAM16(0, v->string_id); truelight@0: SET_DPARAM16(1, v->unitnumber); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: num = v->age / 366; truelight@0: SET_DPARAM16(1, num); truelight@0: truelight@0: x = 2; truelight@0: truelight@0: str = STR_0199_YEAR; truelight@0: if (num != 1) { truelight@0: str += STR_019A_YEARS - STR_0199_YEAR; truelight@0: if ((uint16)(v->max_age - 366) < v->age) truelight@0: str += STR_019B_YEARS - STR_019A_YEARS; truelight@0: } truelight@0: SET_DPARAM16(0, str); truelight@0: SET_DPARAM16(2, v->max_age / 366); truelight@0: SET_DPARAM32(3, GetTrainRunningCost(v) >> 8); truelight@0: DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0); truelight@0: truelight@0: SET_DPARAM16(2, v->max_speed * 10 >> 4); truelight@0: SET_DPARAM32(1, v->u.rail.cached_power); truelight@0: SET_DPARAM16(0, v->u.rail.cached_weight); truelight@0: DrawString(x, 25, STR_885E_WEIGHT_T_POWER_HP_MAX_SPEED, 0); truelight@0: truelight@0: SET_DPARAM32(0, v->profit_this_year); truelight@0: SET_DPARAM32(1, v->profit_last_year); truelight@0: DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0); truelight@0: truelight@0: SET_DPARAM8(0, 100 * (v->reliability>>8) >> 8); truelight@0: SET_DPARAM16(1, v->breakdowns_since_last_service); truelight@0: DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0); truelight@0: truelight@0: SET_DPARAM16(0, v->service_interval); truelight@0: SET_DPARAM16(1, v->date_of_last_service); truelight@0: DrawString(x + 11, 141, STR_883C_SERVICING_INTERVAL_DAYS, 0); truelight@0: truelight@0: x = 1; truelight@0: y = 57; truelight@0: sel = w->vscroll.pos; truelight@0: truelight@0: // draw the first 3 details tabs truelight@0: if (det_tab != 3) { truelight@0: for(;;) { truelight@0: if (--sel < 0 && sel >= -6) { truelight@0: DrawTrainImage(v, x, y, 1, 0, INVALID_VEHICLE); truelight@0: _train_details_drawer_proc[WP(w,traindetails_d).tab](v, x + 30, y + 2); truelight@0: y += 14; truelight@0: } truelight@0: if ( (v=v->next) == NULL) truelight@0: return; truelight@0: } truelight@0: } truelight@0: else { // draw total cargo tab truelight@0: i = 0; truelight@0: DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0); truelight@0: do { truelight@0: if (tot_cargo[i][1] > 0 && --sel < 0 && sel >= -5) { truelight@0: y += 14; truelight@0: // STR_013F_TOTAL_CAPACITY :{LTBLUE}- {CARGO} ({SHORTCARGO}) truelight@0: SET_DPARAM8(0, i); // {CARGO} #1 truelight@0: SET_DPARAM16(1, tot_cargo[i][0]); // {CARGO} #2 truelight@0: SET_DPARAM8(2, i); // {SHORTCARGO} #1 truelight@0: SET_DPARAM16(3, tot_cargo[i][1]); // {SHORTCARGO} #2 truelight@0: DrawString(x, y, STR_013F_TOTAL_CAPACITY, 0); truelight@0: } truelight@0: } while (++i != NUM_CARGO); truelight@0: } truelight@0: } truelight@0: truelight@0: static void TrainDetailsWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawTrainDetailsWindow(w); truelight@0: break; truelight@0: case WE_CLICK: { truelight@0: int mod; truelight@0: Vehicle *v; truelight@0: switch(e->click.widget) { truelight@0: case 2: /* name train */ truelight@0: v = &_vehicles[w->window_number]; truelight@0: SET_DPARAM16(0, v->unitnumber); truelight@0: ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number); truelight@0: break; truelight@0: case 6: /* inc serv interval */ truelight@0: mod = 10; truelight@0: goto do_change_service_int; truelight@0: truelight@0: case 7: /* dec serv interval */ truelight@0: mod = -10; truelight@0: do_change_service_int: truelight@0: v = &_vehicles[w->window_number]; truelight@0: mod += v->service_interval; truelight@0: if (!IS_INT_INSIDE(mod, 30, 800+1)) truelight@0: return; truelight@0: truelight@0: DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); truelight@0: break; truelight@0: /* details buttons*/ truelight@0: case 9: // Cargo truelight@0: case 10: // Information truelight@0: case 11: // Capacities truelight@0: case 12: // Total cargo truelight@0: CLRBIT(w->disabled_state, 9); truelight@0: CLRBIT(w->disabled_state, 10); truelight@0: CLRBIT(w->disabled_state, 11); truelight@0: CLRBIT(w->disabled_state, 12); truelight@0: SETBIT(w->disabled_state, e->click.widget); truelight@0: WP(w,traindetails_d).tab = e->click.widget - 9; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_4: truelight@0: if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL) truelight@0: DeleteWindow(w); truelight@0: break; truelight@0: truelight@0: case WE_ON_EDIT_TEXT: { truelight@0: byte *b = e->edittext.str; truelight@0: if (*b == 0) truelight@0: return; truelight@0: memcpy(_decode_parameters, b, 32); truelight@0: DoCommandP(0, w->window_number, 0, NULL, CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN)); truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _train_details_widgets[] = { truelight@0: { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 14, 11, 329, 0, 13, STR_8802_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_PUSHTXTBTN, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN}, truelight@0: { WWT_PANEL, 14, 0, 369, 14, 55, 0x0, 0}, truelight@0: { WWT_MATRIX, 14, 0, 358, 56, 139, 0x601, 0}, truelight@0: { WWT_SCROLLBAR, 14, 359, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@0: { WWT_PUSHTXTBTN, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, truelight@0: { WWT_PUSHTXTBTN, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, truelight@0: { WWT_PANEL, 14, 11, 369, 140, 151, 0x0, 0}, truelight@0: { WWT_PUSHTXTBTN, 14, 0, 92, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED}, truelight@0: { WWT_PUSHTXTBTN, 14, 93, 184, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES}, truelight@0: { WWT_PUSHTXTBTN, 14, 185, 277, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH}, truelight@0: { WWT_PUSHTXTBTN, 14, 278, 369, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: truelight@0: static const WindowDesc _train_details_desc = { truelight@0: -1,-1, 370, 164, truelight@0: WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _train_details_widgets, truelight@0: TrainDetailsWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: void ShowTrainDetailsWindow(Vehicle *v) truelight@0: { truelight@0: Window *w; truelight@0: VehicleID veh = v->index; truelight@0: truelight@0: DeleteWindowById(WC_VEHICLE_ORDERS, veh); truelight@0: DeleteWindowById(WC_VEHICLE_DETAILS, veh); truelight@0: truelight@0: _alloc_wnd_parent_num = veh; truelight@0: w = AllocateWindowDesc(&_train_details_desc); truelight@0: truelight@0: w->window_number = veh; truelight@0: w->caption_color = v->owner; truelight@0: w->vscroll.cap = 6; truelight@0: WP(w,traindetails_d).tab = 0; truelight@0: } truelight@0: truelight@0: // draw the vehicle profit button in the vehicle list window. truelight@0: void DrawVehicleProfitButton(Vehicle *v, int x, int y) truelight@0: { truelight@0: uint32 ormod; truelight@0: truelight@0: // draw profit-based colored icons truelight@0: if(v->age <= 365 * 2) truelight@0: ormod = 0x3158000; // grey truelight@0: else if(v->profit_last_year < 0) truelight@0: ormod = 0x30b8000; //red truelight@0: else if(v->profit_last_year < 10000) truelight@0: ormod = 0x30a8000; // yellow truelight@0: else truelight@0: ormod = 0x30d8000; // green truelight@0: DrawSprite((SPR_OPENTTD_BASE + 10) | ormod, x, y); truelight@0: } truelight@0: truelight@0: truelight@0: static const StringID _player_trains_tooltips[] = { truelight@0: STR_018B_CLOSE_WINDOW, truelight@0: STR_018C_WINDOW_TITLE_DRAG_THIS, truelight@0: STR_883D_TRAINS_CLICK_ON_TRAIN_FOR, truelight@0: STR_0190_SCROLL_BAR_SCROLLS_LIST, truelight@0: STR_883E_BUILD_NEW_TRAINS_REQUIRES, truelight@0: 0, truelight@0: }; truelight@0: truelight@0: static void PlayerTrainsWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: /* determine amount of items for scroller */ truelight@0: { truelight@0: Vehicle *v; truelight@0: int num = 0; truelight@0: byte owner = (byte)w->window_number; truelight@0: truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && v->subtype == 0 && v->owner == owner) truelight@0: num++; truelight@0: } truelight@0: truelight@0: SetVScrollCount(w, num); truelight@0: } truelight@0: truelight@0: /* draw the widgets */ truelight@0: { truelight@0: Player *p = DEREF_PLAYER(w->window_number); truelight@0: SET_DPARAM16(0, p->name_1); truelight@0: SET_DPARAM32(1, p->name_2); truelight@0: DrawWindowWidgets(w); truelight@0: } truelight@0: truelight@0: /* draw the trains */ truelight@0: { truelight@0: Vehicle *v; truelight@0: int pos = w->vscroll.pos; truelight@0: byte owner = (byte)w->window_number; truelight@0: int x = 2; truelight@0: int y = 15; truelight@0: truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && v->subtype == 0 && v->owner == owner && truelight@0: --pos < 0 && pos >= -7) { truelight@0: StringID str; truelight@0: truelight@0: DrawTrainImage(v, x + 21, y + 6, 10, 0, INVALID_VEHICLE); truelight@0: DrawVehicleProfitButton(v, x, y+13); truelight@0: truelight@0: SET_DPARAM16(0, v->unitnumber); truelight@0: if (IsTrainDepotTile(v->tile)) { truelight@0: str = STR_021F; truelight@0: } else { truelight@0: str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; truelight@0: } truelight@0: DrawString(x, y+2, str, 0); truelight@0: truelight@0: SET_DPARAM32(0, v->profit_this_year); truelight@0: SET_DPARAM32(1, v->profit_last_year); truelight@0: DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); truelight@0: truelight@0: if (v->string_id != STR_SV_TRAIN_NAME) { truelight@0: SET_DPARAM16(0, v->string_id); truelight@0: DrawString(x+21, y, STR_01AB, 0); truelight@0: } truelight@0: truelight@0: y += 26; truelight@0: } truelight@0: } truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@0: case 2: { truelight@0: int idx = (e->click.pt.y - 0xE) / 26; truelight@0: Vehicle *v; truelight@0: byte owner; truelight@0: truelight@0: if ((uint)idx >= 7) truelight@0: break; truelight@0: truelight@0: idx += w->vscroll.pos; truelight@0: truelight@0: owner = (byte)w->window_number; truelight@0: truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && v->subtype == 0 && v->owner == owner && truelight@0: --idx < 0) { truelight@0: ShowTrainViewWindow(v); truelight@0: break; truelight@0: } truelight@0: } truelight@0: } break; truelight@0: truelight@0: case 4: { truelight@0: uint tile; truelight@0: truelight@0: tile = _last_built_train_depot_tile; truelight@0: do { truelight@0: if (_map_owner[tile] == _local_player && truelight@0: IsTrainDepotTile(tile)) { truelight@0: truelight@0: ShowTrainDepotWindow(tile); truelight@0: ShowBuildTrainWindow(tile); truelight@0: return; truelight@0: } truelight@0: truelight@0: tile = TILE_MASK(tile + 1); truelight@0: } while(tile != _last_built_train_depot_tile); truelight@0: truelight@0: ShowBuildTrainWindow(0); truelight@0: } break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _player_trains_widgets[] = { truelight@0: { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 14, 11, 324, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_MATRIX, 14, 0, 313, 14, 195, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, truelight@0: { WWT_SCROLLBAR, 14, 314, 324, 14, 195, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@0: { WWT_PUSHTXTBTN, 14, 0, 161, 196, 207, STR_8815_NEW_VEHICLES, STR_883E_BUILD_NEW_TRAINS_REQUIRES}, truelight@0: { WWT_PANEL, 14, 162, 324, 196, 207, 0x0, 0}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _player_trains_desc = { truelight@0: -1, -1, 325, 208, truelight@0: WC_TRAINS_LIST,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _player_trains_widgets, truelight@0: PlayerTrainsWndProc truelight@0: }; truelight@0: truelight@0: static const Widget _other_player_trains_widgets[] = { truelight@0: { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@0: { WWT_CAPTION, 14, 11, 324, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@0: { WWT_MATRIX, 14, 0, 313, 14, 195, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, truelight@0: { WWT_SCROLLBAR, 14, 314, 324, 14, 195, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@0: { WWT_LAST}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _other_player_trains_desc = { truelight@0: -1, -1, 325, 196, truelight@0: WC_TRAINS_LIST,0, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _other_player_trains_widgets, truelight@0: PlayerTrainsWndProc truelight@0: }; truelight@0: truelight@0: void ShowPlayerTrains(int player) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: if ( player == _local_player) { truelight@0: w = AllocateWindowDescFront(&_player_trains_desc, player); truelight@0: } else { truelight@0: w = AllocateWindowDescFront(&_other_player_trains_desc, player); truelight@0: } truelight@0: if (w) { truelight@0: w->caption_color = w->window_number; truelight@0: w->vscroll.cap = 7; truelight@0: } truelight@0: }