(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.

This commit is contained in:
alberth
2010-03-13 17:11:28 +00:00
parent 19afc9fdc0
commit 7cc68f493d
15 changed files with 268 additions and 80 deletions

View File

@@ -331,7 +331,11 @@ bool RoadVehicle::IsStoppedInDepot() const
CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (v == NULL) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret;
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_SELL_DESTROYED_VEHICLE);
@@ -339,7 +343,7 @@ CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
return_cmd_error(STR_ERROR_ROAD_VEHICLE_MUST_BE_STOPPED_INSIDE_DEPOT);
}
CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
ret = CommandCost(EXPENSES_NEW_VEHICLES, -v->value);
if (flags & DC_EXEC) {
delete v;
@@ -406,7 +410,11 @@ CommandCost CmdSendRoadVehToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1
CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (v == NULL) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret;
if ((v->vehstatus & VS_STOPPED) ||
(v->vehstatus & VS_CRASHED) ||
@@ -1748,8 +1756,12 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
bool only_this = HasBit(p2, 16);
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
if (v == NULL) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret;
if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_ROAD_VEHICLE_MUST_BE_STOPPED_INSIDE_DEPOT);
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);