depot.h
author tron
Wed, 13 Jul 2005 18:04:01 +0000
changeset 2049 538e73c53f54
parent 1977 37bbebf94434
child 2085 876f20a0e843
permissions -rw-r--r--
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
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
1718
96d76767ea93 (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)
96d76767ea93 (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    32
{
96d76767ea93 (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    33
	return index < GetDepotPoolSize();
96d76767ea93 (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    34
}
96d76767ea93 (svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents: 1650
diff changeset
    35
1313
f1013ec3d318 (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)
f1013ec3d318 (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)
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
#define MIN_SERVINT_PERCENT  5
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    40
#define MAX_SERVINT_PERCENT 90
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    41
#define MIN_SERVINT_DAYS    30
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    42
#define MAX_SERVINT_DAYS   800
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    43
1790
47963a0cfca3 (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.
47963a0cfca3 (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
47963a0cfca3 (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.
47963a0cfca3 (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
47963a0cfca3 (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
 */
47963a0cfca3 (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)
47963a0cfca3 (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
{
47963a0cfca3 (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);
47963a0cfca3 (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
}
47963a0cfca3 (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
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    54
VARDEF TileIndex _last_built_train_depot_tile;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    55
VARDEF TileIndex _last_built_road_depot_tile;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    56
VARDEF TileIndex _last_built_aircraft_depot_tile;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    57
VARDEF TileIndex _last_built_ship_depot_tile;
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
    58
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
    59
/**
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
 * 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
    61
 */
1718
96d76767ea93 (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
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
{
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
	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
    65
}
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
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
/**
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
 * 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
    69
 */
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
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
    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
	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
    73
	{
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
    74
		case TRANSPORT_RAIL:
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1977
diff changeset
    75
			return IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xFC) == 0xC0;
1959
c2c3a9850c2e (svn r2465) Remove some unreachable code
tron
parents: 1944
diff changeset
    76
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
    77
		case TRANSPORT_ROAD:
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1977
diff changeset
    78
			return IsTileType(tile, MP_STREET) && (_m[tile].m5 & 0xF0) == 0x20;
1959
c2c3a9850c2e (svn r2465) Remove some unreachable code
tron
parents: 1944
diff changeset
    79
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
    80
		case TRANSPORT_WATER:
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1977
diff changeset
    81
			return IsTileType(tile, MP_WATER) && (_m[tile].m5 & ~3) == 0x80;
1959
c2c3a9850c2e (svn r2465) Remove some unreachable code
tron
parents: 1944
diff changeset
    82
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
    83
		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
    84
			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
    85
			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
    86
	}
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
    87
}
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
    88
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
    89
/**
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
 * 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
    91
 */
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1790
diff changeset
    92
static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type)
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
    93
{
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
	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
    95
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
	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
    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
		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
    99
		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
   100
			/* Rail and road store a diagonal direction in bits 0 and 1 */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1977
diff changeset
   101
			return (DiagDirection)(_m[tile].m5 & 3);
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
   102
		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
   103
			/* Water is stubborn, it stores the directions in a different order. */
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1977
diff changeset
   104
			switch (_m[tile].m5 & 3) {
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1790
diff changeset
   105
				case 0: return DIAGDIR_NE;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1790
diff changeset
   106
				case 1: return DIAGDIR_SW;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1790
diff changeset
   107
				case 2: return DIAGDIR_NW;
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1790
diff changeset
   108
				case 3: return DIAGDIR_SE;
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
   109
			}
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
   110
		default:
1942
c5d5cf5b0263 (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1790
diff changeset
   111
			return INVALID_DIAGDIR; /* Not reached */
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
   112
	}
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
   113
}
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
   114
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1959
diff changeset
   115
Depot *GetDepotByTile(TileIndex tile);
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   116
void InitializeDepot(void);
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   117
Depot *AllocateDepot(void);
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1959
diff changeset
   118
void DoDeleteDepot(TileIndex tile);
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   119
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
diff changeset
   120
#endif /* DEPOT_H */