Exemplo n.º 1
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;
}
Exemplo n.º 2
0
/* remainder is put in the object structure delivered by this call */
struct obj *
splitobj(struct obj *obj, int num)
{
	struct obj *otmp;

	otmp = newobj(0);
	*otmp = *obj;		/* copies whole structure */
	otmp->o_id = flags.ident++;
	otmp->onamelth = 0;
	obj->quan = num;
	obj->owt = weight(obj);
	otmp->quan -= num;
	otmp->owt = weight(otmp);	/* -= obj->owt ? */
	obj->nobj = otmp;
	if(obj->unpaid) splitbill(obj,otmp);
	return(otmp);
}