town_cmd.c
changeset 470 80d30b9c3552
parent 468 9b8e5ac11758
child 473 0da86c59e3ae
equal deleted inserted replaced
469:d26f0e5705dc 470:80d30b9c3552
   664 	int block = 5; // special case
   664 	int block = 5; // special case
   665 
   665 
   666 	TILE_ASSERT(tile);
   666 	TILE_ASSERT(tile);
   667 
   667 
   668 	// Number of times to search.
   668 	// Number of times to search.
   669 	_grow_town_result = 20;
   669 	_grow_town_result = 10 + t->num_houses * 4 / 9;
   670 
   670 
   671 	do {
   671 	do {
   672 		// Get a bitmask of the road blocks on a tile
   672 		// Get a bitmask of the road blocks on a tile
   673 		mask = GetTownRoadMask(tile);
   673 		mask = GetTownRoadMask(tile);
   674 
   674 
   771 }
   771 }
   772 
   772 
   773 static void UpdateTownRadius(Town *t)
   773 static void UpdateTownRadius(Town *t)
   774 {
   774 {
   775 	static const uint16 _town_radius_data[23][5] = {
   775 	static const uint16 _town_radius_data[23][5] = {
   776 		{ 4,  0,  0,  0,  0},
   776 		{ 4,  0,  0,  0,  0}, // 0
   777 		{16,  0,  0,  0,  0},
   777 		{16,  0,  0,  0,  0},
   778 		{25,  0,  0,  0,  0},
   778 		{25,  0,  0,  0,  0},
   779 		{36,  0,  0,  0,  0},
   779 		{36,  0,  0,  0,  0},
   780 		{49,  0,  4,  0,  0},
   780 		{49,  0,  4,  0,  0},
   781 		{64,  0,  4,  0,  0},
   781 		{64,  0,  4,  0,  0}, // 20
   782 		{64,  0,  9,  0,  1},
   782 		{64,  0,  9,  0,  1},
   783 		{64,  0,  9,  0,  4},
   783 		{64,  0,  9,  0,  4},
   784 		{64,  0, 16,  0,  4},
   784 		{64,  0, 16,  0,  4},
   785 		{81,  0, 16,  0,  4},
   785 		{81,  0, 16,  0,  4},
   786 		{81,  0, 16,  0,  4},
   786 		{81,  0, 16,  0,  4}, // 40
   787 		{81,  0, 25,  0,  9},
   787 		{81,  0, 25,  0,  9},
   788 		{81, 36, 25,  0,  9},
   788 		{81, 36, 25,  0,  9},
   789 		{81, 36, 25, 16,  9},
   789 		{81, 36, 25, 16,  9},
   790 		{81, 49,  0, 25,  9},
   790 		{81, 49,  0, 25,  9},
   791 		{81, 64,  0, 25,  9},
   791 		{81, 64,  0, 25,  9}, // 60
   792 		{81, 64,  0, 36,  9},
   792 		{81, 64,  0, 36,  9},
   793 		{81, 64,  0, 36, 16},
   793 		{81, 64,  0, 36, 16},
   794 		{ 0, 81,  0, 49, 16},
   794 		{100, 81,  0, 49, 16},
   795 		{ 0, 81,  0, 49, 25},
   795 		{100, 81,  0, 49, 25},
   796 		{ 0,100,  0, 49, 25},
   796 		{121, 81,  0, 49, 25}, // 80
   797 		{ 0,100,  0, 64, 25},
   797 		{121, 81,  0, 49, 25},
   798 		{ 0,100,  0, 64, 36},
   798 		{121, 81,  0, 49, 36}, // 88
   799 	};
   799 	};
   800 	int i = min(t->num_houses, 88) >> 2;
   800 
   801 	memcpy(t->radius, _town_radius_data[i], sizeof(t->radius));
   801 	if (t->num_houses < 92) {
       
   802 		memcpy(t->radius, _town_radius_data[t->num_houses / 4], sizeof(t->radius));
       
   803 	} else {
       
   804 		int mass = t->num_houses / 8;
       
   805 		// At least very roughly extrapolate. Empirical numbers dancing between
       
   806 		// overwhelming by cottages and skyscrapers outskirts.
       
   807 		t->radius[0] = mass * mass;
       
   808 		// Actually we are proportional to sqrt() but that's right because
       
   809 		// we are covering an area.
       
   810 		t->radius[1] = mass * 7;
       
   811 		t->radius[2] = 0;
       
   812 		t->radius[3] = mass * 4;
       
   813 		t->radius[4] = mass * 3;
       
   814 		//debug("%d (->%d): %d %d %d %d\n", t->num_houses, mass, t->radius[0], t->radius[1], t->radius[3], t->radius[4]);
       
   815 	}
   802 }
   816 }
   803 
   817 
   804 static void UpdateTownVirtCoord(Town *t)
   818 static void UpdateTownVirtCoord(Town *t)
   805 {
   819 {
   806 	Point pt = RemapCoords2(GET_TILE_X(t->xy)*16, GET_TILE_Y(t->xy)*16);
   820 	Point pt = RemapCoords2(GET_TILE_X(t->xy)*16, GET_TILE_Y(t->xy)*16);
  1596 	}
  1610 	}
  1597 
  1611 
  1598 	t->flags12 &= ~1;
  1612 	t->flags12 &= ~1;
  1599 
  1613 
  1600 	if (t->fund_buildings_months != 0) {
  1614 	if (t->fund_buildings_months != 0) {
       
  1615 		static const byte _grow_count_values[6] = {
       
  1616 			60, 60, 60, 50, 40, 30
       
  1617 		};
       
  1618 		m = _grow_count_values[min(n, 5)];
  1601 		t->fund_buildings_months--;
  1619 		t->fund_buildings_months--;
  1602 		m = 60;
       
  1603 	} else if (n == 0) {
  1620 	} else if (n == 0) {
  1604 		m = 160;
  1621 		m = 160;
  1605 		if (!CHANCE16(1, 12))
  1622 		if (!CHANCE16(1, 12))
  1606 			return;
  1623 			return;
  1607 	} else {
  1624 	} else {
  1617 	} else if (_opt.landscape == LT_DESERT) {
  1634 	} else if (_opt.landscape == LT_DESERT) {
  1618  		if (GetMapExtraBits(t->xy) == 1 && (t->act_food==0 || t->act_water==0) && t->population > 60)
  1635  		if (GetMapExtraBits(t->xy) == 1 && (t->act_food==0 || t->act_water==0) && t->population > 60)
  1619 			return;
  1636 			return;
  1620 	}
  1637 	}
  1621 
  1638 
  1622 	t->growth_rate = m;
  1639   	t->growth_rate = m / (t->num_houses / 50 + 1);
  1623 	if (m <= t->grow_counter)
  1640 	if (m <= t->grow_counter)
  1624 		t->grow_counter = m;
  1641 		t->grow_counter = m;
  1625 
  1642 
  1626 	t->flags12 |= 1;
  1643 	t->flags12 |= 1;
  1627 }
  1644 }