Example #1
0
        public static RoadDirection Opposite(RoadDirection dir)
        {
            switch (dir)
            {
            case RoadDirection.Vertical:   return(RoadDirection.Horizontal);

            case RoadDirection.Horizontal: return(RoadDirection.Vertical);

            case RoadDirection.North: return(RoadDirection.South);

            case RoadDirection.South: return(RoadDirection.North);

            case RoadDirection.West:  return(RoadDirection.East);

            case RoadDirection.East:  return(RoadDirection.West);

            case RoadDirection.NorthWest: return(RoadDirection.SouthEast);

            case RoadDirection.NorthEast: return(RoadDirection.SouthWest);

            case RoadDirection.SouthWest: return(RoadDirection.NorthEast);

            case RoadDirection.SouthEast: return(RoadDirection.NorthWest);

            default: return(RoadDirection.None);
            }
        }
Example #2
0
    /// <summary>
    /// Consulta si esta carretera tiene la salida indicada
    /// </summary>
    /// <param name="direction"></param>
    /// <returns></returns>
    public static bool HasDirection(this RoadDirection roadDirection, CardinalPoint direction)
    {
        bool r = false;

        switch (direction)
        {
        case CardinalPoint.N:
            r = roadDirection.HasN();
            break;

        case CardinalPoint.E:
            r = roadDirection.HasE();
            break;

        case CardinalPoint.W:
            r = roadDirection.HasW();
            break;

        case CardinalPoint.S:
            r = roadDirection.HasS();
            break;

        case CardinalPoint.None:
            r = true;
            break;

        default:
            r = false;
            break;
        }
        return(r);
    }
Example #3
0
    public static bool HasS(this RoadDirection roadDirection)
    {
        bool r = false;

        switch (roadDirection)
        {
        case RoadDirection.NEWS:
            r = true;
            break;

        case RoadDirection.NS:
            r = true;
            break;

        case RoadDirection.SE:
            r = true;
            break;

        case RoadDirection.SW:
            r = true;
            break;

        default:
            r = false;
            break;
        }
        return(r);
    }
Example #4
0
    public static List <RoadDirection> GetAll(this RoadDirection thisRD)
    {
        List <RoadDirection> rds = ((RoadDirection[])Enum.GetValues(typeof(RoadDirection))).ToList();

        //rds.Remove(RoadDirection.NEWS);
        return(rds);
    }
Example #5
0
    public void UpdateMaterial(string LowIMGPath)
    {
        if (PermanentVisuals)
        {
            return;
        }
        RoadDirection dir = _direction;

        if (myRoad != null)
        {
            if (myRoad.gameObject.activeSelf == true)
            {
                myRoad.SetFrame((int)dir);
            }
        }
        if (myRoadLow != null)
        {
            if (myRoadLow.gameObject.activeSelf == true)
            {
                string s  = (string)LowIMGPath + "sprite_" + (string)roadDirToString(dir);
                Sprite sp = Resources.Load <Sprite>(s);
                myRoadLow.sprite = sp;
            }
        }
    }
Example #6
0
    /// <summary>
    /// Compara dos "RoadDirection" Devuelve las similitudes en array de Truckdirection
    /// mediante el RETURN.
    /// Devuelve las diferencias en array de TruckDirection mediante out.
    /// Ambas arrays varian entre 0 y 2 elementos
    /// </summary>
    /// <param name="thisRoad">selfroad</param>
    /// <param name="otherRoad">La otra carretera a comparar</param>
    /// <param name="diferences">OUT de array de TruckDirection</param>
    /// <param name="focusDifferencesOnOtherRoad">Si es false, el out "differences" devuelve=> ¿Que tiene esta carretera que no tenga "otherRoad"?. Si es true => ¿Que tiene la otra carretera que no tenga esta?</param>
    /// <returns>array de TruckDirection</returns>
    public static CardinalPoint[] Compare(this RoadDirection thisRoad, RoadDirection otherRoad, out CardinalPoint[] diferences, bool focusDifferencesOnOtherRoad = false)
    {
        bool b = focusDifferencesOnOtherRoad; //alias

        //Arrays temporales a llenar
        CardinalPoint[] diff   = new CardinalPoint[2];
        CardinalPoint[] result = new CardinalPoint[2];
        //contadores para las arrays
        int i = 0; //result
        int e = 0; //diff

        //MainLoop de 1 a 4. el ENUM TruckDirection puede ser casteado a INT (y viceversa)
        //Nota: Enum Truckdirection. None = 0, N = 1, E = 2, W = 3, S = 4.
        for (int index = 1; index <= 4; index++)
        {
            //Sacamos la dirección que vamos a comprobar en este loop:
            CardinalPoint dir = (CardinalPoint)index; //Cast de int a TruckDirection

            //La comprobamos!

            //Si ambos tienen la direción, guaramos la similitud y se acaba el loop
            if (thisRoad.HasDirection(dir) && otherRoad.HasDirection(dir))
            {
                result[i] = dir;
                i++;
            }
            else //Si no comprobamos si alguno de los dos tiene esa dirección
            {
                //Nota: b es el focus.
                //Sobre Que carretera queremos devolver las diferencias
                // !b = esta carretera
                // b = la otra carretera
                if (thisRoad.HasDirection(dir) && !b)
                {
                    diff[e] = dir;
                    e++;
                }
                if (otherRoad.HasDirection(dir) && b)
                {
                    diff[e] = dir;
                    e++;
                }
            }
        }
        //End of Main Loop

        //reconstruimos ambas arrays y devolvemos.
        CardinalPoint[] resultd = new CardinalPoint[result.Length];
        for (int x = 0; x < result.Length; x++)
        {
            resultd[x] = result[x];
        }

        diferences = new CardinalPoint[diff.Length];
        for (int y = 0; y < diff.Length; y++)
        {
            diferences[y] = diff[y];
        }
        return(resultd);
    }
Example #7
0
        private RoadDirection CalculateRoadDirection(Feature feature, LineShape lineShape, Vertex startVertex)
        {
            int index = 0;  // Given the vertex is the first of input line shape.

            if (!GeometryHelper.IsSamePoint(lineShape.Vertices[0], startVertex, Tolerance))
            {
                index = lineShape.Vertices.Count - 1;
            }

            RoadDirection direction = RoadDirection.Noway;

            if (index == 0)
            {
                if (IsRoadDirectionAccessable(feature, RoadDirection.Forward))
                {
                    direction = RoadDirection.Forward;
                }
            }
            else
            {
                if (IsRoadDirectionAccessable(feature, RoadDirection.Backward))
                {
                    direction = RoadDirection.Backward;
                }
            }

            return(direction);
        }
Example #8
0
    void OnPress(bool isPressed)
    {
        if (NumberOfTruckOnTop > 0)
        {
            return;
        }
        if (numberOfComingTrucks > 0)
        {
            return;
        }
        if (freeze)
        {
            return;
        }
        if (!isPressed)
        {
            return;
        }
        if (!isClickable)
        {
            return;
        }

        switch (TypeOfRotation)
        {
        case RoadRotationType.Green:
            myAnimator.SetBool("Next", true);
            StartingGreenRotation = StartingGreenRotation.Next();
            _direction            = StartingGreenRotation.toRoadDirection();
            break;

        case RoadRotationType.Blue:
            myAnimator.SetBool("Next", true);
            StartingGreenRotation = StartingGreenRotation.Next();
            StartingBlueRotation  = StartingGreenRotation.GreenToBlue();
            _direction            = StartingBlueRotation.toRoadDirection();
            break;

        case RoadRotationType.Purple:
            roadStartingPurple = roadStartingPurple.NextPurpleCardinalPoint(roadAnchorPurple, ref purpleDirection);
            direction          = RoadDirectionExtensions.ComposeRoadDirection(roadAnchorPurple, roadStartingPurple);
            TurnOffAllSprites();
            if (direction == RoadDirection.EW || direction == RoadDirection.NS)
            {
                RecalculateSprites(RoadDirectionExtensions.ComposeRoadDirection(roadAnchorPurple, roadStartingPurple.NextPurpleCardinalPoint(roadAnchorPurple, ref purpleDirection)));
            }
            break;

        case RoadRotationType.Gold:
            direction = possibleGoldRotations[0];
            possibleGoldRotations.RemoveAt(0);
            possibleGoldRotations.Add(direction);
            RecalculateSprites();
            break;

        default:
            break;
        }
    }
Example #9
0
    public static RoadDirection ComposeRoadDirection(RoadPositionPurple A, RoadPositionPurple B)
    {
        List <RoadDirection> result = new List <RoadDirection>();
        RoadDirection        dummy  = RoadDirection.NEWS;

        result = dummy.GetAll().FindAll(x => x.HasDirection(A.ToCardinalPoint()) && x.HasDirection(B.ToCardinalPoint()));
        result.Remove(RoadDirection.NEWS);
        return(result[0]);
    }
