public List <List <int[]> > city_coord_to_box_coord(List <List <int[]> > city_coord) { List <List <int[]> > box_coord = new List <List <int[]> >(); List <int[]> city_locations = city_coord[0]; box_coord.Add(new List <int[]>()); if (city_coord.Count > 1) { throw new Exception("too many liusts in here"); } for (int i = 0; i < city_coord.Count; i++) { for (int j = 0; j < city_coord[0].Count; j++) { if (city_coord[i][j] != null) { int[] coord = city_coord[i][j]; Boxcar boxcar = CityManager.Activated_City_Component.city_board[coord[0], coord[1]].GetComponent <Boxcar>(); if (boxcar != null) { box_coord[0].Add(new int[] { boxcar.tile_position.x, boxcar.tile_position.y }); } } } } return(box_coord); }
public static void create_boxcar(Train train, GameObject boxcar) { // save the train on the board, but boxcar will overwrite it if (train.in_city) // if train is in city then add boxcars { Tilemap tilemap = train.station_track.tilemap; Boxcar boxcar_component = boxcar.GetComponent <Boxcar>(); boxcar_counter += 1; boxcar_component.attach_to_train(train); MovingObject last_vehicle = train.get_last_vehicle_added().GetComponent <MovingObject>(); // initalize boxcar position PositionPair pos_pair = TrainRouteManager.get_initial_destination(last_vehicle, tilemap); initialize_position(boxcar_component, pos_pair); boxcar_component.set_initial_rotation(boxcar_component.orientation); //set_initial_angle(boxcar, boxcar_component); boxcar_component.city = train.city; boxcar_component.station_track = train.station_track; boxcar_component.arrive_at_city(); boxcar_component.initialize_boxcar(boxcar_counter); boxcar_component.is_wait_for_turntable = true; train.boxcar_squad.Add(boxcar); // save gameobject tile with adjustments. when a user clicks on a tile, it will be in the tile opposite the vehicle's orientation. Therefore, flip orientation //Vector2Int boxcar_board_position = RouteManager.get_straight_next_tile_pos(TrackManager.flip_straight_orientation(boxcar_component.orientation), (Vector2Int)boxcar_component.tile_position); boxcar_component.city.city_board[pos_pair.tile_dest_pos.x + 1, pos_pair.tile_dest_pos.y + 1] = boxcar; // offset boxcar to be consistent //print("new boxcar created at tile position " + boxcar_component.tile_position); } }
public void boxcar_fill_void(GameObject boxcar_object) { Boxcar boxcar = boxcar_object.GetComponent <Boxcar>(); Train train = boxcar.train; int removed_boxcar_id = boxcar.boxcar_id; List <GameObject> boxcar_squad = train.boxcar_squad; int remove_boxcar_idx = train.get_boxcar_by_id(removed_boxcar_id); //print("remove boxcar id is " + removed_boxcar_id); if (removed_boxcar_id > 0) { Boxcar prev_boxcar = boxcar_squad[remove_boxcar_idx].GetComponent <Boxcar>(); // spot of the previous boxcar for (int i = remove_boxcar_idx + 1; i < boxcar_squad.Count; i++) { boxcar = boxcar_squad[i].GetComponent <Boxcar>(); boxcar.abort_move = true; boxcar.is_fill_void = true; if (boxcar.orientation != prev_boxcar.orientation) { //print("BEZIER move boxcar " + boxcar.boxcar_id + " to previous boxcar id " + prev_boxcar.boxcar_id); StartCoroutine(boxcar.one_time_bezier_move(prev_boxcar)); } else { prev_boxcar.one_time_move_pass = true; // dont stop all boxcars when encountering a stop tile //print("STRAIGHT move boxcar " + boxcar.boxcar_id + " to previous boxcar id " + prev_boxcar.boxcar_id + " spot @ " + prev_boxcar.transform.position); StartCoroutine(boxcar.one_time_straight_move(prev_boxcar)); } boxcar.city.city_board[boxcar.tile_position.x + 1, boxcar.tile_position.y + 1] = null; boxcar.city.city_board[prev_boxcar.tile_position.x + 1, prev_boxcar.tile_position.y + 1] = boxcar.gameObject; prev_boxcar = boxcar; // set prev boxcar location to location of the boxcar that moved in to fill the void } } }
public List <int[]> filter_available_boxcar(List <int[]> possible_boxcar_location, Person person) { int available_boxcar = 0; List <Offset_Tile> offset_tile_list = new List <Offset_Tile>(); List <int[]> available_boxcar_list = new List <int[]>(); GameObject[,] city_board = CityManager.Activated_City_Component.city_board; foreach (int[] boxcar_loc in possible_boxcar_location) { try { GameObject boxcar_go = city_board[boxcar_loc[0] + 1, boxcar_loc[1] + 1]; // offset if (boxcar_go != null && boxcar_go.tag == "boxcar") { Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); if (!boxcar.is_occupied && boxcar.is_wait_for_turntable) // boxcar is ready to be loaded { bool is_boxcar_match = person.is_boxcar_match_desired_activity(boxcar.boxcar_type); if (is_boxcar_match) { Tilemap boxcar_tilemap = CityDetector.boxcar_orientation_to_offset_tilemap(boxcar.orientation); offset_tile_list.Add(new Offset_Tile(boxcar_go)); boxcar_tile_tracker[new Vector2Int(boxcar_loc[0], boxcar_loc[1])] = boxcar_tilemap; available_boxcar_list.Add(new int[] { boxcar_loc[0], boxcar_loc[1] }); available_boxcar++; } } } } catch (IndexOutOfRangeException) { print("eligible boxcar location (" + boxcar_loc[0] + "," + boxcar_loc[1] + ") is not suitable for boxcar placement"); }; } all_eligible_boxcar.AddRange(offset_tile_list); //print("available boxcar tally is " + available_boxcar + " size of available boxcar list is " + available_boxcar_list.Count); return(available_boxcar_list); }
public void turn_on_train(bool menu_state, bool is_game_menu) { StartCoroutine(switch_on_vehicle(menu_state)); foreach (GameObject boxcar_object in boxcar_squad) { Boxcar boxcar = boxcar_object.GetComponent <Boxcar>(); if (is_game_menu) { if (!boxcar.in_city && menu_state) { //print("turn on train boxcar " + boxcar.boxcar_id + " NOT IN CITY and game mneu is on. Turn ON sprit e renderer"); StartCoroutine(boxcar.switch_on_vehicle(true)); continue; } } else // is city menu { if (boxcar.in_city && menu_state && boxcar.city == CityManager.Activated_City_Component) { //print("not GAME MENU. TURN ON TRAIN boxcar " + boxcar.boxcar_id + " IN CITY and . Turn ON sprit e renderer"); StartCoroutine(boxcar.switch_on_vehicle(true)); continue; } } //print("switch vehicle OFF"); StartCoroutine(boxcar.switch_on_vehicle(false)); } }
public static GameObject get_exit_door(Boxcar boxcar, Room room) { // get door that exits to the boxcar // RIGHT DOOR TOP RIGHT ALWAYS FACES THE OUTER TRACK (RIGHT DOOR TOP RIGHT IS ON BOTTOM OF ROOM. OUTER TRACK IS RIGHT IN FRONT OF IT GameObject door_parent; int is_inner = boxcar.station_track.inner; //print("is station track with boxcar inner? " + is_inner); //if (room.outer_door != null && room.inner_door != null) // 2 doors to choose from //{ // choose the door that is on the right side of the track if (is_inner == 0) { door_parent = room.outer_door_container; bool is_outer = room.outer_door_container.GetComponent <Door>().is_outer; Sprite door_sprite = room.outer_door_container.GetComponent <Door>().door_sprite; } else { door_parent = room.inner_door_container; } //} //else { // if (room.outer_door != null) door_parent = room.outer_door_container; // else { door_parent = room.inner_door_container; } //} return(door_parent); }
public void start_all_boxcar_at_turntable() { foreach (GameObject boxcar_go in boxcar_squad) { Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); boxcar.GetComponent <BoxCollider2D>().size = new Vector2(.27f, .73f); // original size boxcar.speed = normal_speed; } }
public GameObject get_last_vehicle_added() { if (boxcar_squad.Count == 0) { return(gameObject); } Boxcar boxcar = boxcar_squad[boxcar_squad.Count - 1].GetComponent <Boxcar>(); return(boxcar_squad[boxcar_squad.Count - 1]); }
public int get_distance_from_train(int boxcar_id) { for (int i = 0; i < boxcar_squad.Count; i++) { Boxcar boxcar = boxcar_squad[i].GetComponent <Boxcar>(); if (boxcar.boxcar_id == boxcar_id) { return(i + 1); } } throw new Exception("boxcar with id " + boxcar_id + " should belong to train"); }
public Offset_Tile(GameObject boxcar_go) { this.boxcar_go = boxcar_go; this.boxcar = boxcar_go.GetComponent <Boxcar>(); boxcar_position = boxcar.transform.position; float offset = RouteManager.cell_width / 2; start_x = boxcar_position.x - offset; end_x = boxcar_position.x + offset; start_y = boxcar_position.y - offset; end_y = boxcar_position.y + offset; }
public int get_boxcar_by_id(int boxcar_id) { for (int i = 0; i < boxcar_squad.Count; i++) { GameObject boxcar_go = boxcar_squad[i]; Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); if (boxcar.boxcar_id == boxcar_id) { return(i); } } throw new Exception("Could not find boxcar id " + boxcar_id + " to remove"); }
public bool all_boxcar_arrived() { // check if train's boxcars have arrived before departing. If one boxcar is not idled, that means not all boxcars have arrived yet for (int i = 0; i < boxcar_squad.Count; i++) { Boxcar boxcar = boxcar_squad[i].GetComponent <Boxcar>(); if (is_pause) { return(false); } } return(true); }
public void spawn_moving_object(MovingObject moving_object) { // position vehicle in center of tile and set first destination Vector3Int tile_position = moving_object.tile_position; Vector3 moving_object_position = TrainRouteManager.get_spawn_location(tile_position, moving_object.orientation); moving_object.transform.position = moving_object_position; if (moving_object.tag == "boxcar") { Boxcar boxcar = (Boxcar)moving_object; } StartCoroutine(moving_object.prepare_for_departure()); }
public void stop_single_boxcar_at_turntable(GameObject boxcar_go) { Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); BoxCollider2D bc2d = boxcar_go.GetComponent <BoxCollider2D>(); bc2d.size = new Vector2(1f, .73f); // fatten the boxcar Tilemap boxcar_tilemap = CityDetector.boxcar_orientation_to_offset_tilemap(boxcar.orientation); Vector3Int boxcar_cell_pos = boxcar_tilemap.WorldToCell(boxcar_go.transform.position); boxcar.prev_tile_position = boxcar.tile_position; // move up one boxcar.tile_position = boxcar_cell_pos; VehicleManager.instance.update_vehicle_board(city.city_board, boxcar_go, boxcar_cell_pos, boxcar.prev_tile_position); // nullify prev tile boxcar.speed = stopping_speed; boxcar.is_halt = true; // only call ONCE when first called }
public IEnumerator unload_train(Boxcar boxcar, Room room, Orientation exit_orientation) { List <Checkpoint> go_home_checkpoints = new List <Checkpoint>(); GameObject person_go_instance = boxcar.passenger_go; boxcar.is_occupied = false; //print("unload train boxcar " + boxcar.boxcar_id + " is NOT occupied"); person_go_instance.transform.parent = null; Person person = person_go_instance.GetComponent <Person>(); boxcar.passenger_go = null; person.boxcar_go = null; person.room = null; room.booked = true; room.person_go_instance = person_go_instance; //print("set room instance to PERSON " + person_go_instance.GetComponent<Person>().name); room.unlocked_door = get_exit_door(boxcar, room); // the final dest tile is offset from the person's route, so find the offset using city map Orientation home_orientation = CityManager.station_track_boarding_map[boxcar.station_track.start_location]; person.room = room; // assign room to person person.city = room.building.city; person.final_dest_tile_pos = (Vector3Int)get_straight_next_tile_pos(home_orientation, room.tile_position); //(Vector3Int) room.tile_position; person.enter_home_orientation = TrackManager.flip_straight_orientation(home_orientation); // reverse direction of exiting the home Orientation flip_exit_orientation = TrackManager.flip_straight_orientation(exit_orientation); // need to flip because offset is in the opposite direction the person is traveling Vector2 exit_boxcar_dest = get_straight_walking_position(boxcar.transform.position, flip_exit_orientation); Checkpoint exit_boxcar_checkpoint = new Checkpoint(exit_boxcar_dest, (Vector2Int)boxcar.tile_position, person.orientation, exit_orientation, "walk"); string track_name = shipyard_track_tilemap.GetTile(boxcar.tile_position).name; go_home_checkpoints.Add(exit_boxcar_checkpoint); Orientation exit_home_orientation = CityManager.station_track_boarding_map[boxcar.station_track.start_location]; Vector2Int doorstep_position = get_straight_next_tile_pos(exit_home_orientation, room.tile_position); Vector2 room_abs_position = track_tilemap.GetCellCenterWorld((Vector3Int)doorstep_position); //one tile offset from home in the center. Because boxcars always stop at tile edges, so center tells us which direction person should exit boxcar person.final_dest_pos = room.unlocked_door.GetComponent <Door>().door_sprite_go.transform.position; yield return(StartCoroutine(person.move_checkpoints(go_home_checkpoints))); go_home_checkpoints.Clear(); Orientation align_track_orientation = TrackManager.get_start_orientation(track_name, boxcar.transform.position, room_abs_position, boxcar); Checkpoint align_track_cp = new Checkpoint(exit_boxcar_checkpoint.dest_pos, exit_boxcar_checkpoint.tile_position, exit_boxcar_checkpoint.end_orientation, align_track_orientation, "walk"); go_home_checkpoints.Add(align_track_cp); yield return(StartCoroutine(person.move_checkpoints(go_home_checkpoints))); //boxcar.passenger_go = null; // TODOED TEST MOVE TO BEGIN OF FUNCTION //person.boxcar_go = null; person.is_exit_boxcar = true; // set off follow track back home sequence }
public bool is_all_boxcar_boarded() { // train cannot leave until all passengers are boarded. foreach (GameObject boxcar_go in boxcar_squad) { Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); if (boxcar.is_occupied) { if (boxcar.passenger_go.GetComponent <Person>().is_board_boxcar) // passenger is in process of boarding boxcar { return(false); } } } return(true); }
public IEnumerator one_time_bezier_move(Boxcar prev_boxcar) { prev_boxcar.train.is_boxcar_filling_void = true; Vector3 prev_destination = prev_boxcar.train_destination; Vector3Int prev_boxcar_position = prev_boxcar.tile_position; RouteManager.Orientation prev_orientation = prev_boxcar.orientation; yield return(StartCoroutine(bezier_move(transform, orientation, prev_boxcar.orientation))); orientation = prev_orientation; tile_position = prev_boxcar_position; next_tilemap_position = (Vector2Int)prev_boxcar_position; prev_tile_position = prev_boxcar_position; train_destination = prev_destination; prev_boxcar.train.is_boxcar_filling_void = false; }
public void board_train(GameObject boxcar_go, Vector2Int room_position) { if (CityManager.Activated_City_Component == this) { GameManager.sound_manager.play_cash(); } Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); Room room = city_room_matrix[room_position.x, room_position.y]; GameObject occupant_go = room.person_go_instance; //todo: laster move the occupant to the room (first checkpoint). Person occupant = occupant_go.GetComponent <Person>(); occupant.is_selected = false; //print("board train boxcar " + boxcar.boxcar_id + " is occupied"); //occupant.boxcar_go = boxcar_go; occupant.station_track = boxcar.station_track; occupant.offset_map = RouteManager.offset_route_map[boxcar.station_track.start_location]; StartCoroutine(GameObject.Find("PersonRouteManager").GetComponent <PersonRouteManager>().board_train(boxcar, room, occupant_go, boxcar.tile_position)); }
public void stop_car_if_wait_tile() { if (!gameObject.GetComponent <Boxcar>().train.is_train_departed_for_turntable&& in_city) { Boxcar boxcar = gameObject.GetComponent <Boxcar>(); int track_location_idx = boxcar.station_track.inner; // 0 means outer track int orientation_idx = boxcar.station_track.station.orientation_to_idx(); int boxcar_pos_idx = boxcar.train.get_boxcar_position(gameObject) - 1; int[] boxcar_wait_tile = CityManager.boxcar_city_wait_tile[orientation_idx][track_location_idx][boxcar_pos_idx]; if (tile_position.x == boxcar_wait_tile[0] && tile_position.y == boxcar_wait_tile[1]) { boxcar.train.GetComponent <CapsuleCollider2D>().size = new Vector2(.205f, .837f); //print("stopping boxcar at position " + boxcar_pos_idx + " at wait tile x " + boxcar_wait_tile[0] + " y " + boxcar_wait_tile[1]); boxcar.train.stop_single_boxcar_at_turntable(gameObject); is_boxcar_stopped = true; } } }
public IEnumerator step_on_boxcar(GameObject person_go_instance, GameObject boxcar_go) { Person person = person_go_instance.GetComponent <Person>(); Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); Vector2 boxcar_position = boxcar_go.transform.position; Orientation final_orientation = TrackManager.enter_boxcar_orientation(boxcar_position, person_go_instance.transform.position); //print("enter boxcar cp with person orientation " + person.orientation + " final orientation " + final_orientation + " boxcar tile pos " + boxcar.tile_position); Checkpoint step_on_boxcar_cp = new Checkpoint(boxcar.transform.position, (Vector2Int)boxcar.tile_position, person.orientation, final_orientation, "walk"); List <Checkpoint> board_train_checkpoints = new List <Checkpoint>() { step_on_boxcar_cp }; yield return(StartCoroutine(person.move_checkpoints(board_train_checkpoints))); StartCoroutine(person.set_animation_clip(rest_animation_name)); person.transform.parent = boxcar.transform; // make person a passenger of boxcar boxcar.is_being_boarded = false; }
public void destroy_train() { // destroy train and collided train/boxcar // TODOED: remove car from city tilemap or vehicle tilemap //print("destroy train " + id + " at " + Time.time); GameManager.train_list.Remove(gameObject); city.train_list.Remove(gameObject); if (city != null) { city.turn_table.GetComponent <Turntable>().remove_train_from_queue(gameObject); } foreach (GameObject boxcar_go in boxcar_squad) { Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); if (boxcar.passenger_go != null) { // leave a RIP review Person deceased_person = boxcar.passenger_go.GetComponent <Person>(); string review_summary = "I died in a train accident departing from " + city.city_type + ". F"; deceased_person.update_review_page(review_summary, 0); if (boxcar.passenger_go.tag == "rich") { GameManager.update_game_money_text(-100); // lawsuit fees } else { GameManager.update_game_money_text(-250); // lawsuit fees } CityManager.update_total_people(-1); Destroy(boxcar.passenger_go); } boxcar.remove_vehicle_from_board(); Destroy(boxcar_go); } foreach (GameObject explosion in explosion_list) { Destroy(explosion); } remove_vehicle_from_board(); Destroy(gameObject); }
public void unload_train(GameObject boxcar_go, Vector2Int room_position) { Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); Person person = boxcar.passenger_go.GetComponent <Person>(); person.offset_map = RouteManager.offset_route_map[boxcar.station_track.start_location]; person.is_enter_home = true; Room room = city_room_matrix[room_position.x, room_position.y]; string track_name = RouteManager.shipyard_track_tilemap.GetTile(boxcar.tile_position).name; try { //print("boxcar track loc " + boxcar.station_track.start_location + " track name is " + track_name); RouteManager.Orientation exit_orientation = CityManager.station_track_unloading_map[boxcar.station_track.start_location][track_name]; StartCoroutine(GameObject.Find("PersonRouteManager").GetComponent <PersonRouteManager>().unload_train(boxcar, room, exit_orientation)); } catch (KeyNotFoundException k) { print("exit orientation not found"); } }
public IEnumerator one_time_straight_move(Boxcar prev_boxcar) { prev_boxcar.train.is_boxcar_filling_void = true; Vector3Int prev_boxcar_position = prev_boxcar.tile_position; //Vector3Int prev_boxcar_prev_tile_position = prev_boxcar.prev_tile_position; //Vector2Int prevboxcar_next_tilemap_position = prev_boxcar.next_tilemap_position; RouteManager.Orientation prev_orientation = prev_boxcar.orientation; Vector3 prev_destination = prev_boxcar.train_destination; //one_time_move_pass = true; // lets boxcar move even though train hasnt departed yet. yield return(StartCoroutine(simple_straight_move(transform.position, prev_boxcar.transform.position))); // dont set new positions until movement is completed //one_time_move_pass = false; tile_position = prev_boxcar_position; next_tilemap_position = (Vector2Int)prev_boxcar_position; prev_tile_position = prev_boxcar_position; orientation = prev_orientation; train_destination = prev_destination; prev_boxcar.train.is_boxcar_filling_void = false; }
public IEnumerator switch_on_vehicle(bool state, bool is_delayed = false) { if (is_delayed) { yield return(new WaitForSeconds(sprite_renderer_delay)); // if in the meantime, (during the delay) the game menu was toggled, mmake sure consistent with game menu state if (!GameManager.game_menu_state) { //print("game menu toggled OFF during delay. dont show BOXCAR sprite renderer"); yield break; } } else { yield return(null); } try { if (gameObject.tag == "boxcar") { Boxcar boxcar = gameObject.GetComponent <Boxcar>(); if (boxcar.is_occupied) { boxcar.passenger_go.GetComponent <SpriteRenderer>().enabled = state; } } if (gameObject.tag == "boxcar") { //print("boxcar " + gameObject.GetComponent<Boxcar>().boxcar_id + " sprite renderer state is " + state); } GetComponent <SpriteRenderer>().enabled = state; } catch (MissingReferenceException e) { print(e.StackTrace); } }
public void board_turntable(RouteManager.Orientation orientation, bool depart_turntable, City city = null) { if (depart_turntable) { if (CityManager.Activated_City_Component == city) { GameManager.sound_manager.play_train_bell(); } start_all_boxcar_at_turntable(); halt_train(true, false); //unhalt the boxcars halt_train(is_halt = false, is_pause = false); // unpause the train is_train_departed_for_turntable = true; city.remove_train_from_station(gameObject); } else // leaving the turntable { leave_city = true; foreach (GameObject boxcar_object in boxcar_squad) { Boxcar boxcar = boxcar_object.GetComponent <Boxcar>(); boxcar.leave_city = true; } } }
public static PositionPair get_destination(Simple_Moving_Object moving_thing, Tilemap tilemap, Vector2 offset) { // modify by offset for a person boarding a train (so hes not standing on the tracks) Vector3Int tile_coord = new Vector3Int(moving_thing.tile_position[0], moving_thing.tile_position[1], 0); Tile track_tile = (Tile)tilemap.GetTile(tile_coord); Vector2 tile_world_coord = tilemap.GetCellCenterWorld(tile_coord); PositionPair pos_pair = get_next_tile_pos(tilemap, track_tile, moving_thing, tile_coord, offset); if (moving_thing.gameObject.tag == "boxcar") { Boxcar bcar = (Boxcar)moving_thing; } if (!moving_thing.in_city) //not inside a city, so check if arrived at city { Tile city_tile = (Tile)city_tilemap.GetTile(tile_coord); if (city_tile != null) //check if arriving at city { City city = CityManager.instance.gameobject_board[tile_coord.x, tile_coord.y].GetComponent <City>(); // check if city arrived at is not the same city we're leaving pos_pair.abs_dest_pos = tile_world_coord; // destination is the center of the tile moving_thing.prepare_to_arrive_at_city(city); } } return(pos_pair); }
public IEnumerator Make_All_Boxcars_Depart(GameObject[,] board, List <GameObject> boxcar_list, Train train) { // start coroutine when a train departs or arrives at a city int boxcar_count = boxcar_list.Count; int boxcar_depart_id = 0; // counter // 1. train departs // 2. train is placed in city tile // 3. train calls Boxcar Depart Coroutine // 4. train moves to city boundary // 5. train updates tile position // 6. train confirms end of track is next tile // 7. train stops and tells boxcars to stop Vector3Int last_location = train.tile_position; ////print("train last location is " + last_location); RouteManager.Orientation depart_orientation = train.orientation; MovingObject last_vehicle = train; if (train.in_city) { board = train.get_city().city_board; } while (boxcar_depart_id < boxcar_count) { if (boxcar_depart_id >= boxcar_list.Count) { break; } GameObject boxcar = boxcar_list[boxcar_depart_id]; if (boxcar == null) { yield break; // the boxcar collidd with another train while entering city. } Boxcar moving_boxcar = boxcar.GetComponent <Boxcar>(); if (!is_vehicle_in_cell(last_location, board) && moving_boxcar.in_city == last_vehicle.in_city && !moving_boxcar.is_pause) // dont depart until boxcar has arrived at city { if (moving_boxcar.in_city && moving_boxcar.city != last_vehicle.city) { yield return(new WaitForEndOfFrame()); continue; } last_vehicle = moving_boxcar; moving_boxcar.departing = false; // reset departing //print("Make Boxcar depart. boxcar orientation is " + moving_boxcar.get_orientation() + " new tile position is " + last_location + "old tile position is " + moving_boxcar.tile_position); moving_boxcar.set_depart_status(true); if (train.in_city) { moving_boxcar.receive_train_order = true; } moving_boxcar.tile_position = last_location; place_vehicle(boxcar); moving_boxcar.is_halt = false; spawn_moving_object(moving_boxcar); moving_boxcar.set_depart_status(false); boxcar_depart_id++; game_manager.enable_vehicle_for_screen(boxcar); // switch on when boxcar is departing from the city. Dont show entire train cargo. //board[last_location.x, last_location.y] = boxcar.gameObject; } yield return(new WaitForEndOfFrame()); } }
public static RouteManager.Orientation get_start_orientation(string track_tile_name, Vector3 track_location, Vector3 destination, Boxcar boxcar) { // boarding train: home -> boxcar // when a train is instantiated, its orientation must match direction of trac // get orientation relative to city RouteManager.Orientation station_orientation = boxcar.station_track.station.orientation; int inner_track = boxcar.station_track.inner; // 0 if false, 1 if true if (track_tile_name == "vert") { return(get_y_axis_orientation(track_location, destination)); } else if (track_tile_name == "hor") { return(get_x_axis_orientation(track_location, destination)); } else if (track_tile_name == "NE") { if (station_orientation == RouteManager.Orientation.South) { return(RouteManager.Orientation.East); } else { if (inner_track == 0) { return(get_y_axis_orientation(track_location, destination)); // RouteManager.Orientation.West; // unloading! } else { return(get_x_axis_orientation(track_location, destination)); } // unloading or boarding } } else if (track_tile_name == "ES") { return(get_x_axis_orientation(track_location, destination)); } else if (track_tile_name == "WS") { if (station_orientation == RouteManager.Orientation.North) { return(get_x_axis_orientation(track_location, destination)); } else // SOUTH STATION { if (inner_track == 0) { return(get_x_axis_orientation(track_location, destination)); } else { return(RouteManager.Orientation.North); } // unloading } } else if (track_tile_name == "WN") { return(get_x_axis_orientation(track_location, destination)); } else { throw new Exception("no start orientation found"); } }
public override void OnPointerClick(PointerEventData eventData) { base.OnPointerClick(eventData); // use the previous hint context to do something, called on click anywhere in board RaycastHit2D[] selected_object = get_all_object_at_cursor(Input.mousePosition); List <Collider2D> collider_list = get_all_collider(selected_object); List <string> collider_tag_list = get_collider_name_list(collider_list); if (hint_context_list.Contains("board")) // behaves different from other hint contexts because eligible tiles are offset from tilemap and must be found by cloesst distance { if (collider_tag_list.Contains("boxcar")) // second condition checks if it is an eligible tile { if (is_tutorial_mode && !TutorialManager.board_flag) { TutorialManager.board_flag = true; StartCoroutine(tutorial_manager.activate_next_tutorial_step(6)); } GameObject boxcar_go = CityManager.get_vehicle_in_activated_city(collider_list, "boxcar"); // get the right boxcar (if exists) if they are on top of each other if (boxcar_go != null) { Boxcar boxcar = boxcar_go.GetComponent <Boxcar>(); if (boxcar.is_wait_for_turntable) // if user clicks on a leaving boxcar ignore { Vector2Int unoffset_boxcar_city_location = (Vector2Int)boxcar_go.GetComponent <Boxcar>().tile_position; //print("board boxcar with tile position " + unoffset_boxcar_city_location); int hint_index = is_selected_tile_in_context(unoffset_boxcar_city_location); if (hint_index != -1) { CityManager.Activated_City_Component.board_train(boxcar_go, hint_tile_pos); } } } } StartCoroutine(clear_hint_list()); // clearn hint list so no other hints get triggered during executing of this hint } else // hhint index is the context of the action (board, unload etc. ). Check if selection is valid for prior hint set. { Vector2Int selected_tile = get_selected_tile(Input.mousePosition); int hint_index = is_selected_tile_in_context(selected_tile); // get from offset grid for "board" if (hint_index != -1) // there is a hint. check if selection is valid { string hint_context = hint_context_list[hint_index]; if (hint_context == "add") // ADD BOXCAR { InventoryPusher ip = GameObject.Find("Shipyard Inventory").GetComponent <InventoryPusher>(); CityManager.instance.add_boxcar_to_station(ip.selected_tile.name, selected_tile, ip.selected_tile_pos); } else if (hint_context == "unload") { //print("unload from boxcar to city"); if (is_tutorial_mode && !TutorialManager.unload_flag && !TutorialManager.step_in_progress) { TutorialManager.unload_flag = true; StartCoroutine(tutorial_manager.activate_next_tutorial_step(5)); } if (hint_tile_go.GetComponent <Boxcar>().is_wait_for_turntable) { CityManager.Activated_City_Component.unload_train(hint_tile_go, selected_tile); // hint tile position is boxcar position } } else if (hint_context == "park") { Boxcar boxcar = hint_gameobject.GetComponent <Boxcar>(); boxcar.city.place_boxcar_tile(boxcar.boxcar_type, (Vector3Int)selected_tile); boxcar.city.add_boxcar_to_tilemap_with_location(boxcar.boxcar_type, selected_tile); VehicleManager.instance.boxcar_fill_void(hint_gameobject); // move boxcars behind this one forward boxcar.train.boxcar_squad.Remove(hint_gameobject); Destroy(hint_gameobject); //boxcar.train.remove_boxcar(boxcar.boxcar_id); } else if (hint_context == "north exit" || hint_context == "east exit" || hint_context == "west exit" || hint_context == "south exit") // DEPART TRAIN { if (is_tutorial_mode && !TutorialManager.exit_flag && !TutorialManager.step_in_progress) { TutorialManager.exit_flag = true; StartCoroutine(tutorial_manager.activate_next_tutorial_step(10)); } bool all_aboard = hint_gameobject.GetComponent <Train>().is_all_boxcar_boarded(); if (all_aboard) { hint_gameobject.GetComponent <Train>().exit_city(hint_context); } } else if (hint_context == "track") // PLACE TILE { Tile clicked_tile = hint_gameobject.GetComponent <GameMenuManager>().clicked_tile; TrackManager.instance.place_tile(selected_tile, clicked_tile, true); } else { throw new Exception("not a valid hint context"); } StartCoroutine(clear_hint_list()); // clearn hint list so no other hints get triggered during executing of this hint } else if (collider_list.Count > 0) { // call pointer events for boxcar and city from GameManager using Raycast data on the UI event detector hint_tile_pos = selected_tile; if (collider_tag_list.Contains("city_building") && CityManager.Activated_City_Component != null) // ADD A PERSON TO THE BOXCAR BOARD TRAIN HINT { if (is_tutorial_mode && !TutorialManager.room_flag && !TutorialManager.step_in_progress) { TutorialManager.room_flag = true; StartCoroutine(tutorial_manager.activate_next_tutorial_step()); } Collider2D collider = get_from_collider_list("city_building", collider_list); collider.gameObject.GetComponent <CityDetector>().click_room(eventData); } else if (collider_tag_list.Contains("boxcar") && CityManager.Activated_City_Component != null) { if (is_tutorial_mode && !TutorialManager.boxcar_flag && !TutorialManager.step_in_progress) { StartCoroutine(tutorial_manager.activate_next_tutorial_step()); } hint_tile_go = CityManager.get_vehicle_in_activated_city(collider_list, "boxcar"); if (hint_tile_go != null) { hint_tile_go.GetComponent <Boxcar>().click_boxcar(eventData); } } else if (collider_tag_list.Contains("train") && CityManager.Activated_City_Component != null) { if (is_tutorial_mode && !TutorialManager.train_flag && !TutorialManager.step_in_progress) { TutorialManager.boxcar_flag = false; TutorialManager.train_flag = true; StartCoroutine(tutorial_manager.activate_next_tutorial_step()); } hint_tile_go = CityManager.get_vehicle_in_activated_city(collider_list, "train"); if (hint_tile_go != null) { hint_tile_go.GetComponent <Train>().click_train(eventData); } } else if (collider_tag_list.Contains("inventory") && CityManager.Activated_City_Component != null) { Collider2D collider = get_from_collider_list("inventory", collider_list); collider.gameObject.GetComponent <InventoryPusher>().click_inventory(eventData); } else if (collider_tag_list.Contains("track_layer")) { GameObject veh = VehicleManager.vehicle_board[selected_tile.x + 1, selected_tile.y + 1]; if (veh == null || veh.GetComponent <MovingObject>().is_pause || veh.GetComponent <MovingObject>().is_halt) // dont switch track as vehicle is passing over it { TrackManager.instance.toggle_on_train_track(selected_tile); } } else if (collider_tag_list.Contains("structure")) { //print("collider tag list includes structure"); if (is_tutorial_mode && !TutorialManager.step_in_progress) { if (!selected_tile.Equals(CityManager.home_base_location)) { StartCoroutine(tutorial_manager.activate_next_tutorial_step()); } else { StartCoroutine(tutorial_manager.activate_next_tutorial_step()); } } GameObject city_object = CityManager.instance.get_city(selected_tile); // display boxcars switch_on_shipyard(true); CityManager.instance.set_activated_city(city_object); MenuManager.instance.activate_handler(new List <GameObject> { shipyard_exit_menu }); if (city_object != CityManager.home_base.gameObject) // not home base, dont show vehicle creation options { CityMenuManager.instance.turn_of_vehicle_in_exit_bar(false); } else { CityMenuManager.instance.turn_of_vehicle_in_exit_bar(true); } CityMenuManager.instance.change_bck_color(city_object.GetComponent <City>().city_type); } else { //invalid hint, clear hint list StartCoroutine(clear_hint_list()); // clearn hint list so no other hints get triggered during executing of this hint } } else // not taking action or setting a new hint { StartCoroutine(clear_hint_list()); } } }
public IEnumerator board_train(Boxcar boxcar, Room room, GameObject occupant_go, Vector3Int destination) { Person occupant = occupant_go.GetComponent <Person>(); GameManager.update_game_money_text(occupant.ticket_cost_map[occupant.desired_activity]); occupant.pop_thought_bubble(); occupant.board_train(); occupant.is_board_boxcar = true; boxcar.passenger_go = occupant_go; boxcar.is_occupied = true; // prevent another pserson from boarding the same boxcar occupant.boxcar_go = boxcar.gameObject; boxcar.is_being_boarded = true; room.booked = false; //print("set room instance to NULL"); room.person_go_instance = null; boxcar.passenger_go = occupant_go; GameObject door = get_exit_door(boxcar, room); room.unlocked_door = door; room.booked = false; // new stuff Door unlocked_door = room.unlocked_door.GetComponent <Door>(); // 2 checkpoints. In first go to doorstep and rotate accordingly. In the next only rotate to face track direction List <Checkpoint> board_train_checkpoints = new List <Checkpoint>(); Vector3Int train_start_location = boxcar.train.station_track.start_location; // id of track Orientation exit_orientation = CityManager.station_track_boarding_map[train_start_location]; Vector2Int doorstep_position = get_straight_next_tile_pos(exit_orientation, room.tile_position); string track_name = shipyard_track_tilemap.GetTile((Vector3Int)doorstep_position).name; occupant.final_dest_tile_pos = boxcar.tile_position; occupant.final_dest_pos = boxcar.transform.position; //start_orientation = CityManager.board_train_orientation_dict[boxcar.station_track.inner, 0]; Station boxcar_station = boxcar.station_track.station; Orientation start_orientation = CityManager.board_train_orientation_dict[boxcar_station.orientation][boxcar.station_track.inner, 0]; Orientation end_orientation = CityManager.board_train_orientation_dict[boxcar_station.orientation][boxcar.station_track.inner, 1]; occupant.arrived_at_room = false; yield return(StartCoroutine(unlocked_door.rotate(true))); string go_to_door_animation_name = get_animation_from_orientation(end_orientation, "walk"); if (end_orientation == Orientation.West) { occupant_go.GetComponent <SpriteRenderer>().flipX = true; } else if (end_orientation == Orientation.East) { occupant_go.GetComponent <SpriteRenderer>().flipX = false; } yield return(StartCoroutine(occupant.set_animation_clip(go_to_door_animation_name))); yield return(StartCoroutine(occupant.bezier_move(occupant.transform, start_orientation, end_orientation))); StartCoroutine(unlocked_door.rotate(false)); // go to doorstep (update tile position and orientation) Vector3 original_euler = occupant.transform.eulerAngles; occupant.transform.eulerAngles = new Vector3(0, 0, occupant.orient_angle); // use angle just to get direction of travelfor offset Vector3 offset_pos = occupant.transform.position + occupant.transform.up * .25f; occupant.transform.eulerAngles = original_euler; // restore angle Checkpoint go_to_doorstep_cp = new Checkpoint(offset_pos, doorstep_position, end_orientation, end_orientation, "walk"); board_train_checkpoints.Add(go_to_doorstep_cp); Orientation align_track_orientation = TrackManager.get_start_orientation(track_name, occupant.transform.position, boxcar.transform.position, boxcar); Checkpoint align_track_cp = new Checkpoint(offset_pos, doorstep_position, end_orientation, align_track_orientation, "walk"); // dont move just rotate board_train_checkpoints.Add(align_track_cp); // no need to align with track if destination is same tile as exit // if destination is reached immediately move to boxcar yield return(StartCoroutine(occupant.move_checkpoints(board_train_checkpoints))); // wait for all preboarding movements to end before going to boxcar room.has_person = false; // egghead is outside the room occupant.in_tile = false; // allow person to follow the track to the destination boxcar // if all goes well then boarding is all that's left occupant.exit_home(); occupant.final_orientation = occupant.orientation; }