Esempio n. 1
0
/**
 * Increases the timed effect `ef_idx` by `timer`.
 *
 * Calculates the new timer, then passes that to mon_set_timed().
 * Note that each effect has a maximum number of turns it can be active for.
 * If this function would put an effect timer over that cap, it sets it for
 * that cap instead.
 *
 * Returns true if the monster's timer changed.
 */
bool mon_inc_timed(struct monster *mon, int ef_idx, int timer, u16b flag,
				   bool id)
{
	struct mon_timed_effect *effect;

	assert(ef_idx >= 0 && ef_idx < MON_TMD_MAX);
	effect = &effects[ef_idx];

	/* For negative amounts, we use mon_dec_timed instead */
	assert(timer > 0);

	/* Make it last for a mimimum # of turns if it is a new effect */
	if ((!mon->m_timed[ef_idx]) && (timer < 2)) timer = 2;

	/* New counter amount - prevent overflow */
	if (SHRT_MAX - timer < mon->m_timed[ef_idx])
		timer = SHRT_MAX;
	else
		timer += mon->m_timed[ef_idx];

	/* Reduce to max_timer if necessary*/
	if (timer > effect->max_timer)
		timer = effect->max_timer;

	return mon_set_timed(mon, ef_idx, timer, flag, id);
}
Esempio n. 2
0
/**
 * Increases the timed effect `ef_idx` by `timer`.
 *
 * Calculates the new timer, then passes that to mon_set_timed().
 * Note that each effect has a maximum number of turns it can be active for.
 * If this function would put an effect timer over that cap, it sets it for
 * that cap instead.
 *
 * Returns TRUE if the monster's timer changed.
 */
bool mon_inc_timed(int m_idx, int ef_idx, int timer, u16b flag, bool id)
{
	monster_type *m_ptr;
	mon_timed_effect *effect;

	assert(ef_idx >= 0 && ef_idx < MON_TMD_MAX);
	effect = &effects[ef_idx];

	assert(m_idx > 0);
	m_ptr = cave_monster(cave, m_idx);

	/* For negative amounts, we use mon_dec_timed instead */
	assert(timer > 0);

	/* Make it last for a mimimum # of turns if it is a new effect */
	if ((!m_ptr->m_timed[ef_idx]) && (timer < 2)) timer = 2;

	/* New counter amount - prevent overflow */
	if (MAX_SHORT - timer < m_ptr->m_timed[ef_idx])
		timer = MAX_SHORT;
	else
		timer += m_ptr->m_timed[ef_idx];

	/* Reduce to max_timer if necessary*/
	if (timer > effect->max_timer)
		timer = effect->max_timer;

	return mon_set_timed(m_ptr, ef_idx, timer, flag, id);
}
Esempio n. 3
0
/**
 * Clears the timed effect `ef_idx`.
 *
 * Returns true if the monster's timer was changed.
 */
bool mon_clear_timed(struct monster *mon, int ef_idx, u16b flag, bool id)
{
	assert(ef_idx >= 0 && ef_idx < MON_TMD_MAX);

	if (!mon->m_timed[ef_idx]) return false;

	/* Clearing never fails */
	flag |= MON_TMD_FLG_NOFAIL;

	return mon_set_timed(mon, ef_idx, 0, flag, id);
}
Esempio n. 4
0
/**
 * Decreases the timed effect `ef_idx` by `timer`.
 *
 * Calculates the new timer, then passes that to mon_set_timed().
 * If a timer would be set to a negative number, it is set to 0 instead.
 * Note that decreasing a timed effect should never fail.
 *
 * Returns TRUE if the monster's timer changed.
 */
bool mon_dec_timed(struct monster *m_ptr, int ef_idx, int timer, u16b flag, bool id)
{
	assert(ef_idx >= 0 && ef_idx < MON_TMD_MAX);
	assert(timer > 0);

	/* Decreasing is never resisted */
	flag |= MON_TMD_FLG_NOFAIL;

	/* New counter amount */
	timer = m_ptr->m_timed[ef_idx] - timer;
	if (timer < 0)
		timer = 0;

	return mon_set_timed(m_ptr, ef_idx, timer, flag, id);
}
Esempio n. 5
0
/**
 * Clears the timed effect `ef_idx`.
 *
 * Returns TRUE if the monster's timer was changed.
 */
bool mon_clear_timed(int m_idx, int ef_idx, u16b flag, bool id)
{
	monster_type *m_ptr;

	assert(ef_idx >= 0 && ef_idx < MON_TMD_MAX);

	assert(m_idx > 0);
	m_ptr = cave_monster(cave, m_idx);

	if (!m_ptr->m_timed[ef_idx]) return FALSE;

	/* Clearing never fails */
	flag |= MON_TMD_FLG_NOFAIL;

	return mon_set_timed(m_ptr, ef_idx, 0, flag, id);
}