Files @ r4548:6a33e364fba5
Branch filter:

Location: cpp/openttd-patchpack/source/depot.h - annotation

rubidium
(svn r6380) -Codechange: unify all ways to quit OTTD.
This means that in the intro menu the 'Quit' button immediatelly quits
and the 'Quit' in the menu of the normal game and scenario editor
immediatelly quits when the 'autosave_on_exit' patch is turned on.
This is the same way as the OS/window manager initiated quits, like
alt-F4 and the 'x' in the (OS/window manager drawn) title bar of OTTD.
r2186:5ee653b1b5e1
r2186:5ee653b1b5e1
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r2085:757cdc338c24
r2085:757cdc338c24
r2085:757cdc338c24
r3147:5edf25fbd66a
r1313:da473558c9d7
r1330:62eaa061ec97
r2153:b45e3461c6c4
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r3346:134319cc6f99
r4388:6e13905f3259
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r4388:6e13905f3259
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
r4346:fa4ac6b6f852
r4346:fa4ac6b6f852
r4388:6e13905f3259
r4346:fa4ac6b6f852
r4388:6e13905f3259
r4346:fa4ac6b6f852
r4346:fa4ac6b6f852
r4352:460a517b040f
r4352:460a517b040f
r4352:460a517b040f
r4352:460a517b040f
r4352:460a517b040f
r4388:6e13905f3259
r4388:6e13905f3259
r4388:6e13905f3259
r4388:6e13905f3259
r4388:6e13905f3259
r4388:6e13905f3259
r4388:6e13905f3259
r4388:6e13905f3259
r4346:fa4ac6b6f852
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
r4388:6e13905f3259
r4388:6e13905f3259
r1790:aafbb2ff1ae7
r1790:aafbb2ff1ae7
r1790:aafbb2ff1ae7
r1790:aafbb2ff1ae7
r4297:03b852eaea64
r1790:aafbb2ff1ae7
r1790:aafbb2ff1ae7
r1790:aafbb2ff1ae7
r1790:aafbb2ff1ae7
r1330:62eaa061ec97
r1330:62eaa061ec97
r1330:62eaa061ec97
r1330:62eaa061ec97
r1330:62eaa061ec97
r4000:702cb45b8eab
r1330:62eaa061ec97
r2049:7e26d55f0f4c
r1959:c5a6f024dd5d
r1330:62eaa061ec97
r2049:7e26d55f0f4c
r1959:c5a6f024dd5d
r1330:62eaa061ec97
r2049:7e26d55f0f4c
r1959:c5a6f024dd5d
r1330:62eaa061ec97
r1330:62eaa061ec97
r1330:62eaa061ec97
r1330:62eaa061ec97
r1330:62eaa061ec97
r1330:62eaa061ec97
r1650:67d8c926c00b
r2085:757cdc338c24
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r2085:757cdc338c24
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r4077:259c4c4aacad
r3636:a8e0c73aca96
r2085:757cdc338c24
r3900:1c2675abec23
r2085:757cdc338c24
r2085:757cdc338c24
r1977:1f8b99c96041
r4347:7bff859eed04
r1313:da473558c9d7
r1313:da473558c9d7
r1313:da473558c9d7
/* $Id$ */

#ifndef DEPOT_H
#define DEPOT_H

/** @file depot.h Header files for depots (not hangars)
  * @see depot.c */

#include "direction.h"
#include "pool.h"
#include "tile.h"
#include "variables.h"

struct Depot {
	TileIndex xy;
	TownID town_index;
	DepotID index;
};

extern MemoryPool _depot_pool;

/**
 * Get the pointer to the depot with index 'index'
 */
static inline Depot *GetDepot(DepotID index)
{
	return (Depot*)GetItemFromPool(&_depot_pool, index);
}

/**
 * Get the current size of the DepotPool
 */
static inline uint16 GetDepotPoolSize(void)
{
	return _depot_pool.total_items;
}

/**
 * Check if a depot really exists.
 */
static inline bool IsValidDepot(const Depot *depot)
{
	return depot != NULL && depot->xy != 0;
}

static inline bool IsValidDepotID(uint index)
{
	return index < GetDepotPoolSize() && IsValidDepot(GetDepot(index));
}

void DestroyDepot(Depot *depot);

static inline void DeleteDepot(Depot *depot)
{
	DestroyDepot(depot);
	depot->xy = 0;
}

#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL) if (IsValidDepot(d))
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)

#define MIN_SERVINT_PERCENT  5
#define MAX_SERVINT_PERCENT 90
#define MIN_SERVINT_DAYS    30
#define MAX_SERVINT_DAYS   800

/**
 * Get the service interval domain.
 * Get the new proposed service interval for the vehicle is indeed, clamped
 * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
 * @param index proposed service interval
 */
static inline Date GetServiceIntervalClamped(uint index)
{
	return (_patches.servint_ispercent) ? clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
}

/**
 * Check if a tile is a depot of the given type.
 */
static inline bool IsTileDepotType(TileIndex tile, TransportType type)
{
	switch (type) {
		case TRANSPORT_RAIL:
			return IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xFC) == 0xC0;

		case TRANSPORT_ROAD:
			return IsTileType(tile, MP_STREET) && (_m[tile].m5 & 0xF0) == 0x20;

		case TRANSPORT_WATER:
			return IsTileType(tile, MP_WATER) && (_m[tile].m5 & ~3) == 0x80;

		default:
			assert(0);
			return false;
	}
}


/**
 * Find out if the slope of the tile is suitable to build a depot of given direction
 * @param direction The direction in which the depot's exit points. Starts with 0 as NE and goes Clockwise
 * @param tileh The slope of the tile in question
 * @return true if the construction is possible

 * This is checked by the ugly 0x4C >> direction magic, which does the following:
 * 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
 * So: for direction (only the significant bits are shown)<p>
 * 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
 * 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
 * 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
 * 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
 * So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh
 */
static inline bool CanBuildDepotByTileh(uint32 direction, Slope tileh)
{
	return ((0x4C >> direction) & tileh) != 0;
}

Depot *GetDepotByTile(TileIndex tile);
void InitializeDepots(void);
Depot *AllocateDepot(void);

#endif /* DEPOT_H */