inline Pathway Statistic::_Walkers::freeTile( TilePos target, TilePos currentPos, const int range ) const { for( int currentRange=1; currentRange <= range; currentRange++ ) { TilePos offset( currentRange, currentRange ); gfx::TilesArray tiles = _parent.map.perimetr( currentPos - offset, currentPos + offset ); tiles = tiles.walkables( true ); float crntDistance = target.distanceFrom( currentPos ); for( auto tile : tiles ) { SmartList<T> eslist = _parent.rcity.walkers( tile->pos() ).select<T>(); if( !eslist.empty() ) continue; if( target.distanceFrom( tile->pos() ) > crntDistance ) continue; Pathway pathway = PathwayHelper::create( currentPos, tile->pos(), PathwayHelper::allTerrain ); if( pathway.isValid() ) { return pathway; } } } return Pathway(); }
SmartList<Dst> select() const { SmartList<Dst> ret; for( auto it : *this ) ret.addIfValid( ptr_cast<Dst>( it ) ); return ret; }
SmartList<Dst> select() const { SmartList<Dst> ret; for( const auto& it : _data ) ret.addIfValid(ptr_cast<Dst>(it)); return ret; }
SmartList<T> exclude() const { SmartList<T> ret; for( auto it : *this ) if( !is_kind_of<W>( it ) ) ret.push_back( it ); return ret; }
SmartList<T> where( std::function<bool (SmartPtr<T>)> comparer ) const { SmartList<T> ret; for( const auto& item : *this ) if( comparer( item ) ) ret.push_back( item ); return ret; }
inline SmartList< T > Statistic::_Objects::find( object::Type type ) const { SmartList< T > ret; auto buildings = _parent.rcity.overlays(); for( auto bld : buildings ) { if( bld.isValid() && (bld->type() == type || type == object::any) ) ret.addIfValid( bld.as<T>() ); } return ret; }
inline SmartList< T > Statistic::_Objects::find( object::TypeSet types ) const { SmartList< T > ret; auto buildings = _parent.rcity.overlays(); for( auto bld : buildings ) { if( bld.isValid() && types.count( bld->type() ) > 0 ) ret.addIfValid( bld.as<T>() ); } return ret; }
inline SmartList< T > Statistic::_Objects::findNotIn( const std::set<object::Group>& which ) const { SmartList< T > ret; auto& overlays = _parent.rcity.overlays(); for( auto ov : overlays ) { if( which.count( ov->group() ) == 0 ) { ret.addIfValid( ov.as<T>() ); } } return ret; }
SmartList<T> Statistic::_Objects::producers(const good::Product goodtype) const { SmartList< T > ret; const OverlayList& overlays = _parent.rcity.overlays(); for( auto ov : overlays ) { SmartPtr< T > b = ov.as<T>(); if( b.isValid() && b->produceGoodType() == goodtype ) { ret.push_back( b ); } } return ret; }
inline SmartList<T> Statistic::_Objects::find( object::Group group ) const { SmartList<T> ret; auto buildings = _parent.rcity.overlays(); for( auto item : buildings ) { SmartPtr<T> b = item.as<T>(); if( b.isValid() && (b->group() == group || group == object::group::any ) ) { ret.push_back( b ); } } return ret; }
inline SmartList< T > Statistic::_Objects::find( const object::Type type, TilePos start, TilePos stop ) const { SmartList< T > ret; gfx::TilesArea area( _parent.rcity.tilemap(), start, stop ); for( auto tile : area ) { SmartPtr<T> obj = ptr_cast< T >( tile->overlay() ); if( obj.isValid() && (obj->type() == type || type == object::any) ) { ret.push_back( obj ); } } return ret; }
inline SmartList< T > Statistic::_Objects::find( object::Group group, const TilePos& start, const TilePos& stop ) { SmartList< T > ret; gfx::TilesArea area( _parent.rcity.tilemap(), start, stop ); for( auto tile : area ) { SmartPtr<T> obj = tile->overlay<T>(); if( obj.isValid() && (obj->getClass() == group || group == object::group::any ) ) { ret.push_back( obj ); } } return ret; }
inline SmartPtr< T > Statistic::_Objects::next( SmartPtr< T > current ) const { if( current.isNull() ) return SmartPtr<T>(); SmartList< T > objects = find<T>( current->type() ); foreach( obj, objects ) { if( current == *obj ) { obj++; if( obj == objects.end() ) { return *objects.begin(); } else { return *obj; } } } return SmartPtr<T>(); }
inline SmartPtr<T> Statistic::_Objects::prew( SmartPtr<T> current) const { if( current.isNull() ) return SmartPtr<T>(); SmartList< T > objects = find<T>( current->type() ); foreach( obj, objects ) { if( current == *obj ) { if (obj == objects.begin()) // MSVC compiler doesn't support circular lists. Neither standart does. { obj = objects.end(); } obj--; return *obj; } } return SmartPtr<T>(); }
inline SmartList<T> Statistic::_Walkers::find( walker::Type type, TilePos start, TilePos stop ) const { WalkerList walkersInArea; TilePos stopPos = stop; if( start == gfx::tilemap::invalidLocation() ) { const WalkerList& all =_parent.rcity.walkers(); walkersInArea.insert( walkersInArea.end(), all.begin(), all.end() ); } else if( stopPos == gfx::tilemap::invalidLocation() ) { const WalkerList& wlkOnTile = _parent.rcity.walkers( start ); walkersInArea.insert( walkersInArea.end(), wlkOnTile.begin(), wlkOnTile.end() ); } else { gfx::TilesArea area( _parent.rcity.tilemap(), start, stop ); for( auto& tile : area) { const WalkerList& wlkOnTile = _parent.rcity.walkers( tile->pos() ); walkersInArea.insert( walkersInArea.end(), wlkOnTile.begin(), wlkOnTile.end() ); } } SmartList< T > result; for( auto& w : walkersInArea ) { if( w->type() == type || type == walker::any ) result.addIfValid( w.as<T>() ); } return result; }