smarter regular funding and massfunding
--HG-- branch : better-funding
This commit is contained in:
@@ -106,6 +106,7 @@ struct Town : TownPool::PoolItem<&_town_pool> {
|
||||
uint houses_reconstruction; ///< number of houses currently being rebuilt
|
||||
uint houses_demolished; ///< number of houses demolished this month
|
||||
bool fund_regularly; ///< funds buildings regularly when previous fund ends
|
||||
bool do_massfund; ///< funds buildings when grow counter is maximal (results in fastest funding possible)
|
||||
|
||||
char *text; ///< General text with additional information.
|
||||
|
||||
|
||||
@@ -820,6 +820,35 @@ void UpdateTownCargoBitmap()
|
||||
|
||||
static bool GrowTown(Town *t);
|
||||
|
||||
static void DoRegularFunding(Town *t)
|
||||
{
|
||||
if (!t->fund_regularly && !t->do_massfund)
|
||||
return;
|
||||
|
||||
if (!t->do_massfund && t->fund_buildings_months > 0)
|
||||
return;
|
||||
|
||||
if (_local_company == COMPANY_SPECTATOR)
|
||||
return;
|
||||
|
||||
if (CB_Enabled() && !t->growing)
|
||||
return;
|
||||
|
||||
if (t->grow_counter == 0)
|
||||
return;
|
||||
|
||||
// do massfund only if grow_counter is max, but do regular even if it is not
|
||||
// (that requires town not to be funded already)
|
||||
if (t->grow_counter < t->growth_rate & (~TOWN_GROW_RATE_CUSTOM) &&
|
||||
(!t->fund_regularly || t->fund_buildings_months > 0))
|
||||
return;
|
||||
|
||||
CompanyByte old = _current_company;
|
||||
_current_company = _local_company;
|
||||
DoCommandP(t->xy, t->index, 5, CMD_DO_TOWN_ACTION);
|
||||
_current_company = old;
|
||||
}
|
||||
|
||||
static void TownTickHandler(Town *t)
|
||||
{
|
||||
if (HasBit(t->flags, TOWN_IS_GROWING)) {
|
||||
@@ -840,6 +869,7 @@ static void TownTickHandler(Town *t)
|
||||
}
|
||||
t->grow_counter = i;
|
||||
}
|
||||
DoRegularFunding(t);
|
||||
}
|
||||
|
||||
void OnTick_Town()
|
||||
@@ -3568,12 +3598,8 @@ void TownsMonthlyLoop()
|
||||
UpdateTownUnwanted(t);
|
||||
UpdateTownCargoes(t);
|
||||
|
||||
if(t->fund_buildings_months == 0 && t->fund_regularly && _local_company != COMPANY_SPECTATOR){
|
||||
CompanyByte old = _current_company;
|
||||
_current_company = _local_company;
|
||||
DoCommandP(t->xy, t->index, 5, CMD_DO_TOWN_ACTION);
|
||||
_current_company = old;
|
||||
}
|
||||
DoRegularFunding(t);
|
||||
|
||||
t->houses_skipped_last_month = t->houses_skipped - t->houses_skipped_prev;
|
||||
t->houses_skipped_prev = t->houses_skipped;
|
||||
t->cycles_skipped_last_month = t->cycles_skipped - t->cycles_skipped_prev;
|
||||
|
||||
@@ -1339,6 +1339,7 @@ public:
|
||||
this->town = Town::Get(window_number);
|
||||
this->InitNested(window_number);
|
||||
if(this->town->fund_regularly) this->LowerWidget(WID_CB_FUND_REGULAR);
|
||||
if(this->town->do_massfund) this->LowerWidget(WID_CB_MASSFUND);
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget, int click_count)
|
||||
@@ -1360,10 +1361,14 @@ public:
|
||||
break;
|
||||
case WID_CB_FUND_REGULAR:
|
||||
this->town->fund_regularly = !this->town->fund_regularly;
|
||||
if(this->town->fund_regularly) this->town->fund_regularly = TownExecuteAction(this->town, HK_FUND);
|
||||
// if(this->town->fund_regularly) this->town->fund_regularly = TownExecuteAction(this->town, HK_FUND);
|
||||
this->SetWidgetLoweredState(widget, this->town->fund_regularly);
|
||||
this->SetWidgetDirty(widget);
|
||||
break;
|
||||
case WID_CB_MASSFUND:
|
||||
this->town->do_massfund = !this->town->do_massfund;
|
||||
this->SetWidgetLoweredState(widget, this->town->do_massfund);
|
||||
this->SetWidgetDirty(widget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1583,6 +1588,12 @@ static const NWidgetPart _nested_cb_town_widgets[] = {
|
||||
NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_CB_FUND_REGULAR),SetMinimalSize(60, 20),SetFill(1, 0), SetDataTip(STR_CB_FUND_REGULAR, STR_CB_FUND_REGULAR_TT),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(4, 0),
|
||||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_CB_ADVERT_REGULAR),SetMinimalSize(60, 20),SetFill(1, 0), SetDataTip(STR_CB_LARGE_ADVERTISING_CAMPAIGN, 0),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(2, 0),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_CB_MASSFUND),SetMinimalSize(60, 20),SetFill(1, 0), SetDataTip(STR_CB_FUND_REGULAR, STR_CB_FUND_REGULAR_TT),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(4, 0),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
NWidget(NWID_SPACER), SetMinimalSize(0, 5),
|
||||
|
||||
@@ -76,8 +76,10 @@ enum TownHK {
|
||||
enum CBTownWidgets {
|
||||
WID_CB_LOCATION,
|
||||
WID_CB_ADVERT,
|
||||
WID_CB_ADVERT_REGULAR,
|
||||
WID_CB_FUND,
|
||||
WID_CB_FUND_REGULAR,
|
||||
WID_CB_MASSFUND,
|
||||
WID_CB_DETAILS,
|
||||
WID_CB_CARGO_NAME,
|
||||
WID_CB_CARGO_AMOUNT,
|
||||
|
||||
Reference in New Issue
Block a user