28-07-2019, Sunday-01:35:38
wenn man die ganze Routine so schreibt dann geht es
aber ich bekomme schon wieder meine Allergie
Zitat:static const building_desc_t* get_city_building_from_list(const vector_tpl<const building_desc_t*>& list, int level, uint16 time, climate cl, uint32 clusters, koord minsize, koord maxsize )
{
weighted_vector_tpl<const building_desc_t *> selections(16);
// DBG_MESSAGE("hausbauer_t::get_aus_liste()","target level %i", level );
const building_desc_t *desc_at_least=NULL;
FOR(vector_tpl<building_desc_t const*>, const desc, list) {
if( (desc->is_allowed_climate(cl) || cl==MAX_CLIMATES ) &&
desc->get_distribution_weight() > 0 &&
desc->is_available(time) &&
// size check
desc->get_x() <= maxsize.x && desc->get_y() <= maxsize.y &&
desc->get_x() >= minsize.x && desc->get_y() >= minsize.y ) {
desc_at_least = desc;
const int thislevel = desc->get_level();
if( thislevel > level ) {
if (selections.empty()) {
// Nothing of the correct level. Continue with search on a higher level.
level = thislevel;
}
else {
// We already found something of the correct level; stop.
break;
}
}
if( thislevel == level ) {
// DBG_MESSAGE("hausbauer_t::get_city_building_from_list()","appended %s at %i", desc->get_name(), thislevel );
/* Level, time period, and climate are all OK.
* Now modify the chance rating by a factor based on the clusters.
*/
// FIXME: the factor should be configurable by the pakset/
int chance = desc->get_distribution_weight();
if( clusters ) {
uint32 my_clusters = desc->get_clusters();
if( my_clusters & clusters ) {
chance *= stadt_t::get_cluster_factor();
}
else {
chance /= stadt_t::get_cluster_factor();
}
}
selections.append(desc, chance);
}
}
}
if(selections.get_sum_weight()==0) {
// this is some level below, but at least it is something
return desc_at_least;
}
if(selections.get_count()==1) {
return selections.front();
}
// now there is something to choose
return pick_any_weighted(selections);
}
aber ich bekomme schon wieder meine Allergie