Пример #1
0
bool Creature::setAttackedCreature(Creature* creature)
{
	if(creature)
	{
		const Position& creaturePos = creature->getPosition();
		if(creaturePos.z != getPosition().z || !canSee(creaturePos))
		{
			attackedCreature = NULL;
			return false;
		}
	}

	attackedCreature = creature;
	if(attackedCreature)
	{
		onTarget(attackedCreature);
		attackedCreature->onAttacked();
	}

	for(std::list<Creature*>::iterator cit = summons.begin(); cit != summons.end(); ++cit)
		(*cit)->setAttackedCreature(creature);

	Condition* condition = getCondition(CONDITION_LOGINPROTECTION, CONDITIONID_DEFAULT);
	if(condition)
		removeCondition(condition);

	return true;
}
Пример #2
0
int main(int argc, char * argv[]){
	std::string filePath = "/home/azgt/share/sf_Share/target.mp4";
	cv::VideoCapture cap;
	cap.open(filePath);
	
	if(!cap.isOpened()){
		std::cout << "Failed to open video file" << std::endl;
		return -1;
	}
	
	cv::namedWindow("Control", CV_WINDOW_NORMAL);
	
	int iLowH = 170;
	int iHighH = 179;
	
	int iLowS = 150;
	int iHighS = 255;
	
	int iLowV = 60;
	int iHighV = 255;
	
	cvCreateTrackbar("LowH", "Control", &iLowH, 179);
	cvCreateTrackbar("HighH", "Control", &iHighH, 179);
	
	cvCreateTrackbar("LowS", "Control", &iLowS, 255);
	cvCreateTrackbar("HighS", "Control", &iHighS, 255);
	
	cvCreateTrackbar("LowV", "Control", &iLowV, 255);
	cvCreateTrackbar("HighV", "Control", &iHighV, 255);
	
	int iLastX = -1;
	int iLastY = -1;
	
	cv::Mat imgTmp;
	cap.read(imgTmp);
	
	cv::Mat imgCombined;
	
	while(true){
		cv::Mat imgOriginal;
		
		bool bSuccess = cap.read(imgOriginal);
		
		if(!bSuccess){
			std::cout << "Cannot read from video feed" << std::endl;
			break;
		}
		
		imgCombined = imgOriginal.clone();
		cv::Size s = imgCombined.size();
		cv::circle(imgCombined, cv::Point(s.width/2,s.height/2), 300, cv::Scalar(0,0,255),5,8);
		
		cv::Mat imgHSV;
		
		cv::cvtColor(imgOriginal,imgHSV,cv::COLOR_BGR2HSV);
		
		cv::Mat imgThresholded;
		
		cv::inRange(imgHSV, cv::Scalar(iLowH, iLowS, iLowV), cv::Scalar(iHighH, iHighS, iHighV), imgThresholded);
		
		cv::erode(imgThresholded, imgThresholded, getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5)));
		cv::dilate(imgThresholded, imgThresholded, getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5)));
		
		cv::dilate(imgThresholded, imgThresholded, getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5)));
		cv::erode(imgThresholded, imgThresholded, getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5)));
		
		// Calculate the moments of the thresholded image
		cv::Moments oMoments = cv::moments(imgThresholded);
		
		double dM01 = oMoments.m01;
		double dM10 = oMoments.m10;
		double dArea = oMoments.m00;
		
		// if the area <= 10000, I consider that the there are no object in the image and it's because of the noise, the area is not zero
		if(dArea > 10000){
			// calculate the position of the ball
			int posX = dM10 / dArea;
			int posY = dM01 / dArea;
			
			if(iLastX >= 0 && iLastY>=0 && posX >= 0 && posY >= 0){
				
				cv::Point target = cv::Point(posX, posY);
				cv::Point center = cv::Point(s.width / 2, s.height / 2);
				cv::Scalar color;
				
				onTarget(center, target, color, 300);
				
				// Draw a red line from the previous point to the current point
				cv::circle(imgCombined, target, 50, cv::Scalar(41,210,15),5,8);
				
				
				// draw a cirle in the middle
				cv::circle(imgCombined, center, 300, color,5,8);
		
			}
			
			iLastX = posX;
			iLastY = posY;
			
		}
		
		cv::namedWindow("Thresholded", CV_WINDOW_NORMAL);
		cv::imshow("Thresholded", imgThresholded);
		
		cv::namedWindow("Display", CV_WINDOW_NORMAL);
		cv::imshow("Display", imgCombined);
		
		
		if(cv::waitKey(30) == 27){
			std::cout << "esc key is pressed by user" << std::endl;
			break;
		}
		
	}
	return 0;
		
}