Angband Forums

Angband Forums (
-   Development (
-   -   locked doors? (

eastwind January 30, 2020 03:45

locked doors?
I was messing around with the town a little bit, and I wanted to add some extra non-shop buildings, with doors, that the player couldn't open. Just for color, to make it look like there were some homes in the town or whatever.

How do I lock a door against the player? I called square_set_door_lock() and gave it a high power, and stepped through the code for that routine and it did it's thing. The lock doesn't show up for the player (because that's the way the trap is defined) but it also doesn't stop the player from opening the door.

Are doors now lockable only against monsters?

Also, I thought I remembered seeing a shockbolt tile of a door with a chain and lock across it, and I can't find that tile anymore either.

Time to punt on this? I can always make the extra buildings doorless, but that's less flavorful.

wobbly January 30, 2020 07:08

In cmd-cave.c


 * Determine if a given grid may be "opened"
static bool do_cmd_open_test(struct loc grid)
        /* Must have knowledge */
        if (!square_isknown(cave, grid)) {
                msg("You see nothing there.");
                return false;

        /* Must be a closed door */
        if (!square_iscloseddoor(cave, grid)) {
                msgt(MSG_NOTHING_TO_OPEN, "You see nothing there to open.");
                return false;

        return (true);

I'd add an extra check for permalocked door, though you'd have to add the relevant bit in cave-square.c & the routine to set a permalocked door.

Another way you can do it would be to make lock values > x unpickable. Anyway you can look through the door opening code in cmd-cave.c & see if there's anything you are comfortable changing.

wobbly January 30, 2020 08:54

A bit hack-ish, but you can just bar lock picking on dlvl 0

eastwind January 30, 2020 20:32

Ok, yeah, thanks, I can make a code change to do it for sure. I was setting power=99 for the lock trap, so I could test for that, or depth==0 as you say, either one.

I was trying to figure out if there was (already) a 'standard' way to do it and follow that, so if not, then inventing a way is no prob.



        /* For newtown, don't allow breaking in buildings there for color */
        if (player->depth == 0) {
                msg("The door is securely locked against adventuresome burglers.");
                return false;

Pete Mack January 30, 2020 22:54

Don't use depth == 0, because it will screw things up if a mage casts create doors. They will be stuck inside, and in principle can permanently close off a store entrance. (Doors created in town are permanent.)

eastwind January 31, 2020 02:41

Ok, so I looked at the caller, do_cmd_open_aux(), set a breakpoint in it, and discovered that trying to move onto the door one time actually rolls 100 times for lock picking. Given that do_cmd_open_aux() enforces a minimum 2% chance of success on each roll, any character with any level of lockpicking skill will succeed against any lock with any power 87% of the time. 1-(.98^100).

When I comment out the minimum 2% enforcement line, I get
"you failed to pick the lock" (100x).

So I could put a specific check in do_cmd_open_aux() for depth == 0 *and* power > 90, and set the power of the doors I make > 90 and then if a wizard creates another door it won't have power > 90 (I assume) and so that new door will be openable.

if ((player->depth == 0) && (j > 90)) {
/* print special you-fail message */

and if I put this before j is changed from power to difficulty, it should work, but will print the special you-fail message 100 times each time they try.

IMHO 100 rolls is too many to give on one player try.

eastwind January 31, 2020 02:53

if ((player->depth == 0) && (j > 90))
msgt(MSG_LOCKPICK_FAIL, "The town resident has securely locked his home's door against adventurous burglers.");

I learned returning false makes it not keep trying, so you only get the message once. This has to go above

/* Extract the difficulty XXX XXX XXX */
j = i - (j * 4);

/* Always have a small chance of success */
if (j < 2) j = 2;

Derakon January 31, 2020 03:59

The 100 attempts is presumably due to auto-repeating safe commands. You'd get fewer repetitions if there was an enemy moving around in your vision, or you were poisoned, or there was something else going on to disturb you. Each attempt still takes a turn.

Pete Mack January 31, 2020 04:27

Just realized I was wrong. The doors in "create doors" are always unlocked, so just banning lock-picking is OK, so long as unlocked doors still open.

All times are GMT +1. The time now is 23:37.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.