|
|
@ -607,18 +607,20 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 fla
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine);
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine);
|
|
|
|
CommandCost value(EXPENSES_NEW_VEHICLES, GetEngine(engine)->GetCost());
|
|
|
|
CommandCost value(EXPENSES_NEW_VEHICLES, GetEngine(engine)->GetCost());
|
|
|
|
|
|
|
|
|
|
|
|
uint num_vehicles = 1 + CountArticulatedParts(engine, false);
|
|
|
|
if (flags & DC_QUERY_COST) return value;
|
|
|
|
|
|
|
|
|
|
|
|
if (!(flags & DC_QUERY_COST)) {
|
|
|
|
|
|
|
|
/* Check that the wagon can drive on the track in question */
|
|
|
|
/* Check that the wagon can drive on the track in question */
|
|
|
|
if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
|
|
|
|
if (!IsCompatibleRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint num_vehicles = 1 + CountArticulatedParts(engine, false);
|
|
|
|
|
|
|
|
|
|
|
|
/* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */
|
|
|
|
/* Allow for the wagon and the articulated parts, plus one to "terminate" the list. */
|
|
|
|
Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1);
|
|
|
|
Vehicle **vl = AllocaM(Vehicle*, num_vehicles + 1);
|
|
|
|
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
|
|
|
memset(vl, 0, sizeof(*vl) * (num_vehicles + 1));
|
|
|
|
|
|
|
|
|
|
|
|
if (!Vehicle::AllocateList(vl, num_vehicles))
|
|
|
|
if (!Vehicle::AllocateList(vl, num_vehicles)) {
|
|
|
|
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
|
|
|
|
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
Vehicle *v = vl[0];
|
|
|
|
Vehicle *v = vl[0];
|
|
|
@ -692,7 +694,6 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 fla
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GetCompany(_current_company)->num_engines[engine]++;
|
|
|
|
GetCompany(_current_company)->num_engines[engine]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -752,25 +753,23 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|
|
|
/* 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_RAIL_VEHICLE_NOT_AVAILABLE);
|
|
|
|
if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Engine *e = GetEngine(p1);
|
|
|
|
|
|
|
|
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (flags & DC_QUERY_COST) return value;
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if the train is actually being built in a depot belonging
|
|
|
|
/* Check if the train is actually being built in a depot belonging
|
|
|
|
* to the company. Doesn't matter if only the cost is queried */
|
|
|
|
* to the company. Doesn't matter if only the cost is queried */
|
|
|
|
if (!(flags & DC_QUERY_COST)) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(p1);
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(p1);
|
|
|
|
|
|
|
|
|
|
|
|
if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags);
|
|
|
|
if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags);
|
|
|
|
|
|
|
|
|
|
|
|
const Engine *e = GetEngine(p1);
|
|
|
|
|
|
|
|
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint num_vehicles =
|
|
|
|
uint num_vehicles =
|
|
|
|
(rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) +
|
|
|
|
(rvi->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) +
|
|
|
|
CountArticulatedParts(p1, false);
|
|
|
|
CountArticulatedParts(p1, false);
|
|
|
|
|
|
|
|
|
|
|
|
if (!(flags & DC_QUERY_COST)) {
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
|
|
|
|
if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR;
|
|
|
@ -786,8 +785,9 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|
|
|
Vehicle *v = vl[0];
|
|
|
|
Vehicle *v = vl[0];
|
|
|
|
|
|
|
|
|
|
|
|
UnitID unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_TRAIN);
|
|
|
|
UnitID unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_TRAIN);
|
|
|
|
if (unit_num > _settings_game.vehicle.max_trains)
|
|
|
|
if (unit_num > _settings_game.vehicle.max_trains) {
|
|
|
|
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
|
|
|
|
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
DiagDirection dir = GetRailDepotDirection(tile);
|
|
|
|
DiagDirection dir = GetRailDepotDirection(tile);
|
|
|
@ -870,7 +870,6 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|
|
|
|
|
|
|
|
|
|
|
GetCompany(_current_company)->num_engines[p1]++;
|
|
|
|
GetCompany(_current_company)->num_engines[p1]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|