172 int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
173 int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
173 { |
174 { |
174 TileIndex tile = TileVirtXY(x, y); |
175 TileIndex tile = TileVirtXY(x, y); |
175 Waypoint *wp; |
176 Waypoint *wp; |
176 uint tileh; |
177 uint tileh; |
177 uint dir; |
178 Axis axis; |
178 |
179 |
179 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
180 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
180 |
181 |
181 /* if custom gfx are used, make sure it is within bounds */ |
182 /* if custom gfx are used, make sure it is within bounds */ |
182 if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR; |
183 if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR; |
183 |
184 |
184 if (!IsTileType(tile, MP_RAILWAY) || ((dir = 0, _m[tile].m5 != 1) && (dir = 1, _m[tile].m5 != 2))) |
185 if (!IsTileType(tile, MP_RAILWAY) || ( |
|
186 (axis = AXIS_X, _m[tile].m5 != TRACK_BIT_DIAG1) && |
|
187 (axis = AXIS_Y, _m[tile].m5 != TRACK_BIT_DIAG2) |
|
188 )) { |
185 return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK); |
189 return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK); |
|
190 } |
186 |
191 |
187 if (!CheckTileOwnership(tile)) |
192 if (!CheckTileOwnership(tile)) |
188 return CMD_ERROR; |
193 return CMD_ERROR; |
189 |
194 |
190 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
195 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
191 |
196 |
192 tileh = GetTileSlope(tile, NULL); |
197 tileh = GetTileSlope(tile, NULL); |
193 if (tileh != 0) { |
198 if (tileh != 0) { |
194 if (!_patches.build_on_slopes || IsSteepTileh(tileh) || !(tileh & (0x3 << dir)) || !(tileh & ~(0x3 << dir))) |
199 if (!_patches.build_on_slopes || IsSteepTileh(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis))) |
195 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
200 return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); |
196 } |
201 } |
197 |
202 |
198 /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */ |
203 /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */ |
199 wp = FindDeletedWaypointCloseTo(tile); |
204 wp = FindDeletedWaypointCloseTo(tile); |
206 wp->town_cn = 0; |
211 wp->town_cn = 0; |
207 } |
212 } |
208 |
213 |
209 if (flags & DC_EXEC) { |
214 if (flags & DC_EXEC) { |
210 const StationSpec *spec = NULL; |
215 const StationSpec *spec = NULL; |
211 ModifyTile(tile, MP_MAP2 | MP_MAP5, wp->index, RAIL_TYPE_WAYPOINT | dir); |
216 MakeRailWaypoint(tile, GetTileOwner(tile), axis, GB(_m[tile].m3, 0, 4), wp->index); |
|
217 MarkTileDirtyByTile(tile); |
212 |
218 |
213 if (GB(p1, 0, 8) < GetNumCustomStations(STAT_CLASS_WAYP)) |
219 if (GB(p1, 0, 8) < GetNumCustomStations(STAT_CLASS_WAYP)) |
214 spec = GetCustomStation(STAT_CLASS_WAYP, GB(p1, 0, 8)); |
220 spec = GetCustomStation(STAT_CLASS_WAYP, GB(p1, 0, 8)); |
215 |
221 |
216 if (spec != NULL) { |
222 if (spec != NULL) { |
292 |
298 |
293 wp->deleted = 30; // let it live for this many days before we do the actual deletion. |
299 wp->deleted = 30; // let it live for this many days before we do the actual deletion. |
294 RedrawWaypointSign(wp); |
300 RedrawWaypointSign(wp); |
295 |
301 |
296 if (justremove) { |
302 if (justremove) { |
297 ModifyTile(tile, MP_MAP2_CLEAR | MP_MAP5, 1<<direction); |
303 MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GB(_m[tile].m3, 0, 4)); |
298 CLRBIT(_m[tile].m3, 4); |
304 MarkTileDirtyByTile(tile); |
299 _m[tile].m4 = 0; |
|
300 } else { |
305 } else { |
301 DoClearSquare(tile); |
306 DoClearSquare(tile); |
302 SetSignalsOnBothDir(tile, direction); |
307 SetSignalsOnBothDir(tile, direction); |
303 } |
308 } |
304 } |
309 } |