Use separate tile hash for each vehicle type
This commit is contained in:
@@ -40,10 +40,79 @@ typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
|
||||
|
||||
void VehicleServiceInDepot(Vehicle *v);
|
||||
uint CountVehiclesInChain(const Vehicle *v);
|
||||
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||
bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||
|
||||
/**
|
||||
* Find a vehicle from a specific location. It will call \a proc for ALL vehicles
|
||||
* on the tile and YOU must make SURE that the "best one" is stored in the
|
||||
* data value and is ALWAYS the same regardless of the order of the vehicles
|
||||
* where proc was called on!
|
||||
* When you fail to do this properly you create an almost untraceable DESYNC!
|
||||
* @note The return value of \a proc will be ignored.
|
||||
* @note Use this function when you have the intention that all vehicles
|
||||
* should be iterated over.
|
||||
* @param tile The location on the map
|
||||
* @param data Arbitrary data passed to \a proc.
|
||||
* @param proc The proc that determines whether a vehicle will be "found".
|
||||
*/
|
||||
inline void FindVehicleOnPos(TileIndex tile, VehicleType type, void *data, VehicleFromPosProc *proc)
|
||||
{
|
||||
extern Vehicle *VehicleFromPos(TileIndex tile, VehicleType type, void *data, VehicleFromPosProc *proc, bool find_first);
|
||||
VehicleFromPos(tile, type, data, proc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a vehicle is on a specific location. It will call \a proc for
|
||||
* vehicles until it returns non-nullptr.
|
||||
* @note Use #FindVehicleOnPos when you have the intention that all vehicles
|
||||
* should be iterated over.
|
||||
* @param tile The location on the map
|
||||
* @param data Arbitrary data passed to \a proc.
|
||||
* @param proc The \a proc that determines whether a vehicle will be "found".
|
||||
* @return True if proc returned non-nullptr.
|
||||
*/
|
||||
inline bool HasVehicleOnPos(TileIndex tile, VehicleType type, void *data, VehicleFromPosProc *proc)
|
||||
{
|
||||
extern Vehicle *VehicleFromPos(TileIndex tile, VehicleType type, void *data, VehicleFromPosProc *proc, bool find_first);
|
||||
return VehicleFromPos(tile, type, data, proc, true) != nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a vehicle from a specific location. It will call proc for ALL vehicles
|
||||
* on the tile and YOU must make SURE that the "best one" is stored in the
|
||||
* data value and is ALWAYS the same regardless of the order of the vehicles
|
||||
* where proc was called on!
|
||||
* When you fail to do this properly you create an almost untraceable DESYNC!
|
||||
* @note The return value of proc will be ignored.
|
||||
* @note Use this when you have the intention that all vehicles
|
||||
* should be iterated over.
|
||||
* @param x The X location on the map
|
||||
* @param y The Y location on the map
|
||||
* @param data Arbitrary data passed to proc
|
||||
* @param proc The proc that determines whether a vehicle will be "found".
|
||||
*/
|
||||
inline void FindVehicleOnPosXY(int x, int y, VehicleType type, void *data, VehicleFromPosProc *proc)
|
||||
{
|
||||
extern Vehicle *VehicleFromPosXY(int x, int y, VehicleType type, void *data, VehicleFromPosProc *proc, bool find_first);
|
||||
VehicleFromPosXY(x, y, type, data, proc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a vehicle in on a specific location. It will call proc for
|
||||
* vehicles until it returns non-nullptr.
|
||||
* @note Use FindVehicleOnPosXY when you have the intention that all vehicles
|
||||
* should be iterated over.
|
||||
* @param x The X location on the map
|
||||
* @param y The Y location on the map
|
||||
* @param data Arbitrary data passed to proc
|
||||
* @param proc The proc that determines whether a vehicle will be "found".
|
||||
* @return True if proc returned non-nullptr.
|
||||
*/
|
||||
inline bool HasVehicleOnPosXY(int x, int y, VehicleType type, void *data, VehicleFromPosProc *proc)
|
||||
{
|
||||
extern Vehicle *VehicleFromPosXY(int x, int y, VehicleType type, void *data, VehicleFromPosProc *proc, bool find_first);
|
||||
return VehicleFromPosXY(x, y, type, data, proc, true) != nullptr;
|
||||
}
|
||||
|
||||
void CallVehicleTicks();
|
||||
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
|
||||
uint8 CalcPercentVehicleFilledOfCargo(const Vehicle *v, CargoID cargo);
|
||||
|
||||
Reference in New Issue
Block a user