Use a single action for build & refit, to make it MP safe.

Pass the cargo ID through the text field (in binary mode).
This commit is contained in:
Jonathan G Rennison
2015-09-12 23:35:32 +01:00
parent 40b7d6d335
commit 2f077f0c42
2 changed files with 26 additions and 5 deletions

View File

@@ -1327,10 +1327,15 @@ struct BuildVehicleWindow : Window {
EngineID sel_eng = this->sel_engine; EngineID sel_eng = this->sel_engine;
if (sel_eng != INVALID_ENGINE) { if (sel_eng != INVALID_ENGINE) {
CommandCallback *callback = (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildPrimaryVehicle; CommandCallback *callback = (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) ? CcBuildWagon : CcBuildPrimaryVehicle;
if (DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback) && if (!this->IsWidgetDisabled(WID_BV_BUILD_REFIT) && this->build_and_refit) {
!this->IsWidgetDisabled(WID_BV_BUILD_REFIT) && this->build_and_refit) { /* build and refit */
// refit to selected cargo filter char text_buffer[2];
DoCommandP(this->window_number, _new_vehicle_id, this->cargo_filter[this->cargo_filter_criteria], GetCmdRefitVeh(this->vehicle_type)); text_buffer[0] = 'R';
text_buffer[1] = this->cargo_filter[this->cargo_filter_criteria];
DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback, text_buffer, true, 2);
} else {
/* build only */
DoCommandP(this->window_number, sel_eng, 0, GetCmdBuildVeh(this->vehicle_type), callback);
} }
} }
break; break;

View File

@@ -71,6 +71,8 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engin
CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v); CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
CommandCost CmdBuildShip (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v); CommandCost CmdBuildShip (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
CommandCost CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v); CommandCost CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **v);
CommandCost CmdRefitVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
static CommandCost GetRefitCost(const Vehicle *v, EngineID engine_type, CargoID new_cid, byte new_subtype, bool *auto_refit_allowed);
/** /**
* Build a vehicle. * Build a vehicle.
@@ -80,7 +82,7 @@ CommandCost CmdBuildAircraft (TileIndex tile, DoCommandFlag flags, const Engin
* bits 0-15: vehicle type being built. * bits 0-15: vehicle type being built.
* bits 16-31: vehicle type specific bits passed on to the vehicle build functions. * bits 16-31: vehicle type specific bits passed on to the vehicle build functions.
* @param p2 User * @param p2 User
* @param text unused * @param text used for combined build and refit command
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
@@ -147,6 +149,20 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
} }
} }
if (value.Succeeded() && text && text[0] == 'R') {
CargoID cargo = text[1];
if (cargo >= NUM_CARGO) return CMD_ERROR;
CargoID default_cargo = e->GetDefaultCargoType();
if (default_cargo != cargo) {
if (flags & DC_EXEC) {
value.AddCost(CmdRefitVehicle(tile, flags, v->index, cargo, NULL));
} else {
bool auto_refit_allowed = false;
value.AddCost(GetRefitCost(NULL, eid, cargo, 0, &auto_refit_allowed));
}
}
}
return value; return value;
} }