132 |
132 |
133 void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2) |
133 void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2) |
134 { |
134 { |
135 Vehicle *v,*found; |
135 Vehicle *v,*found; |
136 |
136 |
137 if (!success) |
137 if (!success) return; |
138 return; |
|
139 |
138 |
140 // find a locomotive in the depot. |
139 // find a locomotive in the depot. |
141 found = NULL; |
140 found = NULL; |
142 FOR_ALL_VEHICLES(v) { |
141 FOR_ALL_VEHICLES(v) { |
143 if (v->type == VEH_Train && IsFrontEngine(v) && |
142 if (v->type == VEH_Train && IsFrontEngine(v) && |
144 v->tile == tile && |
143 v->tile == tile && |
145 v->u.rail.track == 0x80) { |
144 v->u.rail.track == 0x80) { |
146 if (found != NULL) // must be exactly one. |
145 if (found != NULL) return; // must be exactly one. |
147 return; |
|
148 found = v; |
146 found = v; |
149 } |
147 } |
150 } |
148 } |
151 |
149 |
152 // if we found a loco, |
150 // if we found a loco, |
189 |
187 |
190 if (!HasPowerOnRail(e->railtype, railtype) || !(rvi->flags & RVI_WAGON) != is_engine || |
188 if (!HasPowerOnRail(e->railtype, railtype) || !(rvi->flags & RVI_WAGON) != is_engine || |
191 !HASBIT(e->player_avail, _local_player)) |
189 !HASBIT(e->player_avail, _local_player)) |
192 continue; |
190 continue; |
193 |
191 |
194 if (*sel == 0) |
192 if (*sel == 0) *selected_id = i; |
195 *selected_id = i; |
|
196 |
193 |
197 if (IS_INT_INSIDE(--*pos, -show_max, 0)) { |
194 if (IS_INT_INSIDE(--*pos, -show_max, 0)) { |
198 DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10); |
195 DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10); |
199 DrawTrainEngine(*x + 29, *y + 6, i, GetEnginePalette(i, _local_player)); |
196 DrawTrainEngine(*x + 29, *y + 6, i, GetEnginePalette(i, _local_player)); |
200 *y += 14; |
197 *y += 14; |
206 static void NewRailVehicleWndProc(Window *w, WindowEvent *e) |
203 static void NewRailVehicleWndProc(Window *w, WindowEvent *e) |
207 { |
204 { |
208 switch (e->event) { |
205 switch (e->event) { |
209 case WE_PAINT: |
206 case WE_PAINT: |
210 |
207 |
211 if (w->window_number == 0) |
208 if (w->window_number == 0) SETBIT(w->disabled_state, 5); |
212 SETBIT(w->disabled_state, 5); |
|
213 |
209 |
214 { |
210 { |
215 int count = 0; |
211 int count = 0; |
216 RailType railtype = WP(w,buildtrain_d).railtype; |
212 RailType railtype = WP(w,buildtrain_d).railtype; |
217 EngineID i; |
213 EngineID i; |
218 |
214 |
219 for (i = 0; i < NUM_TRAIN_ENGINES; i++) { |
215 for (i = 0; i < NUM_TRAIN_ENGINES; i++) { |
220 const Engine *e = GetEngine(i); |
216 const Engine *e = GetEngine(i); |
221 if (HasPowerOnRail(e->railtype, railtype) |
217 if (HasPowerOnRail(e->railtype, railtype) && |
222 && HASBIT(e->player_avail, _local_player)) |
218 HASBIT(e->player_avail, _local_player)) { |
223 count++; |
219 count++; |
|
220 } |
224 } |
221 } |
225 SetVScrollCount(w, count); |
222 SetVScrollCount(w, count); |
226 } |
223 } |
227 |
224 |
228 SetDParam(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES); |
225 SetDParam(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES); |
414 /* determine amount of items for scroller */ |
411 /* determine amount of items for scroller */ |
415 num = 0; |
412 num = 0; |
416 hnum = 8; |
413 hnum = 8; |
417 FOR_ALL_VEHICLES(v) { |
414 FOR_ALL_VEHICLES(v) { |
418 if (v->type == VEH_Train && |
415 if (v->type == VEH_Train && |
419 (IsFrontEngine(v) || IsFreeWagon(v)) && |
416 (IsFrontEngine(v) || IsFreeWagon(v)) && |
420 v->tile == tile && |
417 v->tile == tile && |
421 v->u.rail.track == 0x80) { |
418 v->u.rail.track == 0x80) { |
422 num++; |
419 num++; |
423 // determine number of items in the X direction. |
420 // determine number of items in the X direction. |
424 if (IsFrontEngine(v)) { |
421 if (IsFrontEngine(v)) { |
560 { |
557 { |
561 Vehicle *v; |
558 Vehicle *v; |
562 |
559 |
563 v = GetVehicle(sel); |
560 v = GetVehicle(sel); |
564 |
561 |
565 if (v == wagon) |
562 if (v == wagon) return; |
566 return; |
|
567 |
563 |
568 if (wagon == NULL) { |
564 if (wagon == NULL) { |
569 if (head != NULL) |
565 if (head != NULL) wagon = GetLastVehicleInChain(head); |
570 wagon = GetLastVehicleInChain(head); |
|
571 } else { |
566 } else { |
572 wagon = GetPrevVehicleInChain(wagon); |
567 wagon = GetPrevVehicleInChain(wagon); |
573 if (wagon == NULL) |
568 if (wagon == NULL) return; |
574 return; |
569 } |
575 } |
570 |
576 |
571 if (wagon == v) return; |
577 if (wagon == v) |
|
578 return; |
|
579 |
572 |
580 DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); |
573 DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); |
581 } |
574 } |
582 |
575 |
583 static void TrainDepotClickTrain(Window *w, int x, int y) |
576 static void TrainDepotClickTrain(Window *w, int x, int y) |
587 Vehicle *v; |
580 Vehicle *v; |
588 |
581 |
589 mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp); |
582 mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp); |
590 |
583 |
591 // share / copy orders |
584 // share / copy orders |
592 if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = gdvp.head; return; } |
585 if (_thd.place_mode && mode <= 0) { |
|
586 _place_clicked_vehicle = gdvp.head; |
|
587 return; |
|
588 } |
593 |
589 |
594 v = gdvp.wagon; |
590 v = gdvp.wagon; |
595 |
591 |
596 switch (mode) { |
592 switch (mode) { |
597 case 0: { // start dragging of vehicle |
593 case 0: { // start dragging of vehicle |
678 } else { |
674 } else { |
679 ResetObjectToPlace(); |
675 ResetObjectToPlace(); |
680 } |
676 } |
681 break; |
677 break; |
682 |
678 |
683 } |
679 } |
684 } break; |
680 } break; |
685 |
681 |
686 case WE_PLACE_OBJ: { |
682 case WE_PLACE_OBJ: |
687 ClonePlaceObj(w); |
683 ClonePlaceObj(w); |
688 } break; |
684 break; |
689 |
685 |
690 case WE_ABORT_PLACE_OBJ: { |
686 case WE_ABORT_PLACE_OBJ: |
691 CLRBIT(w->click_state, 9); |
687 CLRBIT(w->click_state, 9); |
692 InvalidateWidget(w, 9); |
688 InvalidateWidget(w, 9); |
693 } break; |
689 break; |
694 |
690 |
695 // check if a vehicle in a depot was clicked.. |
691 // check if a vehicle in a depot was clicked.. |
696 case WE_MOUSELOOP: { |
692 case WE_MOUSELOOP: { |
697 const Vehicle* v = _place_clicked_vehicle; |
693 const Vehicle* v = _place_clicked_vehicle; |
698 |
694 |
1416 SortVehicleList(vl); |
1412 SortVehicleList(vl); |
1417 |
1413 |
1418 SetVScrollCount(w, vl->list_length); |
1414 SetVScrollCount(w, vl->list_length); |
1419 |
1415 |
1420 // disable 'Sort By' tooltip on Unsorted sorting criteria |
1416 // disable 'Sort By' tooltip on Unsorted sorting criteria |
1421 if (vl->sort_type == SORT_BY_UNSORTED) |
1417 if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3); |
1422 w->disabled_state |= (1 << 3); |
|
1423 |
1418 |
1424 /* draw the widgets */ |
1419 /* draw the widgets */ |
1425 { |
1420 { |
1426 const Player *p = GetPlayer(owner); |
1421 const Player *p = GetPlayer(owner); |
1427 if (station == INVALID_STATION) { |
1422 if (station == INVALID_STATION) { |
1452 |
1447 |
1453 DrawTrainImage(v, x + 21, y + 6, w->hscroll.cap, 0, INVALID_VEHICLE); |
1448 DrawTrainImage(v, x + 21, y + 6, w->hscroll.cap, 0, INVALID_VEHICLE); |
1454 DrawVehicleProfitButton(v, x, y + 13); |
1449 DrawVehicleProfitButton(v, x, y + 13); |
1455 |
1450 |
1456 SetDParam(0, v->unitnumber); |
1451 SetDParam(0, v->unitnumber); |
1457 if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN)) |
1452 if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN)) { |
1458 str = STR_021F; |
1453 str = STR_021F; |
1459 else |
1454 } else { |
1460 str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; |
1455 str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; |
|
1456 } |
1461 DrawString(x, y + 2, str, 0); |
1457 DrawString(x, y + 2, str, 0); |
1462 |
1458 |
1463 SetDParam(0, v->profit_this_year); |
1459 SetDParam(0, v->profit_this_year); |
1464 SetDParam(1, v->profit_last_year); |
1460 SetDParam(1, v->profit_last_year); |
1465 DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
1461 DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); |
1487 ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0); |
1483 ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0); |
1488 return; |
1484 return; |
1489 |
1485 |
1490 case 7: { /* Matrix to show vehicles */ |
1486 case 7: { /* Matrix to show vehicles */ |
1491 uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL; |
1487 uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL; |
|
1488 const Vehicle* v; |
1492 |
1489 |
1493 if (id_v >= w->vscroll.cap) return; // click out of bounds |
1490 if (id_v >= w->vscroll.cap) return; // click out of bounds |
1494 |
1491 |
1495 id_v += w->vscroll.pos; |
1492 id_v += w->vscroll.pos; |
1496 |
1493 |
1497 { |
1494 if (id_v >= vl->list_length) return; // click out of list bound |
1498 Vehicle *v; |
1495 |
1499 |
1496 v = GetVehicle(vl->sort_list[id_v].index); |
1500 if (id_v >= vl->list_length) return; // click out of list bound |
1497 |
1501 |
1498 assert(v->type == VEH_Train && IsFrontEngine(v) && v->owner == owner); |
1502 v = GetVehicle(vl->sort_list[id_v].index); |
1499 |
1503 |
1500 ShowTrainViewWindow(v); |
1504 assert(v->type == VEH_Train && IsFrontEngine(v) && v->owner == owner); |
|
1505 |
|
1506 ShowTrainViewWindow(v); |
|
1507 } |
|
1508 } break; |
1501 } break; |
1509 |
1502 |
1510 case 9: /* Build new Vehicle */ |
1503 case 9: /* Build new Vehicle */ |
1511 if (!IsWindowOfPrototype(w, _player_trains_widgets)) break; |
1504 if (!IsWindowOfPrototype(w, _player_trains_widgets)) break; |
1512 ShowBuildTrainWindow(0); |
1505 ShowBuildTrainWindow(0); |
1513 break; |
1506 break; |
1514 |
1507 |
1515 case 10: { |
1508 case 10: |
1516 if (!IsWindowOfPrototype(w, _player_trains_widgets)) |
1509 if (IsWindowOfPrototype(w, _player_trains_widgets)) break; |
1517 break; |
|
1518 |
|
1519 ShowReplaceVehicleWindow(VEH_Train); |
1510 ShowReplaceVehicleWindow(VEH_Train); |
1520 break; |
1511 break; |
1521 } |
|
1522 |
1512 |
1523 } |
1513 } |
1524 } break; |
1514 } break; |
1525 |
1515 |
1526 case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */ |
1516 case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */ |
1529 vl->flags |= VL_RESORT; |
1519 vl->flags |= VL_RESORT; |
1530 vl->sort_type = e->dropdown.index; |
1520 vl->sort_type = e->dropdown.index; |
1531 _sorting.train.criteria = vl->sort_type; |
1521 _sorting.train.criteria = vl->sort_type; |
1532 |
1522 |
1533 // enable 'Sort By' if a sorter criteria is chosen |
1523 // enable 'Sort By' if a sorter criteria is chosen |
1534 if (vl->sort_type != SORT_BY_UNSORTED) |
1524 if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3); |
1535 CLRBIT(w->disabled_state, 3); |
|
1536 } |
1525 } |
1537 SetWindowDirty(w); |
1526 SetWindowDirty(w); |
1538 break; |
1527 break; |
1539 |
1528 |
1540 case WE_CREATE: /* set up resort timer */ |
1529 case WE_CREATE: /* set up resort timer */ |
1590 if (player == _local_player) { |
1579 if (player == _local_player) { |
1591 w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | player); |
1580 w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | player); |
1592 } else { |
1581 } else { |
1593 w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player); |
1582 w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player); |
1594 } |
1583 } |
1595 if (w) { |
1584 if (w != NULL) { |
1596 w->caption_color = player; |
1585 w->caption_color = player; |
1597 w->hscroll.cap = 10 * 29; |
1586 w->hscroll.cap = 10 * 29; |
1598 w->vscroll.cap = 7; // maximum number of vehicles shown |
1587 w->vscroll.cap = 7; // maximum number of vehicles shown |
1599 w->widget[7].unkA = (w->vscroll.cap << 8) + 1; |
1588 w->widget[7].unkA = (w->vscroll.cap << 8) + 1; |
1600 w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL; |
1589 w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL; |