// if you pass in -1's for x and y, we'll figure out where it can go, and return where it went
int LogisticsVariant::canAddComponent( LogisticsComponent* pComponent, long& x, long& y ) const
{
	/*  weight no longer matters
	int weight = getWeight();
	if ( weight + pComponent->getWeight() > chassis->maxWeight )
		return COMPONENT_TOO_HEAVY;*/

	if ( getHeat() + pComponent->getHeat() > getMaxHeat() )
		return COMPONENT_TOO_HOT;

	if ( pComponent->getType() == COMPONENT_FORM_JUMPJET  )
	{
		if ( !chassis->canHaveJumpJets )
			return JUMPJETS_NOT_ALLOWED;
		else if ( hasJumpJets() )
			return ONLY_ONE_JUMPJET_ALLOWED;
		else if ( ( x!= -1 && x != -2)
					|| ( y != -1 && y != -2 ) )
			return COMPONENT_SLOT_FULL;

		return 0;
	}
	else if ( x == -2 && y == -2 ) // trying to put something illegal in jump jet slot
		return COMPONENT_SLOT_FULL;
		 

	if ( x!= -1 && y != -1 )
	{
		for ( int i = 0; i < pComponent->getComponentWidth(); i++ )
		{
			for ( int j = 0; j < pComponent->getComponentHeight(); j++ )
			{
				if ( getComponentAtLocation( x + i, y  + j)
					|| x + i >= chassis->componentAreaWidth
					|| j + y >= chassis->componentAreaHeight )
					return COMPONENT_SLOT_FULL;
			}  
		}
	}
	else
	{
		for ( int j = 0; j < chassis->componentAreaHeight && x == -1; j++ )
		{
			for ( int i = 0; i < chassis->componentAreaWidth && x == -1; i++ )
			{
				if ( !getComponentAtLocation( i, j ) )
				{
					bool bAdd = true;
					for ( int l = 0; l < pComponent->getComponentHeight(); ++l )
					{
						for ( int k =0; k < pComponent->getComponentWidth(); ++k )
						{

 							if ( getComponentAtLocation( i +k, j + l ) 
								|| ( i + k >= chassis->componentAreaWidth )
								|| ( j +l >= chassis->componentAreaHeight ) )
							{
								bAdd = false;
								break;
								break;
							}
						}
					}

					if ( bAdd )
					{
						x = i;
						y = j;
			
					}
				}

				
			}
		}

		if ( x == -1 || y == -1 )
		{
			return ADD_COMPONENT_FAILED;
		}
	}

	if ( pComponent->getType() == COMPONENT_FORM_BULK )
	{
		if ( getArmor() + 32 > getMaxArmor() )
			return NO_MORE_ARMOR;
	}

	if ( pComponent->getType() == COMPONENT_FORM_SENSOR )
	{
		if ( !chassis->canHaveAdvSensor )
			return SENSORS_NOT_ALLOWED;
		else if ( hasSensor() )
			return ONLY_ONE_SENSOR_ALLOWED;
	}

	if ( pComponent->getType() == COMPONENT_FORM_ECM  )
	{
		if ( !chassis->canHaveECM )
			return ECM_NOT_ALLOWED;
		else if ( hasECM() )
			return ONLY_ONE_ECM_ALLOWED;
	}

	

	return 0;

}
Пример #2
0
void SensorBrowserModel::answerReceived( int hostId,  const QList<QByteArray>&answer )
{
    /* An answer has the following example format:

       cpu/system/idle integer
       cpu/system/sys  integer
       cpu/system/nice integer
       cpu/system/user integer
       ps       table
       */
    HostInfo *hostInfo = getHostInfo(hostId);
    if(!hostInfo) {
        kDebug(1215) << "Invalid hostId " << hostId ;
        return;
    }
    /* We keep a copy of the previous sensor names so that we can detect what sensors have been removed */
    QHash<QString,bool> oldSensorNames = mHostSensorsMap.value(hostId);
    for ( int i = 0; i < answer.count(); ++i ) {
        if ( answer[ i ].isEmpty() )
            continue;

        QList<QByteArray> words = answer[ i ].split('\t');
        if(words.size() != 2) {
            kDebug(1215) << "Invalid data " << answer[i];
            continue;  /* Something wrong with this line of data */
        }
        QString sensorName = QString::fromUtf8(words[ 0 ]);
        QString sensorType = QString::fromUtf8(words[ 1 ]);
        oldSensorNames.remove(sensorName);  /* This sensor has not been removed */
        if ( hasSensor(hostId, sensorName)) {
            continue;
        }
        if(sensorName.isEmpty()) continue;

        if(sensorType == "string") continue;

        /* The sensor browser can display sensors in a hierarchical order.
         * Sensors can be grouped into nodes by seperating the hierarchical
         * nodes through slashes in the sensor name. E. g. cpu/system/user is
         * the sensor user in the cpu node. There is no limit for the
         * depth of nodes. */
        int currentNodeId = hostId;  //Start from the host branch and work our way down the tree
        QStringList absolutePath = sensorName.split( '/' );
        for ( int j = 0; j < absolutePath.count()-1; ++j ) {
            // Localize the sensor name part by part.
            QString name = KSGRD::SensorMgr->translateSensorPath( absolutePath[ j ] );
            currentNodeId = makeTreeBranch(currentNodeId, name);
        }
        QString name = KSGRD::SensorMgr->translateSensorPath( absolutePath[ absolutePath.size()-1] );
        makeSensor(hostInfo, currentNodeId, sensorName, name, sensorType);
    }
    /* Now we have to remove sensors that were not found */
    QHashIterator<QString, bool> it( oldSensorNames );
    while ( it.hasNext() ) {
        it.next();

        int currentNodeId = hostId;  //Start from the host branch and work our way down the tree
        QStringList absolutePath = it.key().split( '/' );
        for ( int j = 0; j < absolutePath.count()-1; ++j ) {
            // Localize the sensor name part by part.
            QString name = KSGRD::SensorMgr->translateSensorPath( absolutePath[ j ] );
            currentNodeId = makeTreeBranch(currentNodeId, name);
        }
        removeSensor(hostInfo, currentNodeId, it.key());
    }
    emit sensorsAddedToHost( createIndex( mHostInfoMap.keys().indexOf(hostId), 0, hostId ) );
}