/// <summary>
        /// De hoofdfunctie van de pathfinding.
        /// </summary>
        /// <param name="a">Start positie als AstarObject</param>
        /// <param name="b">Eind positie als AstarObject</param>
        /// <param name="T"> Het type weg waarin hij moet zoeken</param>
        /// <returns></returns>
        List<Point> FindRoadPath(Road a, Road b, RoadType T)
        {
            AstarObject[,] Set = new AstarObject[14, 9];
            for (int x = 0; x < 14; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    Set[x, y] = new AstarObject(x, y, this);
                }
            }

            Heap<AstarObject> OpenSet = new Heap<AstarObject>(14 * 9);
            HashSet<AstarObject> ClosedSet = new HashSet<AstarObject>();
            AstarObject Start = Set[a.X, a.Y];
            AstarObject End = Set[b.X, b.Y];
            OpenSet.Add(Start);

            while (OpenSet.Count > 0)
            {
                AstarObject CurrentLocation = OpenSet.RemoveFirst();

                ClosedSet.Add(CurrentLocation);

                if (CurrentLocation == End)
                {
                    return RetracePath(Start, End);
                    //Retracepath and stuff.
                }

                List<AstarObject> Neighbours = GetNeighbours(CurrentLocation, ref Set, NeighbourhoodType.Neumann, MapsizeXR, MapsizeYR);
                foreach (AstarObject neighbour in Neighbours)
                {
                    if (neighbour.RType != T || ClosedSet.Contains(neighbour))
                    {
                        continue;
                    }

                    int newMovementCostToNeighbour = CurrentLocation.gCost + GetDistance(CurrentLocation, neighbour);
                    if (newMovementCostToNeighbour < neighbour.gCost || !OpenSet.Contains(neighbour))
                    {
                        neighbour.gCost = newMovementCostToNeighbour;
                        neighbour.hCost = GetDistance(neighbour, End);
                        neighbour.parent = CurrentLocation;

                        if (!OpenSet.Contains(neighbour))
                        {
                            OpenSet.Add(neighbour);
                        }
                        else
                        {
                            OpenSet.UpdateItem(neighbour);
                        }

                    }

                }

            }
            return new List<Point>();
        }
Exemple #2
0
    public void RegisterRoad(Road r)
    {
        if (connectedRoads.Contains(r))
            return;

        connectedRoads.Add(r);
    }
Exemple #3
0
 IEnumerator RUNLerp(Vector3 start,Vector3 end, bool firstRoad)
 {
     endRoad.SetFilled (speed);
     startTime = Time.time;
     journeyLength = Vector3.Distance(start, end);
     while (Vector3.Distance (gameObject.transform.position, end) >= 0.01f) {
         float distCovered = (Time.time - startTime) * speed;
         float fracJourney = distCovered / journeyLength;
         transform.position = Vector3.Lerp (start, end, fracJourney);
         yield return null;
     }
     if (!firstRoad) {
         previousRoad.SetNotFilled();
     }
     startMarker = endMarker;
     endMarker = endRoad.adjRoads [0, 1].WaypointPos();
     previousRoad = endRoad;
     endRoad = endRoad.adjRoads [0, 1];
     if (endRoad.adjRoads [0, 1] == null) {
         endRoad.SetNotFilled();
         previousRoad.SetNotFilled();
         Destroy (gameObject);
     }
     else if (endRoad.CheckFilled () < 0) {
         speed = 0;
         previousRoad.SetFilled (-1);
         yield return null;
     }
     else if (endRoad.CheckFilled () != 0) {
         speed = endRoad.CheckFilled ();
         yield return StartCoroutine (ChangeLanes ());
     } else {
         StartCoroutine (RUNLerp (startMarker, endMarker, false));
     }
 }
        public Road CreateRoad(String name)
        {
            Road road = new Road(name, this);

            roads.Add(road);

            return road;
        }
    Road[] CreateNewRoad(int number)
    {
        Road[] newRoads = new Road[number];
        for (int i = 0; i < number; i++)
        {
            newRoads[i] = Instantiate (this.CreateNewRoad());
        }

        return newRoads;
    }
Exemple #6
0
    public void createStartEndPair(Quaternion garageRotate, Vector3 startPos, Vector3 endPos, int spawnCount, int spawnSpan, Color carColor, Road r)
    {
        Vector3 offset;
        Vector3 scale = new Vector3 (0.5f, 0.5f, 1.0f);

        if (garageRotate == Quaternion.identity) {
            offset = new Vector3 (0.25f, 0f, 0f);
        } else {
            offset = new Vector3 (0f, -0.25f, 0f);
        }

        // instantiate start position for upward-moving cars
        GameObject StartPointObject = (GameObject)Resources.Load ("StartPoint");
        StartPointObject.tag = levelObjTag;
        GameObject garage = Instantiate (StartPointObject, startPos + offset, garageRotate) as GameObject;
        garage.transform.localScale = scale;

        StartCars sc = garage.GetComponent<StartCars> ();
        sc.road = r;
        sc.moveInDirection ((endPos - startPos).normalized);
        sc.setSpawnCount (spawnCount);
        sc.setSpawnSpan (spawnSpan);
        sc.setColor (carColor);
        simObjects.Add (sc);
        road.GetComponent<Road> ().points.Add (garage);

        // Repeat for downward-moving cars
        garage = Instantiate (StartPointObject, endPos - offset, garageRotate) as GameObject;
        garage.transform.localScale = scale;
        sc = garage.GetComponent<StartCars> ();
        sc.road = r;
        sc.moveInDirection (-(endPos - startPos).normalized);
        sc.setSpawnCount (spawnCount);
        sc.setSpawnSpan (spawnSpan);
        sc.setColor (carColor);
        simObjects.Add (sc);
        road.GetComponent<Road> ().points.Add (garage);

        // instantiate end position
        GameObject endPoint = (GameObject)Resources.Load ("EndPoint");
        endPoint.tag = levelObjTag;
        GameObject lot = Instantiate (endPoint, endPos + offset, Quaternion.identity) as GameObject;
        lot.transform.localScale = scale;
        EndPoint parking = lot.GetComponent<EndPoint> ();
        parking.setColor (carColor);
        road.GetComponent<Road> ().points.Add (lot);

        lot = Instantiate (endPoint, startPos - offset, Quaternion.identity) as GameObject;
        lot.transform.localScale = scale;
        parking = lot.GetComponent<EndPoint> ();
        parking.setColor (carColor);
        road.GetComponent<Road> ().points.Add (lot);
    }
    public override GameObject CreateRoad(Road oldRoad)
    {
        GameObject go = base.CreateRoad(oldRoad);

        RoadCorner sample_corner = GameObject.Find("buildRoadCornerHighlight").GetComponent<RoadCorner>();

        roadMaterialCornerTwo = sample_corner.roadMaterialCornerTwo;
        roadMaterialCornerThree = sample_corner.roadMaterialCornerThree;
        roadMaterialCornerFour = sample_corner.roadMaterialCornerFour;

        return go;
    }
Exemple #8
0
        public void Execute(CommandContext context)
        {
            if (!context.Game.Board.RoadGraph
                     .GetNeighbors(context.TargetEdge)
                     .Any(edge =>
                          edge.Has<Road>()
                          && context.Player.Roads.Contains(edge.Get<Road>())))
                throw new Exception("Target road must be adjacent to another road");

            var road = new Road();

            context.Player.Roads.Add(road);
            context.TargetEdge.Add(road);
        }
        public void DrawRoads()
        {
            Roads = new Road[2];
            Roads[0] = new Road(this, HLane, 'H');
            Roads[1] = new Road(this, VLane, 'V');

            //Create the Intersection Block in the Middle
            block = new IntersectionBlock(this);
            block.Location = new Point(Roads[1].Location.X, Roads[0].Location.Y);
            block.Width = Roads[1].Width;
            block.Height = Roads[0].Height;
            block.BackColor = Color.Black;
            block.SendToBack();
        }
Exemple #10
0
 public void roadClicked(Road r)
 {
     if (simMode) {
         if (currSelectedRoad == r) {
             r.renderer.material.color = Constants.grey;
             currSelectedRoad = null;
             return;
         }
         if (currSelectedRoad != null) {
             currSelectedRoad.renderer.material.color = Constants.grey;
         }
         currSelectedRoad = r;
         currSelectedRoad.renderer.material.color = Constants.selectedGrey;
     }
 }
Exemple #11
0
 IEnumerator ChangeLanes()
 {
     if (endRoad.adjRoads [0, 0] != null && endRoad.adjRoads [0, 0].CheckFilled () == 0 && endRoad.adjRoads [1, 0].CheckFilled () == 0) {
         previousRoad.SetNotFilled ();
         endMarker = endRoad.adjRoads [0, 0].WaypointPos ();
         previousRoad = endRoad;
         endRoad = endRoad.adjRoads [0, 0];
         speed = normalSpeed;
         yield return StartCoroutine (RUNLerp (startMarker, endMarker, false));
     } else if (endRoad.adjRoads [0, 2] != null && endRoad.adjRoads [0, 2].CheckFilled () == 0 && endRoad.adjRoads [1, 2].CheckFilled () == 0) {
         previousRoad.SetNotFilled ();
         endMarker = endRoad.adjRoads [0, 2].WaypointPos ();
         previousRoad = endRoad;
         endRoad = endRoad.adjRoads [0, 2];
         speed = normalSpeed;
         yield return StartCoroutine (RUNLerp (startMarker, endMarker, false));
     } else {
         StartCoroutine (RUNLerp (startMarker, endMarker, false));
     }
 }
