Exemple #1
0
void Farm::Update( Logic& l, float delta_time )
{
	if( !used )
		return;

	float efficency = population / population_needed;
	if( efficency > 1.f )
		efficency = 1.f;

	food += food_production * delta_time * efficency;
	if( food > food_max )
		food = food_max;

	// Move extra population to city if possible
	if( population > population_needed )
	{
		int i = l.GetCityIndex( point );
		if( i != -1 )
		{
			City& c( l.GetCityByIndex( i ) );
			c.population += population - population_needed;
			population = population_needed;
		}
	}

	l.PopulationCalculations( food, population, hunger, delta_time );
}
Exemple #2
0
void Quarry::Update( Logic& l, float delta_time )
{
	if( !used )
		return;

	float efficency = population / population_needed;
	if( efficency > 1.f )
		efficency = 1.f;

	l.PopulationCalculations( food_contained, population, hunger, delta_time );

	if( stone_contained >= stone_storage )
	{
		stone_contained = stone_storage;
		return;
	}

	// Reduce mountain maeby change to require more effort to extract more stone
	auto& v( height_map.square_contained );
	auto i = std::find( v.begin(), v.end(), Resource::Stone );
	auto closest = i;
	auto& r( rectangles[ (int)Type::Quarry ][rectangle] );
	auto size = 5; // TODO: Move value to a config file
	auto closest_length = size;
	while(true)
	{
		if( i == v.end() )
		{
			if( closest_length != size )
			{
				auto& resource( height_map.square_amount[ closest - v.begin() ] );
				stone_contained += stone_production * delta_time * efficency;
				resource -= stone_production * delta_time * efficency;
				if( resource <= 0 )
					height_map.Remove( closest - v.begin() );
			}
			break;
		}
		auto s = sqrt( pow( r.x - height_map.PosX( i - v.begin() ), 2 ) + pow( r.y - height_map.PosY( i - v.begin() ), 2 ) ); // TODO: Mabye remove v.begin()
		if( s < closest_length )
		{
			closest_length = s;
			closest = i;
		}
		i = std::find( ++i, v.end(), Resource::Stone );
	}
}