News:

Congratulations!
 You've won the News Item Lottery! Your prize? Reading this news item! :)

find wrong city when use tool_remover_t or tool_change_city_size_t

Started by poppo, Yesterday at 03:52:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

poppo

In remove city by using tool_remove_t or change city size by using tool_change_city_size_t, the city is found by using find_nearest_city(koord).
However, this method can find wrong city, expecially when the more than one cities are overlapped.
So, I propose that we get the city not use position but check the building's city.
//tool_remover_t::tool_remover_intern()
if(gb->is_townhall()) {
stadt_t *stadt = gb->get_stadt();
if(!welt->remove_city( stadt )) {
msg = "Das Feld gehoert\neinem anderen Spieler\n";
return false;
}
}
//tool_change_city_size_t::work()
stadt_t *city=NULL;
// if there is the townhall at this position, we change this city size.
if(  grund_t *gr = welt->lookup(pos)  ) {
if(  gebaeude_t *gb = gr->find<gebaeude_t>()  ) {
if(  gb->is_townhall()  ) {
city = gb->get_stadt();
}
}
}
if(  city==NULL  ) {
// if no townhall, we find nearest city.
city = welt->find_nearest_city(pos.get_2d());
}