mirror of https://github.com/OpenTTD/OpenTTD
(svn r20532) -Codechange: unify selling of vehicles a bit
parent
c14853b72e
commit
4780cc50b2
|
@ -148,7 +148,7 @@
|
|||
const Train *v = ::Train::Get(vehicle_id);
|
||||
while (wagon-- > 0) v = v->GetNextUnit();
|
||||
|
||||
return AIObject::DoCommand(0, v->index, sell_attached_wagons ? 1 : 0, CMD_SELL_RAIL_WAGON);
|
||||
return AIObject::DoCommand(0, v->index, sell_attached_wagons ? 1 : 0, CMD_SELL_VEHICLE);
|
||||
}
|
||||
|
||||
/* static */ bool AIVehicle::SellWagon(VehicleID vehicle_id, int wagon)
|
||||
|
|
|
@ -338,36 +338,6 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sell an aircraft.
|
||||
* @param tile unused
|
||||
* @param flags for command type
|
||||
* @param p1 vehicle ID to be sold
|
||||
* @param p2 unused
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdSellAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
Aircraft *v = Aircraft::GetIfValid(p1);
|
||||
if (v == NULL) return CMD_ERROR;
|
||||
|
||||
CommandCost ret = CheckOwnership(v->owner);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_AIRCRAFT_MUST_BE_STOPPED);
|
||||
|
||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
||||
|
||||
ret = CommandCost(EXPENSES_NEW_VEHICLES, -v->value);
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
delete v;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
|
||||
{
|
||||
const Station *st = GetTargetAirportIfValid(this);
|
||||
|
|
|
@ -80,7 +80,7 @@ CommandProc CmdPlantTree;
|
|||
CommandProc CmdMoveRailVehicle;
|
||||
|
||||
CommandProc CmdBuildVehicle;
|
||||
CommandProc CmdSellRailWagon;
|
||||
CommandProc CmdSellVehicle;
|
||||
|
||||
CommandProc CmdSendTrainToDepot;
|
||||
CommandProc CmdForceTrainProceed;
|
||||
|
@ -112,14 +112,12 @@ CommandProc CmdRenamePresident;
|
|||
CommandProc CmdRenameStation;
|
||||
CommandProc CmdRenameDepot;
|
||||
|
||||
CommandProc CmdSellAircraft;
|
||||
CommandProc CmdSendAircraftToHangar;
|
||||
CommandProc CmdRefitAircraft;
|
||||
|
||||
CommandProc CmdPlaceSign;
|
||||
CommandProc CmdRenameSign;
|
||||
|
||||
CommandProc CmdSellRoadVeh;
|
||||
CommandProc CmdSendRoadVehToDepot;
|
||||
CommandProc CmdTurnRoadVeh;
|
||||
CommandProc CmdRefitRoadVeh;
|
||||
|
@ -139,7 +137,6 @@ CommandProc CmdDeleteTown;
|
|||
CommandProc CmdChangeSetting;
|
||||
CommandProc CmdChangeCompanySetting;
|
||||
|
||||
CommandProc CmdSellShip;
|
||||
CommandProc CmdSendShipToDepot;
|
||||
CommandProc CmdRefitShip;
|
||||
|
||||
|
@ -227,9 +224,9 @@ static const Command _command_proc_table[] = {
|
|||
DEF_CMD(CmdBuildBuoy, CMD_AUTO), // CMD_BUILD_BUOY
|
||||
DEF_CMD(CmdPlantTree, CMD_AUTO), // CMD_PLANT_TREE
|
||||
DEF_CMD(CmdBuildVehicle, 0), // CMD_BUILD_VEHICLE
|
||||
DEF_CMD(CmdMoveRailVehicle, 0), // CMD_MOVE_RAIL_VEHICLE
|
||||
DEF_CMD(CmdSellVehicle, 0), // CMD_SELL_VEHICLE
|
||||
|
||||
DEF_CMD(CmdSellRailWagon, 0), // CMD_SELL_RAIL_WAGON
|
||||
DEF_CMD(CmdMoveRailVehicle, 0), // CMD_MOVE_RAIL_VEHICLE
|
||||
DEF_CMD(CmdSendTrainToDepot, 0), // CMD_SEND_TRAIN_TO_DEPOT
|
||||
DEF_CMD(CmdForceTrainProceed, 0), // CMD_FORCE_TRAIN_PROCEED
|
||||
DEF_CMD(CmdReverseTrainDirection, 0), // CMD_REVERSE_TRAIN_DIRECTION
|
||||
|
@ -259,15 +256,12 @@ static const Command _command_proc_table[] = {
|
|||
DEF_CMD(CmdRenameStation, 0), // CMD_RENAME_STATION
|
||||
DEF_CMD(CmdRenameDepot, 0), // CMD_RENAME_DEPOT
|
||||
|
||||
DEF_CMD(CmdSellAircraft, 0), // CMD_SELL_AIRCRAFT
|
||||
|
||||
DEF_CMD(CmdSendAircraftToHangar, 0), // CMD_SEND_AIRCRAFT_TO_HANGAR
|
||||
DEF_CMD(CmdRefitAircraft, 0), // CMD_REFIT_AIRCRAFT
|
||||
|
||||
DEF_CMD(CmdPlaceSign, 0), // CMD_PLACE_SIGN
|
||||
DEF_CMD(CmdRenameSign, 0), // CMD_RENAME_SIGN
|
||||
|
||||
DEF_CMD(CmdSellRoadVeh, 0), // CMD_SELL_ROAD_VEH
|
||||
DEF_CMD(CmdSendRoadVehToDepot, 0), // CMD_SEND_ROADVEH_TO_DEPOT
|
||||
DEF_CMD(CmdTurnRoadVeh, 0), // CMD_TURN_ROADVEH
|
||||
DEF_CMD(CmdRefitRoadVeh, 0), // CMD_REFIT_ROAD_VEH
|
||||
|
@ -284,7 +278,6 @@ static const Command _command_proc_table[] = {
|
|||
DEF_CMD(CmdExpandTown, CMD_OFFLINE), // CMD_EXPAND_TOWN
|
||||
DEF_CMD(CmdDeleteTown, CMD_OFFLINE), // CMD_DELETE_TOWN
|
||||
|
||||
DEF_CMD(CmdSellShip, 0), // CMD_SELL_SHIP
|
||||
DEF_CMD(CmdSendShipToDepot, 0), // CMD_SEND_SHIP_TO_DEPOT
|
||||
DEF_CMD(CmdRefitShip, 0), // CMD_REFIT_SHIP
|
||||
|
||||
|
|
|
@ -178,10 +178,9 @@ enum Commands {
|
|||
CMD_PLANT_TREE, ///< plant a tree
|
||||
|
||||
CMD_BUILD_VEHICLE, ///< build a vehicle
|
||||
CMD_SELL_VEHICLE, ///< sell a vehicle
|
||||
|
||||
CMD_MOVE_RAIL_VEHICLE, ///< move a rail vehicle (in the depot)
|
||||
|
||||
CMD_SELL_RAIL_WAGON, ///< sell a rail wagon
|
||||
|
||||
CMD_SEND_TRAIN_TO_DEPOT, ///< send a train to a depot
|
||||
CMD_FORCE_TRAIN_PROCEED, ///< proceed a train to pass a red signal
|
||||
CMD_REVERSE_TRAIN_DIRECTION, ///< turn a train around
|
||||
|
@ -210,14 +209,12 @@ enum Commands {
|
|||
CMD_RENAME_STATION, ///< rename a station
|
||||
CMD_RENAME_DEPOT, ///< rename a depot
|
||||
|
||||
CMD_SELL_AIRCRAFT, ///< sell an aircraft
|
||||
CMD_SEND_AIRCRAFT_TO_HANGAR, ///< send an aircraft to a hanger
|
||||
CMD_REFIT_AIRCRAFT, ///< refit the cargo space of an aircraft
|
||||
|
||||
CMD_PLACE_SIGN, ///< place a sign
|
||||
CMD_RENAME_SIGN, ///< rename a sign
|
||||
|
||||
CMD_SELL_ROAD_VEH, ///< sell a road vehicle
|
||||
CMD_SEND_ROADVEH_TO_DEPOT, ///< send a road vehicle to the depot
|
||||
CMD_TURN_ROADVEH, ///< turn a road vehicle around
|
||||
CMD_REFIT_ROAD_VEH, ///< refit the cargo space of a road vehicle
|
||||
|
@ -234,7 +231,6 @@ enum Commands {
|
|||
CMD_EXPAND_TOWN, ///< expand a town
|
||||
CMD_DELETE_TOWN, ///< delete a town
|
||||
|
||||
CMD_SELL_SHIP, ///< sell a ship
|
||||
CMD_SEND_SHIP_TO_DEPOT, ///< send a ship to a depot
|
||||
CMD_REFIT_SHIP, ///< refit the cargo space of a ship
|
||||
|
||||
|
|
|
@ -294,38 +294,6 @@ bool RoadVehicle::IsStoppedInDepot() const
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sell a road vehicle.
|
||||
* @param tile unused
|
||||
* @param flags operation to perform
|
||||
* @param p1 vehicle ID to be sold
|
||||
* @param p2 unused
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
|
||||
if (v == NULL) return CMD_ERROR;
|
||||
|
||||
CommandCost ret = CheckOwnership(v->owner);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
||||
|
||||
if (!v->IsStoppedInDepot()) {
|
||||
return_cmd_error(STR_ERROR_ROAD_VEHICLE_MUST_BE_STOPPED_INSIDE_DEPOT);
|
||||
}
|
||||
|
||||
ret = CommandCost(EXPENSES_NEW_VEHICLES, -v->value);
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
delete v;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FindDepotData FindClosestRoadDepot(const RoadVehicle *v, int max_distance)
|
||||
{
|
||||
if (IsRoadDepotTile(v->tile)) return FindDepotData(v->tile, 0);
|
||||
|
|
|
@ -668,38 +668,6 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, u
|
|||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sell a ship.
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 vehicle ID to be sold
|
||||
* @param p2 unused
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
Ship *v = Ship::GetIfValid(p1);
|
||||
if (v == NULL) return CMD_ERROR;
|
||||
|
||||
CommandCost ret = CheckOwnership(v->owner);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
||||
|
||||
if (!v->IsStoppedInDepot()) {
|
||||
return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
|
||||
}
|
||||
|
||||
ret = CommandCost(EXPENSES_NEW_VEHICLES, -v->value);
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
delete v;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
|
||||
{
|
||||
const Depot *depot = FindClosestShipDepot(this, 0);
|
||||
|
|
|
@ -1319,40 +1319,25 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||
|
||||
/**
|
||||
* Sell a (single) train wagon/engine.
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 the wagon/engine index
|
||||
* @param p2 the selling mode
|
||||
* - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
|
||||
* - p2 = 1: sell the vehicle and all vehicles following it in the chain
|
||||
* @param t the train wagon to sell
|
||||
* @param data the selling mode
|
||||
* - data = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
|
||||
* - data = 1: sell the vehicle and all vehicles following it in the chain
|
||||
* if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, uint16 data)
|
||||
{
|
||||
/* Check if we deleted a vehicle window */
|
||||
Window *w = NULL;
|
||||
|
||||
Train *v = Train::GetIfValid(p1);
|
||||
if (v == NULL) return CMD_ERROR;
|
||||
|
||||
CommandCost ret = CheckOwnership(v->owner);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
/* Sell a chain of vehicles or not? */
|
||||
bool sell_chain = HasBit(p2, 0);
|
||||
bool sell_chain = HasBit(data, 0);
|
||||
|
||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
||||
|
||||
v = v->GetFirstEnginePart();
|
||||
Train *v = Train::From(t)->GetFirstEnginePart();
|
||||
Train *first = v->First();
|
||||
|
||||
/* make sure the vehicle is stopped in the depot */
|
||||
if (!first->IsStoppedInDepot()) {
|
||||
return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT);
|
||||
}
|
||||
|
||||
if (v->IsRearDualheaded()) return_cmd_error(STR_ERROR_REAR_ENGINE_FOLLOW_FRONT);
|
||||
|
||||
/* First make a backup of the order of the train. That way we can do
|
||||
|
@ -1368,7 +1353,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||
ArrangeTrains(&sell_head, NULL, &new_head, v, sell_chain);
|
||||
|
||||
/* We don't need to validate the second train; it's going to be sold. */
|
||||
ret = ValidateTrains(NULL, NULL, first, new_head);
|
||||
CommandCost ret = ValidateTrains(NULL, NULL, first, new_head);
|
||||
if (ret.Failed()) {
|
||||
/* Restore the train we had. */
|
||||
RestoreTrainBackup(original);
|
||||
|
|
|
@ -44,10 +44,10 @@ const uint32 _veh_build_proc_table[] = {
|
|||
};
|
||||
|
||||
const uint32 _veh_sell_proc_table[] = {
|
||||
CMD_SELL_RAIL_WAGON | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN),
|
||||
CMD_SELL_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_SELL_ROAD_VEHICLE),
|
||||
CMD_SELL_SHIP | CMD_MSG(STR_ERROR_CAN_T_SELL_SHIP),
|
||||
CMD_SELL_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_SELL_AIRCRAFT),
|
||||
CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN),
|
||||
CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_ROAD_VEHICLE),
|
||||
CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_SHIP),
|
||||
CMD_SELL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_SELL_AIRCRAFT),
|
||||
};
|
||||
|
||||
const uint32 _veh_refit_proc_table[] = {
|
||||
|
@ -149,6 +149,44 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|||
return value;
|
||||
}
|
||||
|
||||
CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *v, uint16 data);
|
||||
|
||||
/**
|
||||
* Sell a vehicle.
|
||||
* @param tile unused.
|
||||
* @param flags for command.
|
||||
* @param p1 vehicle ID to be sold.
|
||||
* @param p2 unused.
|
||||
* @param text unused.
|
||||
* @return the cost of this operation or an error.
|
||||
*/
|
||||
CommandCost CmdSellVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 16));
|
||||
if (v == NULL) return CMD_ERROR;
|
||||
|
||||
Vehicle *front = v->First();
|
||||
|
||||
CommandCost ret = CheckOwnership(front->owner);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
||||
|
||||
if (!front->IsStoppedInDepot()) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED + front->type);
|
||||
|
||||
if (v->type == VEH_TRAIN) {
|
||||
ret = CmdSellRailWagon(flags, v, GB(p2, 0, 16));
|
||||
} else {
|
||||
ret = CommandCost(EXPENSES_NEW_VEHICLES, -front->value);
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
delete front;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start/Stop a vehicle
|
||||
* @param tile unused
|
||||
|
|
Loading…
Reference in New Issue