Skip to content

Commit

Permalink
ADD: Register lineless convoys at the halts and list them with links …
Browse files Browse the repository at this point in the history
…in the halt details dialog

git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@3641 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
Knightly committed Aug 10, 2010
1 parent 6f030c7 commit 76f3cba
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 37 deletions.
4 changes: 0 additions & 4 deletions gui/fahrplan_gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,6 @@ bool fahrplan_gui_t::infowin_event(const event_t *ev)
}
}
else {
// since matches does not check for depots, we need to do it this way ...
if( fpl->get_count()!=old_fpl->get_count() || !old_fpl->matches( sp->get_welt(), fpl ) ) {
sp->get_welt()->set_schedule_counter();
}
cbuffer_t buf(5500);
fpl->sprintf_schedule( buf );
cnv->call_convoi_tool( 'g', buf );
Expand Down
70 changes: 64 additions & 6 deletions gui/halt_detail.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ void halt_detail_t::halt_detail_info(cbuffer_t & buf)
cont.remove_komponente( b );
delete b;
}
while(!convoylabels.empty()) {
gui_label_t *l = convoylabels.remove_first();
cont.remove_komponente( l );
delete l;
}
while(!convoybuttons.empty()) {
button_t *b = convoybuttons.remove_first();
cont.remove_komponente( b );
delete b;
}
buf.clear();

const slist_tpl<fabrik_t *> & fab_list = halt->get_fab_list();
Expand Down Expand Up @@ -174,11 +184,11 @@ void halt_detail_t::halt_detail_info(cbuffer_t & buf)
buf.append("\n");
offset_y += LINESPACE;

