void World::removeAircraft(int identifier) {
    Aircraft* aircraft = getAircraft(identifier);
    if (aircraft) {
        aircraft->destroy();
        mPlayerAircrafts.erase(std::find(mPlayerAircrafts.begin(), mPlayerAircrafts.end(), aircraft));
    }
}
Exemple #2
0
void World::RemoveAircraft( int identifier )
{
	Aircraft* aircraft = GetAircraft( identifier );
	if ( aircraft )
	{
		aircraft->Destroy();
		pImpl->mPlayerAircrafts.erase( std::find( pImpl->mPlayerAircrafts.begin(), pImpl->mPlayerAircrafts.end(), aircraft ) );
	}
}
Exemple #3
0
Aircraft * Aircraft::createAircraft(const std::string & filename) {
    Aircraft * aircraft = new Aircraft();
    if (aircraft && aircraft->initWithSpriteFrameName(filename)) {
        aircraft->autorelease();
        return aircraft;
    }
    CC_SAFE_DELETE(aircraft);
    return nullptr;
}
Exemple #4
0
void Simulation::evolve(Aircraft& aircraft, UnitTime time) {
    Coordinate coordiante = aircraft.evolve(time);

    std::vector<SimulationListener>::iterator iterator = simulationListeners.begin();
    while (iterator != simulationListeners.end()) {
        SimulationListener simulationListener = *iterator;
        simulationListener.notify(aircraft.getName(), coordiante);
    }
}
Exemple #5
0
/**
 * Clean up a station by clearing vehicle orders, invalidating windows and
 * removing link stats.
 * Aircraft-Hangar orders need special treatment here, as the hangars are
 * actually part of a station (tiletype is STATION), but the order type
 * is OT_GOTO_DEPOT.
 */
Station::~Station()
{
	if (CleaningPool()) return;

	while (!this->loading_vehicles.empty()) {
		this->loading_vehicles.front()->LeaveStation();
	}

	Aircraft *a;
	FOR_ALL_AIRCRAFT(a) {
		if (!a->IsNormalAircraft()) continue;
		if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
	}

	Station *st;
	FOR_ALL_STATIONS(st) {
		for (CargoID c = 0; c < NUM_CARGO; ++c) {
			GoodsEntry &ge = st->goods[c];
			ge.link_stats.erase(this->index);
			DeleteStaleFlows(st->index, c, this->index);
			ge.cargo.RerouteStalePackets(this->index);
		}
	}

	Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		/* Forget about this station if this station is removed */
		if (v->last_station_visited == this->index) {
			v->last_station_visited = INVALID_STATION;
		}
		if (v->last_loading_station == this->index) {
			v->last_loading_station = INVALID_STATION;
		}
	}

	InvalidateWindowData(WC_STATION_LIST, this->owner, 0);

	DeleteWindowById(WC_STATION_VIEW, index);

	/* Now delete all orders that go to the station */
	RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);

	/* Remove all news items */
	DeleteStationNews(this->index);

	for (CargoID c = 0; c < NUM_CARGO; c++) {
		this->goods[c].cargo.Truncate(0);
	}

	CargoPacket::InvalidateAllFrom(this->index);
}
/**
 * Clean up a station by clearing vehicle orders and invalidating windows.
 * Aircraft-Hangar orders need special treatment here, as the hangars are
 * actually part of a station (tiletype is STATION), but the order type
 * is OT_GOTO_DEPOT.
 */
Station::~Station()
{
	if (CleaningPool()) {
		for (CargoID c = 0; c < NUM_CARGO; c++) {
			this->goods[c].cargo.OnCleanPool();
		}
		return;
	}

	while (!this->loading_vehicles.empty()) {
		this->loading_vehicles.front()->LeaveStation();
	}

	Aircraft *a;
	FOR_ALL_AIRCRAFT(a) {
		if (!a->IsNormalAircraft()) continue;
		if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
	}

	Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		/* Forget about this station if this station is removed */
		if (v->last_station_visited == this->index) {
			v->last_station_visited = INVALID_STATION;
		}
	}

	/* Clear the persistent storage. */
	delete this->airport.psa;

	if (this->owner == OWNER_NONE) {
		/* Invalidate all in case of oil rigs. */
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
	} else {
		InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
	}

	DeleteWindowById(WC_STATION_VIEW, index);

	/* Now delete all orders that go to the station */
	RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);

	/* Remove all news items */
	DeleteStationNews(this->index);

	for (CargoID c = 0; c < NUM_CARGO; c++) {
		this->goods[c].cargo.Truncate(0);
	}

	CargoPacket::InvalidateAllFrom(this->index);
}
Exemple #7
0
void World::guideMissiles()
{
    // Setup command that stores all enemies in mActiveEnemies
	Command enemyCollector;
	enemyCollector.category = Category::EnemyAircraft;
	enemyCollector.action = derivedAction<Aircraft>([this] (Aircraft& enemy, sf::Time)
	{
	    if(!enemy.isDestroyed())
		{
		    mActiveEnemies.push_back(&enemy);
		}
	});
	
	// Setup command that guides all missiles to the enemy which is currently closest to the player
	Command missileGuider;
	missileGuider.category = Category::AlliedProjectile;
	missileGuider.action = derivedAction<Projectile>([this] (Projectile& missile, sf::Time)
	{
	    // Ignore unguided bullets
		if(!missile.isGuided())
		{
		    return;
		}
		
		float minDistance = std::numeric_limits<float>::max();
		Aircraft* closestEnemy = nullptr;
		
		// Find closest enemy
		for(Aircraft* enemy : mActiveEnemies)
		{
	        float enemyDistance = distance(missile, *enemy);
			
			if(enemyDistance < minDistance)
			{
			    closestEnemy = enemy;
			    minDistance = enemyDistance;
			}
		}
		
		if(closestEnemy)
		{
		    missile.guideTowards(closestEnemy->getWorldPosition());
		}
	});
	
	// Push commands, reset active enemies
	mCommandQueue.push(enemyCollector);
	mCommandQueue.push(missileGuider);
	mActiveEnemies.clear();
}
Exemple #8
0
void Simulation::evolveAllAircarft() {
    vector<Aircraft>::iterator iterator = aircrafts.begin();
    while (iterator != aircrafts.end()) {
        Aircraft aircraft = *iterator;

        UnitTime deltaTime = getTime() - startedTime;
        if (!aircraft.isFlying(deltaTime)) {
            aircrafts.erase(iterator);
        } else {
            evolve(aircraft, deltaTime);
        }

        iterator++;
    }
}
Exemple #9
0
int main(int argc, char* argv[]) {
	Aircraft* pac;

	pac = new First;
	pac->Normal();
	delete pac;
	cout <<"----------" <<endl;

	pac = new Second;
	pac->Normal();
	delete pac;
	cout <<"----------" <<endl;

	return 0;
} ///:~
Exemple #10
0
bool Aircraft::Colliding(const Aircraft &Other) const
{
    const sf::Vector2f &Me = Shape.getPosition();
    const sf::Vector2f &Pos = Other.Shape.getPosition();
    return OnRunway() == Other.OnRunway() &&
           InRange(Me, Pos, (Radius + Other.Radius) / 1.3f);
}
Exemple #11
0
/**
 * Clean up a station by clearing vehicle orders and invalidating windows.
 * Aircraft-Hangar orders need special treatment here, as the hangars are
 * actually part of a station (tiletype is STATION), but the order type
 * is OT_GOTO_DEPOT.
 */
