/** * qlist->removeat(): Removes the element at the specified position in * this list. * * @param list qlist_t container pointer. * @param index index at which the specified element is to be removed. * * @return a number of removed objects. * @retval errno will be set in error condition. * -ERANGE : Index out of range. */ bool qlist_removeat(qlist_t *list, int index) { qlist_lock(list); // get object pointer qlist_obj_t *obj = get_obj(list, index); if (obj == NULL) { qlist_unlock(list); return false; } bool ret = remove_obj(list, obj); qlist_unlock(list); return ret; }
static void *get_at(qlist_t *list, int index, size_t *size, bool newmem, bool remove) { qlist_lock(list); // get object pointer qlist_obj_t *obj = get_obj(list, index); if (obj == NULL) { qlist_unlock(list); return false; } // copy data void *data; if (newmem == true) { data = malloc(obj->size); if (data == NULL) { qlist_unlock(list); errno = ENOMEM; return false; } memcpy(data, obj->data, obj->size); } else { data = obj->data; } if (size != NULL) *size = obj->size; // remove if necessary if (remove == true) { if (remove_obj(list, obj) == false) { if (newmem == true) free(data); data = NULL; } } qlist_unlock(list); return data; }
bool spec_customs_spice(CHAR_DATA * ch) { CHAR_DATA *victim; CHAR_DATA *v_next; OBJ_DATA *obj; char buf[MAX_STRING_LENGTH]; long ch_exp; if (!IS_AWAKE(ch) || ch->position == POS_FIGHTING) return FALSE; for (victim = ch->in_room->first_person; victim; victim = v_next) { v_next = victim->next_in_room; if (IS_NPC(victim) || victim->position == POS_FIGHTING) continue; for (obj = victim->last_carrying; obj; obj = obj->prev_content) { if (obj->pIndexData->item_type == ITEM_SPICE || obj->pIndexData->item_type == ITEM_RAWSPICE) { if (victim != ch && can_see(ch, victim) && can_see_obj(ch, obj)) { sprintf(buf, "%s is illegal contraband. I'm going to have to confiscate that.", obj->short_descr); do_say(ch, buf); if (obj->wear_loc != WEAR_NONE) remove_obj(victim, obj->wear_loc, TRUE); separate_obj(obj); obj_from_char(obj); act(AT_ACTION, "$n confiscates $p from $N.", ch, obj, victim, TO_NOTVICT); act(AT_ACTION, "$n takes $p from you.", ch, obj, victim, TO_VICT); obj = obj_to_char(obj, ch); SET_BIT(obj->extra_flags, ITEM_CONTRABAND); ch_exp = UMIN(obj->cost * 10, (exp_level (victim-> skill_level [SMUGGLING_ABILITY] + 1) - exp_level(victim-> skill_level [SMUGGLING_ABILITY]))); ch_printf(victim, "You lose %ld experience. \n\r", ch_exp); gain_exp(victim, 0 - ch_exp, SMUGGLING_ABILITY); return TRUE; } else if (can_see(ch, victim) && !IS_SET(obj->extra_flags, ITEM_CONTRABAND)) { ch_exp = UMIN(obj->cost * 10, (exp_level (victim-> skill_level [SMUGGLING_ABILITY] + 1) - exp_level(victim-> skill_level [SMUGGLING_ABILITY]))); ch_printf(victim, "You receive %ld experience for smuggling %s. \n\r", ch_exp, obj->short_descr); gain_exp(victim, ch_exp, SMUGGLING_ABILITY); act(AT_ACTION, "$n looks at $N suspiciously.", ch, NULL, victim, TO_NOTVICT); act(AT_ACTION, "$n look at you suspiciously.", ch, NULL, victim, TO_VICT); SET_BIT(obj->extra_flags, ITEM_CONTRABAND); return TRUE; } else if (!IS_SET (obj->extra_flags, ITEM_CONTRABAND)) { ch_exp = UMIN(obj->cost * 10, (exp_level (victim-> skill_level [SMUGGLING_ABILITY] + 1) - exp_level(victim-> skill_level [SMUGGLING_ABILITY]))); ch_printf(victim, "You receive %ld experience for smuggling %s. \n\r", ch_exp, obj->short_descr); gain_exp(victim, ch_exp, SMUGGLING_ABILITY); SET_BIT(obj->extra_flags, ITEM_CONTRABAND); return TRUE; } } else if (obj->item_type == ITEM_CONTAINER) { OBJ_DATA *content; for (content = obj->first_content; content; content = content->next_content) { if (content->pIndexData->item_type == ITEM_SPICE && !IS_SET(content->extra_flags, ITEM_CONTRABAND)) { ch_exp = UMIN(content->cost * 10, (exp_level (victim-> skill_level [SMUGGLING_ABILITY] + 1) - exp_level(victim-> skill_level [SMUGGLING_ABILITY]))); ch_printf(victim, "You receive %ld experience for smuggling %s.\n\r ", ch_exp, content->short_descr); gain_exp(victim, ch_exp, SMUGGLING_ABILITY); SET_BIT(content->extra_flags, ITEM_CONTRABAND); return TRUE; } } } } } return FALSE; }
void wear_obj(Character *ch, Object *obj, bool fReplace) { if (ch->level < obj->level) { xwritelnf(ch, "You must be level %d to use this object.", obj->level); act(TO_ROOM, ch, obj, 0, "$n tries to use $p, but is too inexperienced."); return; } const wear_table_type *t = wear_table; while (t->display != 0) { if (t->flags == obj->wearFlags) { break; } t++; } if (t != 0 && t->canUse != 0 && !(*t->canUse) (ch)) { xwriteln(ch, "You do not know how to wear that object."); act(TO_ROOM, ch, obj, 0, "$n tries to use $p, but doesn't know how."); return; } switch (obj->wearFlags) { case WEAR_HEAD: if (!remove_obj(ch, WEAR_HEAD, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p on $s head."); act(TO_CHAR, ch, obj, 0, "You wear $p on your head."); equip_char(ch, obj, WEAR_HEAD); return; case WEAR_NECK: if (!remove_obj(ch, WEAR_NECK, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p around $s neck."); act(TO_CHAR, ch, obj, 0, "You wear $p around your neck."); equip_char(ch, obj, WEAR_NECK); return; case WEAR_EYES: if (!remove_obj(ch, WEAR_EYES, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p over $s eyes."); act(TO_CHAR, ch, obj, 0, "You wear $p over your eyes."); equip_char(ch, obj, WEAR_EYES); return; case WEAR_SHOULDERS: if (!remove_obj(ch, WEAR_SHOULDERS, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p on $s shoulders."); act(TO_CHAR, ch, obj, 0, "You wear $p on your shoulders."); equip_char(ch, obj, WEAR_SHOULDERS); return; case WEAR_BACK: if (!remove_obj(ch, WEAR_BACK, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p on $s back."); act(TO_CHAR, ch, obj, 0, "You wear $p on your back."); equip_char(ch, obj, WEAR_BACK); return; case WEAR_ARMS: if (!remove_obj(ch, WEAR_ARMS, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p on $s arms."); act(TO_CHAR, ch, obj, 0, "You wear $p on your arms."); equip_char(ch, obj, WEAR_ARMS); return; case WEAR_HANDS: if (!remove_obj(ch, WEAR_HANDS, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p on $s hands."); act(TO_CHAR, ch, obj, 0, "You wear $p on your hands."); equip_char(ch, obj, WEAR_HANDS); return; case WEAR_WRIST: if (get_eq_char(ch, WEAR_WRIST) != 0 && get_eq_char(ch, WEAR_WRIST_2) != 0 && !remove_obj(ch, WEAR_WRIST, fReplace) && !remove_obj(ch, WEAR_WRIST_2, fReplace)) { return; } if (get_eq_char(ch, WEAR_WRIST) == 0) { act(TO_ROOM, ch, obj, 0, "$n wears $p on $s left wrist."); act(TO_CHAR, ch, obj, 0, "You wear $p on your left wrist."); equip_char(ch, obj, WEAR_WRIST); return; } if (get_eq_char(ch, WEAR_WRIST_2) == 0) { act(TO_ROOM, ch, obj, 0, "$n wears $p on $s right wrist."); act(TO_CHAR, ch, obj, 0, "You wear $p on your right wrist."); equip_char(ch, obj, WEAR_WRIST_2); return; } xwriteln(ch, "You are already wearing something on your wrists."); return; case WEAR_FINGER: if (get_eq_char(ch, WEAR_FINGER) != 0 && get_eq_char(ch, WEAR_FINGER_2) != 0 && !remove_obj(ch, WEAR_FINGER, fReplace) && !remove_obj(ch, WEAR_FINGER_2, fReplace)) { return; } if (get_eq_char(ch, WEAR_FINGER) == 0) { act(TO_ROOM, ch, obj, 0, "$n wears $p on $s left finger."); act(TO_CHAR, ch, obj, 0, "You wear $p on your left finger."); equip_char(ch, obj, WEAR_FINGER); return; } if (get_eq_char(ch, WEAR_FINGER_2) == 0) { act(TO_ROOM, ch, obj, 0, "$n wears $p on $s right finger."); act(TO_CHAR, ch, obj, 0, "You wear $p on your right finger."); equip_char(ch, obj, WEAR_FINGER_2); return; } xwriteln(ch, "You are already wearing two rings."); return; case WEAR_TORSO: if (!remove_obj(ch, WEAR_TORSO, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p on $s torso."); act(TO_CHAR, ch, obj, 0, "You wear $p on your torso."); equip_char(ch, obj, WEAR_TORSO); return; case WEAR_WAIST: if (!remove_obj(ch, WEAR_WAIST, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p around $s waist."); act(TO_CHAR, ch, obj, 0, "You wear $p around your waist."); equip_char(ch, obj, WEAR_WAIST); return; case WEAR_LEGS: if (!remove_obj(ch, WEAR_LEGS, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p on $s legs."); act(TO_CHAR, ch, obj, 0, "You wear $p on your legs."); equip_char(ch, obj, WEAR_LEGS); return; case WEAR_FEET: if (!remove_obj(ch, WEAR_FEET, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p on $s feet."); act(TO_CHAR, ch, obj, 0, "You wear $p on your feet."); equip_char(ch, obj, WEAR_FEET); return; case WEAR_ABOUT: if (!remove_obj(ch, WEAR_ABOUT, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wears $p about $s body."); act(TO_CHAR, ch, obj, 0, "You wear $p about your body."); equip_char(ch, obj, WEAR_ABOUT); return; case WEAR_WIELD: if (!remove_obj(ch, WEAR_WIELD, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wields $p."); act(TO_CHAR, ch, obj, 0, "You wield $p."); equip_char(ch, obj, WEAR_WIELD); return; case WEAR_DUAL: if (!remove_obj(ch, WEAR_DUAL, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n wields $p in $s off hand."); act(TO_CHAR, ch, obj, 0, "You wield $p in your off hand."); equip_char(ch, obj, WEAR_DUAL); return; case WEAR_SHIELD: if (!remove_obj(ch, WEAR_SHIELD, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n usees $p as $s shield."); act(TO_CHAR, ch, obj, 0, "You use $p as your shield."); equip_char(ch, obj, WEAR_SHIELD); return; case WEAR_LIGHT: if (!remove_obj(ch, WEAR_LIGHT, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n lights $p and holds it."); act(TO_CHAR, ch, obj, 0, "You light $p and hold it."); equip_char(ch, obj, WEAR_LIGHT); return; case WEAR_FLOAT: if (!remove_obj(ch, WEAR_FLOAT, fReplace)) { return; } act(TO_ROOM, ch, obj, 0, "$n releases $p to float near $m."); act(TO_CHAR, ch, obj, 0, "You release $p to float nearby."); equip_char(ch, obj, WEAR_FLOAT); return; default: if (fReplace) { xwriteln(ch, "You can't wear, wield, or hold that."); } return; } }