changeset 10577:4436af164dbd draft

(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
author smatz <smatz@openttd.org>
date Sun, 04 Jan 2009 18:34:23 +0000
parents 137a58ac2ca1
children 62307b1b61df
files src/aircraft_cmd.cpp src/date.cpp src/lang/english.txt src/roadveh_cmd.cpp src/settings.cpp src/settings_type.h src/ship_cmd.cpp src/train_cmd.cpp src/vehicle.cpp
diffstat 9 files changed, 32 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -654,19 +654,6 @@
 	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
 }
 
-void AircraftYearlyLoop()
-{
-	Vehicle *v;
-
-	FOR_ALL_VEHICLES(v) {
-		if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) {
-			v->profit_last_year = v->profit_this_year;
-			v->profit_this_year = 0;
-			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
-		}
-	}
-}
-
 static void AgeAircraftCargo(Vehicle *v)
 {
 	if (_age_cargo_skip_counter != 0) return;
--- a/src/date.cpp
+++ b/src/date.cpp
@@ -165,10 +165,7 @@
 extern void StationMonthlyLoop();
 
 extern void CompaniesYearlyLoop();
-extern void TrainsYearlyLoop();
-extern void RoadVehiclesYearlyLoop();
-extern void AircraftYearlyLoop();
-extern void ShipsYearlyLoop();
+extern void VehiclesYearlyLoop();
 extern void TownsYearlyLoop();
 
 extern void ShowEndGameChart();
@@ -270,10 +267,7 @@
 
 	/* yes, call various yearly loops */
 	CompaniesYearlyLoop();
-	TrainsYearlyLoop();
-	RoadVehiclesYearlyLoop();
-	AircraftYearlyLoop();
-	ShipsYearlyLoop();
+	VehiclesYearlyLoop();
 	TownsYearlyLoop();
 #ifdef ENABLE_NETWORK
 	if (_network_server) NetworkServerYearlyLoop();
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -996,7 +996,7 @@
 
 STR_TRAIN_IS_STUCK                                              :{WHITE}{VEHICLE} can't find a path to continue.
 STR_TRAIN_IS_LOST                                               :{WHITE}{VEHICLE} is lost.
-STR_TRAIN_IS_UNPROFITABLE                                       :{WHITE}{VEHICLE}'s profit last year was {CURRENCY}
+STR_VEHICLE_IS_UNPROFITABLE                                     :{WHITE}{VEHICLE}'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!
 
 # Start of order review system.
@@ -1062,7 +1062,7 @@
 STR_CONFIG_PATCHES_ORDER_REVIEW_OFF                             :no
 STR_CONFIG_PATCHES_ORDER_REVIEW_EXDEPOT                         :yes, but exclude stopped vehicles
 STR_CONFIG_PATCHES_ORDER_REVIEW_ON                              :of all vehicles
-STR_CONFIG_PATCHES_WARN_INCOME_LESS                             :{LTBLUE}Warn if a train's income is negative: {ORANGE}{STRING1}
+STR_CONFIG_PATCHES_WARN_INCOME_LESS                             :{LTBLUE}Warn if a vehicle's income is negative: {ORANGE}{STRING1}
 STR_CONFIG_PATCHES_NEVER_EXPIRE_VEHICLES                        :{LTBLUE}Vehicles never expire: {ORANGE}{STRING1}
 STR_CONFIG_PATCHES_AUTORENEW_VEHICLE                            :{LTBLUE}Autorenew vehicle when it gets old
 STR_CONFIG_PATCHES_AUTORENEW_MONTHS                             :{LTBLUE}Autorenew when vehicle is {ORANGE}{STRING1}{LTBLUE} months before/after max age
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1981,20 +1981,6 @@
 	InvalidateWindowClasses(WC_ROADVEH_LIST);
 }
 
