示例#1
0
void activate()
{
  int index;
  char response;

  clearmsg();

  print1("Activate -- item [i] or artifact [a] or quit [ESCAPE]?");
  do response = (char) mcigetc();
  while ((response != 'i') && (response != 'a') && (response != ESCAPE));
  if (response != ESCAPE) {
    if (response == 'i')
      index = getitem(THING);
    else if (response == 'a')
      index = getitem(ARTIFACT);
    if (index != ABORT) {
      clearmsg();
      print1("You activate it.... ");
      morewait();
      item_use(Player.possessions[index]);
    }
    else setgamestatus(SKIP_MONSTERS);
  }
  else setgamestatus(SKIP_MONSTERS);
}
示例#2
0
/* read a scroll, book, tome, etc. */
void peruse()
{
  int index;
  struct object *obj;

  clearmsg();

  if (Player.status[BLINDED] > 0)
    print3("You're blind -- you can't read!!!");
  else if (Player.status[AFRAID] > 0)
    print3("You are too afraid to stop to read a scroll!");
  else {
    print1("Read -- ");
    index = getitem(SCROLL);
    if (index == ABORT)
      setgamestatus(SKIP_MONSTERS);
    else {
      obj = Player.possessions[index];
      if (obj->objchar != SCROLL) {
	print3("There's nothing written on ");
	nprint3(itemid(obj));
      }
      else {
	nprint1("You carefully unfurl the scroll....");
	morewait();
	item_use(obj);
	dispose_lost_objects(1,obj);
      }
    }
  }
}
示例#3
0
void eat()
{
  int index;
  struct object *obj;

  clearmsg();

  print1("Eat --");
  index = getitem(FOOD);
  if (index == ABORT)
    setgamestatus(SKIP_MONSTERS);
  else {
    obj = Player.possessions[index];
    if ((obj->objchar != FOOD)&&(obj->objchar != CORPSE)) {
      print3("You can't eat ");
      nprint3(itemid(obj));
    }
    else {
      if (obj->usef == I_FOOD) Player.food = max(0,Player.food+obj->aux);
      item_use(obj);
      dispose_lost_objects(1,obj);
      if (Current_Dungeon == E_COUNTRYSIDE) {
	Time += 100;
	hourly_check();
      }
    }
  }
  foodcheck();
}
示例#4
0
static void focusenter(MENUSYS *sys, int depth, BOOL exec) {

	MENUHDL	menu;
	MSYSWND	wnd;

	wnd = sys->wnd + depth;
	menu = getitem(sys, depth, wnd->focus);
	if ((menu) && (!(menu->flag & MENU_GRAY)) &&
		(menu->child != NULL)) {
		if (depth == 0) {
			wndclose(sys, 1);
			itemdraw(sys, 0, wnd->focus, 1);
			sys->opened = 1;
		}
		childopn(sys, depth, wnd->focus);
	}
	else if (exec) {
		if ((menu) && (menu->id)) {
			menubase_close();
			sys->cmd(menu->id);
		}
	}
	else {
		focusmove(sys, 0, 1);
	}
}
示例#5
0
extern "C" PyObject* PyObject_GetItem(PyObject* o, PyObject* key) {
    try {
        return getitem(o, key);
    } catch (Box* b) {
        Py_FatalError("unimplemented");
    }
}
示例#6
0
文件: mod_irq.c 项目: 2005wind/tsar
char *irq_ops(char *last_record,
		char *curr_record,
		time_t last_time,
		time_t curr_time,
		int data_type, 
		int output_type)
{
	unsigned long itv;
	char buf[MAX_LINE_LEN];
	int pos = 0;
	unsigned int i = 0;
	/* if statistic structure is not inited, 
	   we will alloc space here */
	int nr = count_irq_nr(last_record);
	if (!f_init) {
		init_structure(nr);
		f_init = TRUE;
	}

	CALITV(last_time, curr_time, itv);

	stats_irq temp_si = s_st_irq;

	char last_mnt[MAX_STRING_LEN] = {0};
	char curr_mnt[MAX_STRING_LEN] = {0};

	if(*last_record == '\0') {
		/* first record */
	}
	else {
		while((last_record = getitem(last_record, last_mnt)) != NULL &&
				(curr_record = getitem(curr_record, curr_mnt)) != NULL) {

			__irq_ops(last_mnt , curr_mnt,
					data_type, output_type,
					temp_si, buf + pos, &pos, itv, i);
			i++;
			temp_si++;
			memset(last_mnt, '0', MAX_STRING_LEN);
			memset(curr_mnt, '0', MAX_STRING_LEN);
		}
	}


	buf[pos] = '\0';
	return(strdup(buf));
}
示例#7
0
extern "C" PyObject* PySequence_GetSlice(PyObject* o, Py_ssize_t i1, Py_ssize_t i2) {
    try {
        // Not sure if this is really the same:
        return getitem(o, new BoxedSlice(boxInt(i1), boxInt(i2), None));
    } catch (Box* b) {
        Py_FatalError("unimplemented");
    }
}
示例#8
0
extern "C" PyObject* PySequence_GetItem(PyObject* o, Py_ssize_t i) {
    try {
        // Not sure if this is really the same:
        return getitem(o, boxInt(i));
    } catch (Box* b) {
        Py_FatalError("unimplemented");
    }
}
示例#9
0
文件: queue.c 项目: shouhutsh/myXinu
pid32	getlast(qid16 qid)
{
	if(isbadqid(qid))
	{
		return EMPTY;
	}

	return getitem(lastid(qid));
}
示例#10
0
文件: kill.c 项目: pvanevery/school
/*------------------------------------------------------------------------
 *  kill  -  Kill a process and remove it from the system
 *------------------------------------------------------------------------
 */
syscall	kill(
	  pid32		pid		/* ID of process to kill	*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	struct	procent *prptr;		/* Ptr to process's table entry	*/
	int32	i;			/* Index into descriptors	*/

	mask = disable();
	if (isbadpid(pid) || (pid == NULLPROC)
	    || ((prptr = &proctab[pid])->prstate) == PR_FREE) {
		restore(mask);
		return SYSERR;
	}

	if (prptr->prcleanup != NULL){
		prptr->prcleanup();
	}

	if (--prcount <= 1) {		/* Last user process completes	*/
		xdone();
	}

	send(prptr->prparent, pid);
	for (i=0; i<3; i++) {
		close(prptr->prdesc[i]);
	}
	freestk(prptr->prstkbase, prptr->prstklen);

	switch (prptr->prstate) {
	case PR_CURR:
		prptr->prstate = PR_FREE;	/* Suicide */
		resched();

	case PR_SLEEP:
	case PR_RECTIM:
		unsleep(pid);
		prptr->prstate = PR_FREE;
		break;

	case PR_WAIT:
		semtab[prptr->prsem].scount++;
		/* Fall through */

	case PR_READY:
		getitem(pid);		/* Remove from queue */
		/* Fall through */

	default:
		prptr->prstate = PR_FREE;
	}

	restore(mask);
	return OK;
}
int main(int argc, const char *[])
{
  boost::optional<int> a = getitem();
  boost::optional<int> b;

  if (argc > 0)
    b = argc;

  if (a == b)
    return 1;

  return 0;
}
示例#12
0
文件: kill.c 项目: JamesLinus/xinu
/**
 * @ingroup threads
 *
 * Kill a thread and remove it from the system
 * @param tid target thread
 * @return OK on success, SYSERR otherwise
 */
syscall kill(tid_typ tid)
{
    register struct thrent *thrptr;     /* thread control block */
    irqmask im;

    im = disable();
    if (isbadtid(tid) || (NULLTHREAD == tid))
    {
        restore(im);
        return SYSERR;
    }
    thrptr = &thrtab[tid];

    if (--thrcount <= 1)
    {
        xdone();
    }

#ifdef UHEAP_SIZE
    /* reclaim used memory regions */
    memRegionReclaim(tid);
#endif                          /* UHEAP_SIZE */

    send(thrptr->parent, tid);

    stkfree(thrptr->stkbase, thrptr->stklen);

    switch (thrptr->state)
    {
    case THRSLEEP:
        unsleep(tid);
        thrptr->state = THRFREE;
        break;
    case THRCURR:
        thrptr->state = THRFREE;        /* suicide */
        resched();

    case THRWAIT:
        semtab[thrptr->sem].count++;

    case THRREADY:
        getitem(tid);           /* removes from queue */

    default:
        thrptr->state = THRFREE;
    }

    restore(im);
    return OK;
}
示例#13
0
/*------------------------------------------------------------------------
 *  getlast  -  Remove a process from end of queue
 *------------------------------------------------------------------------
 */
pid32	getlast(
	  qid16		q		/* ID of queue from which to	*/
	)				/* remove a process (assumed	*/
					/* valid with no check)		*/
{
	pid32 tail;

	if (isempty(q)) {
		return EMPTY;
	}

	tail = queuetail(q);
	return getitem(queuetab[tail].qprev);
}
示例#14
0
/*------------------------------------------------------------------------
 *  getfirst  -  Remove a process from the front of a queue
 *------------------------------------------------------------------------
 */
