コード例 #1
0
ファイル: dothrow.c プロジェクト: saihack/NetHack
int
dothrow()
{
	register struct obj *obj;

	if(check_capacity(NULL)) return(0);
	obj = getobj(toss_objs, "throw");
	/* it is also possible to throw food */
	/* (or jewels, or iron balls... ) */

	if(!obj || !getdir(NULL)) {       /* ask "in what direction?" */
		if (obj && obj->oclass == GOLD_CLASS) {
		    u.ugold += obj->quan;
		    flags.botl = 1;
		    dealloc_obj(obj);
		}
		return(0);
	}

	if(obj->oclass == GOLD_CLASS) return(throw_gold(obj));

	if(!canletgo(obj,"throw"))
		return(0);
	if (obj->oartifact == ART_MJOLLNIR && obj != uwep) {
		You("must be wielding %s in order to throw it.", xname(obj));
		return(0);
	}
	if ((obj->oartifact == ART_MJOLLNIR && ACURR(A_STR) != 125)
	   || (obj->otyp == BOULDER
#ifdef POLYSELF
					&& !throws_rocks(uasmon)
#endif
								)) {
		pline("It's too heavy.");
		return(1);
	}
	if(!u.dx && !u.dy && !u.dz) {
		You("cannot throw an object at yourself.");
		return(0);
	}
	u_wipe_engr(2);

	if(obj == uwep) {
	    if(welded(obj)) {
		weldmsg(obj, FALSE);
		return(1);
	    }
	    if(obj->quan > 1L)
		setuwep(splitobj(obj, 1L));
	    else {
		setuwep((struct obj *)0);
		if (uwep) return(1); /* unwielded, died, rewielded */
	    }
	}
	else if(obj->quan > 1L)
		(void) splitobj(obj, 1L);
	freeinv(obj);
	return(throwit(obj));
}
コード例 #2
0
ファイル: eval.c プロジェクト: zbenjamin/vmscheme
// see note for eval_sequence, below
struct object *
eval(struct pair *form, struct environment *env)
{
  struct pair *seq = make_pair(&form->obj, &NIL->obj);
  struct object *ret = eval_sequence(seq, env);
  dealloc_obj(&seq->obj);
  return ret;
}
コード例 #3
0
ファイル: t.c プロジェクト: stevezhee/shootout
void exit_cleanup(int e)
{

  for(int i = 0; i < g_nobjs; ++i) { dealloc_obj(i); }

  for(unsigned int i = 0; i < NUM_TEX; ++i) { SDL_DestroyTexture(g_tex[i]); }

  if(g_renderer) { SDL_DestroyRenderer(g_renderer); }
  if(g_screen) { SDL_FreeSurface(g_screen); }
  if(g_window) { SDL_DestroyWindow(g_window); }

  SDL_Quit();
  exit(e);
}
コード例 #4
0
ファイル: pager.c プロジェクト: DanielT/NitroHack
static int describe_object(int x, int y, int votyp, char *buf)
{
    int num_objs = 0;
    struct obj *otmp;
    if (votyp == -1)
	return -1;
    
    otmp = vobj_at(x,y);
    
    if (!otmp || otmp->otyp != votyp) {
	if (votyp != STRANGE_OBJECT) {
	    otmp = mksobj(level, votyp, FALSE, FALSE);
	    if (otmp->oclass == COIN_CLASS)
		otmp->quan = 1L; /* to force pluralization off */
	    else if (otmp->otyp == SLIME_MOLD)
		otmp->spe = current_fruit;	/* give the fruit a type */
	    strcpy(buf, distant_name(otmp, xname));
	    dealloc_obj(otmp);
	    otmp = vobj_at(x,y); /* make sure we don't point to the temp obj any more */
	}
    } else
	strcpy(buf, distant_name(otmp, xname));
    
    if (level->locations[x][y].typ == STONE || level->locations[x][y].typ == SCORR)
	strcat(buf, " embedded in stone");
    else if (IS_WALL(level->locations[x][y].typ) || level->locations[x][y].typ == SDOOR)
	strcat(buf, " embedded in a wall");
    else if (closed_door(level, x,y))
	strcat(buf, " embedded in a door");
    else if (is_pool(level, x,y))
	strcat(buf, " in water");
    else if (is_lava(level, x,y))
	strcat(buf, " in molten lava");	/* [can this ever happen?] */
    
    if (!cansee(x, y))
	return -1; /* don't disclose the number of objects for location out of LOS */
    
    if (!otmp)
	/* There is no object here. Since the player sees one it must be a mimic */
	return 1;
    
    if (otmp->otyp != votyp)
	/* Hero sees something other than the actual top object. Probably a mimic */
	num_objs++;
    
    for ( ; otmp; otmp = otmp->nexthere)
	num_objs++;
    
    return num_objs;
}
コード例 #5
0
ファイル: save.c プロジェクト: mbi/NitroHack
static void free_objchn(struct obj *otmp)
{
	struct obj *otmp2;
	while (otmp) {
	    otmp2 = otmp->nobj;
	    if (Has_contents(otmp))
		free_objchn(otmp->cobj);
	    
	    otmp->where = OBJ_FREE;	/* set to free so dealloc will work */
	    otmp->timed = 0;	/* not timed any more */
	    otmp->lamplit = 0;	/* caller handled lights */
	    dealloc_obj(otmp);
	    otmp = otmp2;
	}
}
コード例 #6
0
ファイル: t.c プロジェクト: stevezhee/shootout
void dealloc_timer_1s(int i)
{
  printf("dealloc_timer %d\n", i);
  die_if(i >= g_ntimers, "unknown timer index");

  --g_ntimers;

  int n = g_ntimers;

  dealloc_obj(g_timer_oid[i]);

  if(n == 0 || i == n) { return; }

  g_timer_oid[i] = g_timer_oid[n];
  g_timer_expire[i] = g_timer_expire[n];
  
}
コード例 #7
0
ファイル: pager.c プロジェクト: FredrIQ/nethack4
static int
describe_object(int x, int y, int votyp, char *buf, int known_embed,
                boolean *feature_described)
{
    int num_objs = 0;
    struct obj *otmp;
    int typ;

    *feature_described = FALSE;

    if (votyp == -1)
        return -1;

    otmp = vobj_at(x, y);

    if (!otmp || otmp->otyp != votyp) {
        /* We have a mimic. */
        if (votyp == STRANGE_OBJECT) {
            strcpy(buf, "strange object");
        } else {
            otmp = mktemp_sobj(level, votyp);
            otmp->corpsenm = PM_TENGU;
            /* (basic object only, no random features) */
            if (otmp->oclass == COIN_CLASS)
                otmp->quan = 1L;        /* to force pluralization off */
            else if (otmp->otyp == SLIME_MOLD)
                otmp->spe = gamestate.fruits.current;/* give the fruit a type */
            strcpy(buf, distant_name(otmp, xname));
            dealloc_obj(otmp);
            otmp = vobj_at(x, y);       /* make sure we don't point to the temp 
                                           obj any more */
        }
    } else
        strcpy(buf, distant_name(otmp, xname));

    typ = level->locations[x][y].typ;
    if (known_embed && IS_TREE(typ))
        strcat(buf, " stuck");
    else if (known_embed && (IS_ROCK(typ) || closed_door(level, x, y)))
        strcat(buf, " embedded");
    else if (IS_TREE(typ)) {
        strcat(buf, " stuck in a tree");
        *feature_described = TRUE;
    } else if (typ == STONE || typ == SCORR) {
        strcat(buf, " embedded in stone");
        *feature_described = TRUE;
    } else if (IS_WALL(typ) || typ == SDOOR) {
        strcat(buf, " embedded in a wall");
        *feature_described = TRUE;
    } else if (closed_door(level, x, y)) {
        strcat(buf, " embedded in a door");
        *feature_described = TRUE;
    } else if (is_pool(level, x, y)) {
        strcat(buf, " in water");
        *feature_described = TRUE;
    } else if (is_lava(level, x, y)) {
        strcat(buf, " in molten lava"); /* [can this ever happen?] */
        *feature_described = TRUE;
    }

    if (!cansee(x, y))
        return -1;      /* don't disclose the number of objects for location
                           out of LOS */

    if (!otmp)
        /* There is no object here. Since the player sees one it must be a
           mimic */
        return 1;

    if (otmp->otyp != votyp)
        /* Hero sees something other than the actual top object. Probably a
           mimic */
        num_objs++;

    for (; otmp; otmp = otmp->nexthere)
        num_objs++;

    return num_objs;
}
コード例 #8
0
ファイル: do_name.c プロジェクト: FredrIQ/nhfourk
/*
 * Allocate a new and possibly larger storage space for an obj.
 */
