road_cmd.c
changeset 2493 f6b4300cc2b0
parent 2471 5935596f14a8
child 2502 a77b8b2f173c
equal deleted inserted replaced
2492:b4785c8f3700 2493:f6b4300cc2b0
   229 
   229 
   230 			if (flags & DC_EXEC) {
   230 			if (flags & DC_EXEC) {
   231 				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
   231 				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
   232 
   232 
   233 				_m[tile].m5 ^= c;
   233 				_m[tile].m5 ^= c;
   234 				if ((_m[tile].m5&0xF) == 0)
   234 				if (GB(_m[tile].m5, 0, 4) == 0) {
   235 					DoClearSquare(tile);
   235 					DoClearSquare(tile);
   236 				else
   236 				} else {
   237 					MarkTileDirtyByTile(tile);
   237 					MarkTileDirtyByTile(tile);
   238 
   238 				}
   239 			}
   239 			}
   240 			return cost;
   240 			return cost;
   241 		} else if ((ti.map5 & 0xE0) == 0) { // railroad crossing
   241 		} else if ((ti.map5 & 0xE0) == 0) { // railroad crossing
   242 			byte c;
   242 			byte c;
   243 
   243 
   497 
   497 
   498 	// not owned by me?
   498 	// not owned by me?
   499 	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
   499 	if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
   500 
   500 
   501 	// tile is already of requested type?
   501 	// tile is already of requested type?
   502 	if ((_m[tile].m4 & 0xFU) == totype) return CMD_ERROR;
   502 	if (GB(_m[tile].m4, 0, 4) == totype) return CMD_ERROR;
   503 
   503 
   504 	if (exec) {
   504 	if (exec) {
   505 		// change type.
   505 		// change type.
   506 		_m[tile].m4 = (_m[tile].m4 & 0xF0) + totype;
   506 		SB(_m[tile].m4, 0, 4, totype);
   507 		MarkTileDirtyByTile(tile);
   507 		MarkTileDirtyByTile(tile);
   508 	}
   508 	}
   509 
   509 
   510 	return _price.build_rail >> 1;
   510 	return _price.build_rail >> 1;
   511 }
   511 }
   864 			m2 = GB(_m[ti->tile].m4, 4, 3);
   864 			m2 = GB(_m[ti->tile].m4, 4, 3);
   865 			if (m2 == 0) image |= PALETTE_TO_BARE_LAND;
   865 			if (m2 == 0) image |= PALETTE_TO_BARE_LAND;
   866 			if (m2 > 1) image += 4;
   866 			if (m2 > 1) image += 4;
   867 		}
   867 		}
   868 
   868 
   869 		DrawGroundSprite(image + (_m[ti->tile].m4 & 0xF) * 12);
   869 		DrawGroundSprite(image + GB(_m[ti->tile].m4, 0, 4) * 12);
   870 
   870 
   871 		if (_debug_pbs_level >= 1) {
   871 		if (_debug_pbs_level >= 1) {
   872 			byte pbs = PBSTileReserved(ti->tile);
   872 			byte pbs = PBSTileReserved(ti->tile);
   873 			if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite(0x3ED | PALETTE_CRASH);
   873 			if (pbs & TRACK_BIT_DIAG1) DrawGroundSprite(0x3ED | PALETTE_CRASH);
   874 			if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite(0x3EE | PALETTE_CRASH);
   874 			if (pbs & TRACK_BIT_DIAG2) DrawGroundSprite(0x3EE | PALETTE_CRASH);
  1070 			} else if (b == 0) {
  1070 			} else if (b == 0) {
  1071 				b = p[1];
  1071 				b = p[1];
  1072 			} else {
  1072 			} else {
  1073 				b = 0;
  1073 				b = 0;
  1074 			}
  1074 			}
  1075 			_m[tile].m4 = (_m[tile].m4 & ~0x70) | (b << 4);
  1075 			SB(_m[tile].m4, 4, 3, b);
  1076 			MarkTileDirtyByTile(tile);
  1076 			MarkTileDirtyByTile(tile);
  1077 		}
  1077 		}
  1078 	} else {
  1078 	} else {
  1079 		// Handle road work
  1079 		// Handle road work
  1080 		//XXX undocumented
  1080 		//XXX undocumented
  1095 
  1095 
  1096 void ShowRoadDepotWindow(TileIndex tile);
  1096 void ShowRoadDepotWindow(TileIndex tile);
  1097 
  1097 
  1098 static void ClickTile_Road(TileIndex tile)
  1098 static void ClickTile_Road(TileIndex tile)
  1099 {
  1099 {
  1100 	if ((_m[tile].m5 & 0xF0) == 0x20) {
  1100 	if (GB(_m[tile].m5, 4, 4) == 2) ShowRoadDepotWindow(tile);
  1101 		ShowRoadDepotWindow(tile);
       
  1102 	}
       
  1103 }
  1101 }
  1104 
  1102 
  1105 static const byte _road_trackbits[16] = {
  1103 static const byte _road_trackbits[16] = {
  1106 	0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
  1104 	0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
  1107 };
  1105 };
  1161 };
  1159 };
  1162 
  1160 
  1163 static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
  1161 static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y)
  1164 {
  1162 {
  1165 	if (IsLevelCrossing(tile)) {
  1163 	if (IsLevelCrossing(tile)) {
  1166 		if (v->type == VEH_Train && (_m[tile].m5 & 4) == 0) {
  1164 		if (v->type == VEH_Train && GB(_m[tile].m5, 2, 1) == 0) {
  1167 			/* train crossing a road */
  1165 			/* train crossing a road */
  1168 			SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
  1166 			SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
  1169 			_m[tile].m5 |= 4;
  1167 			SB(_m[tile].m5, 2, 1, 1);
  1170 			MarkTileDirtyByTile(tile);
  1168 			MarkTileDirtyByTile(tile);
  1171 		}
  1169 		}
  1172 	} else if ((_m[tile].m5&0xF0) ==  0x20){
  1170 	} else if (GB(_m[tile].m5, 4, 4) == 2) {
  1173 		if (v->type == VEH_Road && v->u.road.frame == 11) {
  1171 		if (v->type == VEH_Road && v->u.road.frame == 11) {
  1174 			if (_roadveh_enter_depot_unk0[_m[tile].m5&3] == v->u.road.state) {
  1172 			if (_roadveh_enter_depot_unk0[GB(_m[tile].m5, 0, 2)] == v->u.road.state) {
  1175 				RoadVehEnterDepot(v);
  1173 				RoadVehEnterDepot(v);
  1176 				return 4;
  1174 				return 4;
  1177 			}
  1175 			}
  1178 		}
  1176 		}
  1179 	}
  1177 	}
  1182 
  1180 
  1183 static void VehicleLeave_Road(Vehicle *v, TileIndex tile, int x, int y)
  1181 static void VehicleLeave_Road(Vehicle *v, TileIndex tile, int x, int y)
  1184 {
  1182 {
  1185 	if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) {
  1183 	if (IsLevelCrossing(tile) && v->type == VEH_Train && v->next == NULL) {
  1186 		// Turn off level crossing lights
  1184 		// Turn off level crossing lights
  1187 		_m[tile].m5 &= ~4;
  1185 		SB(_m[tile].m5, 2, 1, 0);
  1188 		MarkTileDirtyByTile(tile);
  1186 		MarkTileDirtyByTile(tile);
  1189 	}
  1187 	}
  1190 }
  1188 }
  1191 
  1189 
  1192 static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player)
  1190 static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player)
  1193 {
  1191 {
  1194 	byte b;
       
  1195 
       
  1196 	// road/rail crossing where the road is owned by the current player?
  1192 	// road/rail crossing where the road is owned by the current player?
  1197 	if (old_player == _m[tile].m3 && IsLevelCrossing(tile)) {
  1193 	if (old_player == _m[tile].m3 && IsLevelCrossing(tile)) {
  1198 		_m[tile].m3 = (new_player == OWNER_SPECTATOR) ? OWNER_NONE : new_player;
  1194 		_m[tile].m3 = (new_player == OWNER_SPECTATOR) ? OWNER_NONE : new_player;
  1199 	}
  1195 	}
  1200 
  1196 
  1201 	if (!IsTileOwner(tile, old_player)) return;
  1197 	if (!IsTileOwner(tile, old_player)) return;
  1202 
  1198 
  1203 	if (new_player != 255) {
  1199 	if (new_player != 255) {
  1204 		SetTileOwner(tile, new_player);
  1200 		SetTileOwner(tile, new_player);
  1205 	}	else {
  1201 	}	else {
  1206 		b = _m[tile].m5&0xF0;
  1202 		if (GB(_m[tile].m5, 4, 4) == 0) {
  1207 		if (b == 0) {
       
  1208 			SetTileOwner(tile, OWNER_NONE);
  1203 			SetTileOwner(tile, OWNER_NONE);
  1209 		} else if (IsLevelCrossing(tile)) {
  1204 		} else if (IsLevelCrossing(tile)) {
  1210 			_m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA;
  1205 			_m[tile].m5 = (_m[tile].m5&8) ? 0x5 : 0xA;
  1211 			SetTileOwner(tile, _m[tile].m3);
  1206 			SetTileOwner(tile, _m[tile].m3);
  1212 			_m[tile].m3 = 0;
  1207 			_m[tile].m3 = 0;