bool MapSystem::AddEmptyMap(const std::string& dataPath, const std::string& mapname) { if(IsMapLoaded(mapname)) { return false; } if(GetSystemInterface()->FindDataFile(mapname) != "") { mLoadedMaps.push_back(MapData(mapname, dataPath, static_cast<unsigned int>(mLoadedMaps.size()))); return false; } std::string mappathrel = GetFilePath(mapname); std::ostringstream os; os << dataPath << "/" << mappathrel; std::string mappathabs = os.str(); if(!GetSystemInterface()->FileExists(mappathabs)) { LOG_ERROR("Cannot create map in directory " << mappathabs << "! Does it exist?"); return false; } MapBeginLoadMessage msg; msg.SetMapPath(mapname); GetEntityManager().EmitMessage(msg); mLoadedMaps.push_back(MapData(mapname, dataPath, static_cast<unsigned int>(mLoadedMaps.size()))); MapLoadedMessage msg2; msg2.SetMapPath(mapname); GetEntityManager().EmitMessage(msg2); return true; }
//----------------------------------------------------------------------------- // Draws the puppy //----------------------------------------------------------------------------- void CEntityTeamImagePanel::Paint( void ) { // Determine team index of underlying entity int teamnumber = GetEntity()->GetTeamNumber(); if ( teamnumber < 0 || teamnumber >= MAX_TEAMS ) { Assert( 0 ); return; } if ( !m_Images[ teamnumber ].m_pImage ) return; // Don't draw if I'm not visible in the tactical map if ( MapData().IsEntityVisibleToTactical( GetEntity() ) == false ) return; ComputeAndSetSize(); vgui::surface()->DrawSetColor( m_Images[ teamnumber ].m_r, m_Images[ teamnumber ].m_g, m_Images[ teamnumber ].m_b, m_Images[ teamnumber ].m_b ); Color color; color.SetColor( m_Images[ teamnumber ].m_r, m_Images[ teamnumber ].m_g, m_Images[ teamnumber ].m_b, m_Images[ teamnumber ].m_b ); m_Images[ teamnumber ].m_pImage->SetColor( color ); m_Images[ teamnumber ].m_pImage->DoPaint( GetVPanel() ); }
//----------------------------------------------------------------------------- // called when we're ticked... //----------------------------------------------------------------------------- void CEntityImageHealthPanel::OnTick() { // tick the entity panel BaseClass::OnTick(); C_BaseEntity* pBaseEntity = GetEntity(); if (!pBaseEntity) return; // Don't draw if I'm not visible in the tactical map if ( MapData().IsEntityVisibleToTactical( pBaseEntity ) == false ) return; if ( m_CommanderHealthBar ) m_CommanderHealthBar->SetHealth( (float)pBaseEntity->GetHealth() / (float)pBaseEntity->GetMaxHealth() ); if ( m_NormalHealthBar ) m_NormalHealthBar->SetHealth( (float)pBaseEntity->GetHealth() / (float)pBaseEntity->GetMaxHealth() ); // Hide the health bar we don't want to see C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer && (pBaseEntity->GetTeamNumber() != pPlayer->GetTeamNumber()) ) { if ( m_CommanderHealthBar ) m_CommanderHealthBar->SetVisible( false ); if ( m_NormalHealthBar ) m_NormalHealthBar->SetVisible( false ); if ( m_ResourceLevelBar ) m_ResourceLevelBar->SetVisible( false ); if ( m_pImagePanel ) m_pImagePanel->SetVisible( false ); } else if ( IsLocalPlayerInTactical() ) { if ( m_CommanderHealthBar ) m_CommanderHealthBar->SetVisible( true ); if ( m_NormalHealthBar ) m_NormalHealthBar->SetVisible( false ); if ( m_ResourceLevelBar ) m_ResourceLevelBar->SetVisible( true ); if ( m_pImagePanel ) m_pImagePanel->SetVisible( true ); } else { if ( m_CommanderHealthBar ) m_CommanderHealthBar->SetVisible( false ); if ( m_NormalHealthBar ) m_NormalHealthBar->SetVisible( true ); if ( m_ResourceLevelBar ) m_ResourceLevelBar->SetVisible( true ); if ( m_pImagePanel ) m_pImagePanel->SetVisible( false ); } }
void MapDatabase::InitializeDatabase() { wxInt32 i; //reset the array of game IDs sMapData.clear(); sOffsets.clear(); //key file wxFile keydb; keydb.Open(FilePath::Data(DataFileMapKeys)); wxFileInputStream y(keydb); wxDataInputStream keys(y); //sanity if(false == keydb.IsOpened()) { return; } wxUint32 keyLength; wxInt32 size; //calculate the length of the key file keyLength = keydb.Length(); //determine how many maps there are size = keyLength / sizeof(wxInt32); //reset the offsets sOffsets.resize(size); //read them in for(i = 0; i < size; i++) { keys >> sOffsets[i]; } //now actually read all the map IDs for(i = 0; i < size; i++) { Map map; LoadMap(i, map); sMapData.push_back( MapData(map.read<wxInt32>(shID), map.name(), map.internal_name(), map.read<wxInt32>(shMinPlayers), map.read<wxInt32>(shMaxPlayers), map.read<wxInt32>(shPoints))); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CHudPlayerOverlay::Paint() { // Don't draw if I'm not visible in the tactical map if ( MapData().IsEntityVisibleToTactical( GetEntity() ) == false ) return; // Don't draw if if I haven't chosen a class... SetFgColor( m_fgColor ); SetBgColor( m_bgColor ); BaseClass::Paint(); }
int mainmilk() { std::ifstream fin("milk.in"); std::ofstream fout("milk.out"); std::multimap<unsigned, unsigned> data; unsigned targetMilk; fin >> targetMilk; MapData(data, fin); fout << MinCost(data, targetMilk) << std::endl; return 0; }
bool MapSystem::LoadMap(const std::string& path) { if(IsMapLoaded(path)) { LOG_ERROR("Map already loaded: " + path); return false; } if(!MapExists(path)) { LOG_ERROR("Map not found: " + path); return false; } MapEncoder* enc = GetEncoderForMap(GetFileExtension(path)); if(!enc) { LOG_ERROR("Could not load map: Loader not found for extension " << GetFileExtension(path)); return false; } // get data path containing this map std::string abspath = GetSystemInterface()->FindDataFile(path); std::string mapdatapath = dtEntity::GetSystemInterface()->GetDataFilePathFromFilePath(abspath); assert(mapdatapath != ""); LoadedMaps::size_type mapsaveorder = mLoadedMaps.size(); MapBeginLoadMessage msg; msg.SetMapPath(path); msg.SetDataPath(mapdatapath); msg.SetSaveOrder(mapsaveorder); GetEntityManager().EmitMessage(msg); bool success = enc->LoadMapFromFile(path); if(success) { mLoadedMaps.push_back(MapData(path, mapdatapath, static_cast<unsigned int>(mLoadedMaps.size()))); MapLoadedMessage msg1; msg1.SetMapPath(path); msg1.SetDataPath(mapdatapath); msg1.SetSaveOrder(mapsaveorder); GetEntityManager().EmitMessage(msg1); } return success; }
//----------------------------------------------------------------------------- // Draws the puppy //----------------------------------------------------------------------------- void CEntityImagePanel::Paint( void ) { // Don't draw if I'm not visible in the tactical map if ( MapData().IsEntityVisibleToTactical( GetEntity() ) == false ) return; vgui::surface()->DrawSetColor( m_r, m_g, m_b, m_a ); if ( !m_pImage ) return; Color color; color.SetColor( m_r, m_g, m_b, m_a ); m_pImage->SetColor( color ); m_pImage->DoPaint( GetVPanel() ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void ClientModeTFBase::Update( void ) { MapData().Update(); }
AStarSearch::AStarSearch(MapClass* pMap, UnitClass* pUnit, Coord start, Coord destination) { sizeX = pMap->sizeX; sizeY = pMap->sizeY; mapData = (TileData*) calloc(sizeX*sizeY, sizeof(TileData)); if(mapData == NULL) { throw std::bad_alloc(); } float heuristic = blockDistance(start, destination); float smallestHeuristic = heuristic; bestCoord = Coord(INVALID_POS,INVALID_POS); //if the unit is not directly next to its destination or it is and the destination is unblocked if ((heuristic > 1.5) || (pUnit->canPass(destination.x, destination.y) == true)) { putOnOpenListIfBetter(start, Coord(INVALID_POS, INVALID_POS), 0.0, heuristic); std::vector<short> depthCheckCount(std::min(sizeX, sizeY)); int numNodesChecked = 0; while(openList.empty() == false) { Coord currentCoord = extractMin(); if (MapData(currentCoord).h < smallestHeuristic) { smallestHeuristic = MapData(currentCoord).h; bestCoord = currentCoord; if(currentCoord == destination) { // destination found break; } } if (numNodesChecked < MAX_NODES_CHECKED) { //push a node for each direction we could go for (int angle=0; angle<=7; angle++) { Coord nextCoord = pMap->getMapPos(angle, currentCoord); if(pUnit->canPass(nextCoord.x, nextCoord.y)) { TerrainClass& nextTerrainTile = pMap->cell[nextCoord.x][nextCoord.y]; float g = MapData(currentCoord).g; if((nextCoord.x != currentCoord.x) && (nextCoord.y != currentCoord.y)) { //add diagonal movement cost g += DIAGONALCOST*(pUnit->isAFlyingUnit() ? 1.0 : nextTerrainTile.getDifficulty()); } else { g += (pUnit->isAFlyingUnit() ? 1.0 : nextTerrainTile.getDifficulty()); } if(pUnit->isAFlyingUnit()) { int numDirectionChanges = abs((pUnit->getAngle() - angle)%NUM_ANGLES); double distanceFromStart = blockDistance(start, nextCoord); if(numDirectionChanges > 2) { if(distanceFromStart <= DIAGONALCOST) { g += 3.0; } else if(distanceFromStart <= 2*DIAGONALCOST) { g += 2.0; } } else if(numDirectionChanges > 1) { if(distanceFromStart <= DIAGONALCOST) { g += 3.0; } else if(distanceFromStart <= 2*DIAGONALCOST) { g += 2.0; } } } if(MapData(currentCoord).parentCoord.x != INVALID_POS) { //add cost of turning time int posAngle = currentGameMap->getPosAngle(MapData(currentCoord).parentCoord, currentCoord); if (posAngle != angle) g += (1.0/currentGame->objectData.data[pUnit->getItemID()].turnspeed * (double)std::min(abs(angle - posAngle), NUM_ANGLES - std::max(angle, posAngle) + std::min(angle, posAngle)))/((double)BLOCKSIZE); } float h = blockDistance(nextCoord, destination); if(MapData(nextCoord).bClosed == false) { putOnOpenListIfBetter(nextCoord, currentCoord, g, h); } } } } if (MapData(currentCoord).bClosed == false) { int depth = std::max(abs(currentCoord.x - destination.x), abs(currentCoord.y - destination.y)); if(depth < std::min(sizeX,sizeY)) { // calculate maximum number of cells in a square shape // you could look at without success around a destination x,y // with a specific k distance before knowing that it is // imposible to get to the destination. Each time the astar // algorithm pushes a node with a max diff of k, // depthcheckcount(k) is incremented, if it reaches the // value in depthcheckmax(x,y,k), we know we have done a full // square around target, and thus it is impossible to reach // the target, so we should try and get closer if possible, // but otherwise stop // // Examples on 6x4 map: // // ...... // ..###. - k=1 => 3x3 Square // ..# #. - (x,y)=(3,2) => Square completely inside map // ..###. => depthcheckmax(3,2,1) = 8 // // .#.... // ##.... - k=1 => 3x3 Square // ...... - (x,y)=(0,0) => Square only partly inside map // ...... => depthcheckmax(0,0,1) = 3 // // ...#.. // ...#.. - k=2 => 5x5 Square // ...#.. - (x,y)=(0,1) => Square only partly inside map // ####.. => depthcheckmax(0,1,2) = 7 int x = destination.x; int y = destination.y; int k = depth; int horizontal = std::min(sizeX-1, x+(k-1)) - std::max(0, x-(k-1)) + 1; int vertical = std::min(sizeY-1, y+k) - std::max(0, y-k) + 1; int depthCheckMax = ((x-k >= 0) ? vertical : 0) + ((x+k < sizeX) ? vertical : 0) + ((y-k >= 0) ? horizontal : 0) + ((y+k < sizeY) ? horizontal : 0); if (++depthCheckCount[k] >= depthCheckMax) { // we have searched a whole square around destination, it can't be reached break; } } MapData(currentCoord).bClosed = true; numNodesChecked++; } } } }
/** This method loads the game map. This is based on the [MAP] section in the INI file. */ void INIMapEditorLoader::loadMap() { version = inifile->getIntValue("BASIC", "Version", 1); if(version < 2) { // we have all houses fixed std::vector<MapEditor::Player>& players = pMapEditor->getPlayers(); std::vector<MapEditor::Player>::iterator iter; for(iter = players.begin(); iter != players.end(); ++iter) { iter->bAnyHouse = false; } } pMapEditor->mapInfo.author = inifile->getStringValue("BASIC", "Author"); pMapEditor->mapInfo.license = inifile->getStringValue("BASIC", "License"); pMapEditor->mapInfo.winFlags = inifile->getIntValue("BASIC", "WinFlags", 3); pMapEditor->mapInfo.loseFlags = inifile->getIntValue("BASIC", "LoseFlags", 1); pMapEditor->mapInfo.losePicture = inifile->getStringValue("BASIC", "LosePicture"); pMapEditor->mapInfo.winPicture = inifile->getStringValue("BASIC", "WinPicture"); pMapEditor->mapInfo.briefPicture = inifile->getStringValue("BASIC", "BriefPicture"); pMapEditor->mapInfo.timeout = inifile->getIntValue("BASIC", "TimeOut", 0); pMapEditor->mapInfo.techLevel = inifile->getIntValue("BASIC", "TechLevel", 0); if(version < 2) { int mapscale = inifile->getIntValue("BASIC", "MapScale", 0); pMapEditor->mapInfo.mapSeed = inifile->getIntValue("MAP", "Seed", 0); pMapEditor->map = createMapWithSeed(pMapEditor->mapInfo.mapSeed, mapscale); switch(mapscale) { case 0: { sizeX = 62; sizeY = 62; logicalOffsetX = 1; logicalOffsetY = 1; } break; case 1: { sizeX = 32; sizeY = 32; logicalOffsetX = 16; logicalOffsetY = 16; } break; case 2: { sizeX = 21; sizeY = 21; logicalOffsetX = 11; logicalOffsetY = 11; } break; default: { logError(inifile->getKey("BASIC", "MapScale")->getLineNumber(), "Unknown MapScale '" + stringify(mapscale) + "'!"); } break; } logicalSizeX = 64; logicalSizeY = 64; int cursorPos = inifile->getIntValue("BASIC", "CursorPos", 0); pMapEditor->mapInfo.cursorPos = Coord(getXPos(cursorPos), getYPos(cursorPos)); int tacticalPos = inifile->getIntValue("BASIC", "TacticalPos", 0); pMapEditor->mapInfo.tacticalPos = Coord(getXPos(tacticalPos), getYPos(tacticalPos)); // field, spice bloom and special bloom std::string BloomString = inifile->getStringValue("MAP","Bloom"); if(BloomString != "") { std::vector<std::string> BloomPositions = splitString(BloomString); for(unsigned int i=0; i < BloomPositions.size();i++) { // set bloom int BloomPos; if(parseString(BloomPositions[i], BloomPos)) { int xpos = getXPos(BloomPos); int ypos = getYPos(BloomPos); pMapEditor->getSpiceBlooms().push_back(Coord(xpos,ypos)); } else { logWarning(inifile->getKey("MAP", "Bloom")->getLineNumber(), "Invalid spice bloom position: '" + BloomPositions[i] + "'"); } } } std::string SpecialString = inifile->getStringValue("MAP","Special"); if(SpecialString != "") { std::vector<std::string> SpecialPositions = splitString(SpecialString); for(unsigned int i=0; i < SpecialPositions.size();i++) { // set special int SpecialPos; if(parseString(SpecialPositions[i], SpecialPos)) { int xpos = getXPos(SpecialPos); int ypos = getYPos(SpecialPos); pMapEditor->getSpecialBlooms().push_back(Coord(xpos,ypos)); } else { logWarning(inifile->getKey("MAP", "Special")->getLineNumber(), "Invalid special bloom position: '" + SpecialPositions[i] + "'"); } } } std::string FieldString = inifile->getStringValue("MAP","Field"); if(FieldString != "") { std::vector<std::string> FieldPositions = splitString(FieldString); for(unsigned int i=0; i < FieldPositions.size();i++) { // set bloom int FieldPos; if(parseString(FieldPositions[i], FieldPos)) { int xpos = getXPos(FieldPos); int ypos = getYPos(FieldPos); pMapEditor->getSpiceFields().push_back(Coord(xpos,ypos)); } else { logWarning(inifile->getKey("MAP", "Field")->getLineNumber(), "Invalid spice field position: '" + FieldPositions[i] + "'"); } } } } else { // new map format with saved map pMapEditor->mapInfo.cursorPos = Coord::Invalid(); pMapEditor->mapInfo.tacticalPos = Coord::Invalid(); pMapEditor->mapInfo.mapSeed = INVALID; int sizeX = inifile->getIntValue("MAP", "SizeX", 0); int sizeY = inifile->getIntValue("MAP", "SizeY", 0); pMapEditor->map = MapData(sizeX, sizeY); logicalSizeX = sizeX; logicalSizeY = sizeY; logicalOffsetX = 0; logicalOffsetY = 0; for(int y=0;y<sizeY;y++) { std::string rowKey = strprintf("%.3d", y); if(inifile->hasKey("MAP", rowKey) == false) { logWarning(inifile->getSection("MAP")->getLineNumber(), "Map row " + stringify(y) + " does not exist!"); continue; } std::string rowString = inifile->getStringValue("MAP",rowKey); int rowLength = rowString.size(); if(rowLength < sizeX) { logWarning(inifile->getKey("MAP", rowKey)->getLineNumber(), "Map row " + stringify(y) + " is not long enough!"); } else if(rowLength > sizeX) { logWarning(inifile->getKey("MAP", rowKey)->getLineNumber(), "Map row " + stringify(y) + " is too long!"); rowLength = sizeX; } for(int x=0;x<rowLength;x++) { TERRAINTYPE type = Terrain_Sand; switch(rowString.at(x)) { case '-': { // Normal sand type = Terrain_Sand; } break; case '^': { // Sand dunes type = Terrain_Dunes; } break; case '~': { // Spice type = Terrain_Spice; } break; case '+': { // Thick spice type = Terrain_ThickSpice; } break; case '%': { // Rock type = Terrain_Rock; } break; case '@': { // Mountain type = Terrain_Mountain; } break; case 'O': { // Spice Bloom type = Terrain_SpiceBloom; } break; case 'Q': { // Special Bloom type = Terrain_SpecialBloom; } break; default: { logWarning(inifile->getKey("MAP", rowKey)->getLineNumber(), std::string("Unknown map tile type '") + rowString.at(x) + "' in map tile (" + stringify(x) + ", " + stringify(y) + ")!"); type = Terrain_Sand; } break; } pMapEditor->map(x,y) = type; } } } screenborder->adjustScreenBorderToMapsize(pMapEditor->map.getSizeX(), pMapEditor->map.getSizeY()); }
QVector<MapData> PriorityMap::loadMap() const { QVector<MapData> priorityMap; QFile file(PLUGINS_DIR "/rules"); file.open(QIODevice::ReadOnly); QTextStream in(&file); while (!in.atEnd()) { const float priority = in.readLine().toFloat(); QPoint current; MapType map; for (int row = 0;; ++row) { const QString& line = in.readLine(); if (line[0] == '/') break; const QStringList& cells = line.split(' '); map.push_back(MapLine(cells.size())); MapLine& lastRow = map.back(); for (int column = 0; column < cells.size(); ++column) { const MapElement type = MAP_ELEMENT_TO_STR.right.at(cells[column]); lastRow[column] = type; if (type == MapElement::CU) current = {column, row}; } } priorityMap.push_back(MapData(std::move(map), current, priority)); } priorityMap.reserve(priorityMap.size() * 16); for (int i = 0, max = priorityMap.size(); i < max; ++i) { const MapData& data = priorityMap[i]; priorityMap.push_back(opposite(data)); const MapData& invertedData = inverse(data); priorityMap.push_back(invertedData); priorityMap.push_back(opposite(invertedData)); MapData newData = data; for (int j = 0; j < 3; ++j) { newData = rotate(newData); priorityMap.push_back(newData); priorityMap.push_back(opposite(newData)); const MapData& invertedMap = inverse(newData); priorityMap.push_back(invertedMap); priorityMap.push_back(opposite(invertedMap)); } } return priorityMap; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void ClientModeTFBase::Update( void ) { BaseClass::Update(); MapData().Update(); }
void CHudPlayerOverlay::OnTick( ) { BaseClass::OnTick(); if (!IsLocalPlayerInTactical() || !engine->IsInGame()) { Hide(); return; } // Don't draw if I'm not visible in the tactical map if ( MapData().IsEntityVisibleToTactical( GetEntity() ) == false ) { Hide(); return; } // Don't draw it if I'm on team 0 (haven't decided on a team) C_BaseTFPlayer *pPlayer = m_hPlayer.Get(); if (!pPlayer || (pPlayer->GetTeamNumber() == 0) || (pPlayer->GetClass() == TFCLASS_UNDECIDED)) { Hide(); return; } SetVisible( true ); char *pName = g_PR->Get_Name( m_PlayerNum ); if ( pName ) { m_pName->SetName( pName ); } else { Hide(); return; } Vector pos, screen; C_BaseTFPlayer *tf2player = dynamic_cast<C_BaseTFPlayer *>( GetEntity() ); int iteam = 0; int iclass = 0; if ( tf2player ) { iteam = tf2player->GetTeamNumber(); iclass = tf2player->PlayerClass(); // FIXME: Get max health for player m_pHealth->SetHealth( (float)tf2player->GetHealth() / (float)100.0f ); } m_pClass->SetImage( 0 ); if ( iteam != 0 && iclass != TFCLASS_UNDECIDED ) m_pClass->SetTeamAndClass( iteam, iclass ); // Update our position on screen int sx, sy; GetEntityPosition( sx, sy ); // Set the position SetPos( (int)(sx + m_OffsetX + 0.5f), (int)(sy + m_OffsetY + 0.5f)); // Add it in m_pHealth->SetVisible( true ); m_pName->SetVisible( true ); m_pClass->SetVisible( true ); if ( MapData().m_Players[ m_PlayerNum - 1 ].m_bSelected ) { m_pSelected->SetVisible( true ); } else { m_pSelected->SetVisible( false ); } if ( MapData().m_Players[ m_PlayerNum - 1 ].m_nSquadNumber != 0 ) { char sz[ 32 ]; Q_snprintf( sz, sizeof( sz ), "%i", MapData().m_Players[ m_PlayerNum - 1 ].m_nSquadNumber ); m_pSquad->SetSquad( sz ); m_pSquad->SetVisible( true ); } else { m_pSquad->SetVisible( false ); } // Hide details if it's an enemy if ( ArePlayersOnSameTeam( engine->GetPlayer(), m_PlayerNum ) == false ) { m_pHealth->SetVisible( false ); m_pName->SetVisible( false ); m_pSelected->SetVisible( false ); m_pSquad->SetVisible( false ); // Only show class icon m_pClass->SetVisible( true ); } }