Welcome to the Builder Academy

Question What is the point of handler.c affect_total()?

More
06 Dec 2023 06:10 #10357 by jandulio
I've looked at the function affect_total() in handler.c for a while now, and I am baffled why it's needed.

It looks to me like it:
1) Removes the current affect bits and affect attribute modifiers
2) Resets attributes to default attributes
3) Adds the current affect bits and affect attribute modifiers

So remove everything, then put it all back.  Why?

As a test, I commented out the contents of the function and reran my mud.  Then I casted spells, did Imm "set" commands, removed items with attribute affects, waited for spells to fall off, etc. and it seems to be working fine.

I must be missing something, can someone help me?

Here is the function:
Code:
/* This updates a character by subtracting everything he is affected by * restoring original abilities, and then affecting all again. */ void affect_total(struct char_data *ch) {   struct affected_type *af;   int i, j;   for (i = 0; i < NUM_WEARS; i++) {     if (GET_EQ(ch, i))       for (j = 0; j < MAX_OBJ_AFFECT; j++) affect_modify_ar(ch, GET_EQ(ch, i)->affected[j].location,       GET_EQ(ch, i)->affected[j].modifier,       GET_OBJ_AFFECT(GET_EQ(ch, i)), FALSE);   }   for (af = ch->affected; af; af = af->next)     affect_modify_ar(ch, af->location, af->modifier, af->bitvector, FALSE);   ch->aff_abils = ch->real_abils;   for (i = 0; i < NUM_WEARS; i++) {     if (GET_EQ(ch, i))       for (j = 0; j < MAX_OBJ_AFFECT; j++) affect_modify_ar(ch, GET_EQ(ch, i)->affected[j].location,       GET_EQ(ch, i)->affected[j].modifier,       GET_OBJ_AFFECT(GET_EQ(ch, i)), TRUE);   }   for (af = ch->affected; af; af = af->next)     affect_modify_ar(ch, af->location, af->modifier, af->bitvector, TRUE);   /* Make certain values are between 0..25, not < 0 and not > 25! */   i = (IS_NPC(ch) || GET_LEVEL(ch) >= LVL_GRGOD) ? 25 : 18;   GET_DEX(ch) = MAX(0, MIN(GET_DEX(ch), i));   GET_INT(ch) = MAX(0, MIN(GET_INT(ch), i));   GET_WIS(ch) = MAX(0, MIN(GET_WIS(ch), i));   GET_CON(ch) = MAX(0, MIN(GET_CON(ch), i));   GET_CHA(ch) = MAX(0, MIN(GET_CHA(ch), i));   GET_STR(ch) = MAX(0, GET_STR(ch));   if (IS_NPC(ch) || GET_LEVEL(ch) >= LVL_GRGOD) {     GET_STR(ch) = MIN(GET_STR(ch), i);   } else {     if (GET_STR(ch) > 18) {       i = GET_ADD(ch) + ((GET_STR(ch) - 18) * 10);       GET_ADD(ch) = MIN(i, 100);       GET_STR(ch) = 18;     }   } }

Please Log in or Create an account to join the conversation.

More
06 Dec 2023 19:29 #10359 by thomas
The answer, in short, is that this enforces the limits and resets any ability scores that may have been adjusted "wrong" due to those limits.

Let's say you have 18 dex and wear items that give total +8 more. If you just wear it, you'd get 26 dex, which is above the tables we use for calculation. So you need to limit it to 25 total. You could just do that somewhere else, but you'd still need to do it.

If you then remove all your equipment again, you remove +8 dex. So you end up at 17 dex on your character. Not nice for the min/maxer.

This method makes sure any adjustments to ability scores is done from your real_abils-array, and then add all current affects back to you after setting your "base" to those values.

Please Log in or Create an account to join the conversation.

More
06 Dec 2023 21:28 #10360 by jandulio
Dummy me! I assumed that when something was worn/casted/etc. that it would check in that function. This function makes sense now!

Thanks Thomas!

Please Log in or Create an account to join the conversation.

Time to create page: 0.193 seconds