Detect when regular ad doesn't change station rating and switch station

This commit is contained in:
dP
2023-04-02 17:43:03 +04:00
parent a21cafd2a1
commit 69c8ce63d3

View File

@@ -931,19 +931,19 @@ static void DoRegularAdvertising(Town *t) {
if (!HasBit(t->advertise_regularly, _local_company))
return;
if (t->ad_ref_goods_entry == NULL) {
if (t->ad_ref_goods_entry == nullptr) {
// Pick as ref station and cargo with min rating
for (Station *st : Station::Iterate()) {
if (st->owner == _local_company && DistanceManhattan(t->xy, st->xy) <= 20) {
for (CargoID i = 0; i < NUM_CARGO; i++)
if (st->goods[i].HasRating() && (t->ad_ref_goods_entry == NULL ||
if (st->goods[i].HasRating() && (t->ad_ref_goods_entry == nullptr ||
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)
if (t->ad_ref_goods_entry == nullptr)
return;
}
@@ -956,11 +956,17 @@ static void DoRegularAdvertising(Town *t) {
} else if (_tick_counter - t->last_advertisement < 30) return;
t->last_advertisement = _tick_counter;
auto prev_rating = t->ad_ref_goods_entry->rating;
citymania::cmd::DoTownAction(t->index, HK_LADVERT)
.with_tile(t->xy)
.no_estimate()
.as_company(_local_company)
.post();
.with_callback([=] (bool res) -> bool {
if (res && prev_rating == t->ad_ref_goods_entry->rating) {
t->ad_ref_goods_entry = nullptr;
}
return true;
}).post();
}
static void TownTickHandler(Town *t)