| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#include "automap.h" |
| 50 |
|
| 51 |
#include <stdio.h> |
| 52 |
#include <string.h> |
| 53 |
|
| 54 |
#include "actors.h" |
| 55 |
#include "config.h" |
| 56 |
#include "draw/draw.h" |
| 57 |
#include "draw/draw_actor.h" |
| 58 |
#include "draw/drawtools.h" |
| 59 |
#include "font.h" |
| 60 |
#include "gamedata.h" |
| 61 |
#include "map.h" |
| 62 |
#include "mission.h" |
| 63 |
#include "objs.h" |
| 64 |
#include "pic_manager.h" |
| 65 |
#include "pickup.h" |
| 66 |
|
| 67 |
#define MAP_SCALE_DEFAULT 2 |
| 68 |
#define MASK_ALPHA 128; |
| 69 |
|
| 70 |
color_t colorWall = {72, 152, 72, 255}; |
| 71 |
color_t colorFloor = {12, 92, 12, 255}; |
| 72 |
color_t colorRoom = {24, 112, 24, 255}; |
| 73 |
color_t colorExit = {255, 255, 255, 255}; |
| 74 |
|
| 75 |
static void DisplayPlayer( |
| 76 |
SDL_Renderer *renderer, const TActor *player, struct vec2i pos, |
| 77 |
const int scale) |
| 78 |
{ |
| 79 |
const struct vec2i playerPos = Vec2ToTile(player->thing.Pos); |
| 80 |
pos = svec2i_add(pos, svec2i_scale(playerPos, (float)scale)); |
| 81 |
if (scale >= 2) |
| 82 |
{ |
| 83 |
DrawHead(renderer, ActorGetCharacter(player), DIRECTION_DOWN, pos); |
| 84 |
} |
| 85 |
else |
| 86 |
{ |
| 87 |
DrawPoint(pos, colorWhite); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
static void DisplayObjective( |
| 92 |
Thing *t, int objectiveIndex, struct vec2i pos, int scale, int flags) |
| 93 |
{ |
| 94 |
const struct vec2i objectivePos = Vec2ToTile(t->Pos); |
| 95 |
const Objective *o = |
| 96 |
CArrayGet(&gMission.missionData->Objectives, objectiveIndex); |
| 97 |
color_t color = o->color; |
| 98 |
pos = svec2i_add(pos, svec2i_scale(objectivePos, (float)scale)); |
| 99 |
if (flags & AUTOMAP_FLAGS_MASK) |
| 100 |
{ |
| 101 |
color.a = MASK_ALPHA; |
| 102 |
} |
| 103 |
if (scale >= 2) |
| 104 |
{ |
| 105 |
DrawCross(&gGraphicsDevice, pos, color); |
| 106 |
} |
| 107 |
else |
| 108 |
{ |
| 109 |
DrawPoint(pos, color); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
static void DisplayExits( |
| 114 |
const Map *m, const struct vec2i pos, const int scale, const int flags) |
| 115 |
{ |
| 116 |
CA_FOREACH(const Exit, e, m->exits) |
| 117 |
if (e->Hidden) |
| 118 |
continue; |
| 119 |
const struct vec2i exitPos = |
| 120 |
svec2i_add(svec2i_scale(e->R.Pos, (float)scale), pos); |
| 121 |
const struct vec2i exitSize = svec2i_scale(e->R.Size, (float)scale); |
| 122 |
|
| 123 |
color_t color = colorExit; |
| 124 |
if (flags & AUTOMAP_FLAGS_MASK) |
| 125 |
{ |
| 126 |
color.a = MASK_ALPHA; |
| 127 |
} |
| 128 |
DrawRectangle(&gGraphicsDevice, exitPos, exitSize, color, false); |
| 129 |
CA_FOREACH_END() |
| 130 |
} |
| 131 |
|
| 132 |
static void DisplaySummary(void) |
| 133 |
{ |
| 134 |
char sScore[20]; |
| 135 |
struct vec2i pos; |
| 136 |
pos.y = gGraphicsDevice.cachedConfig.Res.y - 5 - FontH(); |
| 137 |
|
| 138 |
CA_FOREACH(const Objective, o, gMission.missionData->Objectives) |
| 139 |
if (ObjectiveIsRequired(o) || o->done > 0) |
| 140 |
{ |
| 141 |
color_t textColor = colorWhite; |
| 142 |
pos.x = 5; |
| 143 |
|
| 144 |
DrawRectangle( |
| 145 |
&gGraphicsDevice, svec2i(pos.x, pos.y + 3), svec2i(2, 2), o->color, |
| 146 |
false); |
| 147 |
|
| 148 |
pos.x += 5; |
| 149 |
|
| 150 |
sprintf(sScore, "(%d)", o->done); |
| 151 |
|
| 152 |
if (!ObjectiveIsRequired(o)) |
| 153 |
{ |
| 154 |
textColor = colorPurple; |
| 155 |
} |
| 156 |
else if (ObjectiveIsComplete(o)) |
| 157 |
{ |
| 158 |
textColor = colorRed; |
| 159 |
} |
| 160 |
pos = FontStrMask(o->Description, pos, textColor); |
| 161 |
pos.x += 5; |
| 162 |
FontStrMask(sScore, pos, textColor); |
| 163 |
pos.y -= (FontH() + 1); |
| 164 |
} |
| 165 |
CA_FOREACH_END() |
| 166 |
} |
| 167 |
|
| 168 |
static color_t DoorColor(const int x, const int y) |
| 169 |
{ |
| 170 |
const int l = MapGetDoorKeycardFlag(&gMap, svec2i(x, y)); |
| 171 |
return KeyColor(l); |
| 172 |
} |
| 173 |
|
| 174 |
void DrawDot(Thing *t, color_t color, struct vec2i pos, int scale) |
| 175 |
{ |
| 176 |
const struct vec2i dotPos = Vec2ToTile(t->Pos); |
| 177 |
pos = svec2i_add(pos, svec2i_scale(dotPos, (float)scale)); |
| 178 |
DrawRectangle(&gGraphicsDevice, pos, svec2i(scale, scale), color, false); |
| 179 |
} |
| 180 |
|
| 181 |
static void DrawMap( |
| 182 |
Map *map, struct vec2i center, struct vec2i centerOn, struct vec2i size, |
| 183 |
int scale, int flags) |
| 184 |
{ |
| 185 |
int x, y; |
| 186 |
struct vec2i mapPos = |
| 187 |
svec2i_add(center, svec2i_scale(centerOn, (float)-scale)); |
| 188 |
for (y = 0; y < gMap.Size.y; y++) |
| 189 |
{ |
| 190 |
int i; |
| 191 |
for (i = 0; i < scale; i++) |
| 192 |
{ |
| 193 |
for (x = 0; x < gMap.Size.x; x++) |
| 194 |
{ |
| 195 |
Tile *tile = MapGetTile(map, svec2i(x, y)); |
| 196 |
if (tile->Class->Pic != NULL && |
| 197 |
(tile->isVisited || (flags & AUTOMAP_FLAGS_SHOWALL))) |
| 198 |
{ |
| 199 |
int j; |
| 200 |
for (j = 0; j < scale; j++) |
| 201 |
{ |
| 202 |
struct vec2i drawPos = svec2i( |
| 203 |
mapPos.x + x * scale + j, |
| 204 |
mapPos.y + y * scale + i); |
| 205 |
color_t color = colorTransparent; |
| 206 |
switch (tile->Class->Type) |
| 207 |
{ |
| 208 |
case TILE_CLASS_WALL: |
| 209 |
color = colorWall; |
| 210 |
break; |
| 211 |
case TILE_CLASS_DOOR: |
| 212 |
color = DoorColor(x, y); |
| 213 |
break; |
| 214 |
case TILE_CLASS_FLOOR: |
| 215 |
color = |
| 216 |
tile->Class->IsRoom ? colorRoom : colorFloor; |
| 217 |
break; |
| 218 |
default: |
| 219 |
CASSERT(false, "Unknown tile class type"); |
| 220 |
break; |
| 221 |
} |
| 222 |
if (!ColorEquals(color, colorTransparent)) |
| 223 |
{ |
| 224 |
if (flags & AUTOMAP_FLAGS_MASK) |
| 225 |
{ |
| 226 |
color.a = MASK_ALPHA; |
| 227 |
} |
| 228 |
DrawPoint(drawPos, color); |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
if (flags & AUTOMAP_FLAGS_MASK) |
| 236 |
{ |
| 237 |
const color_t color = {255, 255, 255, 128}; |
| 238 |
DrawRectangle( |
| 239 |
&gGraphicsDevice, |
| 240 |
svec2i_subtract(center, svec2i_scale_divide(size, 2)), size, color, |
| 241 |
false); |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
static void DrawThing( |
| 246 |
Thing *t, Tile *tile, struct vec2i pos, int scale, int flags); |
| 247 |
static void DrawObjectivesAndKeys( |
| 248 |
Map *map, struct vec2i pos, int scale, int flags) |
| 249 |
{ |
| 250 |
for (int y = 0; y < map->Size.y; y++) |
| 251 |
{ |
| 252 |
for (int x = 0; x < map->Size.x; x++) |
| 253 |
{ |
| 254 |
Tile *tile = MapGetTile(map, svec2i(x, y)); |
| 255 |
CA_FOREACH(ThingId, tid, tile->things) |
| 256 |
DrawThing(ThingIdGetThing(tid), tile, pos, scale, flags); |
| 257 |
CA_FOREACH_END() |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
static void DrawThing( |
| 262 |
Thing *t, Tile *tile, struct vec2i pos, int scale, int flags) |
| 263 |
{ |
| 264 |
if ((t->flags & THING_OBJECTIVE) != 0) |
| 265 |
{ |
| 266 |
const int obj = ObjectiveFromThing(t->flags); |
| 267 |
const Objective *o = CArrayGet(&gMission.missionData->Objectives, obj); |
| 268 |
if (!(o->Flags & OBJECTIVE_HIDDEN) || (flags & AUTOMAP_FLAGS_SHOWALL)) |
| 269 |
{ |
| 270 |
if ((o->Flags & OBJECTIVE_POSKNOWN) || tile->isVisited || |
| 271 |
(flags & AUTOMAP_FLAGS_SHOWALL)) |
| 272 |
{ |
| 273 |
DisplayObjective(t, obj, pos, scale, flags); |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
else if (t->kind == KIND_PICKUP && tile->isVisited) |
| 278 |
{ |
| 279 |
const Pickup *p = CArrayGet(&gPickups, t->id); |
| 280 |
const int keyFlags = PickupClassGetKeys(p->class); |
| 281 |
if (keyFlags != 0) |
| 282 |
{ |
| 283 |
const color_t dotColor = KeyColor(keyFlags); |
| 284 |
DrawDot(t, dotColor, pos, scale); |
| 285 |
} |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
void AutomapDraw( |
| 290 |
GraphicsDevice *g, SDL_Renderer *renderer, const int flags, |
| 291 |
const bool showExit) |
| 292 |
{ |
| 293 |
if (renderer == NULL) |
| 294 |
{ |
| 295 |
renderer = g->gameWindow.renderer; |
| 296 |
} |
| 297 |
struct vec2i mapCenter = |
| 298 |
svec2i(g->cachedConfig.Res.x / 2, g->cachedConfig.Res.y / 2); |
| 299 |
struct vec2i centerOn = svec2i(gMap.Size.x / 2, gMap.Size.y / 2); |
| 300 |
|
| 301 |
int mapScale = MAP_SCALE_DEFAULT; |
| 302 |
|
| 303 |
if (gMap.Size.x * mapScale > g->cachedConfig.Res.x || |
| 304 |
gMap.Size.y * mapScale > g->cachedConfig.Res.y) |
| 305 |
{ |
| 306 |
mapScale--; |
| 307 |
} |
| 308 |
struct vec2i pos = |
| 309 |
svec2i_add(mapCenter, svec2i_scale(centerOn, -(float)mapScale)); |
| 310 |
|
| 311 |
|
| 312 |
const color_t mask = {0, 128, 0, 128}; |
| 313 |
DrawRectangle(g, svec2i_zero(), g->cachedConfig.Res, |
| 314 |
mask, true); |
| 315 |
|
| 316 |
DrawMap(&gMap, mapCenter, centerOn, gMap.Size, mapScale, flags); |
| 317 |
DrawObjectivesAndKeys(&gMap, pos, mapScale, flags); |
| 318 |
|
| 319 |
CA_FOREACH(const PlayerData, p, gPlayerDatas) |
| 320 |
if (!IsPlayerAlive(p)) |
| 321 |
{ |
| 322 |
continue; |
| 323 |
} |
| 324 |
DisplayPlayer(renderer, ActorGetByUID(p->ActorUID), pos, mapScale); |
| 325 |
CA_FOREACH_END() |
| 326 |
|
| 327 |
if (showExit) |
| 328 |
{ |
| 329 |
DisplayExits(&gMap, pos, mapScale, flags); |
| 330 |
} |
| 331 |
DisplaySummary(); |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
void AutomapDrawRegion( |
| 336 |
SDL_Renderer *renderer, Map *map, struct vec2i pos, |
| 337 |
const struct vec2i size, const struct vec2i mapCenter, const int flags, |
| 338 |
const bool showExit) |
| 339 |
{ |
| 340 |
const int scale = 1; |
| 341 |
const Rect2i oldClip = GraphicsGetClip(renderer); |
| 342 |
GraphicsSetClip(renderer, Rect2iNew(pos, size)); |
| 343 |
pos = svec2i_add(pos, svec2i_scale_divide(size, 2)); |
| 344 |
DrawMap(map, pos, mapCenter, size, scale, flags); |
| 345 |
const struct vec2i centerOn = |
| 346 |
svec2i_add(pos, svec2i_scale(mapCenter, (float)-scale)); |
| 347 |
CA_FOREACH(const PlayerData, p, gPlayerDatas) |
| 348 |
if (!IsPlayerAlive(p)) |
| 349 |
{ |
| 350 |
continue; |
| 351 |
} |
| 352 |
const TActor *player = ActorGetByUID(p->ActorUID); |
| 353 |
DisplayPlayer(renderer, player, centerOn, scale); |
| 354 |
CA_FOREACH_END() |
| 355 |
DrawObjectivesAndKeys(&gMap, centerOn, scale, flags); |
| 356 |
if (showExit) |
| 357 |
{ |
| 358 |
DisplayExits(map, centerOn, scale, flags); |
| 359 |
} |
| 360 |
GraphicsSetClip(renderer, oldClip); |
| 361 |
} |