depot.h
author Darkvater
Wed, 11 May 2005 16:17:03 +0000
changeset 1790 4afb4b4e4278
parent 1718 cef0773365eb
child 1942 634961366cdc
permissions -rw-r--r--
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
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
1790
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    44
/** Get the service interval domain.
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    45
 * Get the new proposed service interval for the vehicle is indeed, clamped
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    46
 * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    47
 * @param index proposed service interval
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    48
 */
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    49
static inline uint16 GetServiceIntervalClamped(uint index)
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    50
{
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    51
	return (_patches.servint_ispercent) ? clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    52
}
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1718
diff changeset
    53
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    54
VARDEF TileIndex _last_built_train_depot_tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    55
VARDEF TileIndex _last_built_road_depot_tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    56
VARDEF TileIndex _last_built_aircraft_depot_tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    57
VARDEF TileIndex _last_built_ship_depot_tile;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    58
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
    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
 * 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
    61
 */
1718
cef0773365eb (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    62
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
    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
	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
    65
}
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
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
/**
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
 * 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
    69
 */
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
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
    71
{
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
	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
    73
	{
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
		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
    75
			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
    76
			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
    77
		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
    78
			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
    79
			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
    80
		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
    81
			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
    82
			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
    83
		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
    84
			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
    85
			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
    86
	}
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
    87
}
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
    88
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
    89
/**
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
 * 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
    91
 */
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
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
    93
{
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
	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
    95
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
	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
    97
	{
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 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
    99
		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
   100
			/* 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
   101
			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
   102
		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
   103
			/* 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
   104
			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
   105
				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
   106
				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
   107
				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
   108
				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
   109
			}
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
   110
		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
   111
			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
   112
	}
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
   113
}
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
   114
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   115
Depot *GetDepotByTile(uint tile);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   116
void InitializeDepot(void);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   117
Depot *AllocateDepot(void);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   118
void DoDeleteDepot(uint tile);
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   119
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   120
#endif /* DEPOT_H */