Skip to content

Commit

Permalink
Now setting load limit to zero and a waiting time will create an abso…
Browse files Browse the repository at this point in the history
…lute dparture

git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@9771 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed May 15, 2021
1 parent 62f342c commit 531a0ea
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 206 deletions.
7 changes: 6 additions & 1 deletion dataobj/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ settings_t::settings_t() :

used_vehicle_reduction = 0;

departures_on_time = false;

// some network thing to keep client in sync
random_counter = 0; // will be set when actually saving
frames_per_second = 20;
Expand Down Expand Up @@ -901,7 +903,8 @@ void settings_t::rdwr(loadsave_t *file)
}
if( file->is_version_atleast(122, 1) ) {
file->rdwr_enum(climate_generator);
file->rdwr_byte( wind_direction );
file->rdwr_byte(wind_direction);
file->rdwr_bool(departures_on_time);
}
else if( file->is_loading() ) {
climate_generator = HEIGHT_BASED;
Expand Down Expand Up @@ -1227,6 +1230,8 @@ void settings_t::parse_simuconf( tabfile_t& simuconf, sint16& disp_width, sint16
factory_maximum_intransit_percentage = contents.get_int_clamped( "maximum_intransit_percentage", factory_maximum_intransit_percentage, 0, 0x7FFF );
factory_enforce_demand = contents.get_int( "factory_enforce_demand", factory_enforce_demand ) != 0;

departures_on_time = contents.get_int("departures_on_time", departures_on_time ) != 0;

tourist_percentage = contents.get_int_clamped( "tourist_percentage", tourist_percentage, 0, 100 );

// .. read twice: old and right spelling
Expand Down
6 changes: 6 additions & 0 deletions dataobj/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class settings_t

uint16 station_coverage_size;

// convois depart even if not unloaded if the time is up
bool departures_on_time;

// the maximum length of each convoi
uint8 max_rail_convoi_length;
uint8 max_road_convoi_length;
Expand Down Expand Up @@ -634,6 +637,9 @@ class settings_t

uint32 get_default_ai_construction_speed() const { return default_ai_construction_speed; }
void set_default_ai_construction_speed( uint32 n ) { default_ai_construction_speed = n; }

bool get_departures_on_time() const { return departures_on_time; }
void set_departures_on_time(bool b) { departures_on_time = b; }
};

#endif
26 changes: 26 additions & 0 deletions dataobj/translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,32 @@ const char *translator::get_short_date(uint16 year, uint16 month)
}


const char* translator::get_month_date(uint16 month, uint16 day)
{
char const* const month_ = get_month_name(month);
char const* const day_sym = strcmp("DAY_SYMBOL", translate("DAY_SYMBOL")) ? translate("DAY_SYMBOL") : "";
static char date[256];
switch (env_t::show_month) {
case env_t::DATE_FMT_GERMAN:
case env_t::DATE_FMT_GERMAN_NO_SEASON:
sprintf(date, "%d. %s ", day, month_);
break;
case env_t::DATE_FMT_US:
case env_t::DATE_FMT_US_NO_SEASON:
sprintf(date, "%s %d ", month_, day);
break;
case env_t::DATE_FMT_JAPANESE:
case env_t::DATE_FMT_JAPANESE_NO_SEASON:
sprintf(date, "%s %d%s", month_, day, day_sym);
break;
case env_t::DATE_FMT_SEASON:
case env_t::DATE_FMT_MONTH:
sprintf(date, "%s, ", month_);
break;
}
return date;
}

/* get a name for a non-matching object */
const char *translator::compatibility_name(const char *str)
{
Expand Down
3 changes: 2 additions & 1 deletion dataobj/translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class translator
// return date in selected format
static const char *get_date(uint16 year, uint16 month);
static const char *get_date(uint16 year, uint16 month, uint16 day, char const* season);
static const char *get_short_date(uint16 year, uint16 month);
static const char* get_short_date(uint16 year, uint16 month);
static const char* get_month_date(uint16 month, uint16 day);
};

#endif
24 changes: 22 additions & 2 deletions gui/halt_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,32 @@ void gui_departure_board_t::update_departures(halthandle_t halt)

