Esempio n. 1
0
void Ship::setUnitAiNone ()
{
    assert(isUnitAiSet());
    
    delete unitAi;
    unitAi = NULL;
}
Esempio n. 2
0
void Ship :: update (WorldInterface& r_world)
{
    if (isUnitAiSet())
    {
        if (!desired_velocity.isZero())
        {
            double theta = max_rotation_rate * TimeSystem::getFrameDuration();
            if(theta > 0.0)
            {
                rotateTowards(desired_velocity.getNormalized(), theta);
            }
            
            double delta = max_acceleration * TimeSystem::getFrameDuration();
            if(delta > 0.0)
            {
                double currentSpeed = getSpeed();
                double desiredSpeed = desired_velocity.getNorm();
                
                if (currentSpeed < desiredSpeed)
                {
                    currentSpeed += delta;
                    if (currentSpeed > desiredSpeed) currentSpeed = desiredSpeed;
                    setSpeed(currentSpeed);
                }
                else if (currentSpeed > desiredSpeed)
                {
                    currentSpeed -= delta;
                    if (currentSpeed < desiredSpeed) currentSpeed = desiredSpeed;
                    setSpeed(currentSpeed);
                }
            }
        }
        
        if (wantsToFire && isReloaded())
        {
            r_world.addBullet(getPosition(), getForward(), getId());
            wantsToFire = false;
            markReloading();
        }
    }
    
	if(isAlive() && isDying())
	{
		r_world.addExplosion(getPositionPrevious(), getRadius() * EXPLOSION_SIZE_FACTOR, 0);
		m_is_dead = true;

		// no further updates
		assert(invariant());
		return;
	}

	if(isAlive())
	{
		updateBasic();  // moves the Ship

		m_reload_timer += TimeSystem::getFrameDuration();
	}

	assert(invariant());
}
Esempio n. 3
0
void Ship::update(WorldInterface& world)
{
	if (m_health <= 0 && m_status == dying){
		m_status = dead;
		world.addExplosion(getPositionPrevious(), EXPLOSION_SIZE, 0);
	}

	if (m_status == alive){
		if (isUnitAiSet()){
			double duration = TimeSystem::getFrameDuration();
			m_coordinate.rotateToVector(m_desired_velocity, duration*m_rotation_rate);
			changeSpeed(m_desired_velocity.getNorm(), duration*m_acceleration);
			if (m_fire_bullet_desired && isBulletReady()){
				world.addBullet(getPosition(), m_coordinate.getForward(), m_id);
				m_fire_bullet_desired = false;
				reloadBullet();
			}
		}
		updateBasic();
		m_reloadTimer.update();
	}


	else if (m_health > 0 && m_status == dead){
		m_status = alive;
		Vector3 position = m_coordinate.getPosition();
		position -= 500 * m_coordinate.getForward();
		m_coordinate.setPosition(position);
	}
}
Esempio n. 4
0
Ship& Ship :: operator= (const Ship& original)
{
	if(&original != this)
	{
		PhysicsObject::operator=(original);

		m_health       = original.m_health;
		m_reload_timer = original.m_reload_timer;
		m_ammo         = original.m_ammo;
		m_is_dead      = original.m_is_dead;
        
        if (isUnitAiSet()) delete unitAi;
        unitAi         = original.unitAi;
	}

	assert(invariant());
	return *this;
}
Esempio n. 5
0
void Ship::setUnitAi (UnitAiSuperclass* p_unit_ai)
{
    if (isUnitAiSet()) delete unitAi;
    unitAi = p_unit_ai;
}
Esempio n. 6
0
void Ship::runAi (const WorldInterface& world)
{
    assert (isUnitAiSet());
    
    unitAi->run(world);
}