Changeset - r28719:83720a6d2be9
[Not reviewed]
master
0 1 0
Tyler Trahan - 10 months ago 2024-02-09 16:45:32
tyler@tylertrahan.com
Fix #12022: Adjust economy date when changing timekeeping units in Scenario Editor (#12042)
1 file changed with 24 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/settings_table.cpp
Show inline comments
 
@@ -17,6 +17,7 @@
 
#include "network/network_func.h"
 
#include "network/core/config.h"
 
#include "pathfinder/pathfinder_type.h"
 
#include "linkgraph/linkgraphschedule.h"
 
#include "genworld.h"
 
#include "train.h"
 
#include "news_func.h"
 
@@ -541,6 +542,29 @@ static void ChangeTimekeepingUnits(int32
 
	}
 

	
 
	InvalidateWindowClassesData(WC_GAME_OPTIONS, 0);
 

	
 
	/* It is possible to change these units in Scenario Editor. We must set the economy date appropriately. */
 
	if (_game_mode == GM_EDITOR) {
 
		TimerGameEconomy::Date new_economy_date;
 
		TimerGameEconomy::DateFract new_economy_date_fract;
 

	
 
		if (TimerGameEconomy::UsingWallclockUnits()) {
 
			/* If the new mode is wallclock units, set the economy year back to 1. */
 
			new_economy_date = TimerGameEconomy::ConvertYMDToDate(1, 0, 1);
 
			new_economy_date_fract = 0;
 
		} else {
 
			/* If the new mode is calendar units, sync the economy year with the calendar year. */
 
			new_economy_date = TimerGameCalendar::date.base();
 
			new_economy_date_fract = TimerGameCalendar::date_fract;
 
		}
 

	
 
		/* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
 
		LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
 
		for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
 

	
 
		/* Only change the date after changing cached values above. */
 
		TimerGameEconomy::SetDate(new_economy_date, new_economy_date_fract);
 
	}
 
}
 

	
 
/**
0 comments (0 inline, 0 general)