// iterate over all convoys stopping here
FOR( slist_tpl<convoihandle_t>, cnv, halt->get_loading_convois() ) {
if( !cnv.is_bound()) {
if( !cnv.is_bound() && cnv->get_state()!=convoi_t::LOADING ) {
continue;
}
halthandle_t next_halt = cnv->get_schedule()->get_next_halt(cnv->get_owner(),halt);
if( next_halt.is_bound() ) {
dest_info_t next( next_halt, 0, cnv );

uint32 delta_ticks = 0;
if( cnv->get_schedule()->get_current_entry().waiting_time > 0 ) {
if( cnv->get_schedule()->get_current_entry().minimum_loading == 0 ) {
// absolute schedule
delta_ticks = cnv->get_departure_ticks();
}
else {
// waiting for load with max time
delta_ticks = cnv->get_arrival_ticks() + cnv->get_schedule()->get_current_entry().get_waiting_ticks();
}
// avoid overflow when departure time has passed but convoi si still loading etc.
uint32 ct = welt->get_ticks();
if (ct > delta_ticks) {
delta_ticks = 0;
}
else {
delta_ticks -= ct;
}
}
dest_info_t next( next_halt, delta_ticks, cnv );
destinations.append_unique( next );
if( grund_t *gr = welt->lookup( cnv->get_vehikel(0)->last_stop_pos ) ) {
if( gr->get_halt().is_bound() && gr->get_halt() != halt ) {
Expand Down
5 changes: 4 additions & 1 deletion gui/settings_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ static char const* const version[] =
"0.120.2",
"0.120.3",
"0.120.4",
"0.120.5"
"0.120.5",
"122.0"
};

bool settings_general_stats_t::action_triggered(gui_action_creator_t *comp, value_t v)
Expand Down Expand Up @@ -84,6 +85,7 @@ void settings_general_stats_t::init(settings_t const* const sets)
INIT_BOOL( "numbered_stations", sets->get_numbered_stations() );
INIT_NUM( "show_names", env_t::show_names, 0, 3, gui_numberinput_t::AUTOLINEAR, true );
SEPERATOR
INIT_BOOL( "departures_on_time", sets->get_departures_on_time() );
INIT_NUM( "bits_per_month", sets->get_bits_per_month(), 16, 24, gui_numberinput_t::AUTOLINEAR, false );
INIT_NUM( "use_timeline", sets->get_use_timeline(), 0, 3, gui_numberinput_t::AUTOLINEAR, false );
INIT_NUM_NEW( "starting_year", sets->get_starting_year(), 0, 2999, gui_numberinput_t::AUTOLINEAR, false );
Expand Down Expand Up @@ -128,6 +130,7 @@ void settings_general_stats_t::read(settings_t* const sets)
READ_BOOL_VALUE( sets->numbered_stations );
READ_NUM_VALUE( env_t::show_names );

READ_BOOL_VALUE( sets->departures_on_time );
READ_NUM_VALUE( sets->bits_per_month );
READ_NUM_VALUE( sets->use_timeline );
READ_NUM_VALUE_NEW( sets->starting_year );
Expand Down
49 changes: 48 additions & 1 deletion simconvoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,8 @@ void convoi_t::step()

// Same as waiting for free way
case ROUTING_1:
// immediate start required
if (wait_lock == 0) break;
case CAN_START:
case WAITING_FOR_CLEARANCE:
// unless a longer wait is requested
Expand Down Expand Up @@ -2845,6 +2847,24 @@ void convoi_t::calc_gewinn()
}



uint32 convoi_t::get_departure_ticks() const
{
// we need to make it this complicated, otherwise times versus the end of a month could be missed
uint32 arrived_month_tick = arrived_time & ~(welt->ticks_per_world_month - 1);
uint32 arrived_ticks = arrived_time - arrived_month_tick;
uint32 departure_ticks = schedule->get_current_entry().get_waiting_ticks();
// if there is less than half a month to wait we will assume we arrived early, else we this we are late ...
if (arrived_ticks > departure_ticks && // we are late
(arrived_ticks - departure_ticks) > (welt->ticks_per_world_month / 2)) {
// but we are more than half a month later => assume the departure is scheduled for next month
arrived_month_tick += welt->ticks_per_world_month;
}
return arrived_month_tick + departure_ticks;
}



/**
* convoi an haltestelle anhalten
*
Expand Down Expand Up @@ -3019,12 +3039,39 @@ station_tile_search_ready: ;
book(gewinn, CONVOI_REVENUE);
}

// if we check here we will continue loading even if the departure is delayed
wait_lock = WTT_LOADING;
if (wants_more) {
if (wants_more && !welt->get_settings().get_departures_on_time() ) {
// not yet fully unloaded/loaded
return;
}

// find out if there is a times departure pending => depart
if( schedule->get_current_entry().minimum_loading == 0 && schedule->get_current_entry().waiting_time > 0 ) {

if( welt->get_ticks() > get_departure_ticks() ) {

// add available capacity after loading(!) to statistics
for (unsigned i = 0; i < anz_vehikel; i++) {
book(get_vehikel(i)->get_cargo_max() - get_vehikel(i)->get_total_cargo(), CONVOI_CAPACITY);
}

// Advance schedule
schedule->advance();
state = ROUTING_1;
loading_limit = 0;
wait_lock = 0;
}

// else continue loading (even if full until departure time reached)
return;
}

if (wants_more) {
// not yet fully unloaded/loaded => continue loading
return;
}

// loading is finished => maybe drive on
if( loading_level >= loading_limit || no_load
|| (schedule->get_current_entry().waiting_time > 0 && (welt->get_ticks() - arrived_time) > schedule->get_current_entry().get_waiting_ticks() ) ) {
Expand Down
4 changes: 4 additions & 0 deletions simconvoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ class convoi_t : public sync_steppable, public overtaker_t
uint32 move_to(uint16 start_index);

public:
uint32 get_arrival_ticks() const { return arrived_time; }

uint32 get_departure_ticks() const;

/**
* Convoi haelt an Haltestelle und setzt quote fuer Fracht
*/
Expand Down
6 changes: 4 additions & 2 deletions simintr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void intr_enable()
}


char const *tick_to_string( uint32 ticks )
char const *tick_to_string( uint32 ticks, bool only_DDMMHHMM )
{
static sint32 tage_per_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
static char const* const seasons[] = { "q2", "q3", "q4", "q1" };
Expand Down Expand Up @@ -189,7 +189,9 @@ char const *tick_to_string( uint32 ticks )

//DBG_MESSAGE("env_t::show_month","%d",env_t::show_month);
// since seasons 0 is always summer for backward compatibility
char const* const date = translator::get_date(year, month, tage, translator::translate(seasons[welt_modell->get_season()]));
char const* const date = only_DDMMHHMM ?
translator::get_month_date(month, tage) :
translator::get_date(year, month, tage, translator::translate(seasons[welt_modell->get_season()]));
switch (env_t::show_month) {
case env_t::DATE_FMT_US:
case env_t::DATE_FMT_US_NO_SEASON: {
Expand Down
7 changes: 4 additions & 3 deletions simintr.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ void interrupt_check(const char* caller_info = "0");
#endif
#endif

// returns a time string in the desired format
// Returns an empty string if called before the world model defining time is initalized.
char const *tick_to_string( uint32 ticks );
// returns a time string in the desired format
// Returns an empty string if called before the world model defining time is initalized.
// reutrns a shorter date (without season and yeear if second parameter true)
char const *tick_to_string( uint32 ticks, bool omit_season_year=false );

// returns a time difference string in the desired format
// assume the month has 31 days
Expand Down
4 changes: 4 additions & 0 deletions simutrans/config/simuconf.tab
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ avoid_overcrowding = 0
# do not create goods/passenger/mail when the only route is over an overcrowded stop
no_routing_over_overcrowded = 0

# if 1, a late convoi with s set departure time will depart without finishing unloading or loading
# 0 means departure after finishing to load/unload
departures_on_time = 0

# in beginner mode, all good prices are multiplied by a factor (default 1500=1.5)
beginner_price_factor = 1500

Expand Down
Loading

0 comments on commit 531a0ea

Please sign in to comment.