示例#1
0
    public float GetLongitudeFromWorld(RemoteFortressReader.WorldMap world)
    {
        float tude = Mathf.InverseLerp(0, world.world_height, world.center_y);

        switch (world.world_poles)
        {
        case RemoteFortressReader.WorldPoles.NO_POLES:
            return(0);

        case RemoteFortressReader.WorldPoles.NORTH_POLE:
            tude = (1 - tude) * 90;
            break;

        case RemoteFortressReader.WorldPoles.SOUTH_POLE:
            tude = tude * 90;
            break;

        case RemoteFortressReader.WorldPoles.BOTH_POLES:
            tude = ((tude * 2) - 1) * -180;
            break;

        default:
            return(0);
        }
        return(tude);
    }
 // Pop a world map update. The map doesn't change, but the clouds do.
 public RemoteFortressReader.WorldMap PopWorldMapUpdate()
 {
     RemoteFortressReader.WorldMap result = null;
     if (Monitor.TryEnter(worldMapLock))
     {
         try
         {
             result       = _netWorldMap;
             _netWorldMap = null;
         }
         finally
         {
             Monitor.Exit(worldMapLock);
         }
     }
     return(result);
 }
    /// <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);
            }
        }
    }