author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9815 | 69440bf2a2e0 |
child 9914 | c07d0352d8d5 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
9036
diff
changeset
|
3 |
/** @file waypoint.cpp Handling of waypoints. */ |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
4 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
7 |
|
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
8 |
#include "command_func.h" |
6453
226bcddeba32
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents:
6451
diff
changeset
|
9 |
#include "landscape.h" |
8784
c2e9d649a9ce
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents:
8579
diff
changeset
|
10 |
#include "order_func.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" |
8138
dbfdc08fa6b9
(svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents:
8131
diff
changeset
|
12 |
#include "rail.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
|
13 |
#include "bridge_map.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
14 |
#include "saveload.h" |
8785
871586967963
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
8784
diff
changeset
|
15 |
#include "station_base.h" |
1542
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" |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3792
diff
changeset
|
19 |
#include "yapf/yapf.h" |
6451
e576c71bfc09
(svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents:
6432
diff
changeset
|
20 |
#include "newgrf.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8108
diff
changeset
|
21 |
#include "strings_func.h" |
8225
cd84a95b6630
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8214
diff
changeset
|
22 |
#include "gfx_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8121
diff
changeset
|
23 |
#include "functions.h" |
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8121
diff
changeset
|
24 |
#include "window_func.h" |
8138
dbfdc08fa6b9
(svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents:
8131
diff
changeset
|
25 |
#include "economy_func.h" |
8140
0d0d8c94f84b
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8139
diff
changeset
|
26 |
#include "date_func.h" |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
27 |
#include "vehicle_func.h" |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
28 |
#include "vehicle_base.h" |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8144
diff
changeset
|
29 |
#include "string_func.h" |
8238
d47a86c79603
(svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents:
8237
diff
changeset
|
30 |
#include "signal_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8238
diff
changeset
|
31 |
#include "player_func.h" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
32 |
#include "settings_type.h" |
8787
41d9d5adbe87
(svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium
parents:
8785
diff
changeset
|
33 |
#include "newgrf_station.h" |
8847
426dd2d582e7
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents:
8836
diff
changeset
|
34 |
#include "oldpool_func.h" |
9129
a7b713cb0422
(svn r12989) -Codechange: move ViewportSign to viewport_type.h.
rubidium
parents:
9111
diff
changeset
|
35 |
#include "viewport_func.h" |
9815
69440bf2a2e0
(svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents:
9789
diff
changeset
|
36 |
#include "pbs.h" |
69440bf2a2e0
(svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents:
9789
diff
changeset
|
37 |
#include "train.h" |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
38 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
39 |
#include "table/strings.h" |
8238
d47a86c79603
(svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents:
8237
diff
changeset
|
40 |
|
7381
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
41 |
DEFINE_OLD_POOL_GENERIC(Waypoint, Waypoint) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
42 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
43 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
44 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
45 |
* Update the sign for the waypoint |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
46 |
* @param wp Waypoint to update sign */ |
2817 | 47 |
static void UpdateWaypointSign(Waypoint* wp) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
48 |
{ |
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
|
49 |
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
|
50 |
SetDParam(0, wp->index); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
51 |
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
|
52 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
53 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
54 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
55 |
* Redraw the sign of a waypoint |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
56 |
* @param wp Waypoint to redraw sign */ |
2752 | 57 |
static void RedrawWaypointSign(const Waypoint* wp) |
1542
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 |
MarkAllViewportsDirty( |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
60 |
wp->sign.left - 6, |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
61 |
wp->sign.top, |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
62 |
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
|
63 |
wp->sign.top + 48); |
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 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
66 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
67 |
* Update all signs |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
68 |
*/ |
6247 | 69 |
void UpdateAllWaypointSigns() |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
70 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
71 |
Waypoint *wp; |
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 |
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
|
74 |
UpdateWaypointSign(wp); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
75 |
} |
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 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
78 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
79 |
* Set the default name for a waypoint |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
80 |
* @param wp Waypoint to work on |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
81 |
*/ |
2752 | 82 |
static void MakeDefaultWaypointName(Waypoint* wp) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
83 |
{ |
8579
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
84 |
uint32 used = 0; // bitmap of used waypoint numbers, sliding window with 'next' as base |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
85 |
uint32 next = 0; // first waypoint number in the bitmap |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
86 |
WaypointID idx = 0; // index where we will stop |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
87 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
88 |
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
|
89 |
|
8579
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
90 |
/* Find first unused waypoint number belonging to this town. This can never fail, |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
91 |
* as long as there can be at most 65535 waypoints in total. |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
92 |
* |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
93 |
* This does 'n * m' search, but with 32bit 'used' bitmap, it needs at most 'n * (1 + ceil(m / 32))' |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
94 |
* steps (n - number of waypoints in pool, m - number of waypoints near this town). |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
95 |
* Usually, it needs only 'n' steps. |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
96 |
* |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
97 |
* If it wasn't using 'used' and 'idx', it would just search for increasing 'next', |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
98 |
* but this way it is faster */ |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
99 |
|
8579
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
100 |
WaypointID cid = 0; // current index, goes to GetWaypointPoolSize()-1, then wraps to 0 |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
101 |
do { |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
102 |
Waypoint *lwp = GetWaypoint(cid); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
103 |
|
8579
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
104 |
/* check only valid waypoints... */ |
8970
da7261f48b7e
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
8847
diff
changeset
|
105 |
if (lwp->IsValid() && wp != lwp) { |
8579
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
106 |
/* only waypoints with 'generic' name within the same city */ |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
107 |
if (lwp->name == NULL && lwp->town_index == wp->town_index) { |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
108 |
/* if lwp->town_cn < next, uint will overflow to '+inf' */ |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
109 |
uint i = (uint)lwp->town_cn - next; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
110 |
|
8579
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
111 |
if (i < 32) { |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
112 |
SetBit(used, i); // update bitmap |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
113 |
if (i == 0) { |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
114 |
/* shift bitmap while the lowest bit is '1'; |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
115 |
* increase the base of the bitmap too */ |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
116 |
do { |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
117 |
used >>= 1; |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
118 |
next++; |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
119 |
} while (HasBit(used, 0)); |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
120 |
/* when we are at 'idx' again at end of the loop and |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
121 |
* 'next' hasn't changed, then no waypoint had town_cn == next, |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
122 |
* so we can safely use it */ |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
123 |
idx = cid; |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
124 |
} |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
125 |
} |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
126 |
} |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
127 |
} |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
128 |
|
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
129 |
cid++; |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
130 |
if (cid == GetWaypointPoolSize()) cid = 0; // wrap to zero... |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
131 |
} while (cid != idx); |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
132 |
|
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
133 |
wp->town_cn = (uint16)next; // set index... |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
134 |
wp->name = NULL; // ... and use generic name |
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 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
137 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
138 |
* Find a deleted waypoint close to a tile. |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
139 |
* @param tile to search from |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
140 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
141 |
static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile) |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
142 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
143 |
Waypoint *wp, *best = NULL; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
144 |
uint thres = 8; |
1542
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 |
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
|
147 |
if (wp->deleted) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
148 |
uint cur_dist = DistanceManhattan(tile, wp->xy); |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
149 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
150 |
if (cur_dist < thres) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
151 |
thres = cur_dist; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
152 |
best = wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
153 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
154 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
155 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
156 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
157 |
return best; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
158 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
159 |
|
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
|
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 |
* 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
|
162 |
* 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
|
163 |
*/ |
6247 | 164 |
void AfterLoadWaypoints() |
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
|
165 |
{ |
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 |
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
|
167 |
|
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 |
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
|
169 |
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
|
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 |
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
|
172 |
|
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
|
173 |
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
|
174 |
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, i); |
6451
e576c71bfc09
(svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents:
6432
diff
changeset
|
175 |
if (statspec != NULL && statspec->grffile->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
|
176 |
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
|
177 |
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
|
178 |
} |
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
|
179 |
} |
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
|
180 |
} |
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
|
181 |
} |
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
|
182 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
183 |
/** 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
|
184 |
* 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
|
185 |
* @param tile tile where waypoint will be built |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
186 |
* @param flags type of operation |
2625
19bf7f695537
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
2624
diff
changeset
|
187 |
* @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
|
188 |
* @param p2 unused |
2085
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
189 |
* |
876f20a0e843
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
190 |
* @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
|
191 |
* 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
|
192 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6453
diff
changeset
|
193 |
CommandCost 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
|
194 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
195 |
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
|
196 |
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
|
197 |
Axis axis; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
198 |
|
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
199 |
/* 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
|
200 |
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
|
201 |
|
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
|
202 |
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
|
203 |
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
|
204 |
(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
|
205 |
(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
|
206 |
)) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
207 |
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
|
208 |
} |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
209 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
210 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
7758
17ad53748c7b
(svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents:
7704
diff
changeset
|
211 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
212 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
213 |
tileh = GetTileSlope(tile, NULL); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
214 |
if (tileh != SLOPE_FLAT && |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9354
diff
changeset
|
215 |
(!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
216 |
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
|
217 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
218 |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5350
diff
changeset
|
219 |
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
|
220 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
221 |
/* 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
|
222 |
wp = FindDeletedWaypointCloseTo(tile); |
9036
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
223 |
if (wp == NULL && !Waypoint::CanAllocateItem()) return CMD_ERROR; |
7381
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
224 |
|
9036
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
225 |
if (flags & DC_EXEC) { |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
226 |
if (wp == NULL) { |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
227 |
wp = new Waypoint(tile); |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
228 |
if (wp == NULL) return CMD_ERROR; |
7704
abfdb91aca4d
(svn r11238) -Fix [FS#1316]: the orders of trains going to a waypoint where not updated when the waypoint would be moved.
rubidium
parents:
7496
diff
changeset
|
229 |
|
9036
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
230 |
wp->town_index = INVALID_TOWN; |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
231 |
wp->name = NULL; |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
232 |
wp->town_cn = 0; |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
233 |
} else { |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
234 |
/* Move existing (recently deleted) waypoint to the new location */ |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
235 |
|
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
236 |
/* First we update the destination for all vehicles that |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
237 |
* have the old waypoint in their orders. */ |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
238 |
Vehicle *v; |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
239 |
FOR_ALL_VEHICLES(v) { |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
240 |
if (v->type == VEH_TRAIN && |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
241 |
v->First() == v && |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
242 |
v->current_order.IsType(OT_GOTO_WAYPOINT) && |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
243 |
v->dest_tile == wp->xy) { |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
244 |
v->dest_tile = tile; |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
245 |
} |
7704
abfdb91aca4d
(svn r11238) -Fix [FS#1316]: the orders of trains going to a waypoint where not updated when the waypoint would be moved.
rubidium
parents:
7496
diff
changeset
|
246 |
} |
9036
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
247 |
|
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
248 |
RedrawWaypointSign(wp); |
6368fe55fd6d
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
8970
diff
changeset
|
249 |
wp->xy = tile; |
7704
abfdb91aca4d
(svn r11238) -Fix [FS#1316]: the orders of trains going to a waypoint where not updated when the waypoint would be moved.
rubidium
parents:
7496
diff
changeset
|
250 |
} |
abfdb91aca4d
(svn r11238) -Fix [FS#1316]: the orders of trains going to a waypoint where not updated when the waypoint would be moved.
rubidium
parents:
7496
diff
changeset
|
251 |
|
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
|
252 |
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
|
253 |
|
9789
b753e2d50d99
(svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents:
9413
diff
changeset
|
254 |
bool reserved = HasBit(GetTrackReservation(tile), AxisToTrack(axis)); |
3242
4c32bf21153b
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3157
diff
changeset
|
255 |
MakeRailWaypoint(tile, GetTileOwner(tile), axis, GetRailType(tile), wp->index); |
9789
b753e2d50d99
(svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents:
9413
diff
changeset
|
256 |
SetDepotWaypointReservation(tile, reserved); |
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
|
257 |
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
|
258 |
|
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
|
259 |
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
|
260 |
|
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
261 |
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
|
262 |
wp->stat_id = p1; |
6451
e576c71bfc09
(svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents:
6432
diff
changeset
|
263 |
wp->grfid = statspec->grffile->grfid; |
3676
680dfa6336a1
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
264 |
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
|
265 |
} else { |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
266 |
/* Specified custom graphics do not exist, so use default. */ |
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
|
267 |
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
|
268 |
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
|
269 |
wp->localidx = 0; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
270 |
} |
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
|
271 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
272 |
wp->deleted = 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
273 |
wp->build_date = _date; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
274 |
|
8501
b58f51323db4
(svn r12076) -Fix: when reusing a renamed deleted waypoint, keep the new name
glx
parents:
8306
diff
changeset
|
275 |
if (wp->town_index == INVALID_TOWN) MakeDefaultWaypointName(wp); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
276 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
277 |
UpdateWaypointSign(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
278 |
RedrawWaypointSign(wp); |
5348
cbe04b6ce2fa
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
279 |
YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis)); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
280 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
281 |
|
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8225
diff
changeset
|
282 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_train_depot); |
1542
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 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
285 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
286 |
* Daily loop for waypoints |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
287 |
*/ |
6247 | 288 |
void WaypointsDailyLoop() |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
289 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
290 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
291 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
292 |
/* 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
|
293 |
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
|
294 |
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
|
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 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
298 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
299 |
* Remove a waypoint |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
300 |
* @param tile from which to remove waypoint |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
301 |
* @param flags type of operation |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
302 |
* @param justremove will indicate if it is removed from rail or if rails are removed too |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
303 |
* @return cost of operation or error |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
304 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6453
diff
changeset
|
305 |
CommandCost 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
|
306 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
307 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
308 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
309 |
/* Make sure it's a waypoint */ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
310 |
if (!IsTileType(tile, MP_RAILWAY) || |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
311 |
!IsRailWaypoint(tile) || |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
312 |
(!CheckTileOwnership(tile) && _current_player != OWNER_WATER) || |
7758
17ad53748c7b
(svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents:
7704
diff
changeset
|
313 |
!EnsureNoVehicleOnGround(tile)) { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
314 |
return CMD_ERROR; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
315 |
} |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
316 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
317 |
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
|
318 |
Track track = GetRailWaypointTrack(tile); |
8300
dfd530665621
(svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents:
8270
diff
changeset
|
319 |
Owner owner = GetTileOwner(tile); // cannot use _current_player because of possible floods |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
320 |
wp = GetWaypointByTile(tile); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
321 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
322 |
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
|
323 |
RedrawWaypointSign(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
324 |
|
9815
69440bf2a2e0
(svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents:
9789
diff
changeset
|
325 |
Vehicle *v = NULL; |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
326 |
if (justremove) { |
9789
b753e2d50d99
(svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents:
9413
diff
changeset
|
327 |
TrackBits tracks = GetRailWaypointBits(tile); |
b753e2d50d99
(svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents:
9413
diff
changeset
|
328 |
bool reserved = GetDepotWaypointReservation(tile); |
b753e2d50d99
(svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents:
9413
diff
changeset
|
329 |
MakeRailNormal(tile, GetTileOwner(tile), tracks, GetRailType(tile)); |
b753e2d50d99
(svn r13931) -Codechange [YAPP]: Retain the reservation state when building/removing waypoints or level crossings. (michi_cc)
rubidium
parents:
9413
diff
changeset
|
330 |
if (reserved) SetTrackReservation(tile, tracks); |
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
|
331 |
MarkTileDirtyByTile(tile); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
332 |
} else { |
9815
69440bf2a2e0
(svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents:
9789
diff
changeset
|
333 |
if (GetDepotWaypointReservation(tile)) { |
69440bf2a2e0
(svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents:
9789
diff
changeset
|
334 |
v = GetTrainForReservation(tile, track); |
69440bf2a2e0
(svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents:
9789
diff
changeset
|
335 |
if (v != NULL) FreeTrainTrackReservation(v); |
69440bf2a2e0
(svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents:
9789
diff
changeset
|
336 |
} |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
337 |
DoClearSquare(tile); |
8306
22e1344c5457
(svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents:
8300
diff
changeset
|
338 |
AddTrackToSignalBuffer(tile, track, owner); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
339 |
} |
5348
cbe04b6ce2fa
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
340 |
YapfNotifyTrackLayoutChange(tile, track); |
9815
69440bf2a2e0
(svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents:
9789
diff
changeset
|
341 |
if (v != NULL) TryPathReserve(v, true); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
342 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
343 |
|
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8225
diff
changeset
|
344 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
345 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
346 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
347 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
348 |
* 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
|
349 |
* @param tile tile where waypoint is to be deleted |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
350 |
* @param flags type of operation |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
351 |
* @param p1 unused |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
352 |
* @param p2 unused |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
353 |
* @return cost of operation or error |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
354 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6453
diff
changeset
|
355 |
CommandCost 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
|
356 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
357 |
return RemoveTrainWaypoint(tile, flags, true); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
358 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
359 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
360 |
static bool IsUniqueWaypointName(const char *name) |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
361 |
{ |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
362 |
const Waypoint *wp; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
363 |
char buf[512]; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
364 |
|
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
365 |
FOR_ALL_WAYPOINTS(wp) { |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
366 |
SetDParam(0, wp->index); |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
367 |
GetString(buf, STR_WAYPOINT_RAW, lastof(buf)); |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
368 |
if (strcmp(buf, name) == 0) return false; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
369 |
} |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
370 |
|
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
371 |
return true; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
372 |
} |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
373 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
374 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
375 |
* 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
|
376 |
* @param tile unused |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
377 |
* @param flags type of operation |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
378 |
* @param p1 id of waypoint |
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
379 |
* @param p2 unused |
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
380 |
* @return cost of operation or error |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
381 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6453
diff
changeset
|
382 |
CommandCost 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
|
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 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
386 |
if (!IsValidWaypointID(p1)) return CMD_ERROR; |
1782
48749e4c2dc6
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
387 |
|
7101
d70ab00ad9f5
(svn r10368) -Fix: when renaming waypoints, ownership was only checked client-side, not in the command.
peter1138
parents:
7097
diff
changeset
|
388 |
wp = GetWaypoint(p1); |
d70ab00ad9f5
(svn r10368) -Fix: when renaming waypoints, ownership was only checked client-side, not in the command.
peter1138
parents:
7097
diff
changeset
|
389 |
if (!CheckTileOwnership(wp->xy)) return CMD_ERROR; |
d70ab00ad9f5
(svn r10368) -Fix: when renaming waypoints, ownership was only checked client-side, not in the command.
peter1138
parents:
7097
diff
changeset
|
390 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
391 |
if (!StrEmpty(_cmd_text)) { |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
392 |
if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
6950
diff
changeset
|
393 |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
394 |
if (flags & DC_EXEC) { |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
395 |
free(wp->name); |
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
396 |
wp->name = strdup(_cmd_text); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
397 |
wp->town_cn = 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
398 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
399 |
UpdateWaypointSign(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
400 |
MarkWholeScreenDirty(); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
401 |
} |
2026 | 402 |
} else { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
403 |
if (flags & DC_EXEC) { |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
404 |
free(wp->name); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
405 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
406 |
MakeDefaultWaypointName(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
407 |
UpdateWaypointSign(wp); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
408 |
MarkWholeScreenDirty(); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
409 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
410 |
} |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
411 |
return CommandCost(); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
412 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
413 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
414 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
415 |
* This hacks together some dummy one-shot Station structure for a waypoint. |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
416 |
* @param tile on which to work |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
417 |
* @return pointer to a Station |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
418 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
419 |
Station *ComposeWaypointStation(TileIndex tile) |
1542
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 = 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
|
422 |
|
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
|
423 |
/* 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
|
424 |
* 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
|
425 |
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
|
426 |
static Station &stat = *(Station*)stat_raw; |
1542
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 |
stat.train_tile = stat.xy = wp->xy; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
429 |
stat.town = GetTown(wp->town_index); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
430 |
stat.build_date = wp->build_date; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
431 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
432 |
return &stat; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
433 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
434 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
435 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
436 |
* Draw a waypoint |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
437 |
* @param x coordinate |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
438 |
* @param y coordinate |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
439 |
* @param stat_id station id |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
440 |
* @param railtype RailType to use for |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
441 |
*/ |
2520
8a52362c4ada
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2261
diff
changeset
|
442 |
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
|
443 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
444 |
x += 33; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
445 |
y += 17; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
446 |
|
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
|
447 |
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
|
448 |
DrawDefaultWaypointSprite(x, y, railtype); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
449 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
450 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
451 |
|
7381
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
452 |
Waypoint::Waypoint(TileIndex tile) |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
453 |
{ |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
454 |
this->xy = tile; |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
455 |
} |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
456 |
|
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
457 |
Waypoint::~Waypoint() |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
458 |
{ |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
459 |
free(this->name); |
7413
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7381
diff
changeset
|
460 |
|
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7381
diff
changeset
|
461 |
if (CleaningPool()) return; |
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7381
diff
changeset
|
462 |
|
7381
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
463 |
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index); |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
464 |
|
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
465 |
RedrawWaypointSign(this); |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
466 |
this->xy = 0; |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
467 |
} |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
468 |
|
6432
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
469 |
/** |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
470 |
* Fix savegames which stored waypoints in their old format |
226650eb2ef3
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6247
diff
changeset
|
471 |
*/ |
6247 | 472 |
void FixOldWaypoints() |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
473 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
474 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
475 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
476 |
/* 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
|
477 |
FOR_ALL_WAYPOINTS(wp) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
478 |
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
|
479 |
wp->town_cn = 0; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
480 |
if (wp->string & 0xC000) { |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
481 |
wp->town_cn = wp->string & 0x3F; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
482 |
wp->string = STR_NULL; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
483 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
484 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
485 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
486 |
|
6247 | 487 |
void InitializeWaypoints() |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
488 |
{ |
7381
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
489 |
_Waypoint_pool.CleanPool(); |
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
490 |
_Waypoint_pool.AddBlockToPool(); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
491 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
492 |
|
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
|
493 |
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
|
494 |
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
|
495 |
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
|
496 |
SLE_CONDVAR(Waypoint, town_index, SLE_UINT16, 12, SL_MAX_VERSION), |
8579
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
497 |
SLE_CONDVAR(Waypoint, town_cn, SLE_FILE_U8 | SLE_VAR_U16, 12, 88), |
db463f9c0256
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8501
diff
changeset
|
498 |
SLE_CONDVAR(Waypoint, town_cn, SLE_UINT16, 89, SL_MAX_VERSION), |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
499 |
SLE_CONDVAR(Waypoint, string, SLE_STRINGID, 0, 83), |
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
500 |
SLE_CONDSTR(Waypoint, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
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
|
501 |
SLE_VAR(Waypoint, deleted, SLE_UINT8), |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
502 |
|
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
|
503 |
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
|
504 |
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
|
505 |
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
|
506 |
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
|
507 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
508 |
SLE_END() |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
509 |
}; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
510 |
|
6247 | 511 |
static void Save_WAYP() |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
512 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
513 |
Waypoint *wp; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
514 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
515 |
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
|
516 |
SlSetArrayIndex(wp->index); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
517 |
SlObject(wp, _waypoint_desc); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
518 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
519 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
520 |
|
6247 | 521 |
static void Load_WAYP() |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
522 |
{ |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
523 |
int index; |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
524 |
|
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
525 |
while ((index = SlIterateArray()) != -1) { |
7381
d7991ec3f19d
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7101
diff
changeset
|
526 |
Waypoint *wp = new (index) Waypoint(); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
527 |
SlObject(wp, _waypoint_desc); |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
528 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
529 |
} |
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
530 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
531 |
extern const ChunkHandler _waypoint_chunk_handlers[] = { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
532 |
{ '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
|
533 |
}; |