depot.h
author Darkvater
Wed, 20 Apr 2005 22:30:40 +0000
changeset 1713 659ca3025cc5
parent 1650 4a5141e10b72
child 1718 96d76767ea93
permissions -rw-r--r--
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     1
#ifndef DEPOT_H
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     2
#define DEPOT_H
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     3
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     4
#include "pool.h"
1330
5d76a0522a11 (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
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     6
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     7
struct Depot {
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     8
	TileIndex xy;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
     9
	uint16 town_index;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    10
	uint16 index;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    11
};
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    12
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    13
extern MemoryPool _depot_pool;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    14
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    15
/**
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    16
 * Get the pointer to the depot with index 'index'
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    17
 */
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    18
static inline Depot *GetDepot(uint index)
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    19
{
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    20
	return (Depot*)GetItemFromPool(&_depot_pool, index);
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    21
}
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    22
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    23
/**
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    24
 * Get the current size of the DepotPool
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    25
 */
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    26
static inline uint16 GetDepotPoolSize(void)
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    27
{
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    28
	return _depot_pool.total_items;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    29
}
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    30
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    31
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1 < GetDepotPoolSize()) ? GetDepot(d->index + 1) : NULL)
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    32
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    33
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    34
#define MIN_SERVINT_PERCENT  5
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    35
#define MAX_SERVINT_PERCENT 90
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    36
#define MIN_SERVINT_DAYS    30
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    37
#define MAX_SERVINT_DAYS   800
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    38
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    39
VARDEF TileIndex _last_built_train_depot_tile;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    40
VARDEF TileIndex _last_built_road_depot_tile;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    41
VARDEF TileIndex _last_built_aircraft_depot_tile;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    42
VARDEF TileIndex _last_built_ship_depot_tile;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    43
1330
5d76a0522a11 (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
    44
/**
5d76a0522a11 (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
    45
 * Check if a depot really exists.
5d76a0522a11 (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
    46
 */
5d76a0522a11 (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
    47
static inline bool IsValidDepot(Depot* depot)
5d76a0522a11 (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
    48
{
5d76a0522a11 (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
	return depot->xy != 0; /* XXX: Replace by INVALID_TILE someday */
5d76a0522a11 (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
}
5d76a0522a11 (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
5d76a0522a11 (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
    52
/**
5d76a0522a11 (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
 * Check if a tile is a depot of the given type.
5d76a0522a11 (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
 */
5d76a0522a11 (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
static inline bool IsTileDepotType(TileIndex tile, TransportType type)
5d76a0522a11 (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
{
5d76a0522a11 (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
	switch(type)
5d76a0522a11 (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
	{
5d76a0522a11 (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
		case TRANSPORT_RAIL:
5d76a0522a11 (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
			return IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0;
5d76a0522a11 (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
			break;
5d76a0522a11 (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
		case TRANSPORT_ROAD:
5d76a0522a11 (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
			return IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x20;
5d76a0522a11 (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
			break;
5d76a0522a11 (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
		case TRANSPORT_WATER:
5d76a0522a11 (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
			return IsTileType(tile, MP_WATER) && (_map5[tile] & ~3) == 0x80;
5d76a0522a11 (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
			break;
5d76a0522a11 (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
		default:
5d76a0522a11 (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
			assert(0);
5d76a0522a11 (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
			return false;
5d76a0522a11 (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
	}
5d76a0522a11 (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
}
5d76a0522a11 (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
1650
4a5141e10b72 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    74
/**
4a5141e10b72 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    75
 * Returns the direction the exit of the depot on the given tile is facing.
4a5141e10b72 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    76
 */
4a5141e10b72 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    77
static inline uint GetDepotDirection(TileIndex tile, TransportType type)
4a5141e10b72 (svn r2154) - Fix: [NPF] Vehicles should no longer try to drive through the back of depots and road stations.
matthijs
parents: 1330
diff changeset
    78
{
4a5141e10b72 (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
	assert(IsTileDepotType(tile, type));
4a5141e10b72 (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
4a5141e10b72 (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
	switch (type)
4a5141e10b72 (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
	{
4a5141e10b72 (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
		case TRANSPORT_RAIL:
4a5141e10b72 (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
		case TRANSPORT_ROAD:
4a5141e10b72 (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
			/* Rail and road store a diagonal direction in bits 0 and 1 */
4a5141e10b72 (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
			return _map5[tile] & 3;
4a5141e10b72 (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
		case TRANSPORT_WATER:
4a5141e10b72 (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
			/* Water is stubborn, it stores the directions in a different order. */
4a5141e10b72 (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
			switch (_map5[tile] & 3) {
4a5141e10b72 (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
				case 0: return 0;
4a5141e10b72 (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
				case 1: return 2;
4a5141e10b72 (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 2: return 3;
4a5141e10b72 (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
				case 3: return 1;
4a5141e10b72 (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
			}
4a5141e10b72 (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
		default:
4a5141e10b72 (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
			return 0; /* Not reached */
4a5141e10b72 (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
	}
4a5141e10b72 (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
}
4a5141e10b72 (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
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   100
Depot *GetDepotByTile(uint tile);
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   101
void InitializeDepot(void);
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   102
Depot *AllocateDepot(void);
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   103
void DoDeleteDepot(uint tile);
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   104
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   105
#endif /* DEPOT_H */