Esempio n. 1
0
 public bool connectTo(POI otherPOI, POI.DIRECTIONS iDirection)
 {
     if (isAlreadyConnected(otherPOI))
     {
         return(false);
     }
     neighbors.Add(Tuple.Create(otherPOI, iDirection));
     otherPOI.oneWayConnectTo(this, revertDirection(iDirection));
     return(true);
 }
Esempio n. 2
0
 public POI tryNeighbor(POI.DIRECTIONS iDirection)
 {
     foreach (Tuple <POI, POI.DIRECTIONS> poi_to_dir in neighbors)
     {
         if (poi_to_dir.Item2 == iDirection)
         {
             return(poi_to_dir.Item1);
         }
     }
     return(null);
 }
Esempio n. 3
0
 private POI.DIRECTIONS revertDirection(POI.DIRECTIONS iDirection)
 {
     if (iDirection == POI.DIRECTIONS.UP)
     {
         return(POI.DIRECTIONS.DOWN);
     }
     else if (iDirection == POI.DIRECTIONS.DOWN)
     {
         return(POI.DIRECTIONS.UP);
     }
     else if (iDirection == POI.DIRECTIONS.LEFT)
     {
         return(POI.DIRECTIONS.RIGHT);
     }
     else if (iDirection == POI.DIRECTIONS.RIGHT)
     {
         return(POI.DIRECTIONS.LEFT);
     }
     else if (iDirection == POI.DIRECTIONS.UPLEFT)
     {
         return(POI.DIRECTIONS.DOWNRIGHT);
     }
     else if (iDirection == POI.DIRECTIONS.DOWNRIGHT)
     {
         return(POI.DIRECTIONS.UPLEFT);
     }
     else if (iDirection == POI.DIRECTIONS.UPRIGHT)
     {
         return(POI.DIRECTIONS.DOWNLEFT);
     }
     else if (iDirection == POI.DIRECTIONS.DOWNLEFT)
     {
         return(POI.DIRECTIONS.UPRIGHT);
     }
     else
     {
         return(POI.DIRECTIONS.NONE);
     }
 }
Esempio n. 4
0
 public void oneWayRevertConnectTo(POI otherPOI, POI.DIRECTIONS iDirection)
 {
     neighbors.Add(Tuple.Create(otherPOI, revertDirection(iDirection)));
 }
Esempio n. 5
0
    private void buildStageAndConnections(int row_boundary, int col_boundary)
    {
        List <Tuple <int, int> > paths = new List <Tuple <int, int> > {
            Tuple.Create(__start_coord.Item1, __start_coord.Item2)
        };

        while (paths.Any())
        {
            Tuple <int, int> curr_path  = paths[0];
            Stage            curr_stage = lstages[__world_stage_layout[curr_path.Item1, curr_path.Item2]];
            paths.RemoveAt(0);

            // update stage completion from save file
            WORLD_POI curr_poi = __world_pois[curr_path.Item1, curr_path.Item2];
            curr_stage.updateCompletion(curr_poi);

            // check neighbors
            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if ((i == 0) && (j == 0))
                    {
                        continue; // self
                    }
                    int row = curr_path.Item1 + i;
                    int col = curr_path.Item2 + j;
                    if ((row < 0) || (col < 0))   // OOB
                    {
                        continue;
                    }
                    if ((row >= row_boundary) || (col >= col_boundary))   // OOB
                    {
                        continue;
                    }
                    WORLD_POI poi = __world_pois[row, col];
                    if (poi == WORLD_POI.NONE)   // NOTHING HERE
                    {
                        continue;
                    }

                    // Stages only reachable for UP/DOWN/LEFT/RIGHT.
                    // we cut corners out
                    bool stage_is_reachable = (Math.Abs(i) + Math.Abs(j)) != 2;
                    if (poiIsStage(poi) && stage_is_reachable)
                    {
                        int            stage_id         = __world_stage_layout[row, col];
                        POI.DIRECTIONS direction        = POI.getDirection(j, i);
                        Stage          stage_to_connect = lstages[stage_id];
                        if (curr_stage.connectTo(stage_to_connect, direction))
                        {
                            paths.Add(Tuple.Create(row, col));
                        }
                    }

                    // POI is a Lconnector, same connectablility than stages
                    if (poiIsLevelConnector(poi) && stage_is_reachable)
                    {
                        int level_id = __world_lconn_layout[row, col];
                        Debug.Log(" Connect level " + level_id);

                        POI.DIRECTIONS direction = POI.getDirection(j, i);
                        POI            target    = null;
                        foreach (LConnector lc in lLConnectors)
                        {
                            if (lc.level_target == level_id)
                            {
                                target = lc;
                                break;
                            }
                        }
                        bool op_succ = curr_stage.connectTo(target, direction);
                        if (!op_succ)
                        {
                            Debug.Log(" FAILED TO CONNECT LEVEL " + level_id);
                        }
                        else
                        {
                            Debug.Log(" SUCCESS TO CONNECT LEVEL " + level_id + " to stage " + curr_stage.id);
                        }
                    }

                    // Connectors can connect diagonally
                    // Only one connector path with a target workds
                    if (poiIsConnector(poi))
                    {
                        POI.DIRECTIONS direction = POI.getDirection(j, i);
                        Tuple <POI, POI.DIRECTIONS> conn_target = findConnectorTarget(row, col, curr_path.Item1, curr_path.Item2, row_boundary, col_boundary);
                        if (conn_target == null)
                        {
                            continue;
                        }

                        // We can use oneWayConnectTo if we want to be really precise
                        // But i find it better if we have more option to crawl through the world
                        // TBD by using it more if we change design and revert it to oneWayConnectTo.
                        curr_stage.connectTo(conn_target.Item1, direction);

                        // The revert connect use the direction from the connector path target to the last
                        // connector of the path. We need to revert this direction thus oneWayRevertConnectTo.
                        conn_target.Item1.oneWayRevertConnectTo(curr_stage, conn_target.Item2);
                    }
                } //! for j cols
            }     //! for i rows
        }
    }