Station::~Station()
{
	if (CleaningPool()) return;

	while (!this->loading_vehicles.empty()) {
		this->loading_vehicles.front()->LeaveStation();
	}

	Aircraft *a;
	FOR_ALL_AIRCRAFT(a) {
		if (!a->IsNormalAircraft()) continue;
		if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
	}

	Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		/* Forget about this station if this station is removed */
		if (v->last_station_visited == this->index) {
			v->last_station_visited = INVALID_STATION;
		}
	}

	this->sign.MarkDirty();
	InvalidateWindowData(WC_STATION_LIST, this->owner, 0);

	DeleteWindowById(WC_STATION_VIEW, index);
	WindowNumber wno = (this->index << 16) | VLW_STATION_LIST | this->owner;
	DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11));
	DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11));
	DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11));
	DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11));

	/* Now delete all orders that go to the station */
	RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);

	/* Remove all news items */
	DeleteStationNews(this->index);

	for (CargoID c = 0; c < NUM_CARGO; c++) {
		this->goods[c].cargo.Truncate(0);
	}

	CargoPacket::InvalidateAllFrom(this->index);
}
Exemple #12
0
void
World::guideMissiles() {
    Command enemyCollector;
    enemyCollector.category = Category::EnemyAircraft;
    enemyCollector.action   = derivedAction<Aircraft>(
        [this] ( Aircraft& enemy, sf::Time ) {
            if ( !enemy.IsDestroyed() ) {
                mActiveEnemies.push_back( &enemy );
            }
        }
    );

    Command missileGuider;
    missileGuider.category  = Category::AlliedProjectile;
    missileGuider.action    = derivedAction<Projectile>(
        // TODO: outsource this function into separate method
        [this] ( Projectile& missile, sf::Time ) {
            // Ignore unguided bullets
            if ( !missile.IsGuided() ) {
                return;
            }

            float minDistance       = std::numeric_limits<float>::max();
            Aircraft* closestEnemy  = nullptr;

            for( Aircraft* enemy : mActiveEnemies ) {
                float enemyDistance = Distance( missile, *enemy );

                if ( enemyDistance < minDistance ) {
                    closestEnemy    = enemy;
                    minDistance     = enemyDistance;
                }
            }
            if ( closestEnemy ) {
                missile.GuideTowards( closestEnemy->GetWorldPosition() );
            }
        }
    );

    mCommandQueue.push( enemyCollector );
    mCommandQueue.push( missileGuider );
    mActiveEnemies.clear();
}
Exemple #13
0
/** need to be called to load aircraft from old version */
void UpdateOldAircraft()
{
	/* set airport_flags to 0 for all airports just to be sure */
	Station *st;
	FOR_ALL_STATIONS(st) {
		st->airport.flags = 0; // reset airport
	}

	Aircraft *a;
	FOR_ALL_AIRCRAFT(a) {
		/* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor)
		 * skip those */
		if (a->IsNormalAircraft()) {
			/* airplane in terminal stopped doesn't hurt anyone, so goto next */
			if ((a->vehstatus & VS_STOPPED) && a->state == 0) {
				a->state = HANGAR;
				continue;
			}

			AircraftLeaveHangar(a, a->direction); // make airplane visible if it was in a depot for example
			a->vehstatus &= ~VS_STOPPED; // make airplane moving
			UpdateAircraftCache(a);
			a->cur_speed = a->vcache.cached_max_speed; // so aircraft don't have zero speed while in air
			if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) {
				/* reset current order so aircraft doesn't have invalid "station-only" order */
				a->current_order.MakeDummy();
			}
			a->state = FLYING;
			AircraftNextAirportPos_and_Order(a); // move it to the entry point of the airport
			GetNewVehiclePosResult gp = GetNewVehiclePos(a);
			a->tile = 0; // aircraft in air is tile=0

			/* correct speed of helicopter-rotors */
			if (a->subtype == AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32;

			/* set new position x,y,z */
			SetAircraftPosition(a, gp.x, gp.y, GetAircraftFlyingAltitude(a));
		}
	}
}
Exemple #14
0
void World::guideMissiles()
{
    Command enemyCollector;
    enemyCollector.category = Category::EnemyAircraft;
    enemyCollector.action = derivedAction<Aircraft>(
            [this](Aircraft& enemy, sf::Time)
                {
                    if(!enemy.isDestroyed())
                        mActiveEnemies.push_back(&enemy);
                });
    Command missileGuider;
    missileGuider.category = Category::AlliedProjectile;
    missileGuider.action = derivedAction<Projectile>(
            [this](Projectile& missile, sf::Time)
                 {
                     if(!missile.isGuided())
                         return;
                     float minDistance = std::numeric_limits<float>::max();
                     Aircraft* closestEnemy = nullptr;
                     
                     for(auto* enemy : mActiveEnemies)
                     {
                         float enemyDistance = distance(missile, *enemy);
                         
                         if(enemyDistance < minDistance)
                         {
                             closestEnemy = enemy;
                             minDistance = enemyDistance;
                         }
                     }
                     if (closestEnemy)
                     {
                         missile.guideTowards(closestEnemy->getWorldPosition());
                     }
                 });
    mCommandQueue.push(enemyCollector);
    mCommandQueue.push(missileGuider);
    mActiveEnemies.clear();
}
Exemple #15
0
// calculate rotational and linear accelerations
void Frame::calculate_forces(const Aircraft &aircraft,
                             const Aircraft::sitl_input &input,
                             Vector3f &rot_accel,
                             Vector3f &body_accel)
{
    Vector3f thrust; // newtons

    for (uint8_t i=0; i<num_motors; i++) {
        Vector3f mraccel, mthrust;
        motors[i].calculate_forces(input, thrust_scale, motor_offset, mraccel, mthrust);
        rot_accel += mraccel;
        thrust += mthrust;
    }

    body_accel = thrust/aircraft.gross_mass();

    if (terminal_rotation_rate > 0) {
        // rotational air resistance
        const Vector3f &gyro = aircraft.get_gyro();
        rot_accel.x -= gyro.x * radians(400.0) / terminal_rotation_rate;
        rot_accel.y -= gyro.y * radians(400.0) / terminal_rotation_rate;
        rot_accel.z -= gyro.z * radians(400.0) / terminal_rotation_rate;
    }

    if (terminal_velocity > 0) {
        // air resistance
        Vector3f air_resistance = -aircraft.get_velocity_air_ef() * (GRAVITY_MSS/terminal_velocity);
        body_accel += aircraft.get_dcm().transposed() * air_resistance;
    }

    // add some noise
    const float gyro_noise = radians(0.1);
    const float accel_noise = 0.3;
    const float noise_scale = thrust.length() / (thrust_scale * num_motors);
    rot_accel += Vector3f(aircraft.rand_normal(0, 1),
                          aircraft.rand_normal(0, 1),
                          aircraft.rand_normal(0, 1)) * gyro_noise * noise_scale;
    body_accel += Vector3f(aircraft.rand_normal(0, 1),
                           aircraft.rand_normal(0, 1),
                           aircraft.rand_normal(0, 1)) * accel_noise * noise_scale;
}
Exemple #16
0
// calculate rotational and linear accelerations
void Frame::calculate_forces(const Aircraft &aircraft,
                             const Aircraft::sitl_input &input,
                             Vector3f &rot_accel,
                             Vector3f &body_accel)
{
    // rotational acceleration, in rad/s/s, in body frame
    float thrust = 0.0f; // newtons

    for (uint8_t i=0; i<num_motors; i++) {
        float motor_speed = constrain_float((input.servos[motor_offset+motors[i].servo]-1100)/900.0, 0, 1);
        rot_accel.x  += -radians(5000.0) * sinf(radians(motors[i].angle)) * motor_speed;
        rot_accel.y  +=  radians(5000.0) * cosf(radians(motors[i].angle)) * motor_speed;
        rot_accel.z += motors[i].yaw_factor * motor_speed * radians(400.0);
        thrust += motor_speed * thrust_scale; // newtons
    }

    body_accel = Vector3f(0, 0, -thrust / mass);

    if (terminal_rotation_rate > 0) {
        // rotational air resistance
        const Vector3f &gyro = aircraft.get_gyro();
        rot_accel.x -= gyro.x * radians(400.0) / terminal_rotation_rate;
        rot_accel.y -= gyro.y * radians(400.0) / terminal_rotation_rate;
        rot_accel.z -= gyro.z * radians(400.0) / terminal_rotation_rate;
    }

    if (terminal_velocity > 0) {
        // air resistance
        Vector3f air_resistance = -aircraft.get_velocity_ef() * (GRAVITY_MSS/terminal_velocity);
        body_accel += aircraft.get_dcm().transposed() * air_resistance;
    }

    // add some noise
    const float gyro_noise = radians(0.1);
    const float accel_noise = 0.3;
    const float noise_scale = thrust / (thrust_scale * num_motors);
    rot_accel += Vector3f(aircraft.rand_normal(0, 1),
                          aircraft.rand_normal(0, 1),
                          aircraft.rand_normal(0, 1)) * gyro_noise * noise_scale;
    body_accel += Vector3f(aircraft.rand_normal(0, 1),
                           aircraft.rand_normal(0, 1),
                           aircraft.rand_normal(0, 1)) * accel_noise * noise_scale;
}
Exemple #17
0
bool Aeromatic::fdm()
{
    Aircraft *aircraft = _aircraft[_atype];
    std::vector<System*> systems = _aircraft[_atype]->get_systems();

    _engines = _MIN(_no_engines, 4);
    aircraft->_engines = _engines;


//***** METRICS ***************************************
    _payload = _max_weight;
    _stall_weight = _max_weight;

    // first, estimate wing loading in psf
    float wing_loading = aircraft->get_wing_loading();

    // if no wing area given, use wing loading to estimate
    bool wingarea_input;
    if (_wing.area == 0)
    {
        wingarea_input = false;
        _wing.area = _max_weight / wing_loading;
    }
    else
    {
        wingarea_input = true;
        wing_loading = _max_weight / _wing.area;
    }

    // calculate wing chord
    if (_wing.aspect == 0) {
        _wing.aspect = aircraft->get_aspect_ratio();
    } else {
        _user_wing_data++;
    }
    if (_wing.chord == 0)
    {
        if (_wing.aspect > 0) {
            _wing.chord = _wing.span / _wing.aspect;
        } else {
            _wing.chord = _wing.area / _wing.span;
        }
    }
    else {
        _user_wing_data++;
    }

    // calculate aspect ratio
    if (_wing.aspect == 0) {
        _wing.aspect = (_wing.span*_wing.span) / _wing.area;
    } else {
        _user_wing_data++;
    }

    if (_wing.taper == 0) {
        _wing.taper = 1.0f;
    }

    float TR = _wing.taper;
    _wing.chord_mean = 0.75f*_wing.chord*(1.0f+TR+TR*TR)/(1.0f+TR);
    _wing.de_da = 4.0f/(_wing.aspect+2.0f);

    // leading edge sweep
    // devide the span by two and account for fuselage width
    float span = 0.45f*_wing.span;
    float root_tip = _wing.chord*(1.0f - _wing.taper);

    if (_wing.sweep_le == 0)
    {
        _wing.sweep_le = atanf(root_tip/span);
        if (_wing.shape != DELTA) {
            _wing.sweep_le *= 0.5f;
        }
        _wing.sweep_le *= RAD_TO_DEG;
        _wing.sweep_le += _wing.sweep;
    }

    if (_wing.thickness == 0)
    {
        // Hofman equation for t/c
//      float Ws = _stall_weight;
        float Vs = _stall_speed * KNOTS_TO_FPS;
        float sweep = _wing.sweep * DEG_TO_RAD;
        float TC = 0.051f * _wing.area * powf(cosf(sweep), 5.0f)/Vs;
        _wing.thickness = TC * _wing.chord;
    }

    // for now let's use a standard 2 degrees wing incidence
    if (_wing.incidence == 0) {
        _wing.incidence = 2.0;
    }

    // estimate horizontal tail area
    if (_htail.area == 0) {
        _htail.area = _wing.area * aircraft->get_htail_area();
    }

    // estimate distance from CG to horizontal tail aero center
    if (_htail.arm == 0) {
        _htail.arm = _length * aircraft->get_htail_arm();
    }

    if (_htail.aspect == 0) {
        _htail.aspect = 5.0f;	// ht_w * _wing.aspect;
    }
    if (_htail.taper == 0) {
        _htail.taper = 0.5f;
    }

    float ht_w = 0.33f; // sqrtf(_htail.area / _wing.area);
    if (_htail.span == 0) {
        _htail.span = ht_w * _wing.span;
    }

    TR = _htail.taper;
    _htail.chord_mean = 0.75f*_htail.chord*(1.0f+TR+TR*TR)/(1.0f+TR);
    _htail.de_da = 4.0f/(_htail.aspect+2.0f);

    // estimate vertical tail area
    if (_vtail.area == 0) {
        _vtail.area = _wing.area * aircraft->get_vtail_area();
    }

    // estimate distance from CG to vertical tail aero center
    if (_vtail.arm == 0) {
        _vtail.arm = _length * aircraft->get_vtail_arm();
    }

    float vt_w = 0.15f; // sqrtf(_vtail.area / _wing.area*0.5f);
    if (_vtail.span == 0) {
        _vtail.span = vt_w * _wing.span;
    }
    if (_vtail.aspect == 0) {
        _vtail.aspect = 1.7f;	// vt_w * _wing.aspect;
    }
    if (_vtail.taper == 0) {
        _vtail.taper = 0.7f;
    }

    TR = _vtail.taper;
    _vtail.chord_mean = 0.75f*_vtail.chord*(1.0f+TR+TR*TR)/(1.0f+TR);
    _vtail.de_da = 4.0f/(_vtail.aspect+2.0f);

//***** EMPTY WEIGHT *********************************

    // estimate empty weight, based on max weight
    if (_empty_weight == 0) {
        _empty_weight = _max_weight * aircraft->get_empty_weight();
    }

//***** MOMENTS OF INERTIA ******************************

    // use Roskam's formulae to estimate moments of inertia
    if (_inertia[X] == 0.0f && _inertia[Y] == 0.0f && _inertia[Z] == 0.0f)
    {
        float slugs = (_empty_weight / 32.2f);	// sluggishness
        const float *R = aircraft->get_roskam();

        // These are for an empty airplane
        _inertia[X] = slugs * powf((R[X] * _wing.span / 2), 2);
        _inertia[Y] = slugs * powf((R[Y] * _length / 2), 2);
        _inertia[Z] = slugs * powf((R[Z] * ((_wing.span + _length)/2)/2), 2);
    }

//***** CG LOCATION ***********************************

    _cg_loc[X] = (_length - _htail.arm) * FEET_TO_INCH;
    _cg_loc[Y] = 0;
    _cg_loc[Z] = -(_length / 40.0f) * FEET_TO_INCH;

//***** AERO REFERENCE POINT **************************

    _aero_rp[X] = _cg_loc[X];
    _aero_rp[Y] = 0;
    _aero_rp[Z] = 0;

//***** PILOT EYEPOINT *********************************

    // place pilot's eyepoint based on airplane type
    const float *_eyept_loc = aircraft->get_eyept_loc();
    float eyept_loc[3];
    eyept_loc[X] = (_length * _eyept_loc[X]) * FEET_TO_INCH;
    eyept_loc[Y] = _eyept_loc[Y];
    eyept_loc[Z] = _eyept_loc[Z];

//***** PAYLOAD ***************************************

    // A point mass will be placed at the CG weighing
    // 1/2 of the usable aircraft load.
    float payload_loc[3];
    payload_loc[X] = _cg_loc[X];
    payload_loc[Y] = _cg_loc[Y];
    payload_loc[Z] = _cg_loc[Z];
    _payload -= _empty_weight;

//***** SYSTEMS ***************************************
    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled()) {
            systems[i]->set(_cg_loc);
        }
    }

