Files
@ r4381:c965d1f3016a
Branch filter:
Location: cpp/openttd-patchpack/source/depot.c - annotation
r4381:c965d1f3016a
2.9 KiB
text/x-c
(svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
-Feature : both unifiedmaglevmode are now set.
Maglev and monorail are not allowed to run on each other tracks and will not be.
Setting those flags will allow grfsets as the Norvegian one to be loaded
-Codechange : link the TTDPatch's irregularstations with OTTD's nonuniform_stations
-Codechange : Reformat the whole array (thanks Rubidium, it sure looks better now)
-Feature : both unifiedmaglevmode are now set.
Maglev and monorail are not allowed to run on each other tracks and will not be.
Setting those flags will allow grfsets as the Norvegian one to be loaded
-Codechange : link the TTDPatch's irregularstations with OTTD's nonuniform_stations
-Codechange : Reformat the whole array (thanks Rubidium, it sure looks better now)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | r2186:5ee653b1b5e1 r2186:5ee653b1b5e1 r1313:da473558c9d7 r1891:c5c5466afa35 r1313:da473558c9d7 r2163:ae001e2aa5b0 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r4346:fa4ac6b6f852 r1313:da473558c9d7 r4346:fa4ac6b6f852 r4346:fa4ac6b6f852 r4346:fa4ac6b6f852 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r3585:4dae9cd69c90 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1977:1f8b99c96041 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r4077:259c4c4aacad r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r4346:fa4ac6b6f852 r1313:da473558c9d7 r4346:fa4ac6b6f852 r4346:fa4ac6b6f852 r4346:fa4ac6b6f852 r4346:fa4ac6b6f852 r4346:fa4ac6b6f852 r1313:da473558c9d7 r4346:fa4ac6b6f852 r4346:fa4ac6b6f852 r1313:da473558c9d7 r4346:fa4ac6b6f852 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r4077:259c4c4aacad r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1977:1f8b99c96041 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r4351:04a502e12263 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r4347:7bff859eed04 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1881:ce1fe6a2816a r4344:bff007ae1fd1 r4344:bff007ae1fd1 r4344:bff007ae1fd1 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r4346:fa4ac6b6f852 r4346:fa4ac6b6f852 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 r1313:da473558c9d7 | /* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "depot.h"
#include "functions.h"
#include "tile.h"
#include "map.h"
#include "table/strings.h"
#include "saveload.h"
#include "order.h"
enum {
/* Max depots: 64000 (8 * 8000) */
DEPOT_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */
DEPOT_POOL_MAX_BLOCKS = 8000,
};
/**
* Called if a new block is added to the depot-pool
*/
static void DepotPoolNewBlock(uint start_item)
{
Depot *d;
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
* TODO - This is just a temporary stage, this will be removed. */
for (d = GetDepot(start_item); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) d->index = start_item++;
}
/* Initialize the town-pool */
MemoryPool _depot_pool = { "Depots", DEPOT_POOL_MAX_BLOCKS, DEPOT_POOL_BLOCK_SIZE_BITS, sizeof(Depot), &DepotPoolNewBlock, NULL, 0, 0, NULL };
/**
* Gets a depot from a tile
*
* @return Returns the depot if the tile had a depot, else it returns NULL
*/
Depot *GetDepotByTile(TileIndex tile)
{
Depot *depot;
FOR_ALL_DEPOTS(depot) {
if (depot->xy == tile) return depot;
}
return NULL;
}
/**
* Allocate a new depot
*/
Depot *AllocateDepot(void)
{
Depot *d;
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
* TODO - This is just a temporary stage, this will be removed. */
for (d = GetDepot(0); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) {
if (!IsValidDepot(d)) {
uint index = d->index;
memset(d, 0, sizeof(Depot));
d->index = index;
return d;
}
}
/* Check if we can add a block to the pool */
if (AddBlockToPool(&_depot_pool)) return AllocateDepot();
return NULL;
}
/**
* Delete a depot
*/
void DoDeleteDepot(TileIndex tile)
{
Depot *depot;
/* Get the depot */
depot = GetDepotByTile(tile);
/* Clear the tile */
DoClearSquare(tile);
/* Clear the depot */
depot->xy = 0;
/* Clear the depot from all order-lists */
RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, depot->index);
/* Delete the depot-window */
DeleteWindowById(WC_VEHICLE_DEPOT, tile);
}
void InitializeDepots(void)
{
CleanPool(&_depot_pool);
AddBlockToPool(&_depot_pool);
}
static const SaveLoad _depot_desc[] = {
SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_VAR(Depot, town_index, SLE_UINT16),
SLE_END()
};
static void Save_DEPT(void)
{
Depot *depot;
FOR_ALL_DEPOTS(depot) {
SlSetArrayIndex(depot->index);
SlObject(depot, _depot_desc);
}
}
static void Load_DEPT(void)
{
int index;
while ((index = SlIterateArray()) != -1) {
Depot *depot;
if (!AddBlockIfNeeded(&_depot_pool, index))
error("Depots: failed loading savegame: too many depots");
depot = GetDepot(index);
SlObject(depot, _depot_desc);
}
}
const ChunkHandler _depot_chunk_handlers[] = {
{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY | CH_LAST},
};
|