mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-04 05:15:21 +00:00
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
This commit is contained in:
parent
19afc9fdc0
commit
7cc68f493d
@ -405,13 +405,17 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||||||
CommandCost CmdSellAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdSellAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Aircraft *v = Aircraft::GetIfValid(p1);
|
Aircraft *v = Aircraft::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_AIRCRAFT_MUST_BE_STOPPED);
|
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_AIRCRAFT_MUST_BE_STOPPED);
|
||||||
|
|
||||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_SELL_DESTROYED_VEHICLE);
|
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_SELL_DESTROYED_VEHICLE);
|
||||||
|
|
||||||
CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
|
ret = CommandCost(EXPENSES_NEW_VEHICLES, -v->value);
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
delete v;
|
delete v;
|
||||||
@ -480,7 +484,12 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||||||
byte new_subtype = GB(p2, 8, 8);
|
byte new_subtype = GB(p2, 8, 8);
|
||||||
|
|
||||||
Aircraft *v = Aircraft::GetIfValid(p1);
|
Aircraft *v = Aircraft::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->IsStoppedInDepot()) return_cmd_error(STR_ERROR_AIRCRAFT_MUST_BE_STOPPED);
|
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_AIRCRAFT_MUST_BE_STOPPED);
|
||||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
|
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
|
||||||
|
|
||||||
|
@ -628,7 +628,10 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1
|
|||||||
Vehicle *v = Vehicle::GetIfValid(p1);
|
Vehicle *v = Vehicle::GetIfValid(p1);
|
||||||
if (v == NULL) return CMD_ERROR;
|
if (v == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
if (!CheckOwnership(v->owner)) return CMD_ERROR;
|
CommandCost ret = CheckOwnership(v->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
if (!v->IsInDepot()) return CMD_ERROR;
|
if (!v->IsInDepot()) return CMD_ERROR;
|
||||||
if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
|
if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
|
||||||
|
|
||||||
|
@ -248,17 +248,17 @@ void GetNameOfOwner(Owner owner, TileIndex tile)
|
|||||||
* @param owner the owner of the thing to check.
|
* @param owner the owner of the thing to check.
|
||||||
* @param tile optional tile to get the right town.
|
* @param tile optional tile to get the right town.
|
||||||
* @pre if tile == 0 then the owner can't be OWNER_TOWN.
|
* @pre if tile == 0 then the owner can't be OWNER_TOWN.
|
||||||
* @return true iff it's owned by the current company.
|
* @return A succeeded command iff it's owned by the current company, else a failed command.
|
||||||
*/
|
*/
|
||||||
bool CheckOwnership(Owner owner, TileIndex tile)
|
CommandCost CheckOwnership(Owner owner, TileIndex tile)
|
||||||
{
|
{
|
||||||
assert(owner < OWNER_END);
|
assert(owner < OWNER_END);
|
||||||
assert(owner != OWNER_TOWN || tile != 0);
|
assert(owner != OWNER_TOWN || tile != 0);
|
||||||
|
|
||||||
if (owner == _current_company) return true;
|
if (owner == _current_company) return CommandCost();
|
||||||
_error_message = STR_ERROR_OWNED_BY;
|
|
||||||
GetNameOfOwner(owner, tile);
|
GetNameOfOwner(owner, tile);
|
||||||
return false;
|
return_cmd_error(STR_ERROR_OWNED_BY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +24,7 @@ void TileLoopClearHelper(TileIndex tile);
|
|||||||
bool CheckCompanyHasMoney(CommandCost &cost);
|
bool CheckCompanyHasMoney(CommandCost &cost);
|
||||||
void SubtractMoneyFromCompany(CommandCost cost);
|
void SubtractMoneyFromCompany(CommandCost cost);
|
||||||
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cost);
|
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cost);
|
||||||
bool CheckOwnership(Owner owner, TileIndex tile = 0);
|
CommandCost CheckOwnership(Owner owner, TileIndex tile = 0);
|
||||||
CommandCost CheckTileOwnership(TileIndex tile);
|
CommandCost CheckTileOwnership(TileIndex tile);
|
||||||
|
|
||||||
/* misc functions */
|
/* misc functions */
|
||||||
|
@ -468,7 +468,11 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
Order new_order(p2);
|
Order new_order(p2);
|
||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(veh);
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
||||||
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;
|
||||||
|
|
||||||
/* Check if the inserted order is to the correct destination (owner, type),
|
/* Check if the inserted order is to the correct destination (owner, type),
|
||||||
* and has the correct flags if any */
|
* and has the correct flags if any */
|
||||||
@ -477,7 +481,11 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
||||||
if (st == NULL) return CMD_ERROR;
|
if (st == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
if (st->owner != OWNER_NONE && !CheckOwnership(st->owner)) return CMD_ERROR;
|
if (st->owner != OWNER_NONE) {
|
||||||
|
CommandCost ret = CheckOwnership(st->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (!CanVehicleUseStation(v, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
if (!CanVehicleUseStation(v, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
||||||
for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
|
for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
|
||||||
@ -521,15 +529,23 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
if (v->type == VEH_AIRCRAFT) {
|
if (v->type == VEH_AIRCRAFT) {
|
||||||
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
||||||
|
|
||||||
if (st == NULL || !CheckOwnership(st->owner) ||
|
if (st == NULL) return CMD_ERROR;
|
||||||
!CanVehicleUseStation(v, st) ||
|
|
||||||
st->GetAirportSpec()->nof_depots == 0) {
|
CommandCost ret = CheckOwnership(st->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
|
if (!CanVehicleUseStation(v, st) || st->GetAirportSpec()->nof_depots == 0) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const Depot *dp = Depot::GetIfValid(new_order.GetDestination());
|
const Depot *dp = Depot::GetIfValid(new_order.GetDestination());
|
||||||
|
|
||||||
if (dp == NULL || !CheckOwnership(GetTileOwner(dp->xy))) return CMD_ERROR;
|
if (dp == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(GetTileOwner(dp->xy));
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
@ -565,14 +581,22 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
default: return CMD_ERROR;
|
default: return CMD_ERROR;
|
||||||
|
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN: {
|
||||||
if (!(wp->facilities & FACIL_TRAIN)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
if (!(wp->facilities & FACIL_TRAIN)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
||||||
if (!CheckOwnership(wp->owner)) return CMD_ERROR;
|
|
||||||
|
CommandCost ret = CheckOwnership(wp->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
if (!(wp->facilities & FACIL_DOCK)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
if (!(wp->facilities & FACIL_DOCK)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
|
||||||
if (!CheckOwnership(wp->owner) && wp->owner != OWNER_NONE) return CMD_ERROR;
|
if (wp->owner != OWNER_NONE) {
|
||||||
|
CommandCost ret = CheckOwnership(wp->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,7 +753,11 @@ CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(veh_id);
|
Vehicle *v = Vehicle::GetIfValid(veh_id);
|
||||||
|
|
||||||
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 we did not select an order, we maybe want to de-clone the orders */
|
/* If we did not select an order, we maybe want to de-clone the orders */
|
||||||
if (sel_ord >= v->GetNumOrders())
|
if (sel_ord >= v->GetNumOrders())
|
||||||
@ -795,10 +823,11 @@ CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(veh_id);
|
Vehicle *v = Vehicle::GetIfValid(veh_id);
|
||||||
|
|
||||||
if (v == NULL || !CheckOwnership(v->owner) || sel_ord == v->cur_order_index ||
|
if (v == NULL || sel_ord == v->cur_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
|
||||||
sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) {
|
|
||||||
return CMD_ERROR;
|
CommandCost ret = CheckOwnership(v->owner);
|
||||||
}
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
v->cur_order_index = sel_ord;
|
v->cur_order_index = sel_ord;
|
||||||
@ -835,7 +864,11 @@ CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
VehicleOrderID target_order = GB(p2, 16, 16);
|
VehicleOrderID target_order = GB(p2, 16, 16);
|
||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(veh);
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
||||||
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;
|
||||||
|
|
||||||
/* Don't make senseless movements */
|
/* Don't make senseless movements */
|
||||||
if (moving_order >= v->GetNumOrders() || target_order >= v->GetNumOrders() ||
|
if (moving_order >= v->GetNumOrders() || target_order >= v->GetNumOrders() ||
|
||||||
@ -916,7 +949,11 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
if (mof >= MOF_END) return CMD_ERROR;
|
if (mof >= MOF_END) return CMD_ERROR;
|
||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(veh);
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
||||||
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;
|
||||||
|
|
||||||
/* Is it a valid order? */
|
/* Is it a valid order? */
|
||||||
if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
|
if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
|
||||||
@ -1139,17 +1176,22 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
VehicleID veh_dst = GB(p1, 0, 16);
|
VehicleID veh_dst = GB(p1, 0, 16);
|
||||||
|
|
||||||
Vehicle *dst = Vehicle::GetIfValid(veh_dst);
|
Vehicle *dst = Vehicle::GetIfValid(veh_dst);
|
||||||
|
if (dst == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
if (dst == NULL || !CheckOwnership(dst->owner)) return CMD_ERROR;
|
CommandCost ret = CheckOwnership(dst->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
switch (p2) {
|
switch (p2) {
|
||||||
case CO_SHARE: {
|
case CO_SHARE: {
|
||||||
Vehicle *src = Vehicle::GetIfValid(veh_src);
|
Vehicle *src = Vehicle::GetIfValid(veh_src);
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
if (src == NULL || !CheckOwnership(src->owner) || dst->type != src->type || dst == src) {
|
if (src == NULL || dst->type != src->type || dst == src) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
|
||||||
}
|
CommandCost ret = CheckOwnership(src->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
/* Trucks can't share orders with busses (and visa versa) */
|
/* Trucks can't share orders with busses (and visa versa) */
|
||||||
if (src->type == VEH_ROAD && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
|
if (src->type == VEH_ROAD && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
|
||||||
@ -1188,9 +1230,11 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
Vehicle *src = Vehicle::GetIfValid(veh_src);
|
Vehicle *src = Vehicle::GetIfValid(veh_src);
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
if (src == NULL || !CheckOwnership(src->owner) || dst->type != src->type || dst == src) {
|
if (src == NULL || dst->type != src->type || dst == src) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
|
||||||
}
|
CommandCost ret = CheckOwnership(src->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
/* Trucks can't copy all the orders from busses (and visa versa),
|
/* Trucks can't copy all the orders from busses (and visa versa),
|
||||||
* and neither can helicopters and aircarft. */
|
* and neither can helicopters and aircarft. */
|
||||||
@ -1264,7 +1308,11 @@ CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
byte subtype = GB(p2, 8, 8);
|
byte subtype = GB(p2, 8, 8);
|
||||||
|
|
||||||
const Vehicle *v = Vehicle::GetIfValid(veh);
|
const Vehicle *v = Vehicle::GetIfValid(veh);
|
||||||
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;
|
||||||
|
|
||||||
Order *order = v->GetOrder(order_number);
|
Order *order = v->GetOrder(order_number);
|
||||||
if (order == NULL) return CMD_ERROR;
|
if (order == NULL) return CMD_ERROR;
|
||||||
@ -1416,7 +1464,12 @@ CommandCost CmdRestoreOrderIndex(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(p1);
|
Vehicle *v = Vehicle::GetIfValid(p1);
|
||||||
/* Check the vehicle type and ownership, and if the service interval and order are in range */
|
/* Check the vehicle type and ownership, and if the service interval and order are in range */
|
||||||
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 (serv_int != GetServiceIntervalClamped(serv_int, v->owner) || cur_ord >= v->GetNumOrders()) return CMD_ERROR;
|
if (serv_int != GetServiceIntervalClamped(serv_int, v->owner) || cur_ord >= v->GetNumOrders()) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
|
@ -131,7 +131,9 @@ CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, R
|
|||||||
* by a town */
|
* by a town */
|
||||||
if (owner != OWNER_TOWN) {
|
if (owner != OWNER_TOWN) {
|
||||||
if (owner == OWNER_NONE) return CommandCost();
|
if (owner == OWNER_NONE) return CommandCost();
|
||||||
return CheckOwnership(owner) ? CommandCost() : CMD_ERROR;
|
CommandCost ret = CheckOwnership(owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!town_check) return CommandCost();
|
if (!town_check) return CommandCost();
|
||||||
@ -502,7 +504,11 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
if (crossing) return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
|
if (crossing) return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
|
||||||
|
|
||||||
Owner owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
Owner owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
||||||
if (owner != OWNER_NONE && !CheckOwnership(owner, tile)) return CMD_ERROR;
|
if (owner != OWNER_NONE) {
|
||||||
|
CommandCost ret = CheckOwnership(owner, tile);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
}
|
||||||
|
|
||||||
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
||||||
ret.SetGlobalErrorMessage();
|
ret.SetGlobalErrorMessage();
|
||||||
|
@ -331,7 +331,11 @@ bool RoadVehicle::IsStoppedInDepot() const
|
|||||||
CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
|
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);
|
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);
|
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) {
|
if (flags & DC_EXEC) {
|
||||||
delete v;
|
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)
|
CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
|
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) ||
|
if ((v->vehstatus & VS_STOPPED) ||
|
||||||
(v->vehstatus & VS_CRASHED) ||
|
(v->vehstatus & VS_CRASHED) ||
|
||||||
@ -1748,8 +1756,12 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|||||||
bool only_this = HasBit(p2, 16);
|
bool only_this = HasBit(p2, 16);
|
||||||
|
|
||||||
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
|
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->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);
|
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
|
||||||
|
|
||||||
|
@ -709,7 +709,11 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Ship *v = Ship::GetIfValid(p1);
|
Ship *v = Ship::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);
|
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_SELL_DESTROYED_VEHICLE);
|
||||||
|
|
||||||
@ -717,7 +721,7 @@ CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p
|
|||||||
return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
|
return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value);
|
ret = CommandCost(EXPENSES_NEW_VEHICLES, -v->value);
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
delete v;
|
delete v;
|
||||||
@ -780,8 +784,12 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
byte new_subtype = GB(p2, 8, 8);
|
byte new_subtype = GB(p2, 8, 8);
|
||||||
|
|
||||||
Ship *v = Ship::GetIfValid(p1);
|
Ship *v = Ship::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_SHIP_MUST_BE_STOPPED_IN_DEPOT);
|
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
|
||||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
|
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
|
||||||
|
|
||||||
|
@ -865,8 +865,10 @@ static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags
|
|||||||
Owner road_owner = GetRoadOwner(cur_tile, ROADTYPE_ROAD);
|
Owner road_owner = GetRoadOwner(cur_tile, ROADTYPE_ROAD);
|
||||||
if (road_owner == OWNER_TOWN) {
|
if (road_owner == OWNER_TOWN) {
|
||||||
if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD);
|
if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD);
|
||||||
} else if (!_settings_game.construction.road_stop_on_competitor_road && road_owner != OWNER_NONE && !CheckOwnership(road_owner)) {
|
} else if (!_settings_game.construction.road_stop_on_competitor_road && road_owner != OWNER_NONE) {
|
||||||
return CMD_ERROR;
|
CommandCost ret = CheckOwnership(road_owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
}
|
}
|
||||||
num_roadbits += CountBits(GetRoadBits(cur_tile, ROADTYPE_ROAD));
|
num_roadbits += CountBits(GetRoadBits(cur_tile, ROADTYPE_ROAD));
|
||||||
}
|
}
|
||||||
@ -874,8 +876,10 @@ static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags
|
|||||||
/* There is a tram, check if we can build road+tram stop over it. */
|
/* There is a tram, check if we can build road+tram stop over it. */
|
||||||
if (HasBit(cur_rts, ROADTYPE_TRAM)) {
|
if (HasBit(cur_rts, ROADTYPE_TRAM)) {
|
||||||
Owner tram_owner = GetRoadOwner(cur_tile, ROADTYPE_TRAM);
|
Owner tram_owner = GetRoadOwner(cur_tile, ROADTYPE_TRAM);
|
||||||
if (!_settings_game.construction.road_stop_on_competitor_road && tram_owner != OWNER_NONE && !CheckOwnership(tram_owner)) {
|
if (!_settings_game.construction.road_stop_on_competitor_road && tram_owner != OWNER_NONE) {
|
||||||
return CMD_ERROR;
|
CommandCost ret = CheckOwnership(tram_owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
}
|
}
|
||||||
num_roadbits += CountBits(GetRoadBits(cur_tile, ROADTYPE_TRAM));
|
num_roadbits += CountBits(GetRoadBits(cur_tile, ROADTYPE_TRAM));
|
||||||
}
|
}
|
||||||
@ -1383,7 +1387,14 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector<T *, 4> &affected
|
|||||||
/* Check ownership of station */
|
/* Check ownership of station */
|
||||||
T *st = T::GetByTile(tile);
|
T *st = T::GetByTile(tile);
|
||||||
if (st == NULL) continue;
|
if (st == NULL) continue;
|
||||||
if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) continue;
|
|
||||||
|
if (_current_company != OWNER_WATER) {
|
||||||
|
CommandCost ret = CheckOwnership(st->owner);
|
||||||
|
if (ret.Failed()) {
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Do not allow removing from stations if non-uniform stations are not enabled
|
/* Do not allow removing from stations if non-uniform stations are not enabled
|
||||||
* The check must be here to give correct error message
|
* The check must be here to give correct error message
|
||||||
@ -1529,7 +1540,11 @@ template <class T>
|
|||||||
CommandCost RemoveRailStation(T *st, DoCommandFlag flags)
|
CommandCost RemoveRailStation(T *st, DoCommandFlag flags)
|
||||||
{
|
{
|
||||||
/* Current company owns the station? */
|
/* Current company owns the station? */
|
||||||
if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR;
|
if (_current_company != OWNER_WATER) {
|
||||||
|
CommandCost ret = CheckOwnership(st->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* determine width and height of platforms */
|
/* determine width and height of platforms */
|
||||||
TileArea ta = st->train_station;
|
TileArea ta = st->train_station;
|
||||||
@ -1829,8 +1844,10 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
|
|||||||
{
|
{
|
||||||
Station *st = Station::GetByTile(tile);
|
Station *st = Station::GetByTile(tile);
|
||||||
|
|
||||||
if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
|
if (_current_company != OWNER_WATER) {
|
||||||
return CMD_ERROR;
|
CommandCost ret = CheckOwnership(st->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_truck = IsTruckStop(tile);
|
bool is_truck = IsTruckStop(tile);
|
||||||
@ -2241,8 +2258,10 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
|
|||||||
{
|
{
|
||||||
Station *st = Station::GetByTile(tile);
|
Station *st = Station::GetByTile(tile);
|
||||||
|
|
||||||
if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
|
if (_current_company != OWNER_WATER) {
|
||||||
return CMD_ERROR;
|
CommandCost ret = CheckOwnership(st->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
tile = st->airport.tile;
|
tile = st->airport.tile;
|
||||||
@ -2456,12 +2475,14 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||||||
static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
|
static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
|
||||||
{
|
{
|
||||||
Station *st = Station::GetByTile(tile);
|
Station *st = Station::GetByTile(tile);
|
||||||
if (!CheckOwnership(st->owner)) return CMD_ERROR;
|
CommandCost ret = CheckOwnership(st->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
TileIndex tile1 = st->dock_tile;
|
TileIndex tile1 = st->dock_tile;
|
||||||
TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
|
TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
|
||||||
|
|
||||||
CommandCost ret = EnsureNoVehicleOnGround(tile1);
|
ret = EnsureNoVehicleOnGround(tile1);
|
||||||
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
|
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
|
||||||
ret.SetGlobalErrorMessage();
|
ret.SetGlobalErrorMessage();
|
||||||
if (ret.Failed()) return ret;
|
if (ret.Failed()) return ret;
|
||||||
@ -3194,7 +3215,11 @@ static bool IsUniqueStationName(const char *name)
|
|||||||
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Station *st = Station::GetIfValid(p1);
|
Station *st = Station::GetIfValid(p1);
|
||||||
if (st == NULL || !CheckOwnership(st->owner)) return CMD_ERROR;
|
if (st == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(st->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
bool reset = StrEmpty(text);
|
bool reset = StrEmpty(text);
|
||||||
|
|
||||||
@ -3441,7 +3466,7 @@ static bool CanRemoveRoadWithStop(TileIndex tile, DoCommandFlag flags)
|
|||||||
if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
||||||
if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
||||||
|
|
||||||
if ((road_owner != OWNER_TOWN && !CheckOwnership(road_owner)) || !CheckOwnership(tram_owner)) return false;
|
if ((road_owner != OWNER_TOWN && CheckOwnership(road_owner).Failed()) || CheckOwnership(tram_owner).Failed()) return false;
|
||||||
|
|
||||||
return road_owner != OWNER_TOWN || CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, ROADTYPE_ROAD, flags).Succeeded();
|
return road_owner != OWNER_TOWN || CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, ROADTYPE_ROAD, flags).Succeeded();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,11 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||||||
VehicleID veh = GB(p1, 0, 16);
|
VehicleID veh = GB(p1, 0, 16);
|
||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(veh);
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
||||||
if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(v->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
VehicleOrderID order_number = GB(p1, 16, 8);
|
VehicleOrderID order_number = GB(p1, 16, 8);
|
||||||
Order *order = v->GetOrder(order_number);
|
Order *order = v->GetOrder(order_number);
|
||||||
@ -128,7 +132,11 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||||||
VehicleID veh = GB(p1, 0, 16);
|
VehicleID veh = GB(p1, 0, 16);
|
||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(veh);
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
||||||
if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(v->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
v->lateness_counter = 0;
|
v->lateness_counter = 0;
|
||||||
@ -150,7 +158,11 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||||||
if (!_settings_game.order.timetabling) return CMD_ERROR;
|
if (!_settings_game.order.timetabling) return CMD_ERROR;
|
||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 16));
|
Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 16));
|
||||||
if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(v->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
/* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
|
/* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
|
||||||
Date start_date = (Date)p2;
|
Date start_date = (Date)p2;
|
||||||
@ -190,7 +202,11 @@ CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||||||
VehicleID veh = GB(p1, 0, 16);
|
VehicleID veh = GB(p1, 0, 16);
|
||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(veh);
|
Vehicle *v = Vehicle::GetIfValid(veh);
|
||||||
if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(v->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
if (HasBit(p2, 0)) {
|
if (HasBit(p2, 0)) {
|
||||||
|
@ -1169,7 +1169,11 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||||||
bool move_chain = HasBit(p2, 0);
|
bool move_chain = HasBit(p2, 0);
|
||||||
|
|
||||||
Train *src = Train::GetIfValid(s);
|
Train *src = Train::GetIfValid(s);
|
||||||
if (src == NULL || !CheckOwnership(src->owner)) return CMD_ERROR;
|
if (src == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(src->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
/* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */
|
/* Do not allow moving crashed vehicles inside the depot, it is likely to cause asserts later */
|
||||||
if (src->vehstatus & VS_CRASHED) return CMD_ERROR;
|
if (src->vehstatus & VS_CRASHED) return CMD_ERROR;
|
||||||
@ -1180,7 +1184,11 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||||||
dst = src->IsEngine() ? NULL : FindGoodVehiclePos(src);
|
dst = src->IsEngine() ? NULL : FindGoodVehiclePos(src);
|
||||||
} else {
|
} else {
|
||||||
dst = Train::GetIfValid(d);
|
dst = Train::GetIfValid(d);
|
||||||
if (dst == NULL || !CheckOwnership(dst->owner)) return CMD_ERROR;
|
if (dst == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(dst->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
/* Do not allow appending to crashed vehicles, too */
|
/* Do not allow appending to crashed vehicles, too */
|
||||||
if (dst->vehstatus & VS_CRASHED) return CMD_ERROR;
|
if (dst->vehstatus & VS_CRASHED) return CMD_ERROR;
|
||||||
@ -1342,7 +1350,11 @@ CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||||||
Window *w = NULL;
|
Window *w = NULL;
|
||||||
|
|
||||||
Train *v = Train::GetIfValid(p1);
|
Train *v = Train::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;
|
||||||
|
|
||||||
/* Sell a chain of vehicles or not? */
|
/* Sell a chain of vehicles or not? */
|
||||||
bool sell_chain = HasBit(p2, 0);
|
bool sell_chain = HasBit(p2, 0);
|
||||||
@ -1372,7 +1384,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||||||
ArrangeTrains(&sell_head, NULL, &new_head, v, sell_chain);
|
ArrangeTrains(&sell_head, NULL, &new_head, v, sell_chain);
|
||||||
|
|
||||||
/* We don't need to validate the second train; it's going to be sold. */
|
/* We don't need to validate the second train; it's going to be sold. */
|
||||||
CommandCost ret = ValidateTrains(NULL, NULL, first, new_head);
|
ret = ValidateTrains(NULL, NULL, first, new_head);
|
||||||
if (ret.Failed()) {
|
if (ret.Failed()) {
|
||||||
/* Restore the train we had. */
|
/* Restore the train we had. */
|
||||||
RestoreTrainBackup(original);
|
RestoreTrainBackup(original);
|
||||||
@ -1815,7 +1827,11 @@ static void ReverseTrainDirection(Train *v)
|
|||||||
CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Train *v = Train::GetIfValid(p1);
|
Train *v = Train::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 (p2 != 0) {
|
if (p2 != 0) {
|
||||||
/* turn a single unit around */
|
/* turn a single unit around */
|
||||||
@ -1882,7 +1898,12 @@ CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32
|
|||||||
CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Train *t = Train::GetIfValid(p1);
|
Train *t = Train::GetIfValid(p1);
|
||||||
if (t == NULL || !CheckOwnership(t->owner)) return CMD_ERROR;
|
if (t == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(t->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
/* If we are forced to proceed, cancel that order.
|
/* If we are forced to proceed, cancel that order.
|
||||||
@ -1915,7 +1936,11 @@ CommandCost CmdRefitRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||||||
bool only_this = HasBit(p2, 16);
|
bool only_this = HasBit(p2, 16);
|
||||||
|
|
||||||
Train *v = Train::GetIfValid(p1);
|
Train *v = Train::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->IsStoppedInDepot()) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED);
|
if (!v->IsStoppedInDepot()) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED);
|
||||||
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
|
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
|
||||||
|
@ -613,12 +613,18 @@ static inline CommandCost CheckAllowRemoveTunnelBridge(TileIndex tile)
|
|||||||
if (road_owner == OWNER_NONE || road_owner == OWNER_TOWN) road_owner = _current_company;
|
if (road_owner == OWNER_NONE || road_owner == OWNER_TOWN) road_owner = _current_company;
|
||||||
if (tram_owner == OWNER_NONE) tram_owner = _current_company;
|
if (tram_owner == OWNER_NONE) tram_owner = _current_company;
|
||||||
|
|
||||||
return (CheckOwnership(road_owner, tile) && CheckOwnership(tram_owner, tile)) ? CommandCost() : CMD_ERROR;
|
CommandCost ret = CheckOwnership(road_owner, tile);
|
||||||
|
if (ret.Succeeded()) ret = CheckOwnership(tram_owner, tile);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TRANSPORT_RAIL:
|
case TRANSPORT_RAIL:
|
||||||
case TRANSPORT_WATER:
|
case TRANSPORT_WATER: {
|
||||||
return CheckOwnership(GetTileOwner(tile)) ? CommandCost() : CMD_ERROR;
|
CommandCost ret = CheckOwnership(GetTileOwner(tile));
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -1665,7 +1665,10 @@ void Vehicle::HandleLoading(bool mode)
|
|||||||
|
|
||||||
CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
|
CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
|
||||||
{
|
{
|
||||||
if (!CheckOwnership(this->owner)) return CMD_ERROR;
|
CommandCost ret = CheckOwnership(this->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
if (this->vehstatus & VS_CRASHED) return CMD_ERROR;
|
if (this->vehstatus & VS_CRASHED) return CMD_ERROR;
|
||||||
if (this->IsStoppedInDepot()) return CMD_ERROR;
|
if (this->IsStoppedInDepot()) return CMD_ERROR;
|
||||||
|
|
||||||
|
@ -74,7 +74,11 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||||||
if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0);
|
if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0);
|
||||||
|
|
||||||
Vehicle *v = Vehicle::GetIfValid(p1);
|
Vehicle *v = Vehicle::GetIfValid(p1);
|
||||||
if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||||
|
|
||||||
|
CommandCost ret = CheckOwnership(v->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case VEH_TRAIN:
|
case VEH_TRAIN:
|
||||||
@ -406,7 +410,9 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|||||||
* w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains
|
* w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!CheckOwnership(v->owner)) return CMD_ERROR;
|
CommandCost ret = CheckOwnership(v->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
if (v->type == VEH_TRAIN && (!Train::From(v)->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return CMD_ERROR;
|
if (v->type == VEH_TRAIN && (!Train::From(v)->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return CMD_ERROR;
|
||||||
|
|
||||||
@ -607,7 +613,11 @@ CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool s
|
|||||||
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Vehicle *v = Vehicle::GetIfValid(p1);
|
Vehicle *v = Vehicle::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;
|
||||||
|
|
||||||
bool reset = StrEmpty(text);
|
bool reset = StrEmpty(text);
|
||||||
|
|
||||||
@ -638,7 +648,11 @@ CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||||||
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Vehicle *v = Vehicle::GetIfValid(p1);
|
Vehicle *v = Vehicle::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;
|
||||||
|
|
||||||
uint16 serv_int = GetServiceIntervalClamped(p2, v->owner); // Double check the service interval from the user-input
|
uint16 serv_int = GetServiceIntervalClamped(p2, v->owner); // Double check the service interval from the user-input
|
||||||
if (serv_int != p2) return CMD_ERROR;
|
if (serv_int != p2) return CMD_ERROR;
|
||||||
|
@ -178,9 +178,11 @@ static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *
|
|||||||
if (GetAxisForNewWaypoint(tile) != axis) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
|
if (GetAxisForNewWaypoint(tile) != axis) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
|
||||||
|
|
||||||
Owner owner = GetTileOwner(tile);
|
Owner owner = GetTileOwner(tile);
|
||||||
if (!CheckOwnership(owner)) return CMD_ERROR;
|
CommandCost ret = CheckOwnership(owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
ret = EnsureNoVehicleOnGround(tile);
|
||||||
ret.SetGlobalErrorMessage();
|
ret.SetGlobalErrorMessage();
|
||||||
if (ret.Failed()) return ret;
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
@ -445,7 +447,13 @@ static bool IsUniqueWaypointName(const char *name)
|
|||||||
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
Waypoint *wp = Waypoint::GetIfValid(p1);
|
Waypoint *wp = Waypoint::GetIfValid(p1);
|
||||||
if (wp == NULL || !(CheckOwnership(wp->owner) || wp->owner == OWNER_NONE)) return CMD_ERROR;
|
if (wp == NULL) return CMD_ERROR;
|
||||||
|
|
||||||
|
if (wp->owner != OWNER_NONE) {
|
||||||
|
CommandCost ret = CheckOwnership(wp->owner);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool reset = StrEmpty(text);
|
bool reset = StrEmpty(text);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user