Skip to content

Commit 6b32507

Browse files
committed
(WIP) feature: locked door variants
1 parent f78033c commit 6b32507

13 files changed

Lines changed: 175 additions & 43 deletions

data/760/walls.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<wall type="horizontal">
8686
<item id="1037" chance="100"/>
8787
<item id="1532" chance="0"/>
88-
<door id="1212" type="normal" open="false"/>
88+
<door id="1212" type="normal" open="false" locked="true"/>
8989
<door id="1213" type="normal" open="false"/>
9090
<door id="1214" type="normal" open="true"/>
9191
<door id="1221" type="locked" open="false"/>
@@ -100,7 +100,7 @@
100100
</wall>
101101
<wall type="vertical">
102102
<item id="1036" chance="100"/>
103-
<door id="1209" type="normal" open="false"/>
103+
<door id="1209" type="normal" open="false" locked="true"/>
104104
<door id="1210" type="normal" open="false"/>
105105
<door id="1211" type="normal" open="true"/>
106106
<door id="1219" type="locked" open="false"/>
@@ -185,7 +185,7 @@
185185
<brush name="sandstone wall" type="wall" server_lookid="1061">
186186
<wall type="horizontal">
187187
<item id="1061" chance="100"/>
188-
<door id="1234" type="normal" open="false"/>
188+
<door id="1234" type="normal" open="false" locked="true"/>
189189
<door id="1235" type="normal" open="false"/>
190190
<door id="1236" type="normal" open="true"/>
191191
<door id="1239" type="locked" open="false"/>
@@ -198,7 +198,7 @@
198198
</wall>
199199
<wall type="vertical">
200200
<item id="1060" chance="100"/>
201-
<door id="1231" type="normal" open="false"/>
201+
<door id="1231" type="normal" open="false" locked="true"/>
202202
<door id="1232" type="normal" open="false"/>
203203
<door id="1233" type="normal" open="true"/>
204204
<door id="1237" type="locked" open="false"/>
@@ -358,7 +358,7 @@
358358
<item id="1168" chance="0"/>
359359
<item id="1178" chance="0"/>
360360
<item id="1176" chance="0"/>
361-
<door id="1252" type="normal" open="false"/>
361+
<door id="1252" type="normal" open="false" locked="true"/>
362362
<door id="1253" type="normal" open="false"/>
363363
<door id="1254" type="normal" open="true"/>
364364
<door id="1257" type="quest" open="false"/>
@@ -405,7 +405,7 @@
405405
<item id="1169" chance="0"/>
406406
<item id="1177" chance="0"/>
407407
<item id="1179" chance="0"/>
408-
<door id="1249" type="normal" open="false"/>
408+
<door id="1249" type="normal" open="false" locked="true"/>
409409
<door id="1250" type="normal" open="false"/>
410410
<door id="1251" type="normal" open="true"/>
411411
<door id="1255" type="quest" open="false"/>
@@ -1122,7 +1122,7 @@
11221122
<wall type="horizontal">
11231123
<item id="3424" chance="100"/>
11241124
<item id="3447" chance="100"/>
1125-
<door id="3535" type="normal" open="false"/>
1125+
<door id="3535" type="normal" open="false" locked="true"/>
11261126
<door id="3536" type="normal" open="false"/>
11271127
<door id="3537" type="normal" open="true"/>
11281128
<door id="3538" type="locked" open="false"/>
@@ -1137,7 +1137,7 @@
11371137
<wall type="vertical">
11381138
<item id="3423" chance="100"/>
11391139
<item id="3450" chance="100"/>
1140-
<door id="3544" type="normal" open="false"/>
1140+
<door id="3544" type="normal" open="false" locked="true"/>
11411141
<door id="3545" type="normal" open="false"/>
11421142
<door id="3546" type="normal" open="true"/>
11431143
<door id="3547" type="locked" open="false"/>
@@ -1693,7 +1693,7 @@
16931693
<wall type="horizontal">
16941694
<item id="5005" chance="100"/>
16951695
<item id="4912" chance="0"/>
1696-
<door id="4916" type="normal" open="false"/>
1696+
<door id="4916" type="normal" open="false" locked="true"/>
16971697
<door id="4917" type="normal" open="false"/>
16981698
<door id="4918" type="normal" open="true"/>
16991699
<door id="5084" type="locked" open="false"/>
@@ -1703,7 +1703,7 @@
17031703
<wall type="vertical">
17041704
<item id="5004" chance="100"/>
17051705
<item id="4921" chance="0"/>
1706-
<door id="4913" type="normal" open="false"/>
1706+
<door id="4913" type="normal" open="false" locked="true"/>
17071707
<door id="4914" type="normal" open="false"/>
17081708
<door id="4915" type="normal" open="true"/>
17091709
<door id="5082" type="locked" open="false"/>

