Ejemplo n.º 1
0
void FireWorkers::exec(Game& game)
{
  Tilemap& tilemap = game.getCity()->getTilemap();
  const int defaultFireWorkersDistance = 40;

  for( int curRange=1; curRange < defaultFireWorkersDistance; curRange++ )
  {
    TilemapArea perimetr = tilemap.getRectangle( _center - TilePos( curRange, curRange ),
                                                 _center + TilePos( curRange, curRange ) );
    foreach( Tile* tile, perimetr )
    {
      WorkingBuildingPtr wrkBuilding = tile->getOverlay().as<WorkingBuilding>();
      if( wrkBuilding.isValid() )
      {
        int bldWorkersCount = wrkBuilding->getWorkersCount();
        wrkBuilding->removeWorkers( _workers );
        _workers -= math::clamp<int>( bldWorkersCount, 0, _workers );
      }

      if( !_workers )
        return;
    }
  }
Ejemplo n.º 2
0
void FireWorkers::_exec(Game& game, unsigned int)
{
  Tilemap& tilemap = game.city()->tilemap();

  for( int curRange=1; curRange < defaultReturnWorkersDistance; curRange++ )
  {
    TilePos range( curRange, curRange );
    TilesArray perimetr = tilemap.rect( _center - range,
                                                _center + range );
    for( auto& tile : perimetr )
    {
      WorkingBuildingPtr wrkBuilding = tile->overlay<WorkingBuilding>();
      if( wrkBuilding.isValid() )
      {
        int removedFromWb = wrkBuilding->removeWorkers( _workers );
        _workers -= removedFromWb;
      }

      if( !_workers )
        return;
    }
  }

  if( _workers > 0 )
  {
    WorkingBuildingList buildings = game.city()->statistic().objects.find<WorkingBuilding>( object::any );
    for( auto&& building : buildings )
    {
      int removedFromWb = building->removeWorkers( _workers );
      _workers -= removedFromWb;

      if( !_workers )
        return;
    }
  }
}