@@ -2276,14 +2276,6 @@
>
</File>
<File
RelativePath=".\..\src\misc\autocopyptr.hpp"
RelativePath=".\..\src\misc\autoptr.hpp"
RelativePath=".\..\src\misc\binaryheap.hpp"
@@ -2273,14 +2273,6 @@
@@ -516,8 +516,6 @@ water_map.h
# Misc
misc/array.hpp
misc/autocopyptr.hpp
misc/autoptr.hpp
misc/binaryheap.hpp
misc/blob.hpp
misc/countedobj.cpp
deleted file
@@ -676,7 +676,7 @@ int AllocateSpecToStation(const StationS
{
uint i;
if (statspec == NULL) return 0;
if (statspec == NULL || st == NULL) return 0;
/* Check if this spec has already been allocated */
for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) {
@@ -294,16 +294,7 @@ protected:
}
public:
/**
* Check whether we can allocate an item in this pool. This to prevent the
* need to actually construct the object and then destructing it again,
* which could be *very* costly.
* @return true if and only if at least ONE item can be allocated.
*/
static inline bool CanAllocateItem()
return AllocateRaw() != NULL;
static bool CanAllocateItem();
};
@@ -31,4 +31,25 @@ template<typename T, typename Tid, OldMe
return NULL;
template<typename T, typename Tid, OldMemoryPool<T> *Tpool> bool PoolItem<T, Tid, Tpool>::CanAllocateItem()
uint last_minus_one = Tpool->GetSize() - 1;
for (T *t = Tpool->Get(Tpool->first_free_index); t != NULL; t = (t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
if (!t->IsValid()) return true;
Tpool->first_free_index = t->index;
/* Check if we can add a block to the pool */
if (Tpool->AddBlockToPool()) return CanAllocateItem();
return false;
#endif /* OLDPOOL_FUNC_H */
@@ -43,6 +43,7 @@
#include "station_map.h"
#include "water_map.h"
#include "functions.h"
#include "oldpool_func.h"
#include "table/sprites.h"
#include "table/strings.h"
@@ -37,6 +37,7 @@
#include "cheat_func.h"
#include "effectvehicle_func.h"
@@ -25,7 +25,6 @@
#include "newgrf_callbacks.h"
#include "newgrf_station.h"
#include "yapf/yapf.h"
#include "misc/autoptr.hpp"
#include "road_type.h"
#include "road_internal.h" /* For drawing catenary/checking road removal */
#include "cargotype.h"
@@ -239,7 +238,7 @@ enum StationNaming {
STATIONNAMING_HELIPORT,
static bool GenerateStationName(Station *st, TileIndex tile, int flag)
static void GenerateStationName(Station *st, TileIndex tile, int flag)
static const uint32 _gen_station_name_bits[] = {
0, /* 0 */
@@ -344,7 +343,6 @@ static bool GenerateStationName(Station
done:
st->string_id = found + STR_SV_STNAME;
return true;
#undef M
@@ -962,10 +960,6 @@ CommandCost CmdBuildRailroadStation(Tile
/* See if there is a deleted station close to us. */
if (st == NULL) st = GetClosestStationFromTile(tile_org);
/* In case of new station if DC_EXEC is NOT set we still need to create the station
* to test if everything is OK. In this case we need to delete it before return. */
AutoPtrT<Station> st_auto_delete;
if (st != NULL) {
/* Reuse an existing station. */
if (st->owner != _current_player)
@@ -983,17 +977,17 @@ CommandCost CmdBuildRailroadStation(Tile
if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR;
} else {
/* allocate and initialize new station */
st = new Station(tile_org);
if (st == NULL) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
st_auto_delete = st;
st->town = ClosestTownFromTile(tile_org, (uint)-1);
if (!GenerateStationName(st, tile_org, STATIONNAMING_RAIL)) return CMD_ERROR;
if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
SetBit(st->town->have_ratings, _current_player);
if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
if (flags & DC_EXEC) {
st = new Station();
GenerateStationName(st, tile_org, STATIONNAMING_RAIL);
if (IsValidPlayer(_current_player)) {
@@ -1088,8 +1082,6 @@ CommandCost CmdBuildRailroadStation(Tile
RebuildStationLists();
InvalidateWindow(WC_STATION_LIST, st->owner);
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
/* success, so don't delete the new station */
st_auto_delete.Detach();
return cost;
@@ -1394,23 +1386,13 @@ CommandCost CmdBuildRoadStop(TileIndex t
if (st == NULL) st = GetClosestStationFromTile(tile);
/* give us a road stop in the list, and check if something went wrong */
RoadStop *road_stop = new RoadStop(tile);
if (road_stop == NULL) {
return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
/* ensure that in case of error (or no DC_EXEC) the new road stop gets deleted upon return */
AutoPtrT<RoadStop> rs_auto_delete(road_stop);
if (!RoadStop::CanAllocateItem()) return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
if (st != NULL &&
GetNumRoadStopsInStation(st, ROADSTOP_BUS) + GetNumRoadStopsInStation(st, ROADSTOP_TRUCK) >= RoadStop::LIMIT) {
if (st->owner != _current_player) {
return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
@@ -1419,26 +1401,25 @@ CommandCost CmdBuildRoadStop(TileIndex t
if (!st->rect.BeforeAddTile(tile, StationRect::ADD_TEST)) return CMD_ERROR;
st = new Station(tile);
/* ensure that in case of error (or no DC_EXEC) the new station gets deleted upon return */
Town *t = st->town = ClosestTownFromTile(tile, (uint)-1);
if (!GenerateStationName(st, tile, STATIONNAMING_ROAD)) return CMD_ERROR;
SetBit(t->have_ratings, _current_player);
st->town = ClosestTownFromTile(tile, (uint)-1);
GenerateStationName(st, tile, STATIONNAMING_ROAD);
st->sign.width_1 = 0;
cost.AddCost((type) ? _price.build_truck_station : _price.build_bus_station);
/* Insert into linked list of RoadStops */
RoadStop **currstop = FindRoadStopSpot(type, st);
*currstop = road_stop;
@@ -1460,9 +1441,6 @@ CommandCost CmdBuildRoadStop(TileIndex t
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
/* success, so don't delete the new station and the new road stop */
rs_auto_delete.Detach();
@@ -1717,10 +1695,6 @@ CommandCost CmdBuildAirport(TileIndex ti
return CMD_ERROR;
@@ -1735,24 +1709,18 @@ CommandCost CmdBuildAirport(TileIndex ti
airport_upgrade = false;
st->town = t;
/* If only helicopters may use the airport generate a helicopter related (5)
* station name, otherwise generate a normal airport name (1) */
if (!GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT)) {
GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT);
@@ -1789,8 +1757,6 @@ CommandCost CmdBuildAirport(TileIndex ti
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
@@ -1860,18 +1826,18 @@ CommandCost CmdBuildBuoy(TileIndex tile,
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_304B_SITE_UNSUITABLE);
Station *st = new Station(tile);
AutoPtrT<Station> st_auto_delete(st);
if (!GenerateStationName(st, tile, STATIONNAMING_BUOY)) return CMD_ERROR;
Station *st = new Station();
GenerateStationName(st, tile, STATIONNAMING_BUOY);
st->dock_tile = tile;
st->facilities |= FACIL_DOCK;
/* Buoys are marked in the Station struct by this flag. Yes, it is this
@@ -1888,8 +1854,6 @@ CommandCost CmdBuildBuoy(TileIndex tile,
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
@@ -2011,10 +1975,6 @@ CommandCost CmdBuildDock(TileIndex tile,
/* Find a station close to us */
@@ -2025,21 +1985,19 @@ CommandCost CmdBuildDock(TileIndex tile,
if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK);
GenerateStationName(st, tile, STATIONNAMING_DOCK);
if (!GenerateStationName(st, tile, STATIONNAMING_DOCK)) return CMD_ERROR;
@@ -2055,8 +2013,6 @@ CommandCost CmdBuildDock(TileIndex tile,
@@ -2877,11 +2833,7 @@ void BuildOilRig(TileIndex tile)
if (!GenerateStationName(st, tile, STATIONNAMING_OILRIG)) {
DEBUG(misc, 0, "Can't allocate station-name for oilrig at 0x%X, reverting to oilrig only", tile);
delete st;
return;
GenerateStationName(st, tile, STATIONNAMING_OILRIG);
MakeOilrig(tile, st->index);
@@ -39,6 +39,7 @@
#include "airport.h"
#include "newgrf_cargo.h"
Status change: