Fix set distributed timetable start not working when using minutes.

Remove WALLCLOCK_NETWORK_COMPATIBLE, it's a pain and not useful.
Whitespace fixes.
This commit is contained in:
Jonathan G Rennison
2016-01-30 15:43:31 +00:00
parent 78cf5ca682
commit 712d5e9c66
7 changed files with 21 additions and 49 deletions

View File

@@ -23,11 +23,7 @@ struct BaseConsist {
/* Used for timetabling. */ /* Used for timetabling. */
uint32 current_order_time; ///< How many ticks have passed since this order started. uint32 current_order_time; ///< How many ticks have passed since this order started.
int32 lateness_counter; ///< How many ticks late (or early if negative) this vehicle is. int32 lateness_counter; ///< How many ticks late (or early if negative) this vehicle is.
#if WALLCLOCK_NETWORK_COMPATIBLE
Date timetable_start; ///< When the vehicle is supposed to start the timetable.
#else
DateTicks timetable_start; ///< When the vehicle is supposed to start the timetable. DateTicks timetable_start; ///< When the vehicle is supposed to start the timetable.
#endif
uint16 service_interval; ///< The interval for (automatic) servicing; either in days or %. uint16 service_interval; ///< The interval for (automatic) servicing; either in days or %.

View File

@@ -264,7 +264,7 @@ struct SetMinutesWindow : SetDateWindow
case WID_SD_SET_DATE: case WID_SD_SET_DATE:
if (this->callback != NULL) { if (this->callback != NULL) {
this->callback(this->parent, (((DateTicks)minutes - _settings_client.gui.clock_offset) * _settings_client.gui.ticks_per_minute) this->callback(this, (((DateTicks)minutes - _settings_client.gui.clock_offset) * _settings_client.gui.ticks_per_minute)
/ _settings_game.economy.day_length_factor); / _settings_game.economy.day_length_factor);
} }
delete this; delete this;

View File

@@ -3098,15 +3098,7 @@ bool AfterLoadGame()
#endif #endif
} }
if (SlXvIsFeaturePresent(XSLFI_TIMETABLES_START_TICKS) && WALLCLOCK_NETWORK_COMPATIBLE) { if (SlXvIsFeatureMissing(XSLFI_TIMETABLES_START_TICKS)) {
// savegame timetable start is in ticks, but we want it in days, fix it up
Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->timetable_start != 0) {
v->timetable_start /= DAY_TICKS;
}
}
} else if (SlXvIsFeatureMissing(XSLFI_TIMETABLES_START_TICKS) && (!WALLCLOCK_NETWORK_COMPATIBLE)) {
// savegame timetable start is in days, but we want it in ticks, fix it up // savegame timetable start is in days, but we want it in ticks, fix it up
Vehicle *v; Vehicle *v;
FOR_ALL_VEHICLES(v) { FOR_ALL_VEHICLES(v) {

View File

@@ -52,7 +52,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_PROG_SIGS, XSCF_NULL, 1, 1, "programmable_signals", NULL, NULL, "SPRG" }, { XSLFI_PROG_SIGS, XSCF_NULL, 1, 1, "programmable_signals", NULL, NULL, "SPRG" },
{ XSLFI_ADJACENT_CROSSINGS, XSCF_NULL, 1, 1, "adjacent_crossings", NULL, NULL, NULL }, { XSLFI_ADJACENT_CROSSINGS, XSCF_NULL, 1, 1, "adjacent_crossings", NULL, NULL, NULL },
{ XSLFI_DEPARTURE_BOARDS, XSCF_IGNORABLE_UNKNOWN, 1, 1, "departure_boards", NULL, NULL, NULL }, { XSLFI_DEPARTURE_BOARDS, XSCF_IGNORABLE_UNKNOWN, 1, 1, "departure_boards", NULL, NULL, NULL },
{ XSLFI_TIMETABLES_START_TICKS, XSCF_NULL, WALLCLOCK_NETWORK_COMPATIBLE ? 0 : 1, 1, "timetable_start_ticks", NULL, NULL, NULL }, { XSLFI_TIMETABLES_START_TICKS, XSCF_NULL, 1, 1, "timetable_start_ticks", NULL, NULL, NULL },
{ XSLFI_TOWN_CARGO_ADJ, XSCF_IGNORABLE_UNKNOWN, 1, 1, "town_cargo_adj", NULL, NULL, NULL }, { XSLFI_TOWN_CARGO_ADJ, XSCF_IGNORABLE_UNKNOWN, 1, 1, "town_cargo_adj", NULL, NULL, NULL },
{ XSLFI_SIG_TUNNEL_BRIDGE, XSCF_NULL, 1, 1, "signal_tunnel_bridge", NULL, NULL, NULL }, { XSLFI_SIG_TUNNEL_BRIDGE, XSCF_NULL, 1, 1, "signal_tunnel_bridge", NULL, NULL, NULL },
{ XSLFI_IMPROVED_BREAKDOWNS, XSCF_NULL, 2, 2, "improved_breakdowns", NULL, NULL, NULL }, { XSLFI_IMPROVED_BREAKDOWNS, XSCF_NULL, 2, 2, "improved_breakdowns", NULL, NULL, NULL },

View File

@@ -15,8 +15,6 @@
#include "date_type.h" #include "date_type.h"
#include "vehicle_type.h" #include "vehicle_type.h"
#define WALLCLOCK_NETWORK_COMPATIBLE 0 ///< Whether wallclock should preserve network compatibility. If so, then timetable start dates cannot be set exactly using minutes.
void ShowTimetableWindow(const Vehicle *v); void ShowTimetableWindow(const Vehicle *v);
void UpdateVehicleTimetable(Vehicle *v, bool travelling); void UpdateVehicleTimetable(Vehicle *v, bool travelling);
void SetTimetableParams(int param1, int param2, Ticks ticks); void SetTimetableParams(int param1, int param2, Ticks ticks);

View File

@@ -284,17 +284,9 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
CommandCost ret = CheckOwnership(v->owner); CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
DateTicks start_date = (Date)p2 / DAY_TICKS;
#if WALLCLOCK_NETWORK_COMPATIBLE
/* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR;
if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (timetable_all && !v->orders.list->IsCompleteTimetable()) return CMD_ERROR; if (timetable_all && !v->orders.list->IsCompleteTimetable()) return CMD_ERROR;
#else
start_date = ((DateTicks)_date * DAY_TICKS) + _date_fract + (DateTicks)(int32)p2; DateTicks start_date = ((DateTicks)_date * DAY_TICKS) + _date_fract + (DateTicks)(int32)p2;
#endif
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
SmallVector<Vehicle *, 8> vehs; SmallVector<Vehicle *, 8> vehs;
@@ -323,11 +315,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
w->lateness_counter = 0; w->lateness_counter = 0;
ClrBit(w->vehicle_flags, VF_TIMETABLE_STARTED); ClrBit(w->vehicle_flags, VF_TIMETABLE_STARTED);
/* Do multiplication, then division to reduce rounding errors. */ /* Do multiplication, then division to reduce rounding errors. */
#if WALLCLOCK_NETWORK_COMPATIBLE
w->timetable_start = start_date + idx * total_duration / num_vehs / DAY_TICKS;
#else
w->timetable_start = start_date + idx * total_duration / num_vehs; w->timetable_start = start_date + idx * total_duration / num_vehs;
#endif
SetWindowDirty(WC_VEHICLE_TIMETABLE, w->index); SetWindowDirty(WC_VEHICLE_TIMETABLE, w->index);
} }
@@ -622,11 +610,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED); just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
if (v->timetable_start != 0) { if (v->timetable_start != 0) {
#if WALLCLOCK_NETWORK_COMPATIBLE
v->lateness_counter = ((_date - v->timetable_start) * DAY_TICKS + _date_fract) * _settings_game.economy.day_length_factor + _tick_skip_counter;
#else
v->lateness_counter = ((_date * DAY_TICKS) + _date_fract - v->timetable_start) * _settings_game.economy.day_length_factor + _tick_skip_counter; v->lateness_counter = ((_date * DAY_TICKS) + _date_fract - v->timetable_start) * _settings_game.economy.day_length_factor + _tick_skip_counter;
#endif
v->timetable_start = 0; v->timetable_start = 0;
} }

View File

@@ -140,6 +140,15 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID
} }
} }
/**
* Callback for when a time has been chosen to start the time table
* @param p1 The p1 parameter to send to CmdSetTimetableStart
* @param date the actually chosen date
*/
static void ChangeTimetableStartIntl(uint32 p1, DateTicks date)
{
DoCommandP(0, p1, (Ticks)(date - (((DateTicks)_date * DAY_TICKS) + _date_fract)), CMD_SET_TIMETABLE_START | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
}
/** /**
* Callback for when a time has been chosen to start the time table * Callback for when a time has been chosen to start the time table
@@ -148,23 +157,19 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID
*/ */
static void ChangeTimetableStartCallback(const Window *w, DateTicks date) static void ChangeTimetableStartCallback(const Window *w, DateTicks date)
{ {
#if WALLCLOCK_NETWORK_COMPATIBLE ChangeTimetableStartIntl(w->window_number, date);
DoCommandP(0, w->window_number, (Date)(date / DAY_TICKS), CMD_SET_TIMETABLE_START | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
#else
DoCommandP(0, w->window_number, (Ticks)(date - (((DateTicks)_date * DAY_TICKS) + _date_fract)), CMD_SET_TIMETABLE_START | CMD_MSG(STR_ERROR_CAN_T_TIMETABLE_VEHICLE));
#endif
} }
struct TimetableWindow : Window { struct TimetableWindow : Window {
int sel_index; int sel_index;
const Vehicle *vehicle; ///< Vehicle monitored by the window. const Vehicle *vehicle; ///< Vehicle monitored by the window.
bool show_expected; ///< Whether we show expected arrival or scheduled bool show_expected; ///< Whether we show expected arrival or scheduled
uint deparr_time_width; ///< The width of the departure/arrival time uint deparr_time_width; ///< The width of the departure/arrival time
uint deparr_abbr_width; ///< The width of the departure/arrival abbreviation uint deparr_abbr_width; ///< The width of the departure/arrival abbreviation
int clicked_widget; ///< The widget that was clicked (used to determine what to do in OnQueryTextFinished) int clicked_widget; ///< The widget that was clicked (used to determine what to do in OnQueryTextFinished)
Scrollbar *vscroll; Scrollbar *vscroll;
bool query_is_speed_query; ///< The currently open query window is a speed query and not a time query. bool query_is_speed_query; ///< The currently open query window is a speed query and not a time query.
bool set_start_date_all; ///< Set start date using minutes text entry: this is a set all vehicle (ctrl-click) action
TimetableWindow(WindowDesc *desc, WindowNumber window_number) : TimetableWindow(WindowDesc *desc, WindowNumber window_number) :
Window(desc), Window(desc),
@@ -513,11 +518,7 @@ struct TimetableWindow : Window {
/* We are running towards the first station so we can start the /* We are running towards the first station so we can start the
* timetable at the given time. */ * timetable at the given time. */
SetDParam(0, STR_JUST_DATE_WALLCLOCK_TINY); SetDParam(0, STR_JUST_DATE_WALLCLOCK_TINY);
#if WALLCLOCK_NETWORK_COMPATIBLE
SetDParam(1, v->timetable_start * DAY_TICKS * _settings_game.economy.day_length_factor);
#else
SetDParam(1, v->timetable_start * _settings_game.economy.day_length_factor); SetDParam(1, v->timetable_start * _settings_game.economy.day_length_factor);
#endif
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_TIMETABLE_STATUS_START_AT); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_TIMETABLE_STATUS_START_AT);
} else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) { } else if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
/* We aren't running on a timetable yet, so how can we be "on time" /* We aren't running on a timetable yet, so how can we be "on time"
@@ -548,7 +549,7 @@ struct TimetableWindow : Window {
{ {
const Vehicle *v = this->vehicle; const Vehicle *v = this->vehicle;
this->clicked_widget = widget; this->clicked_widget = widget;
switch (widget) { switch (widget) {
case WID_VT_ORDER_VIEW: // Order view button case WID_VT_ORDER_VIEW: // Order view button
@@ -565,11 +566,12 @@ struct TimetableWindow : Window {
case WID_VT_START_DATE: // Change the date that the timetable starts. case WID_VT_START_DATE: // Change the date that the timetable starts.
if (_settings_client.gui.time_in_minutes && _settings_client.gui.timetable_start_text_entry) { if (_settings_client.gui.time_in_minutes && _settings_client.gui.timetable_start_text_entry) {
this->set_start_date_all = v->orders.list->IsCompleteTimetable() && _ctrl_pressed;
StringID str = STR_JUST_INT; StringID str = STR_JUST_INT;
uint64 time = CURRENT_SCALED_TICKS; uint64 time = CURRENT_SCALED_TICKS;
time /= _settings_client.gui.ticks_per_minute; time /= _settings_client.gui.ticks_per_minute;
time += _settings_client.gui.clock_offset; time += _settings_client.gui.clock_offset;
time %= 24*60; time %= (24 * 60);
time = (time % 60) + (((time / 60) % 24) * 100); time = (time % 60) + (((time / 60) % 24) * 100);
SetDParam(0, time); SetDParam(0, time);
ShowQueryString(str, STR_TIMETABLE_STARTING_DATE, 31, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); ShowQueryString(str, STR_TIMETABLE_STARTING_DATE, 31, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
@@ -704,7 +706,7 @@ struct TimetableWindow : Window {
if (val < (CURRENT_MINUTE - 60)) val += 60 * 24; if (val < (CURRENT_MINUTE - 60)) val += 60 * 24;
val *= _settings_client.gui.ticks_per_minute; val *= _settings_client.gui.ticks_per_minute;
val /= _settings_game.economy.day_length_factor; val /= _settings_game.economy.day_length_factor;
ChangeTimetableStartCallback(this, val); ChangeTimetableStartIntl(v->index | (this->set_start_date_all ? 1 << 20 : 0), val);
} }
break; break;
} }