struct obj *
realloc_obj(struct obj *obj, int oextra_size, void *oextra_src, int oname_size,
            const char *name)
{
    struct obj *otmp;

    otmp = newobj(oextra_size + oname_size, obj);

    if (oextra_size) {
        if (oextra_src)
            memcpy(otmp->oextra, oextra_src, oextra_size);
    } else {
        otmp->oattached = OATTACHED_NOTHING;
    }
    otmp->oxlth = oextra_size;
    otmp->onamelth = oname_size;

    if (oname_size) {
        if (name)
            strcpy(ONAME_MUTABLE(otmp), name);
    }

    /* !obj->olev means the obj is currently being restored and no pointer from 
       or to it is valid. Re-equipping, timer linking, etc. will happen
       elsewhere in that case. */
    if (obj->olev) {
        int i;
        if (obj->owornmask) {
            boolean save_twoweap = u.twoweap;

            /* unwearing the old instance will clear dual-wield mode if this
               object is either of the two weapons */
            setworn(NULL, obj->owornmask);
            setworn(otmp, otmp->owornmask);
            u.twoweap = save_twoweap;
        }

        /* replace obj with otmp */
        replace_object(obj, otmp);

        /* fix ocontainer pointers */
        if (Has_contents(obj)) {
            struct obj *inside;

            for (inside = obj->cobj; inside; inside = inside->nobj)
                inside->ocontainer = otmp;
        }

        /* move timers and light sources from obj to otmp */
        otmp->timed = 0;        /* not timed, yet */
        if (obj->timed)
            obj_move_timers(obj, otmp);
        otmp->lamplit = 0;      /* ditto */
        if (obj->lamplit)
            obj_move_light_source(obj, otmp);

        /* objects possibly being manipulated by multi-turn occupations which
           have been interrupted but might be subsequently resumed */
        for (i = 0; i <= tos_last_slot; i++) {
            if (obj == u.utracked[i])
                u.utracked[i] = otmp;
        }
        /* This is probably paranoia; it would only come up if an item can
           end up being specific-named as a result of trying to use it. */
        for (i = 0; i <= ttos_last_slot; i++) {
            if (obj == turnstate.tracked[i])
                turnstate.tracked[i] = otmp;
        }
    } else {
        /* During restore, floating objects are on the floating objects
           chain, /but/ may not have OBJ_FREE set. */
        otmp->where = obj->where;
        obj->where = OBJ_FREE;
        obj->timed = FALSE;
        obj->lamplit = FALSE;
    }
    /* obfree(obj, otmp); now unnecessary: no pointers on bill */

    dealloc_obj(obj);   /* let us hope nobody else saved a pointer */
    return otmp;
}
コード例 #9
0
ファイル: do_name.c プロジェクト: DanielT/NitroHack
/*
 * Allocate a new and possibly larger storage space for an obj.
 */
