本文整理汇总了C++中PlayerCityPtr::tilemap方法的典型用法代码示例。如果您正苦于以下问题:C++ PlayerCityPtr::tilemap方法的具体用法?C++ PlayerCityPtr::tilemap怎么用?C++ PlayerCityPtr::tilemap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PlayerCityPtr
的用法示例。
在下文中一共展示了PlayerCityPtr::tilemap方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calcVacantHouse
void Migration::Impl::createMigrationToCity( PlayerCityPtr city )
{
unsigned int vh = calcVacantHouse( city );
if( vh == 0 )
{
return;
}
EmigrantList migrants;
migrants << city->walkers();
if( vh <= migrants.size() * 5 )
{
return;
}
Tile& roadTile = city->tilemap().at( city->borderInfo().roadEntry );
ImmigrantPtr emigrant = Immigrant::create( city );
if( emigrant.isValid() )
{
bool success = emigrant->send2city( roadTile );
emigrant->setSpeedMultiplier( 0.8f + math::random( 40 ) / 100.f );
if( success )
lastMonthComing += emigrant->peoples().count();
}
}
示例2: __removeCorners
static void __removeCorners(Game& game )
{
PlayerCityPtr oCity = game.city();
Tilemap& oTilemap = oCity->tilemap();
unsigned int mapSize = oTilemap.size();
TilePos psAr[8] = { TilePos(0, 1), TilePos(-1, 1), TilePos(-1, 0), TilePos(-1, -1),
TilePos(0, -1), TilePos(1, -1), TilePos(1, 0), TilePos(1, 1)};
//check one water tiles
for( unsigned int i=0; i < mapSize; i++ )
for( unsigned int j=0; j < mapSize; j++ )
{
TilePos tpos = TilePos( i, j );
Tile& wtile = oTilemap.at( tpos );
if( wtile.originalImgId() == 0 ||
wtile.getFlag( Tile::tlWater ) || wtile.getFlag( Tile::tlDeepWater ) )
continue;
for( int k=0; k < 8; k++ )
{
Tile& t = oTilemap.at( tpos + psAr[k] );
bool isWater = ( t.getFlag( Tile::tlWater ) || t.getFlag( Tile::tlDeepWater ) );
if( isWater )
{
wtile.setFlag( Tile::clearAll, true );
wtile.setOriginalImgId( 0 );
wtile.setPicture( Picture() );
break;
}
}
}
}
示例3: _computePictures
void LowBridge::_computePictures(PlayerCityPtr city, const TilePos& startPos, const TilePos& endPos, constants::Direction dir )
{
Tilemap& tilemap = city->tilemap();
//Picture& water = Picture::load( "land1a", 120 );
switch( dir )
{
case northWest:
{
TilesArray tiles = tilemap.getArea( endPos, startPos );
if (tiles.size() < 3) break;
tiles.pop_back();
tiles.erase( tiles.begin() );
_d->addSpan( tiles.front()->pos() - startPos - TilePos( 1, 0 ), LowBridgeSubTile::liftingWest );
foreach( it, tiles )
{
_d->addSpan( (*it)->pos() - startPos, LowBridgeSubTile::spanWest );
}
_d->addSpan( tiles.back()->pos() - startPos + TilePos( 1, 0 ), LowBridgeSubTile::descentWest );
}
break;
case northEast:
{
TilesArray tiles = tilemap.getArea( startPos, endPos );
if (tiles.size() < 3) break;
tiles.pop_back();
tiles.erase( tiles.begin() );
_d->addSpan( tiles.back()->pos() - startPos + TilePos( 0, 1 ), LowBridgeSubTile::liftingNorth );
for( TilesArray::reverse_iterator it=tiles.rbegin(); it != tiles.rend(); ++it )
{
_d->addSpan( (*it)->pos() - startPos, LowBridgeSubTile::spanNorth );
}
_d->addSpan( tiles.front()->pos() - startPos - TilePos( 0, 1 ), LowBridgeSubTile::descentNorth );
}
break;
case southEast:
{
TilesArray tiles = tilemap.getArea( startPos, endPos );
if( tiles.size() < 3 )
break;
tiles.pop_back();
tiles.erase( tiles.begin() );
_d->addSpan( tiles.front()->pos() - startPos - TilePos( 1, 0 ), LowBridgeSubTile::liftingWest );
foreach( it, tiles )
{
_d->addSpan( (*it)->pos() - startPos, LowBridgeSubTile::spanWest );
//_d->subtiles.push_back( LowBridgeSubTile( (*it)->getIJ() - startPos, water ) );
}
_d->addSpan( tiles.back()->pos() - startPos + TilePos( 1, 0 ), LowBridgeSubTile::descentWest );
}
示例4: _computePictures
void LowBridge::_computePictures(PlayerCityPtr city, const TilePos& startPos, const TilePos& endPos, Direction dir )
{
Tilemap& tilemap = city->tilemap();
//Picture& water = Picture::load( "land1a", 120 );
switch( dir )
{
case direction::northWest:
{
Bridge::Area area( tilemap, endPos, startPos );
if (area.size() < 3)
break;
area.cropCorners();
_d->addSpan( area.front()->pos() - startPos - TilePos( 1, 0 ), LowBridgeSubTile::liftingWest );
foreach( it, area )
{
_d->addSpan( (*it)->pos() - startPos, LowBridgeSubTile::spanWest );
}
_d->addSpan( area.back()->pos() - startPos + TilePos( 1, 0 ), LowBridgeSubTile::descentWest );
}
break;
case direction::northEast:
{
Bridge::Area area( tilemap, startPos, endPos );
if (area.size() < 3)
break;
area.cropCorners();
_d->addSpan( area.back()->pos() - startPos + TilePos( 0, 1 ), LowBridgeSubTile::liftingNorth );
for( TilesArray::reverse_iterator it=area.rbegin(); it != area.rend(); ++it )
{
_d->addSpan( (*it)->pos() - startPos, LowBridgeSubTile::spanNorth );
}
_d->addSpan( area.front()->pos() - startPos - TilePos( 0, 1 ), LowBridgeSubTile::descentNorth );
}
break;
case direction::southEast:
{
Bridge::Area area( tilemap, startPos, endPos );
if( area.size() < 3 )
break;
area.cropCorners();
_d->addSpan( area.front()->pos() - startPos - TilePos( 1, 0 ), LowBridgeSubTile::liftingWest );
foreach( it, area )
{
_d->addSpan( (*it)->pos() - startPos, LowBridgeSubTile::spanWest );
}
_d->addSpan( area.back()->pos() - startPos + TilePos( 1, 0 ), LowBridgeSubTile::descentWest );
}
示例5: canBuild
bool MarbleQuarry::canBuild(PlayerCityPtr city, TilePos pos, const TilesArray& aroundTiles ) const
{
bool is_constructible = Construction::canBuild( city, pos, aroundTiles );
bool near_mountain = false; // tells if the factory is next to a mountain
Tilemap& tilemap = city->tilemap();
TilesArray perimetr = tilemap.getRectangle( pos + TilePos( -1, -1 ), size() + Size( 2 ), Tilemap::checkCorners);
foreach( tile, perimetr )
{
near_mountain |= (*tile)->getFlag( Tile::tlRock );
}
示例6: TilePos
void C3Map::Impl::initCameraStartPos(std::fstream &f, PlayerCityPtr ioCity)
{
/*unsigned short int i = 0;
unsigned short int j = 0;
f.seekg(kCamera, std::ios::beg);
f.read((char*)&i, 2);
f.read((char*)&j, 2);*/
int mapSize = ioCity->tilemap().size();
ioCity->setCameraPos( TilePos( mapSize / 2, mapSize / 2 ) );
}
示例7: canBuild
bool Construction::canBuild(PlayerCityPtr city, TilePos pos , const TilesArray& ) const
{
Tilemap& tilemap = city->tilemap();
bool is_constructible = true;
//return area for available tiles
TilesArray area = tilemap.getArea( pos, size() );
//on over map size
if( (int)area.size() != size().area() )
return false;
foreach( tile, area ) {is_constructible &= (*tile)->getFlag( Tile::isConstructible );}
示例8: foreach
void Shoreline::Impl::checkMap( PlayerCityPtr city )
{
const TilesArray& tiles = city->tilemap().allTiles();
foreach( it, tiles )
{
int imgId = (*it)->originalImgId();
if( (imgId >= 372 && imgId <= 403) || (imgId>=414 && imgId<=418) || (*it)->getFlag( Tile::tlCoast ) )
{
slTiles.push_back( *it );
}
if( (*it)->getFlag( Tile::tlDeepWater ) )
{
dwTiles.push_back( *it );
}
}
示例9: TilePos
void C3Sav::Impl::initEntryExit(std::fstream &f, PlayerCityPtr ioCity)
{
unsigned int size = ioCity->tilemap().size();
const unsigned int savePos = f.tellg();
// init road entry/exit point
unsigned short int i = 0;
unsigned short int j = 0;
f.seekg(1236, std::ios::cur);
f.read((char*)&i, 2);
f.read((char*)&j, 2);
BorderInfo borderInfo;
borderInfo.roadEntry = TilePos( i, size - j - 1 );
f.read((char*)&i, 2);
f.read((char*)&j, 2);
borderInfo.roadExit = TilePos( i, size - j - 1 );
// init boat entry/exit point
f.seekg(savePos, std::ios::beg);
f.seekg(1276, std::ios::cur);
f.read((char*)&i, 2);
f.read((char*)&j, 2);
borderInfo.boatEntry = TilePos( i, size - j - 1 );
f.read((char*)&i, 2);
f.read((char*)&j, 2);
borderInfo.boatExit = TilePos( i, size - j - 1);
ioCity->setBorderInfo( borderInfo );
f.seekg(savePos, std::ios::beg);
}
示例10: TilePos
void OMap::Impl::initCameraStartPos(const VariantMap& vm, PlayerCityPtr ioCity)
{
int mapSize = ioCity->tilemap().size();
ioCity->setCameraPos( TilePos( mapSize / 2, mapSize / 2 ) );
}
示例11: PKWareInputStream
//.........这里部分代码省略.........
pk->readShort();
pk->skip(8);
pk->readByte();
pk->readByte();
pk->skip(106);
}
pk->empty();
delete pk;
int length;
f.read((char*)&length, 4); // read next length :-)
if (length <= 0)
f.seekg(1200, std::ios::cur);
else
f.seekg(length, std::ios::cur);
SkipCompressed(f);
SkipCompressed(f);
// 3x int
f.read((char*)&tmp, 4);
f.read((char*)&tmp, 4);
f.read((char*)&tmp, 4);
SkipCompressed(f);
f.seekg(70, std::ios::cur);
SkipCompressed(f); // skip building list
f.seekg(208, std::ios::cur);
SkipCompressed(f); // skip unknown
f.seekg(788, std::ios::cur); // skip unused data
f.read((char*)&tmp, 4); //mapsize
int size = tmp;
PlayerCityPtr oCity = game.city();
Tilemap& oTilemap = oCity->tilemap();
oCity->resize(size);
oCity->setCameraPos( TilePos( 0, 0 ) );
initEntryExit( f, game.city() );
f.seekg(1312, std::ios::cur);
char climate;
f.read(&climate, 1);
oCity->setClimate((ClimateType)climate);
// here goes the WORK!
// loads the graphics map
int border_size = (162 - size) / 2;
std::map< int, std::map< int, unsigned char > > edgeData;
game.city()->setCameraPos( TilePos( size/2, size/2 ) );
for (int itA = 0; itA < size; ++itA)
{
for (int itB = 0; itB < size; ++itB)
{
int i = itB;
int j = size - itA - 1;
int index = 162 * (border_size + itA) + border_size + itB;
Tile& tile = oTilemap.at(i, j);
示例12: THROW
void C3Map::Impl::loadCity(std::fstream& f, PlayerCityPtr oCity)
{
Tilemap& oTilemap = oCity->tilemap();
/* get number of city */
f.seekg(kLocation, std::ios::beg);
unsigned int location=0;
f.read((char*)&location, 1);
Logger::warning( "C3MapLoader: location of city is %d", (int)(location) );
std::string cityName = LoaderHelper::getDefaultCityName( location );
oCity->setName( cityName );
f.seekg(kSize, std::ios::beg);
int map_size; // 32bits
int size_2;
f.read((char*)&map_size, 4);
f.read((char*)&size_2, 4);
Logger::warning( "C3MapLoader: map size is %d", map_size );
if (map_size != size_2)
{
THROW("Horizontal and vertical map sizes are different!");
}
oCity->resize(map_size);
// need to rewrite better
ScopedArrayPtr<short> pGraphicGrid( new short[tilemap::c3mapSizeSq] );
ScopedArrayPtr<unsigned char> pEdgeGrid( new unsigned char[tilemap::c3mapSizeSq] );
ScopedArrayPtr<short> pTerrainGrid( new short[tilemap::c3mapSizeSq] );
ScopedArrayPtr<unsigned char> pRndmTerGrid( new unsigned char[tilemap::c3mapSizeSq] );
ScopedArrayPtr<unsigned char> pRandomGrid( new unsigned char[tilemap::c3mapSizeSq] );
ScopedArrayPtr<unsigned char> pElevationGrid( new unsigned char[tilemap::c3mapSizeSq] );
if( pGraphicGrid.isNull() || pEdgeGrid.isNull() || pTerrainGrid.isNull() ||
pRndmTerGrid.isNull() || pRandomGrid.isNull() || pElevationGrid.isNull() )
{
THROW("NOT ENOUGH MEMORY!!!! FATAL");
}
// here also make copy of original arrays in memory
f.seekg(kGraphicGrid, std::ios::beg);
f.read((char*)pGraphicGrid.data(), tilemap::c3mapSizeSq*2);
f.seekg(kEdgeGrid, std::ios::beg);
f.read((char*)pEdgeGrid.data(), tilemap::c3mapSizeSq);
f.seekg(kTerrainGrid, std::ios::beg);
f.read((char*)pTerrainGrid.data(), tilemap::c3mapSizeSq*2);
f.seekg(kRndmTerGrid, std::ios::beg);
f.read((char*)pRndmTerGrid.data(), tilemap::c3mapSizeSq);
f.seekg(kRandomGrid, std::ios::beg);
f.read((char*)pRandomGrid.data(), tilemap::c3mapSizeSq);
f.seekg(kElevationGrid, std::ios::beg);
f.read((char*)pElevationGrid.data(), tilemap::c3mapSizeSq);
std::map< int, std::map< int, unsigned char > > edgeData;
// loads the graphics map
int border_size = (gfx::tilemap::c3mapSize - map_size) / 2;
for (int itA = 0; itA < map_size; ++itA)
{
for (int itB = 0; itB < map_size; ++itB)
{
int i = itB;
int j = map_size - itA - 1;
int index = gfx::tilemap::c3mapSize * (border_size + itA) + border_size + itB;
Tile& tile = oTilemap.at(i, j);
tile.setPicture( imgid::toResource( pGraphicGrid.data()[index] ) );
tile.setOriginalImgId( pGraphicGrid.data()[index] );
//tile.setHeight( pElevationGrid.data()[ index ] );
edgeData[ i ][ j ] = pEdgeGrid.data()[index];
tile::decode( tile, pTerrainGrid.data()[index] );
tile::fixPlateauFlags( tile );
}
}
for (int i = 0; i < map_size; ++i)
{
for (int j = 0; j < map_size; ++j)
{
unsigned char ed = edgeData[ i ][ j ];
if( ed == 0x00)
{
int size = 1;
{
int dj;
try
{
// find size, 5 is maximal size for building
for (dj = 0; dj < gfx::tilemap::c3bldSize; ++dj)
{
int edd = edgeData[ i ][ j - dj ];
//.........这里部分代码省略.........
示例13: __createRivers
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;
}
示例14: __finalizeMap
static void __finalizeMap(Game& game, int pass )
{
PlayerCityPtr oCity = game.city();
Tilemap& oTilemap = oCity->tilemap();
unsigned int mapSize = oTilemap.size();
//check one water tiles
for( unsigned int i=0; i < mapSize; i++ )
for( unsigned int j=0; j < mapSize; j++ )
{
TilePos tpos = TilePos( i, j );
Tile& wtile = oTilemap.at( tpos );
if( wtile.originalImgId() > 0 )
continue;
int direction = 0;
for( int k=0; k < 8; k++ )
{
Tile& t = oTilemap.at( tpos + psAr[k] );
bool isWater = !t.getFlag( Tile::tlCoast ) && ( t.getFlag( Tile::tlWater ) || t.getFlag( Tile::tlDeepWater ) );
if( isWater )
{
direction += directions[k];
}
}
int start=0, rnd=4;
switch( pass )
{
case passCheckNorthCoastTiles:
switch( direction )
{
case drN: case drN|drNW: case drNW|drNE|drN: case drNE|drN: case drNE|drNW: start=128; break;
}
break;
case passCheckEastCoastTiles:
switch( direction )
{
case drE: case drNE|drE: case drNE|drSE: case drNE|drSE|drE: case drSE|drE: start=132; break;
}
break;
case passCheckSouthCoastTiles:
switch( direction )
{
case drS: case drSW|drS: case drSE|drS: case drSW|drSE|drS: case drSW|drSE: start=136; break;
}
break;
case passCheckWestCoastTiles:
switch( direction )
{
case drW: case drSW|drNW|drW: case drSW|drW: case drNW|drW: case drSW|drNW: start=140; break;
}
break;
case passCheckSmallCoastTiles:
switch( direction )
{
case drE|drS|drSE:
case drE|drNE|drSE|drS:
case drE|drSW|drSE|drS:
case drE|drSW|drSE|drS|drNE:
case drE|drSW|drSE|drNE:
case drE|drSW|drNE: case drNE|drSE|drSW|drS:
case drSE|drNE|drS: case drNE|drS|drE: case drSW|drE:
case drSW|drS|drE: case drNE|drS: case drNE|drSW|drS:
case drNE|drSW|drE|drS:
case drE|drS: case drNE|drSE|drSW: case drSW|drSE|drE: start = 171; rnd=0; break;
case drNW|drSW|drW|drN: case drNW|drW|drN: case drNW|drNE|drW|drN:
case drNW|drNE|drW: case 0xd9: case 0x58: case 0x19:
case 0xd8: case 0xd1: case 0x49: case 0x18: case 0xc1: case 0x41:
case 0x51: case 0x09: case 0x59: case 0xd0: start=173; rnd=0; break;
case 0x13: case 0xb1: case 0x23: case 0x93: case 0x33: case 0xb3: case 0x83:
case 0x31: case 0xa3: case 0x21: case 0x82: case 0xa1: case 0xa2: case 0x92:
case 0xb2: case 0x03: case 0xb0: start=170; rnd=0; break;
case 0xa0: start=168; rnd=0; break;
case 0x50: start=169; rnd=0; break;
case 0xcc: case 0x4c: case 0x6c: case 0xec:
case 0xc4: case 0x68: case 0xe4: case 0xe8: case 0xa8: case 0x84:
case 0x28: case 0xac: case 0xa4: case 0x0c: case 0x8c: case 0x2c:
case 0xe0: start = 172; rnd=0; break;
}
break;
case 6:
break;
case passCheckInsideCornerTiles:
switch( direction )
{
case drNE: start=PicID::coastNE; break;
case drSE: start=PicID::coastSE; break;
case 0x40: start=152; break;
//.........这里部分代码省略.........