depot.h
author matthijs
Mon, 02 May 2005 18:53:06 +0000
changeset 1749 bb7fa90dd0cb
parent 1718 cef0773365eb
child 1790 4afb4b4e4278
permissions -rw-r--r--
(svn r2253) - Fix: [ 1190896 1184378 ] [NPF] Trains ignoring their railtype (mono, maglev) (glx)
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     1
#ifndef DEPOT_H
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     2
#define DEPOT_H
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     3
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     4
#include "pool.h"
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
     5
#include "tile.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     6
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     7
struct Depot {
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     8
	TileIndex xy;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     9
	uint16 town_index;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    10
	uint16 index;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    11
};
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    12
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    13
extern MemoryPool _depot_pool;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    14
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    15
/**
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    16
 * Get the pointer to the depot with index 'index'
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    17
 */
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    18
static inline Depot *GetDepot(uint index)
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    19
{
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    20
	return (Depot*)GetItemFromPool(&_depot_pool, index);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    21
}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    22
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    23
/**
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    24
 * Get the current size of the DepotPool
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    25
 */
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    26
static inline uint16 GetDepotPoolSize(void)
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    27
{
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    28
	return _depot_pool.total_items;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    29
}
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    30
1718
cef0773365eb (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    31
static inline bool IsDepotIndex(uint index)
cef0773365eb (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    32
{
cef0773365eb (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    33
	return index < GetDepotPoolSize();
cef0773365eb (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    34
}
cef0773365eb (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    35
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    36
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL)
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    37
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    38
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    39
#define MIN_SERVINT_PERCENT  5
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    40
#define MAX_SERVINT_PERCENT 90
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    41
#define MIN_SERVINT_DAYS    30
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    42
#define MAX_SERVINT_DAYS   800
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    43
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    44
VARDEF TileIndex _last_built_train_depot_tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    45
VARDEF TileIndex _last_built_road_depot_tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    46
VARDEF TileIndex _last_built_aircraft_depot_tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    47
VARDEF TileIndex _last_built_ship_depot_tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    48
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    49
/**
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    50
 * Check if a depot really exists.
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    51
 */
1718
cef0773365eb (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    52
static inline bool IsValidDepot(const Depot* depot)
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    53
{
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    54
	return depot->xy != 0; /* XXX: Replace by INVALID_TILE someday */
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    55
}
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    56
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    57
/**
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    58
 * Check if a tile is a depot of the given type.
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    59
 */
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    60
static inline bool IsTileDepotType(TileIndex tile, TransportType type)
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    61
{
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    62
	switch(type)
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    63
	{
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    64
		case TRANSPORT_RAIL:
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    65
			return IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0;
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    66
			break;
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    67
		case TRANSPORT_ROAD:
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    68
			return IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x20;
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    69
			break;
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    70
		case TRANSPORT_WATER:
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    71
			return IsTileType(tile, MP_WATER) && (_map5[tile] & ~3) == 0x80;
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    72
			break;
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    73
		default:
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    74
			assert(0);
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    75
			return false;
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    76
	}
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    77
}
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
    78
1650
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    79
/**
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    80
 * Returns the direction the exit of the depot on the given tile is facing.
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    81
 */
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    82
static inline uint GetDepotDirection(TileIndex tile, TransportType type)
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    83
{
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    84
	assert(IsTileDepotType(tile, type));
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    85
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    86
	switch (type)
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    87
	{
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    88
		case TRANSPORT_RAIL:
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    89
		case TRANSPORT_ROAD:
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    90
			/* Rail and road store a diagonal direction in bits 0 and 1 */
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    91
			return _map5[tile] & 3;
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    92
		case TRANSPORT_WATER:
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    93
			/* Water is stubborn, it stores the directions in a different order. */
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    94
			switch (_map5[tile] & 3) {
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    95
				case 0: return 0;
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    96
				case 1: return 2;
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    97
				case 2: return 3;
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    98
				case 3: return 1;
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    99
			}
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
   100
		default:
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
   101
			return 0; /* Not reached */
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
   102
	}
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
   103
}
12a20779af79 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
   104
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   105
Depot *GetDepotByTile(uint tile);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   106
void InitializeDepot(void);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   107
Depot *AllocateDepot(void);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   108
void DoDeleteDepot(uint tile);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   109
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   110
#endif /* DEPOT_H */