示例#1
0
        protected Vector2 CenterInMercator;         //this is like distance (meters) in mercator

        public virtual void Init(BuildingFactory buildingFactory, RoadFactory roadFactory, World.Settings settings)
        {
            //初始经纬度转mercator
            var v2 = GM.LatLonToMeters(settings.Lat, settings.Long);

            Debug.Log("v2:");
            Debug.Log(v2);
            //经纬度转detail level级别的tile坐标
            var tile = GM.MetersToTile(v2, settings.DetailLevel);

            //tilehost为tile的坐标
            TileHost = new GameObject("Tiles").transform;
            TileHost.SetParent(transform, false);

            BuildingFactory = buildingFactory;
            RoadFactory     = roadFactory;
            Tiles           = new Dictionary <Vector2, Tile>();
            CenterTms       = tile;
            //tile 坐标
            CenterInMercator = GM.TileBounds(CenterTms, Zoom).center;
            initposition     = (v2 - CenterInMercator).ToVector3xz();
            GameManager.Instance.yourselfavatar = Instantiate(yourself, initposition, this.transform.rotation) as GameObject;
            GameManager.Instance.yourselfavatar.GetComponent <GPSmovemen>().centertiletms = CenterInMercator;

            Zoom       = settings.DetailLevel;
            Range      = settings.Range;
            LoadImages = settings.LoadImages;
            Debug.Log("Centertms: ");
            Debug.Log(CenterTms);
            Debug.Log("CenterinMercator: ");
            Debug.Log(CenterInMercator);
            LoadTiles(CenterTms, CenterInMercator);
        }
示例#2
0
    public PowerStationRoad BuildPowerstation(Buildable station, Vector2 position, World reference)
    {
        Road    built = null;
        Vector2 toFix;

        switch (station)
        {
        case Buildable.Powerstation_left: {
            built = RoadFactory.CreateChargeSpotLeft((int)position.x, (int)position.y);
            toFix = position - Vector2.right;
            break;
        }

        case Buildable.Powerstation_right: {
            built = RoadFactory.CreateChargeSpotRight((int)position.x, (int)position.y);
            toFix = position + Vector2.right;
            break;
        }

        case Buildable.Powerstation_down: {
            built = RoadFactory.CreateChargeSpotDown((int)position.x, (int)position.y);
            toFix = position - Vector2.up;
            break;
        }

        case Buildable.Powerstation_up: {
            built = RoadFactory.CreateChargeSpotUp((int)position.x, (int)position.y);
            toFix = position + Vector2.up;
            break;
        }

        default: {
            throw new System.ArgumentException();
        }
        }

        //get grid position
        Vector2 imagpos = reference.GetImagWorldCoordinates((int)position.x, (int)position.y);
        Vector2 imagfix = reference.GetImagWorldCoordinates((int)toFix.x, (int)toFix.y);

        //Add new road, destroy old neighbouring road and create new neighbouring road, then ling everything together again
        roadGrid[(int)imagpos.y, (int)imagpos.x] = built;
        roads.Remove(roadGrid[(int)imagfix.y, (int)imagfix.x]);
        //Debug.Log(roadGrid[(int)imagfix.y, (int)imagfix.x]);
        World.Destroy(roadGrid[(int)imagfix.y, (int)imagfix.x].gameObject);
        roadGrid[(int)imagfix.y, (int)imagfix.x] = CreateRoad((int)imagfix.x, (int)imagfix.y, (int)toFix.x, (int)toFix.y);
        Road fixd = roadGrid[(int)imagfix.y, (int)imagfix.x];

        roadGrid[(int)imagpos.y, (int)imagpos.x] = null;
        CreateRoadNetwork(roadGrid);
        roadGrid[(int)imagpos.y, (int)imagpos.x] = built;
        built.neighbourRoads.Add(fixd);
        fixd.neighbourRoads.Add(built);

        roads.Add(built);
        roads.Add(fixd);

        return(built as PowerStationRoad);
    }