Exemple #12
0
        public void OnStreet(int x, int y, int z, Map map)
        {
            if (Active)
            {
                return;
            }
            Active = true;
            X      = x;
            Y      = y;
            Z      = z;
            Map    = map;

            Roads = new Road[0];
            Road road = new Road(X, Y, Z);

            road.Add(new Point3D(X, Y, Z));
            Add(road);
            OnStreet(road, null);
            Active = false;
        }
    /// <summary>
    /// Processes the node.
    /// </summary>
    /// <param name="currentTile">The current tile.</param>
    private void ProcessNode(Tile currentTile)
    {
        // Check if placed object is a road
        Node node = currentTile.gameObject.GetComponent <Node>();
        Road road = _go.GetComponent <Road>();

        if (node == null || road == null)
        {
            return;
        }

        // Find the map tile Node underneath the current Node and set it's traversability
        node.TraversableUp    = road.TraversableUp;
        node.TraversableDown  = road.TraversableDown;
        node.TraversableLeft  = road.TraversableLeft;
        node.TraversableRight = road.TraversableRight;

        // Update map
        GameObject.Find("Game").GetComponent <RoadPathFinder>().UpdateMap();
    }
Exemple #14
0
        private void UpdateCarPositionOnRoad(Road road, LinkedListNode <Car> n)
        {
            var prev = n.Previous;
            //pos of prev car
            var prevPos       = prev == null ? 1000 : prev.Value.PosAlongRoad;
            var prevCarLength = prev == null ? 0 : prev.Value.Length;
            var car           = n.Value;
            var pos           = car.PosAlongRoad;

            if (pos + car.Speed > prevPos - prevCarLength) //пробка, стоим
            {
                return;
            }

            //если мы уже доехали до перекрестка...
            if (car.PosAlongRoad + car.Speed >= 1)
            {
                //выбираем случайным образом следующую дорогу
                road = road.To.RoadsOut.Count <= 1
                    ? road.To.RoadsOut.First.Value
                    : road.To.RoadsOut.Where(r => r.To != road.From).GetRnd();
                //если дорога не заполнена - выезжаем на нее
                var prevCar = road.Cars.Last;
                if (prevCar == null || prevCar.Value.PosAlongRoad - prevCar.Value.Length > 0)
                {
                    n.List.Remove(n);
                    road.Cars.AddLast(car);
                    car.PosAlongRoad = 0;
                }
            }
            else
            {
                //едем вдоль текущей дороги
                car.PosAlongRoad = car.PosAlongRoad + car.Speed;
            }

            var p1 = new PointF(road.From.CellX, road.From.CellY);
            var p2 = new PointF(road.To.CellX, road.To.CellY);

            car.Position = p1.Lerp(p2, car.PosAlongRoad);
        }
Exemple #15
0
        internal static void BuildSamplesInsideLaneSection(
            Road road, int laneId, int numSamplesSection, int outputIdx, TraversalDirection samplingDirection,
            ref SamplingStateRoad samplingState, ref NativeArray <PointSampleGlobal> samplesOut)
        {
            var numSamplesOut    = samplesOut.Length;
            var numEdgesToSample = math.abs(laneId);
            var numSamplesEdge   = numEdgesToSample == 0 ? numSamplesOut : numSamplesOut * numEdgesToSample;
            // We will need to sample the center line as well, if we are not between two lane edges
            var shouldSampleCenter = numEdgesToSample <= 1;
            var samplesEdges       = new NativeArray <PointSampleGlobal>(numSamplesEdge, Allocator.Temp);
            var side         = ToSide(laneId);
            var sectionStart = samplingDirection == TraversalDirection.Forward ? outputIdx : numSamplesSection + outputIdx - 1;

            for (var sampleNum = 0; sampleNum < numSamplesSection; sampleNum++)
            {
                var sampleIdx = sectionStart + sampleNum * (int)samplingDirection;
                var sRoad     = samplingState.sRoadLastComputed;
                SampleLanesOneSide(road, samplingState, side, sRoad, sampleIdx, ref samplesEdges,
                                   numEdgesToSample);
                // Lane index is lane ID - 1 because ID's start at 1, not 0
                var            laneSampleIdx = ComputeLaneSampleIdx(numEdgesToSample - 1, numSamplesOut, sampleIdx);
                var            poseOuterEdge = samplesEdges[laneSampleIdx].pose;
                RigidTransform poseInnerEdge;
                if (shouldSampleCenter)
                {
                    poseInnerEdge = SampleCenter(road, samplingState, sRoad).pose;
                }
                else
                {
                    var innerEdgeIdx = ComputeLaneSampleIdx(numEdgesToSample - 2, numSamplesOut, sampleIdx);
                    poseInnerEdge = samplesEdges[innerEdgeIdx].pose;
                }
                var positionMean = math.lerp(poseInnerEdge.pos, poseOuterEdge.pos, 0.5f);
                var rotationMean = math.nlerp(poseInnerEdge.rot, poseOuterEdge.rot, 0.5f);
                samplesOut[sampleIdx] = new PointSampleGlobal(rotationMean, positionMean);

                samplingState.Step(road);
            }

            samplesEdges.Dispose();
        }
Exemple #16
0
        private static void GetRandomCell(ref ICell cell, int y, int x)
        {
            switch (random.Next(0, 8))
            {
            case 0:
            {
                cell = new Coin()
                {
                    Y = y, X = x
                };
                break;
            }

            case 1:
            case 2:
            case 3:
            case 4:
            {
                cell = new Road()
                {
                    Y = y, X = x
                };
                break;
            }

            case 5:
            case 6:
            case 7:
            {
                cell = new Wall()
                {
                    Y = y, X = x
                };
                break;
            }

            default:
                break;
            }
            cells[y, x] = cell;
        }
    private static bool possibleToBuildRoad(Road road, Player player, Map map)
    {
        GameObject from = map.getTown(road.From.ToString());
        GameObject to   = map.getTown(road.To.ToString());

        bool hasTownFrom = from != null && from.GetComponent <Town>().Owner == player.Index;
        bool hasTownTo   = to != null && to.GetComponent <Town>().Owner == player.Index;
        bool hasTownNear = hasTownFrom || hasTownTo;

        List <GameObject> neighboursFrom = map.townNeighbors(from.GetComponent <Town>().Coord);
        List <GameObject> neighboursTo   = map.townNeighbors(to.GetComponent <Town>().Coord);

        bool hasRoadFrom = false;
        bool hasRoadTo   = false;

        //FROM
        foreach (GameObject near in neighboursFrom)
        {
            GameObject currentRoad = map.getRoad(near.GetComponent <Town>().Coord.ToString() + "-"
                                                 + from.GetComponent <Town>().Coord.ToString());
            if (currentRoad.GetComponent <Road>().Owner == player.Index)
            {
                hasRoadFrom = true;
            }
        }

        //TO
        foreach (GameObject near in neighboursTo)
        {
            GameObject currentRoad = map.getRoad(near.GetComponent <Town>().Coord.ToString() + "-"
                                                 + to.GetComponent <Town>().Coord.ToString());
            if (currentRoad.GetComponent <Road>().Owner == player.Index)
            {
                hasRoadFrom = true;
            }
        }

        bool hasRoad = hasRoadFrom || hasRoadTo;

        return(hasTownNear || hasRoad);
    }
Exemple #18
0
    public void deleteRoad(Road r)
    {
        removeRoad(r);
        Node nstart, nend;

        findNodeAt(r.curve.at(0f), out nstart);
        findNodeAt(r.curve.at(1f), out nend);

        Node[] affectedNides = { nstart, nend };
        foreach (Node n in affectedNides.ToList())
        {
            if (n.connection.Count == 0)
            {
                Destroy(allnodes[Algebra.approximate(n.position)].gameObject);
                allnodes.Remove(Algebra.approximate(n.position));
            }
            else
            {
                /*
                 * if (n.connection.Count == 2){
                 *  if (Geometry.sameMotherCurveUponIntersect(n.connection[0].First.curve, n.connection[1].First.curve)){
                 *      Road r1 = n.connection[0].First;
                 *      Road r2 = n.connection[1].First;
                 *      removeRoadWithoutChangingNodes(r1);
                 *      removeRoadWithoutChangingNodes(r2);
                 *      Destroy(allnodes[Algebra.approximate(n.position)].gameObject);
                 *      allnodes.Remove(Algebra.approximate(n.position));
                 *      Curve c2 = r1.curve.concat(r2.curve);
                 *      addPureRoad(c2, r1.laneconfigure); //TODO: deal with different lane configure
                 *  }
                 * }
                 */
                n.updateMargins();

                foreach (var r1 in n.connection)
                {
                    createRoadObject(r1);
                }
            }
        }
    }
