mirror of https://github.com/OpenTTD/OpenTTD
Merge c86a9e9bfb
into a46a3a97f3
commit
3b483de08b
|
@ -1070,6 +1070,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoType cargo_type, uint
|
|||
|
||||
uint amount = std::min(num_pieces, 0xFFFFu - it->waiting);
|
||||
it->waiting += amount;
|
||||
it->history[THIS_MONTH].accepted += amount;
|
||||
it->last_accepted = TimerGameEconomy::date;
|
||||
num_pieces -= amount;
|
||||
accepted += amount;
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
/** @file graph_gui.cpp GUI that shows performance graphs. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <ranges>
|
||||
#include "misc/history_func.hpp"
|
||||
#include "graph_gui.h"
|
||||
#include "window_gui.h"
|
||||
#include "company_base.h"
|
||||
|
@ -173,6 +175,7 @@ protected:
|
|||
static const int GRAPH_PAYMENT_RATE_STEPS = 20; ///< Number of steps on Payment rate graph.
|
||||
static const int PAYMENT_GRAPH_X_STEP_DAYS = 10; ///< X-axis step label for cargo payment rates "Days in transit".
|
||||
static const int PAYMENT_GRAPH_X_STEP_SECONDS = 20; ///< X-axis step label for cargo payment rates "Seconds in transit".
|
||||
static const int ECONOMY_YEAR_MINUTES = 12; ///< Minutes per economic year.
|
||||
static const int ECONOMY_QUARTER_MINUTES = 3; ///< Minutes per economic quarter.
|
||||
static const int ECONOMY_MONTH_MINUTES = 1; ///< Minutes per economic month.
|
||||
|
||||
|
@ -181,8 +184,27 @@ protected:
|
|||
static const int MIN_GRAPH_NUM_LINES_Y = 9; ///< Minimal number of horizontal lines to draw.
|
||||
static const int MIN_GRID_PIXEL_SIZE = 20; ///< Minimum distance between graph lines.
|
||||
|
||||
uint64_t excluded_data = 0; ///< bitmask of the datasets that shouldn't be displayed.
|
||||
uint64_t excluded_range = 0; ///< bitmask of ranges that should not be displayed.
|
||||
struct GraphScale {
|
||||
StringID label = STR_NULL;
|
||||
uint8_t month_increment = 0;
|
||||
int16_t x_values_increment = 0;
|
||||
};
|
||||
|
||||
static inline constexpr GraphScale MONTHLY_SCALE_WALLCLOCK[] = {
|
||||
{STR_GRAPH_LAST_24_MINUTES_TIME_LABEL, HISTORY_MONTH.total_division, ECONOMY_MONTH_MINUTES},
|
||||
{STR_GRAPH_LAST_72_MINUTES_TIME_LABEL, HISTORY_QUARTER.total_division, ECONOMY_QUARTER_MINUTES},
|
||||
{STR_GRAPH_LAST_288_MINUTES_TIME_LABEL, HISTORY_YEAR.total_division, ECONOMY_YEAR_MINUTES},
|
||||
};
|
||||
|
||||
static inline constexpr GraphScale MONTHLY_SCALE_CALENDAR[] = {
|
||||
{STR_GRAPH_LAST_24_MONTHS, HISTORY_MONTH.total_division, ECONOMY_MONTH_MINUTES},
|
||||
{STR_GRAPH_LAST_24_QUARTERS, HISTORY_QUARTER.total_division, ECONOMY_QUARTER_MINUTES},
|
||||
{STR_GRAPH_LAST_24_YEARS, HISTORY_YEAR.total_division, ECONOMY_YEAR_MINUTES},
|
||||
};
|
||||
|
||||
uint64_t excluded_data = 0; ///< bitmask of datasets hidden by the player.
|
||||
uint64_t excluded_range = 0; ///< bitmask of ranges hidden by the player.
|
||||
uint64_t masked_range = 0; ///< bitmask of ranges that are not available for the current data.
|
||||
uint8_t num_on_x_axis = 0;
|
||||
uint8_t num_vert_lines = GRAPH_NUM_MONTHS;
|
||||
|
||||
|
@ -209,12 +231,22 @@ protected:
|
|||
};
|
||||
std::vector<DataSet> data{};
|
||||
|
||||
std::span<const StringID> ranges = {};
|
||||
std::span<const StringID> ranges{};
|
||||
std::span<const GraphScale> scales{};
|
||||
uint8_t selected_scale = 0;
|
||||
|
||||
uint8_t highlight_data = UINT8_MAX; ///< Data set that should be highlighted, or UINT8_MAX for none.
|
||||
uint8_t highlight_range = UINT8_MAX; ///< Data range that should be highlighted, or UINT8_MAX for none.
|
||||
bool highlight_state = false; ///< Current state of highlight, toggled every TIMER_BLINK_INTERVAL period.
|
||||
|
||||
template <typename Tprojection>
|
||||
struct Filler {
|
||||
DataSet &dataset; ///< Dataset to fill.
|
||||
const Tprojection &proj; ///< Projection to apply.
|
||||
|
||||
inline void Fill(uint i, const auto &data) const { this->dataset.values[i] = std::invoke(this->proj, data); }
|
||||
};
|
||||
|
||||
/**
|
||||
* Get appropriate part of dataset values for the current number of horizontal points.
|
||||
* @param dataset Dataset to get values of
|
||||
|
@ -597,24 +629,34 @@ protected:
|
|||
this->SetDirty();
|
||||
}};
|
||||
|
||||
void UpdateMatrixSize(WidgetID widget, Dimension &size, Dimension &resize, auto labels)
|
||||
{
|
||||
size = {};
|
||||
for (const StringID &str : labels) {
|
||||
size = maxdim(size, GetStringBoundingBox(str, FS_SMALL));
|
||||
}
|
||||
|
||||
size.width += WidgetDimensions::scaled.framerect.Horizontal();
|
||||
size.height += WidgetDimensions::scaled.framerect.Vertical();
|
||||
|
||||
/* Set fixed height for number of ranges. */
|
||||
size.height *= static_cast<uint>(std::size(labels));
|
||||
|
||||
resize.width = 0;
|
||||
resize.height = 0;
|
||||
this->GetWidget<NWidgetCore>(widget)->SetMatrixDimension(1, ClampTo<uint32_t>(std::size(labels)));
|
||||
}
|
||||
|
||||
public:
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_GRAPH_RANGE_MATRIX:
|
||||
for (const StringID &str : this->ranges) {
|
||||
size = maxdim(size, GetStringBoundingBox(str, FS_SMALL));
|
||||
}
|
||||
this->UpdateMatrixSize(widget, size, resize, this->ranges);
|
||||
break;
|
||||
|
||||
size.width += WidgetDimensions::scaled.framerect.Horizontal();
|
||||
size.height += WidgetDimensions::scaled.framerect.Vertical();
|
||||
|
||||
/* Set fixed height for number of ranges. */
|
||||
size.height *= static_cast<uint>(std::size(this->ranges));
|
||||
|
||||
resize.width = 0;
|
||||
resize.height = 0;
|
||||
this->GetWidget<NWidgetCore>(WID_GRAPH_RANGE_MATRIX)->SetMatrixDimension(1, ClampTo<uint32_t>(std::size(this->ranges)));
|
||||
case WID_GRAPH_SCALE_MATRIX:
|
||||
this->UpdateMatrixSize(widget, size, resize, this->scales | std::views::transform(&GraphScale::label));
|
||||
break;
|
||||
|
||||
case WID_GRAPH_GRAPH: {
|
||||
|
@ -663,13 +705,17 @@ public:
|
|||
uint index = 0;
|
||||
Rect line = r.WithHeight(line_height);
|
||||
for (const auto &str : this->ranges) {
|
||||
bool lowered = !HasBit(this->excluded_range, index);
|
||||
bool lowered = !HasBit(this->excluded_range, index) && !HasBit(this->masked_range, index);
|
||||
|
||||
/* Redraw frame if lowered */
|
||||
if (lowered) DrawFrameRect(line, COLOUR_BROWN, FrameFlag::Lowered);
|
||||
|
||||
const Rect text = line.Shrink(WidgetDimensions::scaled.framerect);
|
||||
DrawString(text, str, TC_BLACK, SA_CENTER, false, FS_SMALL);
|
||||
DrawString(text, str, (this->highlight_state && this->highlight_range == index) ? TC_WHITE : TC_BLACK, SA_CENTER, false, FS_SMALL);
|
||||
|
||||
if (HasBit(this->masked_range, index)) {
|
||||
GfxFillRect(line.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(COLOUR_BROWN, SHADE_DARKER), FILLRECT_CHECKER);
|
||||
}
|
||||
|
||||
line = line.Translate(0, line_height);
|
||||
++index;
|
||||
|
@ -677,6 +723,21 @@ public:
|
|||
break;
|
||||
}
|
||||
|
||||
case WID_GRAPH_SCALE_MATRIX: {
|
||||
uint line_height = GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical();
|
||||
uint8_t selected_month_increment = this->scales[this->selected_scale].month_increment;
|
||||
Rect line = r.WithHeight(line_height);
|
||||
for (const auto &scale : this->scales) {
|
||||
/* Redraw frame if selected */
|
||||
if (selected_month_increment == scale.month_increment) DrawFrameRect(line, COLOUR_BROWN, FrameFlag::Lowered);
|
||||
|
||||
DrawString(line.Shrink(WidgetDimensions::scaled.framerect), scale.label, TC_BLACK, SA_CENTER, false, FS_SMALL);
|
||||
|
||||
line = line.Translate(0, line_height);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
@ -692,11 +753,24 @@ public:
|
|||
case WID_GRAPH_RANGE_MATRIX: {
|
||||
int row = GetRowFromWidget(pt.y, widget, 0, GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical());
|
||||
|
||||
if (HasBit(this->masked_range, row)) break;
|
||||
ToggleBit(this->excluded_range, row);
|
||||
this->SetDirty();
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_GRAPH_SCALE_MATRIX: {
|
||||
int row = GetRowFromWidget(pt.y, widget, 0, GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical());
|
||||
const auto &scale = this->scales[row];
|
||||
if (this->selected_scale != row) {
|
||||
this->selected_scale = row;
|
||||
this->month_increment = scale.month_increment;
|
||||
this->x_values_increment = scale.x_values_increment;
|
||||
this->InvalidateData();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
@ -1103,6 +1177,7 @@ struct BaseCargoGraphWindow : BaseGraphWindow {
|
|||
{
|
||||
this->CreateNestedTree();
|
||||
|
||||
this->excluded_range = this->masked_range;
|
||||
this->cargo_types = this->GetCargoTypes(number);
|
||||
|
||||
this->vscroll = this->GetScrollbar(WID_GRAPH_MATRIX_SCROLLBAR);
|
||||
|
@ -1596,7 +1671,9 @@ CompanyID PerformanceRatingDetailWindow::company = CompanyID::Invalid();
|
|||
struct IndustryProductionGraphWindow : BaseCargoGraphWindow {
|
||||
static inline constexpr StringID RANGE_LABELS[] = {
|
||||
STR_GRAPH_INDUSTRY_RANGE_PRODUCED,
|
||||
STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED
|
||||
STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED,
|
||||
STR_GRAPH_INDUSTRY_RANGE_DELIVERED,
|
||||
STR_GRAPH_INDUSTRY_RANGE_WAITING,
|
||||
};
|
||||
|
||||
static inline CargoTypes excluded_cargo_types{};
|
||||
|
@ -1611,13 +1688,27 @@ struct IndustryProductionGraphWindow : BaseCargoGraphWindow {
|
|||
this->draw_dates = !TimerGameEconomy::UsingWallclockUnits();
|
||||
this->ranges = RANGE_LABELS;
|
||||
|
||||
const Industry *i = Industry::Get(window_number);
|
||||
if (!i->IsCargoProduced()) this->masked_range = (1U << 0) | (1U << 1);
|
||||
if (!i->IsCargoAccepted()) this->masked_range = (1U << 2) | (1U << 3);
|
||||
|
||||
this->InitializeWindow(window_number, STR_GRAPH_LAST_24_MINUTES_TIME_LABEL);
|
||||
}
|
||||
|
||||
void OnInit() override
|
||||
{
|
||||
this->BaseCargoGraphWindow::OnInit();
|
||||
|
||||
this->scales = TimerGameEconomy::UsingWallclockUnits() ? MONTHLY_SCALE_WALLCLOCK : MONTHLY_SCALE_CALENDAR;
|
||||
}
|
||||
|
||||
CargoTypes GetCargoTypes(WindowNumber window_number) const override
|
||||
{
|
||||
CargoTypes cargo_types{};
|
||||
const Industry *i = Industry::Get(window_number);
|
||||
for (const auto &a : i->accepted) {
|
||||
if (IsValidCargoType(a.cargo)) SetBit(cargo_types, a.cargo);
|
||||
}
|
||||
for (const auto &p : i->produced) {
|
||||
if (IsValidCargoType(p.cargo)) SetBit(cargo_types, p.cargo);
|
||||
}
|
||||
|
@ -1631,7 +1722,7 @@ struct IndustryProductionGraphWindow : BaseCargoGraphWindow {
|
|||
|
||||
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
|
||||
{
|
||||
if (widget == WID_GRAPH_CAPTION) return GetString(STR_GRAPH_INDUSTRY_PRODUCTION_CAPTION, this->window_number);
|
||||
if (widget == WID_GRAPH_CAPTION) return GetString(STR_GRAPH_INDUSTRY_CAPTION, this->window_number);
|
||||
|
||||
return this->Window::GetWidgetString(widget, stringid);
|
||||
}
|
||||
|
@ -1661,24 +1752,41 @@ struct IndustryProductionGraphWindow : BaseCargoGraphWindow {
|
|||
if (!IsValidCargoType(p.cargo)) continue;
|
||||
const CargoSpec *cs = CargoSpec::Get(p.cargo);
|
||||
|
||||
this->data.reserve(this->data.size() + 2);
|
||||
|
||||
DataSet &produced = this->data.emplace_back();
|
||||
produced.colour = cs->legend_colour;
|
||||
produced.exclude_bit = cs->Index();
|
||||
produced.range_bit = 0;
|
||||
|
||||
for (uint j = 0; j < GRAPH_NUM_MONTHS; j++) {
|
||||
produced.values[j] = p.history[GRAPH_NUM_MONTHS - j].production;
|
||||
}
|
||||
|
||||
DataSet &transported = this->data.emplace_back();
|
||||
transported.colour = cs->legend_colour;
|
||||
transported.exclude_bit = cs->Index();
|
||||
transported.range_bit = 1;
|
||||
transported.dash = 2;
|
||||
|
||||
for (uint j = 0; j < GRAPH_NUM_MONTHS; j++) {
|
||||
transported.values[j] = p.history[GRAPH_NUM_MONTHS - j].transported;
|
||||
}
|
||||
FillFromHistory<GRAPH_NUM_MONTHS>(p.history, this->selected_scale, Filler{produced, &Industry::ProducedHistory::production}, Filler{transported, &Industry::ProducedHistory::transported});
|
||||
}
|
||||
|
||||
for (const auto &a : i->accepted) {
|
||||
if (!IsValidCargoType(a.cargo)) continue;
|
||||
const CargoSpec *cs = CargoSpec::Get(a.cargo);
|
||||
|
||||
this->data.reserve(this->data.size() + 2);
|
||||
|
||||
DataSet &accepted = this->data.emplace_back();
|
||||
accepted.colour = cs->legend_colour;
|
||||
accepted.exclude_bit = cs->Index();
|
||||
accepted.range_bit = 2;
|
||||
accepted.dash = 1;
|
||||
|
||||
DataSet &waiting = this->data.emplace_back();
|
||||
waiting.colour = cs->legend_colour;
|
||||
waiting.exclude_bit = cs->Index();
|
||||
waiting.range_bit = 3;
|
||||
waiting.dash = 4;
|
||||
|
||||
FillFromHistory<GRAPH_NUM_MONTHS>(a.history, this->selected_scale, Filler{accepted, &Industry::AcceptedHistory::accepted}, Filler{waiting, &Industry::AcceptedHistory::waiting});
|
||||
}
|
||||
|
||||
this->SetDirty();
|
||||
|
@ -1698,7 +1806,7 @@ static constexpr NWidgetPart _nested_industry_production_widgets[] = {
|
|||
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GRAPH_GRAPH), SetMinimalSize(495, 0), SetFill(1, 1), SetResize(1, 1),
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
|
||||
NWidget(WWT_MATRIX, COLOUR_BROWN, WID_GRAPH_RANGE_MATRIX), SetFill(1, 0), SetResize(0, 0), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO),
|
||||
NWidget(WWT_MATRIX, COLOUR_BROWN, WID_GRAPH_RANGE_MATRIX), SetFill(1, 0), SetResize(0, 0), SetMatrixDataTip(1, 0, STR_GRAPH_TOGGLE_RANGE),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_ENABLE_CARGOES), SetStringTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GRAPH_DISABLE_CARGOES), SetStringTip(STR_GRAPH_CARGO_DISABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL), SetFill(1, 0),
|
||||
|
@ -1707,6 +1815,8 @@ static constexpr NWidgetPart _nested_industry_production_widgets[] = {
|
|||
NWidget(WWT_MATRIX, COLOUR_BROWN, WID_GRAPH_MATRIX), SetFill(1, 0), SetResize(0, 2), SetMatrixDataTip(1, 0, STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO), SetScrollbar(WID_GRAPH_MATRIX_SCROLLBAR),
|
||||
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GRAPH_MATRIX_SCROLLBAR),
|
||||
EndContainer(),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(0, 4),
|
||||
NWidget(WWT_MATRIX, COLOUR_BROWN, WID_GRAPH_SCALE_MATRIX), SetFill(1, 0), SetResize(0, 0), SetMatrixDataTip(1, 0, STR_GRAPH_SELECT_SCALE),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(0, 24), SetFill(0, 1),
|
||||
EndContainer(),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(5, 0), SetFill(0, 1), SetResize(0, 1),
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#define INDUSTRY_H
|
||||
|
||||
#include "core/flatset_type.hpp"
|
||||
#include "misc/history_type.hpp"
|
||||
#include "newgrf_storage.h"
|
||||
#include "subsidy_type.h"
|
||||
#include "industry_map.h"
|
||||
|
@ -55,9 +56,6 @@ enum class IndustryControlFlag : uint8_t {
|
|||
};
|
||||
using IndustryControlFlags = EnumBitSet<IndustryControlFlag, uint8_t, IndustryControlFlag::End>;
|
||||
|
||||
static const int THIS_MONTH = 0;
|
||||
static const int LAST_MONTH = 1;
|
||||
|
||||
/**
|
||||
* Defines the internal data of a functional industry.
|
||||
*/
|
||||
|
@ -72,18 +70,24 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
|
|||
return ClampTo<uint8_t>(this->transported * 256 / this->production);
|
||||
}
|
||||
};
|
||||
|
||||
struct ProducedCargo {
|
||||
CargoType cargo = 0; ///< Cargo type
|
||||
uint16_t waiting = 0; ///< Amount of cargo produced
|
||||
uint8_t rate = 0; ///< Production rate
|
||||
std::array<ProducedHistory, 25> history{}; ///< History of cargo produced and transported for this month and 24 previous months
|
||||
HistoryData<ProducedHistory> history{}; ///< History of cargo produced and transported for this month and 24 previous months
|
||||
};
|
||||
|
||||
struct AcceptedHistory {
|
||||
uint16_t accepted = 0; /// Total accepted.
|
||||
uint16_t waiting = 0; /// Average waiting.
|
||||
};
|
||||
|
||||
struct AcceptedCargo {
|
||||
CargoType cargo = 0; ///< Cargo type
|
||||
uint16_t waiting = 0; ///< Amount of cargo waiting to processed
|
||||
uint32_t accumulated_waiting = 0; ///< Accumulated waiting total over the last month, used to calculate average.
|
||||
TimerGameEconomy::Date last_accepted{}; ///< Last day cargo was accepted by this industry
|
||||
HistoryData<AcceptedHistory> history{}; ///< History of accepted and waiting cargo.
|
||||
};
|
||||
|
||||
using ProducedCargoes = std::vector<ProducedCargo>;
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
/** @file industry_cmd.cpp Handling of industry tiles. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "misc/history_type.hpp"
|
||||
#include "misc/history_func.hpp"
|
||||
#include "clear_map.h"
|
||||
#include "industry.h"
|
||||
#include "station_base.h"
|
||||
|
@ -1243,6 +1245,10 @@ void OnTick_Industry()
|
|||
|
||||
for (Industry *i : Industry::Iterate()) {
|
||||
ProduceIndustryGoods(i);
|
||||
|
||||
if ((TimerGameTick::counter + i->index) % Ticks::DAY_TICKS == 0) {
|
||||
for (auto &a : i->accepted) a.accumulated_waiting += a.waiting;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2486,22 +2492,45 @@ void GenerateIndustries()
|
|||
_industry_builder.Reset();
|
||||
}
|
||||
|
||||
template <>
|
||||
Industry::ProducedHistory SumHistory(std::span<Industry::ProducedHistory> history)
|
||||
{
|
||||
uint32_t production = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r, const auto &p) { return r + p.production; });
|
||||
uint32_t transported = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r, const auto &p) { return r + p.transported; });
|
||||
auto count = std::size(history);
|
||||
return {.production = ClampTo<uint16_t>(production / count), .transported = ClampTo<uint16_t>(transported / count)};
|
||||
}
|
||||
|
||||
template <>
|
||||
Industry::AcceptedHistory SumHistory(std::span<Industry::AcceptedHistory> history)
|
||||
{
|
||||
uint32_t accepted = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r, const auto &a) { return r + a.accepted; });
|
||||
uint32_t waiting = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r, const auto &a) { return r + a.waiting; });;
|
||||
auto count = std::size(history);
|
||||
return {.accepted = ClampTo<uint16_t>(accepted / count), .waiting = ClampTo<uint16_t>(waiting / count)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Monthly update of industry statistics.
|
||||
* @param i Industry to update.
|
||||
*/
|
||||
static void UpdateIndustryStatistics(Industry *i)
|
||||
{
|
||||
auto month = TimerGameEconomy::month;
|
||||
for (auto &p : i->produced) {
|
||||
if (IsValidCargoType(p.cargo)) {
|
||||
if (p.history[THIS_MONTH].production != 0) i->last_prod_year = TimerGameEconomy::year;
|
||||
|
||||
/* Move history from this month to last month. */
|
||||
std::rotate(std::rbegin(p.history), std::rbegin(p.history) + 1, std::rend(p.history));
|
||||
p.history[THIS_MONTH].production = 0;
|
||||
p.history[THIS_MONTH].transported = 0;
|
||||
RotateHistory(p.history, month);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &a : i->accepted) {
|
||||
if (!IsValidCargoType(a.cargo)) continue;
|
||||
a.history[THIS_MONTH].waiting = GetAndResetAccumulatedAverage<uint16_t>(a.accumulated_waiting);
|
||||
RotateHistory(a.history, month);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -845,7 +845,7 @@ public:
|
|||
nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ScaleZoomGUI(ZoomLevel::Industry));
|
||||
|
||||
const Industry *i = Industry::Get(window_number);
|
||||
if (!i->IsCargoProduced()) this->DisableWidget(WID_IV_GRAPH);
|
||||
if (!i->IsCargoProduced() && !i->IsCargoAccepted()) this->DisableWidget(WID_IV_GRAPH);
|
||||
|
||||
this->InvalidateData();
|
||||
}
|
||||
|
@ -1242,7 +1242,7 @@ static constexpr NWidgetPart _nested_industry_view_widgets[] = {
|
|||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_DISPLAY), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_INDUSTRY_DISPLAY_CHAIN, STR_INDUSTRY_DISPLAY_CHAIN_TOOLTIP),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_GRAPH), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_INDUSTRY_VIEW_PRODUCTION_GRAPH, STR_INDUSTRY_VIEW_PRODUCTION_GRAPH_TOOLTIP),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_CREAM, WID_IV_GRAPH), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_INDUSTRY_VIEW_CARGO_GRAPH, STR_INDUSTRY_VIEW_CARGO_GRAPH_TOOLTIP),
|
||||
NWidget(WWT_RESIZEBOX, COLOUR_CREAM),
|
||||
EndContainer(),
|
||||
};
|
||||
|
|
|
@ -621,6 +621,14 @@ STR_GRAPH_COMPANY_VALUES_CAPTION :{WHITE}Company
|
|||
|
||||
STR_GRAPH_LAST_24_MINUTES_TIME_LABEL :{TINY_FONT}{BLACK}Last 24 minutes
|
||||
STR_GRAPH_LAST_72_MINUTES_TIME_LABEL :{TINY_FONT}{BLACK}Last 72 minutes
|
||||
STR_GRAPH_LAST_288_MINUTES_TIME_LABEL :{TINY_FONT}{BLACK}Last 288 minutes
|
||||
|
||||
STR_GRAPH_LAST_24_MONTHS :{TINY_FONT}{BLACK}2 years (monthly)
|
||||
STR_GRAPH_LAST_24_QUARTERS :{TINY_FONT}{BLACK}6 years (quarterly)
|
||||
STR_GRAPH_LAST_24_YEARS :{TINY_FONT}{BLACK}24 years (yearly)
|
||||
|
||||
STR_GRAPH_TOGGLE_RANGE :Toggle graph for this data range
|
||||
STR_GRAPH_SELECT_SCALE :Change horizontal scale of graph
|
||||
|
||||
STR_GRAPH_CARGO_PAYMENT_RATES_CAPTION :{WHITE}Cargo Payment Rates
|
||||
STR_GRAPH_CARGO_PAYMENT_RATES_DAYS :{TINY_FONT}{BLACK}Days in transit
|
||||
|
@ -633,9 +641,11 @@ STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL :{BLACK}Display
|
|||
STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO :{BLACK}Toggle graph of this cargo type
|
||||
STR_GRAPH_CARGO_PAYMENT_CARGO :{TINY_FONT}{BLACK}{STRING}
|
||||
|
||||
STR_GRAPH_INDUSTRY_PRODUCTION_CAPTION :{WHITE}{INDUSTRY} - Production History
|
||||
STR_GRAPH_INDUSTRY_CAPTION :{WHITE}{INDUSTRY} - Cargo History
|
||||
STR_GRAPH_INDUSTRY_RANGE_PRODUCED :Produced
|
||||
STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED :Transported
|
||||
STR_GRAPH_INDUSTRY_RANGE_DELIVERED :Delivered
|
||||
STR_GRAPH_INDUSTRY_RANGE_WAITING :Waiting
|
||||
|
||||
STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP :{BLACK}Show detailed performance ratings
|
||||
|
||||
|
@ -4016,8 +4026,8 @@ STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE :{BLACK}Producti
|
|||
STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE :{BLACK}Production last minute:
|
||||
STR_INDUSTRY_VIEW_TRANSPORTED :{YELLOW}{CARGO_LONG}{RAW_STRING}{BLACK} ({COMMA}% transported)
|
||||
STR_INDUSTRY_VIEW_LOCATION_TOOLTIP :{BLACK}Centre the main view on industry location. Ctrl+Click to open a new viewport on industry location
|
||||
STR_INDUSTRY_VIEW_PRODUCTION_GRAPH :{BLACK}Production Graph
|
||||
STR_INDUSTRY_VIEW_PRODUCTION_GRAPH_TOOLTIP :{BLACK}Shows the graph of industry production history
|
||||
STR_INDUSTRY_VIEW_CARGO_GRAPH :{BLACK}Cargo Graph
|
||||
STR_INDUSTRY_VIEW_CARGO_GRAPH_TOOLTIP :{BLACK}Shows the graph of industry cargo history
|
||||
STR_INDUSTRY_VIEW_PRODUCTION_LEVEL :{BLACK}Production level: {YELLOW}{COMMA}%
|
||||
STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE :{YELLOW}The industry has announced imminent closure!
|
||||
|
||||
|
|
|
@ -8,5 +8,7 @@ add_files(
|
|||
getoptdata.cpp
|
||||
getoptdata.h
|
||||
hashtable.hpp
|
||||
history_func.hpp
|
||||
history_type.hpp
|
||||
lrucache.hpp
|
||||
)
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file history_func.hpp Functions for storing historical data. */
|
||||
|
||||
#ifndef HISTORY_FUNC_HPP
|
||||
#define HISTORY_FUNC_HPP
|
||||
|
||||
#include "../core/math_func.hpp"
|
||||
|
||||
#include "../timer/timer_game_economy.h"
|
||||
#include "history_type.hpp"
|
||||
|
||||
/**
|
||||
* Sum history data between first and last elements.
|
||||
* @note The summation should prevent overflowing, and perform transformations relevant to the type of data.
|
||||
* @tparam T type of history data element.
|
||||
* @param first First element to sum.
|
||||
* @param last Last element to sum.
|
||||
* @return Sum of history elements.
|
||||
*/
|
||||
template <typename T>
|
||||
T SumHistory(typename std::span<T> first);
|
||||
|
||||
/**
|
||||
* Rotate history.
|
||||
* @tparam T type of history data element.
|
||||
* @param history Historical data to rotate.
|
||||
*/
|
||||
template <typename T>
|
||||
void RotateHistory(HistoryData<T> &history, const HistoryRange &hr, uint age)
|
||||
{
|
||||
if (age % hr.total_division != 0) return;
|
||||
|
||||
std::move_backward(std::next(std::begin(history), hr.first), std::next(std::begin(history), hr.last - 1), std::next(std::begin(history), hr.last));
|
||||
|
||||
if (hr.division == 1) {
|
||||
history[hr.first] = history[hr.first - 1];
|
||||
} else {
|
||||
auto first = std::next(std::begin(history), hr.first - hr.division);
|
||||
auto last = std::next(first, hr.division);
|
||||
history[hr.first] = SumHistory<T>(std::span{first, last});
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void RotateHistory(HistoryData<T> &history, uint age)
|
||||
{
|
||||
RotateHistory(history, HISTORY_MONTH, age);
|
||||
RotateHistory(history, HISTORY_QUARTER, age);
|
||||
RotateHistory(history, HISTORY_YEAR, age);
|
||||
history.front() = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an average value for the previous month, as reset for the next month.
|
||||
* @param total Accrued total to average. Will be reset to zero.
|
||||
* @return Average value for the month.
|
||||
*/
|
||||
template <typename T, typename Taccrued>
|
||||
T GetAndResetAccumulatedAverage(Taccrued &total)
|
||||
{
|
||||
T result = ClampTo<T>(total / std::max(1U, TimerGameEconomy::days_since_last_month));
|
||||
total = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T GetHistory(const HistoryData<T> &history, const HistoryRange &hr, uint age)
|
||||
{
|
||||
if (hr.hr == nullptr) {
|
||||
if (age < hr.periods) return history[hr.first + age];
|
||||
} else {
|
||||
if (age * hr.division < static_cast<uint>(hr.hr->periods - hr.division)) {
|
||||
std::array<T, HISTORY_MAX_DIVISION> result; // No need to clear as we fill every element we use.
|
||||
uint start = age * hr.division + ((TimerGameEconomy::month / hr.hr->division) % hr.division);
|
||||
for (auto i = start; i != start + hr.division; ++i) {
|
||||
result[i - start] = GetHistory(history, *hr.hr, i);
|
||||
}
|
||||
return SumHistory<T>(std::span{std::begin(result), hr.division});
|
||||
}
|
||||
if (age < hr.periods) return history[hr.first + age - ((hr.hr->periods / hr.division) - 1)];
|
||||
}
|
||||
NOT_REACHED();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get history data for the specified period and age within that period.
|
||||
* @param history History data to extract from.
|
||||
* @param period Period to get.
|
||||
* @param age Age of data to get.
|
||||
* @return Historical value for period and age.
|
||||
*/
|
||||
template <typename T>
|
||||
T GetHistory(const HistoryData<T> &history, uint period, uint age)
|
||||
{
|
||||
switch (period) {
|
||||
case 0: return GetHistory(history, HISTORY_MONTH, age);
|
||||
case 1: return GetHistory(history, HISTORY_QUARTER, age);
|
||||
case 2: return GetHistory(history, HISTORY_YEAR, age);
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill some data with historical data.
|
||||
* @param history Historical data to fill from.
|
||||
* @param fillers Fillers to fill with history data.
|
||||
*/
|
||||
template <uint N, typename T, typename... Tfillers>
|
||||
void FillFromHistory(const HistoryData<T> &history, uint period, Tfillers... fillers)
|
||||
{
|
||||
for (uint i = 0; i != N; ++i) {
|
||||
auto data = GetHistory(history, period, N - i - 1);
|
||||
(fillers.Fill(i, data), ...);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HISTORY_FUNC_HPP */
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file history_type.hpp Types for storing historical data. */
|
||||
|
||||
#ifndef HISTORY_TYPE_HPP
|
||||
#define HISTORY_TYPE_HPP
|
||||
|
||||
#include "../stdafx.h"
|
||||
|
||||
static constexpr uint8_t HISTORY_PERIODS = 24;
|
||||
|
||||
struct HistoryRange {
|
||||
const HistoryRange *hr;
|
||||
const uint8_t periods; ///< Number of periods for this range.
|
||||
const uint8_t records; ///< Number of records needed for this range.
|
||||
const uint8_t first; ///< Index of first element in history data.
|
||||
const uint8_t last; ///< Index of last element in history data.
|
||||
const uint8_t division; ///< Number of divisions of the previous history range.
|
||||
const uint8_t total_division; ///< Number of divisions of the initial history range.
|
||||
|
||||
constexpr HistoryRange(uint8_t periods) :
|
||||
hr(nullptr), periods(periods), records(this->periods), first(1), last(this->first + this->records), division(1), total_division(1)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr HistoryRange(const HistoryRange &hr, uint8_t division, uint8_t periods) :
|
||||
hr(&hr), periods(periods), records(this->periods - ((hr.periods / division) - 1)), first(hr.last), last(this->first + this->records),
|
||||
division(division), total_division(division * hr.total_division)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr HistoryRange HISTORY_MONTH{HISTORY_PERIODS};
|
||||
static constexpr HistoryRange HISTORY_QUARTER{HISTORY_MONTH, 3, HISTORY_PERIODS};
|
||||
static constexpr HistoryRange HISTORY_YEAR{HISTORY_QUARTER, 4, HISTORY_PERIODS};
|
||||
|
||||
/** Maximum number of divisions from previous history range. */
|
||||
static constexpr uint8_t HISTORY_MAX_DIVISION = std::max({HISTORY_MONTH.division, HISTORY_QUARTER.division, HISTORY_YEAR.division});
|
||||
|
||||
/** Total number of records require for all history data. */
|
||||
static constexpr uint8_t HISTORY_RECORDS = HISTORY_YEAR.last;
|
||||
|
||||
static constexpr uint8_t THIS_MONTH = 0;
|
||||
static constexpr uint8_t LAST_MONTH = 1;
|
||||
|
||||
/**
|
||||
* Container type for storing history data.
|
||||
* @tparam T type of history data.
|
||||
*/
|
||||
template <typename T>
|
||||
using HistoryData = std::array<T, HISTORY_RECORDS>;
|
||||
|
||||
#endif /* HISTORY_TYPE_HPP */
|
|
@ -19,12 +19,48 @@
|
|||
|
||||
static OldPersistentStorage _old_ind_persistent_storage;
|
||||
|
||||
class SlIndustryAcceptedHistory : public DefaultSaveLoadHandler<SlIndustryAcceptedHistory, Industry::AcceptedCargo> {
|
||||
public:
|
||||
static inline const SaveLoad description[] = {
|
||||
SLE_VAR(Industry::AcceptedHistory, accepted, SLE_UINT16),
|
||||
SLE_VAR(Industry::AcceptedHistory, waiting, SLE_UINT16),
|
||||
};
|
||||
static inline const SaveLoadCompatTable compat_description = _industry_produced_history_sl_compat;
|
||||
|
||||
void Save(Industry::AcceptedCargo *a) const override
|
||||
{
|
||||
if (!IsValidCargoType(a->cargo)) {
|
||||
/* Don't save any history if cargo slot isn't used. */
|
||||
SlSetStructListLength(0);
|
||||
return;
|
||||
}
|
||||
|
||||
SlSetStructListLength(a->history.size());
|
||||
|
||||
for (auto &h : a->history) {
|
||||
SlObject(&h, this->GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void Load(Industry::AcceptedCargo *a) const override
|
||||
{
|
||||
size_t len = SlGetStructListLength(a->history.size());
|
||||
|
||||
for (auto &h : a->history) {
|
||||
if (--len > a->history.size()) break; // unsigned so wraps after hitting zero.
|
||||
SlObject(&h, this->GetDescription());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SlIndustryAccepted : public VectorSaveLoadHandler<SlIndustryAccepted, Industry, Industry::AcceptedCargo, INDUSTRY_NUM_INPUTS> {
|
||||
public:
|
||||
static inline const SaveLoad description[] = {
|
||||
SLE_VAR(Industry::AcceptedCargo, cargo, SLE_UINT8),
|
||||
SLE_VAR(Industry::AcceptedCargo, waiting, SLE_UINT16),
|
||||
SLE_VAR(Industry::AcceptedCargo, last_accepted, SLE_INT32),
|
||||
SLE_CONDVAR(Industry::AcceptedCargo, accumulated_waiting, SLE_UINT32, SLV_INDUSTRY_ACCEPTED_HISTORY, SL_MAX_VERSION),
|
||||
SLEG_CONDSTRUCTLIST("history", SlIndustryAcceptedHistory, SLV_INDUSTRY_ACCEPTED_HISTORY, SL_MAX_VERSION),
|
||||
};
|
||||
static inline const SaveLoadCompatTable compat_description = _industry_accepts_sl_compat;
|
||||
|
||||
|
|
|
@ -404,6 +404,7 @@ enum SaveLoadVersion : uint16_t {
|
|||
SLV_ORDERS_OWNED_BY_ORDERLIST, ///< 354 PR#13948 Orders stored in OrderList, pool removed.
|
||||
|
||||
SLV_FACE_STYLES, ///< 355 PR#14319 Addition of face styles, replacing gender and ethnicity.
|
||||
SLV_INDUSTRY_ACCEPTED_HISTORY, ///< 356 PR#14321 Add per-industry history of cargo delivered and waiting.
|
||||
|
||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@ add_test_files(
|
|||
bitmath_func.cpp
|
||||
enum_over_optimisation.cpp
|
||||
flatset_type.cpp
|
||||
history_func.cpp
|
||||
landscape_partial_pixel_z.cpp
|
||||
math_func.cpp
|
||||
mock_environment.h
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file history_func.cpp Test functionality for misc/history_func. */
|
||||
|
||||
#include "../stdafx.h"
|
||||
|
||||
#include "../3rdparty/catch2/catch.hpp"
|
||||
|
||||
#include "../misc/history_type.hpp"
|
||||
#include "../misc/history_func.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
template <>
|
||||
uint16_t SumHistory(std::span<uint16_t> history)
|
||||
{
|
||||
uint32_t total = std::accumulate(std::begin(history), std::end(history), 0, [](uint32_t r, const uint16_t &value) { return r + value; });
|
||||
return ClampTo<uint16_t>(total);
|
||||
}
|
||||
|
||||
TEST_CASE("History Rotation and Reporting tests")
|
||||
{
|
||||
HistoryData<uint16_t> history{};
|
||||
|
||||
/* Fill the history with decreasing data points for 24 years of history. This ensures that no data period should
|
||||
* contain the same value as another period. */
|
||||
uint16_t i = 12 * HISTORY_PERIODS;
|
||||
for (uint date = 1; date <= 12 * HISTORY_PERIODS; ++date, --i) {
|
||||
history[THIS_MONTH] = i;
|
||||
RotateHistory(history, date % 12);
|
||||
}
|
||||
|
||||
/* With the decreasing sequence, the expected value is triangle number (x*x+n)/2 and the square of the total divisions.
|
||||
* for quarters: 1 + 2 + 3 = 6, 4 + 5 + 6 = 15, 7 + 8 + 9 = 24, 10 + 11 + 12 = 33
|
||||
* 13 + 14 + 15 = 42, 16 + 17 + 18 = 51, 19 + 20 + 21 = 60, 22 + 23 + 24 = 69...
|
||||
* for years: 6 + 15 + 24 + 33 = 78, 42 + 51 + 60 + 69 = 222...
|
||||
*/
|
||||
for (uint j = 0; j < HISTORY_PERIODS; ++j) {
|
||||
CHECK(GetHistory(history, 0, j) == (( 1 * 1 + 1) / 2) + 1 * 1 * j);
|
||||
CHECK(GetHistory(history, 1, j) == (( 3 * 3 + 3) / 2) + 3 * 3 * j);
|
||||
CHECK(GetHistory(history, 2, j) == ((12 * 12 + 12) / 2) + 12 * 12 * j);
|
||||
}
|
||||
|
||||
/* Double-check quarter history matches summed month history. */
|
||||
CHECK(GetHistory(history, 0, 0) + GetHistory(history, 0, 1) + GetHistory(history, 0, 2) == GetHistory(history, 1, 0));
|
||||
CHECK(GetHistory(history, 0, 3) + GetHistory(history, 0, 4) + GetHistory(history, 0, 5) == GetHistory(history, 1, 1));
|
||||
CHECK(GetHistory(history, 0, 6) + GetHistory(history, 0, 7) + GetHistory(history, 0, 8) == GetHistory(history, 1, 2));
|
||||
CHECK(GetHistory(history, 0, 9) + GetHistory(history, 0, 10) + GetHistory(history, 0, 11) == GetHistory(history, 1, 3));
|
||||
CHECK(GetHistory(history, 0, 12) + GetHistory(history, 0, 13) + GetHistory(history, 0, 14) == GetHistory(history, 1, 4));
|
||||
CHECK(GetHistory(history, 0, 15) + GetHistory(history, 0, 16) + GetHistory(history, 0, 17) == GetHistory(history, 1, 5));
|
||||
CHECK(GetHistory(history, 0, 18) + GetHistory(history, 0, 19) + GetHistory(history, 0, 20) == GetHistory(history, 1, 6));
|
||||
CHECK(GetHistory(history, 0, 21) + GetHistory(history, 0, 22) + GetHistory(history, 0, 23) == GetHistory(history, 1, 7));
|
||||
|
||||
/* Double-check year history matches summed quarter history. */
|
||||
CHECK(GetHistory(history, 1, 0) + GetHistory(history, 1, 1) + GetHistory(history, 1, 2) + GetHistory(history, 1, 3) == GetHistory(history, 2, 0));
|
||||
CHECK(GetHistory(history, 1, 4) + GetHistory(history, 1, 5) + GetHistory(history, 1, 6) + GetHistory(history, 1, 7) == GetHistory(history, 2, 1));
|
||||
CHECK(GetHistory(history, 1, 8) + GetHistory(history, 1, 9) + GetHistory(history, 1, 10) + GetHistory(history, 1, 11) == GetHistory(history, 2, 2));
|
||||
CHECK(GetHistory(history, 1, 12) + GetHistory(history, 1, 13) + GetHistory(history, 1, 14) + GetHistory(history, 1, 15) == GetHistory(history, 2, 3));
|
||||
CHECK(GetHistory(history, 1, 16) + GetHistory(history, 1, 17) + GetHistory(history, 1, 18) + GetHistory(history, 1, 19) == GetHistory(history, 2, 4));
|
||||
CHECK(GetHistory(history, 1, 20) + GetHistory(history, 1, 21) + GetHistory(history, 1, 22) + GetHistory(history, 1, 23) == GetHistory(history, 2, 5));
|
||||
}
|
|
@ -37,6 +37,7 @@ TimerGameEconomy::Year TimerGameEconomy::year = {};
|
|||
TimerGameEconomy::Month TimerGameEconomy::month = {};
|
||||
TimerGameEconomy::Date TimerGameEconomy::date = {};
|
||||
TimerGameEconomy::DateFract TimerGameEconomy::date_fract = {};
|
||||
uint TimerGameEconomy::days_since_last_month = {};
|
||||
|
||||
/**
|
||||
* Converts a Date to a Year, Month & Day.
|
||||
|
@ -133,6 +134,7 @@ bool TimerManager<TimerGameEconomy>::Elapsed([[maybe_unused]] TimerGameEconomy::
|
|||
|
||||
/* increase day counter */
|
||||
TimerGameEconomy::date++;
|
||||
++TimerGameEconomy::days_since_last_month;
|
||||
|
||||
TimerGameEconomy::YearMonthDay ymd = TimerGameEconomy::ConvertDateToYMD(TimerGameEconomy::date);
|
||||
|
||||
|
@ -177,6 +179,8 @@ bool TimerManager<TimerGameEconomy>::Elapsed([[maybe_unused]] TimerGameEconomy::
|
|||
}
|
||||
}
|
||||
|
||||
if (new_month) TimerGameEconomy::days_since_last_month = 0;
|
||||
|
||||
/* check if we reached the maximum year, decrement dates by a year */
|
||||
if (TimerGameEconomy::year == EconomyTime::MAX_YEAR + 1) {
|
||||
TimerGameEconomy::year--;
|
||||
|
|
|
@ -37,6 +37,8 @@ public:
|
|||
static Date date; ///< Current date in days (day counter).
|
||||
static DateFract date_fract; ///< Fractional part of the day.
|
||||
|
||||
static uint days_since_last_month; ///< Number of days that have elapsed since the last month.
|
||||
|
||||
static YearMonthDay ConvertDateToYMD(Date date);
|
||||
static Date ConvertYMDToDate(Year year, Month month, Day day);
|
||||
static void SetDate(Date date, DateFract fract);
|
||||
|
|
|
@ -37,6 +37,7 @@ enum GraphWidgets : WidgetID {
|
|||
WID_GRAPH_MATRIX_SCROLLBAR,///< Cargo list scrollbar.
|
||||
|
||||
WID_GRAPH_RANGE_MATRIX, ///< Range list.
|
||||
WID_GRAPH_SCALE_MATRIX, ///< Horizontal axis scale list.
|
||||
|
||||
WID_PHG_DETAILED_PERFORMANCE, ///< Detailed performance.
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue