private bool poiIsStage(WORLD_POI iPOI) { return((iPOI == WORLD_POI.LOCKED_STAGE) || (iPOI == WORLD_POI.UNLOCKED_STAGE) || (iPOI == WORLD_POI.DONE_STAGE) || (iPOI == WORLD_POI.START_STAGE)); }
private bool poiIsLevelConnector(WORLD_POI iPOI) { return(iPOI == WORLD_POI.LEVEL_CONNECTOR); }
private bool poiIsConnectorTarget(WORLD_POI iPOI) { return((iPOI == WORLD_POI.LEVEL_CONNECTOR) || poiIsStage(iPOI)); }
private bool poiIsConnector(WORLD_POI iPOI) { return(iPOI == WORLD_POI.CONNECTOR); }
// Returns the POI and the last direction to reach it from the last connector of the path private Tuple <POI, POI.DIRECTIONS> findConnectorTarget(int conn_x, int conn_y, int from_x, int from_y, int row_boundary, int col_boundary) { Tuple <POI, POI.DIRECTIONS> target = null; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { int row = conn_x + i; int col = conn_y + j; if ((i == 0) && (j == 0)) { continue; // identity } if ((from_x == row) && (from_y == col)) { continue; // loop detected } if ((row < 0) || (col < 0)) // OOB { continue; } if ((row >= row_boundary) || (col >= col_boundary)) // OOB { continue; } WORLD_POI poi = __world_pois[row, col]; if (poiIsConnectorTarget(poi)) { if (poiIsStage(poi)) { int stage_id = __world_stage_layout[row, col]; target = Tuple.Create((POI)lstages[stage_id], POI.getDirection(j, i)); } else // LConnector { int level_to_connect = __world_lconn_layout[row, col]; foreach (LConnector lc in lLConnectors) { if (lc.level_target == level_to_connect) { target = Tuple.Create((POI)lc, POI.getDirection(j, i)); break; } } } break; } if (poiIsConnector(poi)) { return(findConnectorTarget(row, col, conn_x, conn_y, row_boundary, col_boundary)); } } if (target != null) { break; } } return(target); }
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 } }