rail_cmd.c
changeset 1902 5d653da1abb7
parent 1901 fb05044cf5c3
child 1903 725cdd1ec467
equal deleted inserted replaced
1901:fb05044cf5c3 1902:5d653da1abb7
   314 					ret = CheckRailSlope(tileh, rail_bit, 0, tile);
   314 					ret = CheckRailSlope(tileh, rail_bit, 0, tile);
   315 					if (CmdFailed(ret)) return ret;
   315 					if (CmdFailed(ret)) return ret;
   316 					cost += ret;
   316 					cost += ret;
   317 
   317 
   318 					if (flags & DC_EXEC) {
   318 					if (flags & DC_EXEC) {
   319 						_map_owner[tile] = _current_player;
   319 						SetTileOwner(tile, _current_player);
   320 						_map3_lo[tile] &= ~0x0F;
   320 						_map3_lo[tile] &= ~0x0F;
   321 						_map3_lo[tile] |= p1;
   321 						_map3_lo[tile] |= p1;
   322 						_map5[tile] = (m5 & 0xC7) | 0x20; // railroad under bridge
   322 						_map5[tile] = (m5 & 0xC7) | 0x20; // railroad under bridge
   323 					}
   323 					}
   324 					break;
   324 					break;
   363 						(rail_bit == 1 && m5 == 0x05) ||
   363 						(rail_bit == 1 && m5 == 0x05) ||
   364 						(rail_bit == 2 && m5 == 0x0A) // correct direction?
   364 						(rail_bit == 2 && m5 == 0x0A) // correct direction?
   365 					)) {
   365 					)) {
   366 				if (flags & DC_EXEC) {
   366 				if (flags & DC_EXEC) {
   367 					_map3_lo[tile] = GetTileOwner(tile);
   367 					_map3_lo[tile] = GetTileOwner(tile);
   368 					_map_owner[tile] = _current_player;
   368 					SetTileOwner(tile, _current_player);
   369 					_map3_hi[tile] = p1;
   369 					_map3_hi[tile] = p1;
   370 					_map5[tile] = 0x10 | (rail_bit == 1 ? 0x08 : 0x00); // level crossing
   370 					_map5[tile] = 0x10 | (rail_bit == 1 ? 0x08 : 0x00); // level crossing
   371 				}
   371 				}
   372 				break;
   372 				break;
   373 			}
   373 			}
   385 			if (CmdFailed(ret)) return ret;
   385 			if (CmdFailed(ret)) return ret;
   386 			cost += ret;
   386 			cost += ret;
   387 
   387 
   388 			if (flags & DC_EXEC) {
   388 			if (flags & DC_EXEC) {
   389 				SetTileType(tile, MP_RAILWAY);
   389 				SetTileType(tile, MP_RAILWAY);
   390 				_map_owner[tile] = _current_player;
   390 				SetTileOwner(tile, _current_player);
   391 				_map2[tile] = 0; // Bare land
   391 				_map2[tile] = 0; // Bare land
   392 				_map3_lo[tile] = p1; // No signals, rail type
   392 				_map3_lo[tile] = p1; // No signals, rail type
   393 				_map5[tile] = rail_bit;
   393 				_map5[tile] = rail_bit;
   394 			}
   394 			}
   395 			break;
   395 			break;
   459 			return CMD_ERROR;
   459 			return CMD_ERROR;
   460 
   460 
   461 		if (!(flags & DC_EXEC))
   461 		if (!(flags & DC_EXEC))
   462 			return _price.remove_rail;
   462 			return _price.remove_rail;
   463 
   463 
   464 		_map_owner[tile] = OWNER_NONE;
   464 		SetTileOwner(tile, OWNER_NONE);
   465 		_map5[tile] = ti.map5 & 0xC7;
   465 		_map5[tile] = ti.map5 & 0xC7;
   466 	} else if (ti.type == MP_STREET) {
   466 	} else if (ti.type == MP_STREET) {
   467 		byte m5;
   467 		byte m5;
   468 		if (!(ti.map5 & 0xF0))
   468 		if (!(ti.map5 & 0xF0))
   469 			return CMD_ERROR;
   469 			return CMD_ERROR;
   483 
   483 
   484 		if (!(flags & DC_EXEC))
   484 		if (!(flags & DC_EXEC))
   485 			return _price.remove_rail;
   485 			return _price.remove_rail;
   486 
   486 
   487 		_map5[tile] = m5;
   487 		_map5[tile] = m5;
   488 		_map_owner[tile] = _map3_lo[tile];
   488 		SetTileOwner(tile, _map3_lo[tile]);
   489 		_map2[tile] = 0;
   489 		_map2[tile] = 0;
   490 	} else {
   490 	} else {
   491 		assert(ti.type == MP_RAILWAY);
   491 		assert(ti.type == MP_RAILWAY);
   492 
   492 
   493 		if (ti.map5 & RAIL_TYPE_SPECIAL)
   493 		if (ti.map5 & RAIL_TYPE_SPECIAL)
  2026 static void ChangeTileOwner_Track(uint tile, byte old_player, byte new_player)
  2026 static void ChangeTileOwner_Track(uint tile, byte old_player, byte new_player)
  2027 {
  2027 {
  2028 	if (!IsTileOwner(tile, old_player)) return;
  2028 	if (!IsTileOwner(tile, old_player)) return;
  2029 
  2029 
  2030 	if (new_player != 255) {
  2030 	if (new_player != 255) {
  2031 		_map_owner[tile] = new_player;
  2031 		SetTileOwner(tile, new_player);
  2032 	}	else {
  2032 	}	else {
  2033 		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
  2033 		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
  2034 	}
  2034 	}
  2035 }
  2035 }
  2036 
  2036