Files
@ r24498:e9114d9ab04a
Branch filter:
Location: cpp/openttd-patchpack/source/src/station_kdtree.h - annotation
r24498:e9114d9ab04a
1.8 KiB
text/x-c
Fix #6468: don't store version of AIs-started-via-console in name
You can do: "startai myai.3", which starts version 3 of "myai".
This is very useful for testing save/load code between different
versions of your AI.
However, when using this syntax, the AI got saved as "myai.3" as
name of the AI, instead of "myai". This caused several problems,
like indicating to the user the AI could not be found, but still
load the AI. But in all cases, the AI never got the chance to
load the saved data, making the whole reason this exists pointless.
By splitting the name and version already in the console command,
the code becomes simpler and AIs started this way now follow the
normal flow after initialization.
You can do: "startai myai.3", which starts version 3 of "myai".
This is very useful for testing save/load code between different
versions of your AI.
However, when using this syntax, the AI got saved as "myai.3" as
name of the AI, instead of "myai". This caused several problems,
like indicating to the user the AI could not be found, but still
load the AI. But in all cases, the AI never got the chance to
load the saved data, making the whole reason this exists pointless.
By splitting the name and version already in the console command,
the code becomes simpler and AIs started this way now follow the
normal flow after initialization.
r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 r23436:cfad304b5b27 | /*
* 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 station_kdtree.h Declarations for accessing the k-d tree of stations */
#ifndef STATION_KDTREE_H
#define STATION_KDTREE_H
#include "core/kdtree.hpp"
#include "core/math_func.hpp"
#include "station_base.h"
#include "map_func.h"
inline uint16 Kdtree_StationXYFunc(StationID stid, int dim) { return (dim == 0) ? TileX(BaseStation::Get(stid)->xy) : TileY(BaseStation::Get(stid)->xy); }
typedef Kdtree<StationID, decltype(&Kdtree_StationXYFunc), uint16, int> StationKdtree;
extern StationKdtree _station_kdtree;
/**
* Call a function on all stations whose sign is within a radius of a center tile.
* @param center Central tile to search around.
* @param radius Distance in both X and Y to search within.
* @param func The function to call, must take a single parameter which is Station*.
*/
template <typename Func>
void ForAllStationsRadius(TileIndex center, uint radius, Func func)
{
uint16 x1, y1, x2, y2;
x1 = (uint16)max<int>(0, TileX(center) - radius);
x2 = (uint16)min<int>(TileX(center) + radius + 1, MapSizeX());
y1 = (uint16)max<int>(0, TileY(center) - radius);
y2 = (uint16)min<int>(TileY(center) + radius + 1, MapSizeY());
_station_kdtree.FindContained(x1, y1, x2, y2, [&](StationID id) {
func(Station::Get(id));
});
}
#endif
|