[3.5-dev] Monster opening/bashing refactoring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PowerWyrm
    Prophet
    • Apr 2008
    • 2986

    [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.
    PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!
  • AnonymousHero
    Veteran
    • Jun 2007
    • 1393

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

    Comment

    • takkaria
      Veteran
      • Apr 2007
      • 1951

      #3
      Originally posted by AnonymousHero
      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!
      takkaria whispers something about options. -more-

      Comment

      • PowerWyrm
        Prophet
        • Apr 2008
        • 2986

        #4
        Something is slamming against my head!!!!!!

        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...

        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;
        		}
        	}
        }
        PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!

        Comment

        Working...
        😀
        😂
        🥰
        😘
        🤢
        😎
        😞
        😡
        👍
        👎