-
-void RoadVehiclesYearlyLoop()
-{
-	Vehicle *v;
-
-	FOR_ALL_VEHICLES(v) {
-		if (v->type == VEH_ROAD) {
-			v->profit_last_year = v->profit_this_year;
-			v->profit_this_year = 0;
-			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
-		}
-	}
-}
-
 /** Refit a road vehicle to the specified cargo type
  * @param tile unused
  * @param flags operation to perform
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1444,7 +1444,7 @@
 	 SDTC_BOOL(gui.enable_signal_gui,                    S,  0, false,                        STR_CONFIG_PATCHES_ENABLE_SIGNAL_GUI,           CloseSignalGUI),
 	  SDTC_VAR(gui.drag_signals_density,      SLE_UINT8, S,  0,     4,        1,       20, 0, STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY,        DragSignalsDensityChanged),
 	  SDTC_VAR(gui.semaphore_build_before,    SLE_INT32, S, NC,  1975, MIN_YEAR, MAX_YEAR, 1, STR_CONFIG_PATCHES_SEMAPHORE_BUILD_BEFORE_DATE, ResetSignalVariant),
-	 SDTC_BOOL(gui.train_income_warn,                    S,  0,  true,                        STR_CONFIG_PATCHES_WARN_INCOME_LESS,            NULL),
+	 SDTC_BOOL(gui.vehicle_income_warn,                  S,  0,  true,                        STR_CONFIG_PATCHES_WARN_INCOME_LESS,            NULL),
 	  SDTC_VAR(gui.order_review_system,       SLE_UINT8, S, MS,     2,        0,        2, 0, STR_CONFIG_PATCHES_ORDER_REVIEW,                NULL),
 	 SDTC_BOOL(gui.lost_train_warn,                      S,  0,  true,                        STR_CONFIG_PATCHES_WARN_LOST_TRAIN,             NULL),
 	 SDTC_BOOL(gui.autorenew,                            S,  0, false,                        STR_CONFIG_PATCHES_AUTORENEW_VEHICLE,           EngineRenewUpdate),
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -39,7 +39,7 @@
 	bool   sg_full_load_any;                 ///< new full load calculation, any cargo must be full read from pre v93 savegames
 	bool   lost_train_warn;                  ///< if a train can't find its destination, show a warning
 	uint8  order_review_system;              ///< perform order reviews on vehicles
-	bool   train_income_warn;                ///< if train is generating little income, show a warning
+	bool   vehicle_income_warn;              ///< if a vehicle isn't generating income, show a warning
 	bool   status_long_date;                 ///< always show long date in status bar
 	bool   show_finances;                    ///< show finances at end of year
 	bool   sg_new_nonstop;                   ///< ttdpatch compatible nonstop handling read from pre v93 savegames
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -731,20 +731,6 @@
 	ShipController(this);
 }
 
-
-void ShipsYearlyLoop()
-{
-	Vehicle *v;
-
-	FOR_ALL_VEHICLES(v) {
-		if (v->type == VEH_SHIP) {
-			v->profit_last_year = v->profit_this_year;
-			v->profit_this_year = 0;
-			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
-		}
-	}
-}
-
 /** Build a ship.
  * @param tile tile of depot where ship is built
  * @param flags type of operation
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -4471,31 +4471,6 @@
 	}
 }
 
-void TrainsYearlyLoop()
-{
-	Vehicle *v;
-
-	FOR_ALL_VEHICLES(v) {
-		if (v->type == VEH_TRAIN && IsFrontEngine(v)) {
-			/* show warning if train is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) */
-			if (_settings_client.gui.train_income_warn && v->owner == _local_company && v->age >= 730 && v->GetDisplayProfitThisYear() < 0) {
-				SetDParam(1, v->GetDisplayProfitThisYear());
-				SetDParam(0, v->index);
-				AddNewsItem(
-					STR_TRAIN_IS_UNPROFITABLE,
-					NS_ADVICE,
-					v->index,
-					0);
-			}
-
-			v->profit_last_year = v->profit_this_year;
-			v->profit_this_year = 0;
-			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
-		}
-	}
-}
-
-
 void InitializeTrains()
 {
 	_age_cargo_skip_counter = 1;
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2231,3 +2231,29 @@
 		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 	}
 }
+
+void VehiclesYearlyLoop()
+{
+	Vehicle *v;
+	FOR_ALL_VEHICLES(v) {
+		if (v->IsPrimaryVehicle()) {
+			/* show warning if vehicle is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) */
+			if (_settings_client.gui.vehicle_income_warn && v->owner == _local_company && v->age >= 730) {
+				Money profit = v->GetDisplayProfitThisYear();
+				if (profit < 0) {
+					SetDParam(0, v->index);
+					SetDParam(1, profit);
+					AddNewsItem(
+						STR_VEHICLE_IS_UNPROFITABLE,
+						NS_ADVICE,
+						v->index,
+						0);
+				}
+			}
+
+			v->profit_last_year = v->profit_this_year;
+			v->profit_this_year = 0;
+			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
+		}
+	}
+}