Exemple #19
0
        internal override void Process()
        {
            List <string> streets = new List <string>();

            foreach (DataGridViewRow row in mainForm.StreetsGridView.Rows)
            {
                bool rowSelected = (bool)row.Cells[2].Value;
                if (rowSelected)
                {
                    streets.Add((string)row.Cells[0].Value);
                }
            }

            if (streets.Count > 0)
            {
                ConcurrencyUtils.SetAvailability(mainForm.AllDirectionButton, false);
                ConcurrencyUtils.SetAvailability(mainForm.ClearButton, false);
                ConcurrencyUtils.SetAvailability(mainForm.StreetViewsRequestButton, false);

                GeographiData geoData = GeographiData.Instance;
                foreach (string roadName in streets)
                {
                    Road road = geoData.Roads[roadName];
                    foreach (PolylineChunk chunk in road.PolylineChunks)
                    {
                        if (chunk.IsStreetViewsDownloaded)
                        {
                            mainForm.GMapForm.MainMapRoute.DeHighlightPolylineChunk(chunk.OverpassId, true);
                        }
                    }
                }
                downloader = controller.GetStreetViews(streets, "Data\\Chunks");

                Thread roadLoadStatusThread = new Thread(UpdateStatus);
                roadLoadStatusThread.Start();
            }
            else
            {
                ConcurrencyUtils.SetText(mainForm.ResultLabel, "Не выбрано ни одной улицы. Для загрузки панорам выберете хотябы одну улицу.");
            }
        }
        private void GenerateCross()
        {
            float scale = 10;

            rtsRenderer.Scale = scale;
            float displayWidth  = game.GraphicsDevice.DisplayMode.Width / scale;
            float displayHeight = game.GraphicsDevice.DisplayMode.Height / scale;

            float paddingHor = displayWidth / 8;
            float paddingVer = displayHeight / 8;

            Vector2             posIntersection1 = new Vector2(paddingHor, displayHeight / 2);
            FourWayIntersection intersection1    = new FourWayIntersection(posIntersection1);

            Vector2             posIntersection2 = new Vector2(displayWidth / 2, paddingVer);
            FourWayIntersection intersection2    = new FourWayIntersection(posIntersection2);

            Vector2             posIntersection3 = new Vector2(displayWidth - paddingHor, displayHeight / 2);
            FourWayIntersection intersection3    = new FourWayIntersection(posIntersection3);

            Vector2             posIntersection4 = new Vector2(displayWidth / 2, displayHeight - paddingVer);
            FourWayIntersection intersection4    = new FourWayIntersection(posIntersection4);

            Vector2             middle             = new Vector2(displayWidth / 2, displayHeight / 2);
            FourWayIntersection intersectionMiddle = new FourWayIntersection(middle);

            Road road1 = new Road(ref intersection1, ref intersectionMiddle, 3, 3, 30);
            Road road2 = new Road(ref intersection2, ref intersectionMiddle, 3, 3, 30);
            Road road3 = new Road(ref intersectionMiddle, ref intersection3, 3, 3, 30);
            Road road4 = new Road(ref intersectionMiddle, ref intersection4, 3, 3, 30);

            world.AddIntersection(intersection1);
            world.AddIntersection(intersection2);
            world.AddIntersection(intersection3);
            world.AddIntersection(intersection4);
            world.AddIntersection(intersectionMiddle);
            world.AddRoad(road1);
            world.AddRoad(road2);
            world.AddRoad(road3);
            world.AddRoad(road4);
        }
Exemple #21
0
    public void SetConnection(RoadStraight straight, Vector2 direction)
    {
        if (direction == new Vector2(0, 1))
        {
            bottomConnection = straight;
        }
        else if (direction == new Vector2(1, 0))
        {
            leftConnection = straight;
        }
        else if (direction == new Vector2(0, -1))
        {
            topConnection = straight;
        }
        else if (direction == new Vector2(-1, 0))
        {
            rightConnection = straight;
        }

        UpdateMaterials();
    }
Exemple #22
0
        //market should get its resources on its own

        /*public override bool CanAcceptItem(IVoxelHandle handle, ItemType type)
         * {
         *  if (!marketInventory.Any(e => e.ItemType == type)) return false;
         *
         *  return handle.Data.Inventory.AvailableSlots > 0 && handle.Data.Inventory.GetAmountOfType(type) < marketInventory.First(e => e.ItemType == type).MaxResourceLevel;
         * }*/

        private void tryCollect(IVoxelHandle handle)
        {
            if (handle.Data.Inventory.ItemCount == totalCapacity)
            {
                return;
            }
            var warehousesInRange = getWareHousesInRange(handle);

            foreach (var marketResource in marketInventory.Where(e => getNbItemsOfTypeOrKanban(handle.Data.Inventory, e.ItemType) < e.MaxResourceLevel))
            {
                foreach (var warehouse in warehousesInRange.Where(warehouse => warehouse.Data.Inventory.GetAmountOfType(marketResource.ItemType) > 0))
                {
                    var road = Road.IsConnected(warehouse, handle);
                    if (road != null)
                    {
                        Road.DeliverItem(road, warehouse, handle, marketResource.ItemType);
                        break;
                    }
                }
            }
        }
Exemple #23
0
    public virtual GameObject CreateRoad(Road oldRoad)
    {
        //don't forget to set layer
        this.gameObject.layer = InterfaceController.LAYER_ROAD;

        // set old properties
        nameType = oldRoad.GetType();
        roadMaterial = oldRoad.roadMaterial;

        // reflect changes in grid
        SetupPositionAndSize();
        size -= Vector2.one;
        grid_position_max -= Vector2.one;
        GridHelper.BuildGridObject (this, true);

        /*print("min array = " + array_position_min);
        print("max array = " + array_position_max);
        print("size = " + size);*/

        return this.gameObject;
    }
Exemple #24
0
        internal static void rep_path(Building b, PathTypeBuildingSkin skin)
        {
            Road road = b.GetComponent <Road>();

            if (skin.Straight)
            {
                road.Straight = skin.Straight.transform;
            }
            if (skin.Elbow)
            {
                road.Elbow = skin.Elbow.transform;
            }
            if (skin.Threeway)
            {
                road.Intersection3 = skin.Threeway.transform;
            }
            if (skin.Fourway)
            {
                road.Intersection4 = skin.Fourway.transform;
            }
        }
Exemple #25
0
    void DuplicateRoads()
    {
        List <GameObject> roadChilds = new List <GameObject>();

        if (roadsObject == null)
        {
            roadsObject = GameObject.Find("MainRoads");
        }

        GameObject duplicatedRoads = Instantiate(roadsObject);

        duplicatedRoads.name             = "Roads " + gameObject.name;
        duplicatedRoads.transform.parent = transform;

        foreach (Transform child in duplicatedRoads.transform)
        {
            Destroy(child.GetComponent <RoadCreator>());
            child.GetComponent <Road>().inEditor = false;
        }
        currentRoad = duplicatedRoads.gameObject.GetComponentInChildren <Road>();
    }
Exemple #26
0
    public virtual GameObject CreateRoad(Road oldRoad)
    {
        //don't forget to set layer
        this.gameObject.layer = InterfaceController.LAYER_ROAD;

        // set old properties
        nameType     = oldRoad.GetType();
        roadMaterial = oldRoad.roadMaterial;

        // reflect changes in grid
        SetupPositionAndSize();
        size -= Vector2.one;
        grid_position_max -= Vector2.one;
        GridHelper.BuildGridObject(this, true);

        /*print("min array = " + array_position_min);
         * print("max array = " + array_position_max);
         * print("size = " + size);*/

        return(this.gameObject);
    }
Exemple #27
0
 /*  This will find a road adjacent ( or right on, dont @ me )
  *  to the GameItem at x, y.
  *  returns 0 when no road could be found.
  */
 Road FindAdjacentRoad(int x, int y)
 {
     for (int i = x - 1; i <= x + 1; i++)
     {
         for (int j = y - 1; j <= y + 1; j++)
         {
             if (i >= 0 && i < Length && j >= 0 && j < Width)
             {
                 if (GameMap[i, j] != null)
                 {
                     Road r = GameMap[i, j].GetComponent <Road>();
                     if (r != null)
                     {
                         return(r);
                     }
                 }
             }
         }
     }
     return(null);
 }
        public void TestCreateEdge(int source, int destination)
        {
            const int  NUMBER_OF_LOCATIONS = 4;
            const int  NUMBER_OF_CELLS     = 4;
            const int  CELLSIZE            = 40;
            PictureBox EMPTY_PICTURE_BOX   = new PictureBox();

            Map map = new Map(NUMBER_OF_CELLS, CELLSIZE, EMPTY_PICTURE_BOX, NUMBER_OF_LOCATIONS);

            if (source < 0 || destination < 0 || source > map.Locations.Count - 1 || destination > map.Locations.Count - 1)
            {
                Assert.Throws <ArgumentOutOfRangeException>(() => map.Edges.Add(new Road(map.Locations[source], map.Locations[destination])));
            }
            else
            {
                map.Edges.Add(new Road(map.Locations[source], map.Locations[destination]));
                Assert.True(map.Edges.Count == 1);
                Road edge = map.Edges[0]; // As the collection should only hold 1 edge.
                Assert.True(edge.Vertex1 == map.Locations[source] && edge.Vertex2 == map.Locations[destination]);
            }
        }
Exemple #29
0
        /// <summary>
        /// 设置road线条
        /// </summary>
        /// <param name="PointX"></param>
        /// <param name="PointY"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        static void GetRoad(int PointX, int PointY, int width, int height)
        {
            int StartX1 = 0;
            int StartY1 = 0;
            int StartX2 = 0;
            int StartY2 = 0;

            StartX1 = 0;
            StartX2 = 0;
            StartY1 = 15;
            StartY2 = 35;
            int startX1 = PointX + StartX1;
            int startY1 = PointY + StartY1;
            int startX2 = PointX + StartX2;
            int startY2 = PointY + StartY2;
            var road1   = new Road(startX1, startY1, width);
            var road2   = new Road(startX2, startY2, width);

            liR.Add(road1);
            liR.Add(road2);
        }
Exemple #30
0
    public void setLastCheckPoint(Transform a_transform)
    {
        positionRoadBlock.SetPositionAndRotation(a_transform.position, a_transform.rotation);

        int index = a_transform.parent.GetSiblingIndex();

        if (index < roadManager.CheckpointList.childCount - 1)
        {
            index++;
        }

        Road      currentRoad    = currentMap.GetComponent <Road>();
        Transform nextCheckpoint = roadManager.CheckpointList.GetChild(index);

        if (nextCheckpoint.GetComponent <Checkpoint>().IsFinish&& currentRoad.Isloop)
        {
            nextCheckpoint = currentRoad.CheckpointList[0].transform;
        }

        nextCheckpointDirection = nextCheckpoint.right;
    }
Exemple #31
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            _background = Content.Load <Texture2D>("background");

            Road.LoadContent(Content, _graphics);
            FinishLine.LoadContent(Content, _graphics);

            _agentFactory.LoadContent(Content);
            _courseObjectFactory.LoadContent(Content);
            _playerFactory.LoadContent(Content);
            _dashboard.LoadContent(Content);
            if (_playSound)
            {
                _carSoundEffect.Initialize(Content);
            }

            // TEMP
            InitializeModel();

            _viewportManager.SetViewports(_players);
        }
Exemple #32
0
    public void addRoad(Road road, Vector3 position)
    {
        var x = (int)position.x;
        var z = (int)position.z;

        DestoryExistNature(position);

        var addedRoad = Instantiate(road, position, Quaternion.identity, roadsParent.transform);

        tiles[x, z].building = addedRoad;

        CorrectionRoad(x, z, true);
        ConnectRoadPath(x, z, true);

        if (roadsParent.GetComponentsInChildren <Road>().Length % 5 == 0)
        {
            vehicleController.AddAutoDriveCar();
        }

        subtractMoney(addedRoad);
    }
Exemple #33
0
        public void SetPathTo(Road end)
        {
            Queue <PathNode> goThrough = new Queue <PathNode>();
            HashSet <Road>   SeenRoads = new HashSet <Road>();

            goThrough.Enqueue(new PathNode(null, CurrentRoad));

            while (goThrough.Count > 0)
            {
                PathNode curr = goThrough.Dequeue();

                if (curr.CurrRoad == end)
                {
                    PathNode endNode = curr;
                    while (endNode != null)
                    {
                        Path.Add(endNode.CurrRoad);
                        endNode = endNode.PrevNode;
                    }

                    Path.RemoveAt(Path.Count - 1);
                    Path.Reverse();
                    return;
                }

                SeenRoads.Add(curr.CurrRoad);

                foreach (var road in curr.CurrRoad.NextRoads)
                {
                    if (SeenRoads.Contains(road))
                    {
                        continue;
                    }

                    goThrough.Enqueue(new PathNode(curr, road));
                }
            }

            throw new Exception("Failed to find a path.");
        }
Exemple #34
0
        private static void SetWest(Road west)
        {
            west.east = null;
            //road.west = null;

            switch (west.type)
            {
            case RoadType.Corner:   west.SetTypeAndDirection(RoadType.End, west.direction == RoadDirection.NorthEast ? RoadDirection.North : RoadDirection.South); break;

            case RoadType.Straight: west.SetTypeAndDirection(RoadType.End, RoadDirection.West); break;

            case RoadType.End:
                if (!WorldMap.IsOwnerTypeOf(typeof(EntranceBuilding), west.Position))
                {
                    WorldMap.ClearTile(west.Position);
                    Object.Destroy(west.gameObject);
                }
                break;

            case RoadType.Cross_T:
                if (west.direction == RoadDirection.North)
                {
                    west.SetTypeAndDirection(RoadType.Corner, RoadDirection.NorthWest);
                }
                else if (west.direction == RoadDirection.South)
                {
                    west.SetTypeAndDirection(RoadType.Corner, RoadDirection.SouthWest);
                }
                else
                {
                    west.SetTypeAndDirection(RoadType.Straight, RoadDirection.Vertical);
                }
                break;

            case RoadType.Cross_X: west.SetTypeAndDirection(RoadType.Cross_T, RoadDirection.West); break;
            }

            //DelayedOpsManager.AddOperation(() => { RouteSetWP.RecalculateRoutes(west); });
            //RouteSetWP.RecalculateRoutes(west);
        }
Exemple #35
0
        private static void SetSouth(Road south)
        {
            south.north = null;
            //road.south = null;

            switch (south.type)
            {
            case RoadType.Corner:   south.SetTypeAndDirection(RoadType.End, south.direction == RoadDirection.NorthWest ? RoadDirection.West : RoadDirection.East); break;

            case RoadType.Straight: south.SetTypeAndDirection(RoadType.End, RoadDirection.South); break;

            case RoadType.End:
                if (!WorldMap.IsOwnerTypeOf(typeof(EntranceBuilding), south.Position))
                {
                    WorldMap.ClearTile(south.Position);
                    Object.Destroy(south.gameObject);
                }
                break;

            case RoadType.Cross_T:
                if (south.direction == RoadDirection.North)
                {
                    south.SetTypeAndDirection(RoadType.Straight, RoadDirection.Horizontal);
                }
                else if (south.direction == RoadDirection.West)
                {
                    south.SetTypeAndDirection(RoadType.Corner, RoadDirection.SouthWest);
                }
                else
                {
                    south.SetTypeAndDirection(RoadType.Corner, RoadDirection.SouthEast);
                }
                break;

            case RoadType.Cross_X: south.SetTypeAndDirection(RoadType.Cross_T, RoadDirection.South); break;
            }

            //DelayedOpsManager.AddOperation(() => { RouteSetWP.RecalculateRoutes(south); });
            //RouteSetWP.RecalculateRoutes(south);
        }
    /// <summary>
    /// Transforms a map to a directed one by changing undirected roads into two directed.
    /// </summary>
    /// <param name="map">Map we would like to make directed.</param>
    public void MakeDirectedMap(Map map)
    {
        List <Road> newRoads = new List <Road>();

        foreach (Road road in map.roads)
        {
            if (!road.directed) //if undirected
            {
                Intersection end = road.end;

                road.directed = true;
                end.outgoing.Remove(road);

                Road twin = new Road();
                twin.directed  = true;
                twin.start     = road.end;
                twin.end       = road.start;
                twin.length    = road.length;
                twin.traversed = road.traversed;

                twin.roadPoints = new List <Vector3>();
                for (int i = road.roadPoints.Count - 1; i >= 0; i--)
                {
                    twin.roadPoints.Add(road.roadPoints[i]);
                }

                twin.popularities = new List <int>();
                for (int i = road.roadPoints.Count - 1; i >= 0; i--)
                {
                    twin.popularities.Add(road.popularities[i]);
                }

                end.outgoing.Add(twin);
                newRoads.Add(twin);
            }
        }

        map.roads.AddRange(newRoads);
        map.CalcRoadLength();
    }
Exemple #37
0
    private void CreateRoadNetwork(Road[,] roads)
    {
        for (int y = 0; y < roads.GetLength(0); ++y)
        {
            for (int x = 0; x < roads.GetLength(1); ++x)
            {
                Road r = roads[y, x];
                if (r == null)
                {
                    continue;
                }

                //simply check neighbour cells and add neighbours
                try { if (roads[y, x + 1] != null)
                      {
                          r.neighbourRoads.Add(roads[y, x + 1]);
                      }
                }
                catch (System.IndexOutOfRangeException) {}
                try { if (roads[y, x - 1] != null)
                      {
                          r.neighbourRoads.Add(roads[y, x - 1]);
                      }
                }
                catch (System.IndexOutOfRangeException) {}
                try { if (roads[y + 1, x] != null)
                      {
                          r.neighbourRoads.Add(roads[y + 1, x]);
                      }
                }
                catch (System.IndexOutOfRangeException) {}
                try { if (roads[y - 1, x] != null)
                      {
                          r.neighbourRoads.Add(roads[y - 1, x]);
                      }
                }
                catch (System.IndexOutOfRangeException) {}
            }
        }
    }
Exemple #38
0
    public void AddIntersection(Node node, Road road1, Road road2, Segment seg1 = null, Segment seg2 = null, bool coerce = false, Node.Type type = Node.Type.turn)
    {
        UpdatedIntersectionPositions.Add(node.pos());
        if (type == Node.Type.intersection && CheckForIntersection(node.pos()))
        {
            return;
        }
        //Intersection intersection = Instantiate(intersectionPrefab, transform);

        //intersection.transform.position = node.pos();
        node.transform.name = road1.roadName + " and " + road2.roadName;
        //intersection.transform.parent = node.transform;
        nodes.Add(node);
        if (!road1.nodes.Contains(node))
        {
            road1.nodes.Add(node);
        }
        if (!road2.nodes.Contains(node))
        {
            road2.nodes.Add(node);
        }
        if (seg1 != null)
        {
            seg1.AddIntersection(node);
        }
        if (seg2 != null)
        {
            seg2.AddIntersection(node);
        }
        if (seg1 != null && seg2 != null)
        {
            node.Init(new List <Segment> {
                seg1, seg2
            });
        }
        else
        {
            node.Init();
        }
    }
