Exemplo n.º 1
0
    public void StoreTiles(RemoteFortressReader.MapBlock block)
    {
        bool setTiles   = block.tiles.Count > 0;
        bool setLiquids = block.water.Count > 0 || block.magma.Count > 0;

        if (!setTiles && !setLiquids)
        {
            return;
        }

        for (int xx = 0; xx < 16; xx++)
        {
            for (int yy = 0; yy < 16; yy++)
            {
                DFCoord worldCoord = new DFCoord(block.map_x + xx, block.map_y + yy, block.map_z);
                DFCoord localCoord = WorldToLocalSpace(worldCoord);
                int     netIndex   = xx + (yy * 16);
                tilesPresent[PresentIndex(localCoord.x, localCoord.y, localCoord.z)] = true;
                if (setTiles)
                {
                    tiles[localCoord.x, localCoord.y, localCoord.z].tileType          = block.tiles[netIndex];
                    tiles[localCoord.x, localCoord.y, localCoord.z].material          = block.materials[netIndex];
                    tiles[localCoord.x, localCoord.y, localCoord.z].base_material     = block.base_materials[netIndex];
                    tiles[localCoord.x, localCoord.y, localCoord.z].layer_material    = block.layer_materials[netIndex];
                    tiles[localCoord.x, localCoord.y, localCoord.z].vein_material     = block.vein_materials[netIndex];
                    tiles[localCoord.x, localCoord.y, localCoord.z].construction_item = block.construction_items[netIndex];
                }
                if (setLiquids)
                {
                    tiles[localCoord.x, localCoord.y, localCoord.z].waterLevel = block.water[netIndex];
                    tiles[localCoord.x, localCoord.y, localCoord.z].magmaLevel = block.magma[netIndex];
                }
            }
        }
    }
Exemplo n.º 2
0
    void UpdateBlocks()
    {
        loadWatch.Reset();
        loadWatch.Start();
        while (true)
        {
            RemoteFortressReader.MapBlock block = DFConnection.Instance.PopMapBlockUpdate();
            if (block == null)
            {
                break;
            }
            MapDataStore.Main.StoreTiles(block);
            if (block.tiles.Count > 0)
            {
                SetDirtyBlock(block.map_x, block.map_y, block.map_z);
            }
            if (block.water.Count > 0 || block.magma.Count > 0)
            {
                SetDirtyLiquidBlock(block.map_x, block.map_y, block.map_z);
            }
        }
        loadWatch.Stop();
        genWatch.Reset();
        genWatch.Start();
        EnqueueMeshUpdates();
        genWatch.Stop();

        mesher.Poll();

        FetchNewMeshes();
    }
Exemplo n.º 3
0
 void CopyTiles(RemoteFortressReader.MapBlock DFBlock)
 {
     for (int xx = 0; xx < 16; xx++)
     {
         for (int yy = 0; yy < 16; yy++)
         {
             if (tiles[DFBlock.map_x + xx, DFBlock.map_y + yy, DFBlock.map_z] == null)
             {
                 tiles[DFBlock.map_x + xx, DFBlock.map_y + yy, DFBlock.map_z]           = new MapTile();
                 tiles[DFBlock.map_x + xx, DFBlock.map_y + yy, DFBlock.map_z].position  = new DFCoord(DFBlock.map_x + xx, DFBlock.map_y + yy, DFBlock.map_z);
                 tiles[DFBlock.map_x + xx, DFBlock.map_y + yy, DFBlock.map_z].container = tiles;
             }
         }
     }
     if (DFBlock.tiles.Count > 0)
     {
         for (int xx = 0; xx < 16; xx++)
         {
             for (int yy = 0; yy < 16; yy++)
             {
                 MapTile tile = tiles[DFBlock.map_x + xx, DFBlock.map_y + yy, DFBlock.map_z];
                 tile.tileType       = DFBlock.tiles[xx + (yy * 16)];
                 tile.material       = DFBlock.materials[xx + (yy * 16)];
                 tile.base_material  = DFBlock.base_materials[xx + (yy * 16)];
                 tile.layer_material = DFBlock.layer_materials[xx + (yy * 16)];
                 tile.vein_material  = DFBlock.vein_materials[xx + (yy * 16)];
             }
         }
         SetDirtyBlock(DFBlock.map_x, DFBlock.map_y, DFBlock.map_z);
     }
     if (DFBlock.water.Count > 0)
     {
         for (int xx = 0; xx < 16; xx++)
         {
             for (int yy = 0; yy < 16; yy++)
             {
                 MapTile tile = tiles[DFBlock.map_x + xx, DFBlock.map_y + yy, DFBlock.map_z];
                 tile.liquid[l_water] = DFBlock.water[xx + (yy * 16)];
                 tile.liquid[l_magma] = DFBlock.magma[xx + (yy * 16)];
             }
         }
         SetDirtyWaterBlock(DFBlock.map_x, DFBlock.map_y, DFBlock.map_z);
     }
 }