//***** COEFFICIENTS **********************************
    aircraft->set_lift();
    aircraft->set_drag();
    aircraft->set_side();
    aircraft->set_roll();
    aircraft->set_pitch();
    aircraft->set_yaw();

//************************************************
//*                                              *
//*  Print out xml document                      *
//*                                              *
//************************************************

    char str[64];
    time_t t;

    time(&t);
#ifdef _MSC_VER
    struct tm ti;
    localtime_s(&ti, &t);
    strftime(str, sizeof(str), "%d %b %Y", &ti);
#else
    struct tm *ti= localtime(&t);
    strftime(str, sizeof(str), "%d %b %Y", ti);
#endif

    _dir = _subdir ? create_dir(_path, _name) : _path;
    if (_dir.empty()) {
        std::cout << "Unable to create directory: " << _path << "/" << _name << std::endl;
        return false;
    }

    std::string systems_dir;
    if (_system_files)
    {
        systems_dir = create_dir(_dir, "Systems");
        if (systems_dir.empty())
        {
            std::cout << "Unable to create directory: " << _dir<< "/Systems" << std::endl;
            _system_files = false;
        }
    }

    std::string fname = _dir + "/" + std::string(_name) + ".xml";

    std::string version = AEROMATIC_VERSION_STR;

    if (!_overwrite && overwrite(fname)) {
        std::cout << "File already exists: " << fname << std::endl;
        return false;
    }

    std::ofstream file;
    file.open(fname.c_str());
    if (file.fail() || file.bad())
    {
        file.close();
        return false;
    }

    file.precision(2);
    file.flags(std::ios::right);
    file << std::fixed << std::showpoint;

    file << "<?xml version=\"1.0\"?>" << std::endl;
    file << "<?xml-stylesheet type=\"text/xsl\" href=\"http://jsbsim.sourceforge.net/JSBSim.xsl\"?>" << std::endl;
    file << std::endl;
    file << "<fdm_config name=\"" << _name << "\" version=\"2.0\" release=\"ALPHA\"" << std::endl;
    file << "   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << std::endl;
    file << "   xsi:noNamespaceSchemaLocation=\"http://jsbsim.sourceforge.net/JSBSim.xsd\">" << std::endl;
    file << std::endl;
    file << " <fileheader>" << std::endl;
    file << "  <author> Aeromatic v " << version << " </author>" << std::endl;
    file << "  <filecreationdate> " << str << " </filecreationdate>" << std::endl;
    file << "  <version>$Revision: 1.50 $</version>" << std::endl;
    file << "  <description> Models a " << _name << ". </description>" << std::endl;
    file << " </fileheader>" << std::endl;
    file << std::endl;
    file << "<!--\n  File:     " << _name << ".xml" << std::endl;
    file << "  Inputs:" << std::endl;
    file << "    name:          " << _name << std::endl;
    file << "    type:          ";
    switch(_atype)
    {
    case LIGHT:
        if (_no_engines == 0) {
            file << "glider" << std::endl;
        } else {
            file << "light commuter with " << _no_engines << " engines" << std::endl;
        }
        break;
    case PERFORMANCE:
        file << "WWII fighter, subsonic sport, aerobatic" << std::endl;
        break;
    case FIGHTER:
        file << _no_engines << " engine transonic/supersonic fighter" << std::endl;
        break;
    case JET_TRANSPORT:
        file << _no_engines << " engine transonic transport" << std::endl;
        break;
    case PROP_TRANSPORT:
        file << "multi-engine prop transport" << std::endl;
        break;
    }
    file << "    stall speed:   " << _stall_speed << "kts" << std::endl;
    file << "    max weight:    " << _max_weight << " lb" << std::endl;
    file << "    length:        " << _length << " ft" << std::endl;
    file << "    wing: " << std::endl;
    file << "     span:         " << _wing.span << " ft" << std::endl;
    file << "     area:         ";
    if (wingarea_input) {
        file << _wing.area << " sq-ft" << std::endl;
    } else {
        file << "unspecified" << std::endl;
    }
    file << "     chord:        " << _wing.chord << " ft" << std::endl;
    file << "     aspect ratio: " << _wing.aspect << ":1" << std::endl;
    file << "     taper ratio:  " << _wing.taper << ":1" << std::endl;
    file << "     incidence:    " << _wing.incidence << " degrees" << std::endl;
    file << "     dihedral:     " << _wing.dihedral << " degrees" << std::endl;
    file << "     sweep:        " << _wing.sweep << " degrees" << std::endl;
    file << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled()) {
            std::string comment = systems[i]->comment();
            if (!comment.empty()) {
                file << comment << std::endl;
            }
        }
    }

    file << "  Outputs:" << std::endl;
    file << "    wing loading:  " << wing_loading << " lb/sq-ft" << std::endl;
    file << "    payload:       " << _payload << " lbs" << std::endl;
    file << "    CL-alpha:      " << _CLalpha[0] << " per radian" << std::endl;
    file << "    CL-0:          " << _CL0 << std::endl;
    file << "    CL-max:        " << _CLmax[0] << std::endl;
    file << "    CD-0:          " << _CD0 << std::endl;
    file << "    K:             " << _Kdi << std::endl;
    file << "    Mcrit:         " << _Mcrit << std::endl;
    file << "-->" << std::endl;
    file << std::endl;

