Angband Forums

Angband Forums (http://angband.oook.cz/forum/index.php)
-   Vanilla (http://angband.oook.cz/forum/forumdisplay.php?f=3)
-   -   [3.5-dev] Monster opening/bashing refactoring (http://angband.oook.cz/forum/showthread.php?t=6105)

PowerWyrm May 23, 2013 10:09

[3.5-dev] Monster opening/bashing refactoring
 
Monster opening:

Code:

if (cave_iscloseddoor(cave, ny, nx) || cave_issecretdoor(cave, ny, nx))
{
    cave_open_door(c, ny, nx);
}
else if (cave_islockeddoor(cave, ny, nx))
{
    ...

    /* Handle viewable doors */
    if (player_has_los_bold(ny, nx))
        do_view = TRUE;
}

First problem: cave_iscloseddoor() defined in cave.c includes locked doors, so the "else" part is dead code; I think cave_iscloseddoor() should only define "closed non locked" doors so monsters don't open locked doors without a lock power check (I think there are similar problems elsewhere in the code where the wrong check is made).

Second problem: refreshing display (do_view) should be called when the door is opened, not when a monster only "fiddles" with a lock; so the corresponding code should be put in the "if" part, not the "else" part.


Monster bashing:

Code:

else if (rf_has(m_ptr->race->flags, RF_BASH_DOOR))
{
    bash door...
}

This means that monsters having both OPEN_DOOR and BASH_DOOR will always try to open a door instead of bashing it, making BASH_DOOR obsolete. Before the refactoring, monsters failing to unlock a door would try to bash it.

AnonymousHero May 24, 2013 16:35

Why is it that you don't have commit/push rights to the repo?

takkaria May 25, 2013 02:27

Quote:

Originally Posted by AnonymousHero (Post 80609)
Why is it that you don't have commit/push rights to the repo?

I have to admit, PowerWyrm, I'm consistently impressed with a) your tenacity and b) your eye for detail when it comes to bughunting. Thanks a lot for all the time you've spent reporting issues you've found - you catch so many of them that we miss!

PowerWyrm June 27, 2013 12:19

Something is slamming against my head!!!!!! :eek:

Code:

/* Stuck doors -- attempt to bash them down if allowed */
else if (rf_has(m_ptr->race->flags, RF_BASH_DOOR)) {
        int k = cave_door_power(cave, ny, nx);

        /* Print a message */
        if (m_ptr->ml)
                msg("%s slams against the door.", m_name);
        else
                msg("Something slams against a door.");

        /* Attempt to bash */
        if (randint0(m_ptr->hp / 10) > k && one_in_(2)) {
                cave_smash_door(c, ny, nx);
                msg("You hear a door burst open!");

                ...
        }
}

This message that repeats indefinitely every time something tries to bash a door on a level is extremely annoying... :mad:

Also for anything that has less than 20 hps (ants and such), bashing is not possible, so the poor thing will bump forever the door.

To fix this, and to simplify the code a lot (not mentioning the bugs from the previous post), it would be nice to process opening and bashing the same way:
- process closed and secret doors: choose between bashing and opening depending on the OPEN_DOOR and BASH_DOOR flags (50/50 chance if both are present)
- process locked doors: compute door power, try to unlock it, print a message if success and reduce the door power by one

Code should look like this:

Code:

/* Handle doors and secret doors */
else if (cave_iscloseddoor(cave, ny, nx) || cave_issecretdoor(cave, ny, nx))
{
        /* Take a turn */
        do_turn = TRUE;

        /* Learn about door abilities */
        if (m_ptr->ml) {
                rf_on(l_ptr->flags, RF_OPEN_DOOR);
                rf_on(l_ptr->flags, RF_BASH_DOOR);
        }

        /* Creature can open or bash doors */
        if (rf_has(m_ptr->race->flags, RF_OPEN_DOOR) || rf_has(m_ptr->race->flags, RF_BASH_DOOR))
        {
                bool may_bash = ((rf_has(m_ptr->race->flags, RF_BASH_DOOR) && one_in_(2))? TRUE: FALSE);

                /* Stuck door -- try to unlock it */
                if (cave_islockeddoor(cave, ny, nx))
                {
                        int k = cave_door_power(cave, ny, nx);

                        if (randint0(m_ptr->hp / 10) > k)
                        {
                                /* Print a message */
                                if (m_ptr->ml)
                                {
                                        if (may_bash)
                                                msg("%s slams against the door.", m_name);
                                        else
                                                msg("%s fiddles with the lock.", m_name);
                                }
                                else
                                {
                                        if (may_bash)
                                                msg("Something slams against a door.");
                                        else
                                                msg("Something fiddles with a lock.");
                                }

                                /* Reduce the power of the door by one */
                                cave_set_feat(c, ny, nx, cave->feat[ny][nx] - 1);
                        }
                }

                /* Closed or secret door -- open or bash if allowed */
                else
                {
                        if (may_bash)
                        {
                                cave_smash_door(c, ny, nx);
                                msg("You hear a door burst open!");

                                disturb(p_ptr, 0, 0);

                                /* Fall into doorway */
                                do_move = TRUE;
                        }
                        else
                                cave_open_door(c, ny, nx);

                        /* Handle viewable doors */
                        if (player_has_los_bold(ny, nx))
                                do_view = TRUE;
                }
        }
}



All times are GMT +1. The time now is 08:18.

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