Ah glad to hear that issue was resolved! I think that problem is likely something very beyond my very meager programming skills; I likely wouldn't have player housing (but it would be very awesome).
So I reworked the inventory display a little bit, and also got the above rough draft of the check_encumbrance function up and running. Not only does it count the weight in a player's inventory, it also includes the equipment worn as well!
Over in act.informative, here's do_inventory redone.
Code:
ACMD(do_inventory)
{
send_to_char(ch, "Current Weight: %d Max Weight: %d\r\n\r\n", check_encumbrance(ch, SIT_INV_WNUMBER), CAN_CARRY_W(ch));
send_to_char(ch, " Items: %d Max Items: %d\r\n", IS_CARRYING_N(ch), CAN_CARRY_N(ch));
send_to_char(ch, " Encumbrance Rating: ");
check_encumbrance(ch, SIT_INV_MESSAGE);
send_to_char(ch, "\r\nInventory:\r\n");
list_obj_to_char(ch->carrying, ch, SHOW_OBJ_SHORT, TRUE);
}
Over in structs.h, added in these.
Code:
/* How much weight is a character carrying? Light, moderate, or heavy load? */
#define ENC_LIGHT 1
#define ENC_MOD 2
#define ENC_HEAVY 3
#define ENC_NONE 4
/* Used for determining situations that come up when inquiring about encumbrance. */
#define SIT_MOVEMENT 1
#define SIT_INV_MESSAGE 2
#define SIT_INV_WNUMBER 3
Over in act.items, here's the check_encumbrance function.
Code:
int check_encumbrance(struct char_data *ch, int situation) {
int maxcarry = CAN_CARRY_W(ch);
int current = IS_CARRYING_N(ch);
int condition = 0, penalty = 0;
float percent = 0;
/* So we've got the max carry and current weight carried. Time to check EQ slots and tally that weight up! */
if (GET_EQ(ch, WEAR_LIGHT)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_LIGHT));
if (GET_EQ(ch, WEAR_FINGER_R)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_FINGER_R));
if (GET_EQ(ch, WEAR_FINGER_L)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_FINGER_L));
if (GET_EQ(ch, WEAR_NECK_1)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_NECK_1));
if (GET_EQ(ch, WEAR_NECK_2)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_NECK_2));
if (GET_EQ(ch, WEAR_BODY)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_BODY));
if (GET_EQ(ch, WEAR_HEAD)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_HEAD));
if (GET_EQ(ch, WEAR_LEGS)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_LEGS));
if (GET_EQ(ch, WEAR_FEET)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_FEET));
if (GET_EQ(ch, WEAR_HANDS)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_HANDS));
if (GET_EQ(ch, WEAR_ARMS)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_ARMS));
if (GET_EQ(ch, WEAR_SHIELD)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_SHIELD));
if (GET_EQ(ch, WEAR_ABOUT)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_ABOUT));
if (GET_EQ(ch, WEAR_WAIST)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_WAIST));
if (GET_EQ(ch, WEAR_WRIST_R)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_WRIST_R));
if (GET_EQ(ch, WEAR_WRIST_L)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_WRIST_L));
if (GET_EQ(ch, WEAR_WIELD)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_WIELD));
if (GET_EQ(ch, WEAR_HOLD)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_HOLD));
if (GET_EQ(ch, WEAR_BACKPACK)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_BACKPACK));
if (GET_EQ(ch, WEAR_DWIELD)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_DWIELD));
if (GET_EQ(ch, WEAR_BODYARM)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_BODYARM));
if (GET_EQ(ch, WEAR_ARMARM)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_ARMARM));
if (GET_EQ(ch, WEAR_LEGARM)) current += GET_OBJ_WEIGHT(GET_EQ(ch, WEAR_LEGARM));
percent = (float)current / (float)maxcarry;
if (percent <= .25) condition = ENC_NONE;
else if (percent <= .50) condition = ENC_LIGHT;
else if (percent <= .75) condition = ENC_MOD;
else if (percent <= 1) condition = ENC_HEAVY;
/* If the situation is combat, penalty of 1, 2, or 4 is applied to attacks.
However, if the situation is movement, penalty is a multiplier to the
movement cost. Light encumbrance would offer no penalty. */
switch (situation) {
case SIT_MOVEMENT:
switch (condition) {
case ENC_LIGHT:
penalty = 1;
break;
case ENC_MOD:
penalty = 2;
break;
case ENC_HEAVY:
penalty = 3;
break;
default:
penalty = 1;
break;
}
break;
case SIT_INV_MESSAGE:
switch (condition) {
case ENC_LIGHT:
send_to_char(ch, "\tGLight\tn");
break;
case ENC_MOD:
send_to_char(ch, "\tYModerate\tn");
break;
case ENC_HEAVY:
send_to_char(ch, "\tRHeavy\tn");
break;
default:
send_to_char(ch, "\tWNone\tn");
break;
}
return (0);
break;
case SIT_INV_WNUMBER:
return (current);
break;
}
return (penalty);
}
I removed the combat penalty portion, though that could be very easily added once again. So far, it doesn't have any added effect other than "Oh no I'm close to carrying my limit!" Oh wait... forgot one last bit of code. Still in act.item.
Code:
if (!IS_NPC(ch) && !PRF_FLAGGED(ch, PRF_NOHASSLE)) {
if (IS_CARRYING_N(ch) >= CAN_CARRY_N(ch)) {
act("$p: you can't carry that many items.", FALSE, ch, obj, 0, TO_CHAR);
return (0);
} else if ((check_encumbrance(ch, SIT_INV_WNUMBER) + GET_OBJ_WEIGHT(obj)) > CAN_CARRY_W(ch)) { // <----- This is the only line that is changed.
act("$p: you can't carry that much weight.", FALSE, ch, obj, 0, TO_CHAR);
return (0);
}
}
Now the player's total carried weight (inventory + eq) is considered instead of just their inventory weight.
Will do more tomorrow.