void ViewIndex::insert(ViewObject obj) { PROFILE; int ind = objIndex[int(obj.layer())]; if (ind < 100) objects[ind] = std::move(obj); else { objIndex[int(obj.layer())] = objects.size(); objects.push_back(std::move(obj)); } }
void MapGui::drawObjectAbs(Renderer& renderer, int x, int y, const ViewObject& object, int sizeX, int sizeY, Vec2 tilePos) { if (object.hasModifier(ViewObject::Modifier::PLAYER)) { renderer.drawFilledRectangle(x, y, x + sizeX, y + sizeY, Color::Transparent, colors[ColorId::LIGHT_GRAY]); } if (object.hasModifier(ViewObject::Modifier::DRAW_MORALE)) drawMorale(renderer, Rectangle(x, y, x + sizeX, y + sizeY), object.getAttribute(ViewObject::Attribute::MORALE)); if (object.hasModifier(ViewObject::Modifier::TEAM_HIGHLIGHT)) { renderer.drawFilledRectangle(x, y, x + sizeX, y + sizeY, Color::Transparent, colors[ColorId::DARK_GREEN]); } const Tile& tile = Tile::getTile(object, spriteMode); Color color = Renderer::getBleedingColor(object); if (object.hasModifier(ViewObject::Modifier::INVISIBLE) || object.hasModifier(ViewObject::Modifier::HIDDEN)) color = transparency(color, 70); else if (tile.translucent > 0) color = transparency(color, 255 * (1 - tile.translucent)); else if (object.hasModifier(ViewObject::Modifier::ILLUSION)) color = transparency(color, 150); if (object.hasModifier(ViewObject::Modifier::PLANNED)) color = transparency(color, 100); double waterDepth = object.getAttribute(ViewObject::Attribute::WATER_DEPTH); if (waterDepth > 0) { int val = max(0.0, 255.0 - min(2.0, waterDepth) * 60); color = Color(val, val, val); } if (tile.hasSpriteCoord()) { Vec2 move; Vec2 sz = Renderer::tileSize[tile.getTexNum()]; Vec2 off = (Renderer::nominalSize - sz).mult(Vec2(sizeX, sizeY)).div(Renderer::nominalSize * 2); int width = sz.x * sizeX / Renderer::nominalSize.x; int height = sz.y* sizeY / Renderer::nominalSize.y; if (sz.y > Renderer::nominalSize.y) off.y *= 2; EnumSet<Dir> dirs; EnumSet<Dir> borderDirs; if (!object.hasModifier(ViewObject::Modifier::PLANNED)) if (auto connectionId = getConnectionId(object)) for (Vec2 dir : getConnectionDirs(object.id())) { if (tileConnects(*connectionId, tilePos + dir)) dirs.insert(dir.getCardinalDir()); else borderDirs.insert(dir.getCardinalDir()); } Vec2 coord = tile.getSpriteCoord(dirs); if (object.hasModifier(ViewObject::Modifier::MOVE_UP)) move.y = -4* sizeY / Renderer::nominalSize.y; if ((object.layer() == ViewLayer::CREATURE && object.id() != ViewId::BOULDER) || object.hasModifier(ViewObject::Modifier::ROUND_SHADOW)) { renderer.drawSprite(x, y - 2, 2 * Renderer::nominalSize.x, 22 * Renderer::nominalSize.y, Renderer::nominalSize.x, Renderer::nominalSize.y, Renderer::tiles[0], min(Renderer::nominalSize.x, width), min(Renderer::nominalSize.y, height)); move.y = -4* sizeY / Renderer::nominalSize.y; } if (auto background = tile.getBackgroundCoord()) { renderer.drawSprite(x + off.x, y + off.y, background->x * sz.x, background->y * sz.y, sz.x, sz.y, Renderer::tiles[tile.getTexNum()], width, height, color); if (shadowed.count(tilePos)) renderer.drawSprite(x, y, 1 * Renderer::nominalSize.x, 21 * Renderer::nominalSize.y, Renderer::nominalSize.x, Renderer::nominalSize.y, Renderer::tiles[5], width, height); } if (coord.x < 0) return; if (auto dir = object.getAttachmentDir()) move = getAttachmentOffset(*dir, width, height); renderer.drawSprite(x + off.x + move.x, y + move.y + off.y, coord.x * sz.x, coord.y * sz.y, sz.x, sz.y, Renderer::tiles[tile.getTexNum()], width, height, color); if (tile.hasCorners()) { for (Vec2 coord : tile.getCornerCoords(dirs)) renderer.drawSprite(x + off.x + move.x, y + move.y + off.y, coord.x * sz.x, coord.y * sz.y, sz.x, sz.y, Renderer::tiles[tile.getTexNum()], width, height, color); } if (tile.floorBorders) { drawFloorBorders(renderer, borderDirs, x, y); } if (contains({ViewLayer::FLOOR, ViewLayer::FLOOR_BACKGROUND}, object.layer()) && shadowed.count(tilePos) && !tile.noShadow) renderer.drawSprite(x, y, 1 * Renderer::nominalSize.x, 21 * Renderer::nominalSize.y, Renderer::nominalSize.x, Renderer::nominalSize.y, Renderer::tiles[5], width, height); if (object.getAttribute(ViewObject::Attribute::BURNING) > 0) { renderer.drawSprite(x, y, Random.get(10, 12) * Renderer::nominalSize.x, 0 * Renderer::nominalSize.y, Renderer::nominalSize.x, Renderer::nominalSize.y, Renderer::tiles[2], width, height); } if (object.hasModifier(ViewObject::Modifier::LOCKED)) renderer.drawSprite(x + (Renderer::nominalSize.x - Renderer::tileSize[3].x) / 2, y, 5 * Renderer::tileSize[3].x, 6 * Renderer::tileSize[3].y, Renderer::tileSize[3].x, Renderer::tileSize[3].y, Renderer::tiles[3], width / 2, height / 2); } else { renderer.drawText(tile.symFont ? Renderer::SYMBOL_FONT : Renderer::TILE_FONT, sizeY, Tile::getColor(object), x + sizeX / 2, y - 3, tile.text, true); double burningVal = object.getAttribute(ViewObject::Attribute::BURNING); if (burningVal > 0) { renderer.drawText(Renderer::SYMBOL_FONT, sizeY, getFireColor(), x + sizeX / 2, y - 3, L'ѡ', true); if (burningVal > 0.5) renderer.drawText(Renderer::SYMBOL_FONT, sizeY, getFireColor(), x + sizeX / 2, y - 3, L'Ѡ', true); } } }
void MapGui::drawObjectAbs(Renderer& renderer, Vec2 pos, const ViewObject& object, Vec2 size, Vec2 tilePos, int curTimeReal, const EnumMap<HighlightType, double>& highlightMap) { const Tile& tile = Tile::getTile(object.id(), spriteMode); Color color = Renderer::getBleedingColor(object); if (object.hasModifier(ViewObject::Modifier::INVISIBLE) || object.hasModifier(ViewObject::Modifier::HIDDEN)) color = transparency(color, 70); else if (tile.translucent > 0) color = transparency(color, 255 * (1 - tile.translucent)); else if (object.hasModifier(ViewObject::Modifier::ILLUSION)) color = transparency(color, 150); if (object.hasModifier(ViewObject::Modifier::PLANNED)) color = transparency(color, 100); double waterDepth = object.getAttribute(ViewObject::Attribute::WATER_DEPTH); if (waterDepth > 0) { int val = max(0.0, 255.0 - min(2.0, waterDepth) * 60); color = Color(val, val, val); } if (spriteMode && tile.hasSpriteCoord()) { DirSet dirs; DirSet borderDirs; if (auto connectionId = getConnectionId(object)) for (Vec2 dir : getConnectionDirs(object.id())) { if ((tilePos + dir).inRectangle(levelBounds) && connectionMap.has(tilePos + dir, *connectionId)) dirs.insert(dir.getCardinalDir()); else borderDirs.insert(dir.getCardinalDir()); } Vec2 move; Vec2 movement = getMovementOffset(object, size, currentTimeGame, curTimeReal); drawCreatureHighlights(renderer, object, pos + movement, size, curTimeReal); if ((object.layer() == ViewLayer::CREATURE && object.id() != ViewId::BOULDER) || object.hasModifier(ViewObject::Modifier::ROUND_SHADOW)) { static auto coord = renderer.getTileCoord("round_shadow"); renderer.drawTile(pos + movement, coord, size, sf::Color(255, 255, 255, 160)); move.y = -4* size.y / renderer.getNominalSize().y; } static auto shortShadow = renderer.getTileCoord("short_shadow"); if (auto background = tile.getBackgroundCoord()) { renderer.drawTile(pos, *background, size, color); if (shadowed.count(tilePos)) renderer.drawTile(pos, shortShadow, size, sf::Color(255, 255, 255, 170)); } if (auto dir = object.getAttachmentDir()) move = getAttachmentOffset(*dir, size); move += movement; if (mirrorSprite(object.id())) renderer.drawTile(pos + move, tile.getSpriteCoord(dirs), size, color, object.getPositionHash() % 2, object.getPositionHash() % 4 > 1); else renderer.drawTile(pos + move, tile.getSpriteCoord(dirs), size, color); if (object.layer() == ViewLayer::FLOOR && highlightMap[HighlightType::CUT_TREE] > 0) if (auto coord = tile.getHighlightCoord()) renderer.drawTile(pos + move, *coord, size, color); if (!buttonViewId) if (auto id = object.getCreatureId()) creatureMap.push_back(CreatureInfo{Rectangle(pos + move, pos + move + size), *id, object.id()}); if (tile.hasCorners()) { for (auto coord : tile.getCornerCoords(dirs)) renderer.drawTile(pos + move, coord, size, color); } /* if (tile.floorBorders) { drawFloorBorders(renderer, borderDirs, x, y); }*/ if ((object.layer() == ViewLayer::FLOOR || object.layer() == ViewLayer::FLOOR_BACKGROUND) && shadowed.count(tilePos) && !tile.noShadow) renderer.drawTile(pos, shortShadow, size, sf::Color(255, 255, 255, 170)); if (object.getAttribute(ViewObject::Attribute::BURNING) > 0) { static auto fire1 = renderer.getTileCoord("fire1"); static auto fire2 = renderer.getTileCoord("fire2"); renderer.drawTile(pos, Random.choose({fire1, fire2}), size); } static auto key = renderer.getTileCoord("key"); if (object.hasModifier(ViewObject::Modifier::LOCKED)) renderer.drawTile(pos, key, size); } else { Vec2 movement = getMovementOffset(object, size, currentTimeGame, curTimeReal); Vec2 tilePos = pos + movement + Vec2(size.x / 2, -3); drawCreatureHighlights(renderer, object, pos, size, curTimeReal); renderer.drawText(tile.symFont ? Renderer::SYMBOL_FONT : Renderer::TILE_FONT, size.y, Tile::getColor(object), tilePos.x, tilePos.y, tile.text, Renderer::HOR); if (!buttonViewId) if (auto id = object.getCreatureId()) creatureMap.push_back(CreatureInfo{Rectangle(tilePos, tilePos + size), *id, object.id()}); double burningVal = object.getAttribute(ViewObject::Attribute::BURNING); if (burningVal > 0) { renderer.drawText(Renderer::SYMBOL_FONT, size.y, getFireColor(), pos.x + size.x / 2, pos.y - 3, L'ѡ', Renderer::HOR); if (burningVal > 0.5) renderer.drawText(Renderer::SYMBOL_FONT, size.y, getFireColor(), pos.x + size.x / 2, pos.y - 3, L'Ѡ', Renderer::HOR); } } }