Esempio n. 1
0
bool CResourceMapItem::LoadMap ( const char * szMapFilename )
{ 
    assert ( szMapFilename );
    assert ( strlen ( szMapFilename ) > 0 );

    // Don't load twice
    if ( !m_pMapElement && !m_pXMLRootNode )
    {
        // Grab the root element
        m_pRootElement = g_pGame->GetMapManager ()->GetRootElement();

        // Create Map Element
        m_pMapElement = new CDummy ( g_pGame->GetGroups(), m_resource->GetResourceRootElement () );
        m_pMapElement->SetTypeName ( "map" );
        m_pMapElement->SetName ( m_strShortName.c_str () );

        // Load and parse it
        m_pXMLFile = g_pServerInterface->GetXML ()->CreateXML ( szMapFilename );
        if ( m_pXMLFile )
        {
            // Try to parse it
            if ( m_pXMLFile->Parse () )
            {
                // Grab the root item
                m_pXMLRootNode = m_pXMLFile->GetRootNode ();
                if ( m_pXMLRootNode )
                {
                    // Is the rootnode's name <map>?
                    std::string strBuffer;
                    strBuffer = m_pXMLRootNode->GetTagName ();
                    if ( strBuffer.compare ( "map" ) == 0 )
                    {
                        // Load the data
                        m_bIsLoaded = LoadSubNodes ( *m_pXMLRootNode, m_pMapElement, NULL, true );
                        if ( m_bIsLoaded )
                        {
                            LinkupElements ();

                            // Add map element to element group
                            m_pElementGroup->Add ( m_pMapElement );

                            // Success
                            return true;
                        }
                    }
                }
            }

            // Failed, destroy the XML
            delete m_pXMLRootNode;
            m_pXMLRootNode = NULL;
        }

        // Delete map element
        delete m_pMapElement;
    }

    // Failed
    return false;
}
Esempio n. 2
0
bool CResourceMapItem::HandleNode ( CXMLNode& Node, CElement* pParent, vector < CElement* >* pAdded, bool bIsDuringStart, CElement** pCreated )
{
    // Grab the name
    std::string strBuffer;
    strBuffer = Node.GetTagName ();

    // Handle it based on the tag name
    CElement* pNode = NULL;
    if ( strBuffer.compare ( "vehicle" ) == 0 )
    {
        pNode = m_pVehicleManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
    }
    else if ( strBuffer.compare ( "object" ) == 0 )
    {
        bool bIsLowLod = false;
        pNode = m_pObjectManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents, bIsLowLod );
    }
    else if ( strBuffer.compare ( "blip" ) == 0 )
    {
        CBlip* pBlip = m_pBlipManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
        pNode = pBlip;
        /*
        if ( pBlip )
        {
            pBlip->SetIsSynced ( bIsDuringStart );
        }
        */
    }
    else if ( strBuffer.compare ( "pickup" ) == 0 )
    {
        pNode = m_pPickupManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
    }
    else if ( strBuffer.compare ( "marker" ) == 0 )
    {
        CMarker* pMarker = m_pMarkerManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
        pNode = pMarker;
        /*
        if ( pMarker )
        {
            pMarker->SetIsSynced ( bIsDuringStart );
        }
        */
    }
    else if ( strBuffer.compare ( "radararea" ) == 0 )
    {
        CRadarArea* pRadarArea = m_pRadarAreaManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
        pNode = pRadarArea;
        /*
        if ( pRadarArea )
        {
            pRadarArea->SetIsSynced ( bIsDuringStart );
        }
        */
    }
    else if ( strBuffer.compare ( "team" ) == 0 )
    {
        pNode = m_pTeamManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
    }
    else if ( strBuffer.compare ( "ped" ) == 0 )
    {
        pNode = m_pPedManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
    }
    else if ( strBuffer.compare ( "water" ) == 0 )
    {
        pNode = m_pWaterManager->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
    }
    else if ( strBuffer.empty () )
    {
        // Comment, return true
        return true;
    }
    else
    {
        pNode = m_pGroups->CreateFromXML ( pParent, Node, m_pVM, m_pEvents );
    }

    // Set the node we created in the pointer we were given
    if ( pCreated )
    {
        *pCreated = pNode;
    }

    // Got a node created?
    if ( pNode )
    {
        // Set its typename to the name of the tag
        pNode->SetTypeName ( strBuffer.c_str () );

        // Add it to our list over elements added
        if ( pAdded )
        {
            pAdded->push_back ( pNode );
        }

        // Add this element to this map's element group
        if ( m_pElementGroup )
            m_pElementGroup->Add ( pNode );

        // Load the elements below it
        return LoadSubNodes ( Node, pNode, pAdded, bIsDuringStart );
    }
    return false;
}
Esempio n. 3
0
bool CMapManager::HandleNode ( CResource& Loader, CXMLNode& Node, CElement* pParent, vector < CElement* >* pAdded, bool bIsDuringStart, CElement** pCreated )
{
    // Grab the name
    std::string strBuffer = Node.GetTagName ();

    EElementType elementType;
    StringToEnum ( strBuffer, elementType );

    // Handle it based on the tag name
    CElement* pNode = NULL;
    if ( elementType == CElement::VEHICLE )
    {
        pNode = m_pVehicleManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
    }
    else if ( elementType == CElement::OBJECT )
    {
        bool bIsLowLod = false;
        pNode = m_pObjectManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents, bIsLowLod );
    }
    else if ( elementType == CElement::BLIP )
    {
        CBlip* pBlip = m_pBlipManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
        pNode = pBlip;
        /*if ( pBlip )
        {
            pBlip->SetIsSynced ( bIsDuringStart );
        }*/
    }
    else if ( elementType == CElement::PICKUP )
    {
        pNode = m_pPickupManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
    }
    else if ( elementType == CElement::MARKER )
    {
        CMarker* pMarker = m_pMarkerManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
        pNode = pMarker;
        if ( pMarker )
        {
            pMarker->SetIsSynced ( bIsDuringStart );
        }
    }
    else if ( elementType == CElement::RADAR_AREA )
    {
        CRadarArea* pRadarArea = m_pRadarAreaManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
        pNode = pRadarArea;
        if ( pRadarArea )
        {
            pRadarArea->SetIsSynced ( bIsDuringStart );
        }
    }
    else if ( elementType == CElement::TEAM )
    {
        pNode = m_pTeamManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
    }
    else if ( elementType == CElement::PED )
    {
        pNode = m_pPedManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
    }
    else if ( elementType == CElement::WATER )
    {
        pNode = m_pWaterManager->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
    }
    else if ( strBuffer.empty () )
    {
        // Comment, return true
        return true;
    }
    else
    {
        pNode = m_pGroups->CreateFromXML ( pParent, Node, Loader.GetVirtualMachine (), m_pEvents );
    }

    // Set the node we created in the pointer we were given
    if ( pCreated )
    {
        *pCreated = pNode;
    }

    // Got a node created?
    if ( pNode )
    {
        // Set its typename to the name of the tag
        pNode->SetTypeName ( strBuffer );

        // Add it to our list over elements added
        if ( pAdded )
        {
            pAdded->push_back ( pNode );
        }

        // Add this element to the resource's element group so it's deleted with it
        CElementGroup* pElementGroup = Loader.GetElementGroup ();
        if ( pElementGroup )
            pElementGroup->Add ( pNode );

        // Load the elements below it
        return LoadSubNodes ( Loader, Node, pNode, pAdded, bIsDuringStart );
    }
    return false;
}