void _removeGoodFrom( PlayerCityPtr city, objects::Type btype, good::Product what, int& qty ) { SmartList<T> bList; #ifdef CAESARIA_PLATFORM_HAIKU bList << city->overlays(); #else city::Helper helper( city ); bList = helper.find<T>( btype ); #endif foreach( it, bList ) { if( qty <= 0 ) break; good::Store& store = (*it)->store(); int maxQty = std::min( store.getMaxRetrieve( what ), qty ); if( maxQty > 0 ) { good::Stock stock( what, maxQty ); store.retrieve( stock, maxQty ); qty -= maxQty; } } }
void _decreaseHousesHealth( object::Type btype, PlayerCityPtr city, int value ) { TilePos offset( 2, 2 ); const OverlayList& buildings = city->overlays(); foreach( itB, buildings ) { if( (*itB)->type() != btype ) continue; HouseList houses = city::statistic::getObjects<House>( city, object::house, (*itB)->pos() - offset, (*itB)->pos() + offset ); foreach( itHouse, houses ) { (*itHouse)->updateState( pr::health, value ); } }
void LoaderHelper::decodeTerrain( Tile &oTile, PlayerCityPtr city, unsigned int forceId ) { unsigned int imgId = oTile.originalImgId(); TileOverlay::Type ovType = construction::unknown; if( oTile.getFlag( Tile::tlRoad ) ) // road { ovType = construction::road; Picture pic = Picture::load( ResourceGroup::land1a, 230 + math::random( 59) ); oTile.setPicture( pic ); oTile.setOriginalImgId( TileHelper::convPicName2Id( pic.name() ) ); } else if( (imgId >= 372 && imgId <= 427) ) { oTile.setFlag( Tile::tlCoast, true ); if( imgId >= 388 ) oTile.setFlag( Tile::tlRubble, true ); } else /*if( oTile.getFlag( Tile::tlBuilding ) )*/ { unsigned id = forceId > 0 ? forceId : oTile.originalImgId(); ovType = convImgId2ovrType( id ); } if( ovType == construction::unknown ) return; TileOverlayPtr overlay; // This is the overlay object, if any overlay = TileOverlayFactory::instance().create( ovType ); if( ovType == building::elevation ) { std::string elevationPicName = TileHelper::convId2PicName( oTile.originalImgId() ); overlay->setPicture( Picture::load( elevationPicName ) ); } if( overlay != NULL ) { //Logger::warning( "Building at ( %d, %d ) with ID: %x", oTile.i(), oTile.j(), oTile.originalImgId() ); if( oTile.overlay().isValid() ) return; overlay->build( city, oTile.pos() ); city->overlays().push_back( overlay ); } }
static LegionEmblem _findFreeEmblem( PlayerCityPtr city ) { FortList forts; forts << city->overlays(); std::vector<LegionEmblem> availableEmblems; VariantMap emblemsModel = config::load( SETTINGS_RC_PATH( emblemsModel ) ); foreach( it, emblemsModel ) { VariantMap vm_emblem = it->second.toMap(); LegionEmblem newEmblem; newEmblem.name = vm_emblem[ lc_name ].toString(); newEmblem.pic = Picture::load( vm_emblem[ lc_img ].toString() ); if( !newEmblem.name.empty() && newEmblem.pic.isValid() ) { availableEmblems.push_back( newEmblem ); } }
static void __createRivers(Game& game ) { PlayerCityPtr oCity = game.city(); Tilemap& oTilemap = oCity->tilemap(); TerrainGeneratorHelper tgHelper; Pathfinder& pathfinder = Pathfinder::instance(); pathfinder.setCondition( makeDelegate( &tgHelper, &TerrainGeneratorHelper::canBuildRiver ) ); TilesArray terrainTiles = oTilemap.getArea( TilePos(0,0), Size( oTilemap.size() ) ); for( TilesArray::iterator it=terrainTiles.begin(); it != terrainTiles.end(); ) { Tile* tile = *it; if( tile->isWalkable( true ) || tile->getFlag( Tile::tlTree ) ) { ++it; } else { it = terrainTiles.erase( it ); } } int riverCount = 0; for( int tryCount=0; tryCount < 20; tryCount++ ) { if( riverCount++ > oTilemap.size() / 60 ) break; Tile* centertile = terrainTiles.random(); Pathway way; for( int range=0; range < 99; range++ ) { TilesArray perimeter = oTilemap.getRectangle( range, centertile->pos() ); foreach( it, perimeter ) { Tile* currentTile = *it; if( currentTile->getFlag( Tile::tlWater ) ) { way = pathfinder.getPath( *centertile, *currentTile, Pathfinder::customCondition | Pathfinder::fourDirection ); if( way.isValid() ) { break; } } } if( way.isValid() ) break; } if( way.isValid() ) { TilesArray wayTiles = way.allTiles(); foreach( it, wayTiles ) { TileOverlayPtr overlay = TileOverlayFactory::instance().create( constants::objects::river ); //Picture pic = Picture::load( ResourceGroup::land1a, 62 + math::random( 57 ) ); (*it)->setPicture( Picture::getInvalid() ); //(*it)->setOriginalImgId( TileHelper::convPicName2Id( pic.name() ) ); (*it)->setOriginalImgId( 0 ); bool isWater = (*it)->getFlag( Tile::tlWater ); CityAreaInfo info = { oCity, (*it)->pos(), TilesArray() }; overlay->build( info ); oCity->overlays().push_back( overlay ); if( isWater ) break; }