Skip to content

Commit

Permalink
Cleaned up schedule counter updates
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@2607 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Jul 30, 2009
1 parent 1f5e264 commit 9922249
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 91 deletions.
168 changes: 85 additions & 83 deletions simhalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ halthandle_t haltestelle_t::create(karte_t *welt, koord pos, spieler_t *sp)
* removes a ground tile from a station
* @author prissi
*/
bool
haltestelle_t::remove(karte_t *welt, spieler_t *sp, koord3d pos, const char *&msg)
bool haltestelle_t::remove(karte_t *welt, spieler_t *sp, koord3d pos, const char *&msg)
{
msg = NULL;
grund_t *bd = welt->lookup(pos);
Expand All @@ -183,17 +182,18 @@ haltestelle_t::remove(karte_t *welt, spieler_t *sp, koord3d pos, const char *&ms
}

DBG_MESSAGE("haltestelle_t::remove()","removing segment from %d,%d,%d", pos.x, pos.y, pos.z);

// otherwise there will be marked tiles left ...
halt->mark_unmark_coverage(false);
halt->rem_grund(bd);

// remove station building?
gebaeude_t* gb = bd->find<gebaeude_t>();
if(gb) {
DBG_MESSAGE("haltestelle_t::remove()", "removing building" );
hausbauer_t::remove( welt, sp, gb );
bd = NULL; // no need to recalc image
// only try to remove connected buildings, when still in list to avoid infinite loops
if( halt->rem_grund(bd) ) {
// remove station building?
gebaeude_t* gb = bd->find<gebaeude_t>();
if(gb) {
DBG_MESSAGE("haltestelle_t::remove()", "removing building" );
hausbauer_t::remove( welt, sp, gb );
bd = NULL; // no need to recalc image
}
}

if(!halt->existiert_in_welt()) {
Expand All @@ -206,8 +206,6 @@ DBG_DEBUG("haltestelle_t::remove()","destroy");
DBG_DEBUG("haltestelle_t::remove()","not last");
// acceptance and type may have been changed ... (due to post office/dock/railways station deletion)
halt->recalc_station_type();
// recalc all station connections
welt->set_schedule_counter();
}

// if building was removed this is false!
Expand Down Expand Up @@ -404,12 +402,10 @@ haltestelle_t::~haltestelle_t()

// routes may have changed without this station ...
verbinde_fabriken();
welt->set_schedule_counter();
}


void
haltestelle_t::rotate90( const sint16 y_size )
void haltestelle_t::rotate90( const sint16 y_size )
{
init_pos.rotate90( y_size );
// rotate waren destinations
Expand Down Expand Up @@ -2349,93 +2345,99 @@ bool haltestelle_t::add_grund(grund_t *gr)

assert(welt->lookup(pos)->get_halt() == self && gr->is_halt());
init_pos = tiles.front().grund->get_pos().get_2d();
welt->set_schedule_counter();

return true;
}



void haltestelle_t::rem_grund(grund_t *gr)
bool haltestelle_t::rem_grund(grund_t *gr)
{
// namen merken
if(gr) {
slist_tpl<tile_t>::iterator i = std::find(tiles.begin(), tiles.end(), gr);
if (i == tiles.end()) {
// was not part of station => do nothing
dbg->error("haltestelle_t::rem_grund()","removed illegal ground from halt");
return;
if(!gr) {
return false;
}

slist_tpl<tile_t>::iterator i = std::find(tiles.begin(), tiles.end(), gr);
if (i == tiles.end()) {
// was not part of station => do nothing
dbg->error("haltestelle_t::rem_grund()","removed illegal ground from halt");
return false;
}

// first tile => remove name from this tile ...
char buf[256];
const char* station_name_to_transfer = NULL;
if (i == tiles.begin() && (*i).grund->get_name()) {
tstrncpy(buf, get_name(), lengthof(buf));
station_name_to_transfer = buf;
set_name(NULL);
}

// now remove tile from list
tiles.erase(i);
welt->set_schedule_counter();
init_pos = tiles.empty() ? koord::invalid : tiles.front().grund->get_pos().get_2d();

// re-add name
if (station_name_to_transfer != NULL && !tiles.empty()) {
label_t *lb = tiles.front().grund->find<label_t>();
if(lb) {
delete lb;
}
set_name( station_name_to_transfer );
}

// first tile => remove name from this tile ...
char buf[256];
const char* station_name_to_transfer = NULL;
if (i == tiles.begin() && (*i).grund->get_name()) {
tstrncpy(buf, get_name(), lengthof(buf));
station_name_to_transfer = buf;
set_name(NULL);
}

// now remove tile from list
tiles.erase(i);
init_pos = tiles.empty() ? koord::invalid : tiles.front().grund->get_pos().get_2d();

// re-add name
if (station_name_to_transfer != NULL && !tiles.empty()) {
label_t *lb = tiles.front().grund->find<label_t>();
if(lb) {
delete lb;
}
set_name( station_name_to_transfer );
}

planquadrat_t *pl = welt->access( gr->get_pos().get_2d() );
if(pl) {
// no longer connected (upper level)
gr->set_halt(halthandle_t());
// still connected elsewhere?
for(unsigned i=0; i<pl->get_boden_count(); i++ ) {
if(pl->get_boden_bei(i)->get_halt()==self) {
// still connected with other ground => do not remove from plan ...
DBG_DEBUG("haltestelle_t::rem_grund()", "keep floor, count=%i", tiles.get_count());
return;
}
planquadrat_t *pl = welt->access( gr->get_pos().get_2d() );
if(pl) {
// no longer connected (upper level)
gr->set_halt(halthandle_t());
// still connected elsewhere?
for(unsigned i=0; i<pl->get_boden_count(); i++ ) {
if(pl->get_boden_bei(i)->get_halt()==self) {
// still connected with other ground => do not remove from plan ...
DBG_DEBUG("haltestelle_t::rem_grund()", "keep floor, count=%i", tiles.get_count());
return true;
}
DBG_DEBUG("haltestelle_t::rem_grund()", "remove also floor, count=%i", tiles.get_count());
// otherwise remove from plan ...
pl->set_halt(halthandle_t());
pl->get_kartenboden()->set_flag(grund_t::dirty);
}
DBG_DEBUG("haltestelle_t::rem_grund()", "remove also floor, count=%i", tiles.get_count());
// otherwise remove from plan ...
pl->set_halt(halthandle_t());
pl->get_kartenboden()->set_flag(grund_t::dirty);
}

int cov = welt->get_einstellungen()->get_station_coverage();
for (int y = -cov; y <= cov; y++) {
for (int x = -cov; x <= cov; x++) {
planquadrat_t *pl = welt->access( gr->get_pos().get_2d()+koord(x,y) );
if(pl) {
pl->remove_from_haltlist(welt,self);
pl->get_kartenboden()->set_flag(grund_t::dirty);
}
int cov = welt->get_einstellungen()->get_station_coverage();
for (int y = -cov; y <= cov; y++) {
for (int x = -cov; x <= cov; x++) {
planquadrat_t *pl = welt->access( gr->get_pos().get_2d()+koord(x,y) );
if(pl) {
pl->remove_from_haltlist(welt,self);
pl->get_kartenboden()->set_flag(grund_t::dirty);
}
}
}

// factory reach may have been changed ...
verbinde_fabriken();
// factory reach may have been changed ...
verbinde_fabriken();

// remove lines eventually
for( int j=registered_lines.get_count()-1; j>=0; j-- ) {
const schedule_t *fpl = registered_lines[j]->get_schedule();
bool ok=false;
for( int k=0; k<fpl->get_count(); k++ ) {
if(get_halt(welt,fpl->eintrag[k].pos,registered_lines[j]->get_besitzer())==self) {
ok = true;
break;
}
}
// need removal?
if(!ok) {
registered_lines.remove_at(j);
// remove lines eventually
for( int j=registered_lines.get_count()-1; j>=0; j-- ) {
const schedule_t *fpl = registered_lines[j]->get_schedule();
bool ok=false;
for( int k=0; k<fpl->get_count(); k++ ) {
if(get_halt(welt,fpl->eintrag[k].pos,registered_lines[j]->get_besitzer())==self) {
ok = true;
break;
}
}

// need removal?
if(!ok) {
registered_lines.remove_at(j);
}
}

return true;
}


Expand Down
2 changes: 1 addition & 1 deletion simhalt.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class haltestelle_t
#endif

bool add_grund(grund_t *gb);
void rem_grund(grund_t *gb);
bool rem_grund(grund_t *gb);

uint32 get_capacity(uint8 typ) const { return capacity[typ]; }

Expand Down
2 changes: 1 addition & 1 deletion simplan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ planquadrat_t::rdwr(karte_t *welt, loadsave_t *file, koord pos )
grund_t *gr;
//DBG_DEBUG("planquadrat_t::rdwr()","Reading boden");
do {
grund_t::typ gtyp = (grund_t::typ)file->rd_obj_id();
short gtyp = file->rd_obj_id();

switch(gtyp) {
case -1: gr = NULL; break;
Expand Down
7 changes: 1 addition & 6 deletions simwerkz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ DBG_MESSAGE("wkz_remover()", "bound=%i",halt.is_bound());
if (gr->is_halt() && halt.is_bound() && fabrik_t::get_fab(welt,pos.get_2d())==NULL) {
// halt and not a factory (oil rig etc.)
const spieler_t* owner = halt->get_besitzer();
if (owner == sp || owner == welt->get_spieler(1)) {
if( spieler_t::check_owner( owner, sp ) ) {
return haltestelle_t::remove(welt, sp, gr->get_pos(), msg);
}
}
Expand Down Expand Up @@ -2752,11 +2752,6 @@ const char *wkz_station_t::work( karte_t *welt, spieler_t *sp, koord3d pos )
default:
dbg->fatal("wkz_station_t::work()","tool called for illegal besch \"%\"", default_param );
}

if(msg==NULL) {
// no error? => recalc all station connections
welt->set_schedule_counter();
}
return msg;
}

Expand Down

0 comments on commit 9922249

Please sign in to comment.