order_gui.c
author celestar
Wed, 12 Jan 2005 22:09:21 +0000
changeset 995 96e9f70280d7
parent 919 b0d6c7642f99
child 1000 a418026097f6
permissions -rw-r--r--
(svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
of the code written 4 - 8 times in the code.
This currently causes the "non-stop" button to appear for all
vehicles, which is disabled all the time. Don't report this as a bug
please.
This is (hopefully) the first patch in a joint effort to simplify
the order system
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
#include "ttd.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 395
diff changeset
     3
#include "table/strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 560
diff changeset
     4
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "gui.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
static int OrderGetSel(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
{
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
    16
	Vehicle *v = GetVehicle(w->window_number);
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    17
	const Order *sched = v->schedule_ptr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
	int num = WP(w,order_d).sel;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
	int count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
	if (num == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    24
	while (sched->type != OT_NOTHING) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
		sched++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
		count++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
		if (--num == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	return count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
static void DrawOrdersWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	int num, sel;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    38
	const Order *sched;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    39
	Order ord;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	int y, i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	bool shared_schedule;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
    44
	v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
995
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    46
	w->disabled_state = (v->owner == _local_player) ? 0 : (
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    47
		1 << 4 |   //skip
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    48
		1 << 5 |   //delete
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    49
		1 << 6 |   //non-stop
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    50
		1 << 7 |   //go-to
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    51
		1 << 8 |   //full load
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    52
		1 << 9     //unload
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    53
		);
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    54
		
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    55
	//disable non-stop for non-trains
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    56
	if (v->type != VEH_Train) {
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    57
		w->disabled_state |= 1 << 6;
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
    58
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	shared_schedule = IsScheduleShared(v) != NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	sched = v->schedule_ptr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	num=0;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    64
	while (sched->type != OT_NOTHING) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    65
		sched++;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    66
		num++;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    67
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
	if ((uint)num + shared_schedule <= (uint)WP(w,order_d).sel)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
		SETBIT(w->disabled_state, 5); /* delete */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	if (num == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
		SETBIT(w->disabled_state, 4); /* skip */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	SetVScrollCount(w, num+1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	sel = OrderGetSel(w);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    78
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    79
	SetDParam(2,STR_8827_FULL_LOAD);
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
    80
	switch (v->schedule_ptr[sel].type) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
	case OT_GOTO_STATION:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	case OT_GOTO_DEPOT:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
		SETBIT(w->disabled_state, 9);	/* unload */
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    85
		SetDParam(2,STR_SERVICE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
		break;
725
d6543c8b2428 (svn r1177) Enable non-stop flag for waypoints
tron
parents: 679
diff changeset
    87
d6543c8b2428 (svn r1177) Enable non-stop flag for waypoints
tron
parents: 679
diff changeset
    88
	case OT_GOTO_WAYPOINT:
d6543c8b2428 (svn r1177) Enable non-stop flag for waypoints
tron
parents: 679
diff changeset
    89
		SETBIT(w->disabled_state, 8); /* full load */
d6543c8b2428 (svn r1177) Enable non-stop flag for waypoints
tron
parents: 679
diff changeset
    90
		SETBIT(w->disabled_state, 9); /* unload */
d6543c8b2428 (svn r1177) Enable non-stop flag for waypoints
tron
parents: 679
diff changeset
    91
		break;
d6543c8b2428 (svn r1177) Enable non-stop flag for waypoints
tron
parents: 679
diff changeset
    92
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
		SETBIT(w->disabled_state, 6); /* nonstop */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
		SETBIT(w->disabled_state, 8);	/* full load */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    96
		SETBIT(w->disabled_state, 9);	/* unload */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
    99
	SetDParam(0, v->string_id);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   100
	SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	DrawWindowWidgets(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	y = 15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
	i = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
		str = ((byte)v->cur_order_index == i) ? STR_8805 : STR_8804;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   108
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		ord = v->schedule_ptr[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
		if ( (uint)(i - w->vscroll.pos) < 6) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   112
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   113
			if (ord.type == OT_NOTHING) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
				str = shared_schedule ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
			} else {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   116
				SetDParam(1, 6);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   118
				if (ord.type == OT_GOTO_STATION) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   119
					SetDParam(1, STR_8806_GO_TO + (ord.flags >> 1));
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   120
					SetDParam(2, ord.station);
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   121
				} else if (ord.type == OT_GOTO_DEPOT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
					StringID s = STR_NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
					if (v->type == VEH_Aircraft) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
						s = STR_GO_TO_AIRPORT_HANGAR;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   125
					  SetDParam(2, ord.station);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
					} else {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   127
						SetDParam(2, _depots[ord.station].town_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
						switch (v->type) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
						case VEH_Train:	s = STR_880E_GO_TO_TRAIN_DEPOT; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
						case VEH_Road:	s = STR_9038_GO_TO_ROADVEH_DEPOT; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
						case VEH_Ship:	s = STR_GO_TO_SHIP_DEPOT; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
					}
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   134
					if (v->type == VEH_Train && ord.flags & OF_NON_STOP) s += 2;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   135
					if (ord.flags & OF_FULL_LOAD) ++s; /* XXX service */
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   136
					SetDParam(1, s);
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   137
				} else if (ord.type == OT_GOTO_WAYPOINT) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   138
					SetDParam(2, ord.station);
725
d6543c8b2428 (svn r1177) Enable non-stop flag for waypoints
tron
parents: 679
diff changeset
   139
					SetDParam(1, (ord.flags & OF_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
				byte color = (i == WP(w,order_d).sel) ? 0xC : 0x10;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   144
				SetDParam(0, i+1);
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   145
				if (ord.type != OT_DUMMY) {
127
815ec4d365e2 (svn r128) Invalid (void) orders in schedule are highlighted in red (Celestar)
dominik
parents: 44
diff changeset
   146
					DrawString(2, y, str, color);
815ec4d365e2 (svn r128) Invalid (void) orders in schedule are highlighted in red (Celestar)
dominik
parents: 44
diff changeset
   147
				} else {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   148
					SetDParam(1, STR_INVALID_ORDER);
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   149
					SetDParam(2, ord.station);
127
815ec4d365e2 (svn r128) Invalid (void) orders in schedule are highlighted in red (Celestar)
dominik
parents: 44
diff changeset
   150
					DrawString(2, y, str, color);
815ec4d365e2 (svn r128) Invalid (void) orders in schedule are highlighted in red (Celestar)
dominik
parents: 44
diff changeset
   151
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
			y += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
		i++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   158
		if (ord.type == OT_NOTHING)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
// lookup a vehicle on a tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
typedef struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	TileIndex tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	byte owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	byte type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
} FindVehS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
static void *FindVehicleCallb(Vehicle *v, FindVehS *f)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	if (v->tile != f->tile || v->owner != f->owner || v->vehstatus & VS_HIDDEN ) return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	return v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   175
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
Vehicle *GetVehicleOnTile(TileIndex tile, byte owner)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
{
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 725
diff changeset
   179
	FindVehS fs;
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 725
diff changeset
   180
	fs.tile = tile;
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 725
diff changeset
   181
	fs.owner = owner;
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 725
diff changeset
   182
	fs.type = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	return VehicleFromPos(tile, &fs, (VehicleFromPosProc*)FindVehicleCallb);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   186
static Order GetOrderCmdFromTile(Vehicle *v, uint tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
{
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   188
	Order order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
	int st_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	// check depot first
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
	if (_patches.gotodepot) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
		switch(GET_TILETYPE(tile)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
		case MP_RAILWAY:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
			if (v->type == VEH_Train && _map_owner[tile] == _local_player) {
560
bd8a572dc8b9 (svn r962) Fixed a problem with the new order system due to missing '{}' (another place)
Celestar
parents: 559
diff changeset
   197
				if ((_map5[tile]&0xFC)==0xC0) {
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   198
					order.type = OT_GOTO_DEPOT;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   199
					order.flags = OF_UNLOAD;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   200
					order.station = GetDepotByTile(tile);
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   201
					return order;
560
bd8a572dc8b9 (svn r962) Fixed a problem with the new order system due to missing '{}' (another place)
Celestar
parents: 559
diff changeset
   202
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		case MP_STREET:
560
bd8a572dc8b9 (svn r962) Fixed a problem with the new order system due to missing '{}' (another place)
Celestar
parents: 559
diff changeset
   207
			if ((_map5[tile] & 0xF0) == 0x20 && v->type == VEH_Road && _map_owner[tile] == _local_player) {
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   208
				order.type = OT_GOTO_DEPOT;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   209
				order.flags = OF_UNLOAD;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   210
				order.station = GetDepotByTile(tile);
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   211
				return order;
560
bd8a572dc8b9 (svn r962) Fixed a problem with the new order system due to missing '{}' (another place)
Celestar
parents: 559
diff changeset
   212
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		case MP_STATION:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
			if (v->type != VEH_Aircraft) break;
559
2003549c0ddb (svn r961) Fixed a problem with the new order system due to missing '{}'
Celestar
parents: 558
diff changeset
   217
			if ( IsAircraftHangarTile(tile) && _map_owner[tile] == _local_player) {
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   218
				order.type = OT_GOTO_DEPOT;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   219
				order.flags = OF_UNLOAD | OF_NON_STOP;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   220
				order.station = _map2[tile];
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   221
				return order;
560
bd8a572dc8b9 (svn r962) Fixed a problem with the new order system due to missing '{}' (another place)
Celestar
parents: 559
diff changeset
   222
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
		case MP_WATER:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
			if (v->type != VEH_Ship) break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
			if ( IsShipDepotTile(tile) && _map_owner[tile] == _local_player) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
				switch (_map5[tile]) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
				case 0x81: tile--; break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
				case 0x83: tile-= TILE_XY(0,1); break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
				}
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   232
				order.type = OT_GOTO_DEPOT;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   233
				order.flags = OF_UNLOAD;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   234
				order.station = GetDepotByTile(tile);
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   235
				return order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 319
diff changeset
   240
	// check waypoint
319
1891d07574d6 (svn r329) Fix: [ 1035066 ] 'Allow goto depot' turned off, no checkpoints in orders
dominik
parents: 193
diff changeset
   241
	if (IS_TILETYPE(tile, MP_RAILWAY)
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   242
	&& v->type == VEH_Train
319
1891d07574d6 (svn r329) Fix: [ 1035066 ] 'Allow goto depot' turned off, no checkpoints in orders
dominik
parents: 193
diff changeset
   243
	&& _map_owner[tile] == _local_player
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   244
	&& (_map5[tile]&0xFE)==0xC4) {
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   245
		order.type = OT_GOTO_WAYPOINT;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   246
		order.flags = 0;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   247
		order.station = GetWaypointByTile(tile);
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   248
		return order;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   249
	}
319
1891d07574d6 (svn r329) Fix: [ 1035066 ] 'Allow goto depot' turned off, no checkpoints in orders
dominik
parents: 193
diff changeset
   250
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	if (IS_TILETYPE(tile, MP_STATION)) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   252
		st = GetStation(st_index = _map2[tile]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		if (st->owner == _current_player || st->owner == OWNER_NONE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
			byte facil;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
			(facil=FACIL_DOCK, v->type == VEH_Ship) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			(facil=FACIL_TRAIN, v->type == VEH_Train) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			(facil=FACIL_AIRPORT, v->type == VEH_Aircraft) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
			(facil=FACIL_BUS_STOP, v->type == VEH_Road && v->cargo_type == CT_PASSENGERS) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
			(facil=FACIL_TRUCK_STOP, 1);
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   261
			if (st->facilities & facil) {
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   262
				order.type = OT_GOTO_STATION;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   263
				order.flags = 0;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   264
				order.station = st_index;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   265
				return order;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   266
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
	// not found
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   271
	order.type = OT_NOTHING;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   272
	order.flags = 0;
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   273
	return order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
static bool HandleOrderVehClick(Vehicle *v, Vehicle *u, Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	if (u->type != v->type)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	if (u->type == VEH_Train && u->subtype != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
		u = GetFirstVehicleInChain(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
		if (u->subtype != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	// v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	// obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	if (v->num_orders != 0 && _ctrl_pressed == 0) {return false;}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   290
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	if (DoCommandP(v->tile, v->index | (u->index << 16), _ctrl_pressed ? 0 : 1, NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		_ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		WP(w,order_d).sel = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
static void OrdersPlaceObj(Vehicle *v, uint tile, Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
{
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   302
	Order cmd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	Vehicle *u;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   304
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	// check if we're clicking on a vehicle first.. clone orders in that case.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	u = CheckMouseOverVehicle();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	if (u && HandleOrderVehClick(v, u, w))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	cmd = GetOrderCmdFromTile(v, tile);
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   311
	if (cmd.type == OT_NOTHING) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
558
9b115b39c515 (svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents: 555
diff changeset
   313
	if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), PackOrder(&cmd), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
		if (WP(w,order_d).sel != -1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
			WP(w,order_d).sel++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
static void OrdersWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	switch(e->event) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
	case WE_PAINT:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
		DrawOrdersWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	case WE_CLICK: {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   329
		Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
		int mode;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
		switch(e->click.widget) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   332
		case 2:	{/* orders list */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
			int sel;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
			sel = (e->click.pt.y - 15) / 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
			if ( (uint) sel >= 6)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
			sel += w->vscroll.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
44
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   341
			if (_ctrl_pressed && sel < v->num_orders) { // watch out for schedule_ptr overflow
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   342
				Order ord = v->schedule_ptr[sel];
44
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   343
				int xy = 0;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   344
				switch (ord.type) {
44
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   345
				case OT_GOTO_STATION:			/* station order */
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   346
					xy = GetStation(ord.station)->xy ;
44
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   347
					break;
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   348
				case OT_GOTO_DEPOT:				/* goto depot order */
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   349
					xy = _depots[ord.station].xy;
44
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   350
					break;
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 319
diff changeset
   351
				case OT_GOTO_WAYPOINT:	/* goto waypoint order */
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   352
					xy = _waypoints[ord.station].xy;
44
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   353
				}
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   354
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   355
				if (xy)
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   356
					ScrollMainWindowToTile(xy);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   357
44
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   358
				return;
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   359
			}
1923acc255d1 (svn r45) -Feature [992998] Scrollto Station in Orders. CTRL click on orders of a vehicle and main-window scrolls to that station. (chrishuebsch)
darkvater
parents: 25
diff changeset
   360
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
			if (sel == WP(w,order_d).sel) sel = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
			WP(w,order_d).sel = sel;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
		}	break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
		case 4: /* skip button */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
			DoCommandP(v->tile,v->index, 0, NULL, CMD_SKIP_ORDER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		case 5: /* delete button */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
			DoCommandP(v->tile,v->index, OrderGetSel(w), NULL, CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
		case 7: /* goto button */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			InvalidateWidget(w, 7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
			w->click_state ^= 1<<7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
			if (HASBIT(w->click_state, 7)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
				_place_clicked_vehicle = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
				SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, 1, w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
				ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
		case 8: /* full load button */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
			mode = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
			DoCommandP(v->tile, v->index, OrderGetSel(w) | (mode << 8), NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
		case 9: /* unload button */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
			mode = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
			DoCommandP(v->tile, v->index, OrderGetSel(w) | (mode << 8), NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		case 6: /* non stop button */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
			mode = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
			DoCommandP(v->tile, v->index, OrderGetSel(w) | (mode << 8), NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	case WE_RCLICK: {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   404
		Vehicle *v = GetVehicle(w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
		if (e->click.widget != 8) break;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 536
diff changeset
   406
		if (v->schedule_ptr[OrderGetSel(w)].type == OT_GOTO_DEPOT)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
			GuiShowTooltips(STR_SERVICE_HINT);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
		else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
			GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
	case WE_4: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
		if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
			DeleteWindow(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	case WE_PLACE_OBJ: {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   418
		OrdersPlaceObj(GetVehicle(w->window_number), e->place.tile, w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	case WE_ABORT_PLACE_OBJ: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
		w->click_state &= ~(1<<7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
		InvalidateWidget(w, 7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	// check if a vehicle in a depot was clicked..
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	case WE_MOUSELOOP: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
		Vehicle *v = _place_clicked_vehicle;
25
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   429
		/*
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   430
		 * Check if we clicked on a vehicle
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   431
		 * and if the GOTO button of this window is pressed
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   432
		 * This is because of all open order windows WE_MOUSELOOP is called
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   433
		 * and if you have 3 windows open, and this check is not done
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   434
		 * the order is copied to the last open window instead of the
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   435
		 * one where GOTO is enalbed
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   436
		 */
cf54d03fa22f (svn r26) Fix orderwindow issue
truelight
parents: 0
diff changeset
   437
		if (v && HASBIT(w->click_state, 7)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
			_place_clicked_vehicle = NULL;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 893
diff changeset
   439
			HandleOrderVehClick(GetVehicle(w->window_number), v, w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	} break;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   442
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
995
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
   446
static const Widget _orders_widgets[] = {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   447
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,								STR_018B_CLOSE_WINDOW},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   448
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   319,     0,    13, STR_8829_ORDERS,					STR_018C_WINDOW_TITLE_DRAG_THIS},
893
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 867
diff changeset
   449
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   307,    14,    75, 0x0,											STR_8852_ORDERS_LIST_CLICK_ON_ORDER},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 867
diff changeset
   450
{  WWT_SCROLLBAR,   RESIZE_NONE,    14,   308,   319,    14,    75, 0x0,											STR_0190_SCROLL_BAR_SCROLLS_LIST},
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   451
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    52,    76,    87, STR_8823_SKIP,						STR_8853_SKIP_THE_CURRENT_ORDER},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   452
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,    53,   105,    76,    87, STR_8824_DELETE,					STR_8854_DELETE_THE_HIGHLIGHTED},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   453
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   106,   158,    76,    87, STR_8825_NON_STOP,				STR_8855_MAKE_THE_HIGHLIGHTED_ORDER},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   454
{WWT_NODISTXTBTN,   RESIZE_NONE,    14,   159,   211,    76,    87, STR_8826_GO_TO,					STR_8856_INSERT_A_NEW_ORDER_BEFORE},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   455
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   212,   264,    76,    87, STR_FULLLOAD_OR_SERVICE,	STR_NULL},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   456
{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,   265,   319,    76,    87, STR_8828_UNLOAD,					STR_8858_MAKE_THE_HIGHLIGHTED_ORDER},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 127
diff changeset
   457
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
995
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
   460
static const WindowDesc _orders_desc = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	-1,-1, 320, 88,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESTORE_DPARAM,
995
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
   464
	_orders_widgets,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
	OrdersWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
995
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
   468
static const Widget _other_orders_widgets[] = {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   469
{    WWT_TEXTBTN,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,				STR_018B_CLOSE_WINDOW},
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 781
diff changeset
   470
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   319,     0,    13, STR_A00B_ORDERS,	STR_018C_WINDOW_TITLE_DRAG_THIS},
893
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 867
diff changeset
   471
{     WWT_IMGBTN,   RESIZE_NONE,    14,     0,   307,    14,    75, 0x0,							STR_8852_ORDERS_LIST_CLICK_ON_ORDER},
d9e69e5060ba (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 867
diff changeset
   472
{  WWT_SCROLLBAR,   RESIZE_NONE,    14,   308,   319,    14,    75, 0x0,							STR_0190_SCROLL_BAR_SCROLLS_LIST},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 127
diff changeset
   473
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
995
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
   476
static const WindowDesc _other_orders_desc = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	-1,-1, 320, 76,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	WC_VEHICLE_ORDERS,WC_VEHICLE_VIEW,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
995
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
   480
	_other_orders_widgets,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	OrdersWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
void ShowOrdersWindow(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
	VehicleID veh = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   491
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
	_alloc_wnd_parent_num = veh;
995
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
   493
	
96e9f70280d7 (svn r1493) -Codechange: Removed redundancy in the order GUI. Currently we had most
celestar
parents: 919
diff changeset
   494
	w = AllocateWindowDesc( (v->owner == _local_player) ? &_orders_desc : &_other_orders_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	w->window_number = veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
	w->caption_color = v->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
	w->vscroll.cap = 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
	WP(w,order_d).sel = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
}