author | Tero Marttila <terom@fixme.fi> |
Fri, 18 Jul 2008 21:28:42 +0300 | |
changeset 11175 | 020c61e39c94 |
parent 10775 | 7061477bfbcf |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(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:
10314
diff
changeset
|
3 |
/** @file waypoint.cpp Handling of waypoints. */ |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
4 |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
7 |
|
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
8 |
#include "command_func.h" |
6949
72d11a1e1e60
(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:
6947
diff
changeset
|
9 |
#include "landscape.h" |
9280
9c03416d26b1
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents:
9075
diff
changeset
|
10 |
#include "order_func.h" |
3101
e2fdb8802c2f
(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" |
8634
5ffca02f9115
(svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents:
8627
diff
changeset
|
12 |
#include "rail.h" |
5573
afa6f92a71fd
(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
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
14 |
#include "saveload.h" |
9281
d8cd9ac52a68
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
9280
diff
changeset
|
15 |
#include "station_base.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
16 |
#include "town.h" |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
17 |
#include "waypoint.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2085
diff
changeset
|
18 |
#include "variables.h" |
3900
4984308f9125
(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" |
6947
c21859ab4493
(svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents:
6928
diff
changeset
|
20 |
#include "newgrf.h" |
8610
17cc343a23dd
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8604
diff
changeset
|
21 |
#include "strings_func.h" |
8721
b7971ad9bdd9
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8710
diff
changeset
|
22 |
#include "gfx_func.h" |
8627
448ebf3a8291
(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:
8617
diff
changeset
|
23 |
#include "functions.h" |
448ebf3a8291
(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:
8617
diff
changeset
|
24 |
#include "window_func.h" |
8634
5ffca02f9115
(svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents:
8627
diff
changeset
|
25 |
#include "economy_func.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8635
diff
changeset
|
26 |
#include "date_func.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
27 |
#include "vehicle_func.h" |
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
28 |
#include "vehicle_base.h" |
8710
52015340050c
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8640
diff
changeset
|
29 |
#include "string_func.h" |
8734
b7fc8c6fd379
(svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents:
8733
diff
changeset
|
30 |
#include "signal_func.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8734
diff
changeset
|
31 |
#include "player_func.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8760
diff
changeset
|
32 |
#include "settings_type.h" |
9283
624272490f5a
(svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium
parents:
9281
diff
changeset
|
33 |
#include "newgrf_station.h" |
9343
c30fd350dd8c
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents:
9332
diff
changeset
|
34 |
#include "oldpool_func.h" |
10447
a73b8ec66203
(svn r12989) -Codechange: move ViewportSign to viewport_type.h.
rubidium
parents:
10429
diff
changeset
|
35 |
#include "viewport_func.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
36 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
37 |
#include "table/strings.h" |
8734
b7fc8c6fd379
(svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents:
8733
diff
changeset
|
38 |
|
7877
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
39 |
DEFINE_OLD_POOL_GENERIC(Waypoint, Waypoint) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
40 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
41 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
42 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
43 |
* Update the sign for the waypoint |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
44 |
* @param wp Waypoint to update sign */ |
2817 | 45 |
static void UpdateWaypointSign(Waypoint* wp) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
46 |
{ |
3422
12cdb13ddb56
(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
|
47 |
Point pt = RemapCoords2(TileX(wp->xy) * TILE_SIZE, TileY(wp->xy) * TILE_SIZE); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
48 |
SetDParam(0, wp->index); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
49 |
UpdateViewportSignPos(&wp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
50 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
51 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
52 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
53 |
* Redraw the sign of a waypoint |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
54 |
* @param wp Waypoint to redraw sign */ |
2752 | 55 |
static void RedrawWaypointSign(const Waypoint* wp) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
56 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
57 |
MarkAllViewportsDirty( |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
58 |
wp->sign.left - 6, |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
59 |
wp->sign.top, |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
60 |
wp->sign.left + (wp->sign.width_1 << 2) + 12, |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
61 |
wp->sign.top + 48); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
62 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
63 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
64 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
65 |
* Update all signs |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
66 |
*/ |
6573 | 67 |
void UpdateAllWaypointSigns() |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
68 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
69 |
Waypoint *wp; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
70 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
71 |
FOR_ALL_WAYPOINTS(wp) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
72 |
UpdateWaypointSign(wp); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
73 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
74 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
75 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
76 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
77 |
* Set the default name for a waypoint |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
78 |
* @param wp Waypoint to work on |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
79 |
*/ |
2752 | 80 |
static void MakeDefaultWaypointName(Waypoint* wp) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
81 |
{ |
9075
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
82 |
uint32 used = 0; // bitmap of used waypoint numbers, sliding window with 'next' as base |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
83 |
uint32 next = 0; // first waypoint number in the bitmap |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
84 |
WaypointID idx = 0; // index where we will stop |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
85 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
86 |
wp->town_index = ClosestTownFromTile(wp->xy, (uint)-1)->index; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
87 |
|
9075
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
88 |
/* Find first unused waypoint number belonging to this town. This can never fail, |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
89 |
* as long as there can be at most 65535 waypoints in total. |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
90 |
* |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
91 |
* This does 'n * m' search, but with 32bit 'used' bitmap, it needs at most 'n * (1 + ceil(m / 32))' |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
92 |
* steps (n - number of waypoints in pool, m - number of waypoints near this town). |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
93 |
* Usually, it needs only 'n' steps. |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
94 |
* |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
95 |
* If it wasn't using 'used' and 'idx', it would just search for increasing 'next', |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
96 |
* but this way it is faster */ |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
97 |
|
9075
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
98 |
WaypointID cid = 0; // current index, goes to GetWaypointPoolSize()-1, then wraps to 0 |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
99 |
do { |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
100 |
Waypoint *lwp = GetWaypoint(cid); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
101 |
|
9075
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
102 |
/* check only valid waypoints... */ |
10230
bf81856a1101
(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:
9343
diff
changeset
|
103 |
if (lwp->IsValid() && wp != lwp) { |
9075
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
104 |
/* only waypoints with 'generic' name within the same city */ |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
105 |
if (lwp->name == NULL && lwp->town_index == wp->town_index) { |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
106 |
/* if lwp->town_cn < next, uint will overflow to '+inf' */ |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
107 |
uint i = (uint)lwp->town_cn - next; |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
108 |
|
9075
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
109 |
if (i < 32) { |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
110 |
SetBit(used, i); // update bitmap |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
111 |
if (i == 0) { |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
112 |
/* shift bitmap while the lowest bit is '1'; |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
113 |
* increase the base of the bitmap too */ |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
114 |
do { |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
115 |
used >>= 1; |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
116 |
next++; |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
117 |
} while (HasBit(used, 0)); |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
118 |
/* when we are at 'idx' again at end of the loop and |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
119 |
* 'next' hasn't changed, then no waypoint had town_cn == next, |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
120 |
* so we can safely use it */ |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
121 |
idx = cid; |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
122 |
} |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
123 |
} |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
124 |
} |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
125 |
} |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
126 |
|
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
127 |
cid++; |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
128 |
if (cid == GetWaypointPoolSize()) cid = 0; // wrap to zero... |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
129 |
} while (cid != idx); |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
130 |
|
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
131 |
wp->town_cn = (uint16)next; // set index... |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
132 |
wp->name = NULL; // ... and use generic name |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
133 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
134 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
135 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
136 |
* Find a deleted waypoint close to a tile. |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
137 |
* @param tile to search from |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
138 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
139 |
static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
140 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
141 |
Waypoint *wp, *best = NULL; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
142 |
uint thres = 8; |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
143 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
144 |
FOR_ALL_WAYPOINTS(wp) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
145 |
if (wp->deleted) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
146 |
uint cur_dist = DistanceManhattan(tile, wp->xy); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
147 |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
148 |
if (cur_dist < thres) { |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
149 |
thres = cur_dist; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
150 |
best = wp; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
151 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
152 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
153 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
154 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
155 |
return best; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
156 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
157 |
|
2670
34970983ef08
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
158 |
/** |
34970983ef08
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
peter1138
parents:
2668
diff
changeset
|
159 |
* Update waypoint graphics id against saved GRFID/localidx. |
34970983ef08
(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 |
* This is to ensure the chosen graphics are correct if GRF files are changed. |
34970983ef08
(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 |
*/ |
6573 | 162 |
void AfterLoadWaypoints() |
2670
34970983ef08
(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 |
{ |
34970983ef08
(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
|
164 |
Waypoint *wp; |
34970983ef08
(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 |
|
34970983ef08
(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 |
FOR_ALL_WAYPOINTS(wp) { |
34970983ef08
(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 |
uint i; |
34970983ef08
(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 |
|
34970983ef08
(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 |
if (wp->grfid == 0) continue; |
34970983ef08
(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 |
|
34970983ef08
(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 |
for (i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) { |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
172 |
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, i); |
6947
c21859ab4493
(svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents:
6928
diff
changeset
|
173 |
if (statspec != NULL && statspec->grffile->grfid == wp->grfid && statspec->localidx == wp->localidx) { |
2670
34970983ef08
(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
|
174 |
wp->stat_id = i; |
34970983ef08
(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
|
175 |
break; |
34970983ef08
(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 |
} |
34970983ef08
(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 |
} |
34970983ef08
(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 |
} |
34970983ef08
(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 |
} |
34970983ef08
(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 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
181 |
/** Convert existing rail to waypoint. Eg build a waypoint station over |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
182 |
* piece of rail |
3491
4c8427796c64
(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
|
183 |
* @param tile tile where waypoint will be built |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
184 |
* @param flags type of operation |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
2624
diff
changeset
|
185 |
* @param p1 graphics for waypoint type, 0 indicates standard graphics |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
186 |
* @param p2 unused |
2085
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
187 |
* |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
188 |
* @todo When checking for the tile slope, |
ae9e92ffe168
(svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents:
2049
diff
changeset
|
189 |
* distingush between "Flat land required" and "land sloped in wrong direction" |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
190 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6949
diff
changeset
|
191 |
CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
192 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
193 |
Waypoint *wp; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
194 |
Slope tileh; |
3101
e2fdb8802c2f
(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
|
195 |
Axis axis; |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
196 |
|
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
197 |
/* if custom gfx are used, make sure it is within bounds */ |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
2624
diff
changeset
|
198 |
if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
199 |
|
3267
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3242
diff
changeset
|
200 |
if (!IsTileType(tile, MP_RAILWAY) || |
3792
2eb8388731bf
(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
|
201 |
GetRailTileType(tile) != RAIL_TILE_NORMAL || ( |
3267
591027d10884
(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 |
(axis = AXIS_X, GetTrackBits(tile) != TRACK_BIT_X) && |
591027d10884
(svn r3979) Move GetRailFoundation() to rail_map.h and use it and friends to get information about rail tiles
tron
parents:
3242
diff
changeset
|
203 |
(axis = AXIS_Y, GetTrackBits(tile) != TRACK_BIT_Y) |
3101
e2fdb8802c2f
(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
|
204 |
)) { |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
205 |
return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK); |
3101
e2fdb8802c2f
(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
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
207 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
208 |
if (!CheckTileOwnership(tile)) return CMD_ERROR; |
8254
5de2bbd26163
(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:
8200
diff
changeset
|
209 |
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
210 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
211 |
tileh = GetTileSlope(tile, NULL); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
212 |
if (tileh != SLOPE_FLAT && |
10775
7061477bfbcf
(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:
10703
diff
changeset
|
213 |
(!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) { |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
214 |
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
215 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
216 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5350
diff
changeset
|
217 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5350
diff
changeset
|
218 |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
219 |
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
220 |
wp = FindDeletedWaypointCloseTo(tile); |
10314
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
221 |
if (wp == NULL && !Waypoint::CanAllocateItem()) return CMD_ERROR; |
7877
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
222 |
|
10314
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
223 |
if (flags & DC_EXEC) { |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
224 |
if (wp == NULL) { |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
225 |
wp = new Waypoint(tile); |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
226 |
if (wp == NULL) return CMD_ERROR; |
8200
74d44b461346
(svn r11238) -Fix [FS#1316]: the orders of trains going to a waypoint where not updated when the waypoint would be moved.
rubidium
parents:
7992
diff
changeset
|
227 |
|
10314
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
228 |
wp->town_index = INVALID_TOWN; |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
229 |
wp->name = NULL; |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
230 |
wp->town_cn = 0; |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
231 |
} else { |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
232 |
/* Move existing (recently deleted) waypoint to the new location */ |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
233 |
|
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
234 |
/* First we update the destination for all vehicles that |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
235 |
* have the old waypoint in their orders. */ |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
236 |
Vehicle *v; |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
237 |
FOR_ALL_VEHICLES(v) { |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
238 |
if (v->type == VEH_TRAIN && |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
239 |
v->First() == v && |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
240 |
v->current_order.IsType(OT_GOTO_WAYPOINT) && |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
241 |
v->dest_tile == wp->xy) { |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
242 |
v->dest_tile = tile; |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
243 |
} |
8200
74d44b461346
(svn r11238) -Fix [FS#1316]: the orders of trains going to a waypoint where not updated when the waypoint would be moved.
rubidium
parents:
7992
diff
changeset
|
244 |
} |
10314
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
245 |
|
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
246 |
RedrawWaypointSign(wp); |
9cfcdd5b5ddb
(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:
10230
diff
changeset
|
247 |
wp->xy = tile; |
8200
74d44b461346
(svn r11238) -Fix [FS#1316]: the orders of trains going to a waypoint where not updated when the waypoint would be moved.
rubidium
parents:
7992
diff
changeset
|
248 |
} |
74d44b461346
(svn r11238) -Fix [FS#1316]: the orders of trains going to a waypoint where not updated when the waypoint would be moved.
rubidium
parents:
7992
diff
changeset
|
249 |
|
4051
566d63f3c5a2
(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
|
250 |
const StationSpec* statspec; |
566d63f3c5a2
(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
|
251 |
|
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3157
diff
changeset
|
252 |
MakeRailWaypoint(tile, GetTileOwner(tile), axis, GetRailType(tile), wp->index); |
3101
e2fdb8802c2f
(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
|
253 |
MarkTileDirtyByTile(tile); |
2670
34970983ef08
(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
|
254 |
|
4051
566d63f3c5a2
(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
|
255 |
statspec = GetCustomStationSpec(STAT_CLASS_WAYP, p1); |
2670
34970983ef08
(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
|
256 |
|
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
257 |
if (statspec != NULL) { |
4051
566d63f3c5a2
(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
|
258 |
wp->stat_id = p1; |
6947
c21859ab4493
(svn r9601) -Codechange: Store grf file reference in station spec, not just GRF ID
peter1138
parents:
6928
diff
changeset
|
259 |
wp->grfid = statspec->grffile->grfid; |
3676
48444d881fbe
(svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents:
3636
diff
changeset
|
260 |
wp->localidx = statspec->localidx; |
2670
34970983ef08
(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
|
261 |
} else { |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
262 |
/* Specified custom graphics do not exist, so use default. */ |
2670
34970983ef08
(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
|
263 |
wp->stat_id = 0; |
34970983ef08
(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
|
264 |
wp->grfid = 0; |
34970983ef08
(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 |
wp->localidx = 0; |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
266 |
} |
2670
34970983ef08
(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 |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
268 |
wp->deleted = 0; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
269 |
wp->build_date = _date; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
270 |
|
8997
85ddd26ec9c6
(svn r12076) -Fix: when reusing a renamed deleted waypoint, keep the new name
glx
parents:
8802
diff
changeset
|
271 |
if (wp->town_index == INVALID_TOWN) MakeDefaultWaypointName(wp); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
272 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
273 |
UpdateWaypointSign(wp); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
274 |
RedrawWaypointSign(wp); |
5348
0f05b1348b5a
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
275 |
YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis)); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
276 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
277 |
|
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8721
diff
changeset
|
278 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_train_depot); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
279 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
280 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
281 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
282 |
* Daily loop for waypoints |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
283 |
*/ |
6573 | 284 |
void WaypointsDailyLoop() |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
285 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
286 |
Waypoint *wp; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
287 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
288 |
/* Check if we need to delete a waypoint */ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
289 |
FOR_ALL_WAYPOINTS(wp) { |
4500
426d0baa1be5
(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
|
290 |
if (wp->deleted != 0 && --wp->deleted == 0) DeleteWaypoint(wp); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
291 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
292 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
293 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
294 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
295 |
* Remove a waypoint |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
296 |
* @param tile from which to remove waypoint |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
297 |
* @param flags type of operation |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
298 |
* @param justremove will indicate if it is removed from rail or if rails are removed too |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
299 |
* @return cost of operation or error |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
300 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6949
diff
changeset
|
301 |
CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
302 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
303 |
Waypoint *wp; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
304 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
305 |
/* Make sure it's a waypoint */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
306 |
if (!IsTileType(tile, MP_RAILWAY) || |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
307 |
!IsRailWaypoint(tile) || |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
308 |
(!CheckTileOwnership(tile) && _current_player != OWNER_WATER) || |
8254
5de2bbd26163
(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:
8200
diff
changeset
|
309 |
!EnsureNoVehicleOnGround(tile)) { |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
310 |
return CMD_ERROR; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4052
diff
changeset
|
311 |
} |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
312 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
313 |
if (flags & DC_EXEC) { |
5348
0f05b1348b5a
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
314 |
Track track = GetRailWaypointTrack(tile); |
8796
81b0d6b54a1f
(svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents:
8766
diff
changeset
|
315 |
Owner owner = GetTileOwner(tile); // cannot use _current_player because of possible floods |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
316 |
wp = GetWaypointByTile(tile); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
317 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
318 |
wp->deleted = 30; // let it live for this many days before we do the actual deletion. |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
319 |
RedrawWaypointSign(wp); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
320 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
321 |
if (justremove) { |
3242
1cefa03f0d5e
(svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents:
3157
diff
changeset
|
322 |
MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GetRailType(tile)); |
3101
e2fdb8802c2f
(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
|
323 |
MarkTileDirtyByTile(tile); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
324 |
} else { |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
325 |
DoClearSquare(tile); |
8802
e08824cdab46
(svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents:
8796
diff
changeset
|
326 |
AddTrackToSignalBuffer(tile, track, owner); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
327 |
} |
5348
0f05b1348b5a
(svn r7519) -Fix: [YAPF] Cache was not deleted when waypoint was built or removed (frosch)
KUDr
parents:
5216
diff
changeset
|
328 |
YapfNotifyTrackLayoutChange(tile, track); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
329 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
330 |
|
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8721
diff
changeset
|
331 |
return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
332 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
333 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
334 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
335 |
* Delete a waypoint |
3491
4c8427796c64
(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
|
336 |
* @param tile tile where waypoint is to be deleted |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
337 |
* @param flags type of operation |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
338 |
* @param p1 unused |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
339 |
* @param p2 unused |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
340 |
* @return cost of operation or error |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
341 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6949
diff
changeset
|
342 |
CommandCost CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
343 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
344 |
return RemoveTrainWaypoint(tile, flags, true); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
345 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
346 |
|
7593
cfce84f8995c
(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:
7446
diff
changeset
|
347 |
static bool IsUniqueWaypointName(const char *name) |
cfce84f8995c
(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:
7446
diff
changeset
|
348 |
{ |
cfce84f8995c
(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:
7446
diff
changeset
|
349 |
const Waypoint *wp; |
cfce84f8995c
(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:
7446
diff
changeset
|
350 |
char buf[512]; |
cfce84f8995c
(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:
7446
diff
changeset
|
351 |
|
cfce84f8995c
(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:
7446
diff
changeset
|
352 |
FOR_ALL_WAYPOINTS(wp) { |
cfce84f8995c
(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:
7446
diff
changeset
|
353 |
SetDParam(0, wp->index); |
cfce84f8995c
(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:
7446
diff
changeset
|
354 |
GetString(buf, STR_WAYPOINT_RAW, lastof(buf)); |
cfce84f8995c
(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:
7446
diff
changeset
|
355 |
if (strcmp(buf, name) == 0) return false; |
cfce84f8995c
(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:
7446
diff
changeset
|
356 |
} |
cfce84f8995c
(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:
7446
diff
changeset
|
357 |
|
cfce84f8995c
(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:
7446
diff
changeset
|
358 |
return true; |
cfce84f8995c
(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:
7446
diff
changeset
|
359 |
} |
cfce84f8995c
(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:
7446
diff
changeset
|
360 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
361 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
362 |
* Rename a waypoint. |
3491
4c8427796c64
(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
|
363 |
* @param tile unused |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
364 |
* @param flags type of operation |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
365 |
* @param p1 id of waypoint |
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
366 |
* @param p2 unused |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
367 |
* @return cost of operation or error |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
368 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6949
diff
changeset
|
369 |
CommandCost CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
370 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
371 |
Waypoint *wp; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
372 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
373 |
if (!IsValidWaypointID(p1)) return CMD_ERROR; |
1782
0ac16ff36293
(svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents:
1542
diff
changeset
|
374 |
|
7597
73cfa9943246
(svn r10368) -Fix: when renaming waypoints, ownership was only checked client-side, not in the command.
peter1138
parents:
7593
diff
changeset
|
375 |
wp = GetWaypoint(p1); |
73cfa9943246
(svn r10368) -Fix: when renaming waypoints, ownership was only checked client-side, not in the command.
peter1138
parents:
7593
diff
changeset
|
376 |
if (!CheckTileOwnership(wp->xy)) return CMD_ERROR; |
73cfa9943246
(svn r10368) -Fix: when renaming waypoints, ownership was only checked client-side, not in the command.
peter1138
parents:
7593
diff
changeset
|
377 |
|
7593
cfce84f8995c
(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:
7446
diff
changeset
|
378 |
if (!StrEmpty(_cmd_text)) { |
cfce84f8995c
(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:
7446
diff
changeset
|
379 |
if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
cfce84f8995c
(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:
7446
diff
changeset
|
380 |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
381 |
if (flags & DC_EXEC) { |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
382 |
free(wp->name); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
383 |
wp->name = strdup(_cmd_text); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
384 |
wp->town_cn = 0; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
385 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
386 |
UpdateWaypointSign(wp); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
387 |
MarkWholeScreenDirty(); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
388 |
} |
2026 | 389 |
} else { |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
390 |
if (flags & DC_EXEC) { |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
391 |
free(wp->name); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
392 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
393 |
MakeDefaultWaypointName(wp); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
394 |
UpdateWaypointSign(wp); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
395 |
MarkWholeScreenDirty(); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
396 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
397 |
} |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
398 |
return CommandCost(); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
399 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
400 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
401 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
402 |
* This hacks together some dummy one-shot Station structure for a waypoint. |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
403 |
* @param tile on which to work |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
404 |
* @return pointer to a Station |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
405 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
406 |
Station *ComposeWaypointStation(TileIndex tile) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
407 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
408 |
Waypoint *wp = GetWaypointByTile(tile); |
5985
e7a55ca9e43d
(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:
5838
diff
changeset
|
409 |
|
e7a55ca9e43d
(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:
5838
diff
changeset
|
410 |
/* instead of 'static Station stat' use byte array to avoid Station's destructor call upon exit. As |
e7a55ca9e43d
(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:
5838
diff
changeset
|
411 |
* a side effect, the station is not constructed now. */ |
5990
b3c4c4b66249
(svn r8284) -Fix (r8277): g++ compilation error: missing brackets in sizeof
KUDr
parents:
5987
diff
changeset
|
412 |
static byte stat_raw[sizeof(Station)]; |
5985
e7a55ca9e43d
(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:
5838
diff
changeset
|
413 |
static Station &stat = *(Station*)stat_raw; |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
414 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
415 |
stat.train_tile = stat.xy = wp->xy; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
416 |
stat.town = GetTown(wp->town_index); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
417 |
stat.build_date = wp->build_date; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
418 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
419 |
return &stat; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
420 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
421 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
422 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
423 |
* Draw a waypoint |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
424 |
* @param x coordinate |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
425 |
* @param y coordinate |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
426 |
* @param stat_id station id |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
427 |
* @param railtype RailType to use for |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
428 |
*/ |
2520
75eb66d6e371
(svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents:
2261
diff
changeset
|
429 |
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype) |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
430 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
431 |
x += 33; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
432 |
y += 17; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
433 |
|
3764
ebcaf412fb3a
(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
|
434 |
if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) { |
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2254
diff
changeset
|
435 |
DrawDefaultWaypointSprite(x, y, railtype); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
436 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
437 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
438 |
|
7877
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
439 |
Waypoint::Waypoint(TileIndex tile) |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
440 |
{ |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
441 |
this->xy = tile; |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
442 |
} |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
443 |
|
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
444 |
Waypoint::~Waypoint() |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
445 |
{ |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
446 |
free(this->name); |
7909
8df54a2839a1
(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:
7877
diff
changeset
|
447 |
|
8df54a2839a1
(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:
7877
diff
changeset
|
448 |
if (CleaningPool()) return; |
8df54a2839a1
(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:
7877
diff
changeset
|
449 |
|
7877
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
450 |
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index); |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
451 |
|
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
452 |
RedrawWaypointSign(this); |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
453 |
this->xy = 0; |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
454 |
} |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
455 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
456 |
/** |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
457 |
* Fix savegames which stored waypoints in their old format |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
458 |
*/ |
6573 | 459 |
void FixOldWaypoints() |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
460 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
461 |
Waypoint *wp; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
462 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
463 |
/* Convert the old 'town_or_string', to 'string' / 'town' / 'town_cn' */ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
464 |
FOR_ALL_WAYPOINTS(wp) { |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
465 |
wp->town_index = ClosestTownFromTile(wp->xy, (uint)-1)->index; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
466 |
wp->town_cn = 0; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
467 |
if (wp->string & 0xC000) { |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
468 |
wp->town_cn = wp->string & 0x3F; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
469 |
wp->string = STR_NULL; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
470 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
471 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
472 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
473 |
|
6573 | 474 |
void InitializeWaypoints() |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
475 |
{ |
7877
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
476 |
_Waypoint_pool.CleanPool(); |
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
477 |
_Waypoint_pool.AddBlockToPool(); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
478 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
479 |
|
1881
023a134a4b12
(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
|
480 |
static const SaveLoad _waypoint_desc[] = { |
4344
5d0e40cd67b9
(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
|
481 |
SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(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
|
482 |
SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
483 |
SLE_CONDVAR(Waypoint, town_index, SLE_UINT16, 12, SL_MAX_VERSION), |
9075
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
484 |
SLE_CONDVAR(Waypoint, town_cn, SLE_FILE_U8 | SLE_VAR_U16, 12, 88), |
ce14a76881b1
(svn r12160) -Fix [FS#1744]: remove the arbitrary limit of 64 waypoints per town, so weird things won't happen anymore
smatz
parents:
8997
diff
changeset
|
485 |
SLE_CONDVAR(Waypoint, town_cn, SLE_UINT16, 89, SL_MAX_VERSION), |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
486 |
SLE_CONDVAR(Waypoint, string, SLE_STRINGID, 0, 83), |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
487 |
SLE_CONDSTR(Waypoint, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(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
|
488 |
SLE_VAR(Waypoint, deleted, SLE_UINT8), |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
489 |
|
4344
5d0e40cd67b9
(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
|
490 |
SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), |
5d0e40cd67b9
(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
|
491 |
SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
492 |
SLE_CONDVAR(Waypoint, localidx, SLE_UINT8, 3, SL_MAX_VERSION), |
5d0e40cd67b9
(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
|
493 |
SLE_CONDVAR(Waypoint, grfid, SLE_UINT32, 17, SL_MAX_VERSION), |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
494 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
495 |
SLE_END() |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
496 |
}; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
497 |
|
6573 | 498 |
static void Save_WAYP() |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
499 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
500 |
Waypoint *wp; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
501 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
502 |
FOR_ALL_WAYPOINTS(wp) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
503 |
SlSetArrayIndex(wp->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
504 |
SlObject(wp, _waypoint_desc); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
505 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
506 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
507 |
|
6573 | 508 |
static void Load_WAYP() |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
509 |
{ |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
510 |
int index; |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
511 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
512 |
while ((index = SlIterateArray()) != -1) { |
7877
eca84d5e568a
(svn r10750) -Codechange: make the waypoint struct use the new poolitem class as super class.
rubidium
parents:
7597
diff
changeset
|
513 |
Waypoint *wp = new (index) Waypoint(); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
514 |
SlObject(wp, _waypoint_desc); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
515 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
516 |
} |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
517 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
518 |
extern const ChunkHandler _waypoint_chunk_handlers[] = { |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
519 |
{ 'CHKP', Save_WAYP, Load_WAYP, CH_ARRAY | CH_LAST}, |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
diff
changeset
|
520 |
}; |