//***** METRICS **********************************

    file << " <metrics>" << std::endl;
    file << "   <wingarea  unit=\"FT2\"> " << std::setw(8) << _wing.area << " </wingarea>" << std::endl;
    file << "   <wingspan  unit=\"FT\" > " << std::setw(8) << _wing.span << " </wingspan>" << std::endl;
    file << "   <wing_incidence>       " << std::setw(8) << _wing.incidence << " </wing_incidence>" << std::endl;
    file << "   <chord     unit=\"FT\" > " << std::setw(8) << _wing.chord << " </chord>" << std::endl;
    file << "   <htailarea unit=\"FT2\"> " << std::setw(8) << _htail.area << " </htailarea>" << std::endl;
    file << "   <htailarm  unit=\"FT\" > " << std::setw(8) << _htail.arm << " </htailarm>" << std::endl;
    file << "   <vtailarea  unit=\"FT2\">" << std::setw(8) << _vtail.area << " </vtailarea>" << std::endl;
    file << "   <vtailarm  unit=\"FT\" > " << std::setw(8) << _vtail.arm << " </vtailarm>" << std::endl;
    file << "   <location name=\"AERORP\" unit=\"IN\">" << std::endl;
    file << "     <x> " << std::setw(8) << _aero_rp[X] << " </x>" << std::endl;
    file << "     <y> " << std::setw(8) << _aero_rp[Y] << " </y>" << std::endl;
    file << "     <z> " << std::setw(8) << _aero_rp[Z] << " </z>" << std::endl;
    file << "   </location>" << std::endl;
    file << "   <location name=\"EYEPOINT\" unit=\"IN\">" << std::endl;
    file << "     <x> " << std::setw(8) << eyept_loc[X] << " </x>" << std::endl;
    file << "     <y> " << std::setw(8) << eyept_loc[Y] << " </y>" << std::endl;
    file << "     <z> " << std::setw(8) << eyept_loc[Z] << " </z>" << std::endl;
    file << "   </location>" << std::endl;
    file << "   <location name=\"VRP\" unit=\"IN\">" << std::endl;
    file << "     <x>     0.0 </x>" << std::endl;
    file << "     <y>     0.0 </y>" << std::endl;
    file << "     <z>     0.0 </z>" << std::endl;
    file << "   </location>" << std::endl;
    file << " </metrics>"<< std::endl;
    file << std::endl;
    file << " <mass_balance>" << std::endl;
    file << "   <ixx unit=\"SLUG*FT2\">  " << std::setw(8) << _inertia[X] << " </ixx>" << std::endl;
    file << "   <iyy unit=\"SLUG*FT2\">  " << std::setw(8) << _inertia[Y] << " </iyy>" << std::endl;
    file << "   <izz unit=\"SLUG*FT2\">  " << std::setw(8) << _inertia[Z] << " </izz>" << std::endl;
    file << "   <emptywt unit=\"LBS\" >  " << std::setw(8) << _empty_weight << " </emptywt>" << std::endl;
    file << "   <location name=\"CG\" unit=\"IN\">" << std::endl;
    file << "     <x> " << std::setw(8) << _cg_loc[X] << " </x>" << std::endl;
    file << "     <y> " << std::setw(8) << _cg_loc[Y] << " </y>" << std::endl;
    file << "     <z> " << std::setw(8) << _cg_loc[Z] << " </z>" << std::endl;
    file << "   </location>" << std::endl;
    file << "   <pointmass name=\"Payload\">" << std::endl;
    file << "    <description> " << _payload << " LBS should bring model up to entered max weight </description>" << std::endl;
    file << "    <weight unit=\"LBS\"> " << (_payload* 0.5f) << " </weight>" << std::endl;
    file << "    <location name=\"POINTMASS\" unit=\"IN\">" << std::endl;
    file << "     <x> " << std::setw(8) << payload_loc[X] << " </x>" << std::endl;
    file << "     <y> " << std::setw(8) << payload_loc[Y] << " </y>" << std::endl;
    file << "     <z> " << std::setw(8) << payload_loc[Z] << " </z>" << std::endl;
    file << "   </location>" << std::endl;
    file << "  </pointmass>" << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string mass_balance = systems[i]->mass_balance();
            if (!mass_balance.empty()) {
                file << mass_balance << std::endl;
            }
        }
    }

    file << " </mass_balance>" << std::endl;
    file << std::endl;

