View Single Post
Old June 27, 2013, 12:19   #4
PowerWyrm
Prophet
 
PowerWyrm's Avatar
 
Join Date: Apr 2008
Posts: 2,857
PowerWyrm is on a distinguished road
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 http://powerwyrm.monsite-orange.fr (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!
PowerWyrm is offline   Reply With Quote