108 return -1; |
108 return -1; |
109 } |
109 } |
110 |
110 |
111 // If we have a single diagonal track there, the other side of |
111 // If we have a single diagonal track there, the other side of |
112 // tile can be terraformed. |
112 // tile can be terraformed. |
113 if ((_map5[tile]&~0x40) == _railway_modes[mode]) |
113 if ((_m[tile].m5&~0x40) == _railway_modes[mode]) |
114 return 0; |
114 return 0; |
115 } |
115 } |
116 |
116 |
117 ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
117 ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); |
118 |
118 |
388 |
388 |
389 tile = TileVirtXY(x, y); |
389 tile = TileVirtXY(x, y); |
390 |
390 |
391 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
391 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
392 |
392 |
393 if (IsTileType(tile, MP_UNMOVABLE) && _map5[tile] == 3 && |
393 if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 && |
394 IsTileOwner(tile, _current_player)) |
394 IsTileOwner(tile, _current_player)) |
395 return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
395 return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
396 |
396 |
397 cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
397 cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
398 if (CmdFailed(cost)) return CMD_ERROR; |
398 if (CmdFailed(cost)) return CMD_ERROR; |
418 &_price.clear_3,&_price.clear_3,&_price.clear_3,&_price.clear_3, |
418 &_price.clear_3,&_price.clear_3,&_price.clear_3,&_price.clear_3, |
419 &_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
419 &_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
420 &_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
420 &_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land, |
421 &_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2, |
421 &_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2, |
422 }; |
422 }; |
423 const int32 *price = _clear_price_table[_map5[tile] & 0x1F]; |
423 const int32 *price = _clear_price_table[_m[tile].m5 & 0x1F]; |
424 |
424 |
425 if (flags & DC_EXEC) |
425 if (flags & DC_EXEC) |
426 DoClearSquare(tile); |
426 DoClearSquare(tile); |
427 |
427 |
428 if (price == NULL) |
428 if (price == NULL) |
442 |
442 |
443 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
443 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
444 |
444 |
445 tile = TileVirtXY(x, y); |
445 tile = TileVirtXY(x, y); |
446 |
446 |
447 if (!IsTileType(tile, MP_UNMOVABLE) || _map5[tile] != 3) return CMD_ERROR; |
447 if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR; |
448 if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
448 if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
449 |
449 |
450 |
450 |
451 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
451 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
452 |
452 |
520 case 5: |
520 case 5: |
521 DrawGroundSprite( _clear_land_sprites_3[ti->map5&3] + _tileh_to_sprite[ti->tileh]); |
521 DrawGroundSprite( _clear_land_sprites_3[ti->map5&3] + _tileh_to_sprite[ti->tileh]); |
522 break; |
522 break; |
523 } |
523 } |
524 |
524 |
525 DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2); |
525 DrawClearLandFence(ti, _m[ti->tile].m4 >> 2); |
526 } |
526 } |
527 |
527 |
528 static uint GetSlopeZ_Clear(TileInfo *ti) |
528 static uint GetSlopeZ_Clear(TileInfo *ti) |
529 { |
529 { |
530 return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
530 return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z; |
552 static const byte img_by_map5[] = { 0, 0, 0, 2, 1, 1, 0, 0 }; |
552 static const byte img_by_map5[] = { 0, 0, 0, 2, 1, 1, 0, 0 }; |
553 TileIndex dirty = INVALID_TILE; |
553 TileIndex dirty = INVALID_TILE; |
554 |
554 |
555 switch (GetTileType(tile)) { |
555 switch (GetTileType(tile)) { |
556 case MP_CLEAR: |
556 case MP_CLEAR: |
557 img_1 = img_by_map5[(_map5[tile] & 0x1C) >> 2]; |
557 img_1 = img_by_map5[(_m[tile].m5 & 0x1C) >> 2]; |
558 break; |
558 break; |
559 |
559 |
560 case MP_TREES: |
560 case MP_TREES: |
561 if ((_map2[tile] & 0x30) == 0x20) |
561 if ((_m[tile].m2 & 0x30) == 0x20) |
562 img_1 = 1; |
562 img_1 = 1; |
563 else |
563 else |
564 img_1 = 0; |
564 img_1 = 0; |
565 break; |
565 break; |
566 |
566 |
569 break; |
569 break; |
570 } |
570 } |
571 |
571 |
572 switch (GetTileType(TILE_ADDXY(tile, 1, 0))) { |
572 switch (GetTileType(TILE_ADDXY(tile, 1, 0))) { |
573 case MP_CLEAR: |
573 case MP_CLEAR: |
574 img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 1, 0)] & 0x1C) >> 2]; |
574 img_2 = img_by_map5[(_m[TILE_ADDXY(tile, 1, 0)].m5 & 0x1C) >> 2]; |
575 break; |
575 break; |
576 |
576 |
577 case MP_TREES: |
577 case MP_TREES: |
578 if ((_map2[TILE_ADDXY(tile, 1, 0)] & 0x30) == 0x20) |
578 if ((_m[TILE_ADDXY(tile, 1, 0)].m2 & 0x30) == 0x20) |
579 img_2 = 1; |
579 img_2 = 1; |
580 else |
580 else |
581 img_2 = 0; |
581 img_2 = 0; |
582 break; |
582 break; |
583 |
583 |
584 default: |
584 default: |
585 img_2 = 0; |
585 img_2 = 0; |
586 break; |
586 break; |
587 } |
587 } |
588 |
588 |
589 if ((_map3_hi[tile] & 0xE0) == 0) { |
589 if ((_m[tile].m4 & 0xE0) == 0) { |
590 if ((img_1 & 2) != (img_2 & 2)) { |
590 if ((img_1 & 2) != (img_2 & 2)) { |
591 _map3_hi[tile] |= 3 << 5; |
591 _m[tile].m4 |= 3 << 5; |
592 dirty = tile; |
592 dirty = tile; |
593 } |
593 } |
594 } else { |
594 } else { |
595 if (img_1 == 1 && img_2 == 1) { |
595 if (img_1 == 1 && img_2 == 1) { |
596 _map3_hi[tile] &= ~(3 << 5); |
596 _m[tile].m4 &= ~(3 << 5); |
597 dirty = tile; |
597 dirty = tile; |
598 } |
598 } |
599 } |
599 } |
600 |
600 |
601 switch (GetTileType(TILE_ADDXY(tile, 0, 1))) { |
601 switch (GetTileType(TILE_ADDXY(tile, 0, 1))) { |
602 case MP_CLEAR: |
602 case MP_CLEAR: |
603 img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 0, 1)] & 0x1C) >> 2]; |
603 img_2 = img_by_map5[(_m[TILE_ADDXY(tile, 0, 1)].m5 & 0x1C) >> 2]; |
604 break; |
604 break; |
605 |
605 |
606 case MP_TREES: |
606 case MP_TREES: |
607 if ((_map2[TILE_ADDXY(tile, 0, 1)] & 0x30) == 0x20) |
607 if ((_m[TILE_ADDXY(tile, 0, 1)].m2 & 0x30) == 0x20) |
608 img_2 = 1; |
608 img_2 = 1; |
609 else |
609 else |
610 img_2 = 0; |
610 img_2 = 0; |
611 break; |
611 break; |
612 |
612 |
613 default: |
613 default: |
614 img_2 = 0; |
614 img_2 = 0; |
615 break; |
615 break; |
616 } |
616 } |
617 |
617 |
618 if ((_map3_hi[tile] & 0x1C) == 0) { |
618 if ((_m[tile].m4 & 0x1C) == 0) { |
619 if ((img_1 & 2) != (img_2 & 2)) { |
619 if ((img_1 & 2) != (img_2 & 2)) { |
620 _map3_hi[tile] |= 3 << 2; |
620 _m[tile].m4 |= 3 << 2; |
621 dirty = tile; |
621 dirty = tile; |
622 } |
622 } |
623 } else { |
623 } else { |
624 if (img_1 == 1 && img_2 == 1) { |
624 if (img_1 == 1 && img_2 == 1) { |
625 _map3_hi[tile] &= ~(3 << 2); |
625 _m[tile].m4 &= ~(3 << 2); |
626 dirty = tile; |
626 dirty = tile; |
627 } |
627 } |
628 } |
628 } |
629 |
629 |
630 if (dirty != INVALID_TILE) |
630 if (dirty != INVALID_TILE) |
688 m5 = tmp + 1 + 0x10; |
688 m5 = tmp + 1 + 0x10; |
689 } else |
689 } else |
690 return; |
690 return; |
691 } |
691 } |
692 |
692 |
693 _map5[tile] = m5; |
693 _m[tile].m5 = m5; |
694 MarkTileDirtyByTile(tile); |
694 MarkTileDirtyByTile(tile); |
695 } |
695 } |
696 |
696 |
697 static void TileLoopClearDesert(TileIndex tile) |
697 static void TileLoopClearDesert(TileIndex tile) |
698 { |
698 { |
699 if ( (_map5[tile] & 0x1C) == 0x14) |
699 if ( (_m[tile].m5 & 0x1C) == 0x14) |
700 return; |
700 return; |
701 |
701 |
702 if (GetMapExtraBits(tile) == 1) { |
702 if (GetMapExtraBits(tile) == 1) { |
703 _map5[tile] = 0x17; |
703 _m[tile].m5 = 0x17; |
704 } else { |
704 } else { |
705 if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 && |
705 if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 && |
706 GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 && |
706 GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 && |
707 GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 && |
707 GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 && |
708 GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1) |
708 GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1) |
709 return; |
709 return; |
710 _map5[tile] = 0x15; |
710 _m[tile].m5 = 0x15; |
711 } |
711 } |
712 |
712 |
713 MarkTileDirtyByTile(tile); |
713 MarkTileDirtyByTile(tile); |
714 } |
714 } |
715 |
715 |
723 TileLoopClearDesert(tile); |
723 TileLoopClearDesert(tile); |
724 } else if (_opt.landscape == LT_HILLY) { |
724 } else if (_opt.landscape == LT_HILLY) { |
725 TileLoopClearAlps(tile); |
725 TileLoopClearAlps(tile); |
726 } |
726 } |
727 |
727 |
728 m5 = _map5[tile]; |
728 m5 = _m[tile].m5; |
729 if ( (m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14) |
729 if ( (m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14) |
730 return; |
730 return; |
731 |
731 |
732 if ( (m5 & 0x1C) != 0xC) { |
732 if ( (m5 & 0x1C) != 0xC) { |
733 if ( (m5 & 3) == 3) |
733 if ( (m5 & 3) == 3) |
748 } else if (_game_mode != GM_EDITOR) { |
748 } else if (_game_mode != GM_EDITOR) { |
749 /* handle farm field */ |
749 /* handle farm field */ |
750 m5 += 0x20; |
750 m5 += 0x20; |
751 if (m5 >= 0x20) { |
751 if (m5 >= 0x20) { |
752 // Didn't overflow |
752 // Didn't overflow |
753 _map5[tile] = m5; |
753 _m[tile].m5 = m5; |
754 return; |
754 return; |
755 } |
755 } |
756 /* overflowed */ |
756 /* overflowed */ |
757 m3 = _map3_lo[tile] + 1; |
757 m3 = _m[tile].m3 + 1; |
758 assert( (m3 & 0xF) != 0); |
758 assert( (m3 & 0xF) != 0); |
759 if ( (m3 & 0xF) >= 9) /* NOTE: will not work properly if m3&0xF == 0xF */ |
759 if ( (m3 & 0xF) >= 9) /* NOTE: will not work properly if m3&0xF == 0xF */ |
760 m3 &= ~0xF; |
760 m3 &= ~0xF; |
761 _map3_lo[tile] = m3; |
761 _m[tile].m3 = m3; |
762 } |
762 } |
763 |
763 |
764 _map5[tile] = m5; |
764 _m[tile].m5 = m5; |
765 MarkTileDirtyByTile(tile); |
765 MarkTileDirtyByTile(tile); |
766 } |
766 } |
767 |
767 |
768 void GenerateClearTile(void) |
768 void GenerateClearTile(void) |
769 { |
769 { |
774 /* add hills */ |
774 /* add hills */ |
775 i = ScaleByMapSize((Random() & 0x3FF) + 0x400); |
775 i = ScaleByMapSize((Random() & 0x3FF) + 0x400); |
776 do { |
776 do { |
777 tile = TILE_MASK(Random()); |
777 tile = TILE_MASK(Random()); |
778 if (IsTileType(tile, MP_CLEAR)) |
778 if (IsTileType(tile, MP_CLEAR)) |
779 _map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (1<<2)); |
779 _m[tile].m5 = (byte)((_m[tile].m5 & ~(3<<2)) | (1<<2)); |
780 } while (--i); |
780 } while (--i); |
781 |
781 |
782 /* add grey squares */ |
782 /* add grey squares */ |
783 i = ScaleByMapSize((Random() & 0x7F) + 0x80); |
783 i = ScaleByMapSize((Random() & 0x7F) + 0x80); |
784 do { |
784 do { |
787 if (IsTileType(tile, MP_CLEAR)) { |
787 if (IsTileType(tile, MP_CLEAR)) { |
788 j = ((r >> 16) & 0xF) + 5; |
788 j = ((r >> 16) & 0xF) + 5; |
789 for(;;) { |
789 for(;;) { |
790 TileIndex tile_new; |
790 TileIndex tile_new; |
791 |
791 |
792 _map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (2<<2)); |
792 _m[tile].m5 = (byte)((_m[tile].m5 & ~(3<<2)) | (2<<2)); |
793 do { |
793 do { |
794 if (--j == 0) goto get_out; |
794 if (--j == 0) goto get_out; |
795 tile_new = tile + TileOffsByDir(Random() & 3); |
795 tile_new = tile + TileOffsByDir(Random() & 3); |
796 } while (!IsTileType(tile_new, MP_CLEAR)); |
796 } while (!IsTileType(tile_new, MP_CLEAR)); |
797 tile = tile_new; |
797 tile = tile_new; |
825 STR_080D_GRASS, |
825 STR_080D_GRASS, |
826 }; |
826 }; |
827 |
827 |
828 static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
828 static void GetTileDesc_Clear(TileIndex tile, TileDesc *td) |
829 { |
829 { |
830 int i = (_map5[tile]>>2) & 7; |
830 int i = (_m[tile].m5>>2) & 7; |
831 if (i == 0) |
831 if (i == 0) |
832 i = (_map5[tile] & 3) + 8; |
832 i = (_m[tile].m5 & 3) + 8; |
833 td->str = _clear_land_str[i - 1]; |
833 td->str = _clear_land_str[i - 1]; |
834 td->owner = GetTileOwner(tile); |
834 td->owner = GetTileOwner(tile); |
835 } |
835 } |
836 |
836 |
837 static void ChangeTileOwner_Clear(TileIndex tile, byte old_player, byte new_player) |
837 static void ChangeTileOwner_Clear(TileIndex tile, byte old_player, byte new_player) |