コード例 #1
0
    public void Reposition(RemoteFortressReader.BlockList input)
    {
        int diff_x = input.map_x - map_coords.x;
        int diff_y = input.map_y - map_coords.y;

        coordinates.x += (diff_x * 3);
        coordinates.y += (diff_y * 3);
        map_coords.x   = input.map_x;
        map_coords.y   = input.map_y;
        SetUnityPosition();
    }
コード例 #2
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();
 }
コード例 #3
0
    /// <summary>
    /// Performs a single update.
    /// </summary>
    /// <exception cref="System.Exception"></exception>
    void PerformSingleUpdate()
    {
        networkClient.suspend_game();

        if (mapResetRequested.Pop())
        {
            mapResetCall.execute();
        }

        if (mapInfoCall != null)
        {
            RemoteFortressReader.MapInfo mapInfo;
            mapInfoCall.execute(null, out mapInfo);
            if (mapInfo == null)
            {
                if (netMapInfo != null)
                {
                    lock (mapInfoLock)
                    {
                        embarkMapPosition = new DFCoord(-1, -1, -1);
                        embarkMapSize     = new DFCoord(0, 0, 0);
                        MapDataStore.InitMainMap(embarkMapSize.x * 16, embarkMapSize.y * 16, embarkMapSize.z);
                    }
                }
            }
            else
            {
                if ((netMapInfo == null) ||
                    mapInfo.block_pos_x != netMapInfo.block_pos_x ||
                    mapInfo.block_pos_y != netMapInfo.block_pos_y ||
                    mapInfo.block_pos_z != netMapInfo.block_pos_z ||
                    mapInfo.block_size_x != netMapInfo.block_size_x ||
                    mapInfo.block_size_y != netMapInfo.block_size_y ||
                    mapInfo.block_size_z != netMapInfo.block_size_z)
                {
                    lock (mapInfoLock)
                    {
                        embarkMapPosition = new DFCoord(mapInfo.block_pos_x, mapInfo.block_pos_y, mapInfo.block_pos_z);
                        embarkMapSize     = new DFCoord(mapInfo.block_size_x, mapInfo.block_size_y, mapInfo.block_size_z);
                        MapDataStore.InitMainMap(EmbarkMapSize.x * 16, EmbarkMapSize.y * 16, EmbarkMapSize.z);
                        mapResetCall.execute();
                    }
                }
            }
            netMapInfo = mapInfo;
        }

        if (viewInfoCall != null)
        {
            RemoteFortressReader.ViewInfo viewInfo;
            viewInfoCall.execute(null, out viewInfo);
            netViewInfo.Set(viewInfo);
        }
        if (copyScreenCall != null)
        {
            RemoteFortressReader.ScreenCapture screenCapture;
            copyScreenCall.execute(null, out screenCapture);
            netScreenCapture.Set(screenCapture);
        }

        if (unitListCall != null)
        {
            RemoteFortressReader.UnitList unitList;
            unitListCall.execute(null, out unitList);
            netUnitList.Set(unitList);
        }

        if (worldMapCenterCall != null)
        {
            RemoteFortressReader.WorldMap tempWorldMap;
            worldMapCenterCall.execute(null, out tempWorldMap);
            if (tempWorldMap != null)
            {
                DFTime = new DFTime(tempWorldMap.cur_year, tempWorldMap.cur_year_tick);
            }
            if (netWorldMapCenter == null || (tempWorldMap != null &&
                                              (netWorldMapCenter.center_x != tempWorldMap.center_x ||
                                               netWorldMapCenter.center_y != tempWorldMap.center_y)))
            {
                if (worldMapCall != null)
                {
                    RemoteFortressReader.WorldMap worldMap;
                    worldMapCall.execute(null, out worldMap);
                    netWorldMap.Set(worldMap);
                }

                netWorldMapCenter = tempWorldMap;

                worldMapMoved.Set();
                if (regionMapCall != null)
                {
                    RemoteFortressReader.RegionMaps regionMaps;
                    regionMapCall.execute(null, out regionMaps);
                    netRegionMaps.Set(regionMaps);
                }
                nextRegionUpdate = DateTime.Now.AddSeconds(0.2); //add another region map update after this one, to get delayed regions.s
            }
        }


        if (nextRegionUpdate < DateTime.Now)
        {
            if (regionMapCall != null)
            {
                RemoteFortressReader.RegionMaps regionMaps;
                regionMapCall.execute(null, out regionMaps);
                netRegionMaps.Set(regionMaps);
            }
            nextRegionUpdate = DateTime.MaxValue;
        }


        if (keyboardEventCall != null)
        {
            RemoteFortressReader.KeyboardEvent dfEvent;
            while (keyPresses.TryDequeue(out dfEvent))
            {
                keyboardEventCall.execute(dfEvent);
            }
        }

        // since enqueueing results can block, we do it after we've unsuspended df
        RemoteFortressReader.BlockList resultList = null;

        if (EmbarkMapSize.x > 0 &&
            EmbarkMapSize.y > 0 &&
            EmbarkMapSize.z > 0)
        {
            BlockCoord.Range?requestRangeUpdate = requestRegion.Pop();

            if (requestRangeUpdate != null)
            {
                blockRequest.min_x = requestRangeUpdate.Value.Min.x;
                blockRequest.min_y = requestRangeUpdate.Value.Min.y;
                blockRequest.min_z = requestRangeUpdate.Value.Min.z;
                blockRequest.max_x = requestRangeUpdate.Value.Max.x;
                blockRequest.max_y = requestRangeUpdate.Value.Max.y;
                blockRequest.max_z = requestRangeUpdate.Value.Max.z;
            }

            if (blockListCall != null)
            {
                blockListCall.execute(blockRequest, out resultList);
            }
        }
        networkClient.resume_game();

        if (resultList != null)
        {
            foreach (RemoteFortressReader.MapBlock mapBlock in resultList.map_blocks)
            {
                pendingBlocks.Enqueue(mapBlock);
            }
        }
    }