Exemple #39
0
    public virtual void ReadXml(XmlReader reader)
    {
        reader.ReadStartElement();
        int attribute = reader.GetAttribute <int>("Count");

        reader.ReadStartElement("Roads");
        this.roads = new List <Road>(attribute);
        ushort num = 0;

        while ((int)num < attribute)
        {
            if (reader.IsNullElement())
            {
                reader.Skip();
                this.roads.Add(null);
            }
            else
            {
                Road road = new Road();
                road.FromRegion = reader.GetAttribute <short>("From");
                road.ToRegion   = reader.GetAttribute <short>("To");
                road.PathfindingMovementCapacity = (PathfindingMovementCapacity)reader.GetAttribute <int>("MovementCapacity");
                reader.ReadStartElement("Road");
                int attribute2 = reader.GetAttribute <int>("Count");
                reader.ReadStartElement("WorldPositions");
                road.WorldPositions = new WorldPosition[attribute2];
                for (int i = 0; i < attribute2; i++)
                {
                    road.WorldPositions[i] = default(WorldPosition);
                    reader.ReadElementSerializable <WorldPosition>(ref road.WorldPositions[i]);
                }
                reader.ReadEndElement("WorldPositions");
                reader.ReadEndElement("Road");
                this.roads.Add(road);
            }
            num += 1;
        }
        reader.ReadEndElement("Roads");
        ((ICadasterService)this).RefreshCadasterMap();
    }
        public void returnClassVariables()
        {
            string[] roadTestData = { "68",    "HURLEY PL",                      "9",                      "HURLEY PL",  "68",    "9-94m",           "94",         "1967",     "K",     "Concrete",
                                      "9-94m", "WLASS 2015 (Y1)",                "85",                     "85",         "Right", "WLASS 2015 (Y1)", "24/07/2015", "Concrete", null,    null,      null,  null,   null,
                                      null,    null,                             "2",                      null,         null,    null,              null,         null,       "21330", null,      null,  null,   null,
                                      null,    null,                             "9",                      "94",         "8",     "L",               "Latest",     "R",        "C",     "#4?f?4",  "WF",  "WALK", "Walk Over",
                                      "Y",     "Yes, survey data can be edited", "24/7/2015 (100% of 85)", "12/08/2015", "yen",   null,              null };
            //Create test road, taken from .xlxs file
            Road testRoad = new Road(roadTestData);

            //PrintDataShort
            string expectedPrintDataShort = "HURLEY PL                          85        0         0                   0              ";
            string actualPrintDataShort   = testRoad.PrintDataShort();

            Assert.AreEqual(expectedPrintDataShort, actualPrintDataShort);

            //GetRoadName
            string expectedRoadName = "HURLEY PL";
            string actualRoadName   = testRoad.GetRoadName();

            Assert.AreEqual(expectedRoadName, actualRoadName);

            //GetStart
            int expectedStart = 9;
            int actualStart   = testRoad.GetStart();

            Assert.AreEqual(expectedStart, actualStart);

            //GetEnd
            int expectedEnd = 94;
            int actualEnd   = testRoad.GetEnd();

            Assert.AreEqual(expectedEnd, actualEnd);

            //GetFootpathCondition
            int expectedFootpathCondition = 0;
            int actualFootpathCondition   = testRoad.GetFootpathCondition();

            Assert.AreEqual(expectedFootpathCondition, actualFootpathCondition);
        }
Exemple #41
0
    Road PickRoad(Road r, bool up, bool down, bool left, bool right)
    {
        switch (r.GetType().ToString())
        {
        case "NarrowRoad": {
            if (r.up)
            {
                return(RoadFactory.CreateT((int)weavingPosition.x, (int)weavingPosition.y, true, true, left, right));
            }
            else
            {
                return(RoadFactory.CreateT((int)weavingPosition.x, (int)weavingPosition.y, up, down, true, true));
            }
        }

        case "CrossTRoad": {
            return(RoadFactory.CreateQCrossroad((int)weavingPosition.x, (int)weavingPosition.y));
        }

        case "EndRoad": {
            if (r.up)
            {
                return(RoadFactory.CreateTwoSided((int)weavingPosition.x, (int)weavingPosition.y, true, down, left, right));
            }
            else if (r.down)
            {
                return(RoadFactory.CreateTwoSided((int)weavingPosition.x, (int)weavingPosition.y, up, true, left, right));
            }
            else if (r.left)
            {
                return(RoadFactory.CreateTwoSided((int)weavingPosition.x, (int)weavingPosition.y, up, down, true, right));
            }
            else
            {
                return(RoadFactory.CreateTwoSided((int)weavingPosition.x, (int)weavingPosition.y, up, down, left, true));
            }
        }
        }
        return(null);
    }
    private float EvaluateTargetSpeed()
    {
        Collider[] vehiclesWithinRange = Physics.OverlapSphere(transform.position, queueingRadius, LayerUtils.Mask.VEHICLE);

        foreach (Collider vehicleWithinRange in vehiclesWithinRange)
        {
            VehicleController other = vehicleWithinRange.transform.GetComponent <VehicleController>();

            if (other == this)
            {
                continue;
            }

            float thisDistanceToIntersection, otherDistanceToIntersection;
            CalculateDistanceToIntersection(other, out thisDistanceToIntersection, out otherDistanceToIntersection);

            /*float thisDistanceToIntersection = GetDistanceToIntersection(other);
             * float otherDistanceToIntersection = other.GetDistanceToIntersection(this);*/
            // Check whether this vehicle needs to give way to the other vehicle
            if (thisDistanceToIntersection < brakingDistance && otherDistanceToIntersection < brakingDistance)
            {
                if ((thisDistanceToIntersection == otherDistanceToIntersection && GetInstanceID() > other.GetInstanceID()) ||
                    thisDistanceToIntersection > otherDistanceToIntersection)
                {
                    return(0.0f);
                }
            }
        }

        // Check if vehicle should slow down to make a turn
        if (SqrDistFromRoadEnd < roadEndSlowDownThreshold * roadEndSlowDownThreshold && currentRoadNode.Next != null)
        {
            Road  currentRoad  = currentRoadNode.Value;
            Road  nextRoad     = currentRoadNode.Next.Value;
            float turningAngle = Vector3.Angle(currentRoad.RoadDirection, nextRoad.RoadDirection);
            return(maxSpeed * Mathf.Sqrt(1 - Mathf.Pow(turningAngle / 180.0f, 2)));
        }

        return(maxSpeed);
    }
Exemple #43
0
	public void SearchPath(Vector3 StartPosition , Vector3 EndPosition)
	{
		r = GameObject.Find ("RoadPrefab0").GetComponent<Road>();
	
	
		// Search Node where to enter the street
		SearchFirstNode(StartPosition);
		
		//Search Node where to leave the street
		SearchLastNode(EndPosition);
		
		
		//Adding all nodes on street between enter and leave point to list
		for(int i = startNodeID ; i<endNodeID;i++)
		{
			nodes.Add(r.points[i]);
		}
		
		
		//last path point = Endposition
		nodes.Add (EndPosition);
		
	}
Exemple #44
0
        public void AddsARoadToAnEdge()
        {
            var node1 = new Node();
            var node2 = new Node();
            var node3 = new Node();
            var edge1 = new Edge(node1, node2);
            var edge2 = new Edge(node2, node3);
            var road = new Road();
            edge1.Add(road);
            var context = CreateContext(
                edge2,
                new Dictionary<Node, IEnumerable<Edge>>
                    {
                        {node1, new[] {edge1}},
                        {node2, new[] {edge1, edge2}},
                        {node3, new[] {edge2}}
                    });
            context.Player.Roads.Add(road);

            new PlaceRoad().Execute(context);

            Assert.Equal(context.Player.Roads[1], edge2.Get<Road>());
        }
Exemple #45
0
	/**
	 * Called when the script is loaded, before the game starts
	 */
	void Awake () {
		S = this;
	}
Exemple #46
0
	void SpawnNewRoad ()
	{
		myPooledRoad = GameObjectPool.GetPool ("RoadPool").GetInstance ();
		road_Obj = myPooledRoad.GetComponent<Road> ();
		if (GameManager.Instance.crazyStarted3) {
			if (!road_Obj.colored) {
				road_Obj.GetComponent<Animator> ().Play ("Road_Colored");
			}
		} 

		road_Obj.transform.position = new Vector3 (0, 9.9f, 0);
		road_Obj.currentRoad = true;
		road_Obj.name = "CurrentRoad";
		road_Obj.Initialize ();
	}
Exemple #47
0
	void CreateFirstRoad ()
	{
		myPooledRoad = GameObjectPool.GetPool ("RoadPool").GetInstance ();
		road_Obj = myPooledRoad.GetComponent<Road> ();
		road_Obj.transform.position = new Vector3 (0, 0, 0);
		road_Obj.currentRoad = true;
		road_Obj.name = "CurrentRoad";
	}
