diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index c8f99dbc97..112d93f50a 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -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)