Beispiel #1
0
int main()
{
	/*读配置文件*/
	FILE* fp;
	char readin[100],file[100];
	int value1=0, value2=0, value3=0,value4=0,value5=0;
	fopen_s(&fp, "configure/configure.txt", "r");
	fscanf_s(fp, "video: %s", readin, sizeof(readin));
	sprintf(file, readin);
	memset(readin, 0, sizeof(readin));
	fgets(readin, sizeof(readin),fp);
	fscanf_s(fp, "value1: %d", &value1, sizeof(int));
	memset(readin, 0, sizeof(readin));
	fgets(readin, sizeof(readin), fp);
	fscanf_s(fp, "value2: %d", &value2, sizeof(int));
	memset(readin, 0, sizeof(readin));
	fgets(readin, sizeof(readin), fp);;
	fscanf_s(fp, "value3: %d", &value3, sizeof(int));
	memset(readin, 0, sizeof(readin));
	fgets(readin, sizeof(readin), fp);
	fscanf_s(fp, "value4: %d", &value4, sizeof(int));
	memset(readin, 0, sizeof(readin));
	fgets(readin, sizeof(readin), fp);
	fscanf_s(fp, "value5: %d", &value5, sizeof(int));
	printf("%s %d %d %d\n", file,value1,value2,value3);


	/*声明IplImage指针*/
	IplImage *image0 = NULL;		//原始帧
	IplImage *image = NULL;			//当前帧
	IplImage *image_pass = NULL;	//上一帧
	IplImage *res = NULL;			//帧差
	IplImage *res0 = NULL;			//帧差
	IplImage *pFrame = NULL;
	IplImage *pFrImg = NULL;
	IplImage *pBkImg = NULL;

	/*声明CvMat指针*/
	CvMat* pFrameMat = NULL;
	CvMat* pFrMat = NULL;
	CvMat* pBkMat = NULL;
	CvMat* IndexMat = NULL;


	/*声明caputer指针*/
	CvCapture *capture = NULL;
	capture = cvCaptureFromFile(file);
	image0 = cvQueryFrame(capture);
	nFrmNum++;

	// 创建窗口
	//cvNamedWindow("video", 1);
	cvNamedWindow("background", 1);
	cvNamedWindow("tracking", 1);

	// 排列窗口
	//cvMoveWindow("video", 30, 80);
	cvMoveWindow("background",10, 100);
	cvMoveWindow("tracking", 660, 100);

	/*移动物体的队列*/
	movingObject *curr_head = new movingObject();
	movingObject *prev_head = new  movingObject();
	movingObject *p_obj = new movingObject();
	movingObject *share_head = new movingObject();
	curr_head->next = NULL;
	curr_head->share_next = NULL;
	prev_head->next = NULL;
	prev_head->share_next = NULL;
	share_head->next = NULL;

	CvScalar color[7] = { { 0, 0, 0 }, { 0, 255, 0 }, {255, 0, 0 }, { 255, 201, 14 }, { 255, 0, 255 }, { 0, 166, 0 }, {121,255,121} };

	image = cvCreateImage(cvSize(640,360), IPL_DEPTH_8U, 3);
	cvResize(image0, image, CV_INTER_LINEAR);

	int image_width = image->width;
	int image_height = image->height;

	image_pass = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3);
	res = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1);
	res0 = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3);
	pBkImg = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1);
	pFrImg = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1);
	pFrame = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1);

	pBkMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);
	pFrMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);
	pFrameMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);
	IndexMat = cvCreateMat(image_height, image_width, CV_32FC1);

	cvCopy(image, image_pass, NULL);


	/*背景*/
	cvCvtColor(image, pBkImg, CV_BGR2GRAY);
	cvConvert(pBkImg, pBkMat);

	while (1)
	{
		image0 = cvQueryFrame(capture);
		if (!image0) break;	

		cvResize(image0, image, CV_INTER_LINEAR);


		/*高斯平滑*/
		cvSmooth(image, image, CV_GAUSSIAN, 3, 0, 0);

		/*运动目标检测*/
		detect_object(image, pBkImg, pFrImg, pFrameMat, pBkMat, pFrMat,value1);

		/*帧差法优化*/
		frame_dif(image, image_pass, res,res0, pFrImg,pFrame,value2);

		cvConvert(pFrame, pFrMat);

		/*计算连通区域和质心*/
		computeObject(pFrMat, image_width, image_height,IndexMat, curr_head,value3);

		/*画出质心*/
		p_obj = curr_head;
		while (p_obj->next != NULL)
		{
			p_obj = p_obj->next;
			cvRectangle(image, cvPoint(p_obj->x - 1, p_obj->y - 1), cvPoint(p_obj->x + 1, p_obj->y + 1), cvScalar(0, 0, 255), 2, 8, 0);
		}


		if (nFrmNum == 2)
		{
			movingObject* q = NULL;
			computeObject(pFrMat, image_width, image_height, IndexMat, prev_head,value3);

		}
		/*画出跟踪框*/
		if (nFrmNum > 2)
		{
			movingObject *q = NULL, *p = NULL;
			movingObject *last=curr_head;

			for (q = curr_head->next; q; )
			{
				int close = 0;
 				share_head->share_next = NULL;
  				for (p = prev_head->next; p; p = p->next)
				{
					int dist = cal_dist(p->x, p->y, q->x, q->y);
					if (dist <= value5)
					{
						close++;
						p->share_next = share_head->share_next; 
						share_head->share_next= p;
					}

				}

				if (close == 1)
				{
					if (share_head->share_next->track == 1)	//已被用,删掉当前结点
					{
						last->next = q->next;
						movingObject* t=q;
						q = q->next;
						delete t;
						continue;
					}
					q->label = (share_head->share_next)->label;
					cvRectangle(image, q->points[0], q->points[1], color[q->label],2);
					q->move = q->x - (share_head->share_next)->x;	//两帧位移
					share_head->share_next->track = 1;
					q->track = 0; 
					q->keeptime = 0;
					last = q;
					q = q->next;
				}
				else if (close==0)
				{
					//生成新标签
					q->label = ++label_num;
					cvRectangle(image, q->points[0], q->points[1], color[q->label],2);
					q->track = 0;
					q->keeptime = 0;
					last = q;
					q = q->next;
				}
				else if (close>1)
				{
					movingObject* t = share_head->share_next;
					while ( t != NULL)
					{
						if (t->track==1)
						t = t->share_next;
						else break;
					}
					if (t==NULL)	//全部跟踪完毕
					{
						last->next = q->next;
						t = q;
						q = q->next;
						delete t;
						continue;
					}

					//重用当前队列的这一object
					q->label = t->label;
					q->move = t->move;
					q->area = t->area;
					q->x = t->x + t->move;
					q->y = t->y;
					q->points[0].x = t->points[0].x+t->move;
					q->points[0].y = t->points[0].y;
					q->points[1].x = t->points[1].x + t->move;
					q->points[1].y = t->points[1].y;
					q->track = 0;
					t->track = 1;
					q->keeptime = 0;
					cvRectangle(image, q->points[0], q->points[1], color[q->label],2);

					t = t->share_next;
					while (t)
					{
						if (t->track == 1)
						{
							t = t->share_next;
							continue;
						}
						movingObject* newobject = new movingObject();
						newobject->area = t->area;
						newobject->label = t->label;
						newobject->move = t->move;
						newobject->next = q->next;
						q->next = newobject;
						q = newobject;
						newobject->points[0].x = t->points[0].x + t->move;
						newobject->points[0].y = t->points[0].y;
						newobject->points[1].x = t->points[1].x + t->move;
						newobject->points[1].y = t->points[1].y;
						newobject->x = t->x + t->move;
						newobject->y = t->y;
						newobject->track = 0;
						newobject->keeptime = 0;
						cvRectangle(image, newobject->points[0], newobject->points[1], color[newobject->label],2);
						t->track = 1;			//已跟踪这一个prev目标
						t = t->share_next;
					}
					last = q;
					q = q->next;

				}

			}//end for
			detect_hiding(prev_head, image_width, curr_head,value4);
		}//end if
		
		cvShowImage("tracking", image);
		release_link(prev_head,share_head);
		prev_head->next = curr_head->next;
		curr_head->next = NULL;
		
		int ctrl;
		if ( (ctrl=cvWaitKey(20)) == 27)//ESC退出
		{
			break;
		}
		else if (ctrl == 32)	//空格暂停
		{
			while ((ctrl=cvWaitKey(0))!=13)//回车继续
			{
				if (ctrl == 27)
				exit(0);
				continue;
			}

			
		}
	}

	cvReleaseImage(&res);
	cvReleaseImage(&res0);
	cvReleaseImage(&image_pass);
	cvReleaseImage(&pBkImg);
	cvReleaseImage(&pFrImg);
	cvReleaseImage(&pFrame);
	cvReleaseCapture(&capture);

	return 1;
}
Beispiel #2
0
/* Scrolls for the reading				-RAK-	*/
void read_scroll()
{
  int32u i;
  int j, k, item_val, y, x;
  int tmp[6], flag, used_up;
  bigvtype out_val, tmp_str;
  register int ident, l;
  register inven_type *i_ptr;
  register struct misc *m_ptr;

  free_turn_flag = TRUE;
  if (py.flags.blind > 0)
    msg_print("You can't see to read the scroll.");
  else if (no_light())
    msg_print("You have no light to read by.");
  else if (py.flags.confused > 0)
    msg_print("You are too confused to read a scroll.");
  else if (inven_ctr == 0)
    msg_print("You are not carrying anything!");
  else if (!find_range(TV_SCROLL1, TV_SCROLL2, &j, &k))
    msg_print ("You are not carrying any scrolls!");
  else if (get_item(&item_val, "Read which scroll?", j, k, 0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = FALSE;
      used_up = TRUE;
      i = i_ptr->flags;
      ident = FALSE;

      while (i != 0)
	{
	  j = bit_pos(&i) + 1;
	  if (i_ptr->tval == TV_SCROLL2)
	    j += 32;

	  /* Scrolls.			*/
	  switch(j)
	    {
	    case 1:
	      i_ptr = &inventory[INVEN_WIELD];
	      if (i_ptr->tval != TV_NOTHING)
		{
		  objdes(tmp_str, i_ptr, FALSE);
		  (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
		  msg_print(out_val);
		  if (enchant(&i_ptr->tohit))
		    {
		      i_ptr->flags &= ~TR_CURSED;
		      calc_bonuses();
		    }
		  else
		    msg_print("The enchantment fails.");
		  ident = TRUE;
		}
	      break;
	    case 2:
	      i_ptr = &inventory[INVEN_WIELD];
	      if (i_ptr->tval != TV_NOTHING)
		{
		  objdes(tmp_str, i_ptr, FALSE);
		  (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
		  msg_print(out_val);
		  if (enchant(&i_ptr->todam))
		    {
		      i_ptr->flags &= ~TR_CURSED;
		      calc_bonuses ();
		    }
		  else
		    msg_print("The enchantment fails.");
		  ident = TRUE;
		}
	      break;
	    case 3:
	      k = 0;
	      l = 0;
	      if (inventory[INVEN_BODY].tval != TV_NOTHING)
		tmp[k++] = INVEN_BODY;
	      if (inventory[INVEN_ARM].tval != TV_NOTHING)
		tmp[k++] = INVEN_ARM;
	      if (inventory[INVEN_OUTER].tval != TV_NOTHING)
		tmp[k++] = INVEN_OUTER;
	      if (inventory[INVEN_HANDS].tval != TV_NOTHING)
		tmp[k++] = INVEN_HANDS;
	      if (inventory[INVEN_HEAD].tval != TV_NOTHING)
		tmp[k++] = INVEN_HEAD;
	      /* also enchant boots */
	      if (inventory[INVEN_FEET].tval != TV_NOTHING)
		tmp[k++] = INVEN_FEET;

	      if (k > 0)  l = tmp[randint(k)-1];
	      if (TR_CURSED & inventory[INVEN_BODY].flags)
		l = INVEN_BODY;
	      else if (TR_CURSED & inventory[INVEN_ARM].flags)
		l = INVEN_ARM;
	      else if (TR_CURSED & inventory[INVEN_OUTER].flags)
		l = INVEN_OUTER;
	      else if (TR_CURSED & inventory[INVEN_HEAD].flags)
		l = INVEN_HEAD;
	      else if (TR_CURSED & inventory[INVEN_HANDS].flags)
		l = INVEN_HANDS;
	      else if (TR_CURSED & inventory[INVEN_FEET].flags)
		l = INVEN_FEET;

	      if (l > 0)
		{
		  i_ptr = &inventory[l];
		  objdes(tmp_str, i_ptr, FALSE);
		  (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
		  msg_print(out_val);
		  if (enchant(&i_ptr->toac))
		    {
		      i_ptr->flags &= ~TR_CURSED;
		      calc_bonuses ();
		    }
		  else
		    msg_print("The enchantment fails.");
		  ident = TRUE;
		}
	      break;
	    case 4:
	      msg_print("This is an identify scroll.");
	      ident = TRUE;
	      used_up = ident_spell();

	      /* the identify may merge objects, causing the identify scroll
		 to move to a different place.	Check for that here. */
	      if (i_ptr->tval != TV_SCROLL1 || i_ptr->flags != 0x00000008)
		{
		  item_val--;
		  i_ptr = &inventory[item_val];
		  if (i_ptr->tval != TV_SCROLL1 || i_ptr->flags != 0x00000008)
		    {
		      msg_print("internal error with identify spell.");
		      msg_print("Please tell the wizard!");
		      return;
		    }
		}
	      break;
	    case 5:
	      if (remove_curse())
		{
		  msg_print("You feel as if someone is watching over you.");
		  ident = TRUE;
		}
	      break;
	    case 6:
	      ident = light_area(char_row, char_col);
	      break;
	    case 7:
	      for (k = 0; k < randint(3); k++)
		{
		  y = char_row;
		  x = char_col;
		  ident |= summon_monster(&y, &x, FALSE);
		}
	      break;
	    case 8:
	      teleport(10);
	      ident = TRUE;
	      break;
	    case 9:
	      teleport(100);
	      ident = TRUE;
	      break;
	    case 10:
	      (void) tele_level();
	      ident = TRUE;
	      break;
	    case 11:
	      if (py.flags.confuse_monster == 0)
		{
		  msg_print("Your hands begin to glow.");
		  py.flags.confuse_monster = TRUE;
		  ident = TRUE;
		}
	      break;
	    case 12:
	      ident = TRUE;
	      map_area();
	      break;
	    case 13:
	      ident = sleep_monsters1(char_row, char_col);
	      break;
	    case 14:
	      ident = TRUE;
	      warding_glyph();
	      break;
	    case 15:
	      ident = detect_treasure();
	      break;
	    case 16:
	      ident = detect_object();
	      break;
	    case 17:
	      ident = detect_trap();
	      break;
	    case 18:
	      ident = detect_sdoor();
	      break;
	    case 19:
	      msg_print("This is a mass genocide scroll.");
	      ident = mass_genocide(TRUE);
	      break;
	    case 20:
	      ident = detect_invisible();
	      break;
	    case 21:
	      ident = aggravate_monster(20);
	      if (ident)
		msg_print("There is a high pitched humming noise.");
	      break;
	    case 22:
	      ident = trap_creation();
	      break;
	    case 23:
	      ident = td_destroy();
	      break;
	    case 24:  /* Not Used , used to be door creation */
	      break;
	    case 25:
	      msg_print("This is a Recharge-Item scroll.");
	      ident = TRUE;
	      used_up = recharge(60);
	      break;
	    case 26:
	      msg_print("This is a genocide scroll.");
	      ident = genocide(TRUE);
	      break;
	    case 27:
	      ident = unlight_area(char_row, char_col);
	      break;
	    case 28:
	      ident = protect_evil();
	      break;
	    case 29:
	      ident = TRUE;
	      create_food();
	      break;
	    case 30:
	      ident = dispel_creature(UNDEAD, 60);
	      break;
	    case 31:
	      remove_all_curse();
	      ident = TRUE;
	      break;
	    case 33:
	      i_ptr = &inventory[INVEN_WIELD];
	      if (i_ptr->tval != TV_NOTHING)
		{
		  objdes(tmp_str, i_ptr, FALSE);
		  (void) sprintf(out_val, "Your %s glows brightly!", tmp_str);
		  msg_print(out_val);
		  flag = FALSE;
		  for (k = 0; k < randint(2); k++)
		    if (enchant(&i_ptr->tohit))
		      flag = TRUE;
		  for (k = 0; k < randint(2); k++)
		    if (enchant(&i_ptr->todam))
		      flag = TRUE;
		  if (flag)
		    {
		      i_ptr->flags &= ~TR_CURSED;
		      calc_bonuses ();
		    }
		  else
		    msg_print("The enchantment fails.");
		  ident = TRUE;
		}
	      break;
	    case 34:
	      i_ptr = &inventory[INVEN_WIELD];
	      if (i_ptr->tval != TV_NOTHING)
		{
		  objdes(tmp_str, i_ptr, FALSE);
		  (void)sprintf(out_val,"Your %s glows black, fades.",tmp_str);
		  msg_print(out_val);
		  unmagic_name(i_ptr);
		  i_ptr->tohit = -randint(5) - randint(5);
		  i_ptr->todam = -randint(5) - randint(5);
		  i_ptr->flags = TR_CURSED;
		  py_bonuses(i_ptr, -1);
		  calc_bonuses ();
		  ident = TRUE;
		}
	      break;
	    case 35:
	      k = 0;
	      l = 0;
	      if (inventory[INVEN_BODY].tval != TV_NOTHING)
		tmp[k++] = INVEN_BODY;
	      if (inventory[INVEN_ARM].tval != TV_NOTHING)
		tmp[k++] = INVEN_ARM;
	      if (inventory[INVEN_OUTER].tval != TV_NOTHING)
		tmp[k++] = INVEN_OUTER;
	      if (inventory[INVEN_HANDS].tval != TV_NOTHING)
		tmp[k++] = INVEN_HANDS;
	      if (inventory[INVEN_HEAD].tval != TV_NOTHING)
		tmp[k++] = INVEN_HEAD;
	      /* also enchant boots */
	      if (inventory[INVEN_FEET].tval != TV_NOTHING)
		tmp[k++] = INVEN_FEET;

	      if (k > 0)  l = tmp[randint(k)-1];
	      if (TR_CURSED & inventory[INVEN_BODY].flags)
		l = INVEN_BODY;
	      else if (TR_CURSED & inventory[INVEN_ARM].flags)
		l = INVEN_ARM;
	      else if (TR_CURSED & inventory[INVEN_OUTER].flags)
		l = INVEN_OUTER;
	      else if (TR_CURSED & inventory[INVEN_HEAD].flags)
		l = INVEN_HEAD;
	      else if (TR_CURSED & inventory[INVEN_HANDS].flags)
		l = INVEN_HANDS;
	      else if (TR_CURSED & inventory[INVEN_FEET].flags)
		l = INVEN_FEET;

	      if (l > 0)
		{
		  i_ptr = &inventory[l];
		  objdes(tmp_str, i_ptr, FALSE);
		  (void) sprintf(out_val,"Your %s glows brightly!", tmp_str);
		  msg_print(out_val);
		  flag = FALSE;
		  for (k = 0; k < randint(2) + 1; k++)
		    if (enchant(&i_ptr->toac))
		      flag = TRUE;
		  if (flag)
		    {
		      i_ptr->flags &= ~TR_CURSED;
		      calc_bonuses ();
		    }
		  else
		    msg_print("The enchantment fails.");
		  ident = TRUE;
		}
	      break;
	    case 36:
	      if ((inventory[INVEN_BODY].tval != TV_NOTHING)
		  && (randint(4) == 1))
		k = INVEN_BODY;
	      else if ((inventory[INVEN_ARM].tval != TV_NOTHING)
		       && (randint(3) ==1))
		k = INVEN_ARM;
	      else if ((inventory[INVEN_OUTER].tval != TV_NOTHING)
		       && (randint(3) ==1))
		k = INVEN_OUTER;
	      else if ((inventory[INVEN_HEAD].tval != TV_NOTHING)
		       && (randint(3) ==1))
		k = INVEN_HEAD;
	      else if ((inventory[INVEN_HANDS].tval != TV_NOTHING)
		       && (randint(3) ==1))
		k = INVEN_HANDS;
	      else if ((inventory[INVEN_FEET].tval != TV_NOTHING)
		       && (randint(3) ==1))
		k = INVEN_FEET;
	      else if (inventory[INVEN_BODY].tval != TV_NOTHING)
		k = INVEN_BODY;
	      else if (inventory[INVEN_ARM].tval != TV_NOTHING)
		k = INVEN_ARM;
	      else if (inventory[INVEN_OUTER].tval != TV_NOTHING)
		k = INVEN_OUTER;
	      else if (inventory[INVEN_HEAD].tval != TV_NOTHING)
		k = INVEN_HEAD;
	      else if (inventory[INVEN_HANDS].tval != TV_NOTHING)
		k = INVEN_HANDS;
	      else if (inventory[INVEN_FEET].tval != TV_NOTHING)
		k = INVEN_FEET;
	      else
		k = 0;

	      if (k > 0)
		{
		  i_ptr = &inventory[k];
		  objdes(tmp_str, i_ptr, FALSE);
		  (void)sprintf(out_val,"Your %s glows black, fades.",tmp_str);
		  msg_print(out_val);
		  unmagic_name(i_ptr);
		  i_ptr->flags = TR_CURSED;
		  i_ptr->toac = -randint(5) - randint(5);
		  calc_bonuses ();
		  ident = TRUE;
		}
	      break;
	    case 37:
	      ident = FALSE;
	      for (k = 0; k < randint(3); k++)
		{
		  y = char_row;
		  x = char_col;
		  ident |= summon_undead(&y, &x);
		}
	      break;
	    case 38:
	      ident = TRUE;
	      bless(randint(12)+6);
	      break;
	    case 39:
	      ident = TRUE;
	      bless(randint(24)+12);
	      break;
	    case 40:
	      ident = TRUE;
	      bless(randint(48)+24);
	      break;
	    case 41:
	      ident = TRUE;
	      if (py.flags.word_recall == 0)
		py.flags.word_recall = 25 + randint(30);
	      msg_print("The air about you becomes charged.");
	      break;
	    case 42:
	      destroy_area(char_row, char_col);
	      ident = TRUE;
	      break;
	    case 43:
	      place_special(char_row, char_col, SPECIAL);
	      prt_map();
	      break;
	    case 44:
	      special_random_object(char_row, char_col, 1);
	      prt_map();
	      break;
	    default:
	      msg_print("Internal error in scroll()");
	      break;
	    }
	  /* End of Scrolls.			       */
	}
      i_ptr = &inventory[item_val];
      if (ident)
	{
	  if (!known1_p(i_ptr))
	    {
	      m_ptr = &py.misc;
	      /* round half-way case up */
	      m_ptr->exp += (i_ptr->level +(m_ptr->lev >> 1)) / m_ptr->lev;
	      prt_experience();

	      identify(&item_val);
	      i_ptr = &inventory[item_val];
	    }
	}
Beispiel #3
0
/* Use a staff.					-RAK-	*/
void use()
{
  int32u i;
  int j, k, item_val, chance, y, x;
  register int ident;
  register struct misc *m_ptr;
  register inven_type *i_ptr;

  free_turn_flag = TRUE;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(TV_STAFF, TV_NEVER, &j, &k))
    msg_print("You are not carrying any staffs.");
  else if (get_item(&item_val, "Use which staff?", j, k, 0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = FALSE;
      m_ptr = &py.misc;
      chance = m_ptr->save + stat_adj(A_INT) - (int)i_ptr->level - 5
	+ (class_level_adj[m_ptr->pclass][CLA_DEVICE] * m_ptr->lev / 3);
      if (py.flags.confused > 0)
	chance = chance / 2;
      if (chance <= 0)	chance = 1;
      if (randint(chance) < USE_DEVICE)
	msg_print("You failed to use the staff properly.");
      else if (i_ptr->p1 > 0)
	{
	  i = i_ptr->flags;
	  ident = FALSE;
	  (i_ptr->p1)--;
	  switch(i) {
	  case ST_HEALING:
	    ident = hp_player(300);
	    if (py.flags.stun>0) {
	      if (py.flags.stun>50) {
		py.misc.ptohit+=20;
		py.misc.ptodam+=20;
	      } else {
		py.misc.ptohit+=5;
		py.misc.ptodam+=5;
	      }
	      py.flags.stun=0;
	      ident = TRUE;
	      msg_print("You're head stops stinging.");
	    }
	    if (py.flags.cut>0) {
	      py.flags.cut=0;
	      ident = TRUE;
	      msg_print("You feel better.");
	    }
	    break;
	  case ST_GENOCIDE:
	    genocide(FALSE);
	    ident = TRUE;
	    break;
	  case ST_PROBE:
	    probing();
	    ident = TRUE;
	    break;
          case ST_IDENTIFY:
	    ident_spell();
	    ident = TRUE;
	    break;
	  case ST_HOLYNESS:
	    dispel_creature(EVIL,120);
	    protect_evil();
	    cure_poison();
	    remove_fear();
	    hp_player(50);
	    if (py.flags.stun>0) {
	      if (py.flags.stun>50) {
		py.misc.ptohit+=20;
		py.misc.ptodam+=20;
	      } else {
		py.misc.ptohit+=5;
		py.misc.ptodam+=5;
	      }
	      py.flags.stun=0;
	      ident = TRUE;
	      msg_print("You're head stops stinging.");
	    }
	    if (py.flags.cut>0) {
	      py.flags.cut=0;
	      ident = TRUE;
	      msg_print("You feel better.");
	    }
	    ident = TRUE;
	    break;
	  case ST_MAGI:
            if (res_stat(A_INT)) {
	       msg_print("You have a warm feeling.");
	       ident = TRUE;
	    }
	    m_ptr = &py.misc;
	    if (m_ptr->cmana < m_ptr->mana) {
	      m_ptr->cmana = m_ptr->mana;
	      ident = TRUE;
              msg_print("Your feel your head clear.");
	      prt_cmana();
	    }
	    break;
	  case ST_POWER:
	    dispel_creature(0xFFFFFFFFL,120);
            break;
	  case ST_SURROUND:
	    map_area();
	    ident = TRUE;
	    break;
          case ST_LIGHT:
	    ident = light_area(char_row, char_col);
	    break;
	  case ST_DR_LC:
	    ident = detect_sdoor();
	    break;
	  case ST_TRP_LC:
	    ident = detect_trap();
	    break;
	  case ST_TRE_LC:
	    ident = detect_treasure();
	    break;
	  case ST_OBJ_LC:
	    ident = detect_object();
	    break;
          case ST_TELE:
	    teleport(100);
	    ident = TRUE;
	    break;
	  case ST_EARTH:
	    ident = TRUE;
	    earthquake();
	    break;
          case ST_SUMMON:
	    ident = FALSE;
	    for (k = 0; k < randint(4); k++)
	    {
	      y = char_row;
	      x = char_col;
	      ident |= summon_monster(&y, &x, FALSE);
	    }
	    break;
	  case ST_DEST:
	    ident = TRUE;
	    destroy_area(char_row, char_col);
            break;
	  case ST_STAR:
	    ident = TRUE;
	    starlite(char_row, char_col);
	    break;
	  case ST_HAST_MN:
	    ident = speed_monsters(1);
	    break;
	  case ST_SLOW_MN:
	    ident = speed_monsters(-1);
	    break;
	  case ST_SLEE_MN:
	    ident = sleep_monsters2();
	    break;
	  case ST_CURE_LT:
	    ident = hp_player(randint(8));
	    break;
	  case ST_DET_INV:
	    ident = detect_invisible();
	    break;
          case ST_SPEED:
	    if (py.flags.fast == 0) ident = TRUE;
	    if (py.flags.fast <= 0)
	      py.flags.fast += randint(30) + 15;
	    else
	      py.flags.fast += randint(5);
	    break;
          case ST_SLOW:
	    if (py.flags.slow == 0) ident = TRUE;
	    py.flags.slow += randint(30) + 15;
	    break;
	  case ST_REMOVE:
	    if (remove_curse())
	    {
	      if (py.flags.blind < 1)
	        msg_print("The staff glows blue for a moment..");
	      ident = TRUE;
	    }
	    break;
	  case ST_DET_EVI:
	    ident = detect_evil();
            break;
	  case ST_CURING:
	    if ((cure_blindness()) || (cure_poison()) ||
	    (cure_confusion()) || (py.flags.stun>0) || (py.flags.cut>0))
	      ident = TRUE;
	    if (py.flags.stun>0) {
	      if (py.flags.stun>50) {
		py.misc.ptohit+=20;
		py.misc.ptodam+=20;
	      } else {
		py.misc.ptohit+=5;
		py.misc.ptodam+=5;
	      }
	      py.flags.stun=0;
	      msg_print("You're head stops stinging.");
	    } else if (py.flags.cut>0) {
	      py.flags.cut=0;
	      msg_print("You feel better.");
	    }
	    break;
	  case ST_DSP_EVI:
	    ident = dispel_creature(EVIL, 60);
            break;
	  case ST_DARK:
	    ident = unlight_area(char_row, char_col);
            break;
	  default:
	    msg_print("Internal error in staffs()");
	    break;
	  }
	  if (ident)
	    {
	      if (!known1_p(i_ptr))
		{
		  m_ptr = &py.misc;
		  /* round half-way case up */
		  m_ptr->exp += (i_ptr->level + (m_ptr->lev >> 1)) /
		    m_ptr->lev;
		  prt_experience();

		  identify(&item_val);
		  i_ptr = &inventory[item_val];
		}
	    }
Beispiel #4
0
/* Use a staff.					-RAK-	*/
void use()
{
  int32u i;
  int j, k, item_val, chance, y, x;
  register int ident;
  register struct misc *m_ptr;
  register inven_type *i_ptr;

  free_turn_flag = TRUE;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(TV_STAFF, TV_NEVER, &j, &k))
    msg_print("You are not carrying any staffs.");
  else if (get_item(&item_val, "Use which staff?", j, k, CNIL, CNIL))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = FALSE;
      m_ptr = &py.misc;
      chance = m_ptr->save + stat_adj(A_INT) - (int)i_ptr->level - 5
	+ (class_level_adj[m_ptr->pclass][CLA_DEVICE] * m_ptr->lev / 3);
      if (py.flags.confused > 0)
	chance = chance / 2;
      if ((chance < USE_DEVICE) && (randint(USE_DEVICE - chance + 1) == 1))
	chance = USE_DEVICE; /* Give everyone a slight chance */
      if (chance <= 0)	chance = 1;
      if (randint(chance) < USE_DEVICE)
	msg_print("You failed to use the staff properly.");
      else if (i_ptr->p1 > 0)
	{
	  i = i_ptr->flags;
	  ident = FALSE;
	  (i_ptr->p1)--;
	  while (i != 0)
	    {
	      j = bit_pos(&i) + 1;
	      /* Staffs.				*/
	      switch(j)
		{
		case 1:
		  ident = light_area(char_row, char_col);
		  break;
		case 2:
		  ident = detect_sdoor();
		  break;
		case 3:
		  ident = detect_trap();
		  break;
		case 4:
		  ident = detect_treasure();
		  break;
		case 5:
		  ident = detect_object();
		  break;
		case 6:
		  teleport(100);
		  ident = TRUE;
		  break;
		case 7:
		  ident = TRUE;
		  earthquake();
		  break;
		case 8:
		  ident = FALSE;
		  for (k = 0; k < randint(4); k++)
		    {
		      y = char_row;
		      x = char_col;
		      ident |= summon_monster(&y, &x, FALSE);
		    }
		  break;
		case 10:
		  ident = TRUE;
		  destroy_area(char_row, char_col);
		  break;
		case 11:
		  ident = TRUE;
		  starlite(char_row, char_col);
		  break;
		case 12:
		  ident = speed_monsters(1);
		  break;
		case 13:
		  ident = speed_monsters(-1);
		  break;
		case 14:
		  ident = sleep_monsters2();
		  break;
		case 15:
		  ident = hp_player(randint(8));
		  break;
		case 16:
		  ident = detect_invisible();
		  break;
		case 17:
		  if (py.flags.fast == 0)
		    ident = TRUE;
		  py.flags.fast += randint(30) + 15;
		  break;
		case 18:
		  if (py.flags.slow == 0)
		    ident = TRUE;
		  py.flags.slow += randint(30) + 15;
		  break;
		case 19:
		  ident = mass_poly();
		  break;
		case 20:
		  if (remove_curse())
		    {
		      if (py.flags.blind < 1)
			msg_print("The staff glows blue for a moment..");
		      ident = TRUE;
		    }
		  break;
		case 21:
		  ident = detect_evil();
		  break;
		case 22:
		  if ((cure_blindness()) || (cure_poison()) ||
		      (cure_confusion()))
		    ident = TRUE;
		  break;
		case 23:
		  ident = dispel_creature(CD_EVIL, 60);
		  break;
		case 25:
		  ident = unlight_area(char_row, char_col);
		  break;
		case 32:
		  /* store bought flag */
		  break;
		default:
		  msg_print("Internal error in staffs()");
		  break;
		}
	      /* End of staff actions.		*/
	    }
	  if (ident)
	    {
	      if (!known1_p(i_ptr))
		{
		  m_ptr = &py.misc;
		  /* round half-way case up */
		  m_ptr->exp += (i_ptr->level + (m_ptr->lev >> 1)) /
		    m_ptr->lev;
		  prt_experience();

		  identify(&item_val);
		  i_ptr = &inventory[item_val];
		}
	    }