//***** FDM_CONFIG ********************************************

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string fdm = systems[i]->fdm();
            if (!fdm.empty()) {
                file << fdm << std::endl;
            }
        }
    }

//***** SYSTEMS ***********************************************

    if (_system_files == true)
    {
        for (unsigned i=0; i<systems.size(); ++i)
        {
            if (systems[i]->enabled())
            {
                std::string system = systems[i]->system();
                if (!system.empty())
                {
                    std::string sname = systems[i]->get_description();
                    std::string sfname = sname + ".xml";

                    if (!_overwrite && overwrite(sfname))
                    {
                        std::cout << "File already exists: " << fname << std::endl;
                        std::cout << "Skipping." << std::endl;
                    }
                    else
                    {
                        file << " <system file=\"" << sfname << "\"/>" << std::endl;

                        std::string sfpath = systems_dir + "/" + sfname;
                        std::ofstream sfile;
                        sfile.open(sfpath.c_str());
                        if (sfile.fail() || sfile.bad())
                        {
                            std::cout << "Error opening file: " << fname << std::endl;
                            std::cout << "Skipping." << std::endl;
                        }
                        else
                        {
                            sfile << "<?xml version=\"1.0\"?>" << std::endl;
                            sfile << "<system name=\"" << sname << "\">" << std::endl;
                            sfile << system << std::endl;
                            sfile << "</system>" << std::endl;
                        }
                        sfile.close();
                    }
                }
            }
        }
        file << std::endl;
    }

    file << " <flight_control name=\"FCS: " << _name << "\">" << std::endl;
    file << std::endl;

    if (_system_files == false)
    {
        for (unsigned i=0; i<systems.size(); ++i)
        {
            if (systems[i]->enabled())
            {
                std::string system = systems[i]->system();
                if (!system.empty()) {
                    file << system << std::endl;
                }
            }
        }
    }

    file << " </flight_control>"<< std::endl;
    file << std::endl;

