Skip to content

Commit

Permalink
(part of r9462) port some schedule controll function from standard
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranran-the-JuicyPork committed Feb 11, 2024
1 parent 3db7204 commit 7a37d9a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
65 changes: 65 additions & 0 deletions dataobj/schedule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,71 @@ bool schedule_t::remove()



void schedule_t::remove_entry( uint8 delete_enty )
{
if( current_stop > delete_enty ) {
current_stop--;
}
bool ok = entries.remove_at(delete_enty);
make_current_stop_valid();
}



void schedule_t::move_entry_forward( uint8 cur )
{
if( entries.get_count() <= 2 ) {
return;
}
// so we have something to do
uint8 new_cur = (cur + entries.get_count() - 1) % entries.get_count();
schedule_entry_t cur_entry = entries[ cur ];
entries.remove_at( cur );
if ( cur==0 ) {
current_stop = (current_stop + entries.get_count() - 1) % entries.get_count();
entries.append( cur_entry );
}
else {
if( current_stop == cur ) {
current_stop = new_cur;
}
else if( current_stop == new_cur ) {
current_stop++;
}
entries.insert_at( new_cur, cur_entry );
}
make_current_stop_valid();
}



void schedule_t::move_entry_backward( uint8 cur )
{
if( entries.get_count() <= 2 ) {
return;
}
// so we have something to do
uint8 new_cur = (cur + 1) % entries.get_count();
schedule_entry_t cur_entry = entries[ cur ];
entries.remove_at( cur );
if ( new_cur==0 ) {
entries.insert_at( 0, cur_entry );
current_stop = (current_stop + 1) % entries.get_count();
}
else {
if( current_stop == cur ) {
current_stop = new_cur;
}
else if( current_stop == new_cur ) {
current_stop --;
}
entries.insert_at( new_cur, cur_entry );
}
make_current_stop_valid();
}



void schedule_t::rdwr(loadsave_t *file)
{
xml_tag_t f( file, "schedule_t" );
Expand Down
9 changes: 9 additions & 0 deletions dataobj/schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ class schedule_t

virtual waytype_t get_waytype() const = 0;

// remove this entry
void remove_entry( uint8 entry );

// move the entry to front (and wrap)
void move_entry_forward( uint8 entry );

// move the entry to back (and wrap)
void move_entry_backward( uint8 entry );

/**
* Get current stop of the schedule.
*/
Expand Down

0 comments on commit 7a37d9a

Please sign in to comment.