annotate road_cmd.c @ 241:d57b6f171919 draft

(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs) -Fix: Pathfinding under bridges bug for ships introduced in r160 fixed (Darkvater)
author darkvater <darkvater@openttd.org>
date Tue, 14 Sep 2004 01:21:07 +0000
parents d1b097f4593b
children c88b35750799
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1 #include "stdafx.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
2 #include "ttd.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
3 #include "vehicle.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
4 #include "viewport.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
5 #include "command.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
6 #include "player.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
7 #include "town.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
8 #include "gfx.h"
159
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
9 #include "table/directions.h"
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
10
22
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
11 /* When true, GetTrackStatus for roads will treat roads under reconstruction
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
12 * as normal roads instead of impassable. This is used when detecting whether
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
13 * a road can be removed. This is of course ugly, but I don't know a better
7a15e52a1c8f (svn r23) -Some omments on the code (blathijs)
darkvater <darkvater@openttd.org>
parents: 13
diff changeset
14 * solution just like that... */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
15 static bool _road_special_gettrackstatus;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
16
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
17 void RoadVehEnterDepot(Vehicle *v);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
18
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
19
84
784a9e9bb932 (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight <truelight@openttd.org>
parents: 72
diff changeset
20 bool HasTileRoadAt(uint tile, int i)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
21 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
22 int mask;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
23 byte b;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
24
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
25 switch(GET_TILETYPE(tile)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
26 case MP_STREET:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
27 b = _map5[tile];
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
28
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
29 if ((b & 0xF0) == 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
30 } else if ((b & 0xF0) == 0x10) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
31 b = (b&8)?5:10;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
32 } else if ((b & 0xF0) == 0x20) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
33 return (~b & 3) == i;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
34 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
35 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
36 break;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
37
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
38 case MP_STATION:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
39 b = _map5[tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
40 if (!IS_BYTE_INSIDE(b, 0x43, 0x43+8))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
41 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
42 return ((~(b - 0x43) & 3) == i);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
43
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
44 case MP_TUNNELBRIDGE:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
45 mask = GetRoadBitsByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
46 b = 10; if (mask & 1) break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
47 b = 5; if (mask & 2) break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
48 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
49
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
50 default:
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
51 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
52 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
53
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
54 return HASBIT(b, i);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
55 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
56
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
57 static bool CheckAllowRemoveRoad(uint tile, uint br, bool *edge_road)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
58 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
59 int blocks;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
60 byte owner;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
61 uint n;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
62 *edge_road = true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
63
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
64 if (_game_mode == GM_EDITOR)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
65 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
66
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
67 blocks = GetRoadBitsByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
68 if (blocks == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
69 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
70
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
71 // Only do the special processing for actual players.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
72 if (_current_player >= MAX_PLAYERS)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
73 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
74
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
75 // A railway crossing has the road owner in the map3_lo byte.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
76 if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x10) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
77 owner = _map3_lo[tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
78 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
79 owner = _map_owner[tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
80 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
81 // Only do the special processing if the road is owned
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
82 // by a town
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
83 if (owner != OWNER_TOWN) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
84 return owner == OWNER_NONE || CheckOwnership(owner);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
85 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
86
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
87 if (_cheats.magic_bulldozer.value)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
88 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
89
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
90 // Get a bitmask of which neighbouring roads has a tile
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
91 n = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
92 if (blocks&0x25 && HasTileRoadAt(TILE_ADDXY(tile,-1, 0), 1)) n |= 8;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
93 if (blocks&0x2A && HasTileRoadAt(TILE_ADDXY(tile, 0, 1), 0)) n |= 4;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
94 if (blocks&0x19 && HasTileRoadAt(TILE_ADDXY(tile, 1, 0), 3)) n |= 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
95 if (blocks&0x16 && HasTileRoadAt(TILE_ADDXY(tile, 0,-1), 2)) n |= 1;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
96
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
97 // If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
98 // then allow it
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
99 if ((n & (n-1)) != 0 && (n & br) != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
100 Town *t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
101 *edge_road = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
102 // you can remove all kind of roads with extra dynamite
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
103 if (_patches.extra_dynamite)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
104 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
105
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
106 t = ClosestTownFromTile(tile, (uint)-1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
107 SET_DPARAM16(0, t->index);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
108 _error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
109 return false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
110 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
111
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
112 return true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
113 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
114
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
115 bool IsRoadDepotTile(TileIndex tile)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
116 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
117 return IS_TILETYPE(tile, MP_STREET) &&
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
118 (_map5[tile] & 0xF0) == 0x20;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
119 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
120
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
121 uint GetRoadBitsByTile(TileIndex tile)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
122 {
159
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
123 uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
124 return (byte)(r | (r >> 8));
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
125 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
126
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
127 // cost for removing inner/edge -roads
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
128 static const uint16 _road_remove_cost[2] = {50, 18};
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
129
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
130 /* Delete a piece of road
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
131 * p1 = piece type
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
132 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
133 int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
134 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
135 TileInfo ti;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
136 int32 cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
137 uint tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
138 Town *t;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
139 /* true if the roadpiece was always removeable,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
140 false if it was a center piece. Affects town ratings drop
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
141 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
142 bool edge_road;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
143
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
144 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
145
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
146 FindLandscapeHeight(&ti, x, y);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
147 tile = ti.tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
148 t = ClosestTownFromTile(tile, (uint)-1); // needed for town rating penalty
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
149
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
150 // allow deleting road under bridge
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
151 if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
152 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
153
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
154 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
155 bool b;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
156 _road_special_gettrackstatus = true;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
157 b = CheckAllowRemoveRoad(tile, p1, &edge_road);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
158 _road_special_gettrackstatus = false;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
159 if (!b)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
160 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
161 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
162
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
163 if (ti.type == MP_TUNNELBRIDGE) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
164 if (!EnsureNoVehicleZ(tile, GET_TILEHEIGHT(tile)))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
165 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
166
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
167 if ((ti.map5 & 0xE9) == 0xE8) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
168 if (p1 & 10) goto return_error;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
169 } else if ((ti.map5 & 0xE9) == 0xE9) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
170 if (p1 & 5) goto return_error;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
171 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
172 goto return_error;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
173
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
174 cost = _price.remove_road * 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
175
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
176 if (flags & DC_EXEC) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
177 _map5[tile] = ti.map5 & 0xC7;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
178 _map_owner[tile] = OWNER_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
179 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
180 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
181 return cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
182 } else if (ti.type == MP_STREET) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
183 if (!(ti.map5 & 0xF0)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
184 uint c = p1, t2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
185
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
186 if (ti.tileh != 0 && (ti.map5 == 5 || ti.map5 == 10)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
187 c |= (c & 0xC) >> 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
188 c |= (c & 0x3) << 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
189 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
190
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
191 // limit the bits to delete to the existing bits.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
192 if ((c &= ti.map5) == 0) goto return_error;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
193
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
194 // calculate the cost
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
195 t2 = c;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
196 cost = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
197 do {
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
198 if (t2&1) cost += _price.remove_road;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
199 } while(t2>>=1);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
200
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
201 // check if you're allowed to remove the street owned by a town
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
202 // removal allowance depends on difficulty setting
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
203 if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) {
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
204 if (!CheckforTownRating(tile, flags, t, ROAD_REMOVE))
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
205 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
206 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
207
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
208 if (flags & DC_EXEC) {
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
209 // checks if the owner is town than decrease town rating by 50 until you have
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
210 // a "Poor" town rating
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
211 if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR)
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
212 ChangeTownRating(t, -_road_remove_cost[(byte)edge_road], -100);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
213
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
214 _map5[tile] ^= c;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
215 if ((_map5[tile]&0xF) == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
216 DoClearSquare(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
217 else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
218 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
219
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
220 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
221 return cost;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
222 } else if (!(ti.map5 & 0xE0)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
223 byte c;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
224
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
225 if (!(ti.map5 & 8)) {
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
226 c = 2;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
227 if (p1 & 5) goto return_error;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
228 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
229 c = 1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
230 if (p1 & 10) goto return_error;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
231 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
232
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
233 cost = _price.remove_road * 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
234 if (flags & DC_EXEC) {
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
235 ModifyTile(tile,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
236 MP_SETTYPE(MP_RAILWAY) |
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
237 MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
238 _map3_hi[tile] & 0xF, /* map3_lo */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
239 c /* map5 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
240 );
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
241 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
242 return cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
243 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
244 goto return_error;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
245
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
246 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
247 return_error:;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
248 return_cmd_error(INVALID_STRING_ID);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
249 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
250 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
251
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
252
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
253 enum {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
254 ROAD_NW = 1, // NW road track
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
255 ROAD_SW = 2, // SW road track
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
256 ROAD_SE = 4, // SE road track
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
257 ROAD_NE = 8, // NE road track
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
258 ROAD_ALL = (ROAD_NW | ROAD_SW | ROAD_SE | ROAD_NE)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
259 };
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
260
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
261 static const byte _valid_tileh_slopes_road[3][15] = {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
262 // set of normal ones
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
263 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
264 ROAD_ALL, 0, 0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
265 ROAD_SW | ROAD_NE, 0, 0, // 3, 4, 5
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
266 ROAD_NW | ROAD_SE, 0, 0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
267 ROAD_NW | ROAD_SE, 0, 0, // 9, 10, 11
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
268 ROAD_SW | ROAD_NE, 0, 0
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
269 },
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
270 // allowed road for an evenly raised platform
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
271 {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
272 0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
273 ROAD_SW | ROAD_NW,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
274 ROAD_SW | ROAD_SE,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
275 ROAD_NW | ROAD_SE | ROAD_SW,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
276
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
277 ROAD_SE | ROAD_NE, // 4
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
278 ROAD_ALL,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
279 ROAD_SW | ROAD_NE | ROAD_SE,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
280 ROAD_ALL,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
281
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
282 ROAD_NW | ROAD_NE, // 8
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
283 ROAD_SW | ROAD_NE | ROAD_NW,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
284 ROAD_ALL,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
285 ROAD_ALL,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
286
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
287 ROAD_NW | ROAD_SE | ROAD_NE, // 12
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
288 ROAD_ALL,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
289 ROAD_ALL
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
290 },
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
291 // valid railway crossings on slopes
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
292 {
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
293 1, 0, 0, // 0, 1, 2
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
294 0, 0, 1, // 3, 4, 5
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
295 0, 1, 0, // 6, 7, 8
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
296 0, 1, 1, // 9, 10, 11
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
297 0, 1, 1, // 12, 13, 14
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
298 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
299 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
300
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
301
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
302 static uint32 CheckRoadSlope(int tileh, byte *pieces, byte existing)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
303 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
304 if (!(tileh & 0x10)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
305 byte road_bits = *pieces | existing;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
306
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
307 // no special foundation
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
308 if ((~_valid_tileh_slopes_road[0][tileh] & road_bits) == 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
309 // force that all bits are set when we have slopes
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
310 if (tileh != 0) *pieces |= _valid_tileh_slopes_road[0][tileh];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
311 return 0; // no extra cost
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
312 }
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
313
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
314 // foundation is used. Whole tile is leveled up
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
315 if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) {
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
316 return existing ? 0 : _price.terraform;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
317 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
318
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
319 // partly leveled up tile, only if there's no road on that tile
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
320 if ( !existing && (tileh == 1 || tileh == 2 || tileh == 4 || tileh == 8) ) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
321 // force full pieces.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
322 *pieces |= (*pieces & 0xC) >> 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
323 *pieces |= (*pieces & 0x3) << 2;
72
0ecf460b53fc (svn r73) -Fix: Wrong building of road-slopes for a future AI/Town
darkvater <darkvater@openttd.org>
parents: 39
diff changeset
324 return (*pieces == (ROAD_NE|ROAD_SW) || *pieces == (ROAD_SE|ROAD_NW)) ? _price.terraform : CMD_ERROR;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
325 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
326 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
327 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
328 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
329
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
330 /* Build a piece of road
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
331 * p1 = piece flags
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
332 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
333
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
334 int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
335 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
336 TileInfo ti;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
337 int32 cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
338 byte pieces = (byte)p1, existing = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
339 uint tile;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
340
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
341 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
342
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
343 FindLandscapeHeight(&ti, x, y);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
344 tile = ti.tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
345
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
346 // allow building road under bridge
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
347 if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
348 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
349
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
350 if (ti.type == MP_STREET) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
351 if (!(ti.map5 & 0xF0)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
352 if ( ((pieces) & (byte)(ti.map5)) == (pieces))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
353 return_cmd_error(STR_1007_ALREADY_BUILT);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
354 existing = ti.map5;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
355 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
356 if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
357 return_cmd_error(STR_1007_ALREADY_BUILT);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
358 goto do_clear;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
359 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
360 } else if (ti.type == MP_RAILWAY) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
361 byte m5;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
362
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
363 if (ti.tileh & 0x10) // very steep tile
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
364 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
365
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
366 if(!_valid_tileh_slopes_road[2][ti.tileh]) // prevent certain slopes
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
367 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
368
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
369 if (ti.map5 == 2) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
370 if (pieces & 5) goto do_clear;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
371 m5 = 0x10;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
372 } else if (ti.map5 == 1) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
373 if (pieces & 10) goto do_clear;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
374 m5 = 0x18;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
375 } else
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
376 goto do_clear;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
377
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
378 if (flags & DC_EXEC) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
379 ModifyTile(tile,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
380 MP_SETTYPE(MP_STREET) |
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
381 MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI | MP_MAP5,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
382 _current_player, /* map3_lo */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
383 _map3_lo[tile] & 0xF, /* map3_hi */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
384 m5 /* map5 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
385 );
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
386 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
387 return _price.build_road * 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
388 } else if (ti.type == MP_TUNNELBRIDGE) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
389
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
390 /* check for flat land */
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
391 if (ti.tileh & 0x10) // very steep tile
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
392 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
393
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
394 /* is this middle part of a bridge? */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
395 if ((ti.map5 & 0xC0) != 0xC0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
396 goto do_clear;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
397
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
398 /* only allow roads pertendicular to bridge */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
399 if ((pieces & 5) == (ti.map5 & 0x01))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
400 goto do_clear;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
401
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
402 /* check if clear land under bridge */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
403 if ((ti.map5 & 0xF8) == 0xE8) /* road under bridge */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
404 return_cmd_error(STR_1007_ALREADY_BUILT);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
405 else if ((ti.map5 & 0xE0) == 0xE0) /* other transport route under bridge */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
406 return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
407 else if ((ti.map5 & 0xF8) == 0xC8) /* water under bridge */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
408 return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
409
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
410 /* all checked, can build road now! */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
411 cost = _price.build_road * 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
412 if (flags & DC_EXEC) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
413 ModifyTile(tile,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
414 MP_MAPOWNER_CURRENT | MP_MAP5,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
415 (ti.map5 & 0xC7) | 0x28 // map5
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
416 );
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
417 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
418 return cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
419 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
420 do_clear:;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
421 if (DoCommandByTile(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR) == CMD_ERROR)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
422 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
423 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
424
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
425 cost = CheckRoadSlope(ti.tileh, &pieces, existing);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
426 if (cost == CMD_ERROR) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
427
84
784a9e9bb932 (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight <truelight@openttd.org>
parents: 72
diff changeset
428 if (cost && (!_patches.build_on_slopes || (!_patches.ainew_active && _is_ai_player)))
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
429 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
430
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
431 if (!(ti.type == MP_STREET && (ti.map5 & 0xF0) == 0)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
432 cost += DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
433 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
434 // Don't put the pieces that already exist
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
435 pieces &= ~ti.map5;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
436 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
437
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
438 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
439 byte t = pieces;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
440 while (t) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
441 if (t & 1) cost += _price.build_road;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
442 t >>= 1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
443 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
444 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
445
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
446 if (flags & DC_EXEC) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
447 if (ti.type != MP_STREET) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
448 _map_type_and_height[tile] &= 0xF;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
449 _map_type_and_height[tile] |= MP_STREET << 4;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
450 _map5[tile] = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
451 _map_owner[tile] = _current_player;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
452 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
453
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
454 _map5[tile] |= (byte)pieces;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
455
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
456 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
457 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
458 return cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
459 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
460
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
461 int32 DoConvertStreetRail(uint tile, uint totype, bool exec)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
462 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
463 // not a railroad crossing?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
464 if ((_map5[tile] & 0xF0) != 0x10) return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
465
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
466 // not owned by me?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
467 if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
468
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
469 // tile is already of requested type?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
470 if ( (uint)(_map3_hi[tile] & 0xF) == totype) return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
471
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
472 if (exec) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
473 // change type.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
474 _map3_hi[tile] = (_map3_hi[tile] & 0xF0) + totype;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
475 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
476 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
477
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
478 return _price.build_rail >> 1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
479 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
480
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
481
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
482 // Build a long piece of road.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
483 // x,y = end tile
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
484 // p1 = start tile
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
485 // p2&1 = start tile starts in the 2nd half
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
486 // p2&2 = end tile starts in the 2nd half
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
487 // p2&4 = direction (0 = along x, 1=along y)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
488 int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
489 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
490 uint start_tile, end_tile, tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
491 int mode;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
492 int32 cost,ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
493
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
494 start_tile = p1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
495 end_tile = TILE_FROM_XY(x, y);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
496
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
497 if (start_tile > end_tile || (start_tile == end_tile && (p2&1))) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
498 uint t = start_tile; start_tile = end_tile; end_tile = t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
499 p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
500 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
501
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
502 cost = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
503 tile = start_tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
504 // Start tile is the small number.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
505 for(;;) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
506 mode = (p2&4) ? 5 : 10;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
507
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
508 if (tile == start_tile && (p2&1))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
509 mode &= (4+2);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
510 else if (tile == end_tile && !(p2&2))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
511 mode &= (1+8);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
512
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
513 ret = DoCommandByTile(tile, mode, 0, flags, CMD_BUILD_ROAD);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
514 if (ret == CMD_ERROR) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
515 if (_error_message != STR_1007_ALREADY_BUILT)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
516 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
517 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
518 cost += ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
519 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
520
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
521 if (tile == end_tile)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
522 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
523
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
524 tile += (p2&4)?TILE_XY(0,1):TILE_XY(1,0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
525 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
526
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
527 // already built?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
528 if (cost == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
529 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
530
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
531 return cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
532 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
533
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
534 // Remove a long piece of road.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
535 // x,y = end tile
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
536 // p1 = start tile
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
537 // p2&1 = start tile starts in the 2nd half
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
538 // p2&2 = end tile starts in the 2nd half
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
539 // p2&4 = direction (0 = along x, 1=along y)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
540 int32 CmdRemoveLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
541 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
542 uint start_tile, end_tile, tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
543 int32 cost,ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
544
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
545 start_tile = p1;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
546 end_tile = TILE_FROM_XY(x, y);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
547
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
548 if (start_tile > end_tile || (start_tile == end_tile && (p2&1))) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
549 uint t = start_tile; start_tile = end_tile; end_tile = t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
550 p2 ^= IS_INT_INSIDE(p2&3, 1, 3) ? 3 : 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
551 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
552
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
553 cost = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
554 tile = start_tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
555 // Start tile is the small number.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
556 for(;;) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
557 uint bits = (p2 & 4) ? ROAD_SE | ROAD_NW : ROAD_SW | ROAD_NE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
558 if (tile == end_tile && !(p2&2)) bits &= ROAD_NW | ROAD_NE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
559 if (tile == start_tile && (p2&1)) bits &= ROAD_SE | ROAD_SW;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
560
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
561 // try to remove the halves.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
562 if (bits) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
563 ret = DoCommandByTile(tile, bits, 0, flags, CMD_REMOVE_ROAD);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
564 if (ret != CMD_ERROR)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
565 cost += ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
566 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
567
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
568 if (tile == end_tile)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
569 break;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
570
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
571 tile += (p2&4)?TILE_XY(0,1):TILE_XY(1,0);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
572 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
573
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
574 // already built?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
575 if (cost == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
576 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
577
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
578 return cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
579 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
580
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
581 /* Build a road depot
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
582 * p1 - direction (0-3)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
583 * p2 - unused
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
584 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
585
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
586 int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
587 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
588 TileInfo ti;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
589 int32 cost;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
590 Depot *dep;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
591 uint tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
592
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
593 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
594
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
595 FindLandscapeHeight(&ti, x, y);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
596
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
597 tile = ti.tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
598
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
599 if (!EnsureNoVehicle(tile))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
600 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
601
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
602 if (ti.tileh != 0) {
84
784a9e9bb932 (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight <truelight@openttd.org>
parents: 72
diff changeset
603 if (!_patches.build_on_slopes || (ti.tileh & 0x10 || !((0x4C >> p1) & ti.tileh) ))
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
604 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
605 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
606
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
607 cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
608 if (cost == CMD_ERROR)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
609 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
610
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
611 dep = AllocateDepot();
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
612 if (dep == NULL)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
613 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
614
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
615 if (flags & DC_EXEC) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
616 if (_current_player == _local_player)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
617 _last_built_road_depot_tile = (TileIndex)tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
618
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
619 dep->xy = tile;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
620 dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
621
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
622 ModifyTile(tile,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
623 MP_SETTYPE(MP_STREET) |
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
624 MP_MAPOWNER_CURRENT | MP_MAP5,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
625 (p1 | 0x20) /* map5 */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
626 );
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
627
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
628 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
629 return cost + _price.build_road_depot;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
630 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
631
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
632 static int32 RemoveRoadDepot(uint tile, uint32 flags)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
633 {
149
811875caee5f (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater <darkvater@openttd.org>
parents: 84
diff changeset
634 if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
635 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
636
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
637 if (!EnsureNoVehicle(tile))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
638 return CMD_ERROR;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
639
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
640 if (flags & DC_EXEC) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
641 DoDeleteDepot(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
642 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
643
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
644 return _price.remove_road_depot;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
645 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
646
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
647 #define M(x) (1<<(x))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
648
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
649 static int32 ClearTile_Road(uint tile, byte flags) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
650 int32 ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
651 byte m5 = _map5[tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
652
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
653 if ( (m5 & 0xF0) == 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
654 byte b = m5 & 0xF;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
655
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
656 if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
657 if ( (!(flags & DC_AI_BUILDING) || _map_owner[tile]!=OWNER_TOWN) && flags&DC_AUTO)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
658 return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
659 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
660 return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
661 } else if ( (m5 & 0xE0) == 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
662 if (flags & DC_AUTO)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
663 return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
664
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
665 ret = DoCommandByTile(tile, (m5&8)?5:10, 0, flags, CMD_REMOVE_ROAD);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
666 if (ret == CMD_ERROR)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
667 return CMD_ERROR;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
668
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
669 if (flags & DC_EXEC) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
670 DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
671 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
672
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
673 return ret;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
674 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
675 if (flags & DC_AUTO)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
676 return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
677 return RemoveRoadDepot(tile,flags);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
678 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
679 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
680
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
681
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
682 typedef struct DrawRoadTileStruct {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
683 uint16 image;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
684 byte subcoord_x;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
685 byte subcoord_y;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
686 } DrawRoadTileStruct;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
687
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
688 typedef struct DrawRoadSeqStruct {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
689 uint32 image;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
690 byte subcoord_x;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
691 byte subcoord_y;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
692 byte width;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
693 byte height;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
694 } DrawRoadSeqStruct;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
695
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
696 #include "table/road_land.h"
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
697
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
698
84
784a9e9bb932 (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight <truelight@openttd.org>
parents: 72
diff changeset
699 uint GetRoadFoundation(uint tileh, uint bits) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
700 int i;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
701 // normal level sloped building
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
702 if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
703 return tileh;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
704
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
705 // inclined sloped building
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
706 if ( ((i=0, tileh == 1) || (i+=2, tileh == 2) || (i+=2, tileh == 4) || (i+=2, tileh == 8)) &&
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
707 ((bits == (ROAD_SW | ROAD_NE)) || (i++, bits == (ROAD_NW | ROAD_SE))))
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
708 return i + 15;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
709
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
710 // rail crossing
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
711 if ((bits & 0x10) && _valid_tileh_slopes_road[2][tileh])
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
712 return tileh;
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
713
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
714 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
715 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
716
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
717 const byte _road_sloped_sprites[14] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
718 0, 0, 2, 0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
719 0, 1, 0, 0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
720 3, 0, 0, 0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
721 0, 0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
722 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
723
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
724 static void DrawTile_Road(TileInfo *ti)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
725 {
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
726 uint32 image;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
727 byte m2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
728 const byte *s;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
729
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
730 if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
731 const DrawRoadTileStruct *drts;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
732
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
733 if (ti->tileh != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
734 int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
735 if (f) DrawFoundation(ti, f);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
736
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
737 // default sloped sprites..
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
738 if (ti->tileh != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
739 image = _road_sloped_sprites[ti->tileh - 1] + 0x53F;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
740 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
741 image = _road_tile_sprites_1[ti->map5 & 0xF];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
742 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
743 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
744 image = _road_tile_sprites_1[ti->map5 & 0xF];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
745 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
746
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
747 m2 = _map2[ti->tile] & 7;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
748
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
749 if (m2 == 0) image |= 0x3178000;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
750
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
751 if (_map3_hi[ti->tile] & 0x80) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
752 image += 19;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
753 } else if (m2 > 1 && m2 != 6) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
754 image -= 19; /* pavement along the road? */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
755 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
756
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
757 DrawGroundSprite(image);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
758
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
759 if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
760 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
761
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
762 if (m2 >= 6) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
763 // roadwork
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
764 DrawGroundSprite(0x586 + ((ti->map5&8)!=0 ? 0 : 1));
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
765 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
766 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
767
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
768 drts = (const DrawRoadTileStruct*)_road_display_table[m2][ti->map5 & 0xF];
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
769
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
770 while ((image = drts->image) != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
771 int x = ti->x | drts->subcoord_x;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
772 int y = ti->y | drts->subcoord_y;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
773 byte z = ti->z;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
774 if (ti->tileh != 0) z = GetSlopeZ(x, y);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
775 AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
776 drts++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
777 }
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
778 } else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
779 int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF);
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
780 if (f) DrawFoundation(ti, f);
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
781
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
782 image = 0x55B;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
783
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
784 if ( (ti->map5 & 8) != 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
785 image--;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
786
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
787 if ( (ti->map5 & 4) != 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
788 image += 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
789
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
790 if ( _map3_hi[ti->tile] & 0x80) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
791 image += 8;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
792 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
793 m2 = _map2[ti->tile] & 7;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
794 if (m2 == 0) image |= 0x3178000;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
795 if (m2 > 1) image += 4;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
796 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
797
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
798 DrawGroundSprite(image + (_map3_hi[ti->tile] & 0xF) * 12);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
799 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
800 uint32 ormod;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
801 int player;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
802 const DrawRoadSeqStruct *drss;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
803
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
804 if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
805
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
806 ormod = 0x315;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
807 player = _map_owner[ti->tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
808 if (player < MAX_PLAYERS)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
809 ormod = PLAYER_SPRITE_COLOR(player);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
810
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
811 s = _road_display_datas[ti->map5 & 0xF];
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
812
222
d1b097f4593b (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater <darkvater@openttd.org>
parents: 204
diff changeset
813 DrawGroundSprite(*(const uint32*)s);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
814 s += sizeof(uint32);
222
d1b097f4593b (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater <darkvater@openttd.org>
parents: 204
diff changeset
815 drss = (const DrawRoadSeqStruct*)s;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
816
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
817 while ((image=drss->image) != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
818 if (image & 0x8000)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
819 image |= ormod;
204
6b6352ec7434 (svn r205) -Fix: [1026271] Vehicle depots not transparent with transparent buildings.
darkvater <darkvater@openttd.org>
parents: 201
diff changeset
820 if (!(_display_opt & DO_TRANS_BUILDINGS)) // show transparent depots
6b6352ec7434 (svn r205) -Fix: [1026271] Vehicle depots not transparent with transparent buildings.
darkvater <darkvater@openttd.org>
parents: 201
diff changeset
821 image = (image & 0x3FFF) | 0x3224000;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
822
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
823 AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x,
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
824 ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
825 drss++;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
826 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
827 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
828 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
829
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
830 void DrawRoadDepotSprite(int x, int y, int image)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
831 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
832 uint32 ormod;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
833 const DrawRoadSeqStruct *dtss;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
834 const byte *t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
835
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
836 ormod = PLAYER_SPRITE_COLOR(_local_player);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
837
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
838 t = _road_display_datas[image];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
839
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
840 x+=33;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
841 y+=17;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
842
222
d1b097f4593b (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater <darkvater@openttd.org>
parents: 204
diff changeset
843 DrawSprite(*(const uint32*)t, x, y);
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
844 t += sizeof(uint32);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
845
222
d1b097f4593b (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater <darkvater@openttd.org>
parents: 204
diff changeset
846 for(dtss = (const DrawRoadSeqStruct *)t; dtss->image != 0; dtss++) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
847 Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
848
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
849 image = dtss->image;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
850 if (image & 0x8000)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
851 image |= ormod;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
852
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
853 DrawSprite(image, x + pt.x, y + pt.y);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
854 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
855 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
856
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
857 uint GetSlopeZ_Road(TileInfo *ti)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
858 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
859 uint z = ti->z;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
860 int th = ti->tileh;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
861
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
862 // check if it's a foundation
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
863 if (ti->tileh != 0) {
13
c8795721b2d5 (svn r14) Fix: railroad crossings on slopes are now possible
dominik <dominik@openttd.org>
parents: 0
diff changeset
864 if ((ti->map5 & 0xE0) == 0) { /* road or crossing */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
865 uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
866 if (f != 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
867 if (f < 15) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
868 // leveled foundation
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
869 return z + 8;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
870 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
871 // inclined foundation
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
872 th = _inclined_tileh[f - 15];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
873 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
874 } else if ((ti->map5 & 0xF0) == 0x20) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
875 // depot
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
876 return z + 8;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
877 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
878 return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
879 }
39
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
880 return z; // normal Z if no slope
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
881 }
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
882
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
883 uint GetSlopeTileh_Road(TileInfo *ti)
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
884 {
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
885 // check if it's a foundation
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
886 if (ti->tileh != 0) {
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
887 if ((ti->map5 & 0xE0) == 0) { /* road or crossing */
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
888 uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F);
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
889 if (f != 0) {
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
890 if (f < 15) {
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
891 // leveled foundation
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
892 return 0;
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
893 }
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
894 // inclined foundation
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
895 return _inclined_tileh[f - 15];
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
896 }
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
897 } else if ((ti->map5 & 0xF0) == 0x20) {
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
898 // depot
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
899 return 0;
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
900 }
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
901 }
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
902 return ti->tileh;
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
903 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
904
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
905 static void GetAcceptedCargo_Road(uint tile, AcceptedCargo *ac)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
906 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
907 /* not used */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
908 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
909
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
910 static void AnimateTile_Road(uint tile)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
911 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
912 if ((_map5[tile] & 0xF0) == 0x10) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
913 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
914 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
915 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
916
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
917 static const byte _town_road_types[5][2] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
918 {1,1},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
919 {2,2},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
920 {2,2},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
921 {5,5},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
922 {3,2},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
923 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
924
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
925 static const byte _town_road_types_2[5][2] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
926 {1,1},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
927 {2,2},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
928 {3,2},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
929 {3,2},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
930 {3,2},
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
931 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
932
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
933
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
934 static void TileLoop_Road(uint tile)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
935 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
936 Town *t;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
937 int grp;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
938
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
939 if (_opt.landscape == LT_HILLY) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
940 // Fix snow style if the road is above the snowline
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
941 if ((_map3_hi[tile] & 0x80) != ((GetTileZ(tile) > _opt.snow_line) ? 0x80 : 0x00)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
942 _map3_hi[tile] ^= 0x80;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
943 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
944 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
945 } else if (_opt.landscape == LT_DESERT) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
946 // Fix desert style
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
947 if (GetMapExtraBits(tile) == 1 && !(_map3_hi[tile] & 0x80)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
948 _map3_hi[tile] |= 0x80;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
949 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
950 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
951 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
952
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
953 if (_map5[tile] & 0xE0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
954 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
955
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
956 if ((_map2[tile] & 7) < 6) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
957 t = ClosestTownFromTile(tile, (uint)-1);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
958 grp = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
959 if (t != NULL) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
960 // If in the scenario editor, set the owner to a town.
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
961 if (_game_mode == GM_EDITOR) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
962 _map_owner[tile] = OWNER_TOWN;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
963 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
964
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
965 grp = GetTownRadiusGroup(t, tile);
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
966
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
967 // Show an animation to indicate road work
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
968 if (t->road_build_months != 0 &&
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
969 !(GetTileDist(t->xy, tile) >= 8 && grp==0) &&
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
970 (_map5[tile]==5 || _map5[tile]==10)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
971 if (GetTileSlope(tile, NULL) == 0 && EnsureNoVehicle(tile) && CHANCE16(1,20)) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
972 _map2[tile] = ((_map2[tile]&7) <= 1) ? 6 : 7;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
973
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
974 SndPlayTileFx(0x1F,tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
975 CreateEffectVehicleAbove(
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
976 GET_TILE_X(tile) * 16 + 7,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
977 GET_TILE_Y(tile) * 16 + 7,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
978 0,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
979 EV_ROADWORK);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
980 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
981 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
982 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
983 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
984 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
985
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
986 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
987 const byte *p = (_opt.landscape == LT_CANDY) ? _town_road_types_2[grp] : _town_road_types[grp];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
988 byte b = _map2[tile] & 7;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
989
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
990 if (b == p[0])
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
991 return;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
992
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
993 if (b == p[1]) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
994 b = p[0];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
995 } else if (b == 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
996 b = p[1];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
997 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
998 b = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
999 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1000 _map2[tile] = (_map2[tile] & ~7) | b;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1001 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1002 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1003 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1004 // Handle road work
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1005
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1006 byte b = _map2[tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1007 if (b < 0x80) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1008 _map2[tile] = b + 8;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1009 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1010 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1011 _map2[tile] = ((b&7) == 6) ? 1 : 2;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1012 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1013 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1014 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1015
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1016 void ShowRoadDepotWindow(uint tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1017
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1018 static void ClickTile_Road(uint tile)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1019 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1020 if ((_map5[tile] & 0xF0) == 0x20) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1021 ShowRoadDepotWindow(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1022 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1023 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1024
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1025 static const byte _road_trackbits[16] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1026 0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1027 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1028
159
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
1029 static uint32 GetTileTrackStatus_Road(uint tile, TransportType mode) {
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
1030 if (mode == TRANSPORT_RAIL) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1031 if ((_map5[tile] & 0xF0) != 0x10)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1032 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1033 return _map5[tile] & 8 ? 0x101 : 0x202;
159
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
1034 } else if (mode == TRANSPORT_ROAD) {
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1035 byte b = _map5[tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1036 if ((b & 0xF0) == 0) {
159
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
1037 /* Ordinary road */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1038 if (!_road_special_gettrackstatus && (_map2[tile]&7) >= 6)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1039 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1040 return _road_trackbits[b&0xF] * 0x101;
159
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
1041 } else if ((b&0xF0) == 0x10) {
a4e15430335b (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight <truelight@openttd.org>
parents: 149
diff changeset
1042 /* Crossing */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1043 uint32 r = 0x101;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1044 if (b&8) r <<= 1;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1045
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1046 if (b&4) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1047 r *= 0x10001;
201
f2b49b0674c6 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight <truelight@openttd.org>
parents: 159
diff changeset
1048 }
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1049 return r;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1050 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1051 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1052 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1053 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1054
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1055 static const StringID _road_tile_strings[] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1056 STR_1818_ROAD_RAIL_LEVEL_CROSSING,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1057 STR_1817_ROAD_VEHICLE_DEPOT,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1058
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1059 STR_1814_ROAD,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1060 STR_1814_ROAD,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1061 STR_1814_ROAD,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1062 STR_1815_ROAD_WITH_STREETLIGHTS,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1063 STR_1814_ROAD,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1064 STR_1816_TREE_LINED_ROAD,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1065 STR_1814_ROAD,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1066 STR_1814_ROAD,
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1067 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1068
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1069 static void GetTileDesc_Road(uint tile, TileDesc *td)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1070 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1071 int i = (_map5[tile] >> 4);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1072 if (i == 0)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1073 i = (_map2[tile] & 7) + 3;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1074 td->str = _road_tile_strings[i - 1];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1075 td->owner = _map_owner[tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1076 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1077
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1078 static const byte _roadveh_enter_depot_unk0[4] = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1079 8, 9, 0, 1
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1080 };
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1081
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1082 static uint32 VehicleEnter_Road(Vehicle *v, uint tile, int x, int y)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1083 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1084 if ((_map5[tile] & 0xF0) == 0x10) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1085 if (v->type == VEH_Train && (_map5[tile] & 4) == 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1086 /* train crossing a road */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1087 SndPlayVehicleFx(12, v);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1088 _map5[tile] |= 4;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1089 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1090 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1091 } else if ((_map5[tile]&0xF0) == 0x20){
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1092 if (v->type == VEH_Road && v->u.road.frame == 11) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1093 if (_roadveh_enter_depot_unk0[_map5[tile]&3] == v->u.road.state) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1094 RoadVehEnterDepot(v);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1095 return 4;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1096 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1097 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1098 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1099 return 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1100 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1101
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1102 static void VehicleLeave_Road(Vehicle *v, uint tile, int x, int y)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1103 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1104 if ((_map5[tile] & 0xF0) == 0x10 && v->type == VEH_Train && v->next == NULL) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1105 _map5[tile] &= ~4;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1106 MarkTileDirtyByTile(tile);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1107 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1108 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1109
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1110 static void ChangeTileOwner_Road(uint tile, byte old_player, byte new_player)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1111 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1112 byte b;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1113
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1114 // road/rail crossing where the road is owned by the current player?
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1115 if (old_player == _map3_lo[tile] && (_map5[tile]&0xF0) == 0x10) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1116 _map3_lo[tile] = (new_player == 0xFF) ? OWNER_NONE : new_player;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1117 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1118
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1119 if (_map_owner[tile] != old_player)
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1120 return;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1121
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1122 if (new_player != 255) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1123 _map_owner[tile] = new_player;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1124 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1125 b = _map5[tile]&0xF0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1126 if (b == 0) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1127 _map_owner[tile] = OWNER_NONE;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1128 } else if (b == 0x10) {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1129 _map5[tile] = (_map5[tile]&8) ? 0x5 : 0xA;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1130 _map_owner[tile] = _map3_lo[tile];
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1131 _map3_lo[tile] = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1132 _map3_hi[tile] &= 0x80;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1133 } else {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1134 DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1135 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1136 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1137 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1138
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1139 void InitializeRoad()
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1140 {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1141 _last_built_road_depot_tile = 0;
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1142 }
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1143
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1144 const TileTypeProcs _tile_type_road_procs = {
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1145 DrawTile_Road, /* draw_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1146 GetSlopeZ_Road, /* get_slope_z_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1147 ClearTile_Road, /* clear_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1148 GetAcceptedCargo_Road, /* get_accepted_cargo_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1149 GetTileDesc_Road, /* get_tile_desc_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1150 GetTileTrackStatus_Road, /* get_tile_track_status_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1151 ClickTile_Road, /* click_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1152 AnimateTile_Road, /* animate_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1153 TileLoop_Road, /* tile_loop_clear */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1154 ChangeTileOwner_Road, /* change_tile_owner_clear */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1155 NULL, /* get_produced_cargo_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1156 VehicleEnter_Road, /* vehicle_enter_tile_proc */
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1157 VehicleLeave_Road, /* vehicle_leave_tile_proc */
39
927ba896b4a5 (svn r40) Final slope graphics fix
dominik <dominik@openttd.org>
parents: 22
diff changeset
1158 GetSlopeTileh_Road, /* get_slope_tileh_proc */
0
fa6ee4d75c8a (svn r1) Import of revision 975 of old (crashed) SVN
truelight <truelight@openttd.org>
parents:
diff changeset
1159 };