| 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 "door.h" |
| 50 |
|
| 51 |
#include "aheasing/easing.h" |
| 52 |
#include "draw/draw.h" |
| 53 |
#include "gamedata.h" |
| 54 |
#include "log.h" |
| 55 |
#include "net_util.h" |
| 56 |
#include "texture.h" |
| 57 |
|
| 58 |
static DoorType GetDoorType( |
| 59 |
const bool isHorizontal, const int i, const int count) |
| 60 |
{ |
| 61 |
if (isHorizontal) |
| 62 |
{ |
| 63 |
if (count == 1) |
| 64 |
{ |
| 65 |
return DOORTYPE_H; |
| 66 |
} |
| 67 |
else if (i == 0) |
| 68 |
{ |
| 69 |
return DOORTYPE_LEFT; |
| 70 |
} |
| 71 |
else if (i == count - 1) |
| 72 |
{ |
| 73 |
return DOORTYPE_RIGHT; |
| 74 |
} |
| 75 |
else |
| 76 |
{ |
| 77 |
return DOORTYPE_HMID; |
| 78 |
} |
| 79 |
} |
| 80 |
else |
| 81 |
{ |
| 82 |
if (count == 1) |
| 83 |
{ |
| 84 |
return DOORTYPE_V; |
| 85 |
} |
| 86 |
else if (i == 0) |
| 87 |
{ |
| 88 |
return DOORTYPE_TOP; |
| 89 |
} |
| 90 |
else if (i == count - 1) |
| 91 |
{ |
| 92 |
return DOORTYPE_BOTTOM; |
| 93 |
} |
| 94 |
else |
| 95 |
{ |
| 96 |
return DOORTYPE_VMID; |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
static bool DoorTypeIsHorizontal(const DoorType type) |
| 101 |
{ |
| 102 |
return type == DOORTYPE_H || type == DOORTYPE_LEFT || |
| 103 |
type == DOORTYPE_HMID || type == DOORTYPE_RIGHT; |
| 104 |
} |
| 105 |
|
| 106 |
static bool DoorGroupIsHorizontal(const MapBuilder *mb, const struct vec2i v); |
| 107 |
static void DoorGetClassName( |
| 108 |
char *buf, const TileClass *door, const char *key, const DoorType dType); |
| 109 |
static int GetDoorCountInGroup( |
| 110 |
const MapBuilder *mb, const struct vec2i v, const bool isHorizontal); |
| 111 |
static TWatch *CreateCloseDoorWatch( |
| 112 |
MapBuilder *mb, const struct vec2i v, const bool isHorizontal, |
| 113 |
const int doorGroupCount); |
| 114 |
static Trigger *CreateOpenDoorTrigger( |
| 115 |
MapBuilder *mb, const struct vec2i v, const bool isHorizontal, |
| 116 |
const int doorGroupCount, const int keyFlags); |
| 117 |
struct vec2i MapAddDoorGroup( |
| 118 |
MapBuilder *mb, const struct vec2i v, const int keyFlags) |
| 119 |
{ |
| 120 |
const TileClass *door = MapBuilderGetTile(mb, v); |
| 121 |
const bool isHorizontal = DoorGroupIsHorizontal(mb, v); |
| 122 |
const int doorGroupCount = GetDoorCountInGroup(mb, v, isHorizontal); |
| 123 |
const struct vec2i dv = svec2i(isHorizontal ? 1 : 0, isHorizontal ? 0 : 1); |
| 124 |
const struct vec2i dAside = svec2i(dv.y, dv.x); |
| 125 |
|
| 126 |
const char *doorKey; |
| 127 |
switch (keyFlags) |
| 128 |
{ |
| 129 |
case FLAGS_KEYCARD_RED: |
| 130 |
doorKey = "red"; |
| 131 |
break; |
| 132 |
case FLAGS_KEYCARD_BLUE: |
| 133 |
doorKey = "blue"; |
| 134 |
break; |
| 135 |
case FLAGS_KEYCARD_GREEN: |
| 136 |
doorKey = "green"; |
| 137 |
break; |
| 138 |
case FLAGS_KEYCARD_YELLOW: |
| 139 |
doorKey = "yellow"; |
| 140 |
break; |
| 141 |
default: |
| 142 |
doorKey = "normal"; |
| 143 |
break; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
for (int i = 0; i < doorGroupCount; i++) |
| 148 |
{ |
| 149 |
char doorClassName[CDOGS_FILENAME_MAX]; |
| 150 |
const DoorType type = GetDoorType(isHorizontal, i, doorGroupCount); |
| 151 |
DoorGetClassName(doorClassName, door, doorKey, type); |
| 152 |
const TileClass *doorClass = StrTileClass(mb->Map->TileClasses, doorClassName); |
| 153 |
DoorGetClassName(doorClassName, door, "open", type); |
| 154 |
const TileClass *doorClassOpen = StrTileClass(mb->Map->TileClasses, doorClassName); |
| 155 |
const struct vec2i vI = svec2i_add(v, svec2i_scale(dv, (float)i)); |
| 156 |
Tile *tile = MapGetTile(mb->Map, vI); |
| 157 |
tile->Door.Class = doorClass; |
| 158 |
DoorStateInit(&tile->Door, false); |
| 159 |
tile->Door.IsHorizontal = isHorizontal; |
| 160 |
tile->Class = doorClassOpen; |
| 161 |
if (isHorizontal) |
| 162 |
{ |
| 163 |
const struct vec2i vB = svec2i_add(vI, dAside); |
| 164 |
Tile *tileB = MapGetTile(mb->Map, vB); |
| 165 |
if (TileCanWalk(tileB)) |
| 166 |
{ |
| 167 |
if (tileB->Class->Type == TILE_CLASS_FLOOR) |
| 168 |
{ |
| 169 |
|
| 170 |
tileB->Class = TileClassesGetMaskedTile( |
| 171 |
mb->Map->TileClasses, |
| 172 |
tileB->Class, tileB->Class->Style, "shadow", |
| 173 |
tileB->Class->Mask, tileB->Class->MaskAlt); |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
else if (i == 0) |
| 178 |
{ |
| 179 |
|
| 180 |
DoorGetClassName(doorClassName, door, "wall", type); |
| 181 |
tile->Door.Class2 = StrTileClass(mb->Map->TileClasses, doorClassName); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
TWatch *w = CreateCloseDoorWatch(mb, v, isHorizontal, doorGroupCount); |
| 186 |
Trigger *t = |
| 187 |
CreateOpenDoorTrigger(mb, v, isHorizontal, doorGroupCount, keyFlags); |
| 188 |
|
| 189 |
Action *a = TriggerAddAction(t); |
| 190 |
a->Type = ACTION_ACTIVATEWATCH; |
| 191 |
a->u.index = w->index; |
| 192 |
a = WatchAddAction(w); |
| 193 |
a->Type = ACTION_SETTRIGGER; |
| 194 |
a->u.index = t->id; |
| 195 |
|
| 196 |
|
| 197 |
for (int i = 0; i < doorGroupCount; i++) |
| 198 |
{ |
| 199 |
const struct vec2i vI = svec2i_add(v, svec2i_scale(dv, (float)i)); |
| 200 |
MapBuilderSetLeaveFree(mb, vI, true); |
| 201 |
const struct vec2i vI1 = svec2i_add(vI, dAside); |
| 202 |
MapBuilderSetLeaveFree(mb, vI1, true); |
| 203 |
const struct vec2i vI2 = svec2i_subtract(vI, dAside); |
| 204 |
MapBuilderSetLeaveFree(mb, vI2, true); |
| 205 |
} |
| 206 |
|
| 207 |
return isHorizontal ? svec2i(doorGroupCount, 1) |
| 208 |
: svec2i(1, doorGroupCount); |
| 209 |
} |
| 210 |
static bool DoorGroupIsHorizontal(const MapBuilder *mb, const struct vec2i v) |
| 211 |
{ |
| 212 |
const TileClass *tileLeftType = |
| 213 |
MapBuilderGetTile(mb, svec2i(v.x - 1, v.y)); |
| 214 |
const TileClass *tileRightType = |
| 215 |
MapBuilderGetTile(mb, svec2i(v.x + 1, v.y)); |
| 216 |
const TileClass *tileAboveType = |
| 217 |
MapBuilderGetTile(mb, svec2i(v.x, v.y - 1)); |
| 218 |
const TileClass *tileBelowType = |
| 219 |
MapBuilderGetTile(mb, svec2i(v.x, v.y + 1)); |
| 220 |
const bool tileLeftIsDoor = |
| 221 |
tileLeftType != NULL && tileLeftType->Type == TILE_CLASS_DOOR; |
| 222 |
const bool tileRightIsDoor = |
| 223 |
tileRightType != NULL && tileRightType->Type == TILE_CLASS_DOOR; |
| 224 |
const bool tileAboveIsDoor = |
| 225 |
tileAboveType != NULL && tileAboveType->Type == TILE_CLASS_DOOR; |
| 226 |
const bool tileBelowIsDoor = |
| 227 |
tileBelowType != NULL && tileBelowType->Type == TILE_CLASS_DOOR; |
| 228 |
const bool tileLeftCanWalk = tileLeftType != NULL && tileLeftType->canWalk; |
| 229 |
const bool tileRightCanWalk = |
| 230 |
tileRightType != NULL && tileRightType->canWalk; |
| 231 |
const bool tileAboveCanWalk = |
| 232 |
tileAboveType != NULL && tileAboveType->canWalk; |
| 233 |
const bool tileBelowCanWalk = |
| 234 |
tileBelowType != NULL && tileBelowType->canWalk; |
| 235 |
|
| 236 |
if (tileAboveCanWalk && tileBelowCanWalk && tileLeftCanWalk && |
| 237 |
tileRightCanWalk) |
| 238 |
{ |
| 239 |
if (tileLeftIsDoor && tileRightIsDoor) |
| 240 |
{ |
| 241 |
return true; |
| 242 |
} |
| 243 |
if (tileAboveIsDoor && tileBelowIsDoor) |
| 244 |
{ |
| 245 |
return false; |
| 246 |
} |
| 247 |
return tileLeftIsDoor || tileRightIsDoor; |
| 248 |
} |
| 249 |
|
| 250 |
if (tileAboveCanWalk && tileBelowCanWalk) |
| 251 |
{ |
| 252 |
return true; |
| 253 |
} |
| 254 |
if (tileLeftCanWalk && tileRightCanWalk) |
| 255 |
{ |
| 256 |
return false; |
| 257 |
} |
| 258 |
|
| 259 |
if (tileAboveCanWalk || tileBelowCanWalk) |
| 260 |
{ |
| 261 |
return true; |
| 262 |
} |
| 263 |
|
| 264 |
if (tileAboveIsDoor || tileBelowIsDoor) |
| 265 |
{ |
| 266 |
return true; |
| 267 |
} |
| 268 |
return false; |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
static int GetDoorCountInGroup( |
| 274 |
const MapBuilder *mb, const struct vec2i v, const bool isHorizontal) |
| 275 |
{ |
| 276 |
const struct vec2i dv = svec2i(isHorizontal ? 1 : 0, isHorizontal ? 0 : 1); |
| 277 |
int count = 0; |
| 278 |
for (struct vec2i vi = v; |
| 279 |
MapIsTileIn(mb->Map, vi) && |
| 280 |
MapBuilderGetTile(mb, vi)->Type == TILE_CLASS_DOOR; |
| 281 |
vi = svec2i_add(vi, dv)) |
| 282 |
{ |
| 283 |
count++; |
| 284 |
} |
| 285 |
return count; |
| 286 |
} |
| 287 |
|
| 288 |
static TWatch *CreateCloseDoorWatch( |
| 289 |
MapBuilder *mb, const struct vec2i v, const bool isHorizontal, |
| 290 |
const int doorGroupCount) |
| 291 |
{ |
| 292 |
TWatch *w = WatchNew(); |
| 293 |
const struct vec2i dv = svec2i(isHorizontal ? 1 : 0, isHorizontal ? 0 : 1); |
| 294 |
const struct vec2i dAside = svec2i(dv.y, dv.x); |
| 295 |
|
| 296 |
|
| 297 |
for (int i = 0; i < doorGroupCount; i++) |
| 298 |
{ |
| 299 |
const struct vec2i vI = svec2i_add(v, svec2i_scale(dv, (float)i)); |
| 300 |
|
| 301 |
for (int j = -1; j <= 1; j++) |
| 302 |
{ |
| 303 |
WatchAddCondition( |
| 304 |
w, CONDITION_TILECLEAR, gCampaign.Setting.DoorOpenTicks, |
| 305 |
svec2i_add(vI, svec2i_scale(dAside, (float)j))); |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
Action *a; |
| 311 |
|
| 312 |
|
| 313 |
a = WatchAddAction(w); |
| 314 |
a->Type = ACTION_DEACTIVATEWATCH; |
| 315 |
a->u.index = w->index; |
| 316 |
|
| 317 |
a = WatchAddAction(w); |
| 318 |
a->Type = ACTION_EVENT; |
| 319 |
a->u.Event = GameEventNew(GAME_EVENT_SOUND_AT); |
| 320 |
strcpy(a->u.Event.u.SoundAt.Sound, "door_close"); |
| 321 |
a->u.Event.u.SoundAt.Pos = Vec2ToNet(Vec2CenterOfTile( |
| 322 |
svec2i_add(v, svec2i_scale(dv, (float)doorGroupCount / 2)))); |
| 323 |
|
| 324 |
|
| 325 |
for (int i = 0; i < doorGroupCount; i++) |
| 326 |
{ |
| 327 |
const struct vec2i vI = svec2i_add(v, svec2i_scale(dv, (float)i)); |
| 328 |
|
| 329 |
a = WatchAddAction(w); |
| 330 |
a->Type = ACTION_EVENT; |
| 331 |
a->u.Event = GameEventNew(GAME_EVENT_DOOR_TOGGLE); |
| 332 |
a->u.Event.u.DoorToggle.IsOpen = false; |
| 333 |
a->u.Event.u.DoorToggle.Pos = Vec2i2Net(vI); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
if (isHorizontal) |
| 338 |
{ |
| 339 |
for (int i = 0; i < doorGroupCount; i++) |
| 340 |
{ |
| 341 |
const struct vec2i vI = svec2i_add(v, svec2i_scale(dv, (float)i)); |
| 342 |
const struct vec2i vI2 = svec2i(vI.x + dAside.x, vI.y + dAside.y); |
| 343 |
const TileClass *t = MapBuilderGetTile(mb, vI2); |
| 344 |
if (t->Type == TILE_CLASS_FLOOR) |
| 345 |
{ |
| 346 |
a = WatchAddAction(w); |
| 347 |
a->Type = ACTION_EVENT; |
| 348 |
a->u.Event = GameEventNew(GAME_EVENT_TILE_SET); |
| 349 |
a->u.Event.u.TileSet.Pos = Vec2i2Net(vI2); |
| 350 |
TileClassGetName( |
| 351 |
a->u.Event.u.TileSet.ClassName, t, t->Style, "shadow", |
| 352 |
t->Mask, t->MaskAlt); |
| 353 |
} |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
return w; |
| 358 |
} |
| 359 |
static void TileAddTrigger(Tile *t, Trigger *tr); |
| 360 |
static Trigger *CreateOpenDoorTrigger( |
| 361 |
MapBuilder *mb, const struct vec2i v, const bool isHorizontal, |
| 362 |
const int doorGroupCount, const int keyFlags) |
| 363 |
{ |
| 364 |
|
| 365 |
const struct vec2i dv = svec2i(isHorizontal ? 1 : 0, isHorizontal ? 0 : 1); |
| 366 |
const struct vec2i dAside = svec2i(dv.y, dv.x); |
| 367 |
Trigger *t = MapNewTrigger(mb->Map); |
| 368 |
t->flags = keyFlags; |
| 369 |
|
| 370 |
|
| 371 |
Action *a; |
| 372 |
a = TriggerAddAction(t); |
| 373 |
a->Type = ACTION_CLEARTRIGGER; |
| 374 |
a->u.index = t->id; |
| 375 |
|
| 376 |
|
| 377 |
for (int i = 0; i < doorGroupCount; i++) |
| 378 |
{ |
| 379 |
const struct vec2i vI = svec2i_add(v, svec2i_scale(dv, (float)i)); |
| 380 |
a = TriggerAddAction(t); |
| 381 |
a->Type = ACTION_EVENT; |
| 382 |
a->u.Event = GameEventNew(GAME_EVENT_DOOR_TOGGLE); |
| 383 |
a->u.Event.u.DoorToggle.IsOpen = true; |
| 384 |
a->u.Event.u.DoorToggle.Pos = Vec2i2Net(vI); |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
if (isHorizontal) |
| 389 |
{ |
| 390 |
for (int i = 0; i < doorGroupCount; i++) |
| 391 |
{ |
| 392 |
const struct vec2i vI = svec2i_add(v, svec2i_scale(dv, (float)i)); |
| 393 |
const struct vec2i vIAside = svec2i_add(vI, dAside); |
| 394 |
const TileClass *tc = MapBuilderGetTile(mb, vIAside); |
| 395 |
if (tc->Type == TILE_CLASS_FLOOR) |
| 396 |
{ |
| 397 |
a = TriggerAddAction(t); |
| 398 |
|
| 399 |
a->Type = ACTION_EVENT; |
| 400 |
a->u.Event = GameEventNew(GAME_EVENT_TILE_SET); |
| 401 |
a->u.Event.u.TileSet.Pos = Vec2i2Net(vIAside); |
| 402 |
TileClassGetName( |
| 403 |
a->u.Event.u.TileSet.ClassName, tc, tc->Style, "normal", |
| 404 |
tc->Mask, tc->MaskAlt); |
| 405 |
} |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
for (int i = 0; i < doorGroupCount; i++) |
| 411 |
{ |
| 412 |
const struct vec2i vI = svec2i_add(v, svec2i_scale(dv, (float)i)); |
| 413 |
const struct vec2i vIA = svec2i_subtract(vI, dAside); |
| 414 |
TileAddTrigger(MapGetTile(mb->Map, vIA), t); |
| 415 |
const struct vec2i vIB = svec2i_add(vI, dAside); |
| 416 |
TileAddTrigger(MapGetTile(mb->Map, vIB), t); |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
a = TriggerAddAction(t); |
| 421 |
a->Type = ACTION_EVENT; |
| 422 |
a->u.Event = GameEventNew(GAME_EVENT_SOUND_AT); |
| 423 |
strcpy(a->u.Event.u.SoundAt.Sound, "door"); |
| 424 |
a->u.Event.u.SoundAt.Pos = Vec2ToNet(Vec2CenterOfTile( |
| 425 |
svec2i_add(v, svec2i_scale(dv, (float)doorGroupCount / 2)))); |
| 426 |
|
| 427 |
return t; |
| 428 |
} |
| 429 |
static void TileAddTrigger(Tile *t, Trigger *tr) |
| 430 |
{ |
| 431 |
if (t == NULL) |
| 432 |
return; |
| 433 |
CArrayPushBack(&t->triggers, &tr); |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
static void DoorGetTypeName(char *buf, const char *key, const DoorType type) |
| 440 |
{ |
| 441 |
const char *typeStr = ""; |
| 442 |
if (strcmp(key, "wall") == 0) |
| 443 |
{ |
| 444 |
|
| 445 |
} |
| 446 |
else if (strcmp(key, "open") == 0) |
| 447 |
{ |
| 448 |
typeStr = DoorTypeIsHorizontal(type) ? "_h" : "_v"; |
| 449 |
} |
| 450 |
else |
| 451 |
{ |
| 452 |
switch (type) |
| 453 |
{ |
| 454 |
case DOORTYPE_H: |
| 455 |
typeStr = "_h"; |
| 456 |
break; |
| 457 |
case DOORTYPE_LEFT: |
| 458 |
typeStr = "_left"; |
| 459 |
break; |
| 460 |
case DOORTYPE_HMID: |
| 461 |
typeStr = "_hmid"; |
| 462 |
break; |
| 463 |
case DOORTYPE_RIGHT: |
| 464 |
typeStr = "_right"; |
| 465 |
break; |
| 466 |
case DOORTYPE_V: |
| 467 |
typeStr = "_v"; |
| 468 |
break; |
| 469 |
case DOORTYPE_TOP: |
| 470 |
typeStr = "_top"; |
| 471 |
break; |
| 472 |
case DOORTYPE_VMID: |
| 473 |
typeStr = "_vmid"; |
| 474 |
break; |
| 475 |
case DOORTYPE_BOTTOM: |
| 476 |
typeStr = "_bottom"; |
| 477 |
break; |
| 478 |
default: |
| 479 |
CASSERT(false, "unknown doortype"); |
| 480 |
break; |
| 481 |
} |
| 482 |
} |
| 483 |
sprintf(buf, "%s%s", key, typeStr); |
| 484 |
} |
| 485 |
static void DoorGetClassName( |
| 486 |
char *buf, const TileClass *door, const char *key, const DoorType dType) |
| 487 |
{ |
| 488 |
char type[256]; |
| 489 |
DoorGetTypeName(type, key, dType); |
| 490 |
const color_t mask = strcmp(key, "normal") == 0 ? door->Mask : colorWhite; |
| 491 |
const color_t maskAlt = |
| 492 |
strcmp(key, "normal") == 0 ? door->MaskAlt : colorWhite; |
| 493 |
|
| 494 |
TileClassGetName(buf, door, door->Style, type, mask, maskAlt); |
| 495 |
} |
| 496 |
void DoorAddClass( |
| 497 |
map_t c, PicManager *pm, const TileClass *base, const char *key, |
| 498 |
const DoorType type) |
| 499 |
{ |
| 500 |
char buf[CDOGS_FILENAME_MAX]; |
| 501 |
DoorGetTypeName(buf, key, type); |
| 502 |
const color_t mask = strcmp(key, "normal") == 0 ? base->Mask : colorWhite; |
| 503 |
const color_t maskAlt = |
| 504 |
strcmp(key, "normal") == 0 ? base->MaskAlt : colorWhite; |
| 505 |
PicManagerGenerateMaskedStylePic( |
| 506 |
pm, "door", base->Style, buf, mask, maskAlt, true); |
| 507 |
TileClass *t = |
| 508 |
TileClassesAdd(c, pm, base, base->Style, buf, mask, maskAlt); |
| 509 |
CASSERT(t != NULL, "cannot add door class"); |
| 510 |
const bool isOpenOrWallCavity = |
| 511 |
strcmp(key, "open") == 0 || strcmp(key, "wall") == 0; |
| 512 |
t->isOpaque = !isOpenOrWallCavity; |
| 513 |
t->canWalk = isOpenOrWallCavity; |
| 514 |
t->shootable = !isOpenOrWallCavity; |
| 515 |
} |
| 516 |
|
| 517 |
#define DOORSTYLE_COUNT 4 |
| 518 |
const char *IntDoorStyle(const int i) |
| 519 |
{ |
| 520 |
static const char *doorStyles[] = {"office", "dungeon", "blast", "alien"}; |
| 521 |
|
| 522 |
return doorStyles[abs(i) % DOORSTYLE_COUNT]; |
| 523 |
} |
| 524 |
|
| 525 |
static void DoorDrawPic( |
| 526 |
const Pic *pic, const struct vec2i pos, const bool crop, const int dy, |
| 527 |
const int bottom, const color_t mask); |
| 528 |
void DoorDraw(const DoorState *d, const struct vec2i pos, const color_t mask) |
| 529 |
{ |
| 530 |
if (d->Class2) |
| 531 |
{ |
| 532 |
DoorDrawPic(d->Class2->Pic, pos, false, 0, 0, mask); |
| 533 |
} |
| 534 |
if (d->Class && d->Class->Pic && (!d->IsOpen || d->Count > 0)) |
| 535 |
{ |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
const int bottom = |
| 540 |
d->IsHorizontal ? TILE_HEIGHT * 2 - d->Class->Pic->size.y : 0; |
| 541 |
const int doorHCropped = d->Class->Pic->size.y - bottom; |
| 542 |
const double fdy = |
| 543 |
d->IsOpen |
| 544 |
? CircularEaseOut( |
| 545 |
(DOORSTATE_COUNT - d->Count) / (double)DOORSTATE_COUNT) |
| 546 |
: CircularEaseIn(d->Count / (double)DOORSTATE_COUNT); |
| 547 |
const int dy = (int)(fdy * doorHCropped); |
| 548 |
DoorDrawPic(d->Class->Pic, pos, d->IsHorizontal, dy, bottom, mask); |
| 549 |
} |
| 550 |
} |
| 551 |
static void DoorDrawPic( |
| 552 |
const Pic *pic, const struct vec2i pos, const bool crop, const int dy, |
| 553 |
const int bottom, const color_t mask) |
| 554 |
{ |
| 555 |
if (!pic) |
| 556 |
{ |
| 557 |
return; |
| 558 |
} |
| 559 |
struct vec2i offset = |
| 560 |
svec2i((TILE_WIDTH - pic->size.x) / 2, WALL_OFFSET_Y + dy); |
| 561 |
if (pic->size.y > 16) |
| 562 |
{ |
| 563 |
offset.y += TILE_HEIGHT - (pic->size.y % TILE_HEIGHT); |
| 564 |
} |
| 565 |
Rect2i src = Rect2iNew( |
| 566 |
svec2i_zero(), |
| 567 |
svec2i(pic->size.x, pic->size.y - (crop ? dy + bottom : 0))); |
| 568 |
Rect2i dest = Rect2iNew(svec2i_add(pos, offset), src.Size); |
| 569 |
TextureRender( |
| 570 |
pic->Tex, gGraphicsDevice.gameWindow.renderer, src, dest, mask, 0.0, |
| 571 |
SDL_FLIP_NONE); |
| 572 |
} |