source/brush.cpp

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -349,20 +349,20 @@ void DoorBrush::switchDoor(Item* item)
349349
ASSERT(item->isBrushDoor());
350350

351351
WallBrush* wb = item->getWallBrush();
352-
if(!wb) return;
352+
if (!wb) {
353+
return;
354+
}
353355

354356
bool new_open = !item->isOpen();
355357
BorderType wall_alignment = item->getWallAlignment();
356-
DoorType doortype = WALL_UNDEFINED;
357358

358-
for(std::vector<WallBrush::DoorType>::iterator iter = wb->door_items[wall_alignment].begin(); iter != wb->door_items[wall_alignment].end(); ++iter) {
359-
WallBrush::DoorType& dt = *iter;
360-
if(dt.id == item->getID()) {
361-
doortype = dt.type;
362-
break;
363-
}
359+
DoorType doortype = wb->getDoorTypeFromID(item->getID());
360+
if (doortype == WALL_UNDEFINED) {
361+
return;
364362
}
365-
if(doortype == WALL_UNDEFINED) return;
363+
364+
uint16_t oppositeVariant = 0; // give locked/unlocked variant if preferred is unavailable
365+
bool prefLocked = g_gui.HasDoorLocked();
366366

367367
for(std::vector<WallBrush::DoorType>::iterator iter = wb->door_items[wall_alignment].begin(); iter != wb->door_items[wall_alignment].end(); ++iter) {
368368
WallBrush::DoorType& dt = *iter;
@@ -372,11 +372,19 @@ void DoorBrush::switchDoor(Item* item)
372372
ASSERT(it.id != 0);
373373

374374
if(it.isOpen == new_open) {
375-
item->setID(dt.id);
376-
return;
375+
if (!new_open || dt.locked == prefLocked) {
376+
item->setID(dt.id);
377+
return;
378+
} else {
379+
oppositeVariant = dt.id;
380+
}
377381
}
378382
}
379383
}
384+
385+
if (oppositeVariant != 0) {
386+
item->setID(oppositeVariant);
387+
}
380388
}
381389

382390
bool DoorBrush::canDraw(BaseMap* map, const Position& position) const
@@ -406,6 +414,8 @@ bool DoorBrush::canDraw(BaseMap* map, const Position& position) const
406414
open = item->isOpen();
407415
}
408416

