コード例 #1
0
ファイル: Airport.cpp プロジェクト: lorenzodbl/ATCSim
void
Airport::checkCrashes()
{
	if(flights.empty()) return;

	std::list<Flight*>::iterator it;

	it = flights.begin();
	while(it != flights.end())
	{
		if((*it)->getPosition().get_z()<CRASH_Z)
		{
			std::cerr<<"[PoZ]Crash of "<<(*it)->getId()<<std::endl;
			it=removeFlight((*it)->getId());
			points += CRASH_HEIGHT_POINTS;
		}else if(toDegrees(fabs((*it)->getInclination())) > CRASH_INC)
		{
			std::cerr<<"[Inc] Crash of "<<(*it)->getId()<<std::endl;
			it = removeFlight((*it)->getId());
			points += CRASH_INC_POINTS;
		}else if( (*it)->getSpeed()<CRASH_SPEED)
		{
			std::cerr<<"[Spd] Crash of "<<(*it)->getId()<<std::endl;
			it = removeFlight((*it)->getId());
			points += CRASH_SPEED_POINTS;
		}else
			it++;
	}
}
コード例 #2
0
ファイル: Airport.cpp プロジェクト: lorenzodbl/ATCSim
void
Airport::checkCollisions()
{
	if(flights.empty()) return;

	std::list<Flight*>::iterator i,j;
	bool removed = false;


	i =  flights.begin();

	while(i != flights.end())
	{
		j = i;

		if(j!=flights.end()) j++;

		while(j != flights.end())
		{
			if( (*i)->getPosition().distance((*j)->getPosition()) < COLLISION_DISTANCE)
			{
				std::cerr<<"Collision between "<<(*i)->getId()<<" and "<<(*j)->getId()<<std::endl;
				i = removeFlight((*i)->getId());
				j = removeFlight((*j)->getId());
				points += COLLISION_POINTS;
				return; //Avoid not valid iterator. Only one collision per cycle
			}
			j++;
		}
		i++;
	}
}
コード例 #3
0
ファイル: Menu.c プロジェクト: moccaplusplus/VSPlayground
void menuDeleteFlight(char* passMsg) {
	Flight flight = { NULL, NULL, 0, 0 };

	programHeader();
	printf("Usuwanie lotu:\n\n");

	if (_inputFlight(&flight)) {
		if (flight.from == NULL) {
			sprintf(passMsg, "Nie mozna usunac lotu. Lotnisko wylotu nie istnieje w bazie.\n");
		}
		if (flight.to == NULL) {
			sprintf(passMsg, "Nie mozna usunac lotu. Lotnisko przylotu nie istnieje w bazie.\n");
		}
		else {
			Flight* ref = findFlightByAllData(DB_HANDLE,
				flight.from, flight.to, flight.departure, flight.duration);
			if (ref == NULL) {
				sprintf(passMsg, "Nie mozna usunac lotu. Lot z (%s, %s) do (%s, %s) o %hu:%02hu nie istnieje.\n",
					flight.from->name, flight.from->country, flight.to->name, flight.to->country,
					getHour(&flight.departure), getMinutes(&flight.departure));
			}
			else {
				removeFlight(DB_HANDLE, ref);
				sprintf(passMsg, "Lot z (%s, %s) do (%s, %s) o %hu:%02hu zostal usuniety.\n",
					flight.from->name, flight.from->country, flight.to->name, flight.to->country,
					getHour(&flight.departure), getMinutes(&flight.departure));
			}
		}
	}
	else {
		sprintf(passMsg, "Nie mozna usunac lotu. Niepoprawne/niepelne dane.\n");
	}

	menuPrintAllFlights(passMsg);
}
コード例 #4
0
ファイル: Airport.cpp プロジェクト: lorenzodbl/ATCSim
void
Airport::checkLandings()
{
	if(flights.empty()) return;

	//pthread_mutex_lock (&mutex);
	std::list<Flight*>::iterator it;

	it = flights.begin();

	while(it != flights.end())
	{

		if((final_pos.distance((*it)->getPosition()) < LANDING_DIST) &&
				(toDegrees(normalizePi(fabs((*it)->getBearing() - toRadians(LANDING_BEAR))))<LANDING_BEAR_MAX_ERROR) &&
				((*it)->getSpeed()<LANDING_SPEED))
		{

			std::cerr<<"Flight "<<(*it)->getId()<<" landed"<<std::endl;
			points += (int)(*it)->getPoints();

			it = removeFlight((*it)->getId());

			std::cerr<<"*";


			return;
		}else
			it++;
	}
	//pthread_mutex_unlock (&mutex);
}