//***** AERODYNAMICS ******************************************

    file << " <aerodynamics>" << std::endl;
    file << std::endl;

    // ***** LIFT ******************************************

    file << "  <axis name=\"LIFT\">" << std::endl;
    file << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string lift = systems[i]->lift();
            if (!lift.empty()) {
                file << lift << std::endl;
            }
        }
    }

    file << "  </axis>" << std::endl;
    file << std::endl;

    // ***** DRAG ******************************************

    file << "  <axis name=\"DRAG\">" << std::endl;
    file << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string drag = systems[i]->drag();
            if (!drag.empty()) {
               file << drag << std::endl;
            }
        }
    }

    file << "  </axis>" << std::endl;
    file << std::endl;

    // ***** SIDE ******************************************

    file << "  <axis name=\"SIDE\">" << std::endl;
    file << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string side = systems[i]->side();
            if (!side.empty()) {
                file << side << std::endl;
            }
        }
    }

    file << "  </axis>" << std::endl;
    file << std::endl;

    // ***** PITCH *****************************************

    file << "  <axis name=\"PITCH\">" << std::endl;
    file << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string pitch = systems[i]->pitch();
            if (!pitch.empty()) {
                file << pitch << std::endl;
            }
        }
    }

    file << "  </axis>" << std::endl;
    file << std::endl;

    // ***** ROLL ******************************************

    file << "  <axis name=\"ROLL\">" << std::endl;
    file << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string roll = systems[i]->roll();
            if (!roll.empty()) {
                file << roll << std::endl;
            }
        }
    }

    file << "  </axis>" << std::endl;
    file << std::endl;

    // ***** YAW *******************************************

    file << "  <axis name=\"YAW\">" << std::endl;
    file << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string yaw = systems[i]->yaw();
            if (!yaw.empty()) {
                file << yaw << std::endl;
            }
        }
    }

    file << "  </axis>" << std::endl;
    file << std::endl;
    
    file << " </aerodynamics>" << std::endl;
    file << std::endl;

    file << " <external_reactions>" << std::endl;

    for (unsigned i=0; i<systems.size(); ++i)
    {
        if (systems[i]->enabled())
        {
            std::string force = systems[i]->external_force();
            if (!force.empty()) {
                file << force << std::endl;
            }
        }
    }

    file << " </external_reactions>" << std::endl;

    file << std::endl;
    file << "</fdm_config>" << std::endl;

    file.close();

    return true;
}
Exemple #18
0
bool Aircraft::operator==(Aircraft aircraft) {
    return (aircraft.GetTailNumber() == _tail_number &&
        aircraft.GetFlightPlan() == _flight_plan &&
        aircraft.HasAdsB() == _has_AdsB &&
        aircraft.HasTcas() == _has_Tcas);
}
Exemple #19
0
AttackResult Player::HitCheck(Position pos)
{
// 	Draw picaso;

	for (int i = 0; i < m_MyShip.size(); ++i)
	{
		AttackResult result = AR_NONE;
		MapDataTypes shipType = m_MyShip[i]->GetShipType();

		//각각 배로 타입 변환하여 hitcheck
		if (shipType == MD_AIRCRAFT)
		{
			Aircraft* aircraft = (Aircraft*)m_MyShip[i];
			result = aircraft->HitCheck(pos);
		}
		else if (shipType == MD_BATTLESHIP)
		{
			BattleShip_* battleship = (BattleShip_*)m_MyShip[i];
			result = battleship->HitCheck(pos);
		}
		else if (shipType == MD_CRUISER)
		{
			Cruiser* cruiser = (Cruiser*)m_MyShip[i];
			result = cruiser->HitCheck(pos);
		}
		else if(shipType == MD_DESTROYER1 || shipType == MD_DESTROYER2)
		{
			Destroyer* destroyer = (Destroyer*)m_MyShip[i];
			result = destroyer->HitCheck(pos);
		}

		//hit나 destroy 인 경우 
		switch (result)
		{
		case AR_HIT:
			printf_s("HIT\n");
			m_MyMap.ChangeStatusMap(pos, MAP_HIT);
			break;
		case AR_DESTROY_AIRCRAFT:
			m_MyMap.ChangeStatusMap(pos, MAP_DESTROY);
			printf_s("AIRCREFT DESTROY\n");
			break;
		case AR_DESTROY_BATTLESHIP:
			m_MyMap.ChangeStatusMap(pos, MAP_DESTROY);
			printf_s("BATTLESHIP DESTROY\n");
			
			break;
		case AR_DESTROY_CRUISER:
			m_MyMap.ChangeStatusMap(pos, MAP_DESTROY);
			printf_s("CRUISER DESTROY\n");
			
			break;
		case AR_DESTROY_DESTROYER:
			m_MyMap.ChangeStatusMap(pos, MAP_DESTROY);
			printf_s("DESTROYER DESTROY\n");
			break;
		default:
			break;
		}

		//miss가 아닌 경우 바로 리턴
		if (result != AR_MISS)
		{
			return result;
		}
	}

	//반복문을 빠져 나오면 miss인 경우임
	printf_s("MISS\n");
	m_MyMap.ChangeStatusMap(pos, ATTACK);
	return AR_MISS;
}
Exemple #20
0
 void operator() (Aircraft& aircraft, sf::Time) const
 {
   aircraft.accelerate(velocity);
 }
