Skip to content

Commit

Permalink
CHG: limit search when looking for places for city attractions and mo…
Browse files Browse the repository at this point in the history
…numents

git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@6492 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
Dwachs committed May 1, 2013
1 parent b9d07b4 commit a72f438
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
10 changes: 6 additions & 4 deletions simcity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void stadt_t::cityrules_rdwr(loadsave_t *file)
*/
class denkmal_platz_sucher_t : public platzsucher_t {
public:
denkmal_platz_sucher_t(karte_t* welt) : platzsucher_t(welt) {}
denkmal_platz_sucher_t(karte_t* welt, sint16 radius) : platzsucher_t(welt, radius) {}

virtual bool ist_feld_ok(koord pos, koord d, climate_bits cl) const
{
Expand Down Expand Up @@ -1969,7 +1969,7 @@ class bauplatz_mit_strasse_sucher_t: public bauplatz_sucher_t
/// if false, this will the check 'do not build next other to special buildings'
bool big_city;

bauplatz_mit_strasse_sucher_t(karte_t* welt, bool big) : bauplatz_sucher_t (welt), big_city(big) {}
bauplatz_mit_strasse_sucher_t(karte_t* welt, sint16 radius, bool big) : bauplatz_sucher_t(welt, radius), big_city(big) {}

// get distance to next special building
int find_dist_next_special(koord pos) const
Expand Down Expand Up @@ -2051,8 +2051,9 @@ void stadt_t::check_bau_spezial(bool new_town)

bool big_city = buildings.get_count() >= 10;
bool is_rotate = besch->get_all_layouts() > 1;
sint16 radius = koord_distance( get_rechtsunten(), get_linksoben() )/2 + 10;
// find place
koord best_pos = bauplatz_mit_strasse_sucher_t(welt, big_city).suche_platz(pos, besch->get_b(), besch->get_h(), besch->get_allowed_climate_bits(), &is_rotate);
koord best_pos = bauplatz_mit_strasse_sucher_t(welt, radius, big_city).suche_platz(pos, besch->get_b(), besch->get_h(), besch->get_allowed_climate_bits(), &is_rotate);

if (best_pos != koord::invalid) {
// then built it
Expand All @@ -2076,7 +2077,8 @@ void stadt_t::check_bau_spezial(bool new_town)
besch = hausbauer_t::waehle_denkmal(welt->get_timeline_year_month());
if (besch) {
koord total_size = koord(2 + besch->get_b(), 2 + besch->get_h());
koord best_pos(denkmal_platz_sucher_t(welt).suche_platz(pos, total_size.x, total_size.y, besch->get_allowed_climate_bits()));
sint16 radius = koord_distance( get_rechtsunten(), get_linksoben() )/2 + 10;
koord best_pos(denkmal_platz_sucher_t(welt, radius).suche_platz(pos, total_size.x, total_size.y, besch->get_allowed_climate_bits()));

if (best_pos != koord::invalid) {
// check if borders around the monument are inside the map limits
Expand Down
2 changes: 0 additions & 2 deletions simwerkz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
#include "besch/weg_besch.h"
#include "besch/roadsign_besch.h"

#include "sucher/bauplatz_sucher.h"

#include "tpl/vector_tpl.h"

#include "utils/memory_rw.h"
Expand Down
2 changes: 1 addition & 1 deletion sucher/bauplatz_sucher.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class bauplatz_sucher_t : public platzsucher_t {
public:
bauplatz_sucher_t(karte_t *welt) : platzsucher_t(welt) {}
bauplatz_sucher_t(karte_t *welt, sint16 radius = -1) : platzsucher_t(welt, radius) {}

virtual bool ist_platz_ok(koord pos, sint16 b, sint16 h, climate_bits cl) const {
return welt->square_is_free(pos, b, h, NULL, cl);
Expand Down
5 changes: 3 additions & 2 deletions sucher/platzsucher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ bool platzsucher_t::ist_feld_ok(koord /*pos*/, koord /*d*/, climate_bits /*cl*/)

koord platzsucher_t::suche_platz(koord start, sint16 b, sint16 h, climate_bits cl, bool *r)
{
pos_liste_wh_t psuch1(welt->get_size_max(), b, h);
sint16 radius = max_radius > 0 ? max_radius : welt->get_size_max();
pos_liste_wh_t psuch1(radius, b, h);

this->b = b;
this->h = h;
Expand All @@ -219,7 +220,7 @@ koord platzsucher_t::suche_platz(koord start, sint16 b, sint16 h, climate_bits c
//
// Hier suchen wir auch gedrehte Positionen.
//
pos_liste_wh_t psuch2(welt->get_size_max(), h, b);
pos_liste_wh_t psuch2(radius, h, b);

if(ist_platz_ok(start, b, h, cl)) {
*r = false;
Expand Down
4 changes: 3 additions & 1 deletion sucher/platzsucher.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ class platzsucher_t {
karte_t *welt;
sint16 b;
sint16 h;
sint16 max_radius;

virtual bool ist_platz_ok(koord pos, sint16 b, sint16 h, climate_bits cl) const;

virtual bool ist_feld_ok(koord pos, koord d, climate_bits cl) const;

bool ist_randfeld(koord d) const;
platzsucher_t(karte_t *welt) { this->welt = welt; }

platzsucher_t(karte_t *welt, sint16 _max_radius = - 1) { this->welt = welt; max_radius = _max_radius; }
virtual ~platzsucher_t() {}
public:
koord suche_platz(koord start, sint16 b, sint16 h, climate_bits cl, bool *r = NULL);
Expand Down

0 comments on commit a72f438

Please sign in to comment.