void ArenaMap::renderMapOverlay( unsigned int color, short inspectSquareX, short inspectSquareY ) const { unsigned char r = (unsigned char)( ( color & 0xff000000 ) >> 24 ); unsigned char g = (unsigned char)( ( color & 0x00ff0000 ) >> 16 ); unsigned char b = (unsigned char)( ( color & 0x0000ff00 ) >> 8 ); for( int y = 0; y < m_height; ++y ) { for( int x = 0; x < m_width; ++x ) { float alpha = 1.0f; #ifdef MONKY_FRESHNESS_MAP alpha = 1.0f - (float)getMapTile( x, y ).lastTurnUpdated / (float)m_currentTurn; #endif #ifdef MONKY_DEATH_MAP alpha = 1.0f - (float)getMapTile( x, y ).numAgentsKilledInTile / (float)m_maxAgentKillCountInSingleTile; #endif #ifdef MONKY_ENEMY_SEEN_MAP alpha = 1.0f - (float)getMapTile( x, y ).enemyAgentsSeenInThisTile / (float)m_maxEnemySeenCountInSingleTile; #endif glColor4f( r/255.0f, g/255.0f, b/255.0f, alpha ); if( alpha < 1.0f ) int x = 5 + 3; glBegin( GL_QUADS ); { glVertex2f( x - 0.5f, y - 0.5f ); glVertex2f( x - 0.5f, y + 0.5f ); glVertex2f( x + 0.5f, y + 0.5f ); glVertex2f( x + 0.5f, y - 0.5f ); } glEnd(); if( getMapTile( x, y ).isClaimed ) { glColor4f( 0, 0, 1.0f, 1.0f ); glBegin( GL_LINE_LOOP ); { glVertex2f( x - 0.5f, y - 0.5f ); glVertex2f( x - 0.5f, y + 0.5f ); glVertex2f( x + 0.5f, y + 0.5f ); glVertex2f( x + 0.5f, y - 0.5f ); glVertex2f( x - 0.5f, y - 0.5f ); } glEnd(); } } } }
void Engine::drawMap() { for(int i = 0; i < m_CurrentMap->getDimensions().y; i++) { for(int n = 0; n < m_CurrentMap->getDimensions().x; n++) { MapTile *ttile = getMapTile( m_CurrentMap->getTile(n, i)); if(posInViewport(n, i)) { if( inFOV(m_Player->getPosition().x, m_Player->getPosition().y, n, i) ) { drawTileInViewport(n, i, ttile->getTileID(), ttile->getFGColor(), ttile->getBGColor()); if(!m_CurrentMap->tileExplored(n,i)) m_CurrentMap->setExplored(n, i, true); } else if( m_CurrentMap->tileExplored(n, i) ) drawTileInViewport(n, i, ttile->getTileID(), SFC_WHITE, SFC_BLACK); } } } }
void Map::draw() { for (int x = 0; x < MAP_WIDTH; x++) { for (int y = 0; y < MAP_HEIGHT; y++) { Tile *t = getMapTile(x,y); int drawX = cam.getMapDrawX(x); int drawY = cam.getMapDrawY(y); if (!t->drawMe()) { continue; } if (!t->isVisible()) { if (t->alpha > 128) t->alpha -= FOG_FADE_SPEED; // if (t->alpha < 128) continue; } if (!inFOV(x, y, zFocus)) continue; // if (z != zFocus) continue; //if (z < zFocus) continue; if (t->isVisible()) t->alpha += FOG_FADE_SPEED; // if (t->alpha < 255) { // boxRGBA(screen, drawX, drawY, 32, 32, 0, 0, 0, 255); // } boxRGBA(screen, drawX, drawY, drawX+31, drawY+31, 0, 0, 0, 255); drawtile(0, t->getGridX(), t->getGridY(), drawX, drawY, 0, false, t->alpha); } } }
//------------------------------------------------------------ float ArenaMap::getGCostToEnterTile( EntityType entityType, int x, int y ) const { MapTile tile = getMapTile( x, y ); float gCost = tile.gCostToEnterTile; float battleCost = 0.0f; float enemySightingCost = 0.0f; if( m_maxAgentKillCountInSingleTile > 0 ) battleCost = (float)tile.numAgentsKilledInTile / m_maxAgentKillCountInSingleTile; if( m_maxEnemySeenCountInSingleTile > 0 ) enemySightingCost = (float)tile.numAgentsKilledInTile / m_maxEnemySeenCountInSingleTile; switch( entityType ) { case ENTITY_TYPE_QUEEN: gCost = tile.gCostToEnterTileForQueen + 10.0f*battleCost + 10.0f*enemySightingCost; break; case ENTITY_TYPE_SCOUT: if( m_currentTurn > 0 ) gCost = tile.gCostToEnterTileForScout - ( 1.0f - tile.lastTurnUpdated / m_currentTurn ) + battleCost; break; case ENTITY_TYPE_SOLDIER: gCost = tile.gCostToEnterTileForSoldier - battleCost - enemySightingCost; break; case ENTITY_TYPE_WORKER: gCost = tile.gCostToEnterTileForWorker + battleCost + enemySightingCost; break; } return gCost; }
//------------------------------------------------------------ void ArenaMap::addAgentKilledToTile( int x, int y ) { MapTile tile = getMapTile( x, y ); ++tile.numAgentsKilledInTile; if( tile.numAgentsKilledInTile > m_maxAgentKillCountInSingleTile ) m_maxAgentKillCountInSingleTile = tile.numAgentsKilledInTile; }
bool Engine::validWalkableTile(MapChunk *tmap, int x, int y) { if(tmap == NULL) return false; sf::Vector2i tpos(x,y); //check that tile is within map dimensions sf::Vector2i mapdim = tmap->getDimensions(); if(x < 0 || y < 0 || x >= mapdim.x || y >= mapdim.y) return false; //check that tile is walkable MapTile *ttile = getMapTile( tmap->getTile(x,y) ); if(!ttile->isWalkable()) return false; //check that there are no actors there std::vector<Monster*> *actors = tmap->getMapMonsters(); for(int i = 0; i < int(actors->size()); i++) { if((*actors)[i]->getPosition() == tpos) return false; } //check if player is there if( m_Player->getPosition() == tpos) return false; return true; }
void Map::resetVisibility() { for (int z = 0; z < MAP_DEPTH; z++) { for (int x = 0; x < MAP_WIDTH; x++) { for (int y = 0; y < MAP_HEIGHT; y++) { Tile *t = getMapTile(x, y, z); t->setVisible(false); } } } }
//------------------------------------------------------------ void ArenaMap::updateEnemySightingsHeatMap( const ObservedEntities& entities ) { for( int i = 0; i < entities.m_numberOfObservedEntities; ++i ) { TileCoords entityLoc = TileCoords( entities.m_entities[i].m_positionX, entities.m_entities[i].m_positionY ); MapTile& tile = getMapTile( entityLoc.x, entityLoc.y ); ++tile.enemyAgentsSeenInThisTile; if( tile.enemyAgentsSeenInThisTile > m_maxEnemySeenCountInSingleTile ) m_maxEnemySeenCountInSingleTile = tile.enemyAgentsSeenInThisTile; } }
//---------------------------------------------------------------------- bool ArenaMap::checkTileForNutrient( const TileCoords& pos ) const { bool found = false; if( isInMap( pos.x, pos.y ) ) { const MapTile& tile = getMapTile( pos.x, pos.y ); if( tile.tileMaterial == ARENA_SQUARE_TYPE_FOOD && !tile.isClaimed ) { found = true; } } return found; }
void Type::setBorderTiles(const PointVec<uint32>& tiles, REVERT::BrushRevert& revert) { for (auto pos : tiles) { try { auto newTileInfo = m_Layer.getMapTile(pos); revert.addTile(newTileInfo); newTileInfo.getMapTile().m_uiTileID = static_cast<DATABASE::PROTOTYPE::TILE_INDEX>(database::prototype::AutoTile::getAutoTileIndexForTileCheck(m_Layer.checkAutoTile(pos))); m_Layer.setMapTile(newTileInfo); } catch (const MAP::EXCEPTION::TileException&) {} } }
//------------------------------------------------------------ float ArenaMap::getCurrentGValueForTile( int x, int y ) const { return getMapTile( x, y ).currentGCost; }
void Map::setTileGrid(int x, int y, int z, int gridX, int gridY) { Tile *t = getMapTile(x, y, z); t->setGridX(gridX); t->setGridY(gridY); t->setDraw(true); }
//------------------------------------------------------------ OrderCode ArenaMap::getMoveOrderToGetToTileForCurentPath( int x, int y ) const { return getMapTile( x, y ).moveOrderToGetToTileForCurrentPath; }
//------------------------------------------------------------ void ArenaMap::setMoveOrderToGetToTileForCurrentPath( int x, int y, OrderCode order ) { getMapTile( x, y ).moveOrderToGetToTileForCurrentPath = order; }
//------------------------------------------------------------ void ArenaMap::setCurrentFValue( int x, int y, float f ) { getMapTile( x, y ).currentF = f; }
//------------------------------------------------------------ float ArenaMap::getCurrentFValue( int x, int y ) const { return getMapTile( x, y ).currentF; }
//------------------------------------------------------------ void ArenaMap::setLastAIPathOpenedOn( int x, int y, int lastAIPath ) { getMapTile( x, y ).lastAIPathOpenedOn = lastAIPath; }
//------------------------------------------------------------ int ArenaMap::getLastAIPathOpenedOn( int x, int y ) const { return getMapTile( x, y ).lastAIPathOpenedOn; }
// create some cool map or something void Map::init() { for (int z = 0; z < 2; z++) { for (int x = 0; x < 128; x++) { for (int y = 0; y < 128; y++) { Tile *t = getMapTile(x, y, z); if (x > 10 && x < 20) { t->setDraw(true); t->setPassable(true); t->setGridX(getRandomInt(2, 3)); t->setGridY(getRandomInt(2, 4)); } } } for (int x = 0; x < 128; x++) { for (int y = 0; y < 128; y++) { Tile *t = getMapTile(x, y, z); if (y > 10 && y < 20) { t->setDraw(true); t->setPassable(true); t->setGridX(getRandomInt(2, 3)); t->setGridY(getRandomInt(2, 4)); } } } } setTileGrid(0, 10, 0, 0, 8); setTilePassable(0,10, 0, false); setTileGrid(1, 10, 0, 0, 8); setTilePassable(1,10, 0, false); setTileGrid(2, 10, 0, 0, 8); setTilePassable(2,10, 0, false); setTileGrid(0, 30, 0, 0, 8); setTilePassable(0,30, 0, false); setTileGrid(1, 30, 0, 0, 8); setTilePassable(1,30, 0, false); setTileGrid(2, 30, 0, 0, 8); setTilePassable(2,30, 0, false); // crate setTileGrid(10, 7, 0, 0, 0); setTilePassable(10,7, 0, false); setTileGrid(11, 7, 0, 0, 0); setTilePassable(11,7, 0, false); setTileGrid(10, 8, 0, 0, 0); setTilePassable(10,8, 0, false); setTileGrid(11, 8, 0, 0, 0); setTilePassable(11,8, 0, false); // crate setTileGrid(20, 13, 0, 0, 0); setTilePassable(20, 13, 0, false); setTileGrid(21, 13, 0, 0, 0); setTilePassable(20, 13, 0, false); setTileGrid(20, 14, 0, 0, 0); setTilePassable(20,14, 0, false); setTileGrid(21, 14, 0, 0, 0); setTilePassable(20,14, 0, false); }
void Map::setTilePassable(int x, int y, int z, bool passable) { Tile *t = getMapTile(x, y, z); t->setPassable(passable); }
//------------------------------------------------------------ void ArenaMap::setCurrentGValueForTile( int x, int y, float g ) { getMapTile( x, y ).currentGCost = g; }
SDL_Surface* CnCMap::getMiniMap(Uint8 pixsize) { static ImageProc ip; SDL_Rect pos = {0, 0, pixsize, pixsize}; SDL_Surface *cminitile; if (pixsize == 0) { // Argh logger->error("CnCMap::getMiniMap: pixsize is zero, resetting to one\n"); pixsize = 1; } if(minimap != NULL) { if (minimap->w == width*pixsize) { return minimap; } else { // Each minimap surface is about 250k, so caching a lot of zooms // would be somewhat expensive. Could make how much memory to set aside // for this customizable so people with half a gig of RAM can see some // usage :-) // For now, just keep the previous one. SDL_FreeSurface(oldmmap); oldmmap = minimap; minimap = NULL; } } if (oldmmap != NULL && (oldmmap->w == pixsize*width)) { minimap = oldmmap; oldmmap = NULL; return minimap; } minimap = SDL_CreateRGBSurface (SDL_SWSURFACE, width*pixsize,height*pixsize, 16, 0xff, 0xff, 0xff, 0); SDL_Surface *maptileOne = getMapTile(0); minimap->format->Rmask = maptileOne->format->Rmask; minimap->format->Gmask = maptileOne->format->Gmask; minimap->format->Bmask = maptileOne->format->Bmask; minimap->format->Amask = maptileOne->format->Amask; if( maptileOne->format->palette != NULL ) { SDL_SetColors(minimap, maptileOne->format->palette->colors, 0, maptileOne->format->palette->ncolors); } int lineCounter = 0; for(Uint32 i = 0; i < (Uint32) width*height; i++, pos.x += pixsize, lineCounter++) { if(lineCounter == width) { pos.y += pixsize; pos.x = 0; lineCounter = 0; } cminitile = ip.minimapScale(getMapTile(i), pixsize); SDL_BlitSurface(cminitile, NULL, minimap, &pos); SDL_FreeSurface(cminitile); } /* Now fill in clipping details for renderer and UI. * To make things easier, ensure that the geometry is divisable by the * specified width and height. */ Uint16 tx = min(miniclip.sidew, (Uint16)minimap->w); Uint16 ty = min(tx, (Uint16)minimap->h); // w == width in pixels of the minimap miniclip.w = pixsize*(int)floor((double)tx/(double)pixsize); miniclip.h = pixsize*(int)floor((double)ty/(double)pixsize); // x == offset in pixels from the top-left hand corner of the sidebar under // the tab. miniclip.x = abs(miniclip.sidew-miniclip.w)/2+20; miniclip.y = abs(miniclip.sidew-miniclip.h)/2+5; // Tilew == number of tiles visible in minimap horizontally miniclip.tilew = miniclip.w/pixsize; miniclip.tileh = miniclip.h/pixsize; // pixsize == number of pixels wide and high a minimap tile is miniclip.pixsize = pixsize; return minimap; }