diff options
author | frosch <frosch@openttd.org> | 2009-02-21 12:52:41 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-02-21 12:52:41 +0000 |
commit | abe4692da2a22dbfafb990db7c28a6d1d3cdcb16 (patch) | |
tree | 62e06798cf27a41c73412fa15906f2df18c9826c /src/roadveh_cmd.cpp | |
parent | 9eb880ab436cc1bcba703230741b07743189669f (diff) | |
download | openttd-abe4692da2a22dbfafb990db7c28a6d1d3cdcb16.tar.xz |
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
-Codechange: Add Engine::GetDefaultCargoType() and Engine::CanCarryCargo() and use them.
-Fix [FS#2617]: When articulated parts have no available default cargo, use the cargo type of the first part for livery selection.
-Change: To decide whether a vehicle is refittable do not test its current capacity for being zero, but always use the 'capacity property'.
Note: The property is used unmodifed without calling CB 15/36. By setting it to a non-zero value and returning zero in the callback vehicles can be refitted to/from zero capacity for e.g. livery effects.
Note: It is intentional that you cannot control refittability by CB 36.
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r-- | src/roadveh_cmd.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index a15581a47..7878a9d05 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -166,6 +166,9 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint if (!IsEngineBuildable(p1, VEH_ROAD, _current_company)) return_cmd_error(STR_ROAD_VEHICLE_NOT_AVAILABLE); const Engine *e = GetEngine(p1); + /* Engines without valid cargo should not be available */ + if (e->GetDefaultCargoType() == CT_INVALID) return CMD_ERROR; + CommandCost cost(EXPENSES_NEW_VEHICLES, e->GetCost()); if (flags & DC_QUERY_COST) return cost; @@ -217,7 +220,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; v->spritenum = rvi->image_index; - v->cargo_type = rvi->cargo_type; + v->cargo_type = e->GetDefaultCargoType(); v->cargo_subtype = 0; v->cargo_cap = rvi->capacity; // v->cargo_count = 0; @@ -262,7 +265,8 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint /* Call callback 36s after the whole consist has been constructed */ for (Vehicle *u = v; u != NULL; u = u->Next()) { - u->cargo_cap = GetVehicleProperty(u, 0x0F, u->cargo_cap); + /* Cargo capacity is zero if and only if the vehicle cannot carry anything */ + if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, 0x0F, u->cargo_cap); } VehiclePositionChanged(v); @@ -2009,7 +2013,8 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint * [Refit] button near each wagon. */ if (!CanRefitTo(v->engine_type, new_cid)) continue; - if (v->cargo_cap == 0) continue; + const Engine *e = GetEngine(v->engine_type); + if (!e->CanCarryCargo()) continue; if (HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) { /* Back up the cargo type */ @@ -2028,14 +2033,13 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint if (capacity == CALLBACK_FAILED) { /* callback failed or not used, use default capacity */ - const RoadVehicleInfo *rvi = RoadVehInfo(v->engine_type); - CargoID old_cid = rvi->cargo_type; + CargoID old_cid = e->GetDefaultCargoType(); /* normally, the capacity depends on the cargo type, a vehicle can * carry twice as much mail/goods as normal cargo, and four times as * many passengers */ - capacity = GetVehicleProperty(v, 0x0F, rvi->capacity); + capacity = GetVehicleProperty(v, 0x0F, e->u.road.capacity); switch (old_cid) { case CT_PASSENGERS: break; case CT_MAIL: |