1
0
Fork 0

(svn r19621) -Codechange: Remove direct usage of magic 'p1's in build vehicle commands.

release/1.1
frosch 2010-04-13 19:10:08 +00:00
parent 088282bcf8
commit 1f28e232c3
4 changed files with 26 additions and 22 deletions

View File

@ -236,9 +236,10 @@ void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height)
*/ */
CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_company)) return_cmd_error(STR_ERROR_AIRCRAFT_NOT_AVAILABLE); EngineID eid = GB(p1, 0, 16);
if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _current_company)) return_cmd_error(STR_ERROR_AIRCRAFT_NOT_AVAILABLE);
const Engine *e = Engine::Get(p1); const Engine *e = Engine::Get(eid);
const AircraftVehicleInfo *avi = &e->u.air; const AircraftVehicleInfo *avi = &e->u.air;
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost()); CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
@ -251,7 +252,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR; if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
/* Prevent building aircraft types at places which can't handle them */ /* Prevent building aircraft types at places which can't handle them */
if (!CanVehicleUseStation(p1, Station::GetByTile(tile))) return CMD_ERROR; if (!CanVehicleUseStation(eid, Station::GetByTile(tile))) return CMD_ERROR;
/* We will need to allocate 2 or 3 vehicle structs, depending on type */ /* We will need to allocate 2 or 3 vehicle structs, depending on type */
if (!Vehicle::CanAllocateItem(avi->subtype & AIR_CTOL ? 2 : 3)) { if (!Vehicle::CanAllocateItem(avi->subtype & AIR_CTOL ? 2 : 3)) {
@ -298,8 +299,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
v->max_speed = avi->max_speed; v->max_speed = avi->max_speed;
v->acceleration = avi->acceleration; v->acceleration = avi->acceleration;
v->engine_type = p1; v->engine_type = eid;
u->engine_type = p1; u->engine_type = eid;
v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER); v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER);
v->UpdateDeltaXY(INVALID_DIR); v->UpdateDeltaXY(INVALID_DIR);
@ -348,7 +349,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Aircraft with 3 vehicles (chopper)? */ /* Aircraft with 3 vehicles (chopper)? */
if (v->subtype == AIR_HELICOPTER) { if (v->subtype == AIR_HELICOPTER) {
Aircraft *w = new Aircraft(); Aircraft *w = new Aircraft();
w->engine_type = p1; w->engine_type = eid;
w->direction = DIR_N; w->direction = DIR_N;
w->owner = _current_company; w->owner = _current_company;
w->x_pos = v->x_pos; w->x_pos = v->x_pos;
@ -373,7 +374,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (IsLocalCompany()) if (IsLocalCompany())
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Aircraft window InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Aircraft window
Company::Get(_current_company)->num_engines[p1]++; Company::Get(_current_company)->num_engines[eid]++;
} }
return value; return value;

View File

@ -200,9 +200,10 @@ void RoadVehUpdateCache(RoadVehicle *v)
*/ */
CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
if (!IsEngineBuildable(p1, VEH_ROAD, _current_company)) return_cmd_error(STR_ERROR_ROAD_VEHICLE_NOT_AVAILABLE); EngineID eid = GB(p1, 0, 16);
if (!IsEngineBuildable(eid, VEH_ROAD, _current_company)) return_cmd_error(STR_ERROR_ROAD_VEHICLE_NOT_AVAILABLE);
const Engine *e = Engine::Get(p1); const Engine *e = Engine::Get(eid);
/* Engines without valid cargo should not be available */ /* Engines without valid cargo should not be available */
if (e->GetDefaultCargoType() == CT_INVALID) return CMD_ERROR; if (e->GetDefaultCargoType() == CT_INVALID) return CMD_ERROR;
@ -216,7 +217,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (HasTileRoadType(tile, ROADTYPE_TRAM) != HasBit(e->info.misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_ERROR_DEPOT_WRONG_DEPOT_TYPE); if (HasTileRoadType(tile, ROADTYPE_TRAM) != HasBit(e->info.misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_ERROR_DEPOT_WRONG_DEPOT_TYPE);
uint num_vehicles = 1 + CountArticulatedParts(p1, false); uint num_vehicles = 1 + CountArticulatedParts(eid, false);
/* Allow for the front and the articulated parts */ /* Allow for the front and the articulated parts */
if (!Vehicle::CanAllocateItem(num_vehicles)) { if (!Vehicle::CanAllocateItem(num_vehicles)) {
@ -254,7 +255,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
v->last_station_visited = INVALID_STATION; v->last_station_visited = INVALID_STATION;
v->max_speed = rvi->max_speed; v->max_speed = rvi->max_speed;
v->engine_type = (EngineID)p1; v->engine_type = eid;
v->rcache.first_engine = INVALID_ENGINE; // needs to be set before first callback v->rcache.first_engine = INVALID_ENGINE; // needs to be set before first callback
v->reliability = e->reliability; v->reliability = e->reliability;
@ -299,7 +300,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Road window InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Road window
} }
Company::Get(_current_company)->num_engines[p1]++; Company::Get(_current_company)->num_engines[eid]++;
CheckConsistencyOfArticulatedVehicle(v); CheckConsistencyOfArticulatedVehicle(v);
} }