Exemplo n.º 4
0
 public void SetAllTiles(RemoteFortressReader.MapBlock DFBlock, RemoteFortressReader.BlockList blockList, RemoteFortressReader.TiletypeList tiletypeList)
 {
     if (DFBlock.tiles.Count != terrain.Length)
     {
         Debug.LogError("Map Block has " + DFBlock.tiles.Count + " tiles, should be " + terrain.Length);
     }
     for (int i = 0; i < DFBlock.tiles.Count; i++)
     {
         terrain[i] = tiletypeList.tiletype_list[DFBlock.tiles[i]].shape;
         colors[i]  = Color.white;
     }
     SetOpenness();
     coordinates.x = DFBlock.map_x;
     coordinates.y = DFBlock.map_y;
     coordinates.z = DFBlock.map_z;
     map_coords.x  = blockList.map_x;
     map_coords.y  = blockList.map_y;
     SetUnityPosition();
 }
Exemplo n.º 5
0
    public void StoreTiles(RemoteFortressReader.MapBlock block, out bool setTiles, out bool setLiquids, out bool setSpatters)
    {
        setTiles    = block.tiles.Count > 0;
        setLiquids  = block.water.Count > 0 || block.magma.Count > 0;
        setSpatters = block.spatterPile.Count > 0;
        if (!setTiles && !setLiquids)
        {
            return;
        }

        for (int xx = 0; xx < 16; xx++)
        {
            for (int yy = 0; yy < 16; yy++)
            {
                DFCoord worldCoord = new DFCoord(block.map_x + xx, block.map_y + yy, block.map_z);
                if (!InSliceBounds(worldCoord))
                {
                    Debug.LogError(worldCoord + " is out of bounds for " + MapSize);
                    return;
                }
                int netIndex = xx + (yy * 16);
                if (this[worldCoord] == null)
                {
                    this[worldCoord] = new Tile(this, worldCoord);
                }
                if (block.tiles.Count > 0)
                {
                    this[worldCoord].tileType       = block.tiles[netIndex];
                    this[worldCoord].material       = block.materials[netIndex];
                    this[worldCoord].base_material  = block.base_materials[netIndex];
                    this[worldCoord].layer_material = block.layer_materials[netIndex];
                    this[worldCoord].vein_material  = block.vein_materials[netIndex];
                    if (block.construction_items != null && block.construction_items.Count > netIndex)
                    {
                        this[worldCoord].construction_item = block.construction_items[netIndex];
                    }
                    else
                    {
                        this[worldCoord].construction_item = new MatPairStruct(-1, -1);
                    }
                    if (block.tree_percent != null && block.tree_percent.Count > netIndex)
                    {
                        this[worldCoord].trunkPercent   = (byte)block.tree_percent[netIndex];
                        this[worldCoord].positionOnTree = new DFCoord(block.tree_x[netIndex], block.tree_y[netIndex], block.tree_z[netIndex]);
                    }
                    else
                    {
                        this[worldCoord].trunkPercent   = 0;
                        this[worldCoord].positionOnTree = new DFCoord(0, 0, 0);
                    }
                }
                if (setLiquids)
                {
                    this[worldCoord].waterLevel = block.water[netIndex];
                    this[worldCoord].magmaLevel = block.magma[netIndex];
                    if (this[worldCoord].Hidden != block.hidden[netIndex])
                    {
                        this[worldCoord].Hidden = block.hidden[netIndex];
                        setTiles = true;
                    }
                    if (block.tile_dig_designation != null && block.tile_dig_designation.Count > netIndex)
                    {
                        if (this[worldCoord].digDesignation != block.tile_dig_designation[netIndex])
                        {
                            this[worldCoord].digDesignation = block.tile_dig_designation[netIndex];
                            setTiles = true;
                        }
                    }
                }
                if (setSpatters)
                {
                    this[worldCoord].spatters = block.spatterPile[netIndex].spatters;
                }
            }
        }
        foreach (var building in block.buildings)
        {
            if (building.building_type.building_type == 30)
            {
                continue; // We won't do civzones right now.
            }
            for (int xx = building.pos_x_min; xx <= building.pos_x_max; xx++)
            {
                for (int yy = building.pos_y_min; yy <= building.pos_y_max; yy++)
                {
                    if ((building.building_type.building_type == 29) &&
                        building.room != null && building.room.extents.Count > 0)
                    {
                        int buildingLocalX = xx - building.room.pos_x;
                        int buildingLocalY = yy - building.room.pos_y;

                        if (building.room.extents[buildingLocalY * building.room.width + buildingLocalX] == 0)
                        {
                            continue;
                        }
                    }

                    DFCoord   worldCoord         = new DFCoord(xx, yy, block.map_z);
                    DFCoord2d buildingLocalCoord = GetRotatedLocalCoord(worldCoord, building);// = new DFCoord2d(xx - building.pos_x_min, yy - building.pos_y_min);
                    if (!InSliceBounds(worldCoord))
                    {
                        Debug.LogError(worldCoord + " is out of bounds for " + MapSize);
                        continue;
                    }
                    if (this[worldCoord] == null)
                    {
                        this[worldCoord] = new Tile(this, worldCoord);
                    }
                    this[worldCoord].buildingType      = building.building_type;
                    this[worldCoord].buildingMaterial  = building.material;
                    this[worldCoord].buildingLocalPos  = buildingLocalCoord;
                    this[worldCoord].buildingDirection = building.direction;
                }
            }
        }
    }
