void Career::equipGear(unsigned int id)
{
    assert( id>=0 && id<_gears.size() );
    Gear temp;
    switch( _gears[id].type )
    {
    case gtHelmet:
        temp = _virtues.equipment.helmet;
        _virtues.equipment.helmet = _gears[id];
        break;
    case gtSuit:
        temp = _virtues.equipment.suit;
        _virtues.equipment.suit = _gears[id];
        break;
    case gtRig:
        temp = _virtues.equipment.rig;
        _virtues.equipment.rig = _gears[id];
        break;
    case gtCanopy:
        temp = _virtues.equipment.canopy;
        _virtues.equipment.canopy = _gears[id];
        break;
    case gtReserve:
        temp = _virtues.equipment.reserve;
        _virtues.equipment.reserve = _gears[id];
        break;
    default:
        assert( !"shouldn't be here!" );
    }
    removeGear( id );
    if( temp.type != gtUnequipped ) addGear( temp );
}
Exemple #2
0
void SchemaEditor::dropEvent(QDropEvent* event)
{
  QString text;
  
  if ( Q3TextDrag::decode(event, text) )
  {
    event->accept(true);
    addGear(text.toStdString(), event->pos().x(), event->pos().y());
  }
}
Exemple #3
0
bool Schema::load(QDomElement& parent, bool pasting, int dx, int dy)
{    
  std::vector<Gear*> addedGears;
  QDomNode gearsNode = XMLHelper::findChildNode(parent, "Gears");
  // when pasting, gears have to be renamed
  std::map<std::string,std::string> renameMap;
  if (gearsNode.isNull())
  {
    std::cout << "Bad DroneSchema : <Gears> tag not found!" << std::endl;
    return false;
  }

  QDomNode gearNode = gearsNode.firstChild();
  Gear *pgear=NULL;
  while (!gearNode.isNull())
  {
    QDomElement gearElem = gearNode.toElement();
    if (!gearElem.isNull())
    {
      std::string type = gearElem.attribute("Type","").ascii();
      
      if (type == MetaGear::TYPE)        
        //we default the name to metagear, but the name will be overwrited in the load of the metagear itself
        pgear = addMetaGear("MetaGear", gearElem.attribute("Name","").ascii());          
      else                   
        pgear = addGear(type, gearElem.attribute("Name","").ascii());
      
      if (pgear!=NULL)
      {
        pgear->load(gearElem);                                
      }              
                  
      addedGears.push_back(pgear);

    }
    gearNode = gearNode.nextSibling();
  }                
  
  if(pasting)
    for(unsigned int i=0;i<addedGears.size();++i)
    {
      addedGears[i]->getGearGui()->setSelected(true);
      std::string newname = getUniqueGearName(addedGears[i]->type());
      renameMap[addedGears[i]->name()] = getUniqueGearName(addedGears[i]->type());
      std::cerr<<"rename : "<<addedGears[i]->name()<<" to "<<renameMap[addedGears[i]->name()]<<" (newname:) "<<newname<<std::endl;

      addedGears[i]->name(renameMap[addedGears[i]->name()]);
    }
    
  //load connections    
  QDomNode connectionsNode = XMLHelper::findChildNode(parent, "Connections");

  if (connectionsNode.isNull())
  {
    std::cout << "Bad DroneSchema : <Connections> tag not found!" << std::endl;
    return false;
  }

  //iteration on all connections
  QDomNode connectionNode = connectionsNode.firstChild();
  Connection connection;
  while (!connectionNode.isNull())
  {
    QDomElement connectionElem = connectionNode.toElement();

    if (!connectionElem.isNull())
    {
      connection.load(connectionElem);            
      if(pasting)
        connection.updateWithRenameMapping(renameMap);
      connect(connection);
    }

    connectionNode = connectionNode.nextSibling();
  }               
  
  return true;
}
Exemple #4
0
Gear* Schema::addGear(std::string geartype)
{
  return addGear(geartype, getUniqueGearName(geartype));
}
Career::Career(TiXmlElement* node)
{
    assert( strcmp( node->Value(), "career" ) == 0 );

    _name = node->Attribute( "name" );

    _isHomeDefined = false;
    _homeX = _homeY = 0;
    _eventCallback = NULL;
    _eventCallbackData = NULL;

    TiXmlNode* child = node->FirstChild(); assert( child );
    if( child != NULL ) do 
    {
        if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "virtues" ) == 0 )
        {
            int cs;
            static_cast<TiXmlElement*>( child )->Attribute( "checksum", &cs );
            std::string data = static_cast<TiXmlElement*>( child )->Attribute( "data" );
			if (!decrypt( &_virtues, sizeof(Virtues), data, _name.c_str() )) {

				VirtuesLegacy virtuesL;
				decrypt( &virtuesL, sizeof(VirtuesLegacy), data, _name.c_str() );
				
				_virtues.loadLegacy(virtuesL);
				//Virtues *a = NULL;a->appearance.face = 1;
			}
            if( cs != checksum( &_virtues, sizeof(Virtues) ) )
            {
                throw ccor::Exception( "User database entry corrupted: \"%s\"! Cheating not allowed!", _name.c_str() );
            }
        }
        else if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "gears" ) == 0 )
        {
            TiXmlNode* gearNode = child->FirstChild();
            if( gearNode ) do
            {
                assert( gearNode->Type() == TiXmlNode::ELEMENT && strcmp( gearNode->Value(), "gear" ) == 0 );
                int cs;
                static_cast<TiXmlElement*>( gearNode )->Attribute( "checksum", &cs );
                std::string data = static_cast<TiXmlElement*>( gearNode )->Attribute( "data" );
                Gear gear;
                decrypt( &gear, sizeof(Gear), data, _name.c_str() );
                if( cs != checksum( &gear, sizeof(Gear) ) )
                {
                    throw ccor::Exception( "User database entry corrupted: \"%s\"! Cheating not allowed!", _name.c_str() );
                }
                addGear( gear );
                gearNode = gearNode->NextSibling();
            }
            while( gearNode != NULL );
        }
        else if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "home" ) == 0 )
        {
            _isHomeDefined = true;
            static_cast<TiXmlElement*>( child )->Attribute( "x", &_homeX );
            static_cast<TiXmlElement*>( child )->Attribute( "y", &_homeY );
        }
        else if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "events" ) == 0 )
        {
            TiXmlNode* eventNode = child->FirstChild();
            if( eventNode ) do
            {
                if( eventNode->Type() == TiXmlNode::ELEMENT && strcmp( eventNode->Value(), "event" ) == 0 )
                {
                    Event* event = Event::createFromXml( this, static_cast<TiXmlElement*>( eventNode ) );
                    assert( event );
                    _events.push_back( event );
                }
                eventNode = eventNode->NextSibling();
            }
            while( eventNode != NULL );
        }        
        else if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "gamedata" ) == 0 )
        {
            TiXmlNode* entryNode = child->FirstChild();
            if( entryNode ) do
            {
                if( entryNode->Type() == TiXmlNode::ELEMENT && strcmp( entryNode->Value(), "entry" ) == 0 )
                {
                    std::string name = static_cast<TiXmlElement*>( entryNode )->Attribute( "name" );
                    std::string data = static_cast<TiXmlElement*>( entryNode )->Attribute( "data" );
                    int cs;
                    static_cast<TiXmlElement*>( entryNode )->Attribute( "checksum", &cs );
                    GameData* gameData = new GameData( data.length() / 2 );
                    ::decrypt( gameData->getData(), gameData->getSize(), data, _name.c_str() );
                    if( ::checksum( gameData->getData(), gameData->getSize() ) != cs )
                    {
                        throw ccor::Exception( "User database entry corrupted: \"%s\"! Cheating not allowed!", _name.c_str() );
                    }
                    _gameDataM.insert( GameDataT( name, gameData ) );
                }
                entryNode = entryNode->NextSibling();
            }
            while( entryNode != NULL );
        }
        child = child->NextSibling();
    }
    while( child != NULL );

    // TEST_MODE( enable acrobatics )
    
    //setAcrobaticsSkill( acroJumpFromRun, true );
    //setAcrobaticsSkill( acroFreeflyFlip, true );
    //setAcrobaticsSkill( acroFreeflySitfly, true );
    //setAcrobaticsSkill( acroFrontFlip, true );
    //setAcrobaticsSkill( acroFrontBackFlip, true );
    //setAcrobaticsSkill( acroBackFlip, true );
    //setAcrobaticsSkill( acroBackFrontFlip, true );
    

    // initialize game walk-through meter
    initializeWalkthroughMeter();
}
Exemple #6
0
void SchemaEditor::slotMenuGearSelected(QString name)
{        
  addGear(name.ascii(), _contextMenuPos);    
}