if (!halt->registered_lines.empty()) {
buf.append(translator::translate("Lines serving this stop"));
buf.append(":\n");
offset_y += LINESPACE;
buf.append(translator::translate("Lines serving this stop"));
buf.append(":\n");
offset_y += LINESPACE;

if( !halt->registered_lines.empty() ) {
for (unsigned int i = 0; i<halt->registered_lines.get_count(); i++) {
// Line buttons only if owner ...
if (halt->get_welt()->get_active_player()==halt->registered_lines[i]->get_besitzer()) {
Expand All @@ -199,6 +209,46 @@ void halt_detail_t::halt_detail_info(cbuffer_t & buf)
offset_y += LINESPACE;
}
}
else {
buf.append(" ");
buf.append( translator::translate("keine") );
buf.append("\n");
offset_y += LINESPACE;
}

// Knightly : add lineless convoys which serve this stop
buf.append("\n");
offset_y += LINESPACE;

buf.append( translator::translate("Lineless convoys serving this stop") );
buf.append(":\n");
offset_y += LINESPACE;

if( !halt->registered_convoys.empty() ) {
for( uint32 i=0; i<halt->registered_convoys.get_count(); ++i ) {
// Convoy buttons
button_t *b = new button_t();
b->init( button_t::posbutton, NULL, koord(10, offset_y) );
b->set_targetpos( koord(-2, i) );
b->add_listener( this );
convoybuttons.append( b );
cont.add_komponente( b );

// Line labels with color of player
gui_label_t *l = new gui_label_t( halt->registered_convoys[i]->get_name(), PLAYER_FLAG|(halt->registered_convoys[i]->get_besitzer()->get_player_color1()+0) );
l->set_pos( koord(26, offset_y) );
convoylabels.append( l );
cont.add_komponente( l );
buf.append("\n");
offset_y += LINESPACE;
}
}
else {
buf.append(" ");
buf.append( translator::translate("keine") );
buf.append("\n");
offset_y += LINESPACE;
}

buf.append("\n");
offset_y += LINESPACE;
Expand Down Expand Up @@ -268,11 +318,11 @@ bool halt_detail_t::action_triggered( gui_action_creator_t *, value_t extra)
{
if(extra.i&~1) {
koord k = *(const koord *)extra.p;
if(k.x>=0) {
if( k.x>=0 ) {
// goto button pressed
halt->get_welt()->change_world_position( koord3d(k,halt->get_welt()->max_hgt(k)) );
}
else {
else if( k.x==-1 ) {
// Line button pressed.
uint16 j=k.y;
if( j < halt->registered_lines.get_count() ) {
Expand All @@ -286,6 +336,14 @@ bool halt_detail_t::action_triggered( gui_action_creator_t *, value_t extra)
}
}
}
else if( k.x==-2 ) {
// Knightly : lineless convoy button pressed
uint16 j = k.y;
if( j<halt->registered_convoys.get_count() ) {
convoihandle_t convoy = halt->registered_convoys[j];
convoy->zeige_info();
}
}
}
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions gui/halt_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class halt_detail_t : public gui_frame_t, action_listener_t
slist_tpl<button_t *>posbuttons;
slist_tpl<gui_label_t *>linelabels;
slist_tpl<button_t *>linebuttons;
slist_tpl<gui_label_t *> convoylabels;
slist_tpl<button_t *> convoybuttons;

public:
halt_detail_t(halthandle_t halt);
Expand Down
80 changes: 74 additions & 6 deletions simconvoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ DBG_MESSAGE("convoi_t::~convoi_t()", "destroying %d, %p", self.get_id(), this);
welt->sync_remove( this );
welt->rem_convoi( self );

// Knightly : if lineless convoy -> unregister from stops
if( !line.is_bound() ) {
unregister_stops();
}

// force asynchronous recalculation
if(fpl) {
if(!fpl->ist_abgeschlossen()) {
Expand Down Expand Up @@ -358,6 +363,11 @@ DBG_MESSAGE("convoi_t::laden_abschliessen()","next_stop_index=%d", next_stop_ind
}
fahr[0]->set_erstes(true);
}

// Knightly : if lineless convoy -> register itself with stops
if( !line.is_bound() ) {
register_stops();
}
}


Expand Down Expand Up @@ -1357,10 +1367,16 @@ bool convoi_t::set_schedule(schedule_t * f)

DBG_DEBUG("convoi_t::set_schedule()", "new=%p, old=%p", f, fpl);

if(f == NULL) {
if( f==NULL ) {
if( line.is_bound() ) {
unset_line();
}
else {
// Knightly : if schedule is going to be deleted -> make sure to unregister stops for lineless convoys
if( state==INITIAL ) {
unregister_stops();
}
}
if( state==INITIAL ) {
delete fpl;
fpl = NULL;
Expand All @@ -1371,16 +1387,30 @@ bool convoi_t::set_schedule(schedule_t * f)

// happens to be identical?
if(fpl!=f) {
// now check, we we have been bond to a line we are about to loose:
if( line.is_bound() && !f->matches( welt, line->get_schedule() ) ) {
unset_line();
// now check, we we have been bond to a line we are about to lose:
bool changed = false;
if( line.is_bound() ) {
if( !f->matches( welt, line->get_schedule() ) ) {
changed = true;
unset_line();
}
}
else {
if( !f->matches( welt, fpl ) ) {
changed = true;
unregister_stops();
}
}
// destroy a possibly open schedule window
if(fpl && !fpl->ist_abgeschlossen()) {
if( fpl && !fpl->ist_abgeschlossen() ) {
destroy_win((long)fpl);
delete fpl;
}
fpl = f;
if( changed ) {
register_stops();
welt->set_schedule_counter(); // must trigger refresh
}
}

// remove wrong freight
Expand Down Expand Up @@ -2563,9 +2593,14 @@ void convoi_t::set_line(linehandle_t org_line)
if(!org_line.is_bound()) {
return;
}
if(line.is_bound()) {
if( line.is_bound() ) {
unset_line();
}
else {
// Knightly : originally a lineless convoy -> unregister itself from stops as it now belongs to a line
unregister_stops();
welt->set_schedule_counter(); // must trigger refresh
}
line_update_pending = org_line;
check_pending_updates();
}
Expand Down Expand Up @@ -2717,6 +2752,39 @@ void convoi_t::check_pending_updates()
}


/**
* Register the convoy with the stops in the schedule
* @author Knightly
*/
void convoi_t::register_stops()
{
if( fpl ) {
for( uint8 i=0; i<fpl->get_count(); ++i ) {
const halthandle_t halt = haltestelle_t::get_halt( welt, fpl->eintrag[i].pos, besitzer_p );
if( halt.is_bound() ) {
halt->add_convoy(self);
}
}
}
}


/**
* Unregister the convoy from the stops in the schedule
* @author Knightly
*/
void convoi_t::unregister_stops()
{
if( fpl ) {
for( uint8 i=0; i<fpl->get_count(); ++i ) {
const halthandle_t halt = haltestelle_t::get_halt( welt, fpl->eintrag[i].pos, besitzer_p );
if( halt.is_bound() ) {
halt->remove_convoy(self);
}
}
}
}


/*
* the current state saved as color
Expand Down
12 changes: 12 additions & 0 deletions simconvoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,18 @@ class convoi_t : public sync_steppable, public overtaker_t

void check_pending_updates();

/**
* Register the convoy with the stops in the schedule
* @author Knightly
*/
void register_stops();

/**
* Unregister the convoy from the stops in the schedule
* @author Knightly
*/
void unregister_stops();

uint32 move_to(karte_t const&, koord3d const& k, uint16 start_index);

public:
Expand Down
47 changes: 37 additions & 10 deletions simhalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,6 @@ sint32 haltestelle_t::rebuild_destinations()

minivec_tpl<uint8> supported_catg_index(32);

vector_tpl<convoihandle_t>::const_iterator index_for_convoys = welt->convois_begin();

/*
* In the first loops:
* lines==true => search for lines
Expand All @@ -1028,7 +1026,8 @@ sint32 haltestelle_t::rebuild_destinations()
*/
bool lines = true;
uint32 index_for_lines = 0;
while( lines || index_for_convoys < welt->convois_end() ) {
uint32 index_for_convoys = 0;
while( lines || index_for_convoys < registered_convoys.get_count() ) {

// Gives the first occurence of "self" in "fpl".
uint8 first_self_index = 0;
Expand All @@ -1053,7 +1052,7 @@ sint32 haltestelle_t::rebuild_destinations()
goods_catg_index = &line->get_goods_catg_index();
}
else {
convoihandle_t cnv = *index_for_convoys;
convoihandle_t cnv = registered_convoys[index_for_convoys];
++index_for_convoys;
if( cnv->get_line().is_bound() ) {
continue;
Expand Down Expand Up @@ -2461,16 +2460,16 @@ bool haltestelle_t::add_grund(grund_t *gr)
}
}

// check, if we have to add a line to this coordinate
// check if we have to register line(s) and/or lineless convoy(s) which serve this halt
vector_tpl<linehandle_t> check_line(0);
if(get_besitzer()==welt->get_spieler(1)) {
if( get_besitzer()==welt->get_spieler(1) ) {
// must iterate over all players lines ...
for( int i=0; i<MAX_PLAYER_COUNT; i++ ) {
if(welt->get_spieler(i)) {
welt->get_spieler(i)->simlinemgmt.get_lines(simline_t::line, &check_line);
for( uint j=0; j<check_line.get_count(); j++ ) {
// only add unknow lines
if( !registered_lines.is_contained(check_line[j]) ) {
// only add unknown lines
if( !registered_lines.is_contained(check_line[j]) && check_line[j]->count_convoys()>0 ) {
const schedule_t *fpl = check_line[j]->get_schedule();
for( int k=0; k<fpl->get_count(); k++ ) {
if(get_halt(welt,fpl->eintrag[k].pos,check_line[j]->get_besitzer())==self) {
Expand All @@ -2482,12 +2481,26 @@ bool haltestelle_t::add_grund(grund_t *gr)
}
}
}
// Knightly : iterate over all convoys
for( vector_tpl<convoihandle_t>::const_iterator i=welt->convois_begin(), end=welt->convois_end(); i!=end; ++i ) {
const convoihandle_t cnv = (*i);
// only check lineless convoys which are not yet registered
if( !cnv->get_line().is_bound() && !registered_convoys.is_contained(cnv) ) {
const schedule_t *const fpl = cnv->get_schedule();
for( int k=0; k<fpl->get_count(); ++k ) {
if( get_halt(welt, fpl->eintrag[k].pos, get_besitzer())==self ) {
registered_convoys.append(cnv);
break;
}
}
}
}
}
else {
get_besitzer()->simlinemgmt.get_lines(simline_t::line, &check_line);
for( uint32 j=0; j<check_line.get_count(); j++ ) {
// only add unknow lines
if( !registered_lines.is_contained(check_line[j]) ) {
// only add unknown lines
if( !registered_lines.is_contained(check_line[j]) && check_line[j]->count_convoys()>0 ) {
const schedule_t *fpl = check_line[j]->get_schedule();
for( int k=0; k<fpl->get_count(); k++ ) {
if(get_halt(welt,fpl->eintrag[k].pos,get_besitzer())==self) {
Expand All @@ -2497,6 +2510,20 @@ bool haltestelle_t::add_grund(grund_t *gr)
}
}
}
// Knightly : iterate over all convoys
for( vector_tpl<convoihandle_t>::const_iterator i=welt->convois_begin(), end=welt->convois_end(); i!=end; ++i ) {
const convoihandle_t cnv = (*i);
// only check lineless convoys which have matching ownership and which are not yet registered
if( !cnv->get_line().is_bound() && cnv->get_besitzer()==get_besitzer() && !registered_convoys.is_contained(cnv) ) {
const schedule_t *const fpl = cnv->get_schedule();
for( int k=0; k<fpl->get_count(); ++k ) {
if( get_halt(welt, fpl->eintrag[k].pos, get_besitzer())==self ) {
registered_convoys.append(cnv);
break;
}
}
}
}
}

assert(welt->lookup(pos)->get_halt() == self && gr->is_halt());
Expand Down
Loading

0 comments on commit 76f3cba

Please sign in to comment.