当前位置: 首页>>代码示例>>C++>>正文


C++ WorldInterface类代码示例

本文整理汇总了C++中WorldInterface的典型用法代码示例。如果您正苦于以下问题:C++ WorldInterface类的具体用法?C++ WorldInterface怎么用?C++ WorldInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WorldInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: avoidShips

Vector3 UnitAiMoonGuard::avoidShips(const WorldInterface& world, const Vector3& originalVelocity)
{
    Vector3 agentPosition = getShip().getPosition();
    vector<PhysicsObjectId> shipIDs = world.getShipIds(agentPosition, SAFE_DISTANCE);
    unsigned int amount = shipIDs.size();

    if (amount == 1) {
        return originalVelocity;
    }

    PhysicsObjectId closestID = PhysicsObjectId::ID_NOTHING;
    double closestDistance = -1;
    PhysicsObjectId agentID = getShip().getId();
    for (unsigned int i = 0; i < amount; i++) {
        PhysicsObjectId shipID = shipIDs[i];
        if (agentID != shipID) {
            Vector3 shipPosition = world.getPosition(shipIDs[i]);
            double distance = agentPosition.getDistanceSquared(shipPosition);
            if (closestDistance < 0) {
                closestDistance = distance;
                closestID = shipIDs[i];
            }
            else if (distance <= closestDistance) {
                closestDistance = distance;
                closestID = shipIDs[i];
            }
        }
    }
    if (closestDistance == -1) {
        return originalVelocity;
    }
    return 	m_steering_behaviour.evade(world, closestID);
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:33,代码来源:StemCellUnitAi.cpp

示例2: run

void UnitAiMoonGuard :: run (const WorldInterface& world)
{
    assert(world.isAlive(getShipId()));

    scan(world);

    Vector3 v = getShip().getVelocity();
    if (nearestEnemyShip != PhysicsObjectId::ID_NOTHING)
    {
        v = chargeAtTarget(world, nearestEnemyShip, v);
        shootAtShip(world, nearestEnemyShip);
    }
    else
    {
        Vector3 moon_pos = world.getPosition(moon);
        double moon_radius = world.getRadius(moon);
        v = steeringBehaviour->patrolSphere(world,
                                            moon_pos,
                                            moon_radius,
                                            PLANETOID_AVOID_DISTANCE);
        //printf("Patrolling...\n");
    }
    v = avoidShips(world, v);
    v = avoidRingParticles(world, v);

    getShipAi().setDesiredVelocity(v);
}
开发者ID:streibeb,项目名称:cs409,代码行数:27,代码来源:SpaceMongolsUnitAi.cpp

示例3: update

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);
	}
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:30,代码来源:Ship.cpp

示例4: chooseTarget

void UnitAiMoonGuard::chooseTarget(const WorldInterface& world)
{
    const Vector3& ship_position = getShip().getPosition();
    const Vector3& ship_forward = getShip().getForward();
    unsigned int   ship_fleet = getShipId().m_fleet;

    vector<PhysicsObjectId> v_ids = world.getShipIds(ship_position, SCAN_RADIUS);

    m_id_target = PhysicsObjectId::ID_NOTHING;
    double best_angle = VERY_LARGE_ANGLE;

    for (unsigned int i = 0; i < v_ids.size(); i++)
    {
        PhysicsObjectId other_id = v_ids[i];

        if (other_id.m_fleet != ship_fleet)
        {
            // we found an enemy ship

            Vector3 other_position = world.getPosition(other_id);
            Vector3 direction_to_other = other_position - ship_position;
            double angle_to_other = direction_to_other.getAngleSafe(ship_forward);

            if (angle_to_other < best_angle)
            {
                m_id_target = other_id;
                best_angle = angle_to_other;
            }
        }
        // else ship is part of our fleet, so ignore it
    }
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:32,代码来源:StemCellUnitAi.cpp

示例5: update

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());
}
开发者ID:streibeb,项目名称:cs409,代码行数:60,代码来源:Ship.cpp

示例6: getShip

