Skip to content

Commit 131d185

Browse files
authored
Merge pull request #5687 from quietust/drawbridge-tiles
Add drawbridge-tiles tweak for ASCII mode
2 parents a4714bc + 0645b12 commit 131d185

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Template for new versions:
9898

9999
## New Features
100100
- `sort`: Places search widget can search "Siege engines" subtab by name, loaded status, and operator status
101+
- `tweak`: ``drawbridge-tiles``: Make it so raised bridges render with different tiles in ASCII mode to make it more obvious that they ARE raised (and to indicate their direction)
101102

102103
## Fixes
103104
- `sort`: Using the squad unit selector will no longer cause Dwarf Fortress to crash on exit

docs/plugins/tweak.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ Commands
4545
Fixes crafted items not wearing out over time (:bug:`6003`). With this
4646
tweak, items made from cloth and leather will gain a level of wear every 20
4747
in-game years.
48+
``drawbridge-tiles``
49+
Makes raising bridges in ASCII mode render with different tiles when they
50+
are raised.
4851
``eggs-fertile``
4952
Displays an indicator on fertile eggs.
5053
``fast-heat``

plugins/tweak/tweak.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using namespace DFHack;
1616
#include "tweaks/adamantine-cloth-wear.h"
1717
#include "tweaks/animaltrap-reuse.h"
1818
#include "tweaks/craft-age-wear.h"
19+
#include "tweaks/drawbridge-tiles.h"
1920
#include "tweaks/eggs-fertile.h"
2021
#include "tweaks/fast-heat.h"
2122
#include "tweaks/flask-contents.h"
@@ -58,6 +59,8 @@ DFhackCExport command_result plugin_init(color_ostream &out, vector<PluginComman
5859

5960
TWEAK_HOOK("craft-age-wear", craft_age_wear_hook, ageItem);
6061

62+
TWEAK_HOOK("drawbridge-tiles", drawbridge_tiles_hook, drawBuilding);
63+
6164
TWEAK_HOOK("eggs-fertile", eggs_fertile_hook, getItemDescription);
6265

6366
TWEAK_HOOK("fast-heat", fast_heat_hook, updateTempFromMap);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Make raised drawbridge tiles indicate the bridge's direction
2+
3+
#include "df/building_drawbuffer.h"
4+
#include "df/building_bridgest.h"
5+
6+
struct drawbridge_tiles_hook : df::building_bridgest {
7+
typedef df::building_bridgest interpose_base;
8+
9+
DEFINE_VMETHOD_INTERPOSE(void, drawBuilding, (uint32_t curtick, df::building_drawbuffer *buf, int16_t z_offset))
10+
{
11+
static const unsigned char tiles[4][3] =
12+
{
13+
{ 0xB7, 0xB6, 0xBD },
14+
{ 0xD6, 0xC7, 0xD3 },
15+
{ 0xD4, 0xCF, 0xBE },
16+
{ 0xD5, 0xD1, 0xB8 },
17+
};
18+
INTERPOSE_NEXT(drawBuilding)(curtick, buf, z_offset);
19+
20+
// Only redraw "raised" drawbridges
21+
if (!gate_flags.bits.raised || direction == -1)
22+
return;
23+
24+
// Figure out the extents and the axis
25+
int p1, p2;
26+
bool iy = false;
27+
switch (direction)
28+
{
29+
case 0: // Left
30+
case 1: // Right
31+
p1 = buf->y1; p2 = buf->y2; iy = true;
32+
break;
33+
case 2: // Up
34+
case 3: // Down
35+
p1 = buf->x1; p2 = buf->x2;
36+
break;
37+
default:
38+
// Already ignoring retracting above
39+
return;
40+
}
41+
42+
int x = 0, y = 0;
43+
if (p1 == p2)
44+
buf->tile[0][0] = tiles[direction][1];
45+
else for (int p = p1; p <= p2; p++)
46+
{
47+
if (p == p1)
48+
buf->tile[x][y] = tiles[direction][0];
49+
else if (p == p2)
50+
buf->tile[x][y] = tiles[direction][2];
51+
else
52+
buf->tile[x][y] = tiles[direction][1];
53+
if (iy)
54+
y++;
55+
else
56+
x++;
57+
}
58+
}
59+
};
60+
IMPLEMENT_VMETHOD_INTERPOSE(drawbridge_tiles_hook, drawBuilding);

0 commit comments

Comments
 (0)