void CScutFrame::calQuads() { if (getTileCount() == 0) { return; } int nCount = getTileCount(); calTextureTileCount(nCount); initQuads(nCount); initIndices(nCount); }
void House::updateDoorDescription() { std::stringstream houseDescription; houseDescription << "It belongs to house '" << houseName << "'. " << std::endl; if(houseOwner != 0){ houseDescription << houseOwnerName << " owns this house."; } else{ houseDescription << "Nobody owns this house."; if(g_config.getNumber(ConfigManager::SHOW_HOUSE_PRICES)){ uint32_t price = getTileCount() * g_config.getNumber(ConfigManager::HOUSE_TILE_PRICE); houseDescription << std::endl << "It costs " << price << " gold coins."; std::string strPeriod; Houses::getInstance()->getRentPeriodString(strPeriod); if(strPeriod != "never"){ houseDescription << " Its rent costs " << getRent() << " gold coins and it's paid " << strPeriod << "."; } } } HouseDoorList::iterator it; for(it = doorList.begin(); it != doorList.end(); ++it){ (*it)->setSpecialDescription(houseDescription.str()); } }
void Map::cleanInvalidTiles(bool showdialog) { if(showdialog) gui.CreateLoadBar(wxT("Removing invalid tiles...")); uint64_t tiles_done = 0; for(MapIterator miter = begin(); miter != end(); ++miter) { Tile* tile = (*miter)->get(); ASSERT(tile); if(tile->size() == 0) continue; for(ItemVector::iterator item_iter = tile->items.begin(); item_iter != tile->items.end();) { if(item_db.typeExists((*item_iter)->getID())) ++item_iter; else { delete *item_iter; item_iter = tile->items.erase(item_iter); } } ++tiles_done; if(showdialog && tiles_done % 0x10000 == 0) { gui.SetLoadDone(int(tiles_done / double(getTileCount()) * 100.0)); } } if(showdialog) gui.DestroyLoadBar(); }
/** * @brief Assert that an index is valid and within bounds. * @param index the index * @throw Id::RuntimeErrorException if the index is not valid or not within bounds */ void assertValid(const Index1D& index) const { if (Index1D::Invalid == index) { throw Id::RuntimeErrorException(__FILE__, __LINE__, "invalid index"); } if (index >= getTileCount() || index < 0) { throw Id::RuntimeErrorException(__FILE__, __LINE__, "index out of bounds"); } }
bool TileSet::partitionTileSetLoad( WadMapTable &mapping_table, int *percent_complete ) { unsigned long tile_count = getTileCount(); unsigned long partition_index = 0; *percent_complete = -1; while( (partition_load_tile_index < tile_count) && (partition_index < partition_load_partition_count) ) { if ( mapping_table[ partition_load_tile_index ].is_used == true ) { read( partition_load_fhandle, (tile_data + (partition_load_mapped_index*tile_size)), tile_size ); partition_load_mapped_index++; } else { lseek( partition_load_fhandle, tile_size, SEEK_CUR ); } partition_index++; partition_load_tile_index++; } if ( partition_load_tile_index == tile_count ) { close( partition_load_fhandle ); tile_set_loaded = true; TileSet::tile_count = mapping_table.used_tile_count; computeTileConsts(); *percent_complete = 100; return( false ); } else { float percent; percent = ( ( (float) partition_load_tile_index) / ( (float) tile_count ) ) * 100; *percent_complete = (int) percent; partition_index = 0; return( true ); } }
sf::IntRect Tileset::getTileAsRect(unsigned long tileIndex) const { sf::IntRect spriteArea; if (tileIndex < getTileCount()) { unsigned long rowIndex = tileIndex / getColumnCount(); unsigned long columnIndex = tileIndex % getColumnCount(); unsigned long tileWidth = m_spacing.getLeft() + m_tileSize.getWidth() + m_spacing.getRight(); unsigned long tileHeight = m_spacing.getTop() + m_tileSize.getHeight() + m_spacing.getBottom(); spriteArea.left = static_cast<unsigned int>(m_margin.getLeft() + columnIndex * tileWidth); spriteArea.top = static_cast<unsigned int>(m_margin.getTop() + rowIndex * tileHeight); spriteArea.width = static_cast<unsigned int>(m_tileSize.getWidth()); spriteArea.height = static_cast<unsigned int>(m_tileSize.getHeight()); } return spriteArea; }
bool BaseAI::startTurn() { static bool initialized = false; int count = 0; count = getPlayerCount(c); players.clear(); players.resize(count); for(int i = 0; i < count; i++) { players[i] = Player(getPlayer(c, i)); } count = getMappableCount(c); mappables.clear(); mappables.resize(count); for(int i = 0; i < count; i++) { mappables[i] = Mappable(getMappable(c, i)); } count = getTileCount(c); tiles.clear(); tiles.resize(count); for(int i = 0; i < count; i++) { tiles[i] = Tile(getTile(c, i)); } count = getTrapCount(c); traps.clear(); traps.resize(count); for(int i = 0; i < count; i++) { traps[i] = Trap(getTrap(c, i)); } count = getThiefCount(c); thiefs.clear(); thiefs.resize(count); for(int i = 0; i < count; i++) { thiefs[i] = Thief(getThief(c, i)); } count = getThiefTypeCount(c); thiefTypes.clear(); thiefTypes.resize(count); for(int i = 0; i < count; i++) { thiefTypes[i] = ThiefType(getThiefType(c, i)); } count = getTrapTypeCount(c); trapTypes.clear(); trapTypes.resize(count); for(int i = 0; i < count; i++) { trapTypes[i] = TrapType(getTrapType(c, i)); } if(!initialized) { initialized = true; init(); } return run(); }
bool TileSet::startPartitionTileSetLoad( const char *file_path, WadMapTable &mapping_table, unsigned long partitions ) { unsigned long tile_buffer_size; unsigned long tile_size; //int fhandle; // XXX changed _O_BINARY to 0 partition_load_fhandle = open( file_path, 0 ); if ( tile_set_loaded == true ) { if ( tile_data != 0 ) { delete( tile_data ); tile_data = 0; } if ( tile_info != 0 ) { delete( tile_info ); tile_info = 0; } tile_set_loaded = false; } // ** Read Header Info ** //fread( &tile_set_info, sizeof(TILE_DBASE_HEADER), 1, infile ); read( partition_load_fhandle, &tile_set_info, sizeof(TILE_DBASE_HEADER ) ); // ** Read in Tile Info ** tile_info = new TILE_HEADER [ mapping_table.used_tile_count ]; assert( tile_info != 0 ); unsigned short tile_count = 0; unsigned long tile_index = 0; unsigned long mapped_index = 0; tile_count = getTileCount(); for ( tile_index = 0; tile_index < tile_count; tile_index++ ) { if ( mapping_table[ tile_index ].is_used == true ) { read( partition_load_fhandle, (tile_info + mapped_index), sizeof ( TILE_HEADER ) ); //fread( (tile_info + mapped_index), sizeof ( TILE_HEADER ), 1, infile ); mapped_index++; } else { lseek( partition_load_fhandle, sizeof( TILE_HEADER ), SEEK_CUR ); //fseek( infile, sizeof( TILE_HEADER ), SEEK_CUR ); } } // ** Read in tile data ** tile_buffer_size = (tile_set_info.x_pix * tile_set_info.y_pix) * mapping_table.used_tile_count; TileSet::tile_size = tile_size = (tile_set_info.x_pix * tile_set_info.y_pix); tile_data = new unsigned char [tile_buffer_size]; assert( tile_data != 0 ); partition_load_tile_index = 0; partition_load_mapped_index = 0; if( partitions == 0 ) { partition_load_partition_count = tile_count; int percent; partitionTileSetLoad( mapping_table, &percent ); return( false ); } else { partition_load_partition_count = tile_count / partitions; return( true ); } }
void TileSet::loadTileSetInfo( const char *file_path, WadMapTable &mapping_table ) { //FILE *infile; int fhandle; //infile = fopen( file_path, "rb" ); // XXX changed _O_BINARY to 0 fhandle = open( file_path, 0); //assert( infile != 0 ); if ( tile_set_loaded == true ) { if ( tile_data != 0 ) { delete( tile_data ); tile_data = 0; } if ( tile_info != 0 ) { delete( tile_info ); tile_info = 0; } tile_set_loaded = false; } // ** Read Header Info ** //fread( &tile_set_info, sizeof(TILE_DBASE_HEADER), 1, infile ); read( fhandle, &tile_set_info, sizeof(TILE_DBASE_HEADER ) ); // ** Read in Tile Info ** tile_info = new TILE_HEADER [ mapping_table.used_tile_count ]; assert( tile_info != 0 ); unsigned short tile_count = 0; unsigned long tile_index = 0; unsigned long mapped_index = 0; tile_count = getTileCount(); for ( tile_index = 0; tile_index < tile_count; tile_index++ ) { if ( mapping_table[ tile_index ].is_used == true ) { read( fhandle, (tile_info + mapped_index), sizeof ( TILE_HEADER ) ); //fread( (tile_info + mapped_index), sizeof ( TILE_HEADER ), 1, infile ); mapped_index++; } else { lseek( fhandle, sizeof( TILE_HEADER ), SEEK_CUR ); //fseek( infile, sizeof( TILE_HEADER ), SEEK_CUR ); } } close(fhandle ); //fclose( infile ); tile_set_loaded = true; TileSet::tile_count = mapping_table.used_tile_count; computeTileConsts(); }
void TileSet::loadTileSet( const char *file_path, WadMapTable &mapping_table ) { //FILE *infile; unsigned long tile_buffer_size; unsigned long tile_size; int fhandle; // XXX Why, oh why are't we using normal stdio functions here? //infile = fopen( file_path, "rb" ); // XXX changed _O_BINARY to 0... fhandle = open( file_path, 0 ); //assert( infile != 0 ); if ( tile_set_loaded == true ) { if ( tile_data != 0 ) { delete( tile_data ); tile_data = 0; } if ( tile_info != 0 ) { delete( tile_info ); tile_info = 0; } tile_set_loaded = false; } // ** Read Header Info ** //fread( &tile_set_info, sizeof(TILE_DBASE_HEADER), 1, infile ); read( fhandle, &tile_set_info, sizeof(TILE_DBASE_HEADER ) ); // ** Read in Tile Info ** tile_info = new TILE_HEADER [ mapping_table.used_tile_count ]; assert( tile_info != 0 ); unsigned short tile_count = 0; unsigned long tile_index = 0; unsigned long mapped_index = 0; unsigned long unused_tile_count; unsigned long used_tile_count; tile_count = getTileCount(); for ( tile_index = 0; tile_index < tile_count; tile_index++ ) { if ( mapping_table[ tile_index ].is_used == true ) { read( fhandle, (tile_info + mapped_index), sizeof ( TILE_HEADER ) ); //fread( (tile_info + mapped_index), sizeof ( TILE_HEADER ), 1, infile ); mapped_index++; } else { lseek( fhandle, sizeof( TILE_HEADER ), SEEK_CUR ); //fseek( infile, sizeof( TILE_HEADER ), SEEK_CUR ); } } // ** Read in tile data ** tile_buffer_size = (tile_set_info.x_pix * tile_set_info.y_pix) * mapping_table.used_tile_count; tile_size = (tile_set_info.x_pix * tile_set_info.y_pix); tile_data = new unsigned char [tile_buffer_size]; assert( tile_data != 0 ); mapped_index = 0; tile_index = 0; while ( tile_index < tile_count ) { used_tile_count = 0; unused_tile_count = 0; //** find the next used tile while( (tile_index < tile_count) && (mapping_table[ tile_index ].is_used == false) ) { unused_tile_count++; tile_index++; } if ( tile_index < tile_count) { if (unused_tile_count != 0) { lseek( fhandle, tile_size * unused_tile_count, SEEK_CUR ); //fseek( infile, tile_size * unused_tile_count, SEEK_CUR ); } while( (tile_index < tile_count) && (mapping_table[ tile_index ].is_used == true) ) { used_tile_count++; tile_index++; } if (used_tile_count != 0) { read( fhandle, (tile_data + (mapped_index*tile_size)), tile_size * used_tile_count ); //fread( (tile_data + (mapped_index*tile_size)), tile_size , used_tile_count, infile ); mapped_index += used_tile_count; } } // ** if ( tile_index < tile_count) } close(fhandle ); //fclose( infile ); tile_set_loaded = true; TileSet::tile_count = mapping_table.used_tile_count; computeTileConsts(); }
/** * @brief Get if an index is valid and within bounds. * @param index the index * @return @a true if the index is valid and within bounds */ bool isValid(const Index1D& index) const { return Index1D::Invalid != index && index < getTileCount() && index >= 0; }
bool Map::convert(const ConversionMap& rm, bool showdialog) { if(showdialog) gui.CreateLoadBar(wxT("Converting map ...")); uint64_t tiles_done = 0; std::vector<uint16_t> id_list; //std::ofstream conversions("converted_items.txt"); for(MapIterator miter = begin(); miter != end(); ++miter) { Tile* tile = (*miter)->get(); ASSERT(tile); if(tile->size() == 0) continue; // id_list try MTM conversion id_list.clear(); if(tile->ground) id_list.push_back(tile->ground->getID()); for(ItemVector::const_iterator item_iter = tile->items.begin(); item_iter != tile->items.end(); ++item_iter) if((*item_iter)->isBorder()) id_list.push_back((*item_iter)->getID()); std::sort(id_list.begin(), id_list.end()); ConversionMap::MTM::const_iterator cfmtm = rm.mtm.end(); while(id_list.size()) { cfmtm = rm.mtm.find(id_list); if(cfmtm != rm.mtm.end()) break; id_list.pop_back(); } // Keep track of how many items have been inserted at the bottom size_t inserted_items = 0; if(cfmtm != rm.mtm.end()) { const std::vector<uint16_t>& v = cfmtm->first; if(tile->ground && std::find(v.begin(), v.end(), tile->ground->getID()) != v.end()) { delete tile->ground; tile->ground = nullptr; } for(ItemVector::iterator item_iter = tile->items.begin(); item_iter != tile->items.end(); ) { if(std::find(v.begin(), v.end(), (*item_iter)->getID()) != v.end()) { delete *item_iter; item_iter = tile->items.erase(item_iter); } else ++item_iter; } const std::vector<uint16_t>& new_items = cfmtm->second; for(std::vector<uint16_t>::const_iterator iit = new_items.begin(); iit != new_items.end(); ++iit) { Item* item = Item::Create(*iit); if(item->isGroundTile()) tile->ground = item; else { tile->items.insert(tile->items.begin(), item); ++inserted_items; } } } if(tile->ground) { ConversionMap::STM::const_iterator cfstm = rm.stm.find(tile->ground->getID()); if(cfstm != rm.stm.end()) { uint16_t aid = tile->ground->getActionID(); uint16_t uid = tile->ground->getUniqueID(); delete tile->ground; tile->ground = nullptr; const std::vector<uint16_t>& v = cfstm->second; //conversions << "Converted " << tile->getX() << ":" << tile->getY() << ":" << tile->getZ() << " " << id << " -> "; for(std::vector<uint16_t>::const_iterator iit = v.begin(); iit != v.end(); ++iit) { Item* item = Item::Create(*iit); //conversions << *iit << " "; if(item->isGroundTile()) { item->setActionID(aid); item->setUniqueID(uid); tile->addItem(item); } else { tile->items.insert(tile->items.begin(), item); ++inserted_items; } } //conversions << std::endl; } } for(ItemVector::iterator replace_item_iter = tile->items.begin() + inserted_items; replace_item_iter != tile->items.end(); ) { uint16_t id = (*replace_item_iter)->getID(); ConversionMap::STM::const_iterator cf = rm.stm.find(id); if(cf != rm.stm.end()) { //uint16_t aid = (*replace_item_iter)->getActionID(); //uint16_t uid = (*replace_item_iter)->getUniqueID(); delete *replace_item_iter; replace_item_iter = tile->items.erase(replace_item_iter); const std::vector<uint16_t>& v = cf->second; for(std::vector<uint16_t>::const_iterator iit = v.begin(); iit != v.end(); ++iit) { replace_item_iter = tile->items.insert(replace_item_iter, Item::Create(*iit)); //conversions << "Converted " << tile->getX() << ":" << tile->getY() << ":" << tile->getZ() << " " << id << " -> " << *iit << std::endl; ++replace_item_iter; } } else ++replace_item_iter; } ++tiles_done; if(showdialog && tiles_done % 0x10000 == 0) { gui.SetLoadDone(int(tiles_done / double(getTileCount()) * 100.0)); } } if(showdialog) gui.DestroyLoadBar(); return true; }