void Fishery::timeStep(const unsigned int time )
{  
  if( !game::Date::isMonthChanged() )
    return;

  if( _d->places.empty() )
  {
    _d->places = city::statistic::getWalkers<FishPlace>( _city(), walker::fishPlace, TilePos(-1, -1) );
  }

  while( _d->places.size() < _d->maxFishPlace )
  {
    FishPlacePtr fishplace = FishPlace::create( _city() );
    TilePos travelingPoint = _city()->borderInfo().boatExit;
    if( !_d->locations.empty() )
    {
      travelingPoint = _d->locations.size() > 1
                         ? _d->locations[ math::random( _d->locations.size() ) ]
                         : _d->locations.front();
    }

    fishplace->send2city( _city()->borderInfo().boatEntry, travelingPoint );

    if( fishplace->isDeleted() )
    {
      _d->nFailed++;
      return;
    }

    _d->places.push_back( ptr_cast<FishPlace>( fishplace ) );
  }

  utils::eraseDeletedElements( _d->places );
}
示例#2
0
Pathway FishingBoat::Impl::findFishingPlace(PlayerCityPtr city, TilePos pos )
{
  city::Helper helper( city );
  FishPlaceList places = helper.find<FishPlace>( walker::fishPlace, city::Helper::invalidPos );

  int minDistance = 999;
  FishPlacePtr nearest;
  foreach( it, places )
  {
    FishPlacePtr place = *it;
    int currentDistance = pos.distanceFrom( place->pos() );
    if( currentDistance < minDistance )
    {
      minDistance = currentDistance;
      nearest = place;
    }
  }
void Fishery::timeStep(const unsigned int time )
{  
  if( !game::Date::isMonthChanged() )
    return;

  if( _d->places.empty() )
  {
    Helper helper( _city() );
    _d->places = helper.find<FishPlace>( walker::fishPlace, TilePos(-1, -1) );
  }

  while( _d->places.size() < _d->maxFishPlace )
  {
    FishPlacePtr fishplace = FishPlace::create( _city() );
    TilePos travelingPoint = _city()->borderInfo().boatExit;
    if( !_d->locations.empty() )
    {
      travelingPoint = _d->locations.size() > 1
                         ? _d->locations[ math::random( _d->locations.size() ) ]
                         : _d->locations.front();
    }

    fishplace->send2city( _city()->borderInfo().boatEntry, travelingPoint );

    if( fishplace->isDeleted() )
    {
      _d->failedCounter++;
      return;
    }

    _d->places.push_back( ptr_cast<FishPlace>( fishplace ) );
  }

  FishPlaceList::iterator fit = _d->places.begin();
  while( fit != _d->places.end() )
  {
    if( (*fit)->isDeleted() )     {      fit = _d->places.erase( fit );    }
    else {  ++fit;    }
  }
}