Example #10
0
    /// <summary>
    /// Initializes the starting position of the animator if the road is Clickable
    /// and other things
    /// </summary>
    void InitializeAnimator()
    {
        TurnOffAllSprites();
        if (!isClickable || myAnimator == null)
        {
            return;
        }
        switch (TypeOfRotation)
        {
        case RoadRotationType.Green:
            _direction = StartingGreenRotation.toRoadDirection();
            ChangeVisuals(RoadDirection.NE);
            if (myAnimator.GetCurrentAnimatorStateInfo(0).IsName("90_" + greenDirtoString(StartingGreenRotation) + "_state"))
            {
                break;
            }
            myAnimator.SetBool("NoAnim", true);
            myAnimator.SetBool("GoTo" + greenDirtoString(StartingGreenRotation), true);


            break;

        case RoadRotationType.Blue:
            _direction            = StartingBlueRotation.toRoadDirection();
            StartingGreenRotation = StartingBlueRotation.BlueToGreen();
            ChangeVisuals(RoadDirection.EW);
            if (myAnimator.GetCurrentAnimatorStateInfo(0).IsName("90_" + greenDirtoString(StartingBlueRotation.BlueToGreen()) + "_State"))
            {
                break;
            }
            myAnimator.SetBool("NoAnim", true);
            myAnimator.SetBool("GoTo" + greenDirtoString(StartingBlueRotation.BlueToGreen()), true);
            break;

        case RoadRotationType.Purple:
            //This is "not" animator, but it's an initializatin needed for Purple type of clickable roads
            if (roadAnchorPurple == roadStartingPurple)
            {
                roadStartingPurple = roadStartingPurple.NextPurpleCardinalPoint(roadAnchorPurple, ref purpleDirection);
            }
            direction = RoadDirectionExtensions.ComposeRoadDirection(roadAnchorPurple, roadStartingPurple);
            RecalculateSprites(RoadDirectionExtensions.ComposeRoadDirection(roadAnchorPurple, roadStartingPurple.NextPurpleCardinalPoint(roadAnchorPurple, ref purpleDirection)));
            break;

        case RoadRotationType.Gold:

            direction = possibleGoldRotations[0];
            possibleGoldRotations.RemoveAt(0);
            possibleGoldRotations.Add(direction);
            RecalculateSprites();
            break;

        default:
            break;
        }
    }
Example #11
0
        public void SetTypeAndDirection(RoadType type, RoadDirection direction, bool link_wps = true)
        {
            SetType(type);
            SetDirection(direction);

            if (link_wps)
            {
                LinkWayPoints();
            }
        }
Example #12
0
 public bool           isActive; //Gets passed to false when hit
 //Contructor
 public Roads(bool act)
 {
     type      = RoadType.m_null;
     direction = RoadDirection.m_null;
     rotation  = Quaternion.Euler(0, 0, 0);
     pos       = new Vector2(0, 0);
     m_GameObjectPrefabType = null;
     m_GameObjectInstance   = null;
     m_renderer             = null;
     isActive = act;
 }
Example #13
0
        public void setState(TownBuilder builder)
        {
            gameObject.transform.position = builder.Position;
            gameObject.transform.rotation = builder.Quaternion;

            this.direction = builder.Direction;
            layRoad();

            this.id            = builder.Id;
            this.level         = builder.Level;
            this.size          = builder.Size;
            this.priseMag      = builder.PriseMag;
            this.clients       = builder.Clients;
            this.merchants     = builder.Merchants;
            this.citizens      = builder.Citizens;
            this.attributeMag  = builder.AttributeMag;
            this.grid          = builder.Grid;
            this.buildingDatas = builder.BuildingDatas;

            this.attribute = TownAttributeMasterManager.getInstance().getTownAttributeFromId(builder.TownAttributeId);

            Debug.Log("attributeMag count " + attributeMag.Count);

            foreach (var buildingData in buildingDatas)
            {
                var building = buildingData.restore();
                buildings.Add(building);
                building.transform.SetParent(transform);
            }

            characters.AddRange(citizens);

            foreach (Merchant merchant in merchants)
            {
                merchant.setTown(this);
            }
            characters.AddRange(merchants);

            characters.AddRange(clients);

            foreach (IFriendly friendlyCharacter in characters)
            {
                friendlyCharacter.getContainer().transform.SetParent(transform);
            }

            observer = new TownObserver(this);
        }
Example #14
0
        public virtual bool IsRoadDirectionAccessable(Feature feature, RoadDirection roadDirection)
        {
            // Todo: check one-way roads is right to the specific direction.
            bool   isRoadDirectionAccessable = false;
            string onewayValue = feature.ColumnValues["oneway"];

            if (String.Compare(onewayValue.Trim(), "1", true, CultureInfo.InvariantCulture) == 0)
            {
                isRoadDirectionAccessable = true;
            }
            else
            {
                isRoadDirectionAccessable = false;
            }

            return(isRoadDirectionAccessable);
        }
