author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5739 | 5f8e8801cd1c |
child 6247 | 7d81e3a5d803 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
4 |
#include "openttd.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
5 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
6 |
#include "command.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
7 |
#include "functions.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
8 |
#include "gfx.h" |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
9 |
#include "map.h" |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
10 |
#include "order.h" |
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3047
diff
changeset
|
11 |
#include "rail_map.h" |
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5350
diff
changeset
|
12 |
#include "bridge_map.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
13 |
#include "saveload.h" |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
14 |
#include "station.h" |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
15 |
#include "tile.h" |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
16 |
#include "town.h" |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
17 |
#include "waypoint.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2085
diff
changeset
|
18 |
#include "variables.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
19 |
#include "table/strings.h" |
3578
c354a34a7c0a
(svn r4464) -Codechange: Oops, forgot one file in last commit
celestar
parents:
3574
diff
changeset
|
20 |
#include "vehicle.h" |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3792
diff
changeset
|
21 |
#include "yapf/yapf.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4077
diff
changeset
|
22 |
#include "date.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
23 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
24 |
enum { |
4984
f717899efa25
(svn r6987) Use the pool macros for the Waypoint pool
tron
parents:
4527
diff
changeset
|
25 |
MAX_WAYPOINTS_PER_TOWN = 64, |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
26 |
}; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
27 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
28 |
/** |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
29 |
* Called if a new block is added to the waypoint-pool |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
30 |
*/ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
31 |
static void WaypointPoolNewBlock(uint start_item) |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
32 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
33 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
34 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
35 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
36 |
* TODO - This is just a temporary stage, this will be removed. */ |
4984
f717899efa25
(svn r6987) Use the pool macros for the Waypoint pool
tron
parents:
4527
diff
changeset
|
37 |
for (wp = GetWaypoint(start_item); wp != NULL; wp = (wp->index + 1U < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1U) : NULL) wp->index = start_item++; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
38 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
39 |
|
5216
8bd14ee39af2
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
4984
diff
changeset
|
40 |
DEFINE_OLD_POOL(Waypoint, Waypoint, WaypointPoolNewBlock, NULL) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
41 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
42 |
/* Create a new waypoint */ |
2752 | 43 |
static Waypoint* AllocateWaypoint(void) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
44 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
45 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
46 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
47 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
48 |
* TODO - This is just a temporary stage, this will be removed. */ |
4984
f717899efa25
(svn r6987) Use the pool macros for the Waypoint pool
tron
parents:
4527
diff
changeset
|
49 |
for (wp = GetWaypoint(0); wp != NULL; wp = (wp->index + 1U < GetWaypointPoolSize()) ? GetWaypoint(wp->index + 1U) : NULL) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
50 |
if (!IsValidWaypoint(wp)) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
51 |
uint index = wp->index; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
52 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
53 |
memset(wp, 0, sizeof(*wp)); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
54 |
wp->index = index; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
55 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
56 |
return wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
57 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
58 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
59 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
60 |
/* Check if we can add a block to the pool */ |
4984
f717899efa25
(svn r6987) Use the pool macros for the Waypoint pool
tron
parents:
4527
diff
changeset
|
61 |
if (AddBlockToPool(&_Waypoint_pool)) return AllocateWaypoint(); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
62 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
63 |
return NULL; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
64 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
65 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
66 |
/* Update the sign for the waypoint */ |
2817 | 67 |
static void UpdateWaypointSign(Waypoint* wp) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
68 |
{ |
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3349
diff
changeset
|
69 |
Point pt = RemapCoords2(TileX(wp->xy) * TILE_SIZE, TileY(wp->xy) * TILE_SIZE); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
70 |
SetDParam(0, wp->index); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
71 |
UpdateViewportSignPos(&wp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
72 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
73 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
74 |
/* Redraw the sign of a waypoint */ |
2752 | 75 |
static void RedrawWaypointSign(const Waypoint* wp) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
76 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
77 |
MarkAllViewportsDirty( |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
78 |
wp->sign.left - 6, |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
79 |
wp->sign.top, |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
80 |
wp->sign.left + (wp->sign.width_1 << 2) + 12, |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
81 |
wp->sign.top + 48); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
82 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
83 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
84 |
/* Update all signs */ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
85 |
void UpdateAllWaypointSigns(void) |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
86 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
87 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
88 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
89 |
FOR_ALL_WAYPOINTS(wp) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
90 |
UpdateWaypointSign(wp); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
91 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
92 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
93 |
|
4390
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
94 |
/* Internal handler to delete a waypoint */ |
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
95 |
void DestroyWaypoint(Waypoint *wp) |
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
96 |
{ |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4500
diff
changeset
|
97 |
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, wp->index); |
4390
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
98 |
|
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
99 |
if (wp->string != STR_NULL) DeleteName(wp->string); |
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
100 |
|
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
101 |
RedrawWaypointSign(wp); |
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
102 |
} |
c7adc07e4301
(svn r6143) -Codechange: DeleteWaypoint removes a waypoint from the pool
truelight
parents:
4389
diff
changeset
|
103 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
104 |
/* Set the default name for a waypoint */ |
2752 | 105 |
static void MakeDefaultWaypointName(Waypoint* wp) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
106 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
107 |
Waypoint *local_wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
108 |
bool used_waypoint[MAX_WAYPOINTS_PER_TOWN]; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
109 |
int i; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
110 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
111 |
wp->town_index = ClosestTownFromTile(wp->xy, (uint)-1)->index; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
112 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
113 |
memset(used_waypoint, 0, sizeof(used_waypoint)); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
114 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
115 |
/* Find an unused waypoint number belonging to this town */ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
116 |
FOR_ALL_WAYPOINTS(local_wp) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
117 |
if (wp == local_wp) continue; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
118 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
119 |
if (local_wp->xy && local_wp->string == STR_NULL && local_wp->town_index == wp->town_index) |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
120 |
used_waypoint[local_wp->town_cn] = true; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
121 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
122 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
123 |
/* Find an empty spot */ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
124 |
for (i = 0; used_waypoint[i] && i < MAX_WAYPOINTS_PER_TOWN; i++) {} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
125 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
126 |
wp->string = STR_NULL; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
127 |
wp->town_cn = i; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
128 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
129 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
130 |
/* Find a deleted waypoint close to a tile. */ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
131 |
static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
132 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
133 |
Waypoint *wp, *best = NULL; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
134 |
uint thres = 8; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
135 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
136 |
FOR_ALL_WAYPOINTS(wp) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
137 |
if (wp->deleted) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
138 |
uint cur_dist = DistanceManhattan(tile, wp->xy); |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
139 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
140 |
if (cur_dist < thres) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
141 |
thres = cur_dist; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
142 |
best = wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
143 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
144 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
145 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
146 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
147 |
return best; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
148 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
149 |
|
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
150 |
/** |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
151 |
* Update waypoint graphics id against saved GRFID/localidx. |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
152 |
* This is to ensure the chosen graphics are correct if GRF files are changed. |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
153 |
*/ |
5350
7564e1c8f5dd
(svn r7521) -Codechange: Rename UpdateAllWaypointCustomGraphics to AfterLoadWaypoints to be more conforming with other such functions.
Darkvater
parents:
5348
diff
changeset
|
154 |
void AfterLoadWaypoints(void) |
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
155 |
{ |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
156 |
Waypoint *wp; |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
157 |
|
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
158 |
FOR_ALL_WAYPOINTS(wp) { |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
159 |
uint i; |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
160 |
|
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
161 |
if (wp->grfid == 0) continue; |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
162 |
|
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
163 |
for (i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) { |
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
164 |
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, i); |
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
165 |
if (statspec != NULL && statspec->grfid == wp->grfid && statspec->localidx == wp->localidx) { |
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
166 |
wp->stat_id = i; |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
167 |
break; |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
168 |
} |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
169 |
} |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
170 |
} |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
171 |
} |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
172 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
173 |
/** Convert existing rail to waypoint. Eg build a waypoint station over |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
174 |
* piece of rail |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3448
diff
changeset
|
175 |
* @param tile tile where waypoint will be built |
2625
19bf7f695537
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
2624
diff
changeset
|
176 |
* @param p1 graphics for waypoint type, 0 indicates standard graphics |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
177 |
* @param p2 unused |
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
178 |
* |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
179 |
* @todo When checking for the tile slope, |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
180 |
* distingush between "Flat land required" and "land sloped in wrong direction" |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
181 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3448
diff
changeset
|
182 |
int32 CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
183 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
184 |
Waypoint *wp; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
185 |
Slope tileh; |
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3047
diff
changeset
|
186 |
Axis axis; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
187 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
188 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
189 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
190 |
/* if custom gfx are used, make sure it is within bounds */ |
2625
19bf7f695537
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
2624
diff
changeset
|
191 |
if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
192 |
|
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3242
diff
changeset
|
193 |
if (!IsTileType(tile, MP_RAILWAY) || |
3792
67c865c9315c
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3764
diff
changeset
|
194 |
GetRailTileType(tile) != RAIL_TILE_NORMAL || ( |
3267
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3242
diff
changeset
|
195 |
(axis = AXIS_X, GetTrackBits(tile) != TRACK_BIT_X) && |
feff95208a9f
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3242
diff
changeset
|
196 |
(axis = AXIS_Y, GetTrackBits(tile) != TRACK_BIT_Y) |
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3047
diff
changeset
|
197 |
)) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
198 |
return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK); |
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3047
diff
changeset
|
199 |
} |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
200 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
201 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
202 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
203 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
204 |
tileh = GetTileSlope(tile, NULL); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
205 |
if (tileh != SLOPE_FLAT && |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
206 |
(!_patches.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
207 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
208 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
209 |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5350
diff
changeset
|
210 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5350
diff
changeset
|
211 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
212 |
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
213 |
wp = FindDeletedWaypointCloseTo(tile); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
214 |
if (wp == NULL) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
215 |
wp = AllocateWaypoint(); |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
216 |
if (wp == NULL) return CMD_ERROR; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
217 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
218 |
wp->town_index = 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
219 |
wp->string = STR_NULL; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
220 |
wp->town_cn = 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
221 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
222 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
223 |
if (flags & DC_EXEC) { |
4051
22af4bcffbbb
(svn r5325) Don't test something if we already know the result true, because the same test was performed just a few lines before
tron
parents:
4000
diff
changeset
|
224 |
const StationSpec* statspec; |
22af4bcffbbb
(svn r5325) Don't test something if we already know the result true, because the same test was performed just a few lines before
tron
parents:
4000
diff
changeset
|
225 |
|
3242
4c32bf21153b
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3157
diff
changeset
|
226 |
MakeRailWaypoint(tile, GetTileOwner(tile), axis, GetRailType(tile), wp->index); |
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3047
diff
changeset
|
227 |
MarkTileDirtyByTile(tile); |
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
228 |
|
4051
22af4bcffbbb
(svn r5325) Don't test something if we already know the result true, because the same test was performed just a few lines before
tron
parents:
4000
diff
changeset
|
229 |
statspec = GetCustomStationSpec(STAT_CLASS_WAYP, p1); |
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
230 |
|
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
231 |
if (statspec != NULL) { |
4051
22af4bcffbbb
(svn r5325) Don't test something if we already know the result true, because the same test was performed just a few lines before
tron
parents:
4000
diff
changeset
|
232 |
wp->stat_id = p1; |
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
233 |
wp->grfid = statspec->grfid; |
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
234 |
wp->localidx = statspec->localidx; |
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
235 |
} else { |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
236 |
// Specified custom graphics do not exist, so use default. |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
237 |
wp->stat_id = 0; |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
238 |
wp->grfid = 0; |
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
239 |
wp->localidx = 0; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
240 |
} |
2670
f2d6a8424e3e
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
241 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
242 |
wp->deleted = 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
243 |
wp->xy = tile; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
244 |
wp->build_date = _date; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
245 |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
246 |
if (wp->town_index == 0) MakeDefaultWaypointName(wp); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
247 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
248 |
UpdateWaypointSign(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
249 |
RedrawWaypointSign(wp); |
5348
cbe04b6ce2fa
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
250 |
YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis)); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
251 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
252 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
253 |
return _price.build_train_depot; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
254 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
255 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
256 |
/* Daily loop for waypoints */ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
257 |
void WaypointsDailyLoop(void) |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
258 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
259 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
260 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
261 |
/* Check if we need to delete a waypoint */ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
262 |
FOR_ALL_WAYPOINTS(wp) { |
4500
6bcd1f6fdc22
(svn r6285) -Fix r6143: of course deleting a waypoint should call the Delete wrapper, not the Destroy function (/me slaps hisself)
truelight
parents:
4395
diff
changeset
|
263 |
if (wp->deleted != 0 && --wp->deleted == 0) DeleteWaypoint(wp); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
264 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
265 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
266 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
267 |
/* Remove a waypoint */ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
268 |
int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
269 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
270 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
271 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
272 |
/* Make sure it's a waypoint */ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
273 |
if (!IsTileType(tile, MP_RAILWAY) || |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
274 |
!IsRailWaypoint(tile) || |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
275 |
(!CheckTileOwnership(tile) && _current_player != OWNER_WATER) || |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
276 |
!EnsureNoVehicle(tile)) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
277 |
return CMD_ERROR; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
278 |
} |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
279 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
280 |
if (flags & DC_EXEC) { |
5348
cbe04b6ce2fa
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
281 |
Track track = GetRailWaypointTrack(tile); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
282 |
wp = GetWaypointByTile(tile); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
283 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
284 |
wp->deleted = 30; // let it live for this many days before we do the actual deletion. |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
285 |
RedrawWaypointSign(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
286 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
287 |
if (justremove) { |
3242
4c32bf21153b
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3157
diff
changeset
|
288 |
MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GetRailType(tile)); |
3101
a44fdf9faef1
(svn r3696) Add functions to turn a tile into a normal rail tile/depot/waypoint. This is just a tiny step, the rail code needs way more love and caring
tron
parents:
3047
diff
changeset
|
289 |
MarkTileDirtyByTile(tile); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
290 |
} else { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
291 |
DoClearSquare(tile); |
5348
cbe04b6ce2fa
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
292 |
SetSignalsOnBothDir(tile, track); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
293 |
} |
5348
cbe04b6ce2fa
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
294 |
YapfNotifyTrackLayoutChange(tile, track); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
295 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
296 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
297 |
return _price.remove_train_depot; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
298 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
299 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
300 |
/** Delete a waypoint |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3448
diff
changeset
|
301 |
* @param tile tile where waypoint is to be deleted |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
302 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
303 |
* @param p2 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
304 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3448
diff
changeset
|
305 |
int32 CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
306 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
307 |
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
308 |
return RemoveTrainWaypoint(tile, flags, true); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
309 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
310 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
311 |
/** Rename a waypoint. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3448
diff
changeset
|
312 |
* @param tile unused |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
313 |
* @param p1 id of waypoint |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
314 |
* @param p2 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
315 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3448
diff
changeset
|
316 |
int32 CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
317 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
318 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
319 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
320 |
if (!IsValidWaypointID(p1)) return CMD_ERROR; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
321 |
|
1820
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1783
diff
changeset
|
322 |
if (_cmd_text[0] != '\0') { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
323 |
StringID str = AllocateNameUnique(_cmd_text, 0); |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
324 |
|
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
325 |
if (str == 0) return CMD_ERROR; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
326 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
327 |
if (flags & DC_EXEC) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
328 |
wp = GetWaypoint(p1); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
329 |
if (wp->string != STR_NULL) DeleteName(wp->string); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
330 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
331 |
wp->string = str; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
332 |
wp->town_cn = 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
333 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
334 |
UpdateWaypointSign(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
335 |
MarkWholeScreenDirty(); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
336 |
} else { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
337 |
DeleteName(str); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
338 |
} |
2026 | 339 |
} else { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
340 |
if (flags & DC_EXEC) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
341 |
wp = GetWaypoint(p1); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
342 |
if (wp->string != STR_NULL) DeleteName(wp->string); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
343 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
344 |
MakeDefaultWaypointName(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
345 |
UpdateWaypointSign(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
346 |
MarkWholeScreenDirty(); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
347 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
348 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
349 |
return 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
350 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
351 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
352 |
/* This hacks together some dummy one-shot Station structure for a waypoint. */ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
353 |
Station *ComposeWaypointStation(TileIndex tile) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
354 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
355 |
Waypoint *wp = GetWaypointByTile(tile); |
5734
a2d4355c3a58
(svn r8277) -Fix (r8038): assert on game exit when waypoints were used. The static variable of type Station (inside ComposeWaypointStation) replaced by byte array so no destructor is called for it on exit.
KUDr
parents:
5587
diff
changeset
|
356 |
|
a2d4355c3a58
(svn r8277) -Fix (r8038): assert on game exit when waypoints were used. The static variable of type Station (inside ComposeWaypointStation) replaced by byte array so no destructor is called for it on exit.
KUDr
parents:
5587
diff
changeset
|
357 |
/* instead of 'static Station stat' use byte array to avoid Station's destructor call upon exit. As |
a2d4355c3a58
(svn r8277) -Fix (r8038): assert on game exit when waypoints were used. The static variable of type Station (inside ComposeWaypointStation) replaced by byte array so no destructor is called for it on exit.
KUDr
parents:
5587
diff
changeset
|
358 |
* a side effect, the station is not constructed now. */ |
5739
5f8e8801cd1c
(svn r8284) -Fix (r8277): g++ compilation error: missing brackets in sizeof
KUDr
parents:
5736
diff
changeset
|
359 |
static byte stat_raw[sizeof(Station)]; |
5734
a2d4355c3a58
(svn r8277) -Fix (r8038): assert on game exit when waypoints were used. The static variable of type Station (inside ComposeWaypointStation) replaced by byte array so no destructor is called for it on exit.
KUDr
parents:
5587
diff
changeset
|
360 |
static Station &stat = *(Station*)stat_raw; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
361 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
362 |
stat.train_tile = stat.xy = wp->xy; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
363 |
stat.town = GetTown(wp->town_index); |
5736
3d1318bd51c7
(svn r8280) -Codechange: Remove unnecessarily complex assignment of waypoint string ID.
peter1138
parents:
5734
diff
changeset
|
364 |
stat.string_id = wp->string; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
365 |
stat.build_date = wp->build_date; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
366 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
367 |
return &stat; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
368 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
369 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
370 |
/* Draw a waypoint */ |
2520
8a52362c4ada
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2261
diff
changeset
|
371 |
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
372 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
373 |
x += 33; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
374 |
y += 17; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
375 |
|
3764
f017ce73e96b
(svn r4755) - Newstations: add a gui station tile drawing routine and use it in place of the existing one for waypoints.
peter1138
parents:
3751
diff
changeset
|
376 |
if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) { |
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
377 |
DrawDefaultWaypointSprite(x, y, railtype); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
378 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
379 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
380 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
381 |
/* Fix savegames which stored waypoints in their old format */ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
382 |
void FixOldWaypoints(void) |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
383 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
384 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
385 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
386 |
/* Convert the old 'town_or_string', to 'string' / 'town' / 'town_cn' */ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
387 |
FOR_ALL_WAYPOINTS(wp) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
388 |
wp->town_index = ClosestTownFromTile(wp->xy, (uint)-1)->index; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
389 |
wp->town_cn = 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
390 |
if (wp->string & 0xC000) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
391 |
wp->town_cn = wp->string & 0x3F; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
392 |
wp->string = STR_NULL; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
393 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
394 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
395 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
396 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
397 |
void InitializeWaypoints(void) |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
398 |
{ |
4984
f717899efa25
(svn r6987) Use the pool macros for the Waypoint pool
tron
parents:
4527
diff
changeset
|
399 |
CleanPool(&_Waypoint_pool); |
f717899efa25
(svn r6987) Use the pool macros for the Waypoint pool
tron
parents:
4527
diff
changeset
|
400 |
AddBlockToPool(&_Waypoint_pool); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
401 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
402 |
|
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1820
diff
changeset
|
403 |
static const SaveLoad _waypoint_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
404 |
SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
405 |
SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
406 |
SLE_CONDVAR(Waypoint, town_index, SLE_UINT16, 12, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
407 |
SLE_CONDVAR(Waypoint, town_cn, SLE_UINT8, 12, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
408 |
SLE_VAR(Waypoint, string, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
409 |
SLE_VAR(Waypoint, deleted, SLE_UINT8), |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
410 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
411 |
SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
412 |
SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
413 |
SLE_CONDVAR(Waypoint, localidx, SLE_UINT8, 3, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
414 |
SLE_CONDVAR(Waypoint, grfid, SLE_UINT32, 17, SL_MAX_VERSION), |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
415 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
416 |
SLE_END() |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
417 |
}; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
418 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
419 |
static void Save_WAYP(void) |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
420 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
421 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
422 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
423 |
FOR_ALL_WAYPOINTS(wp) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
424 |
SlSetArrayIndex(wp->index); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
425 |
SlObject(wp, _waypoint_desc); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
426 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
427 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
428 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
429 |
static void Load_WAYP(void) |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
430 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
431 |
int index; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
432 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
433 |
while ((index = SlIterateArray()) != -1) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
434 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
435 |
|
4984
f717899efa25
(svn r6987) Use the pool macros for the Waypoint pool
tron
parents:
4527
diff
changeset
|
436 |
if (!AddBlockIfNeeded(&_Waypoint_pool, index)) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
437 |
error("Waypoints: failed loading savegame: too many waypoints"); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
438 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
439 |
wp = GetWaypoint(index); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
440 |
SlObject(wp, _waypoint_desc); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
441 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
442 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
443 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
444 |
extern const ChunkHandler _waypoint_chunk_handlers[] = { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
445 |
{ 'CHKP', Save_WAYP, Load_WAYP, CH_ARRAY | CH_LAST}, |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
446 |
}; |