417+
bool prefLocked = g_gui.HasDoorLocked();
418+
409419
WallBrush* test_brush = wb;
410420
do {
411421
for(std::vector<WallBrush::DoorType>::iterator iter = test_brush->door_items[wall_alignment].begin();
@@ -418,7 +428,12 @@ bool DoorBrush::canDraw(BaseMap* map, const Position& position) const
418428
ASSERT(it.id != 0);
419429

420430
if(it.isOpen == open) {
421-
return true;
431+
if (open || dt.locked == prefLocked) {
432+
return true;
433+
} else {
434+
discarded_id = dt.id;
435+
close_match = true;
436+
}
422437
} else if(!close_match) {
423438
discarded_id = dt.id;
424439
close_match = true;
@@ -481,6 +496,8 @@ void DoorBrush::draw(BaseMap* map, Tile* tile, void* parameter)
481496
open = item->isOpen();
482497
}
483498

499+
bool prefLocked = g_gui.HasDoorLocked();
500+
484501
WallBrush* test_brush = wb;
485502
do {
486503
for(std::vector<WallBrush::DoorType>::iterator iter = test_brush->door_items[wall_alignment].begin();
@@ -494,9 +511,14 @@ void DoorBrush::draw(BaseMap* map, Tile* tile, void* parameter)
494511
ASSERT(it.id != 0);
495512

496513
if(it.isOpen == open) {
497-
item = transformItem(item, dt.id, tile);
498-
perfect_match = true;
499-
break;
514+
if (open || dt.locked == prefLocked) {
515+
item = transformItem(item, dt.id, tile);
516+
perfect_match = true;
517+
break;
518+
} else {
519+
discarded_id = dt.id;
520+
close_match = true;
521+
}
500522
} else if(!close_match) {
501523
discarded_id = dt.id;
502524
close_match = true;
@@ -562,9 +584,14 @@ void DoorBrush::draw(BaseMap* map, Tile* tile, void* parameter)
562584
ASSERT(it.id != 0);
563585

564586
if(it.isOpen == open) {
565-
item = transformItem(item, dt.id, tile);
566-
perfect_match = true;
567-
break;
587+
if (open || dt.locked == prefLocked) {
588+
item = transformItem(item, dt.id, tile);
589+
perfect_match = true;
590+
break;
591+
} else {
592+
discarded_id = dt.id;
593+
close_match = true;
594+
}
568595
} else if(!close_match) {
569596
discarded_id = dt.id;
570597
close_match = true;

source/gui.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ GUI::GUI() :
8686
brush_variation(0),
8787

8888
creature_spawntime(0),
89+
draw_locked_doors(false),
8990
use_custom_thickness(false),
9091
custom_thickness_mod(0.0),
9192
progressBar(nullptr),
@@ -1639,6 +1640,17 @@ void GUI::IncreaseBrushSize(bool wrap)
16391640
}
16401641
}
16411642

1643+
void GUI::SetDoorLocked(bool on)
1644+
{
1645+
draw_locked_doors = on;
1646+
RefreshView();
1647+
}
1648+
1649+
bool GUI::HasDoorLocked()
1650+
{
1651+
return draw_locked_doors;
1652+
}
1653+
16421654
Brush* GUI::GetCurrentBrush() const
16431655
{
16441656
return current_brush;

source/gui.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ class GUI
250250
// Helper functions for size
251251
void DecreaseBrushSize(bool wrap = false);
252252
void IncreaseBrushSize(bool wrap = false);
253-
253+
// Door brush options
254+
void SetDoorLocked(bool on);
255+
bool HasDoorLocked();
254256

255257
// Fetch different useful directories
256258
static wxString GetExecDirectory();
@@ -423,6 +425,7 @@ class GUI
423425
int brush_variation;
424426
int creature_spawntime;
425427

428+
bool draw_locked_doors;
426429
bool use_custom_thickness;
427430
float custom_thickness_mod;
428431

source/gui_ids.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ enum EditorActionID
147147
PALETTE_TERRAIN_BRUSHSIZE_8,
148148
PALETTE_TERRAIN_BRUSHSIZE_11,
149149

150+
PALETTE_TERRAIN_LOCK_DOOR,
151+
150152
MAP_PROPERTIES_VERSION,
151153

152154
ITEM_PROPERTIES_GENERAL_TAB,

source/items.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ class ItemType {
357357
bool isOptionalBorder;
358358
bool isWall;
359359
bool isBrushDoor;
360-
bool isOpen;
360+
bool isOpen; // door or window physically open
361+
bool isLocked; // door key locked
361362
bool isTable;
362363
bool isCarpet;
363364

source/map_drawer.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,12 @@ void MapDrawer::BlitItem(int& draw_x, int& draw_y, const Tile* tile, Item* item,
10381038
void MapDrawer::BlitItem(int& draw_x, int& draw_y, const Position& pos, Item* item, bool ephemeral, int red, int green, int blue, int alpha, const Tile* tile) {
10391039
ItemType& it = g_items[item->getID()];
10401040

1041+
// Locked door indicator
1042+
if (it.isDoor() && it.isLocked) {
1043+
blue /= 2;
1044+
green /= 2;
1045+
}
1046+
10411047
if(!options.ingame && !ephemeral && item->isSelected()) {
10421048
red /= 2;
10431049
blue /= 2;
@@ -1076,9 +1082,9 @@ void MapDrawer::BlitItem(int& draw_x, int& draw_y, const Position& pos, Item* it
10761082
return;
10771083
}
10781084

1085+
// Light source (green flame + square with estimated light strength)
10791086
bool lightSourceFilter = false;
10801087
GameSprite* spr = it.sprite;
1081-
// Light source
10821088
if ((it.clientID >= 39092 && it.clientID <= 39100 || it.clientID == 39236 || it.clientID == 39367 || it.clientID == 39368) && !options.ingame) {
10831089
spr = g_items[SPRITE_LIGHTSOURCE].sprite;
10841090
red = 0;
@@ -1166,10 +1172,11 @@ void MapDrawer::BlitItem(int& draw_x, int& draw_y, const Position& pos, Item* it
11661172
}
11671173
}
11681174

1175+
// draw wall hook
11691176
if (options.show_hooks && (it.hookSouth || it.hookEast) && zoom <= 3.0)
11701177
DrawHookIndicator(draw_x, draw_y, it);
11711178

1172-
// draw light color
1179+
// draw light color indicator
11731180
if (lightSourceFilter) {
11741181
int startOffsetX = 22;
11751182
int startOffsetY = 22;

0 commit comments

Comments
 (0)