| 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 <assert.h> |
| 50 |
#include <math.h> |
| 51 |
#include <stdlib.h> |
| 52 |
#include <string.h> |
| 53 |
|
| 54 |
#include "actor_pickup.h" |
| 55 |
#include "actors.h" |
| 56 |
#include "algorithms.h" |
| 57 |
#include "blit.h" |
| 58 |
#include "config.h" |
| 59 |
#include "door.h" |
| 60 |
#include "draw/draw.h" |
| 61 |
#include "draw/draw_actor.h" |
| 62 |
#include "draw/drawtools.h" |
| 63 |
#include "font.h" |
| 64 |
#include "game_events.h" |
| 65 |
#include "net_util.h" |
| 66 |
#include "objs.h" |
| 67 |
#include "pic_manager.h" |
| 68 |
#include "pickup.h" |
| 69 |
#include "pics.h" |
| 70 |
#include "texture.h" |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
typedef enum |
| 79 |
{ |
| 80 |
TILE_LOS_NORMAL, |
| 81 |
TILE_LOS_FOG, |
| 82 |
TILE_LOS_NONE |
| 83 |
} TileLOS; |
| 84 |
static TileLOS GetTileLOS(const Tile *tile, const bool useFog) |
| 85 |
{ |
| 86 |
if (!tile->isVisited) |
| 87 |
{ |
| 88 |
return TILE_LOS_NONE; |
| 89 |
} |
| 90 |
if (tile->outOfSight) |
| 91 |
{ |
| 92 |
return useFog ? TILE_LOS_FOG : TILE_LOS_NONE; |
| 93 |
} |
| 94 |
return TILE_LOS_NORMAL; |
| 95 |
} |
| 96 |
static color_t GetLOSMask(const Tile *tile, const bool useFog) |
| 97 |
{ |
| 98 |
switch (GetTileLOS(tile, useFog)) |
| 99 |
{ |
| 100 |
case TILE_LOS_NORMAL: |
| 101 |
return colorWhite; |
| 102 |
case TILE_LOS_FOG: |
| 103 |
return colorFog; |
| 104 |
case TILE_LOS_NONE: |
| 105 |
default: |
| 106 |
|
| 107 |
return colorTransparent; |
| 108 |
} |
| 109 |
} |
| 110 |
static void DrawLOSPic( |
| 111 |
const Tile *tile, const Pic *pic, const struct vec2i pos, |
| 112 |
const bool useFog) |
| 113 |
{ |
| 114 |
const color_t mask = GetLOSMask(tile, useFog); |
| 115 |
if (!ColorEquals(mask, colorTransparent)) |
| 116 |
{ |
| 117 |
PicRender( |
| 118 |
pic, gGraphicsDevice.gameWindow.renderer, pos, mask, 0, |
| 119 |
svec2_one(), SDL_FLIP_NONE, Rect2iZero()); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
static void DrawThing( |
| 124 |
DrawBuffer *b, const Thing *t, const struct vec2i offset); |
| 125 |
|
| 126 |
static void DrawTiles( |
| 127 |
DrawBuffer *b, const struct vec2i offset, |
| 128 |
void (*drawTileFunc)( |
| 129 |
DrawBuffer *, const struct vec2i, const Tile *, const struct vec2i, |
| 130 |
const bool)) |
| 131 |
{ |
| 132 |
const bool useFog = ConfigGetBool(&gConfig, "Game.Fog"); |
| 133 |
const Tile **tile = DrawBufferGetFirstTile(b); |
| 134 |
struct vec2i pos; |
| 135 |
int x, y; |
| 136 |
for (y = 0, pos.y = b->dy + offset.y; y < Y_TILES; |
| 137 |
y++, pos.y += TILE_HEIGHT) |
| 138 |
{ |
| 139 |
CArrayClear(&b->displaylist); |
| 140 |
for (x = 0, pos.x = b->dx + offset.x; x < b->Size.x; |
| 141 |
x++, tile++, pos.x += TILE_WIDTH) |
| 142 |
{ |
| 143 |
if (*tile == NULL) |
| 144 |
continue; |
| 145 |
drawTileFunc(b, offset, *tile, pos, useFog); |
| 146 |
} |
| 147 |
DrawBufferSortDisplayList(b); |
| 148 |
CA_FOREACH(const Thing *, tp, b->displaylist) |
| 149 |
DrawThing(b, *tp, offset); |
| 150 |
CA_FOREACH_END() |
| 151 |
tile += X_TILES - b->Size.x; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
static void DrawFloor( |
| 156 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 157 |
const struct vec2i pos, const bool useFog); |
| 158 |
static void DrawThingsBelow( |
| 159 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 160 |
const struct vec2i pos, const bool useFog); |
| 161 |
static void DrawWallsAndThings( |
| 162 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 163 |
const struct vec2i pos, const bool useFog); |
| 164 |
static void DrawThingsAbove( |
| 165 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 166 |
const struct vec2i pos, const bool useFog); |
| 167 |
static void DrawObjectiveHighlights( |
| 168 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 169 |
const struct vec2i pos, const bool useFog); |
| 170 |
static void DrawChatters( |
| 171 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 172 |
const struct vec2i pos, const bool useFog); |
| 173 |
static void DrawPickupMenus( |
| 174 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 175 |
const struct vec2i pos, const bool useFog); |
| 176 |
static void DrawExtra( |
| 177 |
DrawBuffer *b, struct vec2i offset, const DrawBufferArgs *args); |
| 178 |
|
| 179 |
void DrawBufferDraw( |
| 180 |
DrawBuffer *b, struct vec2i offset, const DrawBufferArgs *args) |
| 181 |
{ |
| 182 |
|
| 183 |
DrawTiles(b, offset, DrawFloor); |
| 184 |
|
| 185 |
DrawTiles(b, offset, DrawThingsBelow); |
| 186 |
|
| 187 |
DrawTiles(b, offset, DrawWallsAndThings); |
| 188 |
|
| 189 |
DrawTiles(b, offset, DrawThingsAbove); |
| 190 |
if (args->HUD) |
| 191 |
{ |
| 192 |
|
| 193 |
DrawTiles(b, offset, DrawObjectiveHighlights); |
| 194 |
|
| 195 |
DrawTiles(b, offset, DrawChatters); |
| 196 |
|
| 197 |
DrawTiles(b, offset, DrawPickupMenus); |
| 198 |
} |
| 199 |
|
| 200 |
DrawExtra(b, offset, args); |
| 201 |
} |
| 202 |
|
| 203 |
static void DrawFloor( |
| 204 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 205 |
const struct vec2i pos, const bool useFog) |
| 206 |
{ |
| 207 |
UNUSED(b); |
| 208 |
UNUSED(offset); |
| 209 |
if (t->Class != NULL && t->Class->Pic != NULL && |
| 210 |
t->Class->Pic->Data != NULL && t->Class->Type != TILE_CLASS_WALL) |
| 211 |
{ |
| 212 |
DrawLOSPic(t, t->Class->Pic, pos, useFog); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
static void DrawThingsBelow( |
| 217 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 218 |
const struct vec2i pos, const bool useFog) |
| 219 |
{ |
| 220 |
UNUSED(pos); |
| 221 |
UNUSED(offset); |
| 222 |
UNUSED(useFog); |
| 223 |
if (t->outOfSight) |
| 224 |
{ |
| 225 |
return; |
| 226 |
} |
| 227 |
CA_FOREACH(ThingId, tid, t->things) |
| 228 |
const Thing *ti = ThingIdGetThing(tid); |
| 229 |
if (ThingDrawBelow(ti)) |
| 230 |
{ |
| 231 |
CArrayPushBack(&b->displaylist, &ti); |
| 232 |
} |
| 233 |
CA_FOREACH_END() |
| 234 |
} |
| 235 |
|
| 236 |
static void DrawWallsAndThings( |
| 237 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 238 |
const struct vec2i pos, const bool useFog) |
| 239 |
{ |
| 240 |
UNUSED(offset); |
| 241 |
if (t->Class->Type == TILE_CLASS_WALL) |
| 242 |
{ |
| 243 |
DrawLOSPic( |
| 244 |
t, t->Class->Pic, svec2i_add(pos, svec2i(0, WALL_OFFSET_Y)), |
| 245 |
useFog); |
| 246 |
} |
| 247 |
else if (t->Class->Type == TILE_CLASS_DOOR) |
| 248 |
{ |
| 249 |
const color_t mask = GetLOSMask(t, useFog); |
| 250 |
if (!ColorEquals(mask, colorTransparent)) |
| 251 |
{ |
| 252 |
DoorDraw(&t->Door, pos, mask); |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
if (t->outOfSight) |
| 258 |
{ |
| 259 |
return; |
| 260 |
} |
| 261 |
CA_FOREACH(ThingId, tid, t->things) |
| 262 |
const Thing *ti = ThingIdGetThing(tid); |
| 263 |
if (ThingDrawBelow(ti) || ThingDrawAbove(ti)) |
| 264 |
{ |
| 265 |
continue; |
| 266 |
} |
| 267 |
CArrayPushBack(&b->displaylist, &ti); |
| 268 |
CA_FOREACH_END() |
| 269 |
} |
| 270 |
|
| 271 |
static void DrawThingsAbove( |
| 272 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 273 |
const struct vec2i pos, const bool useFog) |
| 274 |
{ |
| 275 |
UNUSED(offset); |
| 276 |
UNUSED(pos); |
| 277 |
UNUSED(useFog); |
| 278 |
if (t->outOfSight) |
| 279 |
{ |
| 280 |
return; |
| 281 |
} |
| 282 |
CA_FOREACH(ThingId, tid, t->things) |
| 283 |
const Thing *ti = ThingIdGetThing(tid); |
| 284 |
if (ThingDrawAbove(ti)) |
| 285 |
{ |
| 286 |
CArrayPushBack(&b->displaylist, &ti); |
| 287 |
} |
| 288 |
CA_FOREACH_END() |
| 289 |
} |
| 290 |
|
| 291 |
static void DrawObjectiveHighlights( |
| 292 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 293 |
const struct vec2i pos, const bool useFog) |
| 294 |
{ |
| 295 |
UNUSED(pos); |
| 296 |
UNUSED(useFog); |
| 297 |
CA_FOREACH(ThingId, tid, t->things) |
| 298 |
Thing *ti = ThingIdGetThing(tid); |
| 299 |
const Pic *pic = NULL; |
| 300 |
color_t color = colorWhite; |
| 301 |
struct vec2i drawOffsetExtra = svec2i_zero(); |
| 302 |
|
| 303 |
if (ti->flags & THING_OBJECTIVE) |
| 304 |
{ |
| 305 |
|
| 306 |
const int objective = ObjectiveFromThing(ti->flags); |
| 307 |
const Objective *o = |
| 308 |
CArrayGet(&gMission.missionData->Objectives, objective); |
| 309 |
if (o->Flags & OBJECTIVE_HIDDEN) |
| 310 |
{ |
| 311 |
continue; |
| 312 |
} |
| 313 |
if (!(o->Flags & OBJECTIVE_POSKNOWN) && t->outOfSight) |
| 314 |
{ |
| 315 |
continue; |
| 316 |
} |
| 317 |
switch (o->Type) |
| 318 |
{ |
| 319 |
case OBJECTIVE_KILL: |
| 320 |
case OBJECTIVE_DESTROY: |
| 321 |
pic = PicManagerGetPic(&gPicManager, "hud/objective_kill"); |
| 322 |
break; |
| 323 |
case OBJECTIVE_RESCUE: |
| 324 |
case OBJECTIVE_COLLECT: |
| 325 |
pic = PicManagerGetPic(&gPicManager, "hud/objective_collect"); |
| 326 |
break; |
| 327 |
default: |
| 328 |
CASSERT(false, "unexpected objective to draw"); |
| 329 |
continue; |
| 330 |
} |
| 331 |
color = o->color; |
| 332 |
if (ti->kind == KIND_CHARACTER) |
| 333 |
{ |
| 334 |
drawOffsetExtra.y -= 10; |
| 335 |
} |
| 336 |
} |
| 337 |
else if (ti->kind == KIND_PICKUP) |
| 338 |
{ |
| 339 |
|
| 340 |
if (!IsPVP(gCampaign.Entry.Mode) && t->outOfSight) |
| 341 |
{ |
| 342 |
continue; |
| 343 |
} |
| 344 |
|
| 345 |
const Pickup *p = CArrayGet(&gPickups, ti->id); |
| 346 |
if (!PickupClassHasKeyEffect(p->class) && !PickupIsManual(NULL, p)) |
| 347 |
{ |
| 348 |
continue; |
| 349 |
} |
| 350 |
pic = CPicGetPic(&p->thing.CPic, 0); |
| 351 |
color = colorDarker; |
| 352 |
color.a = (Uint8)Pulse256(gMission.time); |
| 353 |
} |
| 354 |
|
| 355 |
if (pic != NULL) |
| 356 |
{ |
| 357 |
const struct vec2i picPos = svec2i_add( |
| 358 |
svec2i_subtract(svec2i_floor(ti->Pos), svec2i(b->xTop, b->yTop)), |
| 359 |
offset); |
| 360 |
color.a = (Uint8)Pulse256(gMission.time); |
| 361 |
|
| 362 |
const struct vec2i drawOffset = svec2i_scale_divide(pic->size, -2); |
| 363 |
PicRender( |
| 364 |
pic, gGraphicsDevice.gameWindow.renderer, |
| 365 |
svec2i_add(picPos, svec2i_add(drawOffset, drawOffsetExtra)), color, |
| 366 |
0, svec2_one(), SDL_FLIP_NONE, Rect2iZero()); |
| 367 |
} |
| 368 |
CA_FOREACH_END() |
| 369 |
} |
| 370 |
|
| 371 |
#define ACTOR_HEIGHT 25 |
| 372 |
static void DrawChatters( |
| 373 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 374 |
const struct vec2i pos, const bool useFog) |
| 375 |
{ |
| 376 |
UNUSED(pos); |
| 377 |
UNUSED(useFog); |
| 378 |
CA_FOREACH(ThingId, tid, t->things) |
| 379 |
|
| 380 |
if (t->outOfSight) |
| 381 |
{ |
| 382 |
continue; |
| 383 |
} |
| 384 |
const Thing *ti = ThingIdGetThing(tid); |
| 385 |
if (ti->kind != KIND_CHARACTER) |
| 386 |
{ |
| 387 |
continue; |
| 388 |
} |
| 389 |
|
| 390 |
const TActor *a = CArrayGet(&gActors, ti->id); |
| 391 |
|
| 392 |
if (strlen(a->Chatter) > 0) |
| 393 |
{ |
| 394 |
const struct vec2i textPos = svec2i( |
| 395 |
(int)a->thing.Pos.x - b->xTop + offset.x - |
| 396 |
FontStrW(a->Chatter) / 2, |
| 397 |
(int)a->thing.Pos.y - b->yTop + offset.y - ACTOR_HEIGHT); |
| 398 |
const color_t mask = GetLOSMask(t, useFog); |
| 399 |
if (!ColorEquals(mask, colorTransparent)) |
| 400 |
{ |
| 401 |
FontStrMask(a->Chatter, textPos, mask); |
| 402 |
} |
| 403 |
} |
| 404 |
CA_FOREACH_END() |
| 405 |
} |
| 406 |
|
| 407 |
static void DrawPickupMenu( |
| 408 |
DrawBuffer *b, const TActor *a, const struct vec2i offset); |
| 409 |
static void DrawPickupMenus( |
| 410 |
DrawBuffer *b, const struct vec2i offset, const Tile *t, |
| 411 |
const struct vec2i pos, const bool useFog) |
| 412 |
{ |
| 413 |
UNUSED(pos); |
| 414 |
CA_FOREACH(ThingId, tid, t->things) |
| 415 |
|
| 416 |
if (t->outOfSight || ColorEquals(GetLOSMask(t, useFog), colorTransparent)) |
| 417 |
{ |
| 418 |
continue; |
| 419 |
} |
| 420 |
const Thing *ti = ThingIdGetThing(tid); |
| 421 |
if (ti->kind != KIND_CHARACTER) |
| 422 |
{ |
| 423 |
continue; |
| 424 |
} |
| 425 |
|
| 426 |
const TActor *a = CArrayGet(&gActors, ti->id); |
| 427 |
|
| 428 |
if (!a->pickupMenu.pickup || !ActorIsLocalPlayer(a->uid)) |
| 429 |
{ |
| 430 |
continue; |
| 431 |
} |
| 432 |
|
| 433 |
DrawPickupMenu(b, a, offset); |
| 434 |
CA_FOREACH_END() |
| 435 |
} |
| 436 |
static void DrawPickupMenu( |
| 437 |
DrawBuffer *b, const TActor *a, const struct vec2i offset) |
| 438 |
{ |
| 439 |
|
| 440 |
|
| 441 |
struct vec2i size = svec2i_zero(); |
| 442 |
struct vec2i ssize = FontStrSize(a->pickupMenu.effect->u.Menu.Text); |
| 443 |
size.x = MAX(size.x, ssize.x); |
| 444 |
size.y += ssize.y; |
| 445 |
size.y += FontH(); |
| 446 |
CA_FOREACH(const PickupMenuItem, m, a->pickupMenu.effect->u.Menu.Items) |
| 447 |
ssize = FontStrSize(m->Text); |
| 448 |
size.x = MAX(size.x, ssize.x); |
| 449 |
size.y += ssize.y; |
| 450 |
CA_FOREACH_END() |
| 451 |
|
| 452 |
struct vec2i pos = svec2i( |
| 453 |
(int)a->thing.Pos.x - b->xTop + offset.x - size.x / 2, |
| 454 |
(int)a->thing.Pos.y - b->yTop + offset.y - size.y / 2); |
| 455 |
const int startX = pos.x; |
| 456 |
|
| 457 |
const color_t cbg = {64, 64, 64, 128}; |
| 458 |
DrawRectangle( |
| 459 |
b->g, svec2i_subtract(pos, svec2i(2, 2)), |
| 460 |
svec2i_add(size, svec2i(4, 4)), cbg, true); |
| 461 |
pos = FontStr(a->pickupMenu.effect->u.Menu.Text, pos); |
| 462 |
pos.x = startX; |
| 463 |
pos.y += FontH() * 2; |
| 464 |
CA_FOREACH(const PickupMenuItem, m, a->pickupMenu.effect->u.Menu.Items) |
| 465 |
const bool selected = _ca_index == a->pickupMenu.index; |
| 466 |
if (selected) |
| 467 |
{ |
| 468 |
|
| 469 |
const struct vec2i bgPos = svec2i_subtract(pos, svec2i_one()); |
| 470 |
const struct vec2i bgSize = |
| 471 |
svec2i_add(svec2i(size.x, FontH()), svec2i(2, 2)); |
| 472 |
DrawRectangle(b->g, bgPos, bgSize, colorSelectedBG, true); |
| 473 |
} |
| 474 |
pos = FontStrMask(m->Text, pos, selected ? colorRed : colorWhite); |
| 475 |
pos.x = startX; |
| 476 |
pos.y += FontH(); |
| 477 |
CA_FOREACH_END() |
| 478 |
} |
| 479 |
|
| 480 |
static void DrawThing(DrawBuffer *b, const Thing *t, const struct vec2i offset) |
| 481 |
{ |
| 482 |
const struct vec2i picPos = svec2i_add( |
| 483 |
svec2i_subtract( |
| 484 |
svec2i_floor(svec2_add(t->Pos, t->drawShake)), |
| 485 |
svec2i(b->xTop, b->yTop)), |
| 486 |
offset); |
| 487 |
|
| 488 |
if (!svec2i_is_zero(t->ShadowSize)) |
| 489 |
{ |
| 490 |
DrawShadow( |
| 491 |
&gGraphicsDevice, picPos, svec2_assign_vec2i(t->ShadowSize), |
| 492 |
colorBlack); |
| 493 |
} |
| 494 |
|
| 495 |
if (t->CPicFunc) |
| 496 |
{ |
| 497 |
t->CPicFunc(b->g, t->id, picPos); |
| 498 |
} |
| 499 |
else if (t->kind == KIND_CHARACTER) |
| 500 |
{ |
| 501 |
const TActor *a = CArrayGet(&gActors, t->id); |
| 502 |
ActorPics pics = GetCharacterPicsFromActor(a); |
| 503 |
DrawActorPics(&pics, picPos, Rect2iZero()); |
| 504 |
|
| 505 |
DrawLaserSight(&pics, a, picPos); |
| 506 |
} |
| 507 |
else |
| 508 |
{ |
| 509 |
(*(t->drawFunc))(picPos, &t->drawData); |
| 510 |
} |
| 511 |
|
| 512 |
#ifdef DEBUG_DRAW_HITBOXES |
| 513 |
const int pulsePeriod = ConfigGetInt(&gConfig, "Game.FPS"); |
| 514 |
int alphaUnscaled = |
| 515 |
(gMission.time % pulsePeriod) * 255 / (pulsePeriod / 2); |
| 516 |
if (alphaUnscaled > 255) |
| 517 |
{ |
| 518 |
alphaUnscaled = 255 * 2 - alphaUnscaled; |
| 519 |
} |
| 520 |
color_t color = colorPurple; |
| 521 |
color.a = (Uint8)alphaUnscaled; |
| 522 |
DrawRectangle( |
| 523 |
&gGraphicsDevice, |
| 524 |
svec2i_subtract(picPos, svec2i_scale_divide(t->size, 2)), t->size, |
| 525 |
color, false); |
| 526 |
#endif |
| 527 |
} |
| 528 |
|
| 529 |
static void DrawPickups( |
| 530 |
DrawBuffer *b, const Map *map, const struct vec2i offset); |
| 531 |
static void DrawEditorTiles( |
| 532 |
DrawBuffer *b, const Map *map, const struct vec2i offset); |
| 533 |
static void DrawGuideImage( |
| 534 |
const DrawBuffer *b, const Pic *guideImage, const uint8_t alpha); |
| 535 |
static void DrawObjectNames(DrawBuffer *b, const struct vec2i offset); |
| 536 |
static void DrawExtra( |
| 537 |
DrawBuffer *b, struct vec2i offset, const DrawBufferArgs *args) |
| 538 |
{ |
| 539 |
|
| 540 |
if (args->GuideImage && !PicIsNone(args->GuideImage) && |
| 541 |
args->GuideImageAlpha > 0) |
| 542 |
{ |
| 543 |
DrawGuideImage(b, args->GuideImage, args->GuideImageAlpha); |
| 544 |
} |
| 545 |
if (args->Editor) |
| 546 |
{ |
| 547 |
|
| 548 |
DrawPickups(b, &gMap, offset); |
| 549 |
DrawEditorTiles(b, &gMap, offset); |
| 550 |
DrawObjectNames(b, offset); |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
static void DrawPickups( |
| 555 |
DrawBuffer *b, const Map *map, const struct vec2i offset) |
| 556 |
{ |
| 557 |
struct vec2i pos; |
| 558 |
pos.y = b->dy + offset.y; |
| 559 |
for (int y = 0; y < Y_TILES; y++, pos.y += TILE_HEIGHT) |
| 560 |
{ |
| 561 |
pos.x = b->dx + offset.x; |
| 562 |
for (int x = 0; x < b->Size.x; x++, pos.x += TILE_WIDTH) |
| 563 |
{ |
| 564 |
const struct vec2i tilePos = svec2i(x + b->xStart, y + b->yStart); |
| 565 |
if (!MapIsTileIn(map, tilePos)) |
| 566 |
{ |
| 567 |
continue; |
| 568 |
} |
| 569 |
|
| 570 |
const Tile *t = MapGetTile(map, tilePos); |
| 571 |
CA_FOREACH(const ThingId, tid, t->things) |
| 572 |
const Thing *ti = ThingIdGetThing(tid); |
| 573 |
if (ti->kind == KIND_PICKUP) |
| 574 |
{ |
| 575 |
DrawThing(b, ti, offset); |
| 576 |
} |
| 577 |
CA_FOREACH_END() |
| 578 |
} |
| 579 |
} |
| 580 |
} |
| 581 |
static void DrawEditorTiles( |
| 582 |
DrawBuffer *b, const Map *map, const struct vec2i offset) |
| 583 |
{ |
| 584 |
const color_t exitColor = colorDarker; |
| 585 |
struct vec2i pos; |
| 586 |
pos.y = b->dy + offset.y; |
| 587 |
for (int y = 0; y < Y_TILES; y++, pos.y += TILE_HEIGHT) |
| 588 |
{ |
| 589 |
pos.x = b->dx + offset.x; |
| 590 |
for (int x = 0; x < b->Size.x; x++, pos.x += TILE_WIDTH) |
| 591 |
{ |
| 592 |
const struct vec2i tilePos = svec2i(x + b->xStart, y + b->yStart); |
| 593 |
if (!MapIsTileIn(map, tilePos)) |
| 594 |
{ |
| 595 |
continue; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
const uint16_t al = MapGetAccessLevel(map, tilePos); |
| 600 |
if (al != 0) |
| 601 |
{ |
| 602 |
color_t highlight = KeyColor(al); |
| 603 |
highlight.a = 64; |
| 604 |
DrawRectangle( |
| 605 |
b->g, pos, svec2i(TILE_WIDTH, TILE_HEIGHT), highlight, |
| 606 |
true); |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
if (!svec2i_is_zero(map->start) && |
| 611 |
svec2i_is_equal(map->start, tilePos)) |
| 612 |
{ |
| 613 |
PicRender( |
| 614 |
PicManagerGetPic(&gPicManager, "editor/start"), |
| 615 |
b->g->gameWindow.renderer, pos, colorWhite, 0, svec2_one(), |
| 616 |
SDL_FLIP_NONE, Rect2iZero()); |
| 617 |
} |
| 618 |
|
| 619 |
|
| 620 |
CA_FOREACH(const Exit, e, map->exits) |
| 621 |
Rect2i exitR = e->R; |
| 622 |
exitR.Size = svec2i_add(exitR.Size, svec2i_one()); |
| 623 |
if (!Rect2iIsInside(exitR, tilePos)) |
| 624 |
{ |
| 625 |
continue; |
| 626 |
} |
| 627 |
if (tilePos.x == e->R.Pos.x) |
| 628 |
{ |
| 629 |
|
| 630 |
DrawLine( |
| 631 |
pos, svec2i_add(pos, svec2i(0, TILE_HEIGHT - 1)), |
| 632 |
exitColor); |
| 633 |
} |
| 634 |
else if (tilePos.x == e->R.Pos.x + e->R.Size.x) |
| 635 |
{ |
| 636 |
|
| 637 |
DrawLine( |
| 638 |
svec2i_add(pos, svec2i(TILE_WIDTH - 1, 0)), |
| 639 |
svec2i_add(pos, svec2i(TILE_WIDTH - 1, TILE_HEIGHT - 1)), |
| 640 |
exitColor); |
| 641 |
} |
| 642 |
if (tilePos.y == e->R.Pos.y) |
| 643 |
{ |
| 644 |
|
| 645 |
DrawLine( |
| 646 |
pos, svec2i_add(pos, svec2i(TILE_WIDTH - 1, 0)), |
| 647 |
exitColor); |
| 648 |
} |
| 649 |
else if (tilePos.y == e->R.Pos.y + e->R.Size.y) |
| 650 |
{ |
| 651 |
|
| 652 |
DrawLine( |
| 653 |
svec2i_add(pos, svec2i(0, TILE_HEIGHT - 1)), |
| 654 |
svec2i_add(pos, svec2i(TILE_WIDTH - 1, TILE_HEIGHT - 1)), |
| 655 |
exitColor); |
| 656 |
} |
| 657 |
if (svec2i_is_equal(tilePos, e->R.Pos)) |
| 658 |
{ |
| 659 |
|
| 660 |
char buf[256]; |
| 661 |
sprintf( |
| 662 |
buf, "Exit %d\nMission %d\n(%d,%d)\n(%dx%d)", _ca_index, |
| 663 |
e->Mission + 1, e->R.Pos.x, e->R.Pos.y, e->R.Size.x, |
| 664 |
e->R.Size.y); |
| 665 |
FontStrMask(buf, svec2i_add(pos, svec2i(3, 3)), exitColor); |
| 666 |
} |
| 667 |
CA_FOREACH_END() |
| 668 |
|
| 669 |
|
| 670 |
const Tile *tile = MapGetTile(map, tilePos); |
| 671 |
if (tile->Class->Type == TILE_CLASS_WALL && tile->Class->canWalk) |
| 672 |
{ |
| 673 |
DrawRectangle( |
| 674 |
b->g, pos, svec2i(TILE_WIDTH, TILE_HEIGHT), colorGreen, |
| 675 |
false); |
| 676 |
} |
| 677 |
} |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
static void DrawGuideImage( |
| 682 |
const DrawBuffer *b, const Pic *guideImage, const uint8_t alpha) |
| 683 |
{ |
| 684 |
|
| 685 |
|
| 686 |
float xScale = (float)(gMap.Size.x * TILE_WIDTH) / guideImage->size.x; |
| 687 |
float yScale = (float)(gMap.Size.y * TILE_HEIGHT) / guideImage->size.y; |
| 688 |
const struct vec2i pos = svec2i(-b->xTop, -b->yTop); |
| 689 |
color_t mask = colorWhite; |
| 690 |
mask.a = alpha; |
| 691 |
TextureRender( |
| 692 |
guideImage->Tex, gGraphicsDevice.gameWindow.renderer, Rect2iZero(), |
| 693 |
Rect2iNew( |
| 694 |
pos, svec2i( |
| 695 |
(mint_t)MROUND(guideImage->size.x * xScale), |
| 696 |
(mint_t)MROUND(guideImage->size.y * yScale))), |
| 697 |
mask, 0, SDL_FLIP_NONE); |
| 698 |
} |
| 699 |
|
| 700 |
|
| 701 |
static void DrawObjectiveName( |
| 702 |
const Thing *ti, DrawBuffer *b, const struct vec2i offset); |
| 703 |
static void DrawSpawnerName( |
| 704 |
const TObject *obj, DrawBuffer *b, const struct vec2i offset, |
| 705 |
const char *name); |
| 706 |
static void DrawPickupName( |
| 707 |
const Pickup *p, DrawBuffer *b, const struct vec2i offset); |
| 708 |
static void DrawObjectNames(DrawBuffer *b, const struct vec2i offset) |
| 709 |
{ |
| 710 |
const Tile **tile = DrawBufferGetFirstTile(b); |
| 711 |
for (int y = 0; y < Y_TILES; y++) |
| 712 |
{ |
| 713 |
for (int x = 0; x < b->Size.x; x++, tile++) |
| 714 |
{ |
| 715 |
if (*tile == NULL) |
| 716 |
continue; |
| 717 |
CA_FOREACH(ThingId, tid, (*tile)->things) |
| 718 |
const Thing *ti = ThingIdGetThing(tid); |
| 719 |
if (ti->flags & THING_OBJECTIVE) |
| 720 |
{ |
| 721 |
DrawObjectiveName(ti, b, offset); |
| 722 |
} |
| 723 |
else if (ti->kind == KIND_OBJECT) |
| 724 |
{ |
| 725 |
const TObject *obj = CArrayGet(&gObjs, ti->id); |
| 726 |
switch (obj->Class->Type) |
| 727 |
{ |
| 728 |
case MAP_OBJECT_TYPE_PICKUP_SPAWNER: |
| 729 |
DrawSpawnerName( |
| 730 |
obj, b, offset, obj->Class->u.PickupClass->Name); |
| 731 |
break; |
| 732 |
case MAP_OBJECT_TYPE_ACTOR_SPAWNER: { |
| 733 |
const Character *c = CArrayGet( |
| 734 |
&gCampaign.Setting.characters.OtherChars, |
| 735 |
obj->Class->u.Character.CharId); |
| 736 |
DrawSpawnerName(obj, b, offset, c->Class->Name); |
| 737 |
} |
| 738 |
break; |
| 739 |
default: |
| 740 |
break; |
| 741 |
} |
| 742 |
} |
| 743 |
else if (ti->kind == KIND_PICKUP) |
| 744 |
{ |
| 745 |
const Pickup *p = CArrayGet(&gPickups, ti->id); |
| 746 |
DrawPickupName(p, b, offset); |
| 747 |
} |
| 748 |
CA_FOREACH_END() |
| 749 |
} |
| 750 |
tile += X_TILES - b->Size.x; |
| 751 |
} |
| 752 |
} |
| 753 |
static void DrawObjectiveName( |
| 754 |
const Thing *ti, DrawBuffer *b, const struct vec2i offset) |
| 755 |
{ |
| 756 |
const int objective = ObjectiveFromThing(ti->flags); |
| 757 |
const Objective *o = |
| 758 |
CArrayGet(&gMission.missionData->Objectives, objective); |
| 759 |
const char *typeName = ObjectiveTypeStr(o->Type); |
| 760 |
const struct vec2i textPos = svec2i( |
| 761 |
(int)ti->Pos.x - b->xTop + offset.x - FontStrW(typeName) / 2, |
| 762 |
(int)ti->Pos.y - b->yTop + offset.y); |
| 763 |
FontStr(typeName, textPos); |
| 764 |
} |
| 765 |
static void DrawSpawnerName( |
| 766 |
const TObject *obj, DrawBuffer *b, const struct vec2i offset, |
| 767 |
const char *name) |
| 768 |
{ |
| 769 |
const struct vec2i textPos = svec2i( |
| 770 |
(int)obj->thing.Pos.x - b->xTop + offset.x - FontStrW(name) / 2, |
| 771 |
(int)obj->thing.Pos.y - b->yTop + offset.y); |
| 772 |
FontStr(name, textPos); |
| 773 |
} |
| 774 |
static void DrawPickupName( |
| 775 |
const Pickup *p, DrawBuffer *b, const struct vec2i offset) |
| 776 |
{ |
| 777 |
CA_FOREACH(const PickupEffect, pe, p->class->Effects) |
| 778 |
if (pe->Type == PICKUP_KEYCARD) |
| 779 |
{ |
| 780 |
const char *label = "key"; |
| 781 |
const color_t c = KeyColor(pe->u.Keys); |
| 782 |
const struct vec2i textPos = svec2i( |
| 783 |
(int)p->thing.Pos.x - b->xTop + offset.x - FontStrW(label) / 2, |
| 784 |
(int)p->thing.Pos.y - b->yTop + offset.y); |
| 785 |
FontStrMask(label, textPos, c); |
| 786 |
break; |
| 787 |
} |
| 788 |
CA_FOREACH_END() |
| 789 |
} |