Vector3 UnitAiMoonGuard::avoidParticles(const WorldInterface& world, const Vector3& originalVelocity) {
    Vector3 agentPosition = getShip().getPosition();
    if (world.getRingDensity(agentPosition) <= 0) {
        return originalVelocity;
    }
    vector<WorldInterface::RingParticleData> particles = world.getRingParticles(agentPosition, SAFE_DISTANCE);
    unsigned int amount = particles.size();
    if (amount == 0) {
        return originalVelocity;
    }

    WorldInterface::RingParticleData cloestParticle = particles[0];
    double closestDistance = cloestParticle.m_position.getDistanceSquared(agentPosition);
    for (unsigned int i = 1; i < amount; i++) {
        WorldInterface::RingParticleData particle = particles[i];
        double distance = particle.m_position.getDistanceSquared(agentPosition);
        if (distance < closestDistance) {
            cloestParticle = particle;
            closestDistance = distance;
        }
    }

    Vector3 avoidVelocity = m_steering_behaviour.avoid(world, avoidVelocity,
                            cloestParticle.m_position,
                            cloestParticle.m_radius,
                            cloestParticle.m_radius,
                            SAFE_DISTANCE);
    double speed = getShip().getSpeedMax() / amount * SAFE_DISTANCE / 100;

    return avoidVelocity.getCopyWithNorm(speed);
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:31,代码来源:StemCellUnitAi.cpp

示例7: UnitAiSuperclass

UnitAiMoonGuard::UnitAiMoonGuard(const AiShipReference& ship,
                                 const WorldInterface& world,
                                 const PhysicsObjectId& id_moon)
    : UnitAiSuperclass(ship), m_id_target(PhysicsObjectId::ID_NOTHING),
      m_steering_behaviour(ship.getId()), m_scan_counter(0),
      m_moon_id(id_moon), mp_world(&world)
{
    assert(ship.isShip());
    assert(id_moon.m_type == PhysicsObjectId::TYPE_PLANETOID);
    assert(world.isAlive(id_moon));
    assert(world.isPlanetoidMoon(id_moon));
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:12,代码来源:StemCellUnitAi.cpp

示例8: patrolMoon

void UnitAiMoonGuard::patrolMoon(const WorldInterface& world, const PhysicsObjectId& moonID)
{
    Vector3         planetoid_center = world.getPosition(moonID);
    double          planetoid_radius = world.getRadius(moonID);
    Vector3 desired_velocity = m_steering_behaviour.patrolSphere(world, planetoid_center,
                               planetoid_radius + PLANETOID_CLEARANCE,
                               planetoid_radius + Const::SHELL_THICKNESS);
    Vector3 avoid_velocity = avoidPlanets(world, desired_velocity);
    avoid_velocity = avoidParticles(world, avoid_velocity);
    avoid_velocity = avoidShips(world, avoid_velocity);
    getShipAi().setDesiredVelocity(avoid_velocity);
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:12,代码来源:StemCellUnitAi.cpp

示例9: avoidPlanets

Vector3 UnitAiMoonGuard::avoidPlanets(const WorldInterface& world, const Vector3& originalVelocity)
{
    PhysicsObjectId planetoid_id = world.getNearestPlanetoidId(getShip().getPosition());
    Vector3         planetoid_center = world.getPosition(planetoid_id);
    double          planetoid_radius = world.getRadius(planetoid_id);
    return m_steering_behaviour.avoid(world,
                                      originalVelocity,
                                      planetoid_center,
                                      planetoid_radius,
                                      PLANETOID_CLEARANCE,
                                      PLANETOID_AVOID_DISTANCE);
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:12,代码来源:StemCellUnitAi.cpp

示例10: avoidPlanetoids

Vector3 UnitAiMoonGuard::avoidPlanetoids(const WorldInterface &world, const Vector3& orig_velocity)
{
    Vector3 planetoid_pos = world.getPosition(nearestPlanetoid);
    double planetoid_radius = world.getRadius(nearestPlanetoid);

    Vector3 v = steeringBehaviour->avoid(world,
                                         orig_velocity,
                                         planetoid_pos,
                                         planetoid_radius,
                                         PLANETOID_CLEARANCE,
                                         PLANETOID_AVOID_DISTANCE);
    //printf("Avoiding Planetoid\n");
    return v;
}
开发者ID:streibeb,项目名称:cs409,代码行数:14,代码来源:SpaceMongolsUnitAi.cpp

示例11: UnitAiMoonGuard

UnitAiMoonGuard :: UnitAiMoonGuard (const AiShipReference& ship,
                                    const WorldInterface& world,
                                    const PhysicsObjectId& id_moon)
    : UnitAiSuperclass(ship)
{
    assert(ship.isShip());
    assert(id_moon.m_type == PhysicsObjectId::TYPE_PLANETOID);
    assert(world.isAlive(id_moon));
    assert(world.isPlanetoidMoon(id_moon));

    steeringBehaviour = new FleetName::SteeringBehaviour(ship.getId());
    moon = id_moon;
    scanCount = rand() % SCAN_COUNT_MAX;

}
开发者ID:streibeb,项目名称:cs409,代码行数:15,代码来源:SpaceMongolsUnitAi.cpp

示例12: run

void UnitAiMoonGuard::run(const WorldInterface& world)
{
    assert(world.isAlive(getShipId()));

    //
    //  Scan for enemies evey few frames.  We use a counter to
    //    know which frames to scan on.
    //

    m_scan_counter++;
    if (m_scan_counter >= SCAN_COUNT_MAX)
    {
        chooseTarget(world);
        m_scan_counter = 0;
    }

    //
    //  Check to make sure the target is still alive.  If we
    //    didn't scan this frame, it might have died since we
    //    last checked.
    //

    if (m_id_target != PhysicsObjectId::ID_NOTHING &&
            !world.isAlive(m_id_target))
    {
        // give up on dead target
        m_id_target = PhysicsObjectId::ID_NOTHING;
    }

    //
    //  If we have a target, shoot at it!  Otherwise, just stop and
    //    wait.  If we don't move while there is no target, we
    //    can't hit anything, so we won't die.
    //

    if (m_id_target != PhysicsObjectId::ID_NOTHING)
    {
        // if we have a living target
        assert(world.isAlive(m_id_target));

        steerToTargetAndShoot(world);
    }
    else
    {
        patrolMoon(world, m_moon_id);
    }
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:47,代码来源:StemCellUnitAi.cpp

示例13: shootAtShip

void UnitAiMoonGuard::shootAtShip(const WorldInterface& world, const PhysicsObjectId& target)
{
    if (!world.isAlive(target)) return;

    Vector3 target_pos = world.getPosition(target);
    Vector3 target_vel = world.getVelocity(target);

    Vector3 aim_dir = steeringBehaviour->getAimDirection(getShip().getPosition(),
                      Bullet::SPEED,
                      target_pos,
                      target_vel);
    double angle = getShip().getVelocity().getAngleSafe(aim_dir);
    if (angle <= SHOOT_ANGLE_RADIANS_MAX && getShip().isReloaded())
    {
        getShipAi().markFireBulletDesired();
        //printf("\tShooting at (%f, %f, %f)\n", target_pos.x, target_pos.y, target_pos.z);
    };
}
开发者ID:streibeb,项目名称:cs409,代码行数:18,代码来源:SpaceMongolsUnitAi.cpp

示例14: flee

Vector3 SteeringBehaviour :: flee (const WorldInterface& world,
                                   const PhysicsObjectId& id_target)
{
	assert(id_target != PhysicsObjectId::ID_NOTHING);

	// no initialization needed
	m_steering_behaviour = FLEE;

	if(!world.isAlive(id_target))
	{
		assert(invariant());
		return Vector3::ZERO;
	}

	assert(world.isAlive(id_target));
	Vector3 result = flee(world, world.getPosition(id_target));
	assert(invariant());
	return result;
}
开发者ID:streibeb,项目名称:cs409,代码行数:19,代码来源:RedSteeringBehaviours.cpp

示例15: steerToTargetAndShoot

void UnitAiMoonGuard::steerToTargetAndShoot(const WorldInterface& world)
{
    assert(m_id_target != PhysicsObjectId::ID_NOTHING);
    assert(world.isAlive(m_id_target));

    Vector3 agent = getShip().getPosition();
    Vector3 agent_velocity = world.getVelocity(getShip().getId());

    Vector3 target = world.getPosition(m_id_target);
    Vector3 target_velocity = world.getVelocity(m_id_target);

    Vector3 desired_velocity;
    double agent_max_speed = world.getShipSpeedMax(getShip().getId());
    double fromAgentToTarget = agent.getAngle(target);
    double fromAgentToTargetFront = agent.getAngle(target + target_velocity);

    if (fromAgentToTargetFront < fromAgentToTarget) {
        desired_velocity = m_steering_behaviour.seek(world, m_id_target);
    }
    else {
        desired_velocity = m_steering_behaviour.getAimDirection(agent, Bullet::SPEED,
                           target, target_velocity);
        if (desired_velocity == Vector3::ZERO) {
            desired_velocity = m_steering_behaviour.pursue(world, m_id_target);
        }
        else {
            desired_velocity.setNorm(agent_max_speed);
        }
    }

    Vector3 avoid_velocity = avoidPlanets(world, desired_velocity);
    avoid_velocity = avoidParticles(world, avoid_velocity);
    avoid_velocity = avoidShips(world, avoid_velocity);
    getShipAi().setDesiredVelocity(avoid_velocity);

    double angle = agent_velocity.getAngle(desired_velocity);
    double distance = target.getDistanceSquared(agent);

    if (angle <= SHOOT_ANGLE_RADIANS_MAX && distance < FIRE_RANGE)
    {
        getShipAi().markFireBulletDesired();
    }
}
开发者ID:whitelight2134,项目名称:spacewar,代码行数:43,代码来源:StemCellUnitAi.cpp


注:本文中的WorldInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。