List <Direction> forbiddenDirections(IDPosFromDoor pos, int id) { List <Direction> forbiddenDirs = new List <Direction>(); switch (pos) { case IDPosFromDoor.LEFT: forbiddenDirs.Add(Direction.LEFT); break; case IDPosFromDoor.MID: forbiddenDirs.Add(Direction.UP); if (id % 10 == 4) { forbiddenDirs.Add(Direction.LEFT); } else if (id % 10 == 5) { forbiddenDirs.Add(Direction.RIGHT); } break; case IDPosFromDoor.RIGHT: forbiddenDirs.Add(Direction.RIGHT); break; case IDPosFromDoor.ON_DOOR: forbiddenDirs.Add(Direction.UP); break; } return(forbiddenDirs); }
void setAllLeavers(Leaver l) { int id = l.getID(); int player_id = getIDPlayer(); IDPosFromDoor pos = getPosFromDoor(id); l.setPos(pos); Direction nextDir; if (pos == IDPosFromDoor.ON_DOOR) { return; } nextDir = calculateNextDir(pos, id, player_id); callNextLeaver(id, nextDir); }
public IEnumerator leavingLoop() { printLeaversList(); int leavers_count = leavers.Count; foreach (Leaver l in leavers) { // print("id #" + l.getID() + ", pos: " + l.getPos()); if (l.getPos() == IDPosFromDoor.ON_DOOR) { audio.Play(audio.passenger_out, passenger_sfx_volume); Destroy(grid.passengers[l.getID()]); grid.passengers[l.getID()] = null; leavers_count--; } } while (leavers_count > 0) { bool moved = false; for (int i = 0; i < leavers.Count; i++) { Leaver l = leavers[i]; int id = l.getID(); IDPosFromDoor pos = l.getPos(); // print ("id #" + id + ", pos: " + pos); if (grid.passengers[id] == null) { continue; } List <GameObject> adjs = grid.calculateAdj(id); foreach (GameObject tile in adjs) { int player_id = getIDPlayer(); int tile_id = tile.GetComponent <Tile>().getTileId(); IDPosFromDoor tile_pos = grid.posFromDoor(tile_id); bool empty = grid.tileIsEmpty(tile_id); if (empty) { Direction tileDir = calculateDirByID(id, tile_id); Direction doorDir = calculateNextDir(pos, id, player_id); if (id == 15) { print("ID#" + id + ", tile_id#" + tile_id); print("Tile_DIR: " + tileDir + ", Door_DIR: " + doorDir); } if (/*forbidden.Contains(tileDir) || */ tileDir != doorDir) { continue; } //print ("Tile #" + tile_id + " is empty (detected by passenger #" + id + ")."); float mov_threshold = 0.1f; float mov_time = Random.Range(swap_duration - mov_threshold, swap_duration + mov_threshold); grid.movePassenger(id, tile_id, mov_time); moved = true; //yield return new WaitForSeconds(0.5f); break; } else { //print ("Tile #" + tile_id + " is NOT empty (detected by passenger #" + id + ")."); } } } if (!moved) { for (int i = 0; i < leavers.Count; i++) { Leaver l = leavers [i]; int id = l.getID(); if (l.getPos() == IDPosFromDoor.ON_DOOR) { if (grid.passengers [l.getID()] == null) { continue; } GameObject go = grid.passengers [l.getID()]; PassengerType p_type = go.GetComponent <Passenger> ().getPassengerType(); grid.types_counter [p_type]--; Destroy(go); audio.Play(audio.passenger_out, passenger_sfx_volume); grid.passengers [l.getID()] = null; leavers_count--; } } } float cycle_threshold = 0.1f; float cycle_time = Random.Range(swap_duration, swap_duration + cycle_threshold); yield return(new WaitForSeconds(cycle_time)); } print("Leavers.count: " + leavers.Count); ready_to_advance = true; }
Direction calculateNextDir(IDPosFromDoor pos, int id, int player_id) { switch (pos) { case IDPosFromDoor.LEFT: if (isOnHorizontalUp(id) && isOnHorizontalUp(player_id)) { return(Direction.DOWN); } else if (isOnHorizontalDown(id) && isOnHorizontalDown(player_id)) { return(Direction.UP); } else if (passengerOnFirstLineOfSeats(id) || passengerOnSecondLineOfSeats(id)) { return(Direction.DOWN); } else if (passengerOnFirstLastLineOfSeats(id) || passengerOnSecondLastLineOfSeats(id)) { return(Direction.UP); } else { return(Direction.RIGHT); } case IDPosFromDoor.RIGHT: if (isOnHorizontalUp(id) && isOnHorizontalUp(player_id)) { return(Direction.DOWN); } else if (isOnHorizontalDown(id) && isOnHorizontalDown(player_id)) { return(Direction.UP); } else if (passengerOnFirstLineOfSeats(id) || passengerOnSecondLineOfSeats(id)) { return(Direction.DOWN); } else if (passengerOnFirstLastLineOfSeats(id) || passengerOnSecondLastLineOfSeats(id)) { return(Direction.UP); } else { return(Direction.LEFT); } case IDPosFromDoor.MID: if (passengerOnFirstLineOfSeats(id) || passengerOnSecondLineOfSeats(id)) { return(Direction.DOWN); } else if (isOnVerticalLeft(id) && isOnVerticalLeft(player_id)) { return(Direction.RIGHT); } else if (isOnVerticalRight(id) && isOnVerticalRight(player_id)) { return(Direction.LEFT); } else { return(Direction.DOWN); } default: //print("nextDir = sair"); return(Direction.DOWN); } }
public void setPos(IDPosFromDoor pos) { this.pos = pos; }