Files @ r14895:fb237f7e7f5b
Branch filter:

Location: cpp/openttd-patchpack/source/src/vehicle_func.h - annotation

peter1138
(svn r19502) -Codechange: During NewGRF loading, store rail type labels in temporary data and process after loading has finished. This avoids deactivated rail vehicles being reactivated if the climate property is set after the rail type property.
r8144:1432edd15267
r8144:1432edd15267
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r9111:983de9c5a848
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8777:59b04e504aa5
r9126:35955a7b9d9e
r11346:032b1fd8218f
r14248:a9050881acd7
r14767:38eb1d96fb0b
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r9775:4eaf88c92876
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r10083:2e8288935c09
r10083:2e8288935c09
r10083:2e8288935c09
r10083:2e8288935c09
r8144:1432edd15267
r11085:c87a330fb4c2
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r11085:c87a330fb4c2
r8144:1432edd15267
r13952:d0372804e739
r13380:487657d263d3
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r11346:032b1fd8218f
r14697:0b5e0f20b510
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r11321:15f691941b01
r8317:d2bb8edc9b31
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r11090:9276cea703d4
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r10260:88d82a40120c
r8144:1432edd15267
r10260:88d82a40120c
r10260:88d82a40120c
r10260:88d82a40120c
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r10207:a1fc2f2a33db
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r10207:a1fc2f2a33db
r8144:1432edd15267
r10207:a1fc2f2a33db
r8144:1432edd15267
r8144:1432edd15267
r10207:a1fc2f2a33db
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r10207:a1fc2f2a33db
r8144:1432edd15267
r8144:1432edd15267
r10207:a1fc2f2a33db
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r13407:428d181f586b
r13378:d77630912fbb
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r14721:f3e02434b6fb
r14771:1d584d5c1e59
r8144:1432edd15267
r8144:1432edd15267
r8144:1432edd15267
r9344:f9f972b7b45d
r8144:1432edd15267
r8144:1432edd15267
r12624:da84c1a9a664
r8144:1432edd15267
r10650:77ed40e17699
r10650:77ed40e17699
r10650:77ed40e17699
r12107:e2e26c8ef3e7
r12107:e2e26c8ef3e7
r9009:e21a5dd1e60e
/* $Id$ */

/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file vehicle_func.h Functions related to vehicles. */

#ifndef VEHICLE_FUNC_H
#define VEHICLE_FUNC_H

#include "gfx_type.h"
#include "direction_type.h"
#include "command_type.h"
#include "vehicle_type.h"
#include "engine_type.h"
#include "transport_type.h"
#include "newgrf_config.h"
#include "company_type.h"
#include "track_type.h"

#define is_custom_sprite(x) (x >= 0xFD)
#define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
#define IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE)

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);
void CallVehicleTicks();
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);

byte VehicleRandomBits();
void ResetVehiclePosHash();
void ResetVehicleColourMap();

byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for);
CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags);

void ViewportAddVehicles(DrawPixelInfo *dpi);

void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);

void DecreaseVehicleValue(Vehicle *v);
void CheckVehicleBreakdown(Vehicle *v);
void AgeVehicle(Vehicle *v);
void VehicleEnteredDepotThisTick(Vehicle *v);

void VehicleMove(Vehicle *v, bool update_viewport);
void MarkSingleVehicleDirty(const Vehicle *v);

UnitID GetFreeUnitNumber(VehicleType type);

CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id);
void VehicleEnterDepot(Vehicle *v);

bool CanBuildVehicleInfrastructure(VehicleType type);

/** Position information of a vehicle after it moved */
struct GetNewVehiclePosResult {
	int x, y;  ///< x and y position of the vehicle after moving
	TileIndex old_tile; ///< Current tile of the vehicle
	TileIndex new_tile; ///< Tile of the vehicle after moving
};

GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
Direction GetDirectionTowards(const Vehicle *v, int x, int y);

static inline bool IsCompanyBuildableVehicleType(VehicleType type)
{
	switch (type) {
		case VEH_TRAIN:
		case VEH_ROAD:
		case VEH_SHIP:
		case VEH_AIRCRAFT:
			return true;

		default: return false;
	}
}

static inline bool IsCompanyBuildableVehicleType(const BaseVehicle *v)
{
	return IsCompanyBuildableVehicleType(v->type);
}

const struct Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v);

/**
 * Get the colour map for an engine. This used for unbuilt engines in the user interface.
 * @param engine_type ID of engine
 * @param company ID of company
 * @return A ready-to-use palette modifier
 */
SpriteID GetEnginePalette(EngineID engine_type, CompanyID company);

/**
 * Get the colour map for a vehicle.
 * @param v Vehicle to get colour map for
 * @return A ready-to-use palette modifier
 */
SpriteID GetVehiclePalette(const Vehicle *v);

uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity = NULL);

extern const uint32 _veh_build_proc_table[];
extern const uint32 _veh_sell_proc_table[];
extern const uint32 _veh_refit_proc_table[];
extern const uint32 _send_to_depot_proc_table[];

/* Functions to find the right command for certain vehicle type */
static inline uint32 GetCmdBuildVeh(VehicleType type)
{
	return _veh_build_proc_table[type];
}

static inline uint32 GetCmdBuildVeh(const BaseVehicle *v)
{
	return GetCmdBuildVeh(v->type);
}

static inline uint32 GetCmdSellVeh(VehicleType type)
{
	return _veh_sell_proc_table[type];
}

static inline uint32 GetCmdSellVeh(const BaseVehicle *v)
{
	return GetCmdSellVeh(v->type);
}

static inline uint32 GetCmdRefitVeh(VehicleType type)
{
	return _veh_refit_proc_table[type];
}

static inline uint32 GetCmdRefitVeh(const BaseVehicle *v)
{
	return GetCmdRefitVeh(v->type);
}

static inline uint32 GetCmdSendToDepot(VehicleType type)
{
	return _send_to_depot_proc_table[type];
}

static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
{
	return GetCmdSendToDepot(v->type);
}

CommandCost EnsureNoVehicleOnGround(TileIndex tile);
CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
void StopAllVehicles();

extern VehicleID _vehicle_id_ctr_day;
extern const Vehicle *_place_clicked_vehicle;
extern VehicleID _new_vehicle_id;
extern uint16 _returned_refit_capacity;
extern byte _age_cargo_skip_counter;

bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);

void ReleaseDisastersTargetingVehicle(VehicleID vehicle);

#endif /* VEHICLE_FUNC_H */