示例#3
0
        protected Vector2 CenterInMercator;         //this is like distance (meters) in mercator

        public virtual void Init(BuildingFactory buildingFactory, RoadFactory roadFactory, World.Settings settings)
        {
            var v2   = GM.LatLonToMeters(settings.Lat, settings.Long);
            var tile = GM.MetersToTile(v2, settings.DetailLevel);

            TileHost = new GameObject("Tiles").transform;
            TileHost.SetParent(transform, false);

            BuildingFactory  = buildingFactory;
            RoadFactory      = roadFactory;
            Tiles            = new Dictionary <Vector2, Tile>();
            CenterTms        = tile;
            CenterInMercator = GM.TileBounds(CenterTms, Zoom).center;
            Zoom             = settings.DetailLevel;
            Range            = settings.Range;
            LoadImages       = settings.LoadImages;

            LoadTiles(CenterTms, CenterInMercator);
        }
示例#4
0
    private Road ChooseSprite(int x, int y, RoadStub[,] roads, int mapX, int mapY)
    {
        //check surrounding

        bool down      = false;
        bool up        = false;
        bool left      = false;
        bool right     = false;
        int  numAround = 0;

        try { if (roads[y, x + 1] != null)
              {
                  numAround++; right = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roads[y, x - 1] != null)
              {
                  numAround++; left = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roads[y + 1, x] != null)
              {
                  numAround++; down = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roads[y - 1, x] != null)
              {
                  numAround++; up = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}

        Road     result = null;
        RoadStub stub   = roads[y, x];

        //Choose correct road
        //Could just use RoadFactory.CreateGeneralRoad, but at the time of writing this,
        //that function did not exist
        switch (numAround)
        {
        case 0: {
            throw new System.ArgumentException();
        }

        case 1: {
            if (stub.type == RoadStub.RoadType.ChargingSpot)
            {
                result = RoadFactory.CreateChargeSpot(mapX, mapY, up, down, left, right);
            }
            else if (stub.type == RoadStub.RoadType.Regular)
            {
                result = RoadFactory.CreateEnd(mapX, mapY, up, down, left, right);
            }
            else if (stub.type == RoadStub.RoadType.ParkingSpot)
            {
                result = RoadFactory.CreateParkingSpot(mapX, mapY, up, down, left, right);
            }
            break;
        }

        case 2: {
            result = RoadFactory.CreateTwoSided(mapX, mapY, up, down, left, right);
            break;
        }

        case 3: {
            result = RoadFactory.CreateT(mapX, mapY, up, down, left, right);
            break;
        }

        case 4: {
            result = RoadFactory.CreateQCrossroad(mapX, mapY);
            break;
        }
        }
        return(result);
    }
示例#5
0
    private Road CreateRoad(int gridx, int gridy, int mapx, int mapy)
    {
        bool down      = false;
        bool up        = false;
        bool left      = false;
        bool right     = false;
        int  numAround = 0;

        try { if (roadGrid[gridy, gridx + 1] != null)
              {
                  numAround++; right = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roadGrid[gridy, gridx - 1] != null)
              {
                  numAround++; left = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roadGrid[gridy + 1, gridx] != null)
              {
                  numAround++; down = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}
        try { if (roadGrid[gridy - 1, gridx] != null)
              {
                  numAround++; up = true;
              }
        }
        catch (System.IndexOutOfRangeException) {}

        Road result = null;

        switch (numAround)
        {
        case 0: {
            throw new System.ArgumentException();
        }

        case 1: {
            throw new System.ArgumentException("1 road around fixee?");
        }

        case 2: {
            result = RoadFactory.CreateTwoSided(mapx, mapy, up, down, left, right);
            break;
        }

        case 3: {
            result = RoadFactory.CreateT(mapx, mapy, up, down, left, right);
            break;
        }

        case 4: {
            result = RoadFactory.CreateQCrossroad(mapx, mapy);
            break;
        }
        }
        return(result);
    }