2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "town.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "viewport.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "waypoint.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-22 06:39:32 +00:00
|
|
|
static int OrderGetSel(const Window* w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-22 06:39:32 +00:00
|
|
|
const Vehicle* v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
int num = WP(w,order_d).sel;
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (num < 0 || num > v->num_orders)
|
|
|
|
return v->num_orders;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
return num;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-15 16:58:15 +00:00
|
|
|
static StringID StationOrderStrings[] = {
|
2005-06-15 17:18:32 +00:00
|
|
|
STR_8806_GO_TO,
|
2005-06-15 16:58:15 +00:00
|
|
|
STR_8807_GO_TO_TRANSFER,
|
|
|
|
STR_8808_GO_TO_UNLOAD,
|
|
|
|
STR_8809_GO_TO_TRANSFER_UNLOAD,
|
|
|
|
STR_880A_GO_TO_LOAD,
|
|
|
|
STR_880B_GO_TO_TRANSFER_LOAD,
|
|
|
|
STR_NULL,
|
|
|
|
STR_NULL,
|
|
|
|
STR_880C_GO_NON_STOP_TO,
|
|
|
|
STR_880D_GO_TO_NON_STOP_TRANSFER,
|
|
|
|
STR_880E_GO_NON_STOP_TO_UNLOAD,
|
|
|
|
STR_880F_GO_TO_NON_STOP_TRANSFER_UNLOAD,
|
|
|
|
STR_8810_GO_NON_STOP_TO_LOAD,
|
|
|
|
STR_8811_GO_TO_NON_STOP_TRANSFER_LOAD,
|
|
|
|
STR_NULL
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void DrawOrdersWindow(Window *w)
|
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
const Vehicle *v;
|
|
|
|
const Order *order;
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
2005-01-15 19:06:22 +00:00
|
|
|
int sel;
|
|
|
|
int y, i;
|
|
|
|
bool shared_orders;
|
|
|
|
byte color;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-12 22:09:21 +00:00
|
|
|
w->disabled_state = (v->owner == _local_player) ? 0 : (
|
|
|
|
1 << 4 | //skip
|
|
|
|
1 << 5 | //delete
|
|
|
|
1 << 6 | //non-stop
|
|
|
|
1 << 7 | //go-to
|
|
|
|
1 << 8 | //full load
|
2005-06-15 16:58:15 +00:00
|
|
|
1 << 9 | //unload
|
|
|
|
1 << 10 //transfer
|
2005-01-12 22:09:21 +00:00
|
|
|
);
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
if (v->type != VEH_Train)
|
|
|
|
SETBIT(w->disabled_state, 6); //disable non-stop for non-trains
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
shared_orders = IsOrderListShared(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-23 19:00:16 +00:00
|
|
|
if ((uint)v->num_orders + (shared_orders?1:0) <= (uint)WP(w,order_d).sel)
|
2004-08-09 17:04:08 +00:00
|
|
|
SETBIT(w->disabled_state, 5); /* delete */
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (v->num_orders == 0)
|
2004-08-09 17:04:08 +00:00
|
|
|
SETBIT(w->disabled_state, 4); /* skip */
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
SetVScrollCount(w, v->num_orders + 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
sel = OrderGetSel(w);
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(2, STR_8827_FULL_LOAD);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
order = GetVehicleOrder(v, sel);
|
2004-12-19 21:03:16 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (order != NULL) {
|
|
|
|
switch (order->type) {
|
|
|
|
case OT_GOTO_STATION:
|
|
|
|
break;
|
|
|
|
case OT_GOTO_DEPOT:
|
|
|
|
SETBIT(w->disabled_state, 9); /* unload */
|
2005-06-15 16:58:15 +00:00
|
|
|
SETBIT(w->disabled_state, 10); /* transfer */
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(2,STR_SERVICE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OT_GOTO_WAYPOINT:
|
|
|
|
SETBIT(w->disabled_state, 8); /* full load */
|
|
|
|
SETBIT(w->disabled_state, 9); /* unload */
|
2005-06-15 16:58:15 +00:00
|
|
|
SETBIT(w->disabled_state, 10); /* transfer */
|
2005-01-15 19:06:22 +00:00
|
|
|
break;
|
2004-12-19 21:03:16 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
default:
|
|
|
|
SETBIT(w->disabled_state, 6); /* nonstop */
|
|
|
|
SETBIT(w->disabled_state, 8); /* full load */
|
|
|
|
SETBIT(w->disabled_state, 9); /* unload */
|
|
|
|
}
|
|
|
|
} else {
|
2004-08-09 17:04:08 +00:00
|
|
|
SETBIT(w->disabled_state, 6); /* nonstop */
|
|
|
|
SETBIT(w->disabled_state, 8); /* full load */
|
2004-09-10 19:02:27 +00:00
|
|
|
SETBIT(w->disabled_state, 9); /* unload */
|
2005-06-15 16:58:15 +00:00
|
|
|
SETBIT(w->disabled_state, 10); /* transfer */
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->string_id);
|
|
|
|
SetDParam(1, v->unitnumber);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
y = 15;
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
i = w->vscroll.pos;
|
|
|
|
order = GetVehicleOrder(v, i);
|
|
|
|
while (order != NULL) {
|
|
|
|
str = (v->cur_order_index == i) ? STR_8805 : STR_8804;
|
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
if (i - w->vscroll.pos < w->vscroll.cap) {
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(1, 6);
|
|
|
|
|
|
|
|
if (order->type == OT_GOTO_STATION) {
|
2005-06-15 16:58:15 +00:00
|
|
|
SetDParam(1, StationOrderStrings[order->flags]);
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(2, order->station);
|
|
|
|
} else if (order->type == OT_GOTO_DEPOT) {
|
|
|
|
StringID s = STR_NULL;
|
2005-06-15 16:58:15 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (v->type == VEH_Aircraft) {
|
|
|
|
s = STR_GO_TO_AIRPORT_HANGAR;
|
|
|
|
SetDParam(2, order->station);
|
|
|
|
} else {
|
2005-02-06 10:18:47 +00:00
|
|
|
SetDParam(2, GetDepot(order->station)->town_index);
|
2005-06-15 16:58:15 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
switch (v->type) {
|
2005-06-15 16:58:15 +00:00
|
|
|
case VEH_Train: s = STR_GO_TO_TRAIN_DEPOT; break;
|
2005-01-15 19:06:22 +00:00
|
|
|
case VEH_Road: s = STR_9038_GO_TO_ROADVEH_DEPOT; break;
|
|
|
|
case VEH_Ship: s = STR_GO_TO_SHIP_DEPOT; break;
|
2005-05-02 23:59:11 +00:00
|
|
|
default:
|
|
|
|
break;
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
2005-06-15 16:58:15 +00:00
|
|
|
|
|
|
|
if (v->type == VEH_Train && order->flags & OF_NON_STOP) s += 2;
|
|
|
|
SetDParam(1, s);
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (order->flags & OF_FULL_LOAD)
|
2005-06-15 16:58:15 +00:00
|
|
|
s++; /* service at */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(1, s);
|
|
|
|
} else if (order->type == OT_GOTO_WAYPOINT) {
|
|
|
|
SetDParam(1, (order->flags & OF_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
|
|
|
|
SetDParam(2, order->station);
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
color = (i == WP(w,order_d).sel) ? 0xC : 0x10;
|
|
|
|
SetDParam(0, i + 1);
|
|
|
|
if (order->type != OT_DUMMY) {
|
|
|
|
DrawString(2, y, str, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(1, STR_INVALID_ORDER);
|
|
|
|
SetDParam(2, order->station);
|
|
|
|
DrawString(2, y, str, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
2005-01-15 19:06:22 +00:00
|
|
|
order = order->next;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
if (i - w->vscroll.pos < w->vscroll.cap) {
|
2005-01-15 19:06:22 +00:00
|
|
|
str = shared_orders ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
|
|
|
|
color = (i == WP(w,order_d).sel) ? 0xC : 0x10;
|
|
|
|
DrawString(2, y, str, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-05 21:30:58 +00:00
|
|
|
Order order;
|
2004-08-09 17:04:08 +00:00
|
|
|
Station *st;
|
|
|
|
int st_index;
|
|
|
|
|
|
|
|
// check depot first
|
|
|
|
if (_patches.gotodepot) {
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case MP_RAILWAY:
|
2005-06-04 11:56:32 +00:00
|
|
|
if (v->type == VEH_Train && IsTileOwner(tile, _local_player)) {
|
2005-07-13 18:04:01 +00:00
|
|
|
if ((_m[tile].m5&0xFC)==0xC0) {
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_DEPOT;
|
2005-03-20 08:43:29 +00:00
|
|
|
order.flags = OF_PART_OF_ORDERS;
|
2005-02-06 10:18:47 +00:00
|
|
|
order.station = GetDepotByTile(tile)->index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-12-06 00:03:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_STREET:
|
2005-07-13 18:04:01 +00:00
|
|
|
if ((_m[tile].m5 & 0xF0) == 0x20 && v->type == VEH_Road && IsTileOwner(tile, _local_player)) {
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_DEPOT;
|
2005-03-20 08:43:29 +00:00
|
|
|
order.flags = OF_PART_OF_ORDERS;
|
2005-02-06 10:18:47 +00:00
|
|
|
order.station = GetDepotByTile(tile)->index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-12-06 00:03:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_STATION:
|
|
|
|
if (v->type != VEH_Aircraft) break;
|
2005-06-04 11:56:32 +00:00
|
|
|
if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_DEPOT;
|
2005-03-20 08:43:29 +00:00
|
|
|
order.flags = OF_PART_OF_ORDERS | OF_NON_STOP; //XXX - whats the nonstop stuff doing here?
|
2005-07-13 18:04:01 +00:00
|
|
|
order.station = _m[tile].m2;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-12-06 00:03:26 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_WATER:
|
|
|
|
if (v->type != VEH_Ship) break;
|
2005-02-07 10:37:12 +00:00
|
|
|
if (IsTileDepotType(tile, TRANSPORT_WATER) &&
|
|
|
|
IsTileOwner(tile, _local_player)) {
|
2005-07-13 18:04:01 +00:00
|
|
|
switch (_m[tile].m5) {
|
2005-06-25 16:44:57 +00:00
|
|
|
case 0x81: tile -= TileDiffXY(1, 0); break;
|
|
|
|
case 0x83: tile -= TileDiffXY(0, 1); break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_DEPOT;
|
2005-03-20 08:43:29 +00:00
|
|
|
order.flags = OF_PART_OF_ORDERS;
|
2005-02-06 10:18:47 +00:00
|
|
|
order.station = GetDepotByTile(tile)->index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-29 15:12:40 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-14 13:07:07 +00:00
|
|
|
// check waypoint
|
2005-06-04 11:56:32 +00:00
|
|
|
if (IsTileType(tile, MP_RAILWAY) &&
|
|
|
|
v->type == VEH_Train &&
|
|
|
|
IsTileOwner(tile, _local_player) &&
|
2005-07-13 18:04:01 +00:00
|
|
|
(_m[tile].m5 & 0xFE) == 0xC4) {
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_GOTO_WAYPOINT;
|
|
|
|
order.flags = 0;
|
2005-03-24 17:03:37 +00:00
|
|
|
order.station = GetWaypointByTile(tile)->index;
|
2004-12-05 21:30:58 +00:00
|
|
|
return order;
|
|
|
|
}
|
2004-09-27 14:30:17 +00:00
|
|
|
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_STATION)) {
|
2005-07-13 18:04:01 +00:00
|
|
|
st = GetStation(st_index = _m[tile].m2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (st->owner == _current_player || st->owner == OWNER_NONE) {
|
|
|
|
byte facil;
|
|
|
|
(facil=FACIL_DOCK, v->type == VEH_Ship) ||
|
|
|
|
(facil=FACIL_TRAIN, v->type == VEH_Train) ||
|
|
|
|
(facil=FACIL_AIRPORT, v->type == VEH_Aircraft) ||
|
|
|
|
(facil=FACIL_BUS_STOP, v->type == VEH_Road && v->cargo_type == CT_PASSENGERS) ||
|
|
|
|
(facil=FACIL_TRUCK_STOP, 1);
|
2004-12-05 21:30:58 +00:00
|
|
|
if (st->facilities & facil) {
|
|
|
|
order.type = OT_GOTO_STATION;
|
|
|
|
order.flags = 0;
|
|
|
|
order.station = st_index;
|
|
|
|
return order;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// not found
|
2004-12-05 21:30:58 +00:00
|
|
|
order.type = OT_NOTHING;
|
|
|
|
order.flags = 0;
|
|
|
|
return order;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool HandleOrderVehClick(Vehicle *v, Vehicle *u, Window *w)
|
|
|
|
{
|
|
|
|
if (u->type != v->type)
|
|
|
|
return false;
|
|
|
|
|
2005-01-19 19:15:03 +00:00
|
|
|
if (u->type == VEH_Train && u->subtype != TS_Front_Engine) {
|
2004-08-09 17:04:08 +00:00
|
|
|
u = GetFirstVehicleInChain(u);
|
2005-01-19 19:15:03 +00:00
|
|
|
if (u->subtype != TS_Front_Engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
|
|
|
|
// obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
|
|
|
|
if (v->num_orders != 0 && _ctrl_pressed == 0) {return false;}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (DoCommandP(v->tile, v->index | (u->index << 16), _ctrl_pressed ? 0 : 1, NULL,
|
|
|
|
_ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
|
|
|
|
WP(w,order_d).sel = -1;
|
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void OrdersPlaceObj(Vehicle *v, TileIndex tile, Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-05 21:30:58 +00:00
|
|
|
Order cmd;
|
2004-08-09 17:04:08 +00:00
|
|
|
Vehicle *u;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// check if we're clicking on a vehicle first.. clone orders in that case.
|
|
|
|
u = CheckMouseOverVehicle();
|
|
|
|
if (u && HandleOrderVehClick(v, u, w))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cmd = GetOrderCmdFromTile(v, tile);
|
2004-12-05 21:30:58 +00:00
|
|
|
if (cmd.type == OT_NOTHING) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-05 21:30:58 +00:00
|
|
|
if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), PackOrder(&cmd), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (WP(w,order_d).sel != -1)
|
|
|
|
WP(w,order_d).sel++;
|
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-13 16:55:17 +00:00
|
|
|
static void OrderClick_Goto(Window *w, Vehicle *v)
|
|
|
|
{
|
|
|
|
InvalidateWidget(w, 7);
|
|
|
|
TOGGLEBIT(w->click_state, 7);
|
|
|
|
if (HASBIT(w->click_state, 7)) {
|
|
|
|
_place_clicked_vehicle = NULL;
|
|
|
|
SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, 1, w);
|
|
|
|
} else {
|
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void OrderClick_FullLoad(Window *w, Vehicle *v)
|
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_FULL_LOAD, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void OrderClick_Unload(Window *w, Vehicle *v)
|
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_UNLOAD, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
static void OrderClick_Nonstop(Window *w, Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_NON_STOP, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2005-06-15 16:58:15 +00:00
|
|
|
static void OrderClick_Transfer(Window *w, Vehicle *v)
|
|
|
|
{
|
|
|
|
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_TRANSFER, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
static void OrderClick_Skip(Window *w, Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_SKIP_ORDER);
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
static void OrderClick_Delete(Window *w, Vehicle *v)
|
2005-01-13 16:55:17 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(v->tile, v->index, OrderGetSel(w), NULL, CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER));
|
2005-01-13 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef void OnButtonClick(Window *w, Vehicle *v);
|
|
|
|
|
|
|
|
static OnButtonClick * const _order_button_proc[] = {
|
|
|
|
OrderClick_Skip,
|
|
|
|
OrderClick_Delete,
|
|
|
|
OrderClick_Nonstop,
|
|
|
|
OrderClick_Goto,
|
|
|
|
OrderClick_FullLoad,
|
2005-06-15 16:58:15 +00:00
|
|
|
OrderClick_Unload,
|
|
|
|
OrderClick_Transfer
|
2005-01-13 16:55:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint16 _order_keycodes[] = {
|
|
|
|
'D', //skip order
|
|
|
|
'F', //delete order
|
|
|
|
'G', //non-stop
|
|
|
|
'H', //goto order
|
|
|
|
'J', //full load
|
|
|
|
'K' //unload
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void OrdersWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch(e->event) {
|
|
|
|
case WE_PAINT:
|
|
|
|
DrawOrdersWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
2005-01-06 22:31:58 +00:00
|
|
|
Vehicle *v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
switch(e->click.widget) {
|
2005-01-30 23:41:57 +00:00
|
|
|
case 2: { /* orders list */
|
2004-08-09 17:04:08 +00:00
|
|
|
int sel;
|
|
|
|
sel = (e->click.pt.y - 15) / 10;
|
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
if ((uint)sel >= w->vscroll.cap)
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
sel += w->vscroll.pos;
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (_ctrl_pressed && sel < v->num_orders) {
|
2005-01-16 14:42:53 +00:00
|
|
|
const Order *ord = GetVehicleOrder(v, sel);
|
2004-08-13 20:30:45 +00:00
|
|
|
int xy = 0;
|
2005-01-15 19:06:22 +00:00
|
|
|
switch (ord->type) {
|
2004-08-13 20:30:45 +00:00
|
|
|
case OT_GOTO_STATION: /* station order */
|
2005-01-15 19:06:22 +00:00
|
|
|
xy = GetStation(ord->station)->xy ;
|
2004-08-13 20:30:45 +00:00
|
|
|
break;
|
|
|
|
case OT_GOTO_DEPOT: /* goto depot order */
|
2005-02-06 10:18:47 +00:00
|
|
|
xy = GetDepot(ord->station)->xy;
|
2004-08-13 20:30:45 +00:00
|
|
|
break;
|
2004-11-14 13:07:07 +00:00
|
|
|
case OT_GOTO_WAYPOINT: /* goto waypoint order */
|
2005-03-24 17:03:37 +00:00
|
|
|
xy = GetWaypoint(ord->station)->xy;
|
2004-08-13 20:30:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xy)
|
|
|
|
ScrollMainWindowToTile(xy);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-13 20:30:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (sel == WP(w,order_d).sel) sel = -1;
|
|
|
|
WP(w,order_d).sel = sel;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 4: /* skip button */
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Skip(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 5: /* delete button */
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Delete(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2005-01-13 16:55:17 +00:00
|
|
|
case 6: /* non stop button */
|
|
|
|
OrderClick_Nonstop(w, v);
|
|
|
|
break;
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case 7: /* goto button */
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Goto(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8: /* full load button */
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_FullLoad(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 9: /* unload button */
|
2005-01-13 16:55:17 +00:00
|
|
|
OrderClick_Unload(w, v);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-06-15 16:58:15 +00:00
|
|
|
case 10: /* transfer button */
|
|
|
|
OrderClick_Transfer(w, v);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2005-01-13 16:55:17 +00:00
|
|
|
case WE_KEYPRESS: {
|
|
|
|
Vehicle *v = GetVehicle(w->window_number);
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
for(i = 0; i < lengthof(_order_keycodes); i++) {
|
|
|
|
if (e->keypress.keycode == _order_keycodes[i]) {
|
|
|
|
e->keypress.cont = false;
|
2005-01-15 08:58:31 +00:00
|
|
|
//see if the button is disabled
|
2005-01-13 16:55:17 +00:00
|
|
|
if (!(HASBIT(w->disabled_state, (i + 4)))) {
|
|
|
|
_order_button_proc[i](w, v);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_RCLICK: {
|
2005-01-06 22:31:58 +00:00
|
|
|
Vehicle *v = GetVehicle(w->window_number);
|
2005-02-01 09:47:18 +00:00
|
|
|
int sel = OrderGetSel(w);
|
|
|
|
if (e->click.widget != 8) break;
|
|
|
|
if (sel == v->num_orders || GetVehicleOrder(v, sel)->type != OT_GOTO_DEPOT)
|
2004-08-09 17:04:08 +00:00
|
|
|
GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER);
|
2005-02-01 09:47:18 +00:00
|
|
|
else
|
|
|
|
GuiShowTooltips(STR_SERVICE_HINT);
|
2005-01-30 23:41:57 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_4: {
|
|
|
|
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL)
|
|
|
|
DeleteWindow(w);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_PLACE_OBJ: {
|
2005-01-06 22:31:58 +00:00
|
|
|
OrdersPlaceObj(GetVehicle(w->window_number), e->place.tile, w);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ: {
|
2005-01-30 23:41:57 +00:00
|
|
|
CLRBIT(w->click_state, 7);
|
2004-08-09 17:04:08 +00:00
|
|
|
InvalidateWidget(w, 7);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
// check if a vehicle in a depot was clicked..
|
|
|
|
case WE_MOUSELOOP: {
|
|
|
|
Vehicle *v = _place_clicked_vehicle;
|
2004-08-12 17:11:47 +00:00
|
|
|
/*
|
|
|
|
* Check if we clicked on a vehicle
|
|
|
|
* and if the GOTO button of this window is pressed
|
|
|
|
* This is because of all open order windows WE_MOUSELOOP is called
|
|
|
|
* and if you have 3 windows open, and this check is not done
|
|
|
|
* the order is copied to the last open window instead of the
|
|
|
|
* one where GOTO is enalbed
|
|
|
|
*/
|
2005-01-30 23:41:57 +00:00
|
|
|
if (v != NULL && HASBIT(w->click_state, 7)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_place_clicked_vehicle = NULL;
|
2005-01-06 22:31:58 +00:00
|
|
|
HandleOrderVehClick(GetVehicle(w->window_number), v, w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
case WE_RESIZE:
|
|
|
|
/* Update the scroll + matrix */
|
|
|
|
w->vscroll.cap = (w->widget[2].bottom - w->widget[2].top) / 10;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
}
|
2005-01-13 16:55:17 +00:00
|
|
|
|
2005-01-21 18:36:17 +00:00
|
|
|
static const Widget _orders_train_widgets[] = {
|
2005-01-30 23:41:57 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-06-15 16:58:15 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 384, 0, 13, STR_8829_ORDERS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 372, 14, 75, 0x0, STR_8852_ORDERS_LIST_CLICK_ON_ORDER},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 373, 384, 14, 75, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-01-30 23:41:57 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 52, 76, 87, STR_8823_SKIP, STR_8853_SKIP_THE_CURRENT_ORDER},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 53, 105, 76, 87, STR_8824_DELETE, STR_8854_DELETE_THE_HIGHLIGHTED},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 106, 158, 76, 87, STR_8825_NON_STOP, STR_8855_MAKE_THE_HIGHLIGHTED_ORDER},
|
|
|
|
{WWT_NODISTXTBTN, RESIZE_TB, 14, 159, 211, 76, 87, STR_8826_GO_TO, STR_8856_INSERT_A_NEW_ORDER_BEFORE},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 212, 264, 76, 87, STR_FULLLOAD_OR_SERVICE, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 265, 319, 76, 87, STR_8828_UNLOAD, STR_8858_MAKE_THE_HIGHLIGHTED_ORDER},
|
2005-06-15 16:58:15 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 320, 372, 76, 87, STR_886F_TRANSFER, STR_886D_MAKE_THE_HIGHLIGHTED_ORDER},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 373, 372, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 373, 384, 76, 87, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-01-21 18:36:17 +00:00
|
|
|
static const WindowDesc _orders_train_desc = {
|
2005-06-15 16:58:15 +00:00
|
|
|
-1,-1, 385, 88,
|
2005-01-21 18:36:17 +00:00
|
|
|
WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
|
2005-07-15 15:09:52 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2005-01-21 18:36:17 +00:00
|
|
|
_orders_train_widgets,
|
|
|
|
OrdersWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _orders_widgets[] = {
|
2005-01-30 23:41:57 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-06-15 16:58:15 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 395, 0, 13, STR_8829_ORDERS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 383, 14, 75, 0x0, STR_8852_ORDERS_LIST_CLICK_ON_ORDER},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 384, 395, 14, 75, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-01-30 23:41:57 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 63, 76, 87, STR_8823_SKIP, STR_8853_SKIP_THE_CURRENT_ORDER},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 64, 128, 76, 87, STR_8824_DELETE, STR_8854_DELETE_THE_HIGHLIGHTED},
|
|
|
|
{ WWT_EMPTY, RESIZE_TB, 14, 0, 0, 76, 87, 0x0, 0x0},
|
|
|
|
{WWT_NODISTXTBTN, RESIZE_TB, 14, 129, 192, 76, 87, STR_8826_GO_TO, STR_8856_INSERT_A_NEW_ORDER_BEFORE},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 193, 256, 76, 87, STR_FULLLOAD_OR_SERVICE, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 257, 319, 76, 87, STR_8828_UNLOAD, STR_8858_MAKE_THE_HIGHLIGHTED_ORDER},
|
2005-06-15 16:58:15 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 320, 383, 76, 87, STR_886F_TRANSFER, STR_886D_MAKE_THE_HIGHLIGHTED_ORDER},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 384, 383, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 384, 395, 76, 87, 0x0, STR_RESIZE_BUTTON},
|
2005-01-21 18:36:17 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
|
2005-01-12 22:09:21 +00:00
|
|
|
static const WindowDesc _orders_desc = {
|
2005-06-15 16:58:15 +00:00
|
|
|
-1,-1, 396, 88,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
|
2005-07-15 15:09:52 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2005-01-12 22:09:21 +00:00
|
|
|
_orders_widgets,
|
2004-08-09 17:04:08 +00:00
|
|
|
OrdersWndProc
|
|
|
|
};
|
|
|
|
|
2005-01-12 22:09:21 +00:00
|
|
|
static const Widget _other_orders_widgets[] = {
|
2005-01-30 23:41:57 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 331, 0, 13, STR_A00B_ORDERS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 319, 14, 75, 0x0, STR_8852_ORDERS_LIST_CLICK_ON_ORDER},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 320, 331, 14, 75, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 14, 0, 319, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 0, 319, 76, 87, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 320, 331, 76, 87, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-01-12 22:09:21 +00:00
|
|
|
static const WindowDesc _other_orders_desc = {
|
2005-01-30 23:41:57 +00:00
|
|
|
-1,-1, 332, 88,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
|
2005-01-30 23:41:57 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2005-01-12 22:09:21 +00:00
|
|
|
_other_orders_widgets,
|
2004-08-09 17:04:08 +00:00
|
|
|
OrdersWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowOrdersWindow(Vehicle *v)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
VehicleID veh = v->index;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, veh);
|
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, veh);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_alloc_wnd_parent_num = veh;
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2005-01-21 18:36:17 +00:00
|
|
|
if (v->owner != _local_player) {
|
|
|
|
w = AllocateWindowDesc( &_other_orders_desc);
|
2005-01-30 23:41:57 +00:00
|
|
|
} else
|
2005-01-21 18:36:17 +00:00
|
|
|
w = AllocateWindowDesc( (v->type == VEH_Train) ? &_orders_train_desc : &_orders_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-30 23:41:57 +00:00
|
|
|
if (w != NULL) {
|
|
|
|
w->window_number = veh;
|
|
|
|
w->caption_color = v->owner;
|
|
|
|
w->vscroll.cap = 6;
|
|
|
|
w->resize.step_height = 10;
|
|
|
|
WP(w,order_d).sel = -1;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|