src/town_cmd.cpp
changeset 6247 7d81e3a5d803
parent 6201 bee01dc45e39
child 6257 5e5a864cacf6
equal deleted inserted replaced
6246:75451000349d 6247:7d81e3a5d803
   249 	UpdateTownVirtCoord(t);
   249 	UpdateTownVirtCoord(t);
   250 
   250 
   251 	if (_town_sort_order & 2) _town_sort_dirty = true;
   251 	if (_town_sort_order & 2) _town_sort_dirty = true;
   252 }
   252 }
   253 
   253 
   254 uint32 GetWorldPopulation(void)
   254 uint32 GetWorldPopulation()
   255 {
   255 {
   256 	uint32 pop;
   256 	uint32 pop;
   257 	const Town* t;
   257 	const Town* t;
   258 
   258 
   259 	pop = 0;
   259 	pop = 0;
   440 	}
   440 	}
   441 
   441 
   442 	UpdateTownRadius(t);
   442 	UpdateTownRadius(t);
   443 }
   443 }
   444 
   444 
   445 void OnTick_Town(void)
   445 void OnTick_Town()
   446 {
   446 {
   447 	if (_game_mode == GM_EDITOR) return;
   447 	if (_game_mode == GM_EDITOR) return;
   448 
   448 
   449 	/* Make sure each town's tickhandler invocation frequency is about the
   449 	/* Make sure each town's tickhandler invocation frequency is about the
   450 	 * same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */
   450 	 * same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */
   758 }
   758 }
   759 
   759 
   760 // Generate a random road block
   760 // Generate a random road block
   761 // The probability of a straight road
   761 // The probability of a straight road
   762 // is somewhat higher than a curved.
   762 // is somewhat higher than a curved.
   763 static RoadBits GenRandomRoadBits(void)
   763 static RoadBits GenRandomRoadBits()
   764 {
   764 {
   765 	uint32 r = Random();
   765 	uint32 r = Random();
   766 	uint a = GB(r, 0, 2);
   766 	uint a = GB(r, 0, 2);
   767 	uint b = GB(r, 8, 2);
   767 	uint b = GB(r, 8, 2);
   768 	if (a == b) b ^= 2;
   768 	if (a == b) b ^= 2;
   985 	t->num_houses -= x;
   985 	t->num_houses -= x;
   986 	UpdateTownRadius(t);
   986 	UpdateTownRadius(t);
   987 	UpdateTownMaxPass(t);
   987 	UpdateTownMaxPass(t);
   988 }
   988 }
   989 
   989 
   990 static Town *AllocateTown(void)
   990 static Town *AllocateTown()
   991 {
   991 {
   992 	Town *t;
   992 	Town *t;
   993 
   993 
   994 	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
   994 	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
   995 	 * TODO - This is just a temporary stage, this will be removed. */
   995 	 * TODO - This is just a temporary stage, this will be removed. */
  1088 	return NULL;
  1088 	return NULL;
  1089 }
  1089 }
  1090 
  1090 
  1091 static const byte _num_initial_towns[3] = {11, 23, 46};
  1091 static const byte _num_initial_towns[3] = {11, 23, 46};
  1092 
  1092 
  1093 bool GenerateTowns(void)
  1093 bool GenerateTowns()
  1094 {
  1094 {
  1095 	uint num = 0;
  1095 	uint num = 0;
  1096 	uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
  1096 	uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
  1097 
  1097 
  1098 	SetGeneratingWorldProgress(GWP_TOWN, n);
  1098 	SetGeneratingWorldProgress(GWP_TOWN, n);
  1805 	}
  1805 	}
  1806 
  1806 
  1807 	return true;
  1807 	return true;
  1808 }
  1808 }
  1809 
  1809 
  1810 void TownsMonthlyLoop(void)
  1810 void TownsMonthlyLoop()
  1811 {
  1811 {
  1812 	Town *t;
  1812 	Town *t;
  1813 
  1813 
  1814 	FOR_ALL_TOWNS(t) {
  1814 	FOR_ALL_TOWNS(t) {
  1815 		if (t->road_build_months != 0) t->road_build_months--;
  1815 		if (t->road_build_months != 0) t->road_build_months--;
  1821 		UpdateTownAmounts(t);
  1821 		UpdateTownAmounts(t);
  1822 		UpdateTownUnwanted(t);
  1822 		UpdateTownUnwanted(t);
  1823 	}
  1823 	}
  1824 }
  1824 }
  1825 
  1825 
  1826 void InitializeTowns(void)
  1826 void InitializeTowns()
  1827 {
  1827 {
  1828 	Subsidy *s;
  1828 	Subsidy *s;
  1829 
  1829 
  1830 	/* Clean the town pool and create 1 block in it */
  1830 	/* Clean the town pool and create 1 block in it */
  1831 	CleanPool(&_Town_pool);
  1831 	CleanPool(&_Town_pool);
  1920 	SLE_CONDNULL(30, 2, SL_MAX_VERSION),
  1920 	SLE_CONDNULL(30, 2, SL_MAX_VERSION),
  1921 
  1921 
  1922 	SLE_END()
  1922 	SLE_END()
  1923 };
  1923 };
  1924 
  1924 
  1925 static void Save_TOWN(void)
  1925 static void Save_TOWN()
  1926 {
  1926 {
  1927 	Town *t;
  1927 	Town *t;
  1928 
  1928 
  1929 	FOR_ALL_TOWNS(t) {
  1929 	FOR_ALL_TOWNS(t) {
  1930 		SlSetArrayIndex(t->index);
  1930 		SlSetArrayIndex(t->index);
  1931 		SlObject(t, _town_desc);
  1931 		SlObject(t, _town_desc);
  1932 	}
  1932 	}
  1933 }
  1933 }
  1934 
  1934 
  1935 static void Load_TOWN(void)
  1935 static void Load_TOWN()
  1936 {
  1936 {
  1937 	int index;
  1937 	int index;
  1938 
  1938 
  1939 	_total_towns = 0;
  1939 	_total_towns = 0;
  1940 
  1940 
  1954 	 *  the size of the TownPool */
  1954 	 *  the size of the TownPool */
  1955 	if (_cur_town_ctr > GetMaxTownIndex())
  1955 	if (_cur_town_ctr > GetMaxTownIndex())
  1956 		_cur_town_ctr = 0;
  1956 		_cur_town_ctr = 0;
  1957 }
  1957 }
  1958 
  1958 
  1959 void AfterLoadTown(void)
  1959 void AfterLoadTown()
  1960 {
  1960 {
  1961 	Town *t;
  1961 	Town *t;
  1962 	FOR_ALL_TOWNS(t) {
  1962 	FOR_ALL_TOWNS(t) {
  1963 		UpdateTownRadius(t);
  1963 		UpdateTownRadius(t);
  1964 		UpdateTownVirtCoord(t);
  1964 		UpdateTownVirtCoord(t);