Changeset - r26:750865a88bb2
[Not reviewed]
master
0 6 0
truelight - 20 years ago 2004-08-12 17:49:16
truelight@openttd.org
(svn r27) -Fix: [1006715] Autorenew issues
-Add: PE_CURRENCY to patchmenu
6 files changed with 70 insertions and 13 deletions:
0 comments (0 inline, 0 general)
lang/english.txt
Show inline comments
 
@@ -903,15 +903,19 @@ STR_TRAIN_IS_LOST						:{WHITE}Train {CO
 
STR_TRAIN_IS_UNPROFITABLE				:{WHITE}Train {COMMA16}'s profit last year was {CURRENCY}
 
STR_EURO_INTRODUCE					:{BLACK}{BIGFONT}European Monetary Union!{}{}The Euro is introduced as the sole currency for everyday transactions in your country!
 

	
 
STR_TRAIN_AUTORENEW_FAILED				:{WHITE}Autorenew failed on train {COMMA16} (money limit)
 
STR_TRAIN_HAS_TOO_FEW_ORDERS				:{WHITE}Train {COMMA16} has too few orders in the schedule
 
STR_TRAIN_HAS_VOID_ORDER						:{WHITE}Train {COMMA16} has a void order
 
STR_TRAIN_HAS_DUPLICATE_ENTRY				:{WHITE}Train {COMMA16} has duplicate orders
 
STR_AIRCRAFT_AUTORENEW_FAILED				:{WHITE}Autorenew failed on aircraft {COMMA16} (money limit)
 
STR_AIRCRAFT_HAS_TOO_FEW_ORDERS			:{WHITE}Aircraft {COMMA16} has too few orders in the schedule
 
STR_AIRCRAFT_HAS_VOID_ORDER					:{WHITE}Aircraft {COMMA16} has void order
 
STR_AIRCRAFT_HAS_DUPLICATE_ENTRY		:{WHITE}Aircraft {COMMA16} has duplicate orders
 
STR_ROADVEHICLE_AUTORENEW_FAILED				:{WHITE}Autorenew failed on road vehicle {COMMA16} (money limit)
 
STR_ROADVEHICLE_HAS_TOO_FEW_ORDERS	:{WHITE}Road Vehicle {COMMA16} has too few orders in the schedule
 
STR_ROADVEHICLE_HAS_VOID_ORDER			:{WHITE}Road Vehicle {COMMA16} has void order
 
STR_ROADVEHICLE_HAS_DUPLICATE_ENTRY	:{WHITE}Road Vehicle {COMMA16} has duplicate orders
 
STR_SHIP_AUTORENEW_FAILED				:{WHITE}Autorenew failed on ship {COMMA16} (money limit)
 
STR_SHIP_HAS_TOO_FEW_ORDERS					:{WHITE}Ship {COMMA16} has too few orders in the schedule
 
STR_SHIP_HAS_VOID_ORDER							:{WHITE}Ship {COMMA16} has void order
 
STR_SHIP_HAS_DUPLICATE_ENTRY				:{WHITE}Ship {COMMA16} has duplicate orders
 
@@ -953,7 +957,9 @@ STR_CONFIG_PATCHES_LOST_TRAIN_DAYS		:{LT
 
STR_CONFIG_PATCHES_LOST_TRAIN_DAYS_DISABLED		:{LTBLUE}A train is lost if no progress is made for: {ORANGE}disabled
 
STR_CONFIG_PATCHES_WARN_INCOME_LESS		:{LTBLUE}Warn if a train's income is negative: {ORANGE}{STRING}
 
STR_CONFIG_PATCHES_NEVER_EXPIRE_VEHICLES	:{LTBLUE}Vehicles never expire: {ORANGE}{STRING}
 
STR_CONFIG_AUTORENEW_VEHICLE			:{LTBLUE}Autorenew vehicle when it gets old
 
STR_CONFIG_PATCHES_AUTORENEW_VEHICLE			:{LTBLUE}Autorenew vehicle when it gets old
 
STR_CONFIG_PATCHES_AUTORENEW_MONTHS			:{LTBLUE}Autorenew when vehice is {ORANGE}{STRING}{LTBLUE} months before/after max age
 
STR_CONFIG_PATCHES_AUTORENEW_MONEY			:{LTBLUE}Autorenew minimum needed money for renew: {ORANGE}{STRING}
 
STR_CONFIG_PATCHES_ERRMSG_DURATION		:{LTBLUE}Duration of error message: {ORANGE}{STRING}
 
STR_CONFIG_PATCHES_SNOWLINE_HEIGHT		:{LTBLUE}Snow line height: {ORANGE}{STRING}
 
STR_CONFIG_PATCHES_STATION_SPREAD		:{LTBLUE}Max station spread: {ORANGE}{STRING}
 
@@ -991,6 +997,7 @@ STR_CONFIG_PATCHES_AI					:{BLACK}Compet
 

	
 
STR_CONFIG_PATCHES_DISABLED				:disabled
 
STR_CONFIG_PATCHES_INT32				:{INT32}
 
STR_CONFIG_PATCHES_CURRENCY				:{CURRENCY}
 

	
 
STR_CONFIG_PATCHES_QUERY_CAPT			:{WHITE}Change setting value
 

	
settings.c
Show inline comments
 
@@ -837,7 +837,8 @@ static const SettingDesc patch_settings[
 
	{"servint_aircraft", SDT_UINT16, (void*)100,(void*)offsetof(Patches, servint_aircraft)},
 

	
 
	{"autorenew", SDT_BOOL, (void*)false,(void*)offsetof(Patches, autorenew)},
 
	{"autorenew_months", SDT_UINT16, (void*)-12, (void*)offsetof(Patches, autorenew_months)},
 
	{"autorenew_months", SDT_INT16, (void*)-6, (void*)offsetof(Patches, autorenew_months)},
 
	{"autorenew_money", SDT_INT32, (void*)100000, (void*)offsetof(Patches, autorenew_money)},
 

	
 
	{"new_pathfinding",  SDT_BOOL, (void*)false, (void*)offsetof(Patches, new_pathfinding)},
 
	{"pf_maxlength", SDT_UINT16, (void*)512, (void*)offsetof(Patches, pf_maxlength)},
settings_gui.c
Show inline comments
 
@@ -659,8 +659,8 @@ typedef struct PatchEntry {
 
	byte flags;		// selector flags
 
	StringID str; // string with descriptive text
 
	void *variable; // pointer to the variable
 
	int16 min,max; // range for spinbox setting
 
	uint16 step;   // step for spinbox
 
	int32 min,max; // range for spinbox setting
 
	uint32 step;   // step for spinbox
 
} PatchEntry;
 

	
 
enum {
 
@@ -669,6 +669,7 @@ enum {
 
	PE_INT16 = 2,
 
	PE_UINT16 = 3,
 
	PE_INT32 = 4,
 
	PE_CURRENCY = 5,
 

	
 
	PF_0ISDIS = 1,
 
	PF_NOCOMMA = 2,
 
@@ -706,7 +707,9 @@ static const PatchEntry _patches_vehicle
 
	{PE_BOOL, 0, STR_CONFIG_PATCHES_NEVER_EXPIRE_VEHICLES, &_patches.never_expire_vehicles},
 

	
 
	{PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_LOST_TRAIN_DAYS, &_patches.lost_train_days, 180, 720, 60},
 
	{PE_BOOL, 0, STR_CONFIG_AUTORENEW_VEHICLE, &_patches.autorenew},
 
	{PE_BOOL, 0, STR_CONFIG_PATCHES_AUTORENEW_VEHICLE, &_patches.autorenew},
 
	{PE_INT16, 0, STR_CONFIG_PATCHES_AUTORENEW_MONTHS, &_patches.autorenew_months, -12, 12, 1},
 
	{PE_CURRENCY, 0, STR_CONFIG_PATCHES_AUTORENEW_MONEY, &_patches.autorenew_money, 0, 2000000, 100000},
 

	
 
	{PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_TRAINS, &_patches.max_trains, 0, 240, 10},
 
	{PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_ROADVEH, &_patches.max_roadveh, 0, 240, 10},
 
@@ -764,6 +767,8 @@ static const PatchPage _patches_page[] =
 
	{_patches_ai, lengthof(_patches_ai) },
 
};
 

	
 
extern uint GetCurrentCurrencyRate();
 

	
 
static int32 ReadPE(const PatchEntry*pe)
 
{
 
	switch(pe->type) {
 
@@ -772,6 +777,7 @@ static int32 ReadPE(const PatchEntry*pe)
 
	case PE_INT16:  return *(int16*)pe->variable;
 
	case PE_UINT16: return *(uint16*)pe->variable;
 
	case PE_INT32:  return *(int32*)pe->variable;
 
	case PE_CURRENCY:  return (*(int64*)pe->variable) * GetCurrentCurrencyRate();
 
	default:
 
		NOT_REACHED();
 
	}
 
@@ -816,6 +822,15 @@ static void WritePE(const PatchEntry *pe
 
								else
 
									*(int32*)pe->variable = val; 
 
								break;
 

	
 
	case PE_CURRENCY: val /= GetCurrentCurrencyRate();
 
								if ((int64)val > (int64)pe->max)
 
									*(int64*)pe->variable = (int64)pe->max;
 
								else if ((int64)val < (int64)pe->min)
 
									*(int64*)pe->variable = (int64)pe->min;
 
								else
 
									*(int64*)pe->variable = val;
 
								break;
 
	default:
 
		NOT_REACHED();
 
	}
 
@@ -852,12 +867,17 @@ static void PatchesSelectionWndProc(Wind
 
				DrawStringCentered(x+20, y+1, STR_681A, 0);
 

	
 
				val = ReadPE(pe);
 
				if (pe->type == PE_CURRENCY)
 
					val /= GetCurrentCurrencyRate();
 
				disabled = ((val == 0) && (pe->flags & PF_0ISDIS));
 
				if (disabled) {
 
					SET_DPARAM16(0, STR_CONFIG_PATCHES_DISABLED);
 
				} else {
 
					SET_DPARAM32(1, val);
 
					SET_DPARAM16(0, pe->flags & PF_NOCOMMA ? STR_CONFIG_PATCHES_INT32 : STR_7024);
 
					if (pe->type == PE_CURRENCY)
 
						SET_DPARAM16(0, STR_CONFIG_PATCHES_CURRENCY);
 
					else
 
						SET_DPARAM16(0, pe->flags & PF_NOCOMMA ? STR_CONFIG_PATCHES_INT32 : STR_7024);
 
				}
 
			}
 
			DrawString(30, y+1, (pe->str)+disabled, 0);
 
@@ -898,6 +918,7 @@ static void PatchesSelectionWndProc(Wind
 
				case PE_INT16:
 
				case PE_UINT16:
 
				case PE_INT32:
 
				case PE_CURRENCY:
 
					// don't allow too fast scrolling
 
					if ((w->flags4 & WF_TIMEOUT_MASK) > 2 << WF_TIMEOUT_SHL) {
 
						_left_button_clicked = false;
strings.c
Show inline comments
 
@@ -322,6 +322,10 @@ static byte *FormatMonthAndYear(byte *bu
 
	return FormatNoCommaNumber(buff, ymd.year + 1920);
 
}
 

	
 
uint GetCurrentCurrencyRate() {
 
    return (&_currency_specs[_opt.currency])->rate;
 
}
 

	
 
static byte *FormatGenericCurrency(byte *buff, const CurrencySpec *spec, int64 number, bool compact)
 
{
 
	const char *s;
variables.h
Show inline comments
 
@@ -120,7 +120,8 @@ typedef struct Patches {
 
	uint16 servint_ships;		// service interval for ships
 

	
 
	bool autorenew;
 
	uint16 autorenew_months;
 
	int16 autorenew_months;
 
	int32 autorenew_money;
 

	
 
	bool new_pathfinding;		// use optimized pathfinding algoritm for trains
 
	byte pf_maxdepth;				// maximum recursion depth when searching for a train route for new pathfinder
vehicle.c
Show inline comments
 
@@ -1302,6 +1302,9 @@ static void ShowVehicleGettingOld(Vehicl
 
{
 
	if (v->owner != _local_player)
 
		return;
 
	// Do not show getting-old message if autorenew is active
 
	if (_patches.autorenew)
 
		return;
 

	
 
	SET_DPARAM16(0, _vehicle_type_names[v->type - 0x10]);
 
	SET_DPARAM16(1, v->unitnumber);
 
@@ -1334,13 +1337,33 @@ void MaybeRenewVehicle(Vehicle *v, int32
 
{
 
	Engine *e;
 

	
 
	// When automatically renewing a vehicle we want to prevent the
 
	// "getting old" messages so we renew it if it won't enter the
 
	// depot during the next service sooner than half a year before
 
	// the vehicle getting old (that's one year before it reaches
 
	// the max_age, see AgeVehicle).
 
	if (!(_patches.autorenew && v->max_age - v->age < 366 + 183 + v->service_interval))
 
	// A vehicle is autorenewed when it it gets the amount of months
 
	//  give by _patches.autorenew_months away for his max age.
 
	//  Standard is -6, meaning 6 months before his max age
 
	//  It can be any value between -12 and 12.
 
	if (!_patches.autorenew || v->age - v->max_age < (_patches.autorenew_months * 30))
 
		return;
 
		
 
	if (DEREF_PLAYER(v->owner)->money64 < _patches.autorenew_money + build_cost - v->value) {
 
		if (v->owner == _local_player) {
 
			int message;
 
			SET_DPARAM16(0, v->unitnumber);
 
			switch (v->type) {
 
				case VEH_Train: message = STR_TRAIN_AUTORENEW_FAILED; break;
 
				case VEH_Road: message = STR_ROADVEHICLE_AUTORENEW_FAILED; break;
 
				case VEH_Ship: message = STR_SHIP_AUTORENEW_FAILED; break;
 
				case VEH_Aircraft: message = STR_AIRCRAFT_AUTORENEW_FAILED; break;
 
				// This should never happen
 
				default: message = 0; break;
 
			}
 

	
 
			AddNewsItem(message, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
 
		}
 
		return;
 
	}
 
	
 
	// Withdraw the money from the right player ;)
 
	_current_player = v->owner;
 

	
 
	e = &_engines[v->engine_type];
 
	v->reliability = e->reliability;
0 comments (0 inline, 0 general)