Example #15
0
		private RoadCreateResult CreateRoad(RoadDirection roadDirection, Vector3 startPosition, int length, int offset = 0) {
			var managerRoads = this.GetManager<ManagerRoads>();
			
			Quaternion roadRotation = Quaternion.identity;
			Vector3 roadAddPositionDirection = Vector3.zero;
			switch (roadDirection) {
				case RoadDirection.Up:
					roadRotation = Quaternion.Euler(0, 90, 0);
					roadAddPositionDirection = new Vector3(0, 0, 1);
					break;
				case RoadDirection.Down:
					roadRotation = Quaternion.Euler(0, 90, 0);
					roadAddPositionDirection = new Vector3(0, 0, -1);
					break;
				case RoadDirection.Right:
					roadRotation = Quaternion.Euler(0, 0, 0);
					roadAddPositionDirection = new Vector3(1, 0, 0);
					break;
				case RoadDirection.Left:
					roadRotation = Quaternion.Euler(0, 0, 0);
					roadAddPositionDirection = new Vector3(-1, 0, 0);
					break;
			}
			
			for (int i = offset; i < length + offset; i++) {
				var controllerRoadStraight = managerRoads.CreateControllerRoadStraight(
					startPosition + new Vector3(0, 0.1f, 0) + roadAddPositionDirection * 7.62f * i
				);
				
				controllerRoadStraight.transform.localRotation = roadRotation;
			}
			
			var controllerRoadCorner = managerRoads.CreateControllerRoadCorner(
				startPosition + new Vector3(0, 0.1f, 0) + roadAddPositionDirection * 7.62f * (length + offset)
			);
			
			var cornerPosition = controllerRoadCorner.transform.position;
			return new RoadCreateResult {
				roadFinalPosition = new Vector3(
					cornerPosition.x,
					startPosition.y,
					cornerPosition.z
				),
			};
		}
Example #16
0
        private Node CreateNode(FeatureSource featureSource, RoadNetwork roadNetwork, Vertex vertex)
        {
            // Create node based on vertex.
            // Todo: check if it has been existed.
            Collection <Feature> adjacentTailNodeFeatures = GetAdjacentFeaturesOfVertex(featureSource, vertex);
            Node tailNode = InitializeNodeFromVeterx(vertex, adjacentTailNodeFeatures);

            roadNetwork.Nodes.Add(tailNode);

            // Loop and see if the queried shape is intersected with processing shape.
            foreach (Feature adjacentTailNodeFeature in adjacentTailNodeFeatures)
            {
                // Given the adjacent line is line shape, and create adjacent list without un-direction consideration.
                LineShape adjacentLineShape = GeometryHelper.GetLineShapes(adjacentTailNodeFeature)[0];
                adjacentLineShape.Id = adjacentTailNodeFeature.Id;


                // Check if it's start vertext or end vertex of the adjacent line shape.
                int vertexIndex = 0;
                if (GeometryHelper.IsSamePoint(vertex, adjacentLineShape.Vertices[adjacentLineShape.Vertices.Count - 1], tolerance))
                {
                    vertexIndex = adjacentLineShape.Vertices.Count - 1;
                }

                // Todo: check if it has been existed.
                Collection <Feature> adjacentHeadNodeFeatures = GetAdjacentFeaturesOfVertex(featureSource, adjacentLineShape.Vertices[vertexIndex]);
                Node headNode = InitializeNodeFromVeterx(adjacentLineShape.Vertices[vertexIndex], adjacentHeadNodeFeatures);
                roadNetwork.Nodes.Add(headNode);

                Arc adjacentArc = new Arc(adjacentTailNodeFeature.Id, headNode, tailNode, CalculateRoadCost(adjacentLineShape));

                // Check if the direction is the allowed of current segment?
                RoadDirection roadDirection = CalculateRoadDirection(adjacentTailNodeFeature, adjacentLineShape, vertex);
                if (roadDirection == RoadDirection.Forward)
                {
                    tailNode.OutgoingArcs.Add(adjacentArc);
                }
                else if (roadDirection == RoadDirection.Backward)
                {
                    tailNode.IncomingArcs.Add(adjacentArc);
                }
            }

            return(tailNode);
        }
