| 220 | } |
| 221 | |
| 222 | sp<RGBImage> BaseGraphics::drawMinimap(sp<GameState> state, const Building &selected) |
| 223 | { |
| 224 | // FIXME: add city ref to building |
| 225 | auto city = state->cities["CITYMAP_HUMAN"]; |
| 226 | auto minimap = mksp<RGBImage>(Vec2<unsigned int>{100, 100}); |
| 227 | RGBImageLock l(minimap); |
| 228 | |
| 229 | // Offset for 'endless grass' outside of city borders |
| 230 | static Vec2<int> offset(20, 20); |
| 231 | |
| 232 | // Draw the city tiles |
| 233 | std::map<Vec2<int>, int> minimap_z; |
| 234 | for (auto &pair : city->initial_tiles) |
| 235 | { |
| 236 | auto &pos = pair.first; |
| 237 | auto &tile = pair.second; |
| 238 | if (pos.x < offset.x || pos.x > city->size.x - offset.x || pos.y < offset.y || |
| 239 | pos.y > city->size.y - offset.y) |
| 240 | continue; |
| 241 | |
| 242 | Vec2<int> pos2d = {pos.x - offset.x, pos.y - offset.y}; |
| 243 | auto it = minimap_z.find(pos2d); |
| 244 | if (it == minimap_z.end() || it->second < pos.z) |
| 245 | { |
| 246 | if (tile->minimap_colour.a == 0) |
| 247 | continue; |
| 248 | minimap_z[pos2d] = pos.z; |
| 249 | l.set(pos2d, tile->minimap_colour); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // Draw all bases as yellow blocks |
| 254 | for (auto &pair : state->player_bases) |
| 255 | { |
| 256 | auto &base = pair.second; |
| 257 | for (int y = base->building->bounds.p0.y; y < base->building->bounds.p1.y; y++) |
| 258 | { |
| 259 | for (int x = base->building->bounds.p0.x; x < base->building->bounds.p1.x; x++) |
| 260 | { |
| 261 | l.set({x - offset.x, y - offset.y}, {255, 255, 0, 255}); |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // Draw the current base as a red block |
| 267 | for (int y = selected.bounds.p0.y; y < selected.bounds.p1.y; y++) |
| 268 | { |
| 269 | for (int x = selected.bounds.p0.x; x < selected.bounds.p1.x; x++) |
| 270 | { |
| 271 | l.set({x - offset.x, y - offset.y}, {255, 0, 0, 255}); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | return minimap; |
| 276 | } |
| 277 | |
| 278 | }; // namespace OpenApoc |