1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-29 17:39:09 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Richard Wheeler
788e4c3ddf Change: Set endgame background to match original graphics borders 2025-08-28 20:34:01 +01:00
Kuhnovic
10e81af663 Codechange: Deduplicate YAPF estimate calculation. (#14527) 2025-08-28 21:09:00 +02:00
9 changed files with 31 additions and 43 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -49,6 +49,9 @@ struct EndGameHighScoreBaseWindow : Window {
this->DrawWidgets();
/* Fill with the appropriate background colour instead of leaving default window colour */
GfxFillRect(Rect{0, 0, this->width, this->height}, PixelColour{105}, FILLRECT_OPAQUE);
/* Standard background slices are 50 pixels high, but it's designed
* for 480 pixels total. 96% of 500 is 480. */
Dimension dim = GetSpriteSize(this->background_img);

View File

@@ -5,7 +5,7 @@
* 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_common.hpp Commonly used classes for YAPF. */
/** @file yapf_common.hpp Commonly used classes and utilities for YAPF. */
#ifndef YAPF_COMMON_HPP
#define YAPF_COMMON_HPP
@@ -119,6 +119,30 @@ class CYapfT
{
};
/**
* Calculates the octile distance cost between a starting tile / trackdir and a destination tile.
* @param start_tile Starting tile.
* @param start_td Starting trackdir.
* @param destination_tile Destination tile.
* @return Octile distance cost between starting tile / trackdir and destination tile.
*/
inline int OctileDistanceCost(TileIndex start_tile, Trackdir start_td, TileIndex destination_tile)
{
static constexpr int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
static constexpr int dg_dir_to_y_offs[] = {0, 1, 0, -1};
const DiagDirection exitdir = TrackdirToExitdir(start_td);
const int x1 = 2 * TileX(start_tile) + dg_dir_to_x_offs[static_cast<int>(exitdir)];
const int y1 = 2 * TileY(start_tile) + dg_dir_to_y_offs[static_cast<int>(exitdir)];
const int x2 = 2 * TileX(destination_tile);
const int y2 = 2 * TileY(destination_tile);
const int dx = abs(x1 - x2);
const int dy = abs(y1 - y2);
const int dmin = std::min(dx, dy);
const int dxy = abs(dx - dy);
return dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
}
#endif /* YAPF_COMMON_HPP */

View File

@@ -194,25 +194,12 @@ public:
*/
inline bool PfCalcEstimate(Node &n)
{
static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
if (this->PfDetectDestination(n)) {
n.estimate = n.cost;
return true;
}
TileIndex tile = n.GetLastTile();
DiagDirection exitdir = TrackdirToExitdir(n.GetLastTrackdir());
int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
int x2 = 2 * TileX(this->dest_tile);
int y2 = 2 * TileY(this->dest_tile);
int dx = abs(x1 - x2);
int dy = abs(y1 - y2);
int dmin = std::min(dx, dy);
int dxy = abs(dx - dy);
int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
n.estimate = n.cost + d;
n.estimate = n.cost + OctileDistanceCost(n.GetLastTile(), n.GetLastTrackdir(), this->dest_tile);
assert(n.estimate >= n.parent->estimate);
return true;
}

View File

@@ -293,25 +293,12 @@ public:
*/
inline bool PfCalcEstimate(Node &n)
{
static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
if (this->PfDetectDestination(n)) {
n.estimate = n.cost;
return true;
}
TileIndex tile = n.segment_last_tile;
DiagDirection exitdir = TrackdirToExitdir(n.segment_last_td);
int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
int x2 = 2 * TileX(this->dest_tile);
int y2 = 2 * TileY(this->dest_tile);
int dx = abs(x1 - x2);
int dy = abs(y1 - y2);
int dmin = std::min(dx, dy);
int dxy = abs(dx - dy);
int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
n.estimate = n.cost + d;
n.estimate = n.cost + OctileDistanceCost(n.segment_last_tile, n.segment_last_td, this->dest_tile);
assert(n.estimate >= n.parent->estimate);
return true;
}

View File

@@ -96,25 +96,12 @@ public:
{
const TileIndex destination_tile = this->has_intermediate_dest ? this->intermediate_dest_tile : this->dest_tile;
static const int dg_dir_to_x_offs[] = { -1, 0, 1, 0 };
static const int dg_dir_to_y_offs[] = { 0, 1, 0, -1 };
if (this->PfDetectDestination(n)) {
n.estimate = n.cost;
return true;
}
TileIndex tile = n.segment_last_tile;
DiagDirection exitdir = TrackdirToExitdir(n.segment_last_td);
int x1 = 2 * TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
int y1 = 2 * TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
int x2 = 2 * TileX(destination_tile);
int y2 = 2 * TileY(destination_tile);
int dx = abs(x1 - x2);
int dy = abs(y1 - y2);
int dmin = std::min(dx, dy);
int dxy = abs(dx - dy);
int d = dmin * YAPF_TILE_CORNER_LENGTH + (dxy - 1) * (YAPF_TILE_LENGTH / 2);
n.estimate = n.cost + d;
n.estimate = n.cost + OctileDistanceCost(n.segment_last_tile, n.segment_last_td, destination_tile);
assert(n.estimate >= n.parent->estimate);
return true;
}