예제 #1
0
/* Returns 1 if otmp is free'd, 0 otherwise. */
int mpickobj(struct monst *mtmp, struct obj *otmp)
{
    int freed_otmp;

    boolean snuff_otmp = FALSE;
    /* don't want hidden light source inside the monster; assumes that
       engulfers won't have external inventories; whirly monsters cause
       the light to be extinguished rather than letting it shine thru */
    if (otmp->lamplit &&  /* hack to avoid function calls for most objs */
      	obj_sheds_light(otmp) &&
	attacktype(mtmp->data, AT_ENGL)) {
	/* this is probably a burning object that you dropped or threw */
	if (u.uswallow && mtmp == u.ustuck && !Blind)
	    pline("%s out.", Tobjnam(otmp, "go"));
	snuff_otmp = TRUE;
    }
    /* Must do carrying effects on object prior to add_to_minv() */
    carry_obj_effects(otmp);
    /* add_to_minv() might free otmp [if merged with something else],
       so we have to call it after doing the object checks */
    freed_otmp = add_to_minv(mtmp, otmp);
    /* and we had to defer this until object is in mtmp's inventory */
    if (snuff_otmp) snuff_light_source(mtmp->mx, mtmp->my);

    return freed_otmp;
}
예제 #2
0
/*
 * Deallocate the object.  _All_ objects should be run through here for
 * them to be deallocated.
 */
void
dealloc_obj(struct obj *obj)
{
    if (obj->where != OBJ_FREE)
        panic("dealloc_obj: obj not free (%d,%d,%d)", obj->where, obj->otyp, obj->invlet);

    /* free up any timers attached to the object */
    if (obj->timed)
        obj_stop_timers(obj);

    /*
     * Free up any light sources attached to the object.
     *
     * We may want to just call del_light_source() without any
     * checks (requires a code change there).  Otherwise this
     * list must track all objects that can have a light source
     * attached to it (and also requires lamplit to be set).
     */
    if (obj_sheds_light(obj))
        del_light_source(LS_OBJECT, (genericptr_t) obj);

    if (obj == thrownobj) thrownobj = (struct obj*)0;

    free((genericptr_t) obj);
}
예제 #3
0
/*
 * Split obj so that it gets size gets reduced by num. The quantity num is
 * put in the object structure delivered by this call.  The returned object
 * has its wornmask cleared and is positioned just following the original
 * in the nobj chain (and nexthere chain when on the floor).
 */
struct obj *
splitobj(struct obj *obj, long int num)
{
    struct obj *otmp;

    if (obj->cobj || num <= 0L || obj->quan <= num)
        panic("splitobj");	/* can't split containers */
    otmp = newobj(obj->oxlth + obj->onamelth);
    *otmp = *obj;		/* copies whole structure */
    otmp->o_id = flags.ident++;
    if (!otmp->o_id) otmp->o_id = flags.ident++;	/* ident overflowed */
    otmp->timed = 0;	/* not timed, yet */
    otmp->lamplit = 0;	/* ditto */
    otmp->owornmask = 0L;	/* new object isn't worn */
    obj->quan -= num;
    obj->owt = weight(obj);
    otmp->quan = num;
    otmp->owt = weight(otmp);	/* -= obj->owt ? */
    obj->nobj = otmp;
    /* Only set nexthere when on the floor, nexthere is also used */
    /* as a back pointer to the container object when contained. */
    if (obj->where == OBJ_FLOOR)
        obj->nexthere = otmp;
    if (obj->oxlth)
        (void)memcpy((genericptr_t)otmp->oextra, (genericptr_t)obj->oextra,
                     obj->oxlth);
    if (obj->onamelth)
        (void)strncpy(ONAME(otmp), ONAME(obj), (int)obj->onamelth);
    if (obj->unpaid) splitbill(obj,otmp);
    if (obj->timed) obj_split_timers(obj, otmp);
    if (obj_sheds_light(obj)) obj_split_light_source(obj, otmp);
    return otmp;
}
예제 #4
0
/* Returns 1 if otmp is free'd, 0 otherwise. */
int mpickobj (struct monst *mtmp, struct obj *otmp) {
    int freed_otmp;

    if (otmp->oclass == COIN_CLASS) {
        mtmp->mgold += otmp->quan;
        obfree(otmp, (struct obj *)0);
        freed_otmp = 1;
    } else {
        bool snuff_otmp = false;
        /* don't want hidden light source inside the monster; assumes that
           engulfers won't have external inventories; whirly monsters cause
           the light to be extinguished rather than letting it shine thru */
        if (otmp->lamplit &&  /* hack to avoid function calls for most objs */
                obj_sheds_light(otmp) &&
                attacktype(mtmp->data, AT_ENGL)) {
            /* this is probably a burning object that you dropped or threw */
            if (u.uswallow && mtmp == u.ustuck && !Blind()) {
                message_object(MSG_O_GO_OUT, otmp);
            }
            snuff_otmp = true;
        }
        /* Must do carrying effects on object prior to add_to_minv() */
        carry_obj_effects(otmp);
        /* add_to_minv() might free otmp [if merged with something else],
           so we have to call it after doing the object checks */
        freed_otmp = add_to_minv(mtmp, otmp);
        /* and we had to defer this until object is in mtmp's inventory */
        if (snuff_otmp) snuff_light_source(mtmp->mx, mtmp->my);
    }
    return freed_otmp;
}