175 b = CheckAllowRemoveRoad(tile, pieces, &edge_road); |
173 b = CheckAllowRemoveRoad(tile, pieces, &edge_road); |
176 _road_special_gettrackstatus = false; |
174 _road_special_gettrackstatus = false; |
177 if (!b) return CMD_ERROR; |
175 if (!b) return CMD_ERROR; |
178 } |
176 } |
179 |
177 |
180 if (ti.type == MP_TUNNELBRIDGE) { |
178 switch (ti.type) { |
181 if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) |
179 case MP_TUNNELBRIDGE: |
182 return CMD_ERROR; |
180 if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR; |
183 |
181 |
184 if ((ti.map5 & 0xE9) == 0xE8) { |
182 if ((ti.map5 & 0xE9) == 0xE8) { |
185 if (pieces & 10) goto return_error; |
183 if (pieces & 10) goto return_error; |
186 } else if ((ti.map5 & 0xE9) == 0xE9) { |
184 } else if ((ti.map5 & 0xE9) == 0xE9) { |
187 if (pieces & 5) goto return_error; |
185 if (pieces & 5) goto return_error; |
188 } else |
186 } else { |
189 goto return_error; |
187 goto return_error; |
190 |
188 } |
191 cost = _price.remove_road * 2; |
189 |
192 |
190 cost = _price.remove_road * 2; |
193 if (flags & DC_EXEC) { |
|
194 ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
|
195 _m[tile].m5 = ti.map5 & 0xC7; |
|
196 SetTileOwner(tile, OWNER_NONE); |
|
197 MarkTileDirtyByTile(tile); |
|
198 } |
|
199 return cost; |
|
200 } else if (ti.type == MP_STREET) { |
|
201 // check if you're allowed to remove the street owned by a town |
|
202 // removal allowance depends on difficulty setting |
|
203 if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR; |
|
204 |
|
205 // XXX - change cascading ifs to switch when doing rewrite |
|
206 if ((ti.map5 & 0xF0) == 0) { // normal road |
|
207 byte c = pieces, t2; |
|
208 |
|
209 if (ti.tileh != 0 && (ti.map5 == 5 || ti.map5 == 10)) { |
|
210 c |= (c & 0xC) >> 2; |
|
211 c |= (c & 0x3) << 2; |
|
212 } |
|
213 |
|
214 // limit the bits to delete to the existing bits. |
|
215 if ((c &= ti.map5) == 0) goto return_error; |
|
216 |
|
217 // calculate the cost |
|
218 t2 = c; |
|
219 cost = 0; |
|
220 do { |
|
221 if (t2 & 1) cost += _price.remove_road; |
|
222 } while (t2 >>= 1); |
|
223 |
191 |
224 if (flags & DC_EXEC) { |
192 if (flags & DC_EXEC) { |
225 ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
193 ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
226 |
194 _m[tile].m5 = ti.map5 & 0xC7; |
227 _m[tile].m5 ^= c; |
195 SetTileOwner(tile, OWNER_NONE); |
228 if (GB(_m[tile].m5, 0, 4) == 0) { |
196 MarkTileDirtyByTile(tile); |
229 DoClearSquare(tile); |
197 } |
230 } else { |
198 return cost; |
231 MarkTileDirtyByTile(tile); |
199 |
|
200 case MP_STREET: |
|
201 // check if you're allowed to remove the street owned by a town |
|
202 // removal allowance depends on difficulty setting |
|
203 if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return CMD_ERROR; |
|
204 |
|
205 switch (GB(ti.map5, 4, 4)) { |
|
206 case 0: { // normal road |
|
207 byte c = pieces, t2; |
|
208 |
|
209 if (ti.tileh != 0 && (ti.map5 == 5 || ti.map5 == 10)) { |
|
210 c |= (c & 0xC) >> 2; |
|
211 c |= (c & 0x3) << 2; |
|
212 } |
|
213 |
|
214 // limit the bits to delete to the existing bits. |
|
215 if ((c &= ti.map5) == 0) goto return_error; |
|
216 |
|
217 // calculate the cost |
|
218 t2 = c; |
|
219 cost = 0; |
|
220 do { |
|
221 if (t2 & 1) cost += _price.remove_road; |
|
222 } while (t2 >>= 1); |
|
223 |
|
224 if (flags & DC_EXEC) { |
|
225 ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
|
226 |
|
227 _m[tile].m5 ^= c; |
|
228 if (GB(_m[tile].m5, 0, 4) == 0) { |
|
229 DoClearSquare(tile); |
|
230 } else { |
|
231 MarkTileDirtyByTile(tile); |
|
232 } |
|
233 } |
|
234 return cost; |
232 } |
235 } |
233 } |
236 |
234 return cost; |
237 case 1: { // level crossing |
235 } else if ((ti.map5 & 0xE0) == 0) { // railroad crossing |
238 byte c; |
236 byte c; |
239 |
237 |
240 if (!(ti.map5 & 8)) { |
238 if (!(ti.map5 & 8)) { |
241 c = 2; |
239 c = 2; |
242 if (pieces & 5) goto return_error; |
240 if (pieces & 5) goto return_error; |
243 } else { |
241 } else { |
244 c = 1; |
242 c = 1; |
245 if (pieces & 10) goto return_error; |
243 if (pieces & 10) goto return_error; |
246 } |
244 } |
247 |
245 |
248 cost = _price.remove_road * 2; |
246 cost = _price.remove_road * 2; |
249 if (flags & DC_EXEC) { |
247 if (flags & DC_EXEC) { |
250 ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
248 ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM); |
251 |
249 |
252 ModifyTile(tile, |
250 ModifyTile(tile, |
253 MP_SETTYPE(MP_RAILWAY) | |
251 MP_SETTYPE(MP_RAILWAY) | |
254 MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5, |
252 MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAP5, |
255 _m[tile].m4 & 0xF, /* map3_lo */ |
253 _m[tile].m4 & 0xF, /* map3_lo */ |
256 c /* map5 */ |
254 c /* map5 */ |
257 ); |
255 ); |
258 } |
256 } |
259 return cost; |
257 return cost; |
260 } |
258 } else |
261 |
259 goto return_error; |
262 default: // depot |
260 |
263 goto return_error; |
261 } else { |
264 } |
|
265 |
|
266 default: |
262 return_error:; |
267 return_error:; |
263 return_cmd_error(INVALID_STRING_ID); |
268 return_cmd_error(INVALID_STRING_ID); |
264 } |
269 } |
265 } |
270 } |
266 |
271 |
267 |
272 |
268 enum { |
273 enum { |
364 tile = ti.tile; |
369 tile = ti.tile; |
365 |
370 |
366 // allow building road under bridge |
371 // allow building road under bridge |
367 if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR; |
372 if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR; |
368 |
373 |
369 if (ti.type == MP_STREET) { |
374 switch (ti.type) { |
370 if (!(ti.map5 & 0xF0)) { |
375 case MP_STREET: |
371 if ((pieces & (byte)ti.map5) == pieces) |
376 if (!(ti.map5 & 0xF0)) { |
|
377 if ((pieces & (byte)ti.map5) == pieces) |
|
378 return_cmd_error(STR_1007_ALREADY_BUILT); |
|
379 existing = ti.map5; |
|
380 } else { |
|
381 if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10)) |
|
382 return_cmd_error(STR_1007_ALREADY_BUILT); |
|
383 goto do_clear; |
|
384 } |
|
385 break; |
|
386 |
|
387 case MP_RAILWAY: { |
|
388 byte m5; |
|
389 |
|
390 if (IsSteepTileh(ti.tileh)) { // very steep tile |
|
391 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
392 } |
|
393 |
|
394 if (!_valid_tileh_slopes_road[2][ti.tileh]) { // prevent certain slopes |
|
395 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
396 } |
|
397 |
|
398 if (ti.map5 == 2) { |
|
399 if (pieces & 5) goto do_clear; |
|
400 m5 = 0x10; |
|
401 } else if (ti.map5 == 1) { |
|
402 if (pieces & 10) goto do_clear; |
|
403 m5 = 0x18; |
|
404 } else { |
|
405 goto do_clear; |
|
406 } |
|
407 |
|
408 if (flags & DC_EXEC) { |
|
409 ModifyTile(tile, |
|
410 MP_SETTYPE(MP_STREET) | |
|
411 MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5, |
|
412 p2, |
|
413 _current_player, /* map3_lo */ |
|
414 _m[tile].m3 & 0xF, /* map3_hi */ |
|
415 m5 /* map5 */ |
|
416 ); |
|
417 } |
|
418 return _price.build_road * 2; |
|
419 } |
|
420 |
|
421 case MP_TUNNELBRIDGE: |
|
422 /* check for flat land */ |
|
423 if (IsSteepTileh(ti.tileh)) { // very steep tile |
|
424 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
425 } |
|
426 |
|
427 /* is this middle part of a bridge? */ |
|
428 if ((ti.map5 & 0xC0) != 0xC0) goto do_clear; |
|
429 |
|
430 /* only allow roads pertendicular to bridge */ |
|
431 if (((pieces & 5U) != 0) == ((ti.map5 & 0x01U) != 0)) goto do_clear; |
|
432 |
|
433 /* check if clear land under bridge */ |
|
434 if ((ti.map5 & 0xF8) == 0xE8) { /* road under bridge */ |
372 return_cmd_error(STR_1007_ALREADY_BUILT); |
435 return_cmd_error(STR_1007_ALREADY_BUILT); |
373 existing = ti.map5; |
436 } else if ((ti.map5 & 0xE0) == 0xE0) { /* other transport route under bridge */ |
374 } else { |
437 return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
375 if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10)) |
438 } else if ((ti.map5 & 0xF8) == 0xC8) { /* water under bridge */ |
376 return_cmd_error(STR_1007_ALREADY_BUILT); |
439 return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
377 goto do_clear; |
440 } |
378 } |
441 |
379 } else if (ti.type == MP_RAILWAY) { |
442 /* all checked, can build road now! */ |
380 byte m5; |
443 cost = _price.build_road * 2; |
381 |
444 if (flags & DC_EXEC) { |
382 if (IsSteepTileh(ti.tileh)) { // very steep tile |
445 ModifyTile(tile, |
383 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
446 MP_MAPOWNER_CURRENT | MP_MAP5, |
384 } |
447 (ti.map5 & 0xC7) | 0x28 // map5 |
385 |
448 ); |
386 if (!_valid_tileh_slopes_road[2][ti.tileh]) { // prevent certain slopes |
449 } |
387 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
450 return cost; |
388 } |
451 |
389 |
452 default: |
390 if (ti.map5 == 2) { |
|
391 if (pieces & 5) goto do_clear; |
|
392 m5 = 0x10; |
|
393 } else if (ti.map5 == 1) { |
|
394 if (pieces & 10) goto do_clear; |
|
395 m5 = 0x18; |
|
396 } else { |
|
397 goto do_clear; |
|
398 } |
|
399 |
|
400 if (flags & DC_EXEC) { |
|
401 ModifyTile(tile, |
|
402 MP_SETTYPE(MP_STREET) | |
|
403 MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5, |
|
404 p2, |
|
405 _current_player, /* map3_lo */ |
|
406 _m[tile].m3 & 0xF, /* map3_hi */ |
|
407 m5 /* map5 */ |
|
408 ); |
|
409 } |
|
410 return _price.build_road * 2; |
|
411 } else if (ti.type == MP_TUNNELBRIDGE) { |
|
412 /* check for flat land */ |
|
413 if (IsSteepTileh(ti.tileh)) { // very steep tile |
|
414 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
|
415 } |
|
416 |
|
417 /* is this middle part of a bridge? */ |
|
418 if ((ti.map5 & 0xC0) != 0xC0) goto do_clear; |
|
419 |
|
420 /* only allow roads pertendicular to bridge */ |
|
421 if (((pieces & 5U) != 0) == ((ti.map5 & 0x01U) != 0)) goto do_clear; |
|
422 |
|
423 /* check if clear land under bridge */ |
|
424 if ((ti.map5 & 0xF8) == 0xE8) { /* road under bridge */ |
|
425 return_cmd_error(STR_1007_ALREADY_BUILT); |
|
426 } else if ((ti.map5 & 0xE0) == 0xE0) { /* other transport route under bridge */ |
|
427 return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK); |
|
428 } else if ((ti.map5 & 0xF8) == 0xC8) { /* water under bridge */ |
|
429 return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER); |
|
430 } |
|
431 |
|
432 /* all checked, can build road now! */ |
|
433 cost = _price.build_road * 2; |
|
434 if (flags & DC_EXEC) { |
|
435 ModifyTile(tile, |
|
436 MP_MAPOWNER_CURRENT | MP_MAP5, |
|
437 (ti.map5 & 0xC7) | 0x28 // map5 |
|
438 ); |
|
439 } |
|
440 return cost; |
|
441 } else { |
|
442 do_clear:; |
453 do_clear:; |
443 if (CmdFailed(DoCommandByTile(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR))) |
454 if (CmdFailed(DoCommandByTile(tile, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR))) |
444 return CMD_ERROR; |
455 return CMD_ERROR; |
445 } |
456 } |
446 |
457 |
447 cost = CheckRoadSlope(ti.tileh, &pieces, existing); |
458 cost = CheckRoadSlope(ti.tileh, &pieces, existing); |
448 if (CmdFailed(cost)) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION); |
459 if (CmdFailed(cost)) return_cmd_error(STR_1800_LAND_SLOPED_IN_WRONG_DIRECTION); |
449 |
460 |
678 |
689 |
679 #define M(x) (1<<(x)) |
690 #define M(x) (1<<(x)) |
680 |
691 |
681 static int32 ClearTile_Road(TileIndex tile, byte flags) |
692 static int32 ClearTile_Road(TileIndex tile, byte flags) |
682 { |
693 { |
683 int32 ret; |
|
684 byte m5 = _m[tile].m5; |
694 byte m5 = _m[tile].m5; |
685 |
695 |
686 if ( (m5 & 0xF0) == 0) { |
696 switch (GB(_m[tile].m5, 4, 4)) { |
687 byte b = m5 & 0xF; |
697 case 0: { // normal road |
688 |
698 byte b = m5 & 0xF; |
689 if (! ((1 << b) & (M(1)|M(2)|M(4)|M(8))) ) { |
699 |
690 if ((!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) && flags & DC_AUTO) |
700 if (!((1 << b) & (M(1)|M(2)|M(4)|M(8))) && |
|
701 (!(flags & DC_AI_BUILDING) || !IsTileOwner(tile, OWNER_TOWN)) && |
|
702 flags & DC_AUTO) { |
691 return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
703 return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
692 } |
704 } |
693 return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD); |
705 return DoCommandByTile(tile, b, 0, flags, CMD_REMOVE_ROAD); |
694 } else if ( (m5 & 0xE0) == 0) { |
706 } |
695 if (flags & DC_AUTO) |
707 |
696 return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
708 case 1: { // level crossing |
697 |
709 int32 ret; |
698 ret = DoCommandByTile(tile, (m5&8)?5:10, 0, flags, CMD_REMOVE_ROAD); |
710 |
699 if (CmdFailed(ret)) return CMD_ERROR; |
711 if (flags & DC_AUTO) { |
700 |
712 return_cmd_error(STR_1801_MUST_REMOVE_ROAD_FIRST); |
701 if (flags & DC_EXEC) { |
713 } |
702 DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
714 |
703 } |
715 ret = DoCommandByTile(tile, (m5 & 8 ? 5 : 10), 0, flags, CMD_REMOVE_ROAD); |
704 |
716 if (CmdFailed(ret)) return CMD_ERROR; |
705 return ret; |
717 |
706 } else { |
718 if (flags & DC_EXEC) { |
707 if (flags & DC_AUTO) |
719 DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
708 return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
720 } |
709 return RemoveRoadDepot(tile,flags); |
721 return ret; |
|
722 } |
|
723 |
|
724 default: // depot |
|
725 if (flags & DC_AUTO) { |
|
726 return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
727 } |
|
728 return RemoveRoadDepot(tile, flags); |
710 } |
729 } |
711 } |
730 } |
712 |
731 |
713 |
732 |
714 typedef struct DrawRoadTileStruct { |
733 typedef struct DrawRoadTileStruct { |
823 static void DrawTile_Road(TileInfo *ti) |
842 static void DrawTile_Road(TileInfo *ti) |
824 { |
843 { |
825 PalSpriteID image; |
844 PalSpriteID image; |
826 uint16 m2; |
845 uint16 m2; |
827 |
846 |
828 if ( (ti->map5 & 0xF0) == 0) { // if it is a road the upper 4 bits are 0 |
847 switch (GB(ti->map5, 4, 4)) { |
829 DrawRoadBits(ti, GB(ti->map5, 0, 4), GB(_m[ti->tile].m4, 4, 3), HASBIT(_m[ti->tile].m4, 7), false); |
848 case 0: // normal road |
830 } else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing |
849 DrawRoadBits(ti, GB(ti->map5, 0, 4), GB(_m[ti->tile].m4, 4, 3), HASBIT(_m[ti->tile].m4, 7), false); |
831 int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
850 break; |
832 if (f) DrawFoundation(ti, f); |
851 |
833 |
852 case 1: { // level crossing |
834 image = GetRailTypeInfo(GB(_m[ti->tile].m4, 0, 4))->base_sprites.crossing; |
853 int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF); |
835 |
854 if (f) DrawFoundation(ti, f); |
836 if (GB(ti->map5, 3, 1) == 0) image++; /* direction */ |
855 |
837 |
856 image = GetRailTypeInfo(GB(_m[ti->tile].m4, 0, 4))->base_sprites.crossing; |
838 if ( (ti->map5 & 4) != 0) |
857 |
839 image += 2; |
858 if (GB(ti->map5, 3, 1) == 0) image++; /* direction */ |
840 |
859 |
841 if ( _m[ti->tile].m4 & 0x80) { |
860 if ((ti->map5 & 4) != 0) image += 2; |
842 image += 8; |
861 |
843 } else { |
862 if ( _m[ti->tile].m4 & 0x80) { |
844 m2 = GB(_m[ti->tile].m4, 4, 3); |
863 image += 8; |
845 if (m2 == 0) image |= PALETTE_TO_BARE_LAND; |
864 } else { |
846 if (m2 > 1) image += 4; |
865 m2 = GB(_m[ti->tile].m4, 4, 3); |
847 } |
866 if (m2 == 0) image |= PALETTE_TO_BARE_LAND; |
848 |
867 if (m2 > 1) image += 4; |
849 DrawGroundSprite(image); |
868 } |
850 } else { |
869 |
851 uint32 ormod; |
870 DrawGroundSprite(image); |
852 PlayerID player; |
871 break; |
853 const DrawRoadSeqStruct *drss; |
872 } |
854 |
873 |
855 if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); } |
874 default: { // depot |
856 |
875 uint32 ormod; |
857 ormod = PALETTE_TO_GREY; //was this a bug/problem? |
876 PlayerID player; |
858 player = GetTileOwner(ti->tile); |
877 const DrawRoadSeqStruct* drss; |
859 if (player < MAX_PLAYERS) |
878 |
860 ormod = PLAYER_SPRITE_COLOR(player); |
879 if (ti->tileh != 0) DrawFoundation(ti, ti->tileh); |
861 |
880 |
862 drss = _road_display_datas[ti->map5 & 0xF]; |
881 ormod = PALETTE_TO_GREY; //was this a bug/problem? |
863 |
882 player = GetTileOwner(ti->tile); |
864 DrawGroundSprite(drss++->image); |
883 if (player < MAX_PLAYERS) ormod = PLAYER_SPRITE_COLOR(player); |
865 |
884 |
866 for (; drss->image != 0; drss++) { |
885 drss = _road_display_datas[ti->map5 & 0xF]; |
867 uint32 image = drss->image; |
886 |
868 |
887 DrawGroundSprite(drss++->image); |
869 if (image & PALETTE_MODIFIER_COLOR) |
888 |
870 image |= ormod; |
889 for (; drss->image != 0; drss++) { |
871 if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots |
890 uint32 image = drss->image; |
872 MAKE_TRANSPARENT(image); |
891 |
873 |
892 if (image & PALETTE_MODIFIER_COLOR) image |= ormod; |
874 AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x, |
893 if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
875 ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z); |
894 |
|
895 AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x, |
|
896 ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z |
|
897 ); |
|
898 } |
|
899 break; |
876 } |
900 } |
877 } |
901 } |
878 } |
902 } |
879 |
903 |
880 void DrawRoadDepotSprite(int x, int y, int image) |
904 void DrawRoadDepotSprite(int x, int y, int image) |
906 uint z = ti->z; |
930 uint z = ti->z; |
907 int th = ti->tileh; |
931 int th = ti->tileh; |
908 |
932 |
909 // check if it's a foundation |
933 // check if it's a foundation |
910 if (ti->tileh != 0) { |
934 if (ti->tileh != 0) { |
911 if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
935 switch (GB(ti->map5, 4, 4)) { |
912 uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
936 case 0: // normal road |
913 if (f != 0) { |
937 case 1: { // level crossing |
914 if (f < 15) { |
938 uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
915 // leveled foundation |
939 if (f != 0) { |
916 return z + 8; |
940 if (f < 15) { |
|
941 // leveled foundation |
|
942 return z + 8; |
|
943 } |
|
944 // inclined foundation |
|
945 th = _inclined_tileh[f - 15]; |
917 } |
946 } |
918 // inclined foundation |
947 break; |
919 th = _inclined_tileh[f - 15]; |
948 } |
920 } |
949 |
921 } else if ((ti->map5 & 0xF0) == 0x20) { |
950 case 2: // depot |
922 // depot |
951 return z + 8; |
923 return z + 8; |
952 |
|
953 default: break; |
924 } |
954 } |
925 return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z; |
955 return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z; |
926 } |
956 } |
927 return z; // normal Z if no slope |
957 return z; // normal Z if no slope |
928 } |
958 } |
929 |
959 |
930 static uint GetSlopeTileh_Road(const TileInfo *ti) |
960 static uint GetSlopeTileh_Road(const TileInfo *ti) |
931 { |
961 { |
932 // check if it's a foundation |
962 // check if it's a foundation |
933 if (ti->tileh != 0) { |
963 if (ti->tileh != 0) { |
934 if ((ti->map5 & 0xE0) == 0) { /* road or crossing */ |
964 switch (GB(ti->map5, 4, 4)) { |
935 uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
965 case 0: // normal road |
936 if (f != 0) { |
966 case 1: { // level crossing |
937 if (f < 15) { |
967 uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F); |
938 // leveled foundation |
968 if (f != 0) { |
939 return 0; |
969 if (f < 15) { |
|
970 // leveled foundation |
|
971 return 0; |
|
972 } |
|
973 // inclined foundation |
|
974 return _inclined_tileh[f - 15]; |
940 } |
975 } |
941 // inclined foundation |
976 break; |
942 return _inclined_tileh[f - 15]; |
977 } |
943 } |
978 |
944 } else if ((ti->map5 & 0xF0) == 0x20) { |
979 case 2: // depot |
945 // depot |
980 return 0; |
946 return 0; |
981 |
|
982 default: break; |
947 } |
983 } |
948 } |
984 } |
949 return ti->tileh; |
985 return ti->tileh; |
950 } |
986 } |
951 |
987 |
1123 8, 9, 0, 1 |
1159 8, 9, 0, 1 |
1124 }; |
1160 }; |
1125 |
1161 |
1126 static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) |
1162 static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) |
1127 { |
1163 { |
1128 if (IsLevelCrossing(tile)) { |
1164 switch (GB(_m[tile].m5, 4, 4)) { |
1129 if (v->type == VEH_Train && GB(_m[tile].m5, 2, 1) == 0) { |
1165 case 1: // level crossing |
1130 /* train crossing a road */ |
1166 if (v->type == VEH_Train && GB(_m[tile].m5, 2, 1) == 0) { |
1131 SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
1167 /* train crossing a road */ |
1132 SB(_m[tile].m5, 2, 1, 1); |
1168 SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); |
1133 MarkTileDirtyByTile(tile); |
1169 SB(_m[tile].m5, 2, 1, 1); |
1134 } |
1170 MarkTileDirtyByTile(tile); |
1135 } else if (GB(_m[tile].m5, 4, 4) == 2) { |
1171 } |
1136 if (v->type == VEH_Road && v->u.road.frame == 11) { |
1172 break; |
1137 if (_roadveh_enter_depot_unk0[GB(_m[tile].m5, 0, 2)] == v->u.road.state) { |
1173 |
1138 RoadVehEnterDepot(v); |
1174 case 2: // depot |
1139 return 4; |
1175 if (v->type == VEH_Road && v->u.road.frame == 11) { |
1140 } |
1176 if (_roadveh_enter_depot_unk0[GB(_m[tile].m5, 0, 2)] == v->u.road.state) { |
1141 } |
1177 RoadVehEnterDepot(v); |
|
1178 return 4; |
|
1179 } |
|
1180 } |
|
1181 break; |
|
1182 |
|
1183 default: break; |
1142 } |
1184 } |
1143 return 0; |
1185 return 0; |
1144 } |
1186 } |
1145 |
1187 |
1146 static void VehicleLeave_Road(Vehicle *v, TileIndex tile, int x, int y) |
1188 static void VehicleLeave_Road(Vehicle *v, TileIndex tile, int x, int y) |
1162 if (!IsTileOwner(tile, old_player)) return; |
1204 if (!IsTileOwner(tile, old_player)) return; |
1163 |
1205 |
1164 if (new_player != OWNER_SPECTATOR) { |
1206 if (new_player != OWNER_SPECTATOR) { |
1165 SetTileOwner(tile, new_player); |
1207 SetTileOwner(tile, new_player); |
1166 } else { |
1208 } else { |
1167 if (GB(_m[tile].m5, 4, 4) == 0) { |
1209 switch (GB(_m[tile].m5, 4, 4)) { |
1168 SetTileOwner(tile, OWNER_NONE); |
1210 case 0: // normal road |
1169 } else if (IsLevelCrossing(tile)) { |
1211 SetTileOwner(tile, OWNER_NONE); |
1170 _m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA; |
1212 break; |
1171 SetTileOwner(tile, _m[tile].m3); |
1213 |
1172 _m[tile].m3 = 0; |
1214 case 1: // level crossing |
1173 _m[tile].m4 &= 0x80; |
1215 _m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA; |
1174 } else { |
1216 SetTileOwner(tile, _m[tile].m3); |
1175 DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
1217 _m[tile].m3 = 0; |
|
1218 _m[tile].m4 &= 0x80; |
|
1219 break; |
|
1220 |
|
1221 default: // depot |
|
1222 DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
|
1223 break; |
1176 } |
1224 } |
1177 } |
1225 } |
1178 } |
1226 } |
1179 |
1227 |
1180 void InitializeRoad(void) |
1228 void InitializeRoad(void) |