Exemple #1
0
void Satellite::findNeighbours()
{
    double rangeLimit = 0;
    unsigned int neighbourCount = _settings->satelliteNeighbourhoodSize();
    bool isNeighbourhoodFull;
    
    double range;
    double rangeTmp;
    
    _neighbours.clear();
    
//    std::cout << "Finding Neighbours!!" << std::endl;
    for(auto &sat : *_swarm){
        
        // Ignore ourselves
        if(sat->getID() == getID()) continue;
        
        isNeighbourhoodFull = (_neighbours.size() >= neighbourCount);
        range = rangeToTarget(sat);
        
        if( isNeighbourhoodFull) {
            if(range > rangeLimit) continue; 
        }
        else {
            // Expand to accept considered satellites
            if (range > rangeLimit) 
                rangeLimit = range;
        }
        
        if( _neighbours.size() == 0 ){
            _neighbours.push_back(sat);
        } else {
            // Loop over current neighbours and insert where appropriate
            for( unsigned int idx = _neighbours.size(); idx > 0; idx-- ){
                rangeTmp = rangeToTarget(_neighbours[idx-1]);
                if(range > rangeTmp ){            
                    _neighbours.insert(_neighbours.begin()+idx, sat);
                    break;              
                } else if (idx == 1) {            
                    _neighbours.insert(_neighbours.begin(), sat);
                    break; 
                } 
            }
        }
//        std::cout << "Checking Neighbours size!!" << std::endl;
        if (_neighbours.size() > neighbourCount){
            rangeLimit = rangeToTarget((_neighbours[neighbourCount-1]));
            _neighbours.resize(neighbourCount);
        }
    }
}
bool TargetManager::StartTargeting(SystemEntity *who, double lockTime, uint32 maxLockedTargets, double maxTargetLockRange)
{
    //first make sure they are not already in the list
    std::map<SystemEntity *, TargetEntry *>::iterator res;
    res = m_targets.find(who);
    if(res != m_targets.end()) {
        //what to do?
        _log(TARGET__TRACE, "Told to start targeting %u, but we are already processing them. Ignoring request.", who->GetID());
        return false;
    }

    //Check that they aren't targeting themselves
    if(who == m_self)
        return false;

    // Check against max locked target count
    if( m_targets.size() >= maxLockedTargets )
        return false;

    // Check against max locked target range
    GVector rangeToTarget( who->GetPosition(), m_self->GetPosition() );
    if( rangeToTarget.length() > maxTargetLockRange )
        return false;

    TargetEntry *te = new TargetEntry(who);
    te->state = TargetEntry::Locking;
	te->timer.Start(lockTime);
	m_targets[who] = te;

    _log(TARGET__TRACE, "%u started targeting %u (%u ms lock time)", m_self->GetID(), who->GetID(), lockTime);
    return true;
}
Exemple #3
0
Satellite::RangeStats Satellite::getRangeStats()
{
    RangeStats stats;
    State nstate;
    
    for (auto &neighbour: _neighbours) {
        stats.ranges.push_back(rangeToTarget(neighbour));
        nstate = neighbour->getState();
        stats.minp = stats.minp.leastOf(nstate.position);
        stats.maxp = stats.maxp.greatestOf(nstate.position);
    }
        
    for (auto r : stats.ranges){
        stats.max = (stats.max < r) ? r : stats.max;
        stats.min = (stats.min > r) ? r : stats.min;
        stats.total += r;
        stats.avg += (r / _neighbours.size());
    }

    for (auto r : stats.ranges)
        stats.std += pow(r - stats.avg, 2);

    stats.std = pow(stats.std / stats.ranges.size(), 0.5);

    return stats;
}
bool TargetManager::StartTargeting(SystemEntity *who, ShipRef ship) {   // needs another argument: "ShipRef ship" to access ship attributes
    //first make sure they are not already in the list
    std::map<SystemEntity *, TargetEntry *>::iterator res;
    res = m_targets.find(who);
    if(res != m_targets.end()) {
        //what to do?
        _log(TARGET__TRACE, "Told to start targeting %u, but we are already processing them. Ignoring request.", who->GetID());
        return false;
    }

    //Check that they aren't targeting themselves
    if(who == m_self)
        return false;

	// Calculate Time to Lock target:
	uint32 lockTime = TimeToLock( ship, who );

    // Check against max locked target count
	uint32 maxLockedTargets = ship->GetAttribute(AttrMaxLockedTargets).get_int();
    if( m_targets.size() >= maxLockedTargets )
        return false;

    // Check against max locked target range
	double maxTargetLockRange = ship->GetAttribute(AttrMaxTargetRange).get_float();
    GVector rangeToTarget( who->GetPosition(), m_self->GetPosition() );
    if( rangeToTarget.length() > maxTargetLockRange )
        return false;

    TargetEntry *te = new TargetEntry(who);
    te->state = TargetEntry::Locking;
    te->timer.Start(lockTime);
	m_targets[who] = te;

    _log(TARGET__TRACE, "%u started targeting %u (%u ms lock time)", m_self->GetID(), who->GetID(), lockTime);
    return true;
}