View File

@ -611,11 +611,12 @@ bool Ship::Tick()
*/ */
CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
EngineID eid = GB(p1, 0, 16);
UnitID unit_num; UnitID unit_num;
if (!IsEngineBuildable(p1, VEH_SHIP, _current_company)) return_cmd_error(STR_ERROR_SHIP_NOT_AVAILABLE); if (!IsEngineBuildable(eid, VEH_SHIP, _current_company)) return_cmd_error(STR_ERROR_SHIP_NOT_AVAILABLE);
const Engine *e = Engine::Get(p1); const Engine *e = Engine::Get(eid);
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost()); CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
/* Engines without valid cargo should not be available */ /* Engines without valid cargo should not be available */
@ -660,7 +661,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
v->last_station_visited = INVALID_STATION; v->last_station_visited = INVALID_STATION;
v->max_speed = svi->max_speed; v->max_speed = svi->max_speed;
v->engine_type = p1; v->engine_type = eid;
v->reliability = e->reliability; v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec; v->reliability_spd_dec = e->reliability_spd_dec;
@ -692,7 +693,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Ship window InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Ship window
} }
Company::Get(_current_company)->num_engines[p1]++; Company::Get(_current_company)->num_engines[eid]++;
} }
return value; return value;

View File

@ -688,10 +688,11 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
*/ */
CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
EngineID eid = GB(p1, 0, 16);
/* Check if the engine-type is valid (for the company) */ /* Check if the engine-type is valid (for the company) */
if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE); if (!IsEngineBuildable(eid, VEH_TRAIN, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE);
const Engine *e = Engine::Get(p1); const Engine *e = Engine::Get(eid);
const RailVehicleInfo *rvi = &e->u.rail; const RailVehicleInfo *rvi = &e->u.rail;
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost()); CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
@ -705,11 +706,11 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (!IsRailDepotTile(tile)) return CMD_ERROR; if (!IsRailDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_company)) return CMD_ERROR; if (!IsTileOwner(tile, _current_company)) return CMD_ERROR;
if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags); if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(eid, tile, flags);
uint num_vehicles = uint num_vehicles =
(rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + (rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) +
CountArticulatedParts(p1, false); CountArticulatedParts(eid, false);
/* Check if depot and new engine uses the same kind of tracks * /* Check if depot and new engine uses the same kind of tracks *
* We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */ * We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */
@ -747,7 +748,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
v->value = value.GetCost(); v->value = value.GetCost();
v->last_station_visited = INVALID_STATION; v->last_station_visited = INVALID_STATION;
v->engine_type = p1; v->engine_type = eid;
v->tcache.first_engine = INVALID_ENGINE; // needs to be set before first callback v->tcache.first_engine = INVALID_ENGINE; // needs to be set before first callback
v->reliability = e->reliability; v->reliability = e->reliability;
@ -792,7 +793,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window
} }
Company::Get(_current_company)->num_engines[p1]++; Company::Get(_current_company)->num_engines[eid]++;
CheckConsistencyOfArticulatedVehicle(v); CheckConsistencyOfArticulatedVehicle(v);
} }