Example #17
0
        public void Render(RectTransform parent, Vector2 position, Vector2 sizes)
        {
            var(unitsNumber, unitLength) = CalculateUnits(sizes);
            RoadDirection direction = sizes.x > sizes.y ? RoadDirection.ToRight : RoadDirection.ToUp;
            Vector2       unitSize  = Vector2.one * unitLength;

            foreach (var i in Enumerable.Range(0, unitsNumber))
            {
                var road          = GameObject.Instantiate(RoadPrefab, parent);
                var rectTransform = road.GetComponent <RectTransform>();
                rectTransform.anchorMin        = Vector2.zero;
                rectTransform.anchorMax        = Vector2.zero;
                rectTransform.pivot            = Vector2.zero;
                rectTransform.anchoredPosition = position;
                rectTransform.sizeDelta        = unitSize;
                position += unitLength * (direction == RoadDirection.ToRight ? Vector2.right : Vector2.up);
            }
        }
Example #18
0
    /// <summary>
    /// Devuelve un string que equivale a la dirección de una carretera
    /// </summary>
    /// <param name="road">Lacarretera</param>
    /// <returns>Un string</returns>
    public static string roadDirToString(RoadDirection road)
    {
        string s;

        switch (road)
        {
        case RoadDirection.EW:
            s = EW;
            break;

        case RoadDirection.NE:
            s = NE;
            break;

        case RoadDirection.NEWS:
            s = NEWS;
            break;

        case RoadDirection.NS:
            s = NS;
            break;

        case RoadDirection.NW:
            s = NW;
            break;

        case RoadDirection.SE:
            s = SE;
            break;

        case RoadDirection.SW:
            s = SW;
            break;

        default:
            s = "";
            break;
        }



        return(s);
    }
Example #19
0
    private RoadDirection SimplifyDirection(RoadDirection dir)
    {
        switch (dir)
        {
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////From straights to straights//////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        case RoadDirection.up: return(RoadDirection.up);

        case RoadDirection.down: return(RoadDirection.down);

        case RoadDirection.left: return(RoadDirection.left);

        case RoadDirection.right: return(RoadDirection.right);

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////From coners to straights/////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        case RoadDirection.up_to_right: return(RoadDirection.right);

        case RoadDirection.down_to_right: return(RoadDirection.right);

        case RoadDirection.up_to_left: return(RoadDirection.left);

        case RoadDirection.down_to_left: return(RoadDirection.left);

        case RoadDirection.left_to_down: return(RoadDirection.down);

        case RoadDirection.left_to_up: return(RoadDirection.up);

        case RoadDirection.right_to_down: return(RoadDirection.down);

        case RoadDirection.right_to_up: return(RoadDirection.up);
        }
        return(RoadDirection.m_null);
    }                                                                                                                             //Takes in a RoadDirection and returns the absolute last direction. Eg Returns RoadDirection.up from input RoadDirection.right_to_up
Example #20
0
    public void CheckDirection(RoadDirection newroaddirection, Turn checkTurn)
    {
        CardinalPoint newtruckdirection = direction;

        switch (newroaddirection)
        {
            #region LineasRectas
        //LineaRecta E <-> W
        case RoadDirection.EW:
            if (direction == CardinalPoint.W)
            {
                newtruckdirection = CardinalPoint.W;
            }
            if (direction == CardinalPoint.E)
            {
                newtruckdirection = CardinalPoint.E;
            }
            break;

        //LineaRecta N <-> S
        case RoadDirection.NS:
            if (direction == CardinalPoint.S)
            {
                newtruckdirection = CardinalPoint.S;
            }
            if (direction == CardinalPoint.N)
            {
                newtruckdirection = CardinalPoint.N;
            }
            break;
            #endregion

        case RoadDirection.NEWS:
            //Todavia no hay!
            break;

            #region Curvas
        case RoadDirection.NE:
            if (direction == CardinalPoint.S)
            {
                if (checkTurn != Turn.Wide)
                {
                    return;
                }
                newtruckdirection = CardinalPoint.E;
            }
            if (direction == CardinalPoint.W)
            {
                if (checkTurn != Turn.Close)
                {
                    return;
                }
                newtruckdirection = CardinalPoint.N;
            }
            break;

        case RoadDirection.NW:
            if (direction == CardinalPoint.S)
            {
                if (checkTurn != Turn.Close)
                {
                    return;
                }
                newtruckdirection = CardinalPoint.W;
            }
            if (direction == CardinalPoint.E)
            {
                if (checkTurn != Turn.Wide)
                {
                    return;
                }
                newtruckdirection = CardinalPoint.N;
            }
            break;

        case RoadDirection.SE:
            if (direction == CardinalPoint.N)
            {
                if (checkTurn != Turn.Close)
                {
                    return;
                }
                newtruckdirection = CardinalPoint.E;
            }
            if (direction == CardinalPoint.W)
            {
                if (checkTurn != Turn.Wide)
                {
                    return;
                }
                newtruckdirection = CardinalPoint.S;
            }
            break;

        case RoadDirection.SW:
            if (direction == CardinalPoint.N)
            {
                if (checkTurn != Turn.Wide)
                {
                    return;
                }
                newtruckdirection = CardinalPoint.W;
            }
            if (direction == CardinalPoint.E)
            {
                if (checkTurn != Turn.Close)
                {
                    return;
                }
                newtruckdirection = CardinalPoint.S;
            }
            break;

            #endregion
        default:
            break;
        }



        if (direction != newtruckdirection)
        {
            ChangeDirection(newtruckdirection, checkTurn);
        }
        direction = newtruckdirection;
    }
