road_cmd.c
changeset 3066 26c43ab051b8
parent 3061 a1cac64b56b6
child 3067 49f7be955db4
equal deleted inserted replaced
3065:c73ad9f6fb33 3066:26c43ab051b8
    41 			default: return false;
    41 			default: return false;
    42 		}
    42 		}
    43 		break;
    43 		break;
    44 
    44 
    45 	case MP_STATION:
    45 	case MP_STATION:
    46 		b = _m[tile].m5;
    46 		return
    47 		if (!IS_BYTE_INSIDE(b, 0x43, 0x43 + 8)) return false;
    47 			IS_BYTE_INSIDE(_m[tile].m5, 0x43, 0x43 + 8) &&
    48 		return ((~(b - 0x43) & 3) == i);
    48 			(~(_m[tile].m5 - 0x43) & 3) == i;
    49 
    49 
    50 	case MP_TUNNELBRIDGE:
    50 	case MP_TUNNELBRIDGE:
    51 		mask = GetRoadBitsByTile(tile);
    51 		mask = GetRoadBitsByTile(tile);
    52 		b = 10; if (mask & 1) break;
    52 		b = 10; if (mask & 1) break;
    53 		b = 5;  if (mask & 2) break;
    53 		b = 5;  if (mask & 2) break;
   371 	// allow building road under bridge
   371 	// allow building road under bridge
   372 	if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR;
   372 	if (ti.type != MP_TUNNELBRIDGE && !EnsureNoVehicle(tile)) return CMD_ERROR;
   373 
   373 
   374 	switch (ti.type) {
   374 	switch (ti.type) {
   375 		case MP_STREET:
   375 		case MP_STREET:
   376 			if (!(ti.map5 & 0xF0)) {
   376 			switch (GB(ti.map5, 4, 4)) {
   377 				if ((pieces & (byte)ti.map5) == pieces)
   377 				case 0: // normal road
   378 					return_cmd_error(STR_1007_ALREADY_BUILT);
   378 					if ((pieces & (byte)ti.map5) == pieces) {
   379 				existing = ti.map5;
   379 						return_cmd_error(STR_1007_ALREADY_BUILT);
   380 			} else {
   380 					}
   381 				if (!(ti.map5 & 0xE0) && pieces != ((ti.map5 & 8) ? 5 : 10))
   381 					existing = ti.map5;
   382 					return_cmd_error(STR_1007_ALREADY_BUILT);
   382 					break;
   383 				goto do_clear;
   383 
       
   384 				case 1: // level crossing
       
   385 					if (pieces != (ti.map5 & 8 ? 5 : 10)) {
       
   386 						return_cmd_error(STR_1007_ALREADY_BUILT);
       
   387 					}
       
   388 					goto do_clear;
       
   389 
       
   390 				default: // depot
       
   391 					goto do_clear;
   384 			}
   392 			}
   385 			break;
   393 			break;
   386 
   394 
   387 		case MP_RAILWAY: {
   395 		case MP_RAILWAY: {
   388 			byte m5;
   396 			byte m5;
  1106 	0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
  1114 	0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
  1107 };
  1115 };
  1108 
  1116 
  1109 static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode)
  1117 static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode)
  1110 {
  1118 {
  1111 	if (mode == TRANSPORT_RAIL) {
  1119 	switch (mode) {
  1112 		if (!IsLevelCrossing(tile))
  1120 		case TRANSPORT_RAIL:
  1113 			return 0;
  1121 			if (!IsLevelCrossing(tile)) return 0;
  1114 		return _m[tile].m5 & 8 ? 0x101 : 0x202;
  1122 			return _m[tile].m5 & 8 ? 0x101 : 0x202;
  1115 	} else if  (mode == TRANSPORT_ROAD) {
  1123 
  1116 		byte b = _m[tile].m5;
  1124 		case TRANSPORT_ROAD:
  1117 		if ((b & 0xF0) == 0) {
  1125 			switch (GB(_m[tile].m5, 4, 4)) {
  1118 			/* Ordinary road */
  1126 				case 0: // normal road
  1119 			if (!_road_special_gettrackstatus && GB(_m[tile].m4, 4, 3) >= 6)
  1127 					if (!_road_special_gettrackstatus && GB(_m[tile].m4, 4, 3) >= 6) {
  1120 				return 0;
  1128 						return 0;
  1121 			return _road_trackbits[b&0xF] * 0x101;
  1129 					}
  1122 		} else if (IsLevelCrossing(tile)) {
  1130 					return _road_trackbits[GB(_m[tile].m5, 0, 4)] * 0x101;
  1123 			/* Crossing */
  1131 
  1124 			uint32 r = 0x101;
  1132 				case 1: { // level crossing
  1125 			if (b&8) r <<= 1;
  1133 					uint32 r = (_m[tile].m5 & 8 ? 0x202 : 0x101);
  1126 
  1134 					if (_m[tile].m5 & 4) r *= 0x10001;
  1127 			if (b&4) {
  1135 					return r;
  1128 				r *= 0x10001;
  1136 				}
  1129 			}
  1137 
  1130 			return r;
  1138 				default: // depot
  1131 		}
  1139 					break;
       
  1140 			}
       
  1141 			break;
       
  1142 
       
  1143 		default: break;
  1132 	}
  1144 	}
  1133 	return 0;
  1145 	return 0;
  1134 }
  1146 }
  1135 
  1147 
  1136 static const StringID _road_tile_strings[] = {
  1148 static const StringID _road_tile_strings[] = {