Esempio n. 1
0
File: World.cs Progetto: mxgmn/GENW
    public void Load()
    {
        Log.Write("loading the world... ");
        XmlNode xnode = MyXml.SecondChild("Data/world.xml");
        Log.Assert(xnode.Name == "map", "wrong world file format");

        int width = MyXml.GetInt(xnode, "width");
        int height = MyXml.GetInt(xnode, "height");
        map.margin.x = MyXml.GetInt(xnode, "vMargin");
        map.margin.y = MyXml.GetInt(xnode, "hMargin");
        string method = MyXml.GetString(xnode, "method");

        map.Load(width, height, method);

        xnode = xnode.NextSibling;
        camera = new ZPoint(MyXml.GetInt(xnode, "x"), MyXml.GetInt(xnode, "y"));

        player = new Player();
        player.SetPosition(camera, 0.01f);
        player.UpdateVisitedLocations();

        for (xnode = xnode.NextSibling.FirstChild; xnode != null; xnode = xnode.NextSibling)
        {
            GlobalObject o = new GlobalObject(BigBase.Instance.gShapes.Get(MyXml.GetString(xnode, "name")));
            o.uniqueName = MyXml.GetString(xnode, "uniqueName");

            string dialogName = MyXml.GetString(xnode, "dialog");
            if (dialogName != "") o.dialog = BigBase.Instance.dialogs.Get(dialogName);

            o.SetPosition(new HexPoint(MyXml.GetInt(xnode, "x"), MyXml.GetInt(xnode, "y")), 0.01f);

            for (XmlNode xitem = xnode.FirstChild; xitem != null; xitem = xitem.NextSibling)
                o.inventory.Add(new Item(MyXml.GetString(xitem, "name"), MyXml.GetInt(xitem, "amount", 1)));

            gObjects.Add(o);
        }

        Log.WriteLine("OK");
    }