struct obj *realloc_obj(struct obj *obj, int oextra_size, void *oextra_src,
			int oname_size, const char *name)
{
	struct obj *otmp;

	otmp = newobj(oextra_size + oname_size);
	*otmp = *obj;	/* the cobj pointer is copied to otmp */
	if (oextra_size) {
	    if (oextra_src)
		memcpy(otmp->oextra, oextra_src, oextra_size);
	} else {
	    otmp->oattached = OATTACHED_NOTHING;
	}
	otmp->oxlth = oextra_size;
	otmp->onamelth = oname_size;
	
	if (oname_size) {
	    if (name)
		strcpy(ONAME(otmp), name);
	}

	/* !obj->olev means the obj is currently being restored and no pointer
	 * from or to it is valid. Re-equipping, timer linking, etc. will happen
	 * elsewhere in that case. */
	if (obj->olev) { 
	    if (obj->owornmask) {
		    boolean save_twoweap = u.twoweap;
		    /* unwearing the old instance will clear dual-wield mode
		    if this object is either of the two weapons */
		    setworn(NULL, obj->owornmask);
		    setworn(otmp, otmp->owornmask);
		    u.twoweap = save_twoweap;
	    }

	    /* replace obj with otmp */
	    replace_object(obj, otmp);

	    /* fix ocontainer pointers */
	    if (Has_contents(obj)) {
		    struct obj *inside;

		    for (inside = obj->cobj; inside; inside = inside->nobj)
			    inside->ocontainer = otmp;
	    }

	    /* move timers and light sources from obj to otmp */
	    otmp->timed = 0;	/* not timed, yet */
	    if (obj->timed) obj_move_timers(obj, otmp);
	    otmp->lamplit = 0;	/* ditto */
	    if (obj->lamplit) obj_move_light_source(obj, otmp);

	    /* objects possibly being manipulated by multi-turn occupations
	    which have been interrupted but might be subsequently resumed */
	    if (obj->oclass == FOOD_CLASS)
		food_substitution(obj, otmp);	/* eat food or open tin */
	    else if (obj->oclass == SPBOOK_CLASS)
		book_substitution(obj, otmp);	/* read spellbook */
	} else {
	    /* make sure dealloc_obj doesn't explode */
	    obj->where = OBJ_FREE;
	    obj->timed = FALSE;
	    obj->lamplit = FALSE;
	}
	/* obfree(obj, otmp);	now unnecessary: no pointers on bill */
	dealloc_obj(obj);	/* let us hope nobody else saved a pointer */
	return otmp;
}