Exemple #21
0
int main(void)
{
   sg::PWorld world;
   sg::PWorldInterface wi;
   sg::PWorldInterface wi2;
    
   try
   {
      world = abidos::load_world( "FooWorld", "/home/thomas.cocagne/devel/stargate/test_world.wdf" );

      wi = abidos::createWorldInterface( "test_iface", world );

      wi2 = abidos::createWorldInterface( "test_iface2", world );

      if (!wi || !wi2)
      {
         cerr << "Failed to create world interface!!!" << endl;
         return 0;
      }
   } 
   catch (abidos::LoadError & e)
   {
      cerr << "Failed to load world!: " << e.what() << endl;
      return 0;
   }

//    return 0;
    
   cerr << "************ World Types *************" << endl;
    
   world->printTypes();
    
   cerr << "**************************************" << endl;
    
    
   //PhysicalEntityObject po = wi->createObject<PhysicalEntityObject>();

   wi2->setNewObjectHandler( PhysicalEntity::ID, test_cb );
   
   wi2->setNewObjectHandler< VehicleObject >( test2_cb );
   
   cerr << " %% Running Callbacks (should be empty) %% " << endl;
   
   wi2->runCallbacks();
   
   AircraftObject po = wi->createObject<AircraftObject>();
    
   cerr << "******* object created ********" << endl;

   cerr << "FQ Latitude: " << po.getInstance().loc().pos().longitude() << endl;
    
   PhysicalEntity pe = po.getInstance();
    
   cerr << "Got Instance" << endl;
    
   Location l = pe.loc();
    
   cerr << "Got Location" << endl;
    
   Position p = l.pos();
    
   cerr << "Got Position" << endl;
    
   cerr << "Lat, lon, alt = " << p.latitude() << ", " << p.longitude() << ", " << p.altitude() << endl;
    
   p.latitude( 3.14159 );
        
   cerr << "Lat, lon, alt = " << p.latitude() << ", " << p.longitude() << ", " << p.altitude() << endl;

   // String test
   Aircraft a = po.getInstance();

   cerr << "Callsign: " << (const char *) (a.callsign()->data()) << endl;

   a.callsign( "Foo Bar" );

   cerr << "Callsign: " << (const char *) (a.callsign()->data()) << endl;

   cerr << " %% Running Callbacks (should see 1) %% " << endl;
   wi2->runCallbacks();
    
   return 0;
}
Exemple #22
0
	void operator() (Aircraft& aircraft, sf::Time) const
	{
		aircraft.accelerate(velocity * aircraft.getMaxSpeed());
	}