Exemplo n.º 6
0
        internal void LoadBlock(RemoteFortressReader.MapBlock block)
        {
            foreach (var building in block.buildings)
            {
                BuildingModel builtBuilding;
                if (!sceneBuildings.ContainsKey(building.index))
                {
                    Profiler.BeginSample("Init Building " + building.index);
                    BuildingStruct type = building.building_type;

                    DFCoord origin = new DFCoord(
                        (building.pos_x_min + building.pos_x_max) / 2,
                        (building.pos_y_min + building.pos_y_max) / 2,
                        building.pos_z_max);

                    if (type.building_type == 19) //Bridge
                    {
                        switch (building.direction)
                        {
                        case BuildingDirection.NORTH:
                            origin = new DFCoord(
                                (building.pos_x_min + building.pos_x_max) / 2,
                                building.pos_y_min,
                                building.pos_z_max);
                            break;

                        case BuildingDirection.EAST:
                            origin = new DFCoord(
                                building.pos_x_max,
                                (building.pos_y_min + building.pos_y_max) / 2,
                                building.pos_z_max);
                            break;

                        case BuildingDirection.SOUTH:
                            origin = new DFCoord(
                                (building.pos_x_min + building.pos_x_max) / 2,
                                building.pos_y_max,
                                building.pos_z_max);
                            break;

                        case BuildingDirection.WEST:
                            origin = new DFCoord(
                                building.pos_x_min,
                                (building.pos_y_min + building.pos_y_max) / 2,
                                building.pos_z_max);
                            break;

                        case BuildingDirection.NONE:
                            break;

                        default:
                            break;
                        }
                    }

                    if (!buidlingPrefabs.ContainsKey(type))
                    {
                        type = new BuildingStruct(type.building_type, type.building_subtype, -1);
                    }
                    if (!buidlingPrefabs.ContainsKey(type))
                    {
                        type = new BuildingStruct(type.building_type, -1, -1);
                    }
                    if (!buidlingPrefabs.ContainsKey(type))
                    {
                        type = new BuildingStruct(-1, -1, -1);
                    }
                    if (buidlingPrefabs.ContainsKey(type))
                    {
                        builtBuilding = Instantiate(buidlingPrefabs[type], GameMap.DFtoUnityCoord(origin), TranslateDirection(building.direction), transform);
                    }
                    else
                    {
                        builtBuilding = Instantiate(defaultBuilding, GameMap.DFtoUnityCoord(origin), TranslateDirection(building.direction), transform);
                    }

                    sceneBuildings[building.index] = builtBuilding;
                    Profiler.EndSample();
                }
                else
                {
                    builtBuilding = sceneBuildings[building.index];
                }
                Profiler.BeginSample("BuildingModel.Initialize");
                builtBuilding.Initialize(building);
                Profiler.EndSample();
            }
        }