mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use economy dates for industry production changes and closures
parent
c8468812d6
commit
8601dd5a4f
|
@ -1081,7 +1081,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
|
||||||
|
|
||||||
uint amount = std::min(num_pieces, 0xFFFFu - it->waiting);
|
uint amount = std::min(num_pieces, 0xFFFFu - it->waiting);
|
||||||
it->waiting += amount;
|
it->waiting += amount;
|
||||||
it->last_accepted = TimerGameCalendar::date;
|
it->last_accepted = TimerGameEconomy::date;
|
||||||
num_pieces -= amount;
|
num_pieces -= amount;
|
||||||
accepted += amount;
|
accepted += amount;
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
#include "tilearea_type.h"
|
#include "tilearea_type.h"
|
||||||
#include "station_base.h"
|
#include "station_base.h"
|
||||||
#include "timer/timer_game_calendar.h"
|
#include "timer/timer_game_calendar.h"
|
||||||
|
#include "timer/timer_game_economy.h"
|
||||||
|
|
||||||
|
|
||||||
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
|
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
|
||||||
extern IndustryPool _industry_pool;
|
extern IndustryPool _industry_pool;
|
||||||
|
|
||||||
static const TimerGameCalendar::Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS = 5; ///< If a processing industry doesn't produce for this many consecutive years, it may close.
|
static const TimerGameEconomy::Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS = 5; ///< If a processing industry doesn't produce for this many consecutive economy years, it may close.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Production level maximum, minimum and default values.
|
* Production level maximum, minimum and default values.
|
||||||
|
@ -86,7 +87,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
|
||||||
struct AcceptedCargo {
|
struct AcceptedCargo {
|
||||||
CargoID cargo; ///< Cargo type
|
CargoID cargo; ///< Cargo type
|
||||||
uint16_t waiting; ///< Amount of cargo waiting to processed
|
uint16_t waiting; ///< Amount of cargo waiting to processed
|
||||||
TimerGameCalendar::Date last_accepted; ///< Last day cargo was accepted by this industry
|
TimerGameEconomy::Date last_accepted; ///< Last day cargo was accepted by this industry
|
||||||
};
|
};
|
||||||
|
|
||||||
using ProducedCargoArray = std::array<ProducedCargo, INDUSTRY_NUM_OUTPUTS>;
|
using ProducedCargoArray = std::array<ProducedCargo, INDUSTRY_NUM_OUTPUTS>;
|
||||||
|
@ -103,7 +104,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
|
||||||
IndustryType type; ///< type of industry.
|
IndustryType type; ///< type of industry.
|
||||||
Owner owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
|
Owner owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
|
||||||
byte random_colour; ///< randomized colour of the industry, for display purpose
|
byte random_colour; ///< randomized colour of the industry, for display purpose
|
||||||
TimerGameCalendar::Year last_prod_year; ///< last year of production
|
TimerGameEconomy::Year last_prod_year; ///< last economy year of production
|
||||||
byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
|
byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
|
||||||
IndustryControlFlags ctlflags; ///< flags overriding standard behaviours
|
IndustryControlFlags ctlflags; ///< flags overriding standard behaviours
|
||||||
|
|
||||||
|
|
|
@ -1783,7 +1783,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||||
i->counter = GB(r, 4, 12);
|
i->counter = GB(r, 4, 12);
|
||||||
i->random = initial_random_bits;
|
i->random = initial_random_bits;
|
||||||
i->was_cargo_delivered = false;
|
i->was_cargo_delivered = false;
|
||||||
i->last_prod_year = TimerGameCalendar::year;
|
i->last_prod_year = TimerGameEconomy::year;
|
||||||
i->founder = founder;
|
i->founder = founder;
|
||||||
i->ctlflags = INDCTL_NONE;
|
i->ctlflags = INDCTL_NONE;
|
||||||
|
|
||||||
|
@ -2466,7 +2466,7 @@ static void UpdateIndustryStatistics(Industry *i)
|
||||||
{
|
{
|
||||||
for (auto &p : i->produced) {
|
for (auto &p : i->produced) {
|
||||||
if (IsValidCargoID(p.cargo)) {
|
if (IsValidCargoID(p.cargo)) {
|
||||||
if (p.history[THIS_MONTH].production != 0) i->last_prod_year = TimerGameCalendar::year;
|
if (p.history[THIS_MONTH].production != 0) i->last_prod_year = TimerGameEconomy::year;
|
||||||
|
|
||||||
/* Move history from this month to last month. */
|
/* Move history from this month to last month. */
|
||||||
std::rotate(std::rbegin(p.history), std::rbegin(p.history) + 1, std::rend(p.history));
|
std::rotate(std::rbegin(p.history), std::rbegin(p.history) + 1, std::rend(p.history));
|
||||||
|
@ -2889,7 +2889,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!callback_enabled && (indspec->life_type & INDUSTRYLIFE_PROCESSING)) {
|
if (!callback_enabled && (indspec->life_type & INDUSTRYLIFE_PROCESSING)) {
|
||||||
if (TimerGameCalendar::year - i->last_prod_year >= PROCESSING_INDUSTRY_ABANDONMENT_YEARS && Chance16(1, original_economy ? 2 : 180)) {
|
if (TimerGameEconomy::year - i->last_prod_year >= PROCESSING_INDUSTRY_ABANDONMENT_YEARS && Chance16(1, original_economy ? 2 : 180)) {
|
||||||
closeit = true;
|
closeit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,7 +396,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte layo
|
||||||
case 0xA6: return indspec->grf_prop.local_id;
|
case 0xA6: return indspec->grf_prop.local_id;
|
||||||
case 0xA7: return this->industry->founder;
|
case 0xA7: return this->industry->founder;
|
||||||
case 0xA8: return this->industry->random_colour;
|
case 0xA8: return this->industry->random_colour;
|
||||||
case 0xA9: return ClampTo<uint8_t>(this->industry->last_prod_year - CalendarTime::ORIGINAL_BASE_YEAR);
|
case 0xA9: return ClampTo<uint8_t>(this->industry->last_prod_year - EconomyTime::ORIGINAL_BASE_YEAR);
|
||||||
case 0xAA: return this->industry->counter;
|
case 0xAA: return this->industry->counter;
|
||||||
case 0xAB: return GB(this->industry->counter, 8, 8);
|
case 0xAB: return GB(this->industry->counter, 8, 8);
|
||||||
case 0xAC: return this->industry->was_cargo_delivered;
|
case 0xAC: return this->industry->was_cargo_delivered;
|
||||||
|
@ -405,7 +405,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte layo
|
||||||
case 0xB3: return this->industry->construction_type; // Construction type
|
case 0xB3: return this->industry->construction_type; // Construction type
|
||||||
case 0xB4: {
|
case 0xB4: {
|
||||||
auto it = std::max_element(std::begin(this->industry->accepted), std::end(this->industry->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; });
|
auto it = std::max_element(std::begin(this->industry->accepted), std::end(this->industry->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; });
|
||||||
return ClampTo<uint16_t>(it->last_accepted - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days)
|
return ClampTo<uint16_t>(it->last_accepted - EconomyTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -844,7 +844,7 @@ static void OnStartScenario()
|
||||||
|
|
||||||
/* Make sure all industries were built "this year", to avoid too early closures. (#9918) */
|
/* Make sure all industries were built "this year", to avoid too early closures. (#9918) */
|
||||||
for (Industry *i : Industry::Iterate()) {
|
for (Industry *i : Industry::Iterate()) {
|
||||||
i->last_prod_year = TimerGameCalendar::year;
|
i->last_prod_year = TimerGameEconomy::year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1437,8 +1437,8 @@ bool AfterLoadGame()
|
||||||
for (Station *st : Station::Iterate()) st->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
for (Station *st : Station::Iterate()) st->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||||
for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||||
for (Engine *e : Engine::Iterate()) e->intro_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
for (Engine *e : Engine::Iterate()) e->intro_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||||
for (Company *c : Company::Iterate()) c->inaugurated_year += CalendarTime::ORIGINAL_BASE_YEAR;
|
for (Company *c : Company::Iterate()) c->inaugurated_year += EconomyTime::ORIGINAL_BASE_YEAR;
|
||||||
for (Industry *i : Industry::Iterate()) i->last_prod_year += CalendarTime::ORIGINAL_BASE_YEAR;
|
for (Industry *i : Industry::Iterate()) i->last_prod_year += EconomyTime::ORIGINAL_BASE_YEAR;
|
||||||
|
|
||||||
for (Vehicle *v : Vehicle::Iterate()) {
|
for (Vehicle *v : Vehicle::Iterate()) {
|
||||||
v->date_of_last_service += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
v->date_of_last_service += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||||
|
|
|
@ -50,12 +50,12 @@ public:
|
||||||
/* Old array structure used for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
|
/* Old array structure used for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
|
||||||
static CargoID old_cargo[INDUSTRY_NUM_INPUTS];
|
static CargoID old_cargo[INDUSTRY_NUM_INPUTS];
|
||||||
static uint16_t old_waiting[INDUSTRY_NUM_INPUTS];
|
static uint16_t old_waiting[INDUSTRY_NUM_INPUTS];
|
||||||
static TimerGameCalendar::Date old_last_accepted[INDUSTRY_NUM_INPUTS];
|
static TimerGameEconomy::Date old_last_accepted[INDUSTRY_NUM_INPUTS];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* static */ CargoID SlIndustryAccepted::old_cargo[INDUSTRY_NUM_INPUTS];
|
/* static */ CargoID SlIndustryAccepted::old_cargo[INDUSTRY_NUM_INPUTS];
|
||||||
/* static */ uint16_t SlIndustryAccepted::old_waiting[INDUSTRY_NUM_INPUTS];
|
/* static */ uint16_t SlIndustryAccepted::old_waiting[INDUSTRY_NUM_INPUTS];
|
||||||
/* static */ TimerGameCalendar::Date SlIndustryAccepted::old_last_accepted[INDUSTRY_NUM_INPUTS];
|
/* static */ TimerGameEconomy::Date SlIndustryAccepted::old_last_accepted[INDUSTRY_NUM_INPUTS];
|
||||||
|
|
||||||
class SlIndustryProducedHistory : public DefaultSaveLoadHandler<SlIndustryProducedHistory, Industry::ProducedCargo> {
|
class SlIndustryProducedHistory : public DefaultSaveLoadHandler<SlIndustryProducedHistory, Industry::ProducedCargo> {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -844,8 +844,8 @@ static bool LoadOldIndustry(LoadgameState *ls, int num)
|
||||||
if (i->type > 0x06) i->type++; // Printing Works were added
|
if (i->type > 0x06) i->type++; // Printing Works were added
|
||||||
if (i->type == 0x0A) i->type = 0x12; // Iron Ore Mine has different ID
|
if (i->type == 0x0A) i->type = 0x12; // Iron Ore Mine has different ID
|
||||||
|
|
||||||
TimerGameCalendar::YearMonthDay ymd;
|
TimerGameEconomy::YearMonthDay ymd;
|
||||||
TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
|
TimerGameEconomy::ConvertDateToYMD(TimerGameEconomy::date, &ymd);
|
||||||
i->last_prod_year = ymd.year;
|
i->last_prod_year = ymd.year;
|
||||||
|
|
||||||
i->random_colour = RemapTTOColour(i->random_colour);
|
i->random_colour = RemapTTOColour(i->random_colour);
|
||||||
|
|
Loading…
Reference in New Issue