void TestAircraft::menuItemCallback(CCObject* menuItem)
{
	CCMenuItemLabel* menuItemLabel = dynamic_cast<CCMenuItemLabel*>(menuItem);

	CCSize screenSize = CCDirector::sharedDirector()->getWinSize();

	if(menuItemLabel)
	{
		CCLabelTTF* label = dynamic_cast<CCLabelTTF*>(menuItemLabel->getLabel());

		if(!label)
			return;

		string labelString = label->getString();

		if(labelString == "straight")
		{
			// straight
			{
				Aircraft* enemy = Aircraft::createEnemyStraight();
				addChild(enemy);
				enemy->setPosition(screenSize.width/2, screenSize.height/2 + 150);
			}
		}
		else if(labelString == "omni")
		{
			// enemy omni
			{
				Aircraft* omni = Aircraft::createEnemyOmni();
				addChild(omni);
				omni->setPosition(screenSize.width/2, screenSize.height/2 + 150);
			}
		}
		else if(labelString == "ray gun")
		{
			// ray gun
			{
				Aircraft* enemy = Aircraft::createEnemyRayGun();
				addChild(enemy);
				enemy->setPosition(screenSize.width/2, screenSize.height/2 + 150);
			}
		}
		else if(labelString == "tank")
		{
			// tank
			{
				Aircraft* enemy = Aircraft::createEnemyTank();
				addChild(enemy);
				enemy->setPosition(screenSize.width/2, screenSize.height/2 + 150);
			}
		}

		else if(labelString == "boss00")
		{

			// enemy boss
			Aircraft* boss = Aircraft::createBoss00();
			addChild(boss);
			boss->setPosition(screenSize.width/2, screenSize.height/2 + 150);
		}

		else if(labelString == "boss01")
		{
			// boss 01
			{
				Aircraft* enemy = Aircraft::createBoss01();
				addChild(enemy);
				enemy->setPosition(screenSize.width/2, screenSize.height/2 + 150);
			}
		}

		else if(labelString == "hero")
		{
			Aircraft* hero = Aircraft::createHeroAircraft();
			addChild(hero);
			hero->setPosition(screenSize.width/2, screenSize.height/2);
			GameController::sharedInstance()->setPlayerAircraft(hero);
		}
	}
}
int main(void)
{
    Aircraft ac;
/*
    int p1[3] = {15, 50, 5};
    int v1[3] = {25, 1, 0};

    int p2[3] = {161, 102, 9};
    int v2[3] = {-10, -10, -1};
*/

    /*
    int p1[3] = {0, 0, 0};
    int v1[3] = {-2, 2, 0};

    int p2[3] = {9, 0, 5};
    int v2[3] = {2, 2, 0};
    int R = 5;
    */

    /*
    int p1[3] = {-2838,-7940,-2936};
    int v1[3] = {1, 1, -2};

    int p2[3] = {532,3850,9590};
    int v2[3] = {1, 0, -3};

    int R = 3410;
    */

    /*
    int p1[3] = {-7163,-371,-2459};
    int v1[3] = {-59,-41,-14};

    int p2[3] = {-2398,-426,-5487};
    int v2[3] = {-43,27,67};

    int R = 5410;
    */

    /*
    int p1[3] = {3731,8537,5661};
    int v1[3] = {-70,71,32};

    int p2[3] = {8701,-1886,-5115};
    int v2[3] = {28,-13,7};

    int R = 9766;
    */

    /*
    int p1[3] = {-8509,9560,345};
    int v1[3] = {-89,-33,62};

    int p2[3] = {-5185,-1417,2846};
    int v2[3] = {-58,24,26};

    int R = 8344;
    */

    /*
    int p1[3] = {0,0,0};
    int v1[3] = {1,0,0};

    int p2[3] = {0,0,1};
    int v2[3] = {0,1,0};

    int R = 1;
    */
/*
    int p1[3] = {0, 2856, -2856};
    int v1[3] = {98, -9996, 9996};

    int p2[3] = {10000, -2856, 2856};
    int v2[3] = {98, 9996, -9996};

    int R = 10000;
    */

    /*
    int p1[3] = {-8509, 9560, 345};
    int v1[3] = {-89, -33, 62};

    int p2[3] = {-5185, -1417, 2846};
    int v2[3] = {-58, 24, 26};
    int R = 8343;
    */
    // {{0, 1, -1}, {3, -3, 3}, {1, -1, 1}, {3, 3, -3}, 1}

    /*
    int p1[3] = {0, 1, -1};
    int v1[3] = {3, -3, 3};

    int p2[3] = {1, -1, 1};
    int v2[3] = {3, 3, -3};
    int R = 1;
    */

    // {{-7163, -371, -2459}, {-59, -41, -14}, {-2398, -426, -5487}, {-43, 27, 67}, 5410}

    /*
    int p1[3] = {-7163, -371, -2459};
    int v1[3] = {-59, -41, -14};

    int p2[3] = {-2398, -426, -5487};
    int v2[3] = {-43, 27, 67};
    int R = 5410;
    */
    // {{0, 2856, -2856}, {98, -9996, 9996}, {10000, -2856, 2856}, {98, 9996, -9996}, 10000}

    int p1[3] = {0, 2856, -2856};
    int v1[3] = {98, -9996, 9996};

    int p2[3] = {10000, -2856, 2856};
    int v2[3] = {98, 9996, -9996};
    int R = 10000;

    vector<int> p1vec;
    vector<int> p2vec;
    vector<int> v1vec;
    vector<int> v2vec;

    for (int i = 0; i < 3; i++) {
        p1vec.push_back(p1[i]);
        p2vec.push_back(p2[i]);
        v1vec.push_back(v1[i]);
        v2vec.push_back(v2[i]);
    }

    cout << ac.nearMiss(p1vec, v1vec, p2vec, v2vec, R) << endl;

    return 0;
}
// on "init" you need to initialize your instance
bool TestAircraft::init()
{
	if ( !CCLayer::init() )
	{
		return false;
	}

	// ------------
	// init input manager
	// ---------------
	InputManager* input = InputManager::sharedInstance();
	CCDirector::sharedDirector()->getKeypadDispatcher()->addDelegate(input);

	// -------------
	// init physics
	// -----------
	PhysicsManager::sharedInstance()->enableDebugDraw(true);
	GB2ShapeCache::sharedGB2ShapeCache()->addShapesWithFile("png/physics.plist");

	// step
	schedule(schedule_selector(TestAircraft::stepForPhysicsManager));

	// -----------------
	// Init Audio
	// ------------
	SimpleAudioEngine::sharedEngine()->preloadEffect("wav/exploStd.wav");

	// ------------
	// Hero Aircraft
	// -----------
	Aircraft* hero = Aircraft::createHeroAircraft();
	addChild(hero);

	CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
	hero->setPosition(screenSize.width/2, screenSize.height/2);

	GameController::sharedInstance()->setPlayerAircraft(hero);

	// ------------
	// create menu
	// -------------
	CCMenu* menu = CCMenu::create();

	// straight menu item
	{
		CCMenuItemFont* menuItem = CCMenuItemFont::create("straight", this, menu_selector(TestAircraft::menuItemCallback));
		menu->addChild(menuItem);
	}

	// omni 
	{
		CCMenuItemFont* menuItem = CCMenuItemFont::create("omni", this, menu_selector(TestAircraft::menuItemCallback));
		menu->addChild(menuItem);
	}

	// ray gun 
	{
		CCMenuItemFont* menuItem = CCMenuItemFont::create("ray gun", this, menu_selector(TestAircraft::menuItemCallback));
		menu->addChild(menuItem);
	}

	// tank
	{
		CCMenuItemFont* menuItem = CCMenuItemFont::create("tank", this, menu_selector(TestAircraft::menuItemCallback));
		menu->addChild(menuItem);
	}

	// boss00
	{
		CCMenuItemFont* menuItem = CCMenuItemFont::create("boss00", this, menu_selector(TestAircraft::menuItemCallback));
		menu->addChild(menuItem);
	}

	// boss01
	{
		CCMenuItemFont* menuItem = CCMenuItemFont::create("boss01", this, menu_selector(TestAircraft::menuItemCallback));
		menu->addChild(menuItem);
	}

	// hero
	{
		CCMenuItemFont* menuItem = CCMenuItemFont::create("hero", this, menu_selector(TestAircraft::menuItemCallback));
		menu->addChild(menuItem);
	}

	menu->alignItemsVertically();
	addChild(menu);

	menu->setPositionX(menu->getPositionX() + 200);



	return true;
}
Exemple #26
0
/**
 * Clean up a station by clearing vehicle orders, invalidating windows and
 * removing link stats.
 * Aircraft-Hangar orders need special treatment here, as the hangars are
 * actually part of a station (tiletype is STATION), but the order type
 * is OT_GOTO_DEPOT.
 */
Station::~Station()
{
	if (CleaningPool()) {
		for (CargoID c = 0; c < NUM_CARGO; c++) {
			this->goods[c].cargo.OnCleanPool();
		}
		return;
	}

	while (!this->loading_vehicles.empty()) {
		this->loading_vehicles.front()->LeaveStation();
	}

	Aircraft *a;
	FOR_ALL_AIRCRAFT(a) {
		if (!a->IsNormalAircraft()) continue;
		if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
	}

	for (CargoID c = 0; c < NUM_CARGO; ++c) {
		LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
		if (lg == NULL) continue;

		for (NodeID node = 0; node < lg->Size(); ++node) {
			Station *st = Station::Get((*lg)[node].Station());
			st->goods[c].flows.erase(this->index);
			if ((*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) {
				st->goods[c].flows.DeleteFlows(this->index);
				RerouteCargo(st, c, this->index, st->index);
			}
		}
		lg->RemoveNode(this->goods[c].node);
		if (lg->Size() == 0) {
			LinkGraphSchedule::instance.Unqueue(lg);
			delete lg;
		}
	}

	Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		/* Forget about this station if this station is removed */
		if (v->last_station_visited == this->index) {
			v->last_station_visited = INVALID_STATION;
		}
		if (v->last_loading_station == this->index) {
			v->last_loading_station = INVALID_STATION;
		}
	}

	/* Clear the persistent storage. */
	delete this->airport.psa;

	if (this->owner == OWNER_NONE) {
		/* Invalidate all in case of oil rigs. */
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
	} else {
		InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
	}

	if (Overlays::Instance()->HasStation(Station::Get(this->index))) {
		Overlays::Instance()->ToggleStation(Station::Get(this->index));
	};

	DeleteWindowById(WC_STATION_VIEW, index);

	/* Now delete all orders that go to the station */
	RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);

	/* Remove all news items */
	DeleteStationNews(this->index);

	for (CargoID c = 0; c < NUM_CARGO; c++) {
		this->goods[c].cargo.Truncate();
	}

	CargoPacket::InvalidateAllFrom(this->index);
}