town_cmd.c
changeset 1451 eb24b5a58340
parent 1448 472b3b3855e7
child 1500 a66721629bc0
equal deleted inserted replaced
1450:6bf299c74d88 1451:eb24b5a58340
    37 
    37 
    38 /* Initialize the town-pool */
    38 /* Initialize the town-pool */
    39 MemoryPool _town_pool = { "Towns", TOWN_POOL_MAX_BLOCKS, TOWN_POOL_BLOCK_SIZE_BITS, sizeof(Town), &TownPoolNewBlock, 0, 0, NULL };
    39 MemoryPool _town_pool = { "Towns", TOWN_POOL_MAX_BLOCKS, TOWN_POOL_BLOCK_SIZE_BITS, sizeof(Town), &TownPoolNewBlock, 0, 0, NULL };
    40 
    40 
    41 
    41 
       
    42 /* This is the base "normal" number of towns on the 8x8 map, when
       
    43  * one town should get grown per tick. The other numbers of towns
       
    44  * are then scaled based on that. */
       
    45 #define TOWN_GROWTH_FREQUENCY 23
       
    46 
    42 enum {
    47 enum {
    43 	TOWN_HAS_CHURCH     = 0x02,
    48 	TOWN_HAS_CHURCH     = 0x02,
    44 	TOWN_HAS_STADIUM    = 0x04
    49 	TOWN_HAS_STADIUM    = 0x04
    45 };
    50 };
    46 
    51 
   425 	UpdateTownRadius(t);
   430 	UpdateTownRadius(t);
   426 }
   431 }
   427 
   432 
   428 void OnTick_Town(void)
   433 void OnTick_Town(void)
   429 {
   434 {
   430 	uint i;
   435 	static int counter;
   431 	Town *t;
       
   432 	int towns;
       
   433 
   436 
   434 	if (_game_mode == GM_EDITOR)
   437 	if (_game_mode == GM_EDITOR)
   435 		return;
   438 		return;
   436 
   439 
   437 	/* FIXME: This way we scale for larger map, but not for the smaller
   440 	/* Make sure each town's tickhandler invocation frequency is about the
   438 	 * ones. --pasky */
   441 	 * same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */
   439 	for (towns = ScaleByMapSize(1); towns > 0; towns--) {
   442 	for (counter += GetTownPoolSize();
   440 		i = _cur_town_ctr;
   443 	     counter >= TOWN_GROWTH_FREQUENCY;
       
   444 	     counter -= TOWN_GROWTH_FREQUENCY) {
       
   445 		int i = _cur_town_ctr;
       
   446 		Town *t;
       
   447 
   441 		if (++_cur_town_ctr >= GetTownPoolSize())
   448 		if (++_cur_town_ctr >= GetTownPoolSize())
   442 			_cur_town_ctr = 0;
   449 			_cur_town_ctr = 0;
   443 
   450 
   444 		t = GetTown(i);
   451 		t = GetTown(i);
   445 
   452