Esempio n. 1
0
void MapNode::Deserialize(SerializedGameData& sgd, const unsigned numPlayers)
{
    for(unsigned z = 0; z < roads.size(); ++z)
    {
        roads[z] = sgd.PopUnsignedChar();
        RTTR_Assert(roads[z] < 4);
        roads_real[z] = roads[z] != 0;
    }

    altitude = sgd.PopUnsignedChar();
    shadow = sgd.PopUnsignedChar();
    t1 = TerrainType(sgd.PopUnsignedChar());
    RTTR_Assert(t1 < TT_COUNT);
    t2 = TerrainType(sgd.PopUnsignedChar());
    RTTR_Assert(t2 < TT_COUNT);
    resources = sgd.PopUnsignedChar();
    reserved = sgd.PopBool();
    owner = sgd.PopUnsignedChar();
    for(unsigned b = 0; b < boundary_stones.size(); ++b)
        boundary_stones[b] = sgd.PopUnsignedChar();
    bq = BuildingQuality(sgd.PopUnsignedChar());
    bqVisual = BuildingQuality(sgd.PopUnsignedChar());
    RTTR_Assert(numPlayers < fow.size());
    for(unsigned z = 0; z < numPlayers; ++z)
    {
        MapNode::FoWData& curFoW = fow[z];
        curFoW.visibility = Visibility(sgd.PopUnsignedChar());
        // Only in FoW can be FoW objects
        if(curFoW.visibility == VIS_FOW)
        {
            curFoW.last_update_time = sgd.PopUnsignedInt();
            curFoW.object = sgd.PopFOWObject();
            for(unsigned r = 0; r < curFoW.roads.size(); ++r)
                curFoW.roads[r] = sgd.PopUnsignedChar();
            curFoW.owner = sgd.PopUnsignedChar();
            for(unsigned b = 0; b < curFoW.boundary_stones.size(); ++b)
                curFoW.boundary_stones[b] = sgd.PopUnsignedChar();
        }
        else
        {
            curFoW.last_update_time = 0;
            curFoW.object = NULL;
            for(unsigned r = 0; r < curFoW.roads.size(); ++r)
                curFoW.roads[r] = 0;
            curFoW.owner = 0;
            for(unsigned b = 0; b < curFoW.boundary_stones.size(); ++b)
                curFoW.boundary_stones[b] = 0;
        }
    }
    obj = sgd.PopObject<noBase>(GOT_UNKNOWN);
    sgd.PopObjectContainer(figures, GOT_UNKNOWN);
    sea_id = sgd.PopUnsignedShort();
    harbor_id = sgd.PopUnsignedInt();
}
Esempio n. 2
0
void GameWorld::Deserialize(SerializedGameData& sgd)
{
    // Headinformationen
    width_ = sgd.PopUnsignedShort();
    height_ = sgd.PopUnsignedShort();
    lt = LandscapeType(sgd.PopUnsignedChar());

    // Initialisierungen
    Init();

    // Obj-ID-Counter setzen
    GameObject::SetObjIDCounter(sgd.PopUnsignedInt());

    // Trade graphs
    // Only if trade is enabled
    if(GAMECLIENT.GetGGS().isEnabled(ADDON_TRADE))
    {
        tgs.resize(sgd.PopUnsignedChar());
        for(unsigned i = 0; i < tgs.size(); ++i)
            tgs[i] = new TradeGraph(sgd, this);
    }

    // Alle Weltpunkte serialisieren
    for(unsigned i = 0; i < map_size; ++i)
    {
        for(unsigned z = 0; z < 3; ++z)
        {
            nodes[i].roads[z] = sgd.PopUnsignedChar();
            nodes[i].roads_real[z] = nodes[i].roads[z] ? true : false;
        }


        nodes[i].altitude = sgd.PopUnsignedChar();
        nodes[i].shadow = sgd.PopUnsignedChar();
        nodes[i].t1 = TerrainType(sgd.PopUnsignedChar());
        nodes[i].t2 = TerrainType(sgd.PopUnsignedChar());
        nodes[i].resources = sgd.PopUnsignedChar();
        nodes[i].reserved = sgd.PopBool();
        nodes[i].owner = sgd.PopUnsignedChar();
        for(unsigned b = 0; b < 4; ++b)
            nodes[i].boundary_stones[b] = sgd.PopUnsignedChar();
        nodes[i].bq = BuildingQuality(sgd.PopUnsignedChar());
        for(unsigned z = 0; z < GAMECLIENT.GetPlayerCount(); ++z)
        {
            MapNode::FoWData& fow = nodes[i].fow[z];
            fow.visibility = Visibility(sgd.PopUnsignedChar());
            // Nur im FoW können FOW-Objekte stehen
            if(fow.visibility == VIS_FOW)
            {
                fow.last_update_time = sgd.PopUnsignedInt();
                fow.object = sgd.PopFOWObject();
                for(unsigned r = 0; r < 3; ++r)
                    fow.roads[r] = sgd.PopUnsignedChar();
                fow.owner = sgd.PopUnsignedChar();
                for(unsigned b = 0; b < 4; ++b)
                    fow.boundary_stones[b] = sgd.PopUnsignedChar();
            }
            else
            {
                fow.last_update_time = 0;
                fow.object = NULL;
                for(unsigned r = 0; r < 3; ++r)
                    fow.roads[r] = 0;
                fow.owner = 0;
                for(unsigned b = 0; b < 4; ++b)
                    fow.boundary_stones[b] = 0;
            }
        }
        nodes[i].obj = sgd.PopObject<noBase>(GOT_UNKNOWN);
        sgd.PopObjectContainer(nodes[i].figures, GOT_UNKNOWN);
        nodes[i].sea_id = sgd.PopUnsignedShort();
        nodes[i].harbor_id = sgd.PopUnsignedInt();

        if (nodes[i].harbor_id)
        {
            GameWorldBase::HarborPos p(MapPoint((MapCoord) (i % width_), (MapCoord) (i / width_)));
            harbor_pos.push_back(p);
        }
    }

    // Katapultsteine deserialisieren
    sgd.PopObjectContainer(catapult_stones, GOT_CATAPULTSTONE);

    // Meeresinformationen deserialisieren
    seas.resize(sgd.PopUnsignedInt());
    for(unsigned i = 0; i < seas.size(); ++i)
    {
        seas[i].nodes_count = sgd.PopUnsignedInt();
    }

    // Hafenpositionen serialisieren
    harbor_pos.resize(sgd.PopUnsignedInt());
    for(unsigned i = 0; i < harbor_pos.size(); ++i)
    {
        harbor_pos[i].pos = sgd.PopMapPoint();
        for(unsigned z = 0; z < 6; ++z)
            harbor_pos[i].cps[z].sea_id = sgd.PopUnsignedShort();
        for(unsigned z = 0; z < 6; ++z)
        {
            harbor_pos[i].neighbors[z].resize(sgd.PopUnsignedInt());
            for(unsigned c = 0; c < harbor_pos[i].neighbors[z].size(); ++c)
            {
                harbor_pos[i].neighbors[z][c].id = sgd.PopUnsignedInt();
                harbor_pos[i].neighbors[z][c].distance = sgd.PopUnsignedInt();
            }
        }
    }

    sgd.PopObjectContainer(harbor_building_sites_from_sea, GOT_BUILDINGSITE);

    // BQ neu berechnen
    for(unsigned y = 0; y < height_; ++y)
    {
        for(unsigned x = 0; x < width_; ++x)
        {
            SetBQ(MapPoint(x, y), GAMECLIENT.GetPlayerID());
        }
    }

    tr.GenerateOpenGL(*this);

    // Zum HQ am Anfang springen, falls dieses existiert
    if(GetPlayer(GAMECLIENT.GetPlayerID()).hqPos.x != 0xFFFF)
        this->MoveToMapObject(GetPlayer(GAMECLIENT.GetPlayerID()).hqPos);
}