pid32	getfirst(
	  qid16		q		/* ID of queue from which to	*/
	)				/* remove a process (assumed	*/
					/* valid with no check)		*/
{
	pid32	head;

	if (isempty(q)) {
		return EMPTY;
	}

	head = queuehead(q);
	return getitem(queuetab[head].qnext);
}
示例#15
0
Box* seqiterHasnext(Box* s) {
    RELEASE_ASSERT(s->cls == seqiter_cls || s->cls == seqreviter_cls, "");
    BoxedSeqIter* self = static_cast<BoxedSeqIter*>(s);

    Box* next;
    try {
        next = getitem(self->b, boxInt(self->idx));
    } catch (ExcInfo e) {
        return False;
    }
    self->idx++;
    self->next = next;
    return True;
}
示例#16
0
static void itemdraw(MENUSYS *sys, int depth, int pos, int flag) {

	MENUHDL		menu;
	VRAMHDL	vram;
	void		(*drawfn)(VRAMHDL vram, MENUHDL menu, int flag);

	menu = getitem(sys, depth, pos);
	if (menu) {
		vram = sys->wnd[depth].vram;
		drawfn = (depth)?citemdraw:bitemdraw;
		drawfn(vram, menu, flag);
		menubase_setrect(vram, &menu->rct);
	}
}
示例#17
0
/* ARGSUSED */
static void *consumer(void *arg) {                   /* compute partial sums */ 
   int error;
   buffer_t nextitem;
   double value;
 
   for (  ;  ;  )  {
      if (error = getitem(&nextitem))              /* retrieve the next item */
         break;
      value = sin(nextitem);
      if (error = add(value))
         break;
   }
   seterror(error);
   return NULL;
}
void *consumer_thread(void *arg)
{
    
   int ret;
   char cdatabuf[1024];

   while(1){

        ret = getitem(cdatabuf);                             //consume
        if(ret != 0) exit(4); //fatal error
        //printf("the received data is %s\n", cdatabuf);
   }

pthread_exit(NULL);

} 
示例#19
0
/*------------------------------------------------------------------------
 *  unsleep  -  Remove a process from the sleep queue prematurely by
 *			adjusting the delay of successive processes
 *------------------------------------------------------------------------
 */
syscall	unsleep(
	  pid32		pid		/* ID of process to remove	*/
        )
{
	intmask	mask;			/* saved interrupt mask		*/
        struct	procent	*prptr;		/* ptr to process' table entry	*/

        pid32	pidnext;		/* ID of process on sleep queue	*/
					/* that follows the process that*/
					/* is being removed		*/

	mask = disable();

	if (isbadpid(pid)) {
		restore(mask);
		return SYSERR;
	}

	/* Verify that candidate process is on the sleep queue */

	prptr = &proctab[pid];
	if ((prptr->prstate!=PR_SLEEP) && (prptr->prstate!=PR_RECTIM)) {
		restore(mask);
		return SYSERR;
	}

	/* Increment delay of next process if such a process exists */

	pidnext = queuetab[pid].qnext;
	if (pidnext < NPROC) {
		queuetab[pidnext].qkey += queuetab[pid].qkey;
	}

	if ( nonempty(sleepq) ) {
		sltop = &queuetab[firstid(sleepq)].qkey;
		slnonempty = TRUE;
	} else {
		slnonempty = FALSE;
	}
	getitem(pid);			/* unlink process from queue */
	restore(mask);
	return OK;
}
示例#20
0
void quaff()
{
  int index;
  struct object *obj;
  clearmsg();
  print1("Quaff --");
  index = getitem(POTION);
  if (index == ABORT)
    setgamestatus(SKIP_MONSTERS);
  else {
    obj = Player.possessions[index];
    if (obj->objchar != POTION) {
      print3("You can't drink ");
      nprint3(itemid(obj));
    }
    else {
      print1("You drink it down.... ");
      item_use(obj);
      morewait();
      dispose_lost_objects(1,obj);
    }
  }
}
/*------------------------------------------------------------------------
 *  unsleep  -  Internal function to remove a process from the sleep
 *		    queue prematurely.  The caller must adjust the delay
 *		    of successive processes.
 *------------------------------------------------------------------------
 */
