changeset 18562:799e3cfa2a65 draft

(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
author terkhen <terkhen@openttd.org>
date Sat, 03 Dec 2011 22:23:10 +0000
parents 05ffde57e1fe
children ef59dafc8b47
files src/saveload/town_sl.cpp src/town.h src/town_cmd.cpp
diffstat 3 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/saveload/town_sl.cpp
+++ b/src/saveload/town_sl.cpp
@@ -99,6 +99,7 @@
 		UpdateTownRadius(town);
 		UpdateTownCargos(town);
 	}
+	UpdateTownCargoBitmap();
 }
 
 /** Save and load of towns. */
--- a/src/town.h
+++ b/src/town.h
@@ -185,6 +185,7 @@
 void UpdateTownRadius(Town *t);
 void UpdateTownCargos(Town *t);
 void UpdateTownCargoTotal(Town *t);
+void UpdateTownCargoBitmap();
 CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
 Town *ClosestTownFromTile(TileIndex tile, uint threshold);
 void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags);
@@ -284,4 +285,6 @@
 	obj->town_cn = (uint16)next; // set index...
 }
 
+extern uint32 _town_cargos_accepted;
+
 #endif /* TOWN_H */
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -52,6 +52,7 @@
 #include "table/town_land.h"
 
 TownID _new_town_id;
+uint32 _town_cargos_accepted; ///< Bitmap of all cargos accepted by houses.
 
 /* Initialize the town-pool */
 TownPool _town_pool("Town");
@@ -742,6 +743,17 @@
 	UpdateTownCargoTotal(t);
 }
 
+/** Updates the bitmap of all cargos accepted by houses. */
+void UpdateTownCargoBitmap()
+{
+	Town *town;
+	_town_cargos_accepted = 0;
+
+	FOR_ALL_TOWNS(town) {
+		_town_cargos_accepted |= town->cargo_accepted_total;
+	}
+}
+
 static bool GrowTown(Town *t);
 
 static void TownTickHandler(Town *t)
@@ -3143,6 +3155,8 @@
 		UpdateTownUnwanted(t);
 		UpdateTownCargos(t);
 	}
+
+	UpdateTownCargoBitmap();
 }
 
 void TownsYearlyLoop()