Example #21
0
        public virtual bool IsRoadDirectionAccessable(Feature feature, RoadDirection roadDirection)
        {
            // Todo: check one-way roads is right to the specific direction.
            bool isRoadDirectionAccessable = false;
            string onewayValue = feature.ColumnValues["oneway"];
            if (String.Compare(onewayValue.Trim(), "1", true, CultureInfo.InvariantCulture) == 0)
            {
                isRoadDirectionAccessable = true;
            }
            else
            {
                isRoadDirectionAccessable = false;
            }

            return isRoadDirectionAccessable;
        }
Example #22
0
    /// <summary>
    /// Selecciona que Sprites deben estar activados en función de si la carretera se puede mover.
    /// </summary>
    public void RecalculateSprites(RoadDirection RdPurple = RoadDirection.NEWS)
    {
        TurnOffAllSprites();
        if (TypeOfRotation != RoadRotationType.Gold && TypeOfRotation != RoadRotationType.Purple)
        {
            return;
        }
        RoadDirection currentState = direction;
        RoadDirection nextState    = RoadDirection.NEWS;

        if (TypeOfRotation == RoadRotationType.Gold)
        {
            nextState = possibleGoldRotations[0];
        }
        if (TypeOfRotation == RoadRotationType.Purple)
        {
            if (RdPurple == RoadDirection.NEWS)
            {
                return;
            }
            nextState = RdPurple;
        }
        if (nextState == RoadDirection.NEWS)
        {
            return;
        }
        CardinalPoint[]      differences;
        CardinalPoint[]      equals  = currentState.Compare(nextState, out differences, true);
        List <CardinalPoint> changed = new List <CardinalPoint>();

        foreach (CardinalPoint dir in differences)
        {
            if (dir != CardinalPoint.None)
            {
                TurnOnArrow(dir);
                changed.Add(dir);
            }
        }
        if (TypeOfRotation == RoadRotationType.Purple)
        {
            return;
        }
        foreach (CardinalPoint dir1 in equals)
        {
            if (dir1 != CardinalPoint.None)
            {
                TurnOnEquals(dir1);
                changed.Add(dir1);
            }
        }
        if (possibleGoldRotations.Count <= 2 || TypeOfRotation != RoadRotationType.Gold)
        {
            return;
        }
        RoadDirection AfterState = possibleGoldRotations[1];

        equals = nextState.Compare(AfterState, out differences, true);
        foreach (CardinalPoint dir in differences)
        {
            if (dir != CardinalPoint.None && (changed.Contains(dir) == false))
            {
                //TurnOnArrowTrans(dir);
                changed.Add(dir);
            }
        }
    }
