* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file water_regions.cpp Handles dividing the water in the map into square regions to assist pathfinding. */
if (current_region.NumberOfPatches() == 1 && neighboring_region.NumberOfPatches() == 1) {
func(WaterRegionPatchDesc{ nx, ny, FIRST_REGION_LABEL }); // No further checks needed because we know there is just one patch for both adjacent regions
return;
}
/* Multiple water patches can be reached from the current patch. Check each edge tile individually. */
static std::vector<TWaterRegionPatchLabel> unique_labels; // static and vector-instead-of-map for performance reasons
unique_labels.clear();
for (int x_or_y = 0; x_or_y < WATER_REGION_EDGE_LENGTH; ++x_or_y) {
if (!HasBit(traversability_bits, x_or_y)) continue;
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file water_regions.h Handles dividing the water in the map into regions to assist pathfinding. */
#ifndef WATER_REGIONS_H
#define WATER_REGIONS_H
#include "tile_type.h"
#include "map_func.h"
using TWaterRegionPatchLabel = uint8_t;
using TWaterRegionIndex = uint;
constexpr int WATER_REGION_EDGE_LENGTH = 16;
constexpr int WATER_REGION_NUMBER_OF_TILES = WATER_REGION_EDGE_LENGTH * WATER_REGION_EDGE_LENGTH;
/**
* Describes a single interconnected patch of water within a particular water region.
*/
struct WaterRegionPatchDesc
{
int x; ///< The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis
int y; ///< The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis
TWaterRegionPatchLabel label; ///< Unique label identifying the patch within the region
bool operator==(const WaterRegionPatchDesc &other) const { return x == other.x && y == other.y && label == other.label; }
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file yapf_ship_regions.cpp Implementation of YAPF for water regions, which are used for finding intermediate ship destinations. */
#include "../../stdafx.h"
#include "../../ship.h"
#include "yapf.hpp"
#include "yapf_ship_regions.h"
#include "../water_regions.h"
#include "../../safeguards.h"
constexpr int DIRECT_NEIGHBOR_COST = 100;
constexpr int NODES_PER_REGION = 4;
constexpr int MAX_NUMBER_OF_NODES = 65536;
/** Yapf Node Key that represents a single patch of interconnected water within a water region. */
struct CYapfRegionPatchNodeKey {
WaterRegionPatchDesc m_water_region_patch;
static_assert(sizeof(TWaterRegionPatchLabel) == sizeof(byte)); // Important for the hash calculation.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file yapf_ship_regions.h Implementation of YAPF for water regions, which are used for finding intermediate ship destinations. */
#ifndef YAPF_SHIP_REGIONS_H
#define YAPF_SHIP_REGIONS_H
#include "../../stdafx.h"
#include "../../tile_type.h"
#include "../water_regions.h"
struct Ship;
std::vector<WaterRegionPatchDesc> YapfShipFindWaterRegionPath(const Ship *v, TileIndex start_tile, int max_returned_path_length);
#endif /* YAPF_SHIP_REGIONS_H */
src/saveload/CMakeLists.txt
➞
Show inline comments
@@ -41,7 +41,8 @@ add_files(
strings_sl.cpp
story_sl.cpp
subsidy_sl.cpp
town_sl.cpp
vehicle_sl.cpp
waypoint_sl.cpp
water_regions_sl.cpp
)
src/saveload/afterload.cpp
➞
Show inline comments
@@ -58,12 +58,13 @@
#include "../disaster_vehicle.h"
#include "../ship.h"
#include "../water.h"
#include "../timer/timer.h"
#include "../timer/timer_game_calendar.h"
#include "../timer/timer_game_tick.h"
#include "../pathfinder/water_regions.h"
#include "saveload_internal.h"
#include <signal.h>
#include "../safeguards.h"
@@ -3293,12 +3294,14 @@ bool AfterLoadGame()
if (!Company::IsValidID(first_human_company)) {
Company *c = DoStartupNewCompany(false, first_human_company);
c->settings = _settings_client.company;
}
}
if (IsSavegameVersionBefore(SLV_WATER_REGIONS)) InitializeWaterRegions();
return true;
}
/**
* Reload all NewGRF files during a running game. This is a cut-down
SLV_CARGO_TRAVELLED, ///< 319 PR#11283 CargoPacket now tracks how far it travelled inside a vehicle.
SLV_STATION_RATING_CHEAT, ///< 320 PR#11346 Add cheat to fix station ratings at 100%.
SLV_TIMETABLE_START_TICKS, ///< 321 PR#11468 Convert timetable start from a date to ticks.
SLV_TIMETABLE_START_TICKS_FIX, ///< 322 PR#11557 Fix for missing convert timetable start from a date to ticks.
SLV_TIMETABLE_TICKS_TYPE, ///< 323 PR#11435 Convert timetable current order time to ticks.
SLV_WATER_REGIONS, ///< 324 PR#10543 Water Regions for ship pathfinder.
SL_MAX_VERSION, ///< Highest possible saveload version
};
/** Save or load result codes. */
enum SaveOrLoadResult {
src/saveload/water_regions_sl.cpp
➞
Show inline comments
new file 100644
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file water_regions_sl.cpp Handles saving and loading of water region data */