public void connectByRoad(Junction source, AbsDirection connectDirection, GameObject roadParent, ref List <Junction> roadEnds,
                                  ref List <Road> roads, ref List <Junction> junctions, ref JunctionIndexer indexer, ref JunctionGenerator junctionGenerator)
        {
            int coDirection = (int)connectDirection;
            int opDirection = ((int)connectDirection + 2) % 4;

            if (indexer.getIndex(source.coordIndex + directions[coDirection]) >= 0)
            {
                Junction target = junctions[indexer.getIndex(source.coordIndex + directions[coDirection])];
                //Debug.Log(source.ToString() + "\t" + target.ToString() + "\r" + source.connectRoadIdx[coDirection] + "\t" + target.connectRoadIdx[opDirection]);
                if (source.connectRoadIdx[coDirection] < 0 && target.connectRoadIdx[opDirection] < 0)
                {
                    createRoads(source, target, ref roads, roadParent);
                }
                else if (source.connectRoadIdx[coDirection] < 0)
                {
                    source.connectRoadIdx[coDirection] = target.connectRoadIdx[opDirection];
                }
                else if (target.connectRoadIdx[opDirection] < 0)
                {
                    target.connectRoadIdx[opDirection] = source.connectRoadIdx[coDirection];
                }
            }
            else
            {
                junctionGenerator.createNullJunction(source.coordIndex + directions[coDirection], source, (AbsDirection)coDirection, ref roadEnds);
                createRoads(source, roadEnds[roadEnds.Count - 1], ref roads, roadParent);
            }
        }
Beispiel #2
0
        private bool checkByDirection(Vector2 junctionIndex, int direction, Area area, int targetPosition, ref List <Junction> junctions, ref JunctionIndexer indexer, ref List <AreaSet> areaSet)
        {
            bool isMerged      = false;
            int  neighborIndex = indexer.getIndex((directions[direction] + junctionIndex));

            if (indexer.getIndex((directions[direction] + junctionIndex)) >= 0)
            {
                int index = junctions[neighborIndex].areas[targetPosition].areaSetIndex;
                if (index >= 0)
                {
                    areaSet[index].addArea(area);
                    area.setAreaSetIndex(index);
                    isMerged = true;
                }
                else
                {
                    Debug.Log("ERROR: World - connectJunctions - Negative Index error");
                }
            }
            return(isMerged);
        }
Beispiel #3
0
        //private JunctionSize setNextSize(Junction junction, int hrzWeight, int vtcWeight)
        private JunctionSize getNextSize(Vector2 newJunctionIndex, ref List <Junction> junctions, ref JunctionIndexer indexer)
        {
            int          hrzWeight = 0;
            int          vtcWeight = 0;
            JunctionSize size      = new JunctionSize();

            if (indexer.getIndex((int)newJunctionIndex.x + 1, (int)newJunctionIndex.y) >= 0)
            {
                //Debug.Log(indexer.getIndex((int)newJunctionIndex.x + 1, (int)newJunctionIndex.y));
                size.lenOfVtcLane = junctions[indexer.getIndex((int)newJunctionIndex.x + 1, (int)newJunctionIndex.y)].size.lenOfVtcLane;
                size.numOfHrzLane = junctions[indexer.getIndex((int)newJunctionIndex.x + 1, (int)newJunctionIndex.y)].size.numOfHrzLane;
                hrzWeight         = 1;
            }
            if (indexer.getIndex((int)newJunctionIndex.x - 1, (int)newJunctionIndex.y) >= 0)
            {
                //Debug.Log(indexer.getIndex((int)newJunctionIndex.x - 1, (int)newJunctionIndex.y));
                size.lenOfVtcLane = junctions[indexer.getIndex((int)newJunctionIndex.x - 1, (int)newJunctionIndex.y)].size.lenOfVtcLane;
                size.numOfHrzLane = junctions[indexer.getIndex((int)newJunctionIndex.x - 1, (int)newJunctionIndex.y)].size.numOfHrzLane;
                hrzWeight         = -1;
            }
            if (indexer.getIndex((int)newJunctionIndex.x, (int)newJunctionIndex.y + 1) >= 0)
            {
                //Debug.Log(indexer.getIndex((int)newJunctionIndex.x, (int)newJunctionIndex.y + 1));
                size.lenOfHrzLane = junctions[indexer.getIndex((int)newJunctionIndex.x, (int)newJunctionIndex.y + 1)].size.lenOfHrzLane;
                size.numOfVtcLane = junctions[indexer.getIndex((int)newJunctionIndex.x, (int)newJunctionIndex.y + 1)].size.numOfVtcLane;
                vtcWeight         = 1;
            }
            if (indexer.getIndex((int)newJunctionIndex.x, (int)newJunctionIndex.y - 1) >= 0)
            {
                //Debug.Log(indexer.getIndex((int)newJunctionIndex.x, (int)newJunctionIndex.y - 1));
                size.lenOfHrzLane = junctions[indexer.getIndex((int)newJunctionIndex.x, (int)newJunctionIndex.y - 1)].size.lenOfHrzLane;
                size.numOfVtcLane = junctions[indexer.getIndex((int)newJunctionIndex.x, (int)newJunctionIndex.y - 1)].size.numOfVtcLane;
                vtcWeight         = -1;
            }
            int hW = Mathf.Abs(hrzWeight);
            int vW = Mathf.Abs(vtcWeight);

            return(new JunctionSize(hW * size.numOfHrzLane, vW * size.numOfVtcLane, vW * size.lenOfHrzLane, hW * size.lenOfVtcLane));
        }