Exemple #48
0
 public RoadAndPr(Road cRoad, double cPr)
 {
     road = cRoad;
     pr = cPr;
 }
 public override void SetRoadConnection(Road road)
 {
     roadConnection = road;
 }
        public void AddToScene()
        {
            if (!inScene)
            {
                inScene = true;

                // set up the road in the scene manager
                road = Axiom.SceneManagers.Multiverse.TerrainManager.Instance.CreateRoad(name);
                road.HalfWidth = halfWidth;
                RefreshPoints();

                // display the markers
                foreach (IWorldObject child in children)
                {
                    child.AddToScene();
                }
            }
        }
        public void CreateMap()
        {
            Roads = new Road[MapsizeXR, MapsizeYR];
            for (int x = 0; x < MapsizeXR; x++)
            {
                for (int y = 0; y < MapsizeYR; y++)
                {
                    Roads[x, y] = new Road(x, y, RoadType.NULL);
                }
            }
            Point[] _points = GeneratePointSet();
            CheckPoints = _points;

            for (int i = 0; i < _points.Length; i++)
            {
                int SX = 0;
                int SY = 0;
                if (i != _points.Length - 1)
                {
                    SX = _points[i + 1].x;
                    SY = _points[i + 1].y;
                }
                else
                {
                    SX = _points[0].x;
                    SY = _points[0].y;
                }
                List<Point> P = FindRoadPath(Roads[_points[i].x, _points[i].y], Roads[SX, SY], RoadType.NULL);
                List<Road> CurrentPath = new List<Road>();
                for (int j = 0; j < P.Count; j++)
                {
                    CurrentPath.Add(Roads[P[j].x, P[j].y]);
                }
                SetRoadType(P);
            }

            for (int i = 1; i < SpecialRoadList.Count; i += 2)
            {
                if (i == SpecialRoadList.Count - 1)
                {
                    SetSpecialRoadType(SpecialRoadList[i], SpecialRoadList[0]);
                    //ER MOET MINIMAAL 1 BLOK TUSSEN DE ROADS ZITTEN!!!
                }
                else
                {
                    SetSpecialRoadType(SpecialRoadList[i], SpecialRoadList[i + 1]);
                }
            }

            //Pitstopmagic
            for (int i = 0; i < PitstopLocations.Count; ++i)
            {
                Roads[PitstopLocations[i].x, PitstopLocations[i].y].roadType = RoadType.PitstopSpecial;
            }

            Background = new Bitmap(MapsizeX, MapsizeY);
            CellularAutomata();

            for (int x = 0; x < MapsizeX; ++x)
            {
                for (int y = 0; y < MapsizeY; ++y)
                {
                    Background.SetPixel(x, y, GameField[x, y] == 1 ? Color.Green : Color.FromArgb(255, 93, 171, 67));
                }
            }
            for (int x = 0; x < MapsizeXR; x++)
            {
                for (int y = 0; y < MapsizeYR; y++)
                {
                    Bitmap T;
                    if (Roads[x, y].roadType != RoadType.PitstopSpecial)
                    {
                        switch (Roads[x, y].roadType)
                        {
                            case RoadType.horizontalStraight:
                                T = Bitmaps.Roads.HorizontalStraight;
                                break;
                            case RoadType.verticalStraight:
                                T = Bitmaps.Roads.VerticalStraight;
                                break;
                            case RoadType.bottomleftCorner:
                                T = Bitmaps.Roads.LeftBottom;
                                break;
                            case RoadType.bottomrightCorner:
                                T = Bitmaps.Roads.RightBottom;
                                break;
                            case RoadType.topleftCorner:
                                T = Bitmaps.Roads.LeftTop;
                                break;
                            case RoadType.toprightCorner:
                                T = Bitmaps.Roads.RightTop;
                                break;
                            default:
                                T = null;
                                break;
                        }
                        for (int x2 = 0; x2 < 72; x2++)
                        {
                            for (int y2 = 0; y2 < 72; y2++)
                            {
                                if (T != null && T.GetPixel(x2, y2).A != 0)
                                {
                                    Background.SetPixel(x * 72 + x2, y * 72 + y2, T.GetPixel(x2, y2));
                                }
                            }
                        }
                    }
                    else
                    {
                        //Pitstop code
                        if (pitstopType == PitStopType.Horizontal)
                        {
                            T = Bitmaps.Roads.HorizontalPitstop;
                            if (Roads[x, y].X == 6 && Roads[x, y].Y == 0)
                            {
                                for (int x2 = 0; x2 < 216; ++x2)
                                {
                                    for (int y2 = 0; y2 < 144; ++y2)
                                    {
                                        if (T.GetPixel(x2, y2).A != 0)
                                            Background.SetPixel(x * 72 + x2, y * 72 + y2, T.GetPixel(x2, y2));
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (pitstopType == PitStopType.Vertical)
                            {
                                T = Bitmaps.Roads.VerticalPitstop;
                                if (Roads[x, y].X == 0 && Roads[x, y].Y == 3)
                                {
                                    for (int x2 = 0; x2 < 144; ++x2)
                                    {
                                        for (int y2 = 0; y2 < 216; ++y2)
                                        {
                                            if (T.GetPixel(x2, y2).A != 0)
                                                Background.SetPixel(x * 72 + x2, y * 72 + y2, T.GetPixel(x2, y2));
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("INVALID PITSTOPTYPE GAME.CS");
                            }
                        }
                    }
                }
            }
            for (int x = 0; x < 16; ++x)
            {
                for (int y = 0; y < 16; ++y)
                {
                    if (Bitmaps.Other.Wrench.GetPixel(x, y).A != 0)
                        Background.SetPixel(PitStopPoint.x - 8 + x, PitStopPoint.y - 8 + y, Bitmaps.Other.Wrench.GetPixel(x, y));
                }
            }
            CheckPointsPassedP1 = new bool[CheckPoints.Length];
            CheckPointsPassedP2 = new bool[CheckPoints.Length];
            forceCheck = true;
            Finish();
            Base.drawInfos.Add(new DrawInfo(Background, MapsizeX / 2, MapsizeY / 2, MapsizeX, MapsizeY, 270, 0));
            Base.gameTasks.Add(CheckPoint);
            Base.gameTasks.Add(CheckFinish);
            GenerateObstacles();
        }
        public void RemoveFromScene()
        {
            if (inScene)
            {
                inScene = false;

                points.RemoveFromScene();

                Axiom.SceneManagers.Multiverse.TerrainManager.Instance.RemoveRoad(road);

                road.Dispose();
                road = null;
            }
        }
Exemple #53
0
	public void OnEnable()
	{
		road = (Road)target;
	}
        private void AddContent(bool drawForest1, bool drawForest2, bool lakes, bool ocean, bool buildings, bool roads)
        {
            if (drawForest1 || drawForest2)
            {
                treeSceneNode = scene.RootSceneNode.CreateChildSceneNode("Trees");
            }

            bool betaWorldForest = false;

            if (betaWorldForest)
            {
                boundary1 = new Boundary("boundary1");
                boundary1.AddPoint(new Vector3(441 * oneMeter, 0, 4269 * oneMeter));
                boundary1.AddPoint(new Vector3(105 * oneMeter, 0, 4278 * oneMeter));
                boundary1.AddPoint(new Vector3(66 * oneMeter, 0, 4162 * oneMeter));
                boundary1.AddPoint(new Vector3(-132 * oneMeter, 0, 4102 * oneMeter));
                boundary1.AddPoint(new Vector3(-540 * oneMeter, 0, 3658 * oneMeter));
                boundary1.AddPoint(new Vector3(-639 * oneMeter, 0, 3570 * oneMeter));
                boundary1.AddPoint(new Vector3(182 * oneMeter, 0, 3510 * oneMeter));
                boundary1.AddPoint(new Vector3(236 * oneMeter, 0, 3845 * oneMeter));
                boundary1.AddPoint(new Vector3(382 * oneMeter, 0, 3966 * oneMeter));
                boundary1.Close();

                //boundary1.Hilight = true;

                mvScene.AddBoundary(boundary1);

                forest = new Forest(1234, "Forest1", treeSceneNode);
                boundary1.AddSemantic(forest);

                forest.WindFilename = "demoWind.ini";

                forest.WindDirection = Vector3.UnitX;
                forest.WindStrength = 0.0f;

                forest.AddTreeType("CedarOfLebanon_RT.spt", 55 * 300, 0, 4);
                forest.AddTreeType("WeepingWillow_RT.spt", 50 * 300, 0, 5);
                forest.AddTreeType("DatePalm_RT.spt", 40 * 300, 0, 16);

                Boundary boundary4 = new Boundary("boundary4");
                boundary4.AddPoint(new Vector3(441 * oneMeter, 0, 4269 * oneMeter));
                boundary4.AddPoint(new Vector3(105 * oneMeter, 0, 4278 * oneMeter));
                boundary4.AddPoint(new Vector3(66 * oneMeter, 0, 4162 * oneMeter));
                boundary4.AddPoint(new Vector3(-132 * oneMeter, 0, 4102 * oneMeter));
                boundary4.AddPoint(new Vector3(-540 * oneMeter, 0, 3658 * oneMeter));
                boundary4.AddPoint(new Vector3(-639 * oneMeter, 0, 3570 * oneMeter));
                boundary4.AddPoint(new Vector3(182 * oneMeter, 0, 3510 * oneMeter));
                boundary4.AddPoint(new Vector3(236 * oneMeter, 0, 3845 * oneMeter));
                boundary4.AddPoint(new Vector3(382 * oneMeter, 0, 3966 * oneMeter));
                boundary4.Close();

                //boundary1.Hilight = true;

                mvScene.AddBoundary(boundary4);

                Forest forest4 = new Forest(1234, "Forest4", treeSceneNode);
                boundary4.AddSemantic(forest);

                forest4.WindFilename = "demoWind.ini";

                forest4.WindDirection = Vector3.UnitX;
                forest4.WindStrength = 1.0f;

                forest4.AddTreeType("DatePalm_RT.spt", 40 * 300, 0, 14);
                forest4.AddTreeType("CoconutPalm_RT.spt", 55 * 300, 0, 23);
                forest4.AddTreeType("CinnamonFern_RT.spt", 70 * 300, 0, 14);

                boundary2 = new Boundary("boundary2");
                boundary2.AddPoint(new Vector3(285 * oneMeter, 0, 3462 * oneMeter));
                boundary2.AddPoint(new Vector3(-679 * oneMeter, 0, 3560 * oneMeter));
                boundary2.AddPoint(new Vector3(-647 * oneMeter, 0, 3381 * oneMeter));
                boundary2.AddPoint(new Vector3(-512 * oneMeter, 0, 3230 * oneMeter));
                boundary2.AddPoint(new Vector3(402 * oneMeter, 0, 3116 * oneMeter));
                boundary2.AddPoint(new Vector3(402 * oneMeter, 0, 3339 * oneMeter));
                boundary2.AddPoint(new Vector3(305 * oneMeter, 0, 3363 * oneMeter));
                boundary2.Close();

                mvScene.AddBoundary(boundary2);

                Forest forest2 = new Forest(1234, "Forest2", treeSceneNode);

                boundary2.AddSemantic(forest2);

                forest2.WindFilename = "demoWind.ini";

                forest2.WindDirection = Vector3.UnitX;
                forest2.WindStrength = 1.0f;

                forest2.AddTreeType("SpiderTree_RT_Dead.spt", 80 * 300, 0, 23);
                forest2.AddTreeType("CinnamonFern_RT.spt", 70 * 300, 0, 12);
                forest2.AddTreeType("CoconutPalm_RT.spt", 55 * 300, 0, 12);

                Boundary boundary3 = new Boundary("boundary3");
                boundary3.AddPoint(new Vector3(285 * oneMeter, 0, 3462 * oneMeter));
                boundary3.AddPoint(new Vector3(-679 * oneMeter, 0, 3560 * oneMeter));
                boundary3.AddPoint(new Vector3(-647 * oneMeter, 0, 3381 * oneMeter));
                boundary3.AddPoint(new Vector3(-512 * oneMeter, 0, 3230 * oneMeter));
                boundary3.AddPoint(new Vector3(402 * oneMeter, 0, 3116 * oneMeter));
                boundary3.AddPoint(new Vector3(402 * oneMeter, 0, 3339 * oneMeter));
                boundary3.AddPoint(new Vector3(305 * oneMeter, 0, 3363 * oneMeter));
                boundary3.Close();

                mvScene.AddBoundary(boundary3);

                Forest forest3 = new Forest(1234, "Forest3", treeSceneNode);

                boundary3.AddSemantic(forest3);

                forest3.WindFilename = "demoWind.ini";

                forest3.WindDirection = Vector3.UnitX;
                forest3.WindStrength = 1.0f;

                forest3.AddTreeType("DatePalm_RT.spt", 40 * 300, 0, 14);
                forest3.AddTreeType("AmericanHolly_RT.spt", 40 * 300, 0, 24);
                forest3.AddTreeType("CoconutPalm_RT.spt", 55 * 300, 0, 23);
                forest3.AddTreeType("SpiderTree_RT_Dead.spt", 80 * 300, 0, 9);
            }

            if (drawForest1)
            {
                boundary1 = new Boundary("boundary1");
                boundary1.AddPoint(new Vector3(441 * oneMeter, 0, 4269 * oneMeter));
                boundary1.AddPoint(new Vector3(105 * oneMeter, 0, 4278 * oneMeter));
                boundary1.AddPoint(new Vector3(66 * oneMeter, 0, 4162 * oneMeter));
                boundary1.AddPoint(new Vector3(-132 * oneMeter, 0, 4102 * oneMeter));
                boundary1.AddPoint(new Vector3(-540 * oneMeter, 0, 3658 * oneMeter));
                boundary1.AddPoint(new Vector3(-639 * oneMeter, 0, 3570 * oneMeter));
                boundary1.AddPoint(new Vector3(182 * oneMeter, 0, 3510 * oneMeter));
                boundary1.AddPoint(new Vector3(236 * oneMeter, 0, 3845 * oneMeter));
                boundary1.AddPoint(new Vector3(382 * oneMeter, 0, 3966 * oneMeter));
                boundary1.Close();

                //boundary1.Hilight = true;

                mvScene.AddBoundary(boundary1);

                forest = new Forest(1234, "Forest1", treeSceneNode);
                boundary1.AddSemantic(forest);

                forest.WindFilename = "demoWind.ini";

                forest.WindDirection = Vector3.UnitX;
                forest.WindStrength = 1.0f;

                //forest.AddTreeType("EnglishOak_RT.spt", 55 * 300, 0, 100);
                //forest.AddTreeType("AmericanHolly_RT.spt", 40 * 300, 0, 100);
                //forest.AddTreeType("ChristmasScotchPine_RT.spt", 70 * 300, 0, 100);

                //forest.AddTreeType("CedarOfLebanon_RT.spt", 55 * 300, 0, 4);
                //forest.AddTreeType("WeepingWillow_RT.spt", 50 * 300, 0, 5);
                //forest.AddTreeType("DatePalm_RT.spt", 40 * 300, 0, 16);
                //forest.AddTreeType("DatePalm_RT.spt", 40 * 300, 0, 14);
                //forest.AddTreeType("CoconutPalm_RT.spt", 55 * 300, 0, 23);
                //forest.AddTreeType("CinnamonFern_RT.spt", 70 * 300, 0, 14);
                //forest.AddTreeType("SpiderTree_RT_Dead.spt", 80 * 300, 0, 23);
                //forest.AddTreeType("CinnamonFern_RT.spt", 70 * 300, 0, 12);
                //forest.AddTreeType("CoconutPalm_RT.spt", 55 * 300, 0, 12);
                //forest.AddTreeType("DatePalm_RT.spt", 40 * 300, 0, 14);
                //forest.AddTreeType("AmericanHolly_RT.spt", 40 * 300, 0, 24);
                //forest.AddTreeType("CoconutPalm_RT.spt", 55 * 300, 0, 23);
                //forest.AddTreeType("SpiderTree_RT_Dead.spt", 80 * 300, 0, 9);

                uint numinstances = 50;

                //forest.AddTreeType("Azalea_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("Azalea_RT_Pink.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("AzaleaPatch_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("AzaleaPatch_RT_Pink.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("CurlyPalm_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("CurlyPalmCluster_RT.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("FraserFir_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("FraserFir_RT_Snow.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("FraserFirCluster_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("FraserFirCluster_RT_Snow.spt", 55 * 300, 0, numinstances);

                forest.AddTreeType("RDApple_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("RDApple_RT_Apples.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("RDApple_RT_Spring.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("RDApple_RT_Winter.spt", 55 * 300, 0, numinstances);

                forest.AddTreeType("UmbrellaThorn_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("UmbrellaThorn_RT_Dead.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("UmbrellaThorn_RT_Flowers.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("WeepingWillow_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("WeepingWillow_RT_Fall.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("WeepingWillow_RT_Winter.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("AmericanBoxwood_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("AmericanBoxwoodCluster_RT.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("Beech_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("Beech_RT_Fall.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("Beech_RT_Winter.spt", 55 * 300, 0, numinstances);

                forest.AddTreeType("SugarPine_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("SugarPine_RT_Winter.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("VenusTree_RT.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("CherryTree_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("CherryTree_RT_Spring.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("CherryTree_RT_Fall.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("CherryTree_RT_Winter.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("SpiderTree_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("SpiderTree_RT_Dead.spt", 55 * 300, 0, numinstances);

                //forest.AddTreeType("JungleBrush_RT.spt", 55 * 300, 0, numinstances);

                forest.AddTreeType("QueenPalm_RT.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("QueenPalm_RT_Flowers.spt", 55 * 300, 0, numinstances);
                //forest.AddTreeType("QueenPalmCluster_RT.spt", 55 * 300, 0, numinstances);

                if (false)
                {
                    //uint numinstances = 30;
                    forest.AddTreeType("CurlyPalm_RT.spt", 55 * 300, 0, numinstances);
                    forest.AddTreeType("DatePalm_RT.spt", 40 * 300, 0, numinstances);
                    forest.AddTreeType("JungleBrush_RT.spt", 70 * 300, 0, numinstances);
                    forest.AddTreeType("Cercropia_RT.spt", 55 * 300, 0, numinstances);
                    forest.AddTreeType("CommonOlive_RT_Summer.spt", 40 * 300, 0, numinstances);
                    forest.AddTreeType("ColvilleaRacemosa_RT_Flower.spt", 70 * 300, 0, numinstances);
                    forest.AddTreeType("JapaneseAngelica_RT_Summer.spt", 55 * 300, 0, numinstances);
                    forest.AddTreeType("NorthIslandRata_RT_Spring.spt", 40 * 300, 0, numinstances);
                    forest.AddTreeType("SpiderTree_RT.spt", 70 * 300, 0, numinstances);
                    forest.AddTreeType("Stump_RT.spt", 150 * 300, 0, numinstances);
                    forest.AddTreeType("UmbrellaThorn_RT_Flowers.spt", 70 * 300, 0, numinstances);

                    forest.AddTreeType("AmurCork_RT_LateSummer.spt", 55 * 300, 0, numinstances);
                    forest.AddTreeType("ArizonaBush_RT_Flowers.spt", 40 * 300, 0, numinstances);
                    forest.AddTreeType("BananaTree_RT.spt", 70 * 300, 0, numinstances);
                    forest.AddTreeType("Baobab_RT.spt", 55 * 300, 0, numinstances);
                    forest.AddTreeType("CaliforniaBuckeye_RT_Nuts.spt", 120 * 300, 0, numinstances);

                    forest.AddTreeType("CedarOfLebanon_RT.spt", 55 * 300, 0, numinstances);
                    forest.AddTreeType("CherryTree_RT_Spring.spt", 40 * 300, 0, numinstances);
                    forest.AddTreeType("CinnamonFern_RT.spt", 70 * 300, 0, numinstances);
                    forest.AddTreeType("CoconutPalm_RT.spt", 55 * 300, 0, numinstances);
                    forest.AddTreeType("Crepe Myrtle_RT_Flowers.spt", 120 * 300, 0, numinstances);
                }
                //forest.AddTreeType("CedarOfLebanon_RT.spt", 100 * 300, 0, 30);
                //forest.AddTreeType("CherryTree_RT_Spring.spt", 40 * 300, 0, 30);
                //forest.AddTreeType("CinnamonFern_RT.spt", 70 * 300, 0, 30);
                //forest.AddTreeType("CoconutPalm_RT.spt", 55 * 300, 0, 30);
                //forest.AddTreeType("Crepe Myrtle_RT_Flowers.spt", 120 * 300, 0, 30);

                if (false)
                {
                    forest.AddTreeType("Crepe Myrtle_RT_Winter.spt", 100 * 300, 0, 30);
                    forest.AddTreeType("FanPalm_RT.spt", 40 * 300, 0, 30);
                    forest.AddTreeType("ItalianCypress_RT.spt", 70 * 300, 0, 30);
                    forest.AddTreeType("JapaneseMaple_RT_Summer.spt", 55 * 300, 0, 30);
                    forest.AddTreeType("JoshuaTree_RT.spt", 120 * 300, 0, 30);

                    forest.AddTreeType("KoreanStewartia_RT.spt", 100 * 300, 0, 30);
                    forest.AddTreeType("ManchurianAngelicaTree_RT_Small.spt", 100 * 300, 0, 30);
                    forest.AddTreeType("MimosaTree_RT.spt", 100 * 300, 0, 30);
                    forest.AddTreeType("MimosaTree_RT_Flower.spt", 100 * 300, 0, 30);
                    forest.AddTreeType("Mulga_RT_Flowers.spt", 50 * 300, 0, 30);

                    forest.AddTreeType("OmenTree_RT.spt", 80 * 300, 0, 30);
                    forest.AddTreeType("OrientalSpruce_RT.spt", 50 * 300, 0, 30);
                    forest.AddTreeType("PonytailPalm_RT.spt", 140 * 300, 0, 30);
                    forest.AddTreeType("QueenPalm_RT.spt", 55 * 300, 0, 30);
                    forest.AddTreeType("ColvilleaRacemosa_RT.spt", 50 * 300, 0, 30);

                    forest.AddTreeType("SpiderTree_RT_Dead.spt", 80 * 300, 0, 30);
                    forest.AddTreeType("Tamarind_RT_Spring.spt", 50 * 300, 0, 30);
                    forest.AddTreeType("WeepingWillow_RT.spt", 50 * 300, 0, 30);
                }
            }

            if ( drawForest2 ) {
                boundary2 = new Boundary("boundary2");
                boundary2.AddPoint(new Vector3(285 * oneMeter, 0, 3462 * oneMeter));
                boundary2.AddPoint(new Vector3(-679 * oneMeter, 0, 3560 * oneMeter));
                boundary2.AddPoint(new Vector3(-647 * oneMeter, 0, 3381 * oneMeter));
                boundary2.AddPoint(new Vector3(-512 * oneMeter, 0, 3230 * oneMeter));
                boundary2.AddPoint(new Vector3(402 * oneMeter, 0, 3116 * oneMeter));
                boundary2.AddPoint(new Vector3(402 * oneMeter, 0, 3339 * oneMeter));
                boundary2.AddPoint(new Vector3(305 * oneMeter, 0, 3363 * oneMeter));
                boundary2.Close();

                mvScene.AddBoundary(boundary2);

                Forest forest2 = new Forest(1234, "Forest2", treeSceneNode);

                boundary2.AddSemantic(forest2);

                forest2.WindFilename = "demoWind.ini";

                forest2.AddTreeType("EnglishOak_RT.spt", 55 * 300, 0, 150);
                forest2.AddTreeType("AmericanHolly_RT.spt", 40 * 300, 0, 150);
                forest2.AddTreeType("ChristmasScotchPine_RT.spt", 70 * 300, 0, 150);

                forest2.WindDirection = Vector3.UnitX;
                forest2.WindStrength = 0f;
            }

            if (lakes)
            {
                boundary3 = new Boundary("boundary3");
                boundary3.AddPoint(new Vector3(-540 * oneMeter, 0, 3151 * oneMeter));
                boundary3.AddPoint(new Vector3(-656 * oneMeter, 0, 3058 * oneMeter));
                boundary3.AddPoint(new Vector3(-631 * oneMeter, 0, 2878 * oneMeter));
                boundary3.AddPoint(new Vector3(-335 * oneMeter, 0, 2882 * oneMeter));
                boundary3.AddPoint(new Vector3(-336 * oneMeter, 0, 3098 * oneMeter));
                boundary3.AddPoint(new Vector3(-478 * oneMeter, 0, 3166 * oneMeter));
                boundary3.Close();

                //boundary3.Hilight = true;

                mvScene.AddBoundary(boundary3);

                WaterPlane waterSemantic = new WaterPlane(42 * WorldManager.oneMeter, "lake1", treeSceneNode);

                boundary3.AddSemantic(waterSemantic);

            }

            if (buildings)
            {
                Entity entity = scene.CreateEntity("tree", "demotree4.mesh");

                SceneNode node = scene.RootSceneNode.CreateChildSceneNode();
                node.AttachObject(entity);
                node.Position = new Vector3(332383, 71536, 4247994);

                entity = scene.CreateEntity("house", "human_house_stilt.mesh");

                node = scene.RootSceneNode.CreateChildSceneNode();
                node.AttachObject(entity);
                node.Position = new Vector3(0, 130.0f * oneMeter, 3900 * oneMeter);

            }

            if (ocean)
            {
                Entity waterEntity = scene.CreateEntity("Water", "WaterPlane");

                Debug.Assert(waterEntity != null);
                waterEntity.MaterialName = "MVSMOcean";

                SceneNode waterNode = scene.RootSceneNode.CreateChildSceneNode("WaterNode");
                Debug.Assert(waterNode != null);
                waterNode.AttachObject(waterEntity);
                waterNode.Translate(new Vector3(0, 0, 0));
            }

            if (roads)
            {
                road1 = mvScene.CreateRoad("Via Appia");
                road1.HalfWidth = 2;

                List<Vector3> roadPoints = new List<Vector3>();
                roadPoints.Add(new Vector3(97000, 0, 4156000));
                roadPoints.Add(new Vector3(205000, 0, 4031000));
                roadPoints.Add(new Vector3(254000, 0, 3954000));
                roadPoints.Add(new Vector3(234000, 0, 3500000));
                roadPoints.Add(new Vector3(256000, 0, 3337000));
                roadPoints.Add(new Vector3(98000, 0, 3242000));

                road1.AddPoints(roadPoints);

            }
        }
        private void NewRoad()
        {
            road2 = mvScene.CreateRoad("Via Sacra");

            List<Vector3> road2Points = new List<Vector3>();
            road2Points.Add(new Vector3(71000, 0, 4014000));
            road2Points.Add(new Vector3(265000, 0, 4177000));

            road2.AddPoints(road2Points);
        }
Exemple #56
0
 public void joinRoads(Road thisR, Road otherR)
 {
     //Do this sometime
 }
 public override void SetRoadConnection(Road road)
 {
     roadConnections.Add(road);
     // should also check for potentially removed connections
 }
        public void RemoveRoad(Road road)
        {
            roads.Remove(road);

            road.Dispose();

            RebuildMask();
        }
 public void RemoveRoad(Road r)
 {
     roads.RemoveRoad(r);
 }
Exemple #60
0
    // Update is called once per frame
    void Update()
    {
        if (!isInitialized) {
            this.Initialize();
        }

        // Check ticks
        if (Time.time > tick) {
            tick += TICK_INTERVAL;
            // Grow buildings
            foreach (Building building in this.buildings) {
                building.Grow();
            }
        }

        // Get on-screen mouse transltion
        float ix = Input.mousePosition.x;
        float iy = Input.mousePosition.y;
        Vector3 transMouse = GUI.matrix.inverse.MultiplyPoint3x4(new Vector3(ix, Screen.height - iy, 1));

        // Execute UI if the mouse is not over the menu box
        if (!menuBox.Contains(new Vector2(transMouse.x, transMouse.y))) {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit = new RaycastHit();
            if (Physics.Raycast(ray, out hit))
            {
                // Check mouse
                if (Input.GetMouseButtonUp(0)) // LMB Clicked, drop cubes
                {
                    // Add object at cursor
                    Vector3 cubePoint = new Vector3(hit.point.x, hit.point.y, hit.point.z);
                    cubePoint.x -= (cubePoint.x % terrainGenerator.TileWide) - terrainGenerator.TileWide / 2f;
                    cubePoint.z -= (cubePoint.z % terrainGenerator.TileHigh) - terrainGenerator.TileHigh / 2f;

                    Vector2 tilePoint = new Vector2(Mathf.FloorToInt(cubePoint.x / terrainGenerator.TileWide), Mathf.FloorToInt(cubePoint.z / terrainGenerator.TileHigh));
                    Building tile = null;

                    switch (selectionStrings[selectionGridInt]) {
                    case "Residential":
                        tile = new Building();
                        break;
                    case "Clear":
                        if (tileMap.ContainsKey(tilePoint)) {
                            Destroy(tileMap[tilePoint].TileObject);
                            if (tileMap[tilePoint] is Building) {
                                buildings.Remove((Building)tileMap[tilePoint]);
                            }
                            tileMap.Remove(tilePoint);
                        }
                        break;
                    default:
                        break;
                    }
                    if (tile != null && !tileMap.ContainsKey(tilePoint)) {
                        cubePoint.y += activeCursor.transform.localScale.y / 2f;
                        tile.TileObject = (GameObject)Instantiate(activeCursor, cubePoint, Quaternion.identity);
                        tileMap.Add (tilePoint, tile);
                        buildings.Add(tile);
                    }
                }
                else if (Input.GetMouseButton(0)) // LMB down, paint planes
                {
                    // Add object at cursor
                    Vector3 cubePoint = new Vector3(hit.point.x, hit.point.y, hit.point.z);
                    cubePoint.x -= (cubePoint.x % terrainGenerator.TileWide) - terrainGenerator.TileWide / 2f;
                    cubePoint.z -= (cubePoint.z % terrainGenerator.TileHigh) - terrainGenerator.TileHigh / 2f;

                    Vector2 tilePoint = new Vector2(Mathf.FloorToInt(cubePoint.x / terrainGenerator.TileWide), Mathf.FloorToInt(cubePoint.z / terrainGenerator.TileHigh));
                    Tile tile = null;

                    switch (selectionStrings[selectionGridInt]) {
                    case "Road":
                        tile = new Road();
                        break;
                    default:
                        break;
                    }
                    if (tile != null && !tileMap.ContainsKey(tilePoint)) {
                        cubePoint.y += 0.1f; // float a slight static height above the terrain
                        tile.TileObject = (GameObject)Instantiate(activeCursor, cubePoint, Quaternion.identity);
                        tileMap.Add (tilePoint, tile);
                    }
                }
                else
                {
                    // Draw cursor
                    Vector3 cursorPoint = new Vector3(hit.point.x, hit.point.y, hit.point.z);
                    cursorPoint.x -= (cursorPoint.x % terrainGenerator.TileWide) - terrainGenerator.TileWide / 2f;
                    cursorPoint.z -= (cursorPoint.z % terrainGenerator.TileHigh) - terrainGenerator.TileHigh / 2f;
                    cursorPrefab.transform.position = cursorPoint;
                }
            }
        }
    }