status	unsleep(
	  pid32		pid		/* ID of process to remove	*/
        )
{
	intmask	mask;			/* Saved interrupt mask		*/
        struct	procent	*prptr;		/* Ptr to process' table entry	*/

        pid32	pidnext;		/* ID of process on sleep queue	*/
					/*   that follows the process	*/
					/*   which is being removed	*/

	mask = disable();

	if (isbadpid(pid)) {
		restore(mask);
		return SYSERR;
	}

	/* Verify that candidate process is on the sleep queue */

	prptr = &proctab[pid];
	if ((prptr->prstate!=PR_SLEEP) && (prptr->prstate!=PR_RECTIM)) {
		restore(mask);
		return SYSERR;
	}

	/* Increment delay of next process if such a process exists */

	pidnext = queuetab[pid].qnext;
	if (pidnext < NPROC) {
		queuetab[pidnext].qkey += queuetab[pid].qkey;
	}

	getitem(pid);			/* Unlink process from queue */
	restore(mask);
	return OK;
}
示例#22
0
uint32_t get_template_flags(mychan_t *mc, char *name)
{
	metadata_t *md;
	char *d;

	if (*name != '\0' && !strcasecmp(name + 1, "op"))
	{
		switch (*name)
		{
			case 's': case 'S': return chansvs.ca_sop;
			case 'a': case 'A': return chansvs.ca_aop;
			case 'h': case 'H': return chansvs.ca_hop;
			case 'v': case 'V': return chansvs.ca_vop;
		}
	}
	md = metadata_find(mc, METADATA_CHANNEL, "private:templates");
	if (md != NULL)
	{
		d = getitem(md->value, name);
		if (d != NULL)
			return flags_to_bitmask(d, chanacs_flags, 0);
	}
	return 0;
}
示例#23
0
文件: guild2.c 项目: anylonen/omega
void l_thieves_guild(void)
{
  int fee,count,i,number,done=FALSE,dues=1000;
  char c,action;
  pob lockpick;
  print1("You have penetrated to the Lair of the Thieves' Guild.");
  if (! nighttime()) 
    print2("There aren't any thieves around in the daytime.");
  else {
    if ((Player.rank[THIEVES]==TMASTER) &&
	(Player.level > Shadowlordlevel) &&
	find_and_remove_item(OB_JUSTICIAR_BADGE,-1)) {
      print2("You nicked the Justiciar's Badge!");
      morewait();
      print1("The Badge is put in a place of honor in the Guild Hall.");
      print2("You are now the Shadowlord of the Thieves' Guild!");
      morewait();
      print1("Who says there's no honor among thieves?");
      strcpy(Shadowlord,Player.name);
      Shadowlordlevel = Player.level;
      morewait();
      Shadowlordbehavior = fixnpc(4);
      save_hiscore_npc(7);
      clearmsg();
      print1("You learn the Spell of Shadowform.");
      Spells[S_SHADOWFORM].known = TRUE;
      morewait();
      clearmsg();
      Player.rank[THIEVES]=SHADOWLORD;
      Player.maxagi += 2;
      Player.maxdex += 2;
      Player.agi += 2;
      Player.dex += 2;
    }
    while (! done) {
      menuclear();
      if (Player.rank[THIEVES] == 0)
	menuprint("a: Join the Thieves' Guild.\n");
      else
	menuprint("b: Raise your Guild rank.\n");
      menuprint("c: Get an item identified.\n");
      if (Player.rank[THIEVES] > 0)
	menuprint("d: Fence an item.\n");
      menuprint("ESCAPE: Leave this Den of Iniquity.");
      showmenu();
      action = mgetc();
      if (action == ESCAPE) done = TRUE;
      else if (action == 'a') {
	done = TRUE;
	if (Player.rank[THIEVES]> 0)
	  print2("You are already a member!");
	else if (Player.alignment > 10) 
	  print2("You are too lawful to be a thief!");
	else {
	  dues += dues*(12-Player.dex)/9;
	  dues += Player.alignment*5;
	  dues = max(100,dues);
	  clearmsg();
	  mprint("Dues are");
	  mnumprint(dues);
	  mprint(" Au. Pay it? [yn] ");
	  if (ynq1() =='y') {
	    if (Player.cash < dues) {
	      print1("You can't cheat the Thieves' Guild!");
	      print2("... but the Thieves' Guild can cheat you....");
	      Player.cash = 0;
	    }
	    else {
	      print1("Shadowlord ");
	      nprint1(Shadowlord);
	      print2("enters your name into the roll of the Guild."); 
	      morewait();
	      clearmsg();
	      print1("As a special bonus, you get a free lockpick.");
	      print2("You are taught the spell of Object Detection.");
	      morewait();
	      Spells[S_OBJ_DET].known = TRUE; 
	      lockpick = ((pob) checkmalloc(sizeof(objtype)));
	      *lockpick = Objects[OB_LOCK_PICK]; /* lock pick */
	      gain_item(lockpick);
	      Player.cash -= dues;
	      dataprint();
	      Player.guildxp[THIEVES]=1;
	      Player.rank[THIEVES]=TMEMBER;
	      Player.maxdex++;Player.dex++;Player.agi++;Player.maxagi++;
	    }
	  }
	}
      }
      else if (action == 'b') {
	if (Player.rank[THIEVES]==0)
	  print2("You are not even a member!");
	else if (Player.rank[THIEVES]==SHADOWLORD) 
	  print2("You can't get any higher than this!");
	else if (Player.rank[THIEVES]==TMASTER) {
	  if (Player.level <= Shadowlordlevel)
	    print2("You are not experienced enough to advance.");
	  else print2("You must bring back the Justiciar's Badge!");
	}
	else if (Player.rank[THIEVES]==THIEF) {
	  if (Player.guildxp[THIEVES] < 4000)
	    print2("You are not experienced enough to advance.");
	  else  {
	    print1("You are now a Master Thief of the Guild!");
	    print2("You are taught the Spell of Apportation.");
	    morewait();
	    print1("To advance to the next level you must return with");
	    print2("the badge of the Justiciar (cursed be his name).");
	    morewait();
	    clearmsg();
	    print1("The Justiciar's office is just south of the gaol.");
	    Spells[S_APPORT].known = TRUE;
	    Player.rank[THIEVES]=TMASTER;
	    Player.maxagi++;
	    Player.maxdex++;
	    Player.agi++;
	    Player.dex++;
	  }
	}
	else if (Player.rank[THIEVES]==ATHIEF) {	
	  if (Player.guildxp[THIEVES] < 1500)
	    print2("You are not experienced enough to advance.");
	  else  {
	    print1("You are now a ranking Thief of the Guild!");
	    print2("You learn the Spell of Invisibility.");
	    Spells[S_INVISIBLE].known = TRUE;
	    Player.rank[THIEVES]=THIEF;
	    Player.agi++;
	    Player.maxagi++;
	  }
	}
	else if (Player.rank[THIEVES]==TMEMBER) {
	  if (Player.guildxp[THIEVES] < 400)
	    print2("You are not experienced enough to advance.");
	  else {
	    print1("You are now an Apprentice Thief!");
	    print2("You are taught the Spell of Levitation.");
	    Spells[S_LEVITATE].known = TRUE;
	    Player.rank[THIEVES]=ATHIEF;
	    Player.dex++;
	    Player.maxdex++;
	  }
	}
      }
      else if (action == 'c') {
	if (Player.rank[THIEVES]==0) {
	  print1("RTG, Inc, Appraisers. Identification Fee: 50Au/item.");
	  fee = 50;
	}
	else {
	  fee = 5;
	  print1("The fee is 5Au per item.");
	}
	print2("Identify one item, or all possessions? [ip] ");
	if ((char) mcigetc()=='i') {
	  if (Player.cash < fee)
	    print2("Try again when you have the cash.");
	  else {
	    Player.cash -= fee;
	    dataprint();
	    identify(0);
	  }
	}
	else {
	  count = 0;
	  for(i=1;i<MAXITEMS;i++)
	    if (Player.possessions[i] != NULL)
	      if (Player.possessions[i]->known < 2)
		count++;
	  for(i=0;i<Player.packptr;i++)
	    if (Player.pack[i] != NULL)
	      if (Player.pack[i]->known < 2)
		count++;
	  clearmsg();
	  print1("The fee will be: ");
	  mnumprint(max(count*fee,fee));
	  nprint1("Au. Pay it? [yn] ");
	  if (ynq1()=='y')
	  {
	    if (Player.cash < max(count*fee,fee))
	      print2("Try again when you have the cash.");
	    else {
	      Player.cash -= max(count*fee,fee);
	      dataprint();
	      identify(1);
	    }
	  }
	}
      }
      else if (action == 'd') {
	if (Player.rank[THIEVES]==0)
	  print2("Fence? Who said anything about a fence?");
	else {
	  print1("Fence one item or go through pack? [ip] ");
	  if ((char) mcigetc()=='i') {
	    i = getitem(NULL_ITEM);
	    if ((i==ABORT) || (Player.possessions[i] == NULL))
	      print2("Huh, Is this some kind of set-up?");
	    else if (Player.possessions[i]->blessing < 0) 
	      print2("I don't want to buy a cursed item!");
	    else {
	      clearmsg();
	      print1("I'll give you ");
	      mlongprint(2 * item_value(Player.possessions[i]) / 3);
	      nprint1("Au each. OK? [yn] ");
	      if (ynq1() == 'y') {
		number = getnumber(Player.possessions[i]->number);
		if ((number >= Player.possessions[i]->number) &&
		    Player.possessions[i]->used) {
		  Player.possessions[i]->used = FALSE;
		  item_use(Player.possessions[i]);
		}
		Player.cash += number*2*item_value(Player.possessions[i])/3;
		/* Fenced artifacts could turn up anywhere, really... */
		if (Objects[Player.possessions[i]->id].uniqueness >
		    UNIQUE_UNMADE)
		  Objects[Player.possessions[i]->id].uniqueness = UNIQUE_UNMADE;
		dispose_lost_objects(number,Player.possessions[i]);
		dataprint();
	      }
	      else print2("Hey, gimme a break, it was a fair price!");
	    }
	  }
	  else {
	    for(i=0;i<Player.packptr;i++) {
	      if (Player.pack[i]->blessing > -1) {
		clearmsg();
		print1("Sell ");
		nprint1(itemid(Player.pack[i]));
		nprint1(" for ");
		mlongprint(2*item_value(Player.pack[i])/3);
		nprint1("Au each? [ynq] ");
		if ((c=ynq1())=='y') {
		  number = getnumber(Player.pack[i]->number);
		  Player.cash += 2*number * item_value(Player.pack[i]) / 3;
		  Player.pack[i]->number -= number;
		  if (Player.pack[i]->number < 1) {
                    /* Fenced an artifact?  You just might see it again. */
 		    if (Objects[Player.pack[i]->id].uniqueness > UNIQUE_UNMADE)
 		      Objects[Player.pack[i]->id].uniqueness = UNIQUE_UNMADE;
		    free((char *)Player.pack[i]);
		    Player.pack[i] = NULL;
		  }
		  dataprint();
		}
		else if (c=='q') break;
	      }
	    }
	    fixpack();
	  }
	}
      }
    }
  }
  xredraw();
}
示例#24
0
// Pick up items at (pos).
void Pickup::pick_up( const tripoint &pos, int min )
{
    int cargo_part = -1;

    const optional_vpart_position vp = g->m.veh_at( pos );
    vehicle *const veh = veh_pointer_or_null( vp );
    bool from_vehicle = false;

    if( min != -1 ) {
        switch( interact_with_vehicle( veh, pos, vp ? vp->part_index() : -1 ) ) {
            case DONE:
                return;
            case ITEMS_FROM_CARGO: {
                const cata::optional<vpart_reference> carg = vp.part_with_feature( "CARGO", false );
                cargo_part = carg ? carg->part_index() : -1;
            }
            from_vehicle = cargo_part >= 0;
            break;
            case ITEMS_FROM_GROUND:
                // Nothing to change, default is to pick from ground anyway.
                if( g->m.has_flag( "SEALED", pos ) ) {
                    return;
                }

                break;
        }
    }

    if( !from_vehicle ) {
        bool isEmpty = ( g->m.i_at( pos ).empty() );

        // Hide the pickup window if this is a toilet and there's nothing here
        // but water.
        if( ( !isEmpty ) && g->m.furn( pos ) == f_toilet ) {
            isEmpty = true;
            for( auto maybe_water : g->m.i_at( pos ) ) {
                if( maybe_water.typeId() != "water" ) {
                    isEmpty = false;
                    break;
                }
            }
        }

        if( isEmpty && ( min != -1 || !get_option<bool>( "AUTO_PICKUP_ADJACENT" ) ) ) {
            return;
        }
    }

    // which items are we grabbing?
    std::vector<item> here;
    if( from_vehicle ) {
        auto vehitems = veh->get_items( cargo_part );
        here.resize( vehitems.size() );
        std::copy( vehitems.begin(), vehitems.end(), here.begin() );
    } else {
        auto mapitems = g->m.i_at( pos );
        here.resize( mapitems.size() );
        std::copy( mapitems.begin(), mapitems.end(), here.begin() );
    }

    if( min == -1 ) {
        // Recursively pick up adjacent items if that option is on.
        if( get_option<bool>( "AUTO_PICKUP_ADJACENT" ) && g->u.pos() == pos ) {
            //Autopickup adjacent
            direction adjacentDir[8] = {NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST};
            for( auto &elem : adjacentDir ) {

                tripoint apos = tripoint( direction_XY( elem ), 0 );
                apos += pos;

                pick_up( apos, min );
            }
        }

        // Bail out if this square cannot be auto-picked-up
        if( g->check_zone( zone_type_id( "NO_AUTO_PICKUP" ), pos ) ) {
            return;
        } else if( g->m.has_flag( "SEALED", pos ) ) {
            return;
        }
    }

    // Not many items, just grab them
    if( ( int )here.size() <= min && min != -1 ) {
        g->u.assign_activity( activity_id( "ACT_PICKUP" ) );
        g->u.activity.placement = pos - g->u.pos();
        g->u.activity.values.push_back( from_vehicle );
        // Only one item means index is 0.
        g->u.activity.values.push_back( 0 );
        // auto-pickup means pick up all.
        g->u.activity.values.push_back( 0 );
        return;
    }

    std::vector<std::list<item_idx>> stacked_here;
    for( size_t i = 0; i < here.size(); i++ ) {
        item &it = here[i];
        bool found_stack = false;
        for( auto &stack : stacked_here ) {
            if( stack.begin()->_item.stacks_with( it ) ) {
                item_idx el = { it, i };
                stack.push_back( el );
                found_stack = true;
                break;
            }
        }
        if( !found_stack ) {
            std::list<item_idx> newstack;
            newstack.push_back( { it, i } );
            stacked_here.push_back( newstack );
        }
    }
    std::reverse( stacked_here.begin(), stacked_here.end() );

    if( min != -1 ) { // don't bother if we're just autopickuping
        g->temp_exit_fullscreen();
    }
    bool sideStyle = use_narrow_sidebar();

    // Otherwise, we have Autopickup, 2 or more items and should list them, etc.
    int maxmaxitems = sideStyle ? TERMY : getmaxy( g->w_messages ) - 3;

    int itemsH = std::min( 25, TERMY / 2 );
    int pickupBorderRows = 3;

    // The pickup list may consume the entire terminal, minus space needed for its
    // header/footer and the item info window.
    int minleftover = itemsH + pickupBorderRows;
    if( maxmaxitems > TERMY - minleftover ) {
        maxmaxitems = TERMY - minleftover;
    }

    const int minmaxitems = sideStyle ? 6 : 9;

    std::vector<pickup_count> getitem( stacked_here.size() );

    int maxitems = stacked_here.size();
    maxitems = ( maxitems < minmaxitems ? minmaxitems : ( maxitems > maxmaxitems ? maxmaxitems :
                 maxitems ) );

    int itemcount = 0;

    if( min == -1 ) { //Auto Pickup, select matching items
        if( !select_autopickup_items( stacked_here, getitem ) ) {
            // If we didn't find anything, bail out now.
            return;
        }
    } else {
        int pickupH = maxitems + pickupBorderRows;
        int pickupW = getmaxx( g->w_messages );
        int pickupY = VIEW_OFFSET_Y;
        int pickupX = getbegx( g->w_messages );

        int itemsW = pickupW;
        int itemsY = sideStyle ? pickupY + pickupH : TERMY - itemsH;
        int itemsX = pickupX;

        catacurses::window w_pickup = catacurses::newwin( pickupH, pickupW, pickupY, pickupX );
        catacurses::window w_item_info = catacurses::newwin( itemsH,  itemsW,  itemsY,  itemsX );

        std::string action;
        long raw_input_char = ' ';
        input_context ctxt( "PICKUP" );
        ctxt.register_action( "UP" );
        ctxt.register_action( "DOWN" );
        ctxt.register_action( "RIGHT" );
        ctxt.register_action( "LEFT" );
        ctxt.register_action( "NEXT_TAB", _( "Next page" ) );
        ctxt.register_action( "PREV_TAB", _( "Previous page" ) );
        ctxt.register_action( "SCROLL_UP" );
        ctxt.register_action( "SCROLL_DOWN" );
        ctxt.register_action( "CONFIRM" );
        ctxt.register_action( "SELECT_ALL" );
        ctxt.register_action( "QUIT", _( "Cancel" ) );
        ctxt.register_action( "ANY_INPUT" );
        ctxt.register_action( "HELP_KEYBINDINGS" );
        ctxt.register_action( "FILTER" );

        int start = 0;
        int cur_it = 0;
        bool update = true;
        mvwprintw( w_pickup, 0, 0, _( "PICK UP" ) );
        int selected = 0;
        int iScrollPos = 0;

        std::string filter;
        std::string new_filter;
        std::vector<int> matches;//Indexes of items that match the filter
        bool filter_changed = true;
        if( g->was_fullscreen ) {
            g->draw_ter();
        }
        // Now print the two lists; those on the ground and about to be added to inv
        // Continue until we hit return or space
        do {
            const std::string pickup_chars =
                ctxt.get_available_single_char_hotkeys( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;" );
            int idx = -1;
            for( int i = 1; i < pickupH; i++ ) {
                mvwprintw( w_pickup, i, 0,
                           "                                                " );
            }
            if( action == "ANY_INPUT" &&
                raw_input_char >= '0' && raw_input_char <= '9' ) {
                int raw_input_char_value = ( char )raw_input_char - '0';
                itemcount *= 10;
                itemcount += raw_input_char_value;
                if( itemcount < 0 ) {
                    itemcount = 0;
                }
            } else if( action == "SCROLL_UP" ) {
                iScrollPos--;
            } else if( action == "SCROLL_DOWN" ) {
                iScrollPos++;
            } else if( action == "PREV_TAB" ) {
                if( start > 0 ) {
                    start -= maxitems;
                } else {
                    start = ( int )( ( matches.size() - 1 ) / maxitems ) * maxitems;
                }
                selected = start;
                mvwprintw( w_pickup, maxitems + 2, 0, "         " );
            } else if( action == "NEXT_TAB" ) {
                if( start + maxitems < ( int )matches.size() ) {
                    start += maxitems;
                } else {
                    start = 0;
                }
                iScrollPos = 0;
                selected = start;
                mvwprintw( w_pickup, maxitems + 2, pickupH, "            " );
            } else if( action == "UP" ) {
                selected--;
                iScrollPos = 0;
                if( selected < 0 ) {
                    selected = matches.size() - 1;
                    start = ( int )( matches.size() / maxitems ) * maxitems;
                    if( start >= ( int )matches.size() ) {
                        start -= maxitems;
                    }
                } else if( selected < start ) {
                    start -= maxitems;
                }
            } else if( action == "DOWN" ) {
                selected++;
                iScrollPos = 0;
                if( selected >= ( int )matches.size() ) {
                    selected = 0;
                    start = 0;
                } else if( selected >= start + maxitems ) {
                    start += maxitems;
                }
            } else if( selected >= 0 && selected < int( matches.size() ) &&
                       ( ( action == "RIGHT" && !getitem[matches[selected]].pick ) ||
                         ( action == "LEFT" && getitem[matches[selected]].pick ) ) ) {
                idx = selected;
            } else if( action == "FILTER" ) {
                new_filter = filter;
                string_input_popup popup;
                popup
                .title( _( "Set filter" ) )
                .width( 30 )
                .edit( new_filter );
                if( !popup.canceled() ) {
                    filter_changed = true;
                } else {
                    wrefresh( g->w_terrain );
                }
            } else if( action == "ANY_INPUT" && raw_input_char == '`' ) {
                std::string ext = string_input_popup()
                                  .title( _( "Enter 2 letters (case sensitive):" ) )
                                  .width( 3 )
                                  .max_length( 2 )
                                  .query_string();
                if( ext.size() == 2 ) {
                    int p1 = pickup_chars.find( ext.at( 0 ) );
                    int p2 = pickup_chars.find( ext.at( 1 ) );
                    if( p1 != -1 && p2 != -1 ) {
                        idx = pickup_chars.size() + ( p1 * pickup_chars.size() ) + p2;
                    }
                }
            } else if( action == "ANY_INPUT" ) {
                idx = ( raw_input_char <= 127 ) ? pickup_chars.find( raw_input_char ) : -1;
                iScrollPos = 0;
            }

            if( idx >= 0 && idx < ( int )matches.size() ) {
                size_t true_idx = matches[idx];
                if( itemcount != 0 || getitem[true_idx].count == 0 ) {
                    item &temp = stacked_here[true_idx].begin()->_item;
                    int amount_available = temp.count_by_charges() ? temp.charges : stacked_here[true_idx].size();
                    if( itemcount >= amount_available ) {
                        itemcount = 0;
                    }
                    getitem[true_idx].count = itemcount;
                    itemcount = 0;
                }

                // Note: this might not change the value of getitem[idx] at all!
                getitem[true_idx].pick = ( action == "RIGHT" ? true :
                                           ( action == "LEFT" ? false :
                                             !getitem[true_idx].pick ) );
                if( action != "RIGHT" && action != "LEFT" ) {
                    selected = idx;
                    start = ( int )( idx / maxitems ) * maxitems;
                }

                if( !getitem[true_idx].pick ) {
                    getitem[true_idx].count = 0;
                }
                update = true;
            }
            if( filter_changed ) {
                matches.clear();
                while( matches.empty() ) {
                    auto filter_func = item_filter_from_string( new_filter );
                    for( size_t index = 0; index < stacked_here.size(); index++ ) {
                        if( filter_func( stacked_here[index].begin()->_item ) ) {
                            matches.push_back( index );
                        }
                    }
                    if( matches.empty() ) {
                        popup( _( "Your filter returned no results" ) );
                        wrefresh( g->w_terrain );
                        // The filter must have results, or simply be emptied or canceled,
                        // as this screen can't be reached without there being
                        // items available
                        string_input_popup popup;
                        popup
                        .title( _( "Set filter" ) )
                        .width( 30 )
                        .edit( new_filter );
                        if( popup.canceled() ) {
                            new_filter = filter;
                            filter_changed = false;
                        }
                    }
                }
                if( filter_changed ) {
                    filter = new_filter;
                    filter_changed = false;
                    selected = 0;
                    start = 0;
                    iScrollPos = 0;
                }
                wrefresh( g->w_terrain );
            }
            item &selected_item = stacked_here[matches[selected]].begin()->_item;

            werase( w_item_info );
            if( selected >= 0 && selected <= ( int )stacked_here.size() - 1 ) {
                std::vector<iteminfo> vThisItem;
                std::vector<iteminfo> vDummy;
                selected_item.info( true, vThisItem );

                draw_item_info( w_item_info, "", "", vThisItem, vDummy, iScrollPos, true, true );
            }
            draw_custom_border( w_item_info, false );
            mvwprintw( w_item_info, 0, 2, "< " );
            trim_and_print( w_item_info, 0, 4, itemsW - 8, c_white, "%s >",
                            selected_item.display_name().c_str() );
            wrefresh( w_item_info );

            if( action == "SELECT_ALL" ) {
                int count = 0;
                for( auto i : matches ) {
                    if( getitem[i].pick ) {
                        count++;
                    }
                    getitem[i].pick = true;
                }
                if( count == ( int )stacked_here.size() ) {
                    for( size_t i = 0; i < stacked_here.size(); i++ ) {
                        getitem[i].pick = false;
                    }
                }
                update = true;
            }
            for( cur_it = start; cur_it < start + maxitems; cur_it++ ) {
                mvwprintw( w_pickup, 1 + ( cur_it % maxitems ), 0,
                           "                                        " );
                if( cur_it < ( int )matches.size() ) {
                    int true_it = matches[cur_it];
                    item &this_item = stacked_here[ true_it ].begin()->_item;
                    nc_color icolor = this_item.color_in_inventory();
                    if( cur_it == selected ) {
                        icolor = hilite( icolor );
                    }

                    if( cur_it < ( int )pickup_chars.size() ) {
                        mvwputch( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor,
                                  char( pickup_chars[cur_it] ) );
                    } else if( cur_it < ( int )pickup_chars.size() + ( int )pickup_chars.size() *
                               ( int )pickup_chars.size() ) {
                        int p = cur_it - pickup_chars.size();
                        int p1 = p / pickup_chars.size();
                        int p2 = p % pickup_chars.size();
                        mvwprintz( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, "`%c%c",
                                   char( pickup_chars[p1] ), char( pickup_chars[p2] ) );
                    } else {
                        mvwputch( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, ' ' );
                    }
                    if( getitem[true_it].pick ) {
                        if( getitem[true_it].count == 0 ) {
                            wprintz( w_pickup, c_light_blue, " + " );
                        } else {
                            wprintz( w_pickup, c_light_blue, " # " );
                        }
                    } else {
                        wprintw( w_pickup, " - " );
                    }
                    std::string item_name;
                    if( stacked_here[true_it].begin()->_item.ammo_type() == "money" ) {
                        //Count charges
                        //TODO: transition to the item_location system used for the inventory
                        unsigned long charges_total = 0;
                        for( const auto item : stacked_here[true_it] ) {
                            charges_total += item._item.charges;
                        }
                        //Picking up none or all the cards in a stack
                        if( !getitem[true_it].pick || getitem[true_it].count == 0 ) {
                            item_name = stacked_here[true_it].begin()->_item.display_money( stacked_here[true_it].size(),
                                        charges_total );
                        } else {
                            unsigned long charges = 0;
                            int c = getitem[true_it].count;
                            for( auto it = stacked_here[true_it].begin(); it != stacked_here[true_it].end() &&
                                 c > 0; ++it, --c ) {
                                charges += it->_item.charges;
                            }
                            item_name = string_format( _( "%s of %s" ),
                                                       stacked_here[true_it].begin()->_item.display_money( getitem[true_it].count, charges ),
                                                       format_money( charges_total ) );
                        }
                    } else {
                        item_name = this_item.display_name( stacked_here[true_it].size() );
                    }
                    if( stacked_here[true_it].size() > 1 ) {
                        item_name = string_format( "%d %s", stacked_here[true_it].size(), item_name.c_str() );
                    }
                    if( get_option<bool>( "ITEM_SYMBOLS" ) ) {
                        item_name = string_format( "%s %s", this_item.symbol().c_str(),
                                                   item_name.c_str() );
                    }
                    trim_and_print( w_pickup, 1 + ( cur_it % maxitems ), 6, pickupW - 4, icolor,
                                    item_name );
                }
            }

            mvwprintw( w_pickup, maxitems + 1, 0, _( "[%s] Unmark" ),
                       ctxt.get_desc( "LEFT", 1 ).c_str() );

            center_print( w_pickup, maxitems + 1, c_light_gray, string_format( _( "[%s] Help" ),
                          ctxt.get_desc( "HELP_KEYBINDINGS", 1 ).c_str() ) );

            right_print( w_pickup, maxitems + 1, 0, c_light_gray, string_format( _( "[%s] Mark" ),
                         ctxt.get_desc( "RIGHT", 1 ).c_str() ) );

            mvwprintw( w_pickup, maxitems + 2, 0, _( "[%s] Prev" ),
                       ctxt.get_desc( "PREV_TAB", 1 ).c_str() );

            center_print( w_pickup, maxitems + 2, c_light_gray, string_format( _( "[%s] All" ),
                          ctxt.get_desc( "SELECT_ALL", 1 ).c_str() ) );

            right_print( w_pickup, maxitems + 2, 0, c_light_gray, string_format( _( "[%s] Next" ),
                         ctxt.get_desc( "NEXT_TAB", 1 ).c_str() ) );

            if( update ) { // Update weight & volume information
                update = false;
                for( int i = 9; i < pickupW; ++i ) {
                    mvwaddch( w_pickup, 0, i, ' ' );
                }
                units::mass weight_picked_up = 0;
                units::volume volume_picked_up = 0;
                for( size_t i = 0; i < getitem.size(); i++ ) {
                    if( getitem[i].pick ) {
                        item temp = stacked_here[i].begin()->_item;
                        if( temp.count_by_charges() && getitem[i].count < temp.charges && getitem[i].count != 0 ) {
                            temp.charges = getitem[i].count;
                        }
                        int num_picked = std::min( stacked_here[i].size(),
                                                   getitem[i].count == 0 ? stacked_here[i].size() : getitem[i].count );
                        weight_picked_up += temp.weight() * num_picked;
                        volume_picked_up += temp.volume() * num_picked;
                    }
                }

                auto weight_predict = g->u.weight_carried() + weight_picked_up;
                auto volume_predict = g->u.volume_carried() + volume_picked_up;

                mvwprintz( w_pickup, 0, 9, weight_predict > g->u.weight_capacity() ? c_red : c_white,
                           _( "Wgt %.1f" ), round_up( convert_weight( weight_predict ), 1 ) );

                wprintz( w_pickup, c_white, "/%.1f", round_up( convert_weight( g->u.weight_capacity() ), 1 ) );

                std::string fmted_volume_predict = format_volume( volume_predict );
                mvwprintz( w_pickup, 0, 24, volume_predict > g->u.volume_capacity() ? c_red : c_white,
                           _( "Vol %s" ), fmted_volume_predict.c_str() );

                std::string fmted_volume_capacity = format_volume( g->u.volume_capacity() );
                wprintz( w_pickup, c_white, "/%s", fmted_volume_capacity.c_str() );
            };

            wrefresh( w_pickup );

            action = ctxt.handle_input();
            raw_input_char = ctxt.get_raw_input().get_first_input();

        } while( action != "QUIT" && action != "CONFIRM" );

        bool item_selected = false;
        // Check if we have selected an item.
        for( auto selection : getitem ) {
            if( selection.pick ) {
                item_selected = true;
            }
        }
        if( action != "CONFIRM" || !item_selected ) {
            w_pickup = catacurses::window();
            w_item_info = catacurses::window();
            add_msg( _( "Never mind." ) );
            g->reenter_fullscreen();
            g->refresh_all();
            return;
        }
    }

    // At this point we've selected our items, register an activity to pick them up.
    g->u.assign_activity( activity_id( "ACT_PICKUP" ) );
    g->u.activity.placement = pos - g->u.pos();
    g->u.activity.values.push_back( from_vehicle );
    if( min == -1 ) {
        // Auto pickup will need to auto resume since there can be several of them on the stack.
        g->u.activity.auto_resume = true;
    }
    std::vector<std::pair<int, int>> pick_values;
    for( size_t i = 0; i < stacked_here.size(); i++ ) {
        const auto &selection = getitem[i];
        if( !selection.pick ) {
            continue;
        }

        const auto &stack = stacked_here[i];
        // Note: items can be both charged and stacked
        // For robustness, let's assume they can be both in the same stack
        bool pick_all = selection.count == 0;
        size_t count = selection.count;
        for( const item_idx &it : stack ) {
            if( !pick_all && count == 0 ) {
                break;
            }

            if( it._item.count_by_charges() ) {
                size_t num_picked = std::min( ( size_t )it._item.charges, count );
                pick_values.push_back( { static_cast<int>( it.idx ), static_cast<int>( num_picked ) } );
                count -= num_picked;
            } else {
                size_t num_picked = 1;
                pick_values.push_back( { static_cast<int>( it.idx ), 0 } );
                count -= num_picked;
            }
        }
    }
    // The pickup activity picks up items last-to-first from its values list, so make sure the
    // higher indices are at the end.
    std::sort( pick_values.begin(), pick_values.end() );
    for( auto &it : pick_values ) {
        g->u.activity.values.push_back( it.first );
        g->u.activity.values.push_back( it.second );
    }

    g->reenter_fullscreen();
}
示例#25
0
static BRESULT childopn(MENUSYS *sys, int depth, int pos) {

	MENUHDL	menu;
	RECT_T	parent;
	int		dir;
	int		width;
	int		height;
	int		items;
	MSYSWND	wnd;
	int		drawitems;
	POINT_T	pt;

	menu = getitem(sys, depth, pos);
	if ((menu == NULL) || (menu->child == NULL)) {
		TRACEOUT(("child not found."));
		goto copn_err;
	}
	wnd = sys->wnd + depth;
	if ((menu->flag & MENUS_CTRLMASK) == MENUS_POPUP) {
		parent.left = sys->popupx;
		parent.top = max(sys->popupy, wnd->vram->height);
		parent.right = parent.left;
		parent.bottom = parent.top;
		dir = 0;
	}
	else {
		parent.left = wnd->vram->posx + menu->rct.left;
		parent.top = wnd->vram->posy + menu->rct.top;
		parent.right = wnd->vram->posx + menu->rct.right;
		parent.bottom = wnd->vram->posy + menu->rct.bottom;
		dir = depth + 1;
	}
	if (depth >= (MENUSYS_MAX - 1)) {
		TRACEOUT(("menu max."));
		goto copn_err;
	}
	wnd++;
	width = 0;
	height = (MENU_FBORDER + MENU_BORDER);
	items = 0;
	drawitems = 0;
	menu = menu->child;
	wnd->menu = menu;
	while(menu) {
		if (!(menu->flag & MENU_DISABLE)) {
			menu->rct.left = (MENU_FBORDER + MENU_BORDER);
			menu->rct.top = height;
			if (menu->flag & MENU_SEPARATOR) {
				if (height > (menubase.height - MENUSYS_CYSEP -
											(MENU_FBORDER + MENU_BORDER))) {
					break;
				}
				height += MENUSYS_CYSEP;
				menu->rct.bottom = height;
			}
			else {
				if (height > (menubase.height - MENUSYS_CYITEM -
											(MENU_FBORDER + MENU_BORDER))) {
					break;
				}
				height += MENUSYS_CYITEM;
				menu->rct.bottom = height;
				fontmng_getsize(menubase.font, menu->string, &pt);
				if (width < pt.x) {
					width = pt.x;
				}
			}
		}
		items++;
		menu = menu->next;
	}
	width += ((MENU_FBORDER + MENU_BORDER + MENUSYS_SXITEM) * 2) +
										MENUSYS_CXCHECK + MENUSYS_CXNEXT;
	if (width >= menubase.width) {
		width = menubase.width;
	}
	height += (MENU_FBORDER + MENU_BORDER);
	wnd->vram = menuvram_create(width, height, menubase.bpp);
	if (wnd->vram == NULL) {
		TRACEOUT(("sub menu vram couldn't create"));
		goto copn_err;
	}
	if (dir == 1) {
		if ((parent.top < height) ||
			(parent.bottom < (menubase.height - height))) {
			parent.top = parent.bottom;
		}
		else {
			parent.top -= height;
		}
	}
	else if (dir >= 2) {
		if ((parent.left < width) ||
			(parent.right < (menubase.width - width))) {
			parent.left = parent.right;
		}
		else {
			parent.left -= width;
		}
		if ((parent.top > (menubase.height - height)) &&
			(parent.bottom >= height)) {
			parent.top = parent.bottom - height;
		}
	}
	wnd->vram->posx = min(parent.left, menubase.width - width);
	wnd->vram->posy = min(parent.top, menubase.height - height);
	wnd->items = items;
	wnd->focus = -1;
	sys->depth++;
	menu = wnd->menu;
	drawitems = items;
	while(drawitems--) {
		if (!(menu->flag & MENU_DISABLE)) {
			menu->rct.right = width - (MENU_FBORDER + MENU_BORDER);
			citemdraw(wnd->vram, menu, 0);
		}
		menu = menu->next;
	}
	menubase_setrect(wnd->vram, NULL);
	return(SUCCESS);

copn_err:
	return(FAILURE);
}
示例#26
0
/* enchant */
void enchant(int delta)
{
    int i,used = false;
    long change_cash;

    if (delta < 0) {
        i = random_item();
        if (i == ABORT || Player.possessions[i]->usef == I_NOTHING ||
                Player.possessions[i]->usef == I_NO_OP ||
                Player.possessions[i]->usef == I_NORMAL_ARMOR ||
                Player.possessions[i]->usef == I_NORMAL_WEAPON ||
                Player.possessions[i]->usef == I_NORMAL_SHIELD ||
                Player.possessions[i]->objchar == FOOD ||
                Player.possessions[i]->objchar == MISSILEWEAPON) {
            print1("You feel fortunate.");
            morewait();
        }
        else if (Player.possessions[i]->blessing < 0 ||
                 (Player.possessions[i]->objchar == ARTIFACT && random_range(3))) {
            if (Player.possessions[i]->uniqueness == COMMON)
                print1("Your ");
            nprint1(itemid(Player.possessions[i]));
            nprint1(" glows, but the glow flickers out...");
            morewait();
        }
        else {
            used = (Player.possessions[i]->used);
            if (used) {
                Player.possessions[i]->used = false;
                item_use(Player.possessions[i]);
            }
            if (Player.possessions[i]->uniqueness == COMMON)
                print1("Your ");
            nprint1(itemid(Player.possessions[i]));
            nprint1(" radiates an aura of mundanity!");
            morewait();
            Player.possessions[i]->plus = 0;
            Player.possessions[i]->charge = -1;
            Player.possessions[i]->usef = I_NOTHING;
            if (used) {
                Player.possessions[i]->used = true;
                item_use(Player.possessions[i]);
            }
        }
    }
    else {
        i = getitem(CASH);
        if (i == ABORT) {
            print1("You feel unlucky.");
            morewait();
        }
        else if (i == CASHVALUE) {
            print1("You enchant your money.... What a concept!");
            change_cash = Player.cash*(random_range(7) - 3)/6;
            if (change_cash > 0) print2("Seems to have been a good idea!");
            else print2("Maybe it wasn't such a good idea....");
            Player.cash += change_cash;
            morewait();
        }
        else if (Player.possessions[i]->objchar == ARTIFACT) {
            if (Player.possessions[i]->usef !=
                    Objects[Player.possessions[i]->id].usef) {
                print1("It re-acquires its magical aura!");
                Player.possessions[i]->usef = Objects[Player.possessions[i]->id].usef;
            }
            else {
                print1("The enchantment spell enfolds the ");
                nprint1(itemid(Player.possessions[i]));
                print2("and the potent enchantment of the Artifact causes a backlash!");
                morewait();
                clearmsg();
                manastorm(Player.x,Player.y,Player.possessions[i]->level*5);
            }
        }
        else {
            if (Player.possessions[i]->plus > random_range(20)+1) {
                print1("Uh-oh, the force of the enchantment was too much!");
                print2("There is a loud explosion!");
                morewait();
                manastorm(Player.x,Player.y,Player.possessions[i]->plus*5);
                dispose_lost_objects(1,Player.possessions[i]);
            }
            else {
                used = (Player.possessions[i]->used);
                if (used) {
                    State.setSuppressPrinting( true );
                    Player.possessions[i]->used = false;
                    item_use(Player.possessions[i]);
                    State.setSuppressPrinting( false );
                }
                print1("The item shines!");
                morewait();
                Player.possessions[i]->plus += delta+1;
                if (Player.possessions[i]->charge > -1)
                    Player.possessions[i]->charge +=
                        ((delta+1) * (random_range(10) + 1));
                if (used) {
                    State.setSuppressPrinting( true );
                    Player.possessions[i]->used = true;
                    item_use(Player.possessions[i]);
                    State.setSuppressPrinting( false );
                }
            }
        }
        calc_melee();
    }
}
示例#27
0
/* bless */
void bless(int blessing)
{
    int index,used;

    if (blessing < 0) {
        index = random_item();
        if (index == ABORT) {
            print1("You feel fortunate.");
            morewait();
        }
        else {
            print1("A foul odor arises from ");
            if (Player.possessions[index]->uniqueness == COMMON)
                nprint1("your ");
            nprint1(itemid(Player.possessions[index]));
            morewait();
            used = (Player.possessions[index]->used);
            if (used) {
                State.setSuppressPrinting( true );
                Player.possessions[index]->used = false;
                item_use(Player.possessions[index]);
                State.setSuppressPrinting( false );
            }
            Player.possessions[index]->blessing -= 2;
            if (Player.possessions[index]->blessing < 0)
                Player.possessions[index]->plus =
                    abs(Player.possessions[index]->plus) - 1;
            if (used) {
                State.setSuppressPrinting( true );
                Player.possessions[index]->used = true;
                item_use(Player.possessions[index]);
                State.setSuppressPrinting( false );
            }
        }
    }
    else {
        index = getitem(NULL_ITEM);
        if (index == CASHVALUE) {
            print1("Blessing your money has no effect.");
            morewait();
        }
        else if (index != ABORT) {
            used = Player.possessions[index]->isUsed();
            if (used) {
                State.setSuppressPrinting( true );
                Player.possessions[index]->used = false;
                item_use(Player.possessions[index]);
                State.setSuppressPrinting( false );
            }
            print1("A pure white light surrounds the item... ");
            if (Player.possessions[index]->blessing < 0-(blessing+1)) {
                print2("which is evil enough to resist the effect of the blessing!");
                morewait();
            }
            else if (Player.possessions[index]->blessing < -1) {
                print2("which disintegrates under the influence of the holy aura!");
                morewait();
                Player.itemweight -=  Player.possessions[index]->weight;
                dispose_lost_objects(1,Player.possessions[index]);
            }
            else if (Player.possessions[index]->blessing < blessing+1) {
                print2("which now seems affected by afflatus!");
                morewait();
                Player.possessions[index]->blessing++;
                Player.possessions[index]->plus =
                    abs(Player.possessions[index]->plus)+1;
            }
            else {
                print2("The hierolux fades without any appreciable effect....");
                morewait();
            }
            if (used && (Player.possessions[index] != NULL)) {
                State.setSuppressPrinting( true );
                Player.possessions[index]->used = true;
                item_use(Player.possessions[index]);
                State.setSuppressPrinting( false );
            }
        }
    }
    calc_melee();
}
示例#28
0
#include <stdlib.h>
#include <stdio.h>
#include "new.h"
#include "list.h"
#include "int.h"
#include "iterator.h"

int main()
{
    Object *obj = new(List, 10, Int, 42);
    additem(obj, 10);
    setitem(obj, 0, 84);
    printf("%s\n", str(obj));
    pop_front(obj);
    pop_back(obj);
    printf("%s\n", str(obj));
    push_front(obj, 100);
    push_back(obj, 200);
    printf("%s\n", str(obj));
    Object *obj2 = getitem(obj, 1);
    printf("obj2 : %s\n", str(obj2));
    Iterator *it = begin(obj), *e = end(obj);

    while (lt(it, e)) {
	printf("%s\n", str(getval(it)));
	incr(it);
    }
    delete(obj);
    return (0);
}
示例#29
0
// Pick up items at (pos).
void Pickup::pick_up( const tripoint &pos, int min )
{
    int veh_root_part = 0;
    int cargo_part = -1;

    vehicle *veh = g->m.veh_at( pos, veh_root_part );
    bool from_vehicle = false;

    if( min != -1 ) {
        switch( interact_with_vehicle( veh, pos, veh_root_part ) ) {
            case DONE:
                return;
            case ITEMS_FROM_CARGO:
                cargo_part = veh->part_with_feature( veh_root_part, "CARGO", false );
                from_vehicle = cargo_part >= 0;
                break;
            case ITEMS_FROM_GROUND:
                // Nothing to change, default is to pick from ground anyway.
                if( g->m.has_flag( "SEALED", pos ) ) {
                    return;
                }

                break;
        }
    }

    if( !from_vehicle ) {
        bool isEmpty = ( g->m.i_at( pos ).empty() );

        // Hide the pickup window if this is a toilet and there's nothing here
        // but water.
        if( ( !isEmpty ) && g->m.furn( pos ) == f_toilet ) {
            isEmpty = true;
            for( auto maybe_water : g->m.i_at( pos ) ) {
                if( maybe_water.typeId() != "water" ) {
                    isEmpty = false;
                    break;
                }
            }
        }

        if( isEmpty && ( min != -1 || !OPTIONS["AUTO_PICKUP_ADJACENT"] ) ) {
            return;
        }
    }

    // which items are we grabbing?
    std::vector<item> here;
    if( from_vehicle ) {
        auto vehitems = veh->get_items( cargo_part );
        here.resize( vehitems.size() );
        std::copy( vehitems.rbegin(), vehitems.rend(), here.begin() );
    } else {
        auto mapitems = g->m.i_at( pos );
        here.resize( mapitems.size() );
        std::copy( mapitems.rbegin(), mapitems.rend(), here.begin() );
    }

    if( min == -1 ) {
        if( g->check_zone( "NO_AUTO_PICKUP", pos ) ) {
            here.clear();
        }

        // Recursively pick up adjacent items if that option is on.
        if( OPTIONS["AUTO_PICKUP_ADJACENT"] && g->u.pos() == pos ) {
            //Autopickup adjacent
            direction adjacentDir[8] = {NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST};
            for( auto &elem : adjacentDir ) {

                tripoint apos = tripoint( direction_XY( elem ), 0 );
                apos += pos;

                if( g->m.has_flag( "SEALED", apos ) ) {
                    continue;
                }
                if( g->check_zone( "NO_AUTO_PICKUP", apos ) ) {
                    continue;
                }
                pick_up( apos, min );
            }
        }
    }

    // Not many items, just grab them
    if( ( int )here.size() <= min && min != -1 ) {
        g->u.assign_activity( ACT_PICKUP, 0 );
        g->u.activity.placement = pos - g->u.pos();
        g->u.activity.values.push_back( from_vehicle );
        // Only one item means index is 0.
        g->u.activity.values.push_back( 0 );
        // auto-pickup means pick up all.
        g->u.activity.values.push_back( 0 );
        return;
    }

    if( min != -1 ) { // don't bother if we're just autopickup-ing
        g->temp_exit_fullscreen();
    }
    bool sideStyle = use_narrow_sidebar();

    // Otherwise, we have Autopickup, 2 or more items and should list them, etc.
    int maxmaxitems = sideStyle ? TERMY : getmaxy( g->w_messages ) - 3;

    int itemsH = std::min( 25, TERMY / 2 );
    int pickupBorderRows = 3;

    // The pickup list may consume the entire terminal, minus space needed for its
    // header/footer and the item info window.
    int minleftover = itemsH + pickupBorderRows;
    if( maxmaxitems > TERMY - minleftover ) {
        maxmaxitems = TERMY - minleftover;
    }

    const int minmaxitems = sideStyle ? 6 : 9;

    std::vector<pickup_count> getitem( here.size() );

    int maxitems = here.size();
    maxitems = ( maxitems < minmaxitems ? minmaxitems : ( maxitems > maxmaxitems ? maxmaxitems :
                 maxitems ) );

    int itemcount = 0;

    if( min == -1 ) { //Auto Pickup, select matching items
        if( !select_autopickup_items( here, getitem ) ) {
            // If we didn't find anything, bail out now.
            return;
        }
    } else {
        int pickupH = maxitems + pickupBorderRows;
        int pickupW = getmaxx( g->w_messages );
        int pickupY = VIEW_OFFSET_Y;
        int pickupX = getbegx( g->w_messages );

        int itemsW = pickupW;
        int itemsY = sideStyle ? pickupY + pickupH : TERMY - itemsH;
        int itemsX = pickupX;

        WINDOW *w_pickup    = newwin( pickupH, pickupW, pickupY, pickupX );
        WINDOW *w_item_info = newwin( itemsH,  itemsW,  itemsY,  itemsX );
        WINDOW_PTR w_pickupptr( w_pickup );
        WINDOW_PTR w_item_infoptr( w_item_info );

        std::string action;
        long raw_input_char = ' ';
        input_context ctxt( "PICKUP" );
        ctxt.register_action( "UP" );
        ctxt.register_action( "DOWN" );
        ctxt.register_action( "RIGHT" );
        ctxt.register_action( "LEFT" );
        ctxt.register_action( "NEXT_TAB", _( "Next page" ) );
        ctxt.register_action( "PREV_TAB", _( "Previous page" ) );
        ctxt.register_action( "SCROLL_UP" );
        ctxt.register_action( "SCROLL_DOWN" );
        ctxt.register_action( "CONFIRM" );
        ctxt.register_action( "SELECT_ALL" );
        ctxt.register_action( "QUIT", _( "Cancel" ) );
        ctxt.register_action( "ANY_INPUT" );
        ctxt.register_action( "HELP_KEYBINDINGS" );

        int start = 0, cur_it;
        player pl_copy = g->u;
        pl_copy.set_fake( true );
        bool update = true;
        mvwprintw( w_pickup, 0, 0, _( "PICK UP" ) );
        int selected = 0;
        int iScrollPos = 0;

        if( g->was_fullscreen ) {
            g->draw_ter();
        }
        // Now print the two lists; those on the ground and about to be added to inv
        // Continue until we hit return or space
        do {
            const std::string pickup_chars =
                ctxt.get_available_single_char_hotkeys( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;" );
            int idx = -1;
            for( int i = 1; i < pickupH; i++ ) {
                mvwprintw( w_pickup, i, 0,
                           "                                                " );
            }
            if( action == "ANY_INPUT" &&
                raw_input_char >= '0' && raw_input_char <= '9' ) {
                int raw_input_char_value = ( char )raw_input_char - '0';
                itemcount *= 10;
                itemcount += raw_input_char_value;
                if( itemcount < 0 ) {
                    itemcount = 0;
                }
            } else if( action == "SCROLL_UP" ) {
                iScrollPos--;
            } else if( action == "SCROLL_DOWN" ) {
                iScrollPos++;
            } else if( action == "PREV_TAB" ) {
                if( start > 0 ) {
                    start -= maxitems;
                } else {
                    start = ( int )( ( here.size() - 1 ) / maxitems ) * maxitems;
                }
                selected = start;
                mvwprintw( w_pickup, maxitems + 2, 0, "         " );
            } else if( action == "NEXT_TAB" ) {
                if( start + maxitems < ( int )here.size() ) {
                    start += maxitems;
                } else {
                    start = 0;
                }
                iScrollPos = 0;
                selected = start;
                mvwprintw( w_pickup, maxitems + 2, pickupH, "            " );
            } else if( action == "UP" ) {
                selected--;
                iScrollPos = 0;
                if( selected < 0 ) {
                    selected = here.size() - 1;
                    start = ( int )( here.size() / maxitems ) * maxitems;
                    if( start >= ( int )here.size() ) {
                        start -= maxitems;
                    }
                } else if( selected < start ) {
                    start -= maxitems;
                }
            } else if( action == "DOWN" ) {
                selected++;
                iScrollPos = 0;
                if( selected >= ( int )here.size() ) {
                    selected = 0;
                    start = 0;
                } else if( selected >= start + maxitems ) {
                    start += maxitems;
                }
            } else if( selected >= 0 && (
                           ( action == "RIGHT" && !getitem[selected] ) ||
                           ( action == "LEFT" && getitem[selected] )
                       ) ) {
                idx = selected;
            } else if( action == "ANY_INPUT" && raw_input_char == '`' ) {
                std::string ext = string_input_popup(
                                      _( "Enter 2 letters (case sensitive):" ), 3, "", "", "", 2 );
                if( ext.size() == 2 ) {
                    int p1 = pickup_chars.find( ext.at( 0 ) );
                    int p2 = pickup_chars.find( ext.at( 1 ) );
                    if( p1 != -1 && p2 != -1 ) {
                        idx = pickup_chars.size() + ( p1 * pickup_chars.size() ) + p2;
                    }
                }
            } else if( action == "ANY_INPUT" ) {
                idx = ( raw_input_char <= 127 ) ? pickup_chars.find( raw_input_char ) : -1;
                iScrollPos = 0;
            }

            if( idx >= 0 && idx < ( int )here.size() ) {
                if( getitem[idx] ) {
                    if( here[idx].count_by_charges() ) {
                        if( getitem[idx].count == 0 ) {
                            pl_copy.inv.find_item( getitem[idx].position ).charges -= here[idx].charges;
                        } else {
                            pl_copy.inv.find_item( getitem[idx].position ).charges -= getitem[idx].count;
                        }
                    } else {
                        unsigned stack_size = pl_copy.inv.const_stack( getitem[idx].position ).size();
                        pl_copy.i_rem( getitem[idx].position );
                        //if the stack_was emptied, removing the item invalidated later positions- fix them
                        if( stack_size == 1 ) {
                            for( unsigned i = 0; i < here.size(); i++ ) {
                                if( getitem[i] && getitem[i].position > getitem[idx].position ) {
                                    getitem[i].position--;
                                }
                            }
                        }
                    }
                } //end if getitem[idx]

                if( itemcount != 0 || getitem[idx].count == 0 ) {
                    if( itemcount >= here[idx].charges || !here[idx].count_by_charges() ) {
                        // Ignore the count if we pickup the whole stack anyway
                        // or something that is not counted by charges (tools)
                        itemcount = 0;
                    }
                    getitem[idx].count = itemcount;
                    itemcount = 0;
                }

                // Note: this might not change the value of getitem[idx] at all!
                getitem[idx].pick = ( action == "RIGHT" ? true : ( action == "LEFT" ? false : !getitem[idx] ) );
                if( action != "RIGHT" && action != "LEFT" ) {
                    selected = idx;
                    start = ( int )( idx / maxitems ) * maxitems;
                }

                if( getitem[idx] ) {
                    item temp = here[idx];
                    if( getitem[idx].count != 0 &&
                        getitem[idx].count < here[idx].charges ) {
                        temp.charges = getitem[idx].count;
                    }
                    item *added = &( pl_copy.i_add( temp ) );
                    getitem[idx].position = pl_copy.inv.position_by_item( added );
                } else {
                    getitem[idx].count = 0;
                }
                update = true;
            }

            werase( w_item_info );
            if( selected >= 0 && selected <= ( int )here.size() - 1 ) {
                std::vector<iteminfo> vThisItem, vDummy;
                here[selected].info( true, vThisItem );

                draw_item_info( w_item_info, "", "", vThisItem, vDummy, iScrollPos, true, true );
            }
            draw_custom_border( w_item_info, false );
            mvwprintw( w_item_info, 0, 2, "< " );
            trim_and_print( w_item_info, 0, 4, itemsW - 8, c_white, "%s >",
                            here[selected].display_name().c_str() );
            wrefresh( w_item_info );

            if( action == "SELECT_ALL" ) {
                int count = 0;
                for( size_t i = 0; i < here.size(); i++ ) {
                    if( getitem[i] ) {
                        count++;
                    } else {
                        item *added = &( pl_copy.i_add( here[i] ) );
                        getitem[i].position = pl_copy.inv.position_by_item( added );
                    }
                    getitem[i].pick = true;
                }
                if( count == ( int )here.size() ) {
                    for( size_t i = 0; i < here.size(); i++ ) {
                        getitem[i].pick = false;
                    }
                    pl_copy = g->u;
                    pl_copy.set_fake( true );
                }
                update = true;
            }

            for( cur_it = start; cur_it < start + maxitems; cur_it++ ) {
                mvwprintw( w_pickup, 1 + ( cur_it % maxitems ), 0,
                           "                                        " );
                if( cur_it < ( int )here.size() ) {
                    nc_color icolor = here[cur_it].color_in_inventory();
                    if( cur_it == selected ) {
                        icolor = hilite( icolor );
                    }

                    if( cur_it < ( int )pickup_chars.size() ) {
                        mvwputch( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor,
                                  char( pickup_chars[cur_it] ) );
                    } else if( cur_it < ( int )pickup_chars.size() + ( int )pickup_chars.size() *
                               ( int )pickup_chars.size() ) {
                        int p = cur_it - pickup_chars.size();
                        int p1 = p / pickup_chars.size();
                        int p2 = p % pickup_chars.size();
                        mvwprintz( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, "`%c%c",
                                   char( pickup_chars[p1] ), char( pickup_chars[p2] ) );
                    } else {
                        mvwputch( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, ' ' );
                    }
                    if( getitem[cur_it] ) {
                        if( getitem[cur_it].count == 0 ) {
                            wprintz( w_pickup, c_ltblue, " + " );
                        } else {
                            wprintz( w_pickup, c_ltblue, " # " );
                        }
                    } else {
                        wprintw( w_pickup, " - " );
                    }
                    std::string item_name = here[cur_it].display_name();
                    if( OPTIONS["ITEM_SYMBOLS"] ) {
                        item_name = string_format( "%s %s", here[cur_it].symbol().c_str(),
                                                   item_name.c_str() );
                    }
                    trim_and_print( w_pickup, 1 + ( cur_it % maxitems ), 6, pickupW - 4, icolor,
                                    "%s", item_name.c_str() );
                }
            }

            mvwprintw( w_pickup, maxitems + 1, 0, _( "[%s] Unmark" ),
                       ctxt.get_desc( "LEFT", 1 ).c_str() );

            center_print( w_pickup, maxitems + 1, c_ltgray, _( "[%s] Help" ),
                          ctxt.get_desc( "HELP_KEYBINDINGS", 1 ).c_str() );

            right_print( w_pickup, maxitems + 1, 0, c_ltgray, _( "[%s] Mark" ),
                         ctxt.get_desc( "RIGHT", 1 ).c_str() );

            mvwprintw( w_pickup, maxitems + 2, 0, _( "[%s] Prev" ),
                       ctxt.get_desc( "PREV_TAB", 1 ).c_str() );

            center_print( w_pickup, maxitems + 2, c_ltgray, _( "[%s] All" ),
                          ctxt.get_desc( "SELECT_ALL", 1 ).c_str() );

            right_print( w_pickup, maxitems + 2, 0, c_ltgray, _( "[%s] Next" ),
                         ctxt.get_desc( "NEXT_TAB", 1 ).c_str() );

            if( update ) { // Update weight & volume information
                update = false;
                for( int i = 9; i < pickupW; ++i ) {
                    mvwaddch( w_pickup, 0, i, ' ' );
                }
                mvwprintz( w_pickup, 0,  9,
                           ( pl_copy.weight_carried() > g->u.weight_capacity() ? c_red : c_white ),
                           _( "Wgt %.1f" ), convert_weight( pl_copy.weight_carried() ) + 0.05 ); // +0.05 to round up
                wprintz( w_pickup, c_white, "/%.1f", convert_weight( g->u.weight_capacity() ) );
                mvwprintz( w_pickup, 0, 24,
                           ( pl_copy.volume_carried() > g->u.volume_capacity() ? c_red : c_white ),
                           _( "Vol %d" ), pl_copy.volume_carried() );
                wprintz( w_pickup, c_white, "/%d", g->u.volume_capacity() );
            }
            wrefresh( w_pickup );

            action = ctxt.handle_input();
            raw_input_char = ctxt.get_raw_input().get_first_input();

        } while( action != "QUIT" && action != "CONFIRM" );

        bool item_selected = false;
        // Check if we have selected an item.
        for( auto selection : getitem ) {
            if( selection ) {
                item_selected = true;
            }
        }
        if( action != "CONFIRM" || !item_selected ) {
            w_pickupptr.reset();
            w_item_infoptr.reset();
            add_msg( _( "Never mind." ) );
            g->reenter_fullscreen();
            g->refresh_all();
            return;
        }
    }

    // At this point we've selected our items, register an activity to pick them up.
    g->u.assign_activity( ACT_PICKUP, 0 );
    g->u.activity.placement = pos - g->u.pos();
    g->u.activity.values.push_back( from_vehicle );
    if( min == -1 ) {
        // Auto pickup will need to auto resume since there can be several of them on the stack.
        g->u.activity.auto_resume = true;
    }
    std::reverse( getitem.begin(), getitem.end() );
    for( size_t i = 0; i < here.size(); i++ ) {
        if( getitem[i] ) {
            g->u.activity.values.push_back( i );
            g->u.activity.values.push_back( getitem[i].count );
        }
    }

    g->reenter_fullscreen();
}
示例#30
0
/* Prayer occurs at altars, hence the name of the function */
void l_altar()
{
    int i;
    int deity;
    char response;

    if(Current_Environment == E_COUNTRYSIDE) {
        deity = DRUID;
    }
    else {
        deity = Level->site[Player.x][Player.y].aux;
    }

    switch(deity) {
    case ODIN:
        print1("This granite altar is graven with a gallows.");

        break;
    case SET:
        print1("This sandstone altar has a black hand drawn on it.");

        break;
    case HECATE:
        print1("This silver altar is inlaid with a black cresent moon.");

        break;
    case ATHENA:
        print1("This golden altar is inscribed with an owl.");

        break;
    case DESTINY:
        print1("This crystal altar is in the form of an omega.");

        break;
    case DRUID:
        print1("This oaken altar is ornately engraved with leaves.");

        break;
    default:
        print1("This rude altar has no markings.");

        break;
    }

    print2("Worship at this altar? [yn] ");

    if(ynq2() == 'y') {
        if(Player.rank[PRIESTHOOD] == 0) {
            increase_priest_rank(deity);
        }
        else if(!check_sacrilege(deity)) {
            if(Blessing) {
                print1("You have a sense of immanence.");
            }

            print2("Request a Blessing, Sacrifice an item, or just Pray [b,s,p] ");
            response = mcigetc();

            while((response != 'b')
                  && (response != 's')
                  && (response != 'p')
                  && (response != ESCAPE)) {
                response = mcigetc();
            }

            if(response == 'b') {
                print1("You beg a heavenly benefice.");
                print2("You hear a gong resonating throughout eternity...");
                morewait();

                if(Blessing) {
                    print1("A shaft of lecent radiance lances dwon from the heavens!");
                    print2("You feel uplifted...");
                    morewait();
                    gain_experience(Player.rank[PRIESTHOOD] * Player.rank[PRIESTHOOD] * 50);
                    cleanse(1);
                    heal(10);
                    bless(1);
                    Blessing = FALSE;
                    increase_priest_rank(deity);
                }
                else {
                    print1("Your ardent plea is ignored.");
                    print2("You feel ashamed.");
                    Player.xp -= (Player.xp / 4);
                }

                calc_melee();
            }
            else if(response == 's') {
                print1("Which item to Sacrifice?");
                i = getitem('\0');

                if(i == ABORT) {
                    i = 0;
                }

                if(Player.possessions[i] == NULL) {
                    print1("You have insulted your deity!");
                    print2("Not a good idea, as it turns out...");
                    dispel(-1);
                    p_damage(Player.hp - 1, UNSTOPPABLE, "a god's pique");
                }
                else if(true_item_value(Player.possessions[i]) > (Player.rank[PRIESTHOOD] * Player.rank[PRIESTHOOD] * Player.rank[PRIESTHOOD] * 50)) {
                    print1("With a burst of blue flame, your offering vanishes!");
                    dispose_lost_objects(1, Player.possessions[i]);
                    print2("A violet nimbus settles around your head and slowly fades.");
                    morewait();
                    Blessing = TRUE;
                }
                else {
                    print1("A darkling glow envelopes your offering!");
                    print2("The glow slowly fades...");
                    morewait();
                    setgamestatus(SUPPRESS_PRINTING);

                    if(Player.possessions[i]->used) {
                        Player.possessions[i]->used = FALSE;
                        item_use(Player.possessions[i]);
                        Player.possessions[i]->blessing = -1 - abs(Player.possessions[i]->blessing);
                        Player.possessions[i]->used = TRUE;
                        item_use(Player.possessions[i]);
                    }
                    else {
                        Player.possessions[i]->blessing = -1 - abs(Player.possessions[i]->blessing);
                    }

                    resetgamestatus(SUPPRESS_PRINTING);
                }
            }
            else if(response == 'p') {
                if(deity != Player.patron) {
                    print1("Nothing seems to happen.");
                }
                else {
                    increase_priest_rank(deity);
                }
            }
        }
    }
}