regular advirtisement
--HG-- branch : better-funding
This commit is contained in:
+1
-1
@@ -110,7 +110,7 @@ struct Town : TownPool::PoolItem<&_town_pool> {
|
||||
bool do_massfund; ///< funds buildings when grow counter is maximal (results in fastest funding possible)
|
||||
bool advertise_regularly; ///< advertised regularly to keep stations rating on desired value
|
||||
uint8 ad_rating_goal; ///< value to keep rating at (for regular advertisement) (0..255)
|
||||
GoodsEntry *ad_ref_goods_entry; ///< poiter to goods entry of some station, used to check rating for regular advertisement
|
||||
const GoodsEntry *ad_ref_goods_entry; ///< poiter to goods entry of some station, used to check rating for regular advertisement
|
||||
|
||||
char *text; ///< General text with additional information.
|
||||
|
||||
|
||||
+18
-4
@@ -839,14 +839,14 @@ static void DoRegularFunding(Town *t)
|
||||
|
||||
// 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) &&
|
||||
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;
|
||||
CompanyByte old = _current_company;
|
||||
_current_company = _local_company;
|
||||
DoCommandP(t->xy, t->index, HK_FUND, CMD_DO_TOWN_ACTION);
|
||||
// _current_company = old;
|
||||
_current_company = old;
|
||||
}
|
||||
|
||||
static void DoRegularAdvertising(Town *t) {
|
||||
@@ -855,6 +855,17 @@ static void DoRegularAdvertising(Town *t) {
|
||||
|
||||
if (t->ad_ref_goods_entry == NULL) {
|
||||
// Pick as ref station and cargo with min rating
|
||||
const Station *st;
|
||||
fprintf(stderr, "searching ref %d %d\n", (int)_current_company, (int)_local_company);
|
||||
FOR_ALL_STATIONS(st) {
|
||||
if (st->town == t && st->owner == _local_company) {
|
||||
for (CargoID i = 0; i < NUM_CARGO; i++)
|
||||
if (st->goods[i].HasRating() && (t->ad_ref_goods_entry == NULL ||
|
||||
t->ad_ref_goods_entry->rating < st->goods[i].rating)) {
|
||||
t->ad_ref_goods_entry = &st->goods[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (t->ad_ref_goods_entry == NULL)
|
||||
return;
|
||||
@@ -863,7 +874,10 @@ static void DoRegularAdvertising(Town *t) {
|
||||
if (t->ad_ref_goods_entry->rating >= t->ad_rating_goal)
|
||||
return;
|
||||
|
||||
CompanyByte old = _current_company;
|
||||
_current_company = _local_company;
|
||||
DoCommandP(t->xy, t->index, HK_LADVERT, CMD_DO_TOWN_ACTION);
|
||||
_current_company = old;
|
||||
}
|
||||
|
||||
static void TownTickHandler(Town *t)
|
||||
|
||||
+18
-4
@@ -1374,14 +1374,28 @@ public:
|
||||
this->SetWidgetDirty(widget);
|
||||
break;
|
||||
case WID_CB_ADVERT_REGULAR:
|
||||
this->town->advertise_regularly = !this->town->advertise_regularly;
|
||||
this->town->ad_ref_goods_entry = NULL;
|
||||
this->SetWidgetLoweredState(widget, this->town->advertise_regularly);
|
||||
this->SetWidgetDirty(widget);
|
||||
if (!this->town->advertise_regularly) {
|
||||
SetDParam(0, ToPercent8(this->town->ad_rating_goal));
|
||||
ShowQueryString(STR_JUST_INT, STR_FOUND_TOWN_CAPTION,
|
||||
4, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
|
||||
} else this->OnQueryTextFinished(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnQueryTextFinished(char *str)
|
||||
{
|
||||
this->town->advertise_regularly = (str != NULL);
|
||||
this->town->ad_ref_goods_entry = NULL;
|
||||
this->SetWidgetLoweredState(WID_CB_ADVERT_REGULAR, this->town->advertise_regularly);
|
||||
this->SetWidgetDirty(WID_CB_ADVERT_REGULAR);
|
||||
|
||||
if (str == NULL)
|
||||
return;
|
||||
uint val = Clamp(StrEmpty(str) ? 0 : strtol(str, NULL, 10), 1, 100);
|
||||
this->town->ad_rating_goal = ((val << 8) + 255) / 101;
|
||||
}
|
||||
|
||||
virtual void SetStringParameters(int widget) const
|
||||
{
|
||||
if (widget == WID_TV_CAPTION){
|
||||
|
||||
Reference in New Issue
Block a user