Mercurial > hg > openttd
comparison water_cmd.c @ 3491:6aef91e18846 draft
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
Remove DoCommandByTile(), because now it does the same as DoCommand()
author | tron <tron@openttd.org> |
---|---|
date | Mon, 10 Apr 2006 07:15:58 +0000 |
parents | ae76c6e2369a |
children | 5e564dc2f774 |
comparison
equal
deleted
inserted
replaced
3490:1f9cfbde101b | 3491:6aef91e18846 |
---|---|
40 | 40 |
41 | 41 |
42 static void FloodVehicle(Vehicle *v); | 42 static void FloodVehicle(Vehicle *v); |
43 | 43 |
44 /** Build a ship depot. | 44 /** Build a ship depot. |
45 * @param x,y tile coordinates where ship depot is built | 45 * @param tile tile where ship depot is built |
46 * @param p1 depot direction (0 == X or 1 == Y) | 46 * @param p1 depot direction (0 == X or 1 == Y) |
47 * @param p2 unused | 47 * @param p2 unused |
48 */ | 48 */ |
49 int32 CmdBuildShipDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) | 49 int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
50 { | 50 { |
51 TileIndex tile, tile2; | 51 TileIndex tile2; |
52 | 52 |
53 int32 cost, ret; | 53 int32 cost, ret; |
54 Depot *depot; | 54 Depot *depot; |
55 | 55 |
56 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); | 56 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
57 | 57 |
58 if (p1 > 1) return CMD_ERROR; | 58 if (p1 > 1) return CMD_ERROR; |
59 | 59 |
60 tile = TileVirtXY(x, y); | |
61 if (!EnsureNoVehicle(tile)) return CMD_ERROR; | 60 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
62 | 61 |
63 tile2 = tile + (p1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0)); | 62 tile2 = tile + (p1 ? TileDiffXY(0, 1) : TileDiffXY(1, 0)); |
64 if (!EnsureNoVehicle(tile2)) return CMD_ERROR; | 63 if (!EnsureNoVehicle(tile2)) return CMD_ERROR; |
65 | 64 |
66 if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2)) | 65 if (!IsClearWaterTile(tile) || !IsClearWaterTile(tile2)) |
67 return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); | 66 return_cmd_error(STR_3801_MUST_BE_BUILT_ON_WATER); |
68 | 67 |
69 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 68 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
70 if (CmdFailed(ret)) return CMD_ERROR; | 69 if (CmdFailed(ret)) return CMD_ERROR; |
71 ret = DoCommandByTile(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 70 ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
72 if (CmdFailed(ret)) return CMD_ERROR; | 71 if (CmdFailed(ret)) return CMD_ERROR; |
73 | 72 |
74 // pretend that we're not making land from the water even though we actually are. | 73 // pretend that we're not making land from the water even though we actually are. |
75 cost = 0; | 74 cost = 0; |
76 | 75 |
121 { | 120 { |
122 int32 ret; | 121 int32 ret; |
123 int delta; | 122 int delta; |
124 | 123 |
125 // middle tile | 124 // middle tile |
126 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 125 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
127 if (CmdFailed(ret)) return CMD_ERROR; | 126 if (CmdFailed(ret)) return CMD_ERROR; |
128 | 127 |
129 delta = TileOffsByDir(dir); | 128 delta = TileOffsByDir(dir); |
130 // lower tile | 129 // lower tile |
131 ret = DoCommandByTile(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 130 ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
132 if (CmdFailed(ret)) return CMD_ERROR; | 131 if (CmdFailed(ret)) return CMD_ERROR; |
133 if (GetTileSlope(tile - delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); | 132 if (GetTileSlope(tile - delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
134 | 133 |
135 // upper tile | 134 // upper tile |
136 ret = DoCommandByTile(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 135 ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
137 if (CmdFailed(ret)) return CMD_ERROR; | 136 if (CmdFailed(ret)) return CMD_ERROR; |
138 if (GetTileSlope(tile + delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); | 137 if (GetTileSlope(tile + delta, NULL)) return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
139 | 138 |
140 if (flags & DC_EXEC) { | 139 if (flags & DC_EXEC) { |
141 MakeLock(tile, dir); | 140 MakeLock(tile, dir); |
171 MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); | 170 MarkTileDirtyByTile(TILE_ADDXY(tile, 1, 0)); |
172 MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); | 171 MarkTileDirtyByTile(TILE_ADDXY(tile, -1, 0)); |
173 } | 172 } |
174 | 173 |
175 /** Builds a lock (ship-lift) | 174 /** Builds a lock (ship-lift) |
176 * @param x,y tile coordinates where to place the lock | 175 * @param tile tile where to place the lock |
177 * @param p1 unused | 176 * @param p1 unused |
178 * @param p2 unused | 177 * @param p2 unused |
179 */ | 178 */ |
180 int32 CmdBuildLock(int x, int y, uint32 flags, uint32 p1, uint32 p2) | 179 int32 CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
181 { | 180 { |
182 TileIndex tile = TileVirtXY(x, y); | |
183 DiagDirection dir; | 181 DiagDirection dir; |
184 | 182 |
185 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); | 183 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
186 | 184 |
187 switch (GetTileSlope(tile, NULL)) { | 185 switch (GetTileSlope(tile, NULL)) { |
193 } | 191 } |
194 return DoBuildShiplift(tile, dir, flags); | 192 return DoBuildShiplift(tile, dir, flags); |
195 } | 193 } |
196 | 194 |
197 /** Build a piece of canal. | 195 /** Build a piece of canal. |
198 * @param x,y end tile of stretch-dragging | 196 * @param tile end tile of stretch-dragging |
199 * @param p1 start tile of stretch-dragging | 197 * @param p1 start tile of stretch-dragging |
200 * @param p2 unused | 198 * @param p2 unused |
201 */ | 199 */ |
202 int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2) | 200 int32 CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
203 { | 201 { |
204 int32 cost; | 202 int32 cost; |
205 int size_x, size_y; | 203 int size_x, size_y; |
204 int x; | |
205 int y; | |
206 int sx, sy; | 206 int sx, sy; |
207 | 207 |
208 if (p1 >= MapSize()) return CMD_ERROR; | 208 if (p1 >= MapSize()) return CMD_ERROR; |
209 | 209 |
210 x = TileX(tile); | |
211 y = TileY(tile); | |
210 sx = TileX(p1); | 212 sx = TileX(p1); |
211 sy = TileY(p1); | 213 sy = TileY(p1); |
212 /* x,y are in pixel-coordinates, transform to tile-coordinates | |
213 * to be able to use the BEGIN_TILE_LOOP() macro */ | |
214 x >>= 4; y >>= 4; | |
215 | 214 |
216 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); | 215 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
217 | 216 |
218 if (x < sx) intswap(x, sx); | 217 if (x < sx) intswap(x, sx); |
219 if (y < sy) intswap(y, sy); | 218 if (y < sy) intswap(y, sy); |
239 if (IsWaterUnderBridge(tile)) return_cmd_error(STR_1007_ALREADY_BUILT); | 238 if (IsWaterUnderBridge(tile)) return_cmd_error(STR_1007_ALREADY_BUILT); |
240 | 239 |
241 if (flags & DC_EXEC) SetWaterUnderBridge(tile); | 240 if (flags & DC_EXEC) SetWaterUnderBridge(tile); |
242 } else { | 241 } else { |
243 /* no bridge, try to clear it. */ | 242 /* no bridge, try to clear it. */ |
244 int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); | 243 int32 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
245 | 244 |
246 if (CmdFailed(ret)) return ret; | 245 if (CmdFailed(ret)) return ret; |
247 cost += ret; | 246 cost += ret; |
248 | 247 |
249 if (flags & DC_EXEC) MakeWater(tile); | 248 if (flags & DC_EXEC) MakeWater(tile); |
522 /* FALLTHROUGH */ | 521 /* FALLTHROUGH */ |
523 | 522 |
524 case MP_CLEAR: | 523 case MP_CLEAR: |
525 case MP_TREES: | 524 case MP_TREES: |
526 _current_player = OWNER_WATER; | 525 _current_player = OWNER_WATER; |
527 if (!CmdFailed(DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { | 526 if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { |
528 MakeShore(target); | 527 MakeShore(target); |
529 MarkTileDirtyByTile(target); | 528 MarkTileDirtyByTile(target); |
530 } | 529 } |
531 break; | 530 break; |
532 | 531 |
555 { | 554 { |
556 Vehicle *v = FindVehicleOnTileZ(target, 0); | 555 Vehicle *v = FindVehicleOnTileZ(target, 0); |
557 if (v != NULL) FloodVehicle(v); | 556 if (v != NULL) FloodVehicle(v); |
558 } | 557 } |
559 | 558 |
560 if (!CmdFailed(DoCommandByTile(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { | 559 if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) { |
561 MakeWater(target); | 560 MakeWater(target); |
562 MarkTileDirtyByTile(target); | 561 MarkTileDirtyByTile(target); |
563 } | 562 } |
564 } | 563 } |
565 } | 564 } |
682 if (!IsTileOwner(tile, old_player)) return; | 681 if (!IsTileOwner(tile, old_player)) return; |
683 | 682 |
684 if (new_player != OWNER_SPECTATOR) { | 683 if (new_player != OWNER_SPECTATOR) { |
685 SetTileOwner(tile, new_player); | 684 SetTileOwner(tile, new_player); |
686 } else { | 685 } else { |
687 DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); | 686 DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
688 } | 687 } |
689 } | 688 } |
690 | 689 |
691 static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y) | 690 static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y) |
692 { | 691 { |