Example #23
0
        public override GameObject GetModel()
        {
            if (!_cachedPrefabs)
            {
                LoadRoadPrefabs();
            }
            //We need to know if we have roads in 4 tile positions around this tile.
            //Example: We are #, tiles we want are N S E W.
            //   5 - - - - -
            //   4 - - N - -
            //   3 - W # E -
            //   2 - - S - -
            // y 1 - - - - -
            //   x 0 1 2 3 4
            //If a tile doesnt exist, wrong type or is out of bounds, it counts as a false reading.

            //Get if we have roads or not in the 4 tile positions;
            RoadDirection roadD = new RoadDirection();

            roadD.N = CheckTileForRoad(new Vector2Int(0, 1));
            roadD.E = CheckTileForRoad(new Vector2Int(1, 0));
            roadD.S = CheckTileForRoad(new Vector2Int(0, -1));
            roadD.W = CheckTileForRoad(new Vector2Int(-1, 0));

            int numTrue = 0;

            if (roadD.N)
            {
                numTrue++;
            }
            if (roadD.E)
            {
                numTrue++;
            }
            if (roadD.S)
            {
                numTrue++;
            }
            if (roadD.W)
            {
                numTrue++;
            }

            //Check for road positions and decide what model to use and how to transform it (if at all).
            //We currently have to check for all 15 possible variations. Can be made more efficient but wont be very readable.

            if (numTrue == 1)
            {
                //One road piece
                if (roadD.N && !roadD.E && !roadD.S && !roadD.W)
                {
                    _yRotationToApply = 90;
                    return(RoadPrefabs[0]);
                }
                if (!roadD.N && roadD.E && !roadD.S && !roadD.W)
                {
                    return(RoadPrefabs[0]);
                }
                if (!roadD.N && !roadD.E && roadD.S && !roadD.W)
                {
                    _yRotationToApply = 90;
                    return(RoadPrefabs[0]);
                }
                if (!roadD.N && !roadD.E && !roadD.S && roadD.W)
                {
                    return(RoadPrefabs[0]);
                }
            }
            else if (numTrue == 2)
            {
                //Two road pieces
                if (roadD.N && !roadD.E && roadD.S && !roadD.W)
                {
                    _yRotationToApply = 90;
                    return(RoadPrefabs[0]);
                }
                if (!roadD.N && roadD.E && !roadD.S && roadD.W)
                {
                    return(RoadPrefabs[0]);
                }
                if (roadD.N && roadD.E && !roadD.S && !roadD.W)
                {
                    _yRotationToApply = 90;
                    return(RoadPrefabs[3]);
                }
                if (!roadD.N && roadD.E && roadD.S && !roadD.W)
                {
                    _yRotationToApply = 180;
                    return(RoadPrefabs[3]);
                }
                if (!roadD.N && !roadD.E && roadD.S && roadD.W)
                {
                    _yRotationToApply = -90;
                    return(RoadPrefabs[3]);
                }
                if (roadD.N && !roadD.E && !roadD.S && roadD.W)
                {
                    return(RoadPrefabs[3]);
                }
            }
            else if (numTrue == 3)
            {
                //Three road pieces
                if (!roadD.N && roadD.E && roadD.S && roadD.W)
                {
                    _yRotationToApply = -90;
                    return(RoadPrefabs[2]);
                }
                if (roadD.N && !roadD.E && roadD.S && roadD.W)
                {
                    return(RoadPrefabs[2]);
                }
                if (roadD.N && roadD.E && !roadD.S && roadD.W)
                {
                    _yRotationToApply = 90;
                    return(RoadPrefabs[2]);
                }
                if (roadD.N && roadD.E && roadD.S && !roadD.W)
                {
                    _yRotationToApply = 180;
                    return(RoadPrefabs[2]);
                }
            }

            //If none are true, return the 4 way piece
            return(RoadPrefabs[1]);
        }
Example #24
0
    /// <summary>
    /// Cambia el material de la carretera
    /// </summary>
    /// <param name="dir"></param>
    public void ChangeVisuals(RoadDirection dir, GraphicQualitySettings GQS = GraphicQualitySettings.None, string LowIMGPath = "")
    {
        if (isClickable && TypeOfRotation == RoadRotationType.Green)
        {
            dir = RoadDirection.NE;
        }
        if (isClickable && TypeOfRotation == RoadRotationType.Blue)
        {
            dir = RoadDirection.EW;
        }
        if (LowIMGPath == "")
        {
            if (GameConfig.s == null)
            {
                LowIMGPath = "IMG\\LowIMGs\\";
            }
            if (GameConfig.s != null)
            {
                LowIMGPath = GameConfig.s.LowIMGPath;
            }
        }
        if (GQS == GraphicQualitySettings.None)
        {
            if (sProfileManager.ProfileSingleton == null)
            {//we are probably at editor time, we change all roads
                ChangeVisuals(dir, GraphicQualitySettings.High, LowIMGPath);
                ChangeVisuals(dir, GraphicQualitySettings.Low, LowIMGPath);
                //Debug.Log("ChangingVisuals: EditorTime");
                return;
            }
            else
            {
                //Debug.Log("ChangingVisuals: PlayTime");
                GQS = sProfileManager.ProfileSingleton.GlobalGraphicQualitySettings;
            }
        }
        else
        {
            //Debug.Log("ChangingVisuals: PlayTime 2 "+ dir.ToString());
        }

        if (PermanentVisuals)
        {
            return;
        }
        switch (GQS)
        {
        case GraphicQualitySettings.Low:
            //Low Quality using old Materials
            Sprite sprite = (Sprite)Resources.Load <Sprite>(LowIMGPath + "sprite_" + roadDirToString(dir));
            if (myRoadLow != null)
            {
                myRoadLow.sprite = sprite;
            }


            break;

        case GraphicQualitySettings.Medium:
            Sprite sprite1 = (Sprite)Resources.Load <Sprite>(LowIMGPath + "sprite_" + roadDirToString(dir));
            if (myRoadLow != null)
            {
                myRoadLow.sprite = sprite1;
            }
            break;

        case GraphicQualitySettings.High:
            //High Quality using PicaVoxel
            if (myRoad != null)
            {
                myRoad.SetFrame((int)dir);
            }

            break;

        default:
            break;
        }
    }
