Regen and Bleed

Given that I haven’t updated the blog with fun bits of code in a while, here’s a bit to add to the community: BLEED and REGEN affects.

I’m not going to go too in depth here, if you need help adding AFF_ flags to the stock code, leave a response and I’ll get into it in more detail.  Also, you should know how to add bitvector values to spells (see the Sanctuary spell).

Bleed and regen affects are unlike most other affects, instead of applying every tick (how useful is hp/tick when fights last less than 1 tick), they are applied every round (but only when you’re fighting).

Code after the jump.

if (AFF_FLAGGED(ch, AFF_REGEN)) {
 if (!IS_NPC(ch)) {
 for (af = ch->affected; af; af = naff) {
 naff = af->next;
 if (af->type == SPELL_REGEN) {
 GET_HIT(ch) = MIN(GET_HIT(ch) + af->modifier, GET_MAX_HIT(ch));
 if (!(af->duration--)) {
 if (spell_info[af->type].wear_off_msg)
 send_to_char(ch, "%s\r\n", spell_info[af->type].wear_off_msg);
 affect_remove(ch, af); }
 }
 }
 } /* End of player regen */
 else
 GET_HIT(ch) = MIN(GET_HIT(ch) + GET_LEVEL(ch), GET_MAX_HIT(ch));
 }

That’s the REGEN code, added to FIGHT.C in the perform_violence function.  If a character isn’t fighting, assuming you add the affect through a spell, it will tick off regularly.  Also, mobs can be affected with the REGEN special ability during creation (MEDIT), which will give them a permanent regeneration special ability.

Here’s bleed, it’s similar to REGEN, except I added a check so that mobs can’t bleed out.  Basically, I did this because the damage() function handles the issue, and I don’t want to deal with it here.

if (AFF_FLAGGED(ch, AFF_BLEED)) {
 if ((af = affected_by_spell(ch, SKILL_THRUST))) {
 if (GET_HIT(ch) > af->modifier) {             /* Monsters can't be killed by bleed effects */
 GET_HIT(ch) = GET_HIT(ch) - af->modifier;
 send_to_char(ch, "Your wounds continue to bleed!");
 act("$n's wounds seep blood.", FALSE, ch, 0, 0, TO_ROOM);
 }
 if (!(af->duration--)) {
 affect_remove(ch, af);
 send_to_char(ch, "Your wounds stop bleeding.");
 }
 }
 else if (GET_HIT(ch) > GET_LEVEL(ch))
 GET_HIT(ch) -= GET_LEVEL(ch);
 }

Enjoy!

Leave a comment