Yes, I'm looking at that now, but I'm confused because it already seems to be written as if it should behave as I've described, with the "allow_earlier" being set, in this instance, from "new_town" being p****ed to it. Then it appears to give a 35% chance of an old building being allowed to be selected from the list. So maybe it's a bug that prevents old buildings being used?
static const haus_besch_t* get_aus_liste(const vector_tpl<const haus_besch_t*>& liste, int level, uint16 time, climate cl, bool allow_earlier)
{
weighted_vector_tpl<const haus_besch_t *> auswahl(16);
// DBG_MESSAGE("hausbauer_t::get_aus_liste()","target level %i", level );
const haus_besch_t *besch_at_least=NULL;
for (vector_tpl<const haus_besch_t*>::const_iterator i = liste.begin(), end = liste.end(); i != end; ++i) {
const haus_besch_t* besch = *i;
const uint16 random = simrand(100);
if( besch->is_allowed_climate(cl) &&
besch->get_chance()>0 &&
(time==0 || (besch->get_intro_year_month()<=time && ((allow_earlier && random > 65) || besch->get_retire_year_month()>time)))) {
besch_at_least = besch;
}
const int thislevel = besch->get_level();
if(thislevel>level) {n
if (auswahl.empty()) {
// continue with search ...
level = thislevel;
}
else {
// ok, we found something
break;
}
}
if(thislevel==level && besch->get_chance()>0) {
if(cl==MAX_CLIMATES || besch->is_allowed_climate(cl)) {
if(time==0 || (besch->get_intro_year_month()<=time && ((allow_earlier && random > 65) || besch->get_retire_year_month()>time))) {
// DBG_MESSAGE("hausbauer_t::get_aus_liste()","appended %s at %i", besch->get_name(), thislevel );
auswahl.append(besch,besch->get_chance(),4);
}
}
}
}
if(auswahl.get_sum_weight()==0) {
// this is some level below, but at least it is something
return besch_at_least;
}
if(auswahl.get_count()==1) {
return auswahl.front();
}
// now there is something to choose
return auswahl.at_weight( simrand(auswahl.get_sum_weight()) );
}