summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2011-08-03 20:55:08 +0000
committermichi_cc <michi_cc@openttd.org>2011-08-03 20:55:08 +0000
commit08b7981f37431f57ca2fa8dd25db4088c7c69d4e (patch)
treed55fa560c79768b03077cb544552875e8064d17e
parent442b92ff33c31317f77786f23539c2566f8252f3 (diff)
downloadopenttd-08b7981f37431f57ca2fa8dd25db4088c7c69d4e.tar.xz
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
-rw-r--r--src/aircraft_cmd.cpp5
-rw-r--r--src/engine.cpp2
-rw-r--r--src/engine_type.h1
-rw-r--r--src/newgrf.cpp16
-rw-r--r--src/newgrf_properties.h4
-rw-r--r--src/roadveh_cmd.cpp3
-rw-r--r--src/saveload/misc_sl.cpp5
-rw-r--r--src/saveload/oldloader_sl.cpp1
-rw-r--r--src/saveload/saveload.cpp3
-rw-r--r--src/saveload/vehicle_sl.cpp10
-rw-r--r--src/ship_cmd.cpp3
-rw-r--r--src/table/engines.h10
-rw-r--r--src/train_cmd.cpp1
-rw-r--r--src/vehicle.cpp14
-rw-r--r--src/vehicle_base.h4
-rw-r--r--src/vehicle_cmd.cpp7
-rw-r--r--src/vehicle_func.h1
17 files changed, 74 insertions, 16 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index ae80ae7f9..ce969a533 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -549,6 +549,11 @@ void UpdateAircraftCache(Aircraft *v)
/* Use the default max speed of the vehicle. */
v->vcache.cached_max_speed = AircraftVehInfo(v->engine_type)->max_speed;
}
+
+ /* Update cargo aging period. */
+ v->vcache.cached_cargo_age_period = GetVehicleProperty(v, PROP_AIRCRAFT_CARGO_AGE_PERIOD, EngInfo(v->engine_type)->cargo_age_period);
+ Aircraft *u = v->Next(); // Shadow for mail
+ u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_AIRCRAFT_CARGO_AGE_PERIOD, EngInfo(u->engine_type)->cargo_age_period);
}
diff --git a/src/engine.cpp b/src/engine.cpp
index 42454e401..05bbc9113 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -98,6 +98,8 @@ Engine::Engine(VehicleType type, EngineID base)
case VEH_SHIP: this->u.ship.visual_effect = VE_DEFAULT; break;
default: break; // The aircraft, disasters and especially visual effects have no NewGRF configured visual effects
}
+ /* Set cargo aging period to the default value. */
+ this->info.cargo_age_period = CARGO_AGING_TICKS;
return;
}
diff --git a/src/engine_type.h b/src/engine_type.h
index 6f93bfbb6..2bd7fae47 100644
--- a/src/engine_type.h
+++ b/src/engine_type.h
@@ -134,6 +134,7 @@ struct EngineInfo {
byte callback_mask; ///< Bitmask of vehicle callbacks that have to be called
int8 retire_early; ///< Number of years early to retire vehicle
StringID string_id; ///< Default name of engine
+ uint16 cargo_age_period; ///< Number of ticks before carried cargo is aged.
};
/**
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 86d2da2a6..514d6dfdf 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -966,6 +966,10 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
ei->base_intro = buf->ReadDWord();
break;
+ case PROP_TRAIN_CARGO_AGE_PERIOD: // 0x2B Cargo aging period
+ ei->cargo_age_period = buf->ReadWord();
+ break;
+
default:
ret = CommonVehicleChangeInfo(ei, prop, buf);
break;
@@ -1108,6 +1112,10 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop
}
break;
+ case PROP_ROADVEH_CARGO_AGE_PERIOD: // 0x22 Cargo aging period
+ ei->cargo_age_period = buf->ReadWord();
+ break;
+
default:
ret = CommonVehicleChangeInfo(ei, prop, buf);
break;
@@ -1238,6 +1246,10 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
}
break;
+ case PROP_SHIP_CARGO_AGE_PERIOD: // 0x1D Cargo aging period
+ ei->cargo_age_period = buf->ReadWord();
+ break;
+
default:
ret = CommonVehicleChangeInfo(ei, prop, buf);
break;
@@ -1352,6 +1364,10 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int
AlterVehicleListOrder(e->index, buf->ReadExtendedByte());
break;
+ case PROP_AIRCRAFT_CARGO_AGE_PERIOD: // 0x1C Cargo aging period
+ ei->cargo_age_period = buf->ReadWord();
+ break;
+
default:
ret = CommonVehicleChangeInfo(ei, prop, buf);
break;
diff --git a/src/newgrf_properties.h b/src/newgrf_properties.h
index 900220f94..1f18940e0 100644
--- a/src/newgrf_properties.h
+++ b/src/newgrf_properties.h
@@ -26,6 +26,7 @@ enum PropertyID {
PROP_TRAIN_COST_FACTOR = 0x17, ///< Purchase cost (if dualheaded: sum of both vehicles)
PROP_TRAIN_TRACTIVE_EFFORT = 0x1F, ///< Tractive effort coefficient in 1/256
PROP_TRAIN_USER_DATA = 0x25, ///< User defined data for vehicle variable 0x42
+ PROP_TRAIN_CARGO_AGE_PERIOD = 0x2B, ///< Number of ticks before carried cargo is aged
PROP_ROADVEH_RUNNING_COST_FACTOR = 0x09, ///< Yearly runningcost
PROP_ROADVEH_CARGO_CAPACITY = 0x0F, ///< Capacity
@@ -34,17 +35,20 @@ enum PropertyID {
PROP_ROADVEH_WEIGHT = 0x14, ///< Weight in 1/4 t
PROP_ROADVEH_SPEED = 0x15, ///< Max. speed: 1 unit = 1/0.8 mph = 2 km-ish/h
PROP_ROADVEH_TRACTIVE_EFFORT = 0x18, ///< Tractive effort coefficient in 1/256
+ PROP_ROADVEH_CARGO_AGE_PERIOD = 0x22, ///< Number of ticks before carried cargo is aged
PROP_SHIP_COST_FACTOR = 0x0A, ///< Purchase cost
PROP_SHIP_SPEED = 0x0B, ///< Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h
PROP_SHIP_CARGO_CAPACITY = 0x0D, ///< Capacity
PROP_SHIP_RUNNING_COST_FACTOR = 0x0F, ///< Yearly runningcost
+ PROP_SHIP_CARGO_AGE_PERIOD = 0x1D, ///< Number of ticks before carried cargo is aged
PROP_AIRCRAFT_COST_FACTOR = 0x0B, ///< Purchase cost
PROP_AIRCRAFT_SPEED = 0x0C, ///< Max. speed: 1 unit = 8 mph = 12.8 km-ish/h
PROP_AIRCRAFT_RUNNING_COST_FACTOR = 0x0E, ///< Yearly runningcost
PROP_AIRCRAFT_PASSENGER_CAPACITY = 0x0F, ///< Passenger Capacity
PROP_AIRCRAFT_MAIL_CAPACITY = 0x11, ///< Mail Capacity
+ PROP_AIRCRAFT_CARGO_AGE_PERIOD = 0x1C, ///< Number of ticks before carried cargo is aged
};
#endif /* NEWGRF_PROPERTIES_H */
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 8a77e9d89..672c6e426 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -201,6 +201,9 @@ void RoadVehUpdateCache(RoadVehicle *v)
/* Invalidate the vehicle colour map */
u->colourmap = PAL_NONE;
+
+ /* Update cargo aging period. */
+ u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_ROADVEH_CARGO_AGE_PERIOD, EngInfo(u->engine_type)->cargo_age_period);
}
uint max_speed = GetVehicleProperty(v, PROP_ROADVEH_SPEED, 0);
diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp
index 2f3827ce9..ccfc7a2d3 100644
--- a/src/saveload/misc_sl.cpp
+++ b/src/saveload/misc_sl.cpp
@@ -60,6 +60,7 @@ void ResetViewportAfterLoadGame()
MarkWholeScreenDirty();
}
+byte _age_cargo_skip_counter; ///< Skip aging of cargo? Used before savegame version 162.
static const SaveLoadGlobVarList _date_desc[] = {
SLEG_CONDVAR(_date, SLE_FILE_U16 | SLE_VAR_I32, 0, 30),
@@ -67,7 +68,7 @@ static const SaveLoadGlobVarList _date_desc[] = {
SLEG_VAR(_date_fract, SLE_UINT16),
SLEG_VAR(_tick_counter, SLE_UINT16),
SLE_CONDNULL(2, 0, 156), // _vehicle_id_ctr_day
- SLEG_VAR(_age_cargo_skip_counter, SLE_UINT8),
+ SLEG_CONDVAR(_age_cargo_skip_counter, SLE_UINT8, 0, 161),
SLE_CONDNULL(1, 0, 45),
SLEG_CONDVAR(_cur_tileloop_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLEG_CONDVAR(_cur_tileloop_tile, SLE_UINT32, 6, SL_MAX_VERSION),
@@ -92,7 +93,7 @@ static const SaveLoadGlobVarList _date_check_desc[] = {
SLE_NULL(2), // _date_fract
SLE_NULL(2), // _tick_counter
SLE_CONDNULL(2, 0, 156), // _vehicle_id_ctr_day
- SLE_NULL(1), // _age_cargo_skip_counter
+ SLE_CONDNULL(1, 0, 161), // _age_cargo_skip_counter
SLE_CONDNULL(1, 0, 45),
SLE_CONDNULL(2, 0, 5), // _cur_tileloop_tile
SLE_CONDNULL(4, 6, SL_MAX_VERSION), // _cur_tileloop_tile
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
index 7f1722e0f..d4ff3758a 100644
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -1573,6 +1573,7 @@ static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int num)
extern TileIndex _cur_tileloop_tile;
extern uint16 _disaster_delay;
extern byte _trees_tick_ctr;
+extern byte _age_cargo_skip_counter; // From misc_sl.cpp
static const OldChunks main_chunk[] = {
OCL_ASSERT( OC_TTD, 0 ),
OCL_ASSERT( OC_TTO, 0 ),
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 486d1d8e5..162776533 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -226,8 +226,9 @@
* 159 21962
* 160 21974
* 161 22567
+ * 162 22713
*/
-extern const uint16 SAVEGAME_VERSION = 161; ///< Current savegame version of OpenTTD.
+extern const uint16 SAVEGAME_VERSION = 162; ///< Current savegame version of OpenTTD.
SavegameType _savegame_type; ///< type of savegame we are loading
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index b9b2d53ce..ff738c7e2 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -237,6 +237,8 @@ static void CheckValidVehicles()
}
}
+extern byte _age_cargo_skip_counter; // From misc_sl.cpp
+
/** Called after load to update coordinates */
void AfterLoadVehicles(bool part_of_load)
{
@@ -342,6 +344,13 @@ void AfterLoadVehicles(bool part_of_load)
}
}
}
+
+ if (IsSavegameVersionBefore(162)) {
+ /* Set the vehicle-local cargo age counter from the old global counter. */
+ FOR_ALL_VEHICLES(v) {
+ v->cargo_age_counter = _age_cargo_skip_counter;
+ }
+ }
}
CheckValidVehicles();
@@ -499,6 +508,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_VAR(Vehicle, cargo_cap, SLE_UINT16),
SLEG_CONDVAR( _cargo_count, SLE_UINT16, 0, 67),
SLE_CONDLST(Vehicle, cargo.packets, REF_CARGO_PACKET, 68, SL_MAX_VERSION),
+ SLE_CONDVAR(Vehicle, cargo_age_counter, SLE_UINT16, 162, SL_MAX_VERSION),
SLE_VAR(Vehicle, day_counter, SLE_UINT8),
SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 29959c931..222d48994 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -182,6 +182,9 @@ void Ship::UpdateCache()
/* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
this->vcache.cached_max_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed) * (256 - speed_frac) / 256;
+ /* Update cargo aging period. */
+ this->vcache.cached_cargo_age_period = GetVehicleProperty(this, PROP_SHIP_CARGO_AGE_PERIOD, EngInfo(this->engine_type)->cargo_age_period);
+
this->UpdateVisualEffect();
}
diff --git a/src/table/engines.h b/src/table/engines.h
index 5be991475..77574fd7a 100644
--- a/src/table/engines.h
+++ b/src/table/engines.h
@@ -26,7 +26,7 @@
* @param f Bitmask of the climates
* @note the 5 between b and f is the load amount
*/
-#define MT(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 1 << EF_RAIL_FLIPS, 0, 0, STR_EMPTY }
+#define MT(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 1 << EF_RAIL_FLIPS, 0, 0, STR_EMPTY, CARGO_AGING_TICKS }
/**
* Writes the properties of a train carriage into the EngineInfo struct.
@@ -39,7 +39,7 @@
* @see MT
* @note the 5 between b and f is the load amount
*/
-#define MW(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 1 << EF_RAIL_FLIPS, 0, 0, STR_EMPTY }
+#define MW(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 1 << EF_RAIL_FLIPS, 0, 0, STR_EMPTY, CARGO_AGING_TICKS }
/**
* Writes the properties of a road vehicle into the EngineInfo struct.
@@ -52,7 +52,7 @@
* @param f Bitmask of the climates
* @note the 5 between b and f is the load amount
*/
-#define MR(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 0, 0, 0, STR_EMPTY }
+#define MR(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, f, e, 0, 8, 0, 0, 0, STR_EMPTY, CARGO_AGING_TICKS }
/**
* Writes the properties of a ship into the EngineInfo struct.
@@ -64,7 +64,7 @@
* @param f Bitmask of the climates
* @note the 10 between b and f is the load amount
*/
-#define MS(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, f, e, 0, 8, 0, 0, 0, STR_EMPTY }
+#define MS(a, b, c, d, e, f) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, f, e, 0, 8, 0, 0, 0, STR_EMPTY, CARGO_AGING_TICKS }
/**
* Writes the properties of an aeroplane into the EngineInfo struct.
@@ -75,7 +75,7 @@
* @param e Bitmask of the climates
* @note the 20 between b and e is the load amount
*/
-#define MA(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, CT_INVALID, 0, 8, 0, 0, 0, STR_EMPTY }
+#define MA(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, CT_INVALID, 0, 8, 0, 0, 0, STR_EMPTY, CARGO_AGING_TICKS }
/* Climates
* T = Temperate
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 8db6490b9..149aa25da 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -233,6 +233,7 @@ void Train::ConsistChanged(bool same_length)
}
u->cargo_cap = GetVehicleCapacity(u);
+ u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_TRAIN_CARGO_AGE_PERIOD, e_u->info.cargo_age_period);
/* check the vehicle length (callback) */
uint16 veh_len = CALLBACK_FAILED;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index ccbb96068..ab1b4df2f 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -60,7 +60,6 @@
VehicleID _new_vehicle_id;
uint16 _returned_refit_capacity; ///< Stores the capacity after a refit operation.
uint16 _returned_mail_refit_capacity; ///< Stores the mail capacity after a refit operation (Aircraft only).
-byte _age_cargo_skip_counter; ///< Skip aging of cargo?
/** The pool with all our precious vehicles. */
@@ -245,6 +244,7 @@ Vehicle::Vehicle(VehicleType type)
this->fill_percent_te_id = INVALID_TE_ID;
this->first = this;
this->colourmap = PAL_NONE;
+ this->cargo_age_counter = 1;
}
/**
@@ -586,8 +586,6 @@ static AutoreplaceMap _vehicles_to_autoreplace;
void InitializeVehicles()
{
- _age_cargo_skip_counter = 1;
-
_vehicles_to_autoreplace.Reset();
ResetVehiclePosHash();
}
@@ -801,8 +799,6 @@ void CallVehicleTicks()
{
_vehicles_to_autoreplace.Clear();
- _age_cargo_skip_counter = (_age_cargo_skip_counter == 0) ? CARGO_AGING_TICKS - 1 : (_age_cargo_skip_counter - 1);
-
RunVehicleDayProc();
Station *st;
@@ -825,7 +821,13 @@ void CallVehicleTicks()
case VEH_ROAD:
case VEH_AIRCRAFT:
case VEH_SHIP:
- if (_age_cargo_skip_counter == 0) v->cargo.AgeCargo();
+ if (v->vcache.cached_cargo_age_period != 0) {
+ v->cargo_age_counter = min(v->cargo_age_counter, v->vcache.cached_cargo_age_period);
+ if (--v->cargo_age_counter == 0) {
+ v->cargo.AgeCargo();
+ v->cargo_age_counter = v->vcache.cached_cargo_age_period;
+ }
+ }
if (v->type == VEH_TRAIN && Train::From(v)->IsWagon()) continue;
if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue;
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 6781b472d..547344c27 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -100,7 +100,8 @@ enum GroundVehicleSubtypeFlags {
/** Cached often queried values common to all vehicles. */
struct VehicleCache {
- uint16 cached_max_speed; ///< Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
+ uint16 cached_max_speed; ///< Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
+ uint16 cached_cargo_age_period; ///< Number of ticks before carried cargo is aged.
byte cached_vis_effect; ///< Visual effect to show (see #VisualEffect)
};
@@ -213,6 +214,7 @@ public:
byte cargo_subtype; ///< Used for livery refits (NewGRF variations)
uint16 cargo_cap; ///< total capacity
VehicleCargoList cargo; ///< The cargo this vehicle is carrying
+ uint16 cargo_age_counter; ///< Ticks till cargo is aged next.
byte day_counter; ///< Increased by one for each day
byte tick_counter; ///< Increased by one for each tick
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index ec341163e..fdb9fd66c 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -30,6 +30,7 @@
#include "autoreplace_gui.h"
#include "company_base.h"
#include "order_backup.h"
+#include "ship.h"
#include "table/strings.h"
@@ -373,9 +374,15 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
break;
case VEH_SHIP:
+ v->InvalidateNewGRFCacheOfChain();
+ v->colourmap = PAL_NONE; // invalidate vehicle colour map
+ Ship::From(v)->UpdateCache();
+ break;
+
case VEH_AIRCRAFT:
v->InvalidateNewGRFCacheOfChain();
v->colourmap = PAL_NONE; // invalidate vehicle colour map
+ UpdateAircraftCache(Aircraft::From(v));
break;
default: NOT_REACHED();
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index ebdb5f343..166c0b9cf 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -161,7 +161,6 @@ CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
extern VehicleID _new_vehicle_id;
extern uint16 _returned_refit_capacity;
extern uint16 _returned_mail_refit_capacity;
-extern byte _age_cargo_skip_counter;
bool CanVehicleUseStation(EngineID engine_type, const struct Station *st);
bool CanVehicleUseStation(const Vehicle *v, const struct Station *st);