Changeset - r5215:5975e06c9f82
[Not reviewed]
master
0 8 0
peter1138 - 18 years ago 2006-12-03 15:48:21
peter1138@openttd.org
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
player, resulting in an empty vehicle purchase list. Specify the player
as an argument to IsEngineBuildable()
8 files changed with 11 insertions and 10 deletions:
0 comments (0 inline, 0 general)
aircraft_cmd.c
Show inline comments
 
@@ -204,13 +204,13 @@ int32 CmdBuildAircraft(TileIndex tile, u
 
	Vehicle *vl[3], *v, *u, *w;
 
	UnitID unit_num;
 
	const AircraftVehicleInfo *avi;
 
	const AirportFTAClass* ap;
 
	Engine *e;
 

	
 
	if (!IsEngineBuildable(p1, VEH_Aircraft)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE);
 
	if (!IsEngineBuildable(p1, VEH_Aircraft, _current_player)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE);
 

	
 
	value = EstimateAircraftCost(p1);
 

	
 
	// to just query the cost, it is not neccessary to have a valid tile (automation/AI)
 
	if (flags & DC_QUERY_COST) return value;
 

	
build_vehicle_gui.c
Show inline comments
 
@@ -287,13 +287,13 @@ static void GenerateBuildAircraftList(Wi
 
	/* Make list of all available planes.
 
	 * Also check to see if the previously selected plane is still available,
 
	 * and if not, reset selection to INVALID_ENGINE. This could be the case
 
	 * when planes become obsolete and are removed */
 
	sel_id = INVALID_ENGINE;
 
	for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) {
 
		if (IsEngineBuildable(eid, VEH_Aircraft)) {
 
		if (IsEngineBuildable(eid, VEH_Aircraft, _local_player)) {
 
			const AircraftVehicleInfo *avi = AircraftVehInfo(eid);
 
			switch (bv->filter.acc_planes) {
 
				case HELICOPTERS_ONLY:
 
					if (avi->subtype != 0) continue; // if not helicopter
 
					break;
 

	
engine.c
Show inline comments
 
@@ -398,31 +398,32 @@ int32 CmdRenameEngine(TileIndex tile, ui
 
	return 0;
 
}
 

	
 

	
 
/*
 
 * returns true if an engine is valid, of the specified type, and buildable by
 
 * the current player, false otherwise
 
 * the given player, false otherwise
 
 *
 
 * engine = index of the engine to check
 
 * type   = the type the engine should be of (VEH_xxx)
 
 * player = index of the player
 
 */
 
bool IsEngineBuildable(uint engine, byte type)
 
bool IsEngineBuildable(EngineID engine, byte type, PlayerID player)
 
{
 
	const Engine *e;
 

	
 
	// check if it's an engine that is in the engine array
 
	if (!IsEngineIndex(engine)) return false;
 

	
 
	e = GetEngine(engine);
 

	
 
	// check if it's an engine of specified type
 
	if (e->type != type) return false;
 

	
 
	// check if it's available
 
	if (!HASBIT(e->player_avail, _current_player)) return false;
 
	if (!HASBIT(e->player_avail, player)) return false;
 

	
 
	return true;
 
}
 

	
 
/************************************************************************
 
 * Engine Replacement stuff
engine.h
Show inline comments
 
@@ -134,13 +134,13 @@ void DrawRoadVehEngine(int x, int y, Eng
 
void DrawShipEngine(int x, int y, EngineID engine, uint32 image_ormod);
 
void DrawAircraftEngine(int x, int y, EngineID engine, uint32 image_ormod);
 

	
 
void LoadCustomEngineNames(void);
 
void DeleteCustomEngineNames(void);
 

	
 
bool IsEngineBuildable(uint engine, byte type);
 
bool IsEngineBuildable(EngineID engine, byte type, PlayerID player);
 

	
 
enum {
 
	NUM_NORMAL_RAIL_ENGINES = 54,
 
	NUM_MONORAIL_ENGINES    = 30,
 
	NUM_MAGLEV_ENGINES      = 32,
 
	NUM_TRAIN_ENGINES       = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES,
roadveh_cmd.c
Show inline comments
 
@@ -111,13 +111,13 @@ int32 CmdBuildRoadVeh(TileIndex tile, ui
 
{
 
	int32 cost;
 
	Vehicle *v;
 
	UnitID unit_num;
 
	Engine *e;
 

	
 
	if (!IsEngineBuildable(p1, VEH_Road)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE);
 
	if (!IsEngineBuildable(p1, VEH_Road, _current_player)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 

	
 
	cost = EstimateRoadVehCost(p1);
 
	if (flags & DC_QUERY_COST) return cost;
 

	
ship_cmd.c
Show inline comments
 
@@ -811,13 +811,13 @@ int32 CmdBuildShip(TileIndex tile, uint3
 
{
 
	int32 value;
 
	Vehicle *v;
 
	UnitID unit_num;
 
	Engine *e;
 

	
 
	if (!IsEngineBuildable(p1, VEH_Ship)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE);
 
	if (!IsEngineBuildable(p1, VEH_Ship, _current_player)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 

	
 
	value = EstimateShipCost(p1);
 
	if (flags & DC_QUERY_COST) return value;
 

	
train_cmd.c
Show inline comments
 
@@ -740,13 +740,13 @@ int32 CmdBuildRailVehicle(TileIndex tile
 
	Vehicle *v;
 
	UnitID unit_num;
 
	Engine *e;
 
	uint num_vehicles;
 

	
 
	/* Check if the engine-type is valid (for the player) */
 
	if (!IsEngineBuildable(p1, VEH_Train)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE);
 
	if (!IsEngineBuildable(p1, VEH_Train, _current_player)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE);
 

	
 
	/* Check if the train is actually being built in a depot belonging
 
	 * to the player. Doesn't matter if only the cost is queried */
 
	if (!(flags & DC_QUERY_COST)) {
 
		if (!IsTileDepotType(tile, TRANSPORT_RAIL)) return CMD_ERROR;
 
		if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
train_gui.c
Show inline comments
 
@@ -390,13 +390,13 @@ static void GenerateBuildList(Window *w)
 
	 * when engines become obsolete and are removed */
 
	for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) {
 
		const Engine *e = GetEngine(eid);
 
		const RailVehicleInfo *rvi = RailVehInfo(eid);
 

	
 
		if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(e->railtype, bv->filter.railtype)) continue;
 
		if (!IsEngineBuildable(eid, VEH_Train)) continue;
 
		if (!IsEngineBuildable(eid, VEH_Train, _local_player)) continue;
 

	
 
		EngList_Add(&bv->eng_list, eid);
 
		if ((rvi->flags & RVI_WAGON) == 0) {
 
			num_engines++;
 
		} else {
 
			num_wagons++;
0 comments (0 inline, 0 general)