Example #25
0
 public Road(int row, int column, RoadDirection roadDirection)
 {
     Row           = row;
     Column        = column;
     RoadDirection = roadDirection;
 }
Example #26
0
    private bool CheckCollision(RoadDirection dir, Vector2 pos, Vector2[] roadsPos, ref Vector2 m_checked)
    {
        Vector2 CheckedPos;
        bool    found;

        switch (dir)
        {
        case RoadDirection.up:
            CheckedPos = new Vector2(pos.x, pos.y + inGameUnitsSize); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.down:
            CheckedPos = new Vector2(pos.x, pos.y - inGameUnitsSize); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.right:
            CheckedPos = new Vector2(pos.x + inGameUnitsSize, pos.y); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.left:
            CheckedPos = new Vector2(pos.x - inGameUnitsSize, pos.y); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.left_to_up:
            CheckedPos = new Vector2(pos.x, pos.y + inGameUnitsSize); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.right_to_up:
            CheckedPos = new Vector2(pos.x, pos.y + inGameUnitsSize); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.left_to_down:
            CheckedPos = new Vector2(pos.x, pos.y - inGameUnitsSize); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.right_to_down:
            CheckedPos = new Vector2(pos.x, pos.y - inGameUnitsSize); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.down_to_right:
            CheckedPos = new Vector2(pos.x + inGameUnitsSize, pos.y); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.up_to_right:
            CheckedPos = new Vector2(pos.x + inGameUnitsSize, pos.y); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.down_to_left:
            CheckedPos = new Vector2(pos.x - inGameUnitsSize, pos.y); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);

        case RoadDirection.up_to_left:
            CheckedPos = new Vector2(pos.x - inGameUnitsSize, pos.y); m_checked = CheckedPos;
            found      = CheckVecArray(CheckedPos, roadsPos);
            return(found);
        }
        return(false);
    }
Example #27
0
        public void SetDirection(RoadDirection direction)
        {
            ArgumentException AE = new ArgumentException("Direction \"" + direction.ToString() + "\" is not compatible with road type " + this.type.ToString() + ".");

            switch (this.type)
            {
            case RoadType.Straight:
                if (direction == RoadDirection.Vertical)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 0);
                }
                else if (direction == RoadDirection.Horizontal)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 270);
                }
                else
                {
                    throw AE;
                }
                break;

            case RoadType.End:
                if (direction == RoadDirection.North)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 180);
                }
                else if (direction == RoadDirection.South)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 0);
                }
                else if (direction == RoadDirection.East)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 90);
                }
                else if (direction == RoadDirection.West)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 270);
                }
                else
                {
                    throw AE;
                }
                break;

            case RoadType.Corner:
                if (direction == RoadDirection.NorthEast)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 90);
                }
                else if (direction == RoadDirection.NorthWest)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 180);
                }
                else if (direction == RoadDirection.SouthEast)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 0);
                }
                else if (direction == RoadDirection.SouthWest)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 270);
                }
                else
                {
                    throw AE;
                }
                break;

            case RoadType.Cross_T:
                if (direction == RoadDirection.North)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 90);
                }
                else if (direction == RoadDirection.South)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 270);
                }
                else if (direction == RoadDirection.East)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 0);
                }
                else if (direction == RoadDirection.West)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 180);
                }
                else
                {
                    throw AE;
                }
                break;

            case RoadType.Cross_X:
                if (direction != RoadDirection.None)
                {
                    throw AE;
                }
                break;

            case RoadType.Single:
                if (direction == RoadDirection.None)
                {
                    transform.localEulerAngles = new Vector3(90, 0, 0);
                }
                else
                {
                    throw AE;
                }
                break;
            }
            this.direction = direction;

            //SetPoints();
        }
Example #28
0
 public static string ToAddress(this RoadDirection direction)
 {
     return($"Assets/Tileset/{direction.ToString().ToLowerKebabCase()}.asset");
 }
 public static bool IsSouth(this RoadDirection value)
 {
     return(value == RoadDirection.SE || value == RoadDirection.SW);
 }
Example #30
0
 public RoadDirectionChangeCommand(Ground ground, RoadDirection oldDirection, RoadDirection newDirection)
 {
     this.ground       = ground;
     this.oldDirection = oldDirection;
     this.newDirection = newDirection;
 }
 public static bool IsNorth(this RoadDirection value)
 {
     return(value == RoadDirection.NE || value == RoadDirection.NW);
 }