Skip to content

Commit

Permalink
sanitize reserved_tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
teamhimeh committed Oct 31, 2018
1 parent 81168a0 commit 16284a7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
27 changes: 27 additions & 0 deletions simconvoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4165,3 +4165,30 @@ void convoi_t::request_longblock_signal_judge(signal_t *sig, uint16 next_block)
longblock_signal_request.next_block = next_block;
longblock_signal_request.valid = true;
}

void convoi_t::clear_reserved_tiles(){
if( reserved_tiles.get_count()==0 ) {
// nothing to do.
return;
}
// determine next_reservation_index
for( sint32 i=route.get_count()-1; i>=0; i-- ) {
if( reserved_tiles.is_contained(route.at(i)) ) {
// set next_reservation_index
set_next_reservation_index(i);
break;
}
}
// unreserve all tiles that are not in route
for( uint32 i=0; i<reserved_tiles.get_count(); i++ ) {
if( !route.is_contained(reserved_tiles[i]) ) {
// unreserve the tile
grund_t* gr = welt->lookup(reserved_tiles[i]);
schiene_t* sch = gr ? (schiene_t*)gr->get_weg(front()->get_waytype()) : NULL;
if( sch ) {
sch->unreserve(self);
}
}
}
reserved_tiles.clear();
}
1 change: 1 addition & 0 deletions simconvoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ class convoi_t : public sync_steppable, public overtaker_t
void reserve_pos(koord3d pos) {reserved_tiles.append_unique(pos); }
bool is_reservation_empty() const { return reserved_tiles.empty(); }
vector_tpl<koord3d>& get_reserved_tiles() { return reserved_tiles; }
void clear_reserved_tiles();

/* the current state of the convoi */
PIXVAL get_status_color() const;
Expand Down
2 changes: 1 addition & 1 deletion simversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// NOTE: increment before next release to enable save/load of new features

#define OTRP_VERSION_MAJOR 19
#define OTRP_VERSION_MINOR 1
#define OTRP_VERSION_MINOR 2
// NOTE: increment OTRP_VERSION_MAJOR when the save data structure changes.

#define MAKEOBJ_VERSION "60.2"
Expand Down
5 changes: 5 additions & 0 deletions vehicle/simvehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3657,6 +3657,11 @@ bool rail_vehicle_t::is_signal_clear(uint16 next_block, sint32 &restart_speed)
// action depend on the next signal
const roadsign_desc_t *sig_desc=sig->get_desc();

// If the next signal is not a longblock signal, reservation must be handled by next_reservation_index.
if( !sig_desc->is_longblock_signal() ) {
cnv->clear_reserved_tiles();
}

// simple signal: drive on, if next block is free
if( !sig_desc->is_longblock_signal() &&
!sig_desc->is_choose_sign() &&
Expand Down

0 comments on commit 16284a7

Please sign in to comment.