Welcome to the Builder Academy

Question handler.c apply_ac

More
28 Dec 2015 13:49 #5544 by Fubar
handler.c apply_ac was created by Fubar
the following code compiles wit no errors or warnings. But I would like any suggestion cause i believe this will cause problems.
Code:
/* local file scope functions */ static int apply_ac(struct char_data *ch, int eq_pos, int imp_pos); /* Return the effect of a piece of armor in position eq_pos */ static int apply_ac(struct char_data *ch, int eq_pos, int imp_pos) { int factor; if (GET_EQ(ch, eq_pos) == NULL) { core_dump(); return (0); } if (GET_IMP(ch, imp_pos) == NULL) { core_dump(); return (0); } if (!(GET_OBJ_TYPE(GET_EQ(ch, eq_pos)) == ITEM_ARMOR)) return (0); if (!(GET_OBJ_TYPE(GET_IMP(ch, imp_pos)) == ITEM_ARMOR)) return (0); switch (eq_pos) { case WEAR_BODY: factor = 3; break; /* 30% */ case WEAR_HEAD: factor = 2; break; /* 20% */ case WEAR_LEGS: factor = 2; break; /* 20% */ default: factor = 1; break; /* all others 10% */ } switch (imp_pos) { case IMPLANT_CHEST: factor = 3; break; /* 30% */ case IMPLANT_HEAD: factor = 2; break; /* 20% */ case IMPLANT_LEGS: factor = 2; break; /* 20% */ default: factor = 1; break; /* all others 10% */ } return (factor * GET_OBJ_VAL(GET_IMP(ch, imp_pos), 0) && GET_OBJ_VAL(GET_EQ(ch, eq_pos), 0)); } /* WHEN I HAVE TO APPLY_AC */ if (GET_OBJ_TYPE(obj) == ITEM_ARMOR) GET_AC(ch) += apply_ac(ch, pos, pos);

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

More
29 Dec 2015 21:00 #5548 by WhiskyTest
Replied by WhiskyTest on topic handler.c apply_ac

return (factor * GET_OBJ_VAL(GET_IMP(ch, imp_pos), 0) && GET_OBJ_VAL(GET_EQ(ch, eq_pos), 0));

I don't know what you get returned by having that logical && there, but definitely not what you'll be expecting.

Do you mean to add them together?

factor * (GET_OBJ_VAL(GET_IMP(ch, imp_pos), 0) + GET_OBJ_VAL(GET_EQ(ch, eq_pos), 0)

Or are you wanting a percentage returned?
You'd need to use double rather than int in that case, or something like this:

Warning: Spoiler!

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

Time to create page: 0.215 seconds