protected void goToRestaurant() { int restNumber; if (!goToWork || jobBuilding == null) { while (true) { restNumber = (int) (Math.random() * 7); if (restNumber >= 6) { bigState = BigState.goHome; return; } else if ((cityData.restaurants.get(restNumber)).isOpen()) break; } destinationBuilding = cityData.restaurants.get(restNumber); } else { destinationBuilding = jobBuilding; } if (destinationBuilding != currentBuilding) { System.out.println("Going to restaurant as " + desiredRole); GoToDestination(); personGui.DoGoToBuilding(destinationBuilding.buildingNumber); try { atBuilding.acquire(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); } currentBuilding = destinationBuilding; } Building restaurant = destinationBuilding; if (goToWork && !desiredRole.equals("Customer")) { if (desiredRole.equals("Host") && !restaurant.hasHost()) { personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); return; } else if (restaurant.openToEmployee()) { if (desiredRole.equals("Waiter") || desiredRole.equals("Cook")) { personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); return; } else if (desiredRole.equals("Cashier") && !restaurant.hasCashier()) { personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); return; } } } // This is only reached if the person is unemployed if (desiredRole.equals("Customer") && restaurant.isOpen()) { personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); bigState = BigState.waiting; return; } bigState = BigState.goHome; homeState = HomeState.onCouch; }
protected void goToMarket() { int marketNumber = 0; destinationBuilding = cityData.markets.get(0); GoToDestination(); personGui.DoGoToBuilding(19); currentBuilding = cityData.buildings.get(19); atBuilding.drainPermits(); try { atBuilding.acquire(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); } personGui.DoGoIntoBuilding(); currentBuilding.EnterBuilding(this, desiredRole); }
protected void goToBank() { int bankNumber = 0; destinationBuilding = cityData.banks.get(bankNumber); GoToDestination(); personGui.DoGoToBuilding(18); currentBuilding = cityData.buildings.get(18); atBuilding.drainPermits(); try { atBuilding.acquire(); if (currentBuilding.type == BuildingType.bank) print("made it past at Building acquire"); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); } personGui.DoGoIntoBuilding(); print("entering the building and desired role is " + desiredRole); currentBuilding.EnterBuilding(this, desiredRole); }
public void GoToDestination() { currGrid = cityData.cityGrid[personGui.getX() / 20][personGui.getY() / 20]; if (walk == true) { personGui.DoGoToBuilding(destinationBuilding.buildingNumber); // PersonGui.DoWalk(if you ever hit an RGrid, acquire it first, and then walk through, and // don't walk through bgrids) walking = true; while (walking) { if (crossingRoad) { try { currRGrid.occupied.acquire(); // System.out.println("1"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { nextRGrid.occupied.acquire(); // System.out.println("2"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } personGui.crossRoad(); try { gridding.acquire(); } catch (Exception e) { } currRGrid.occupied.release(); // System.out.println("1"); nextRGrid.occupied.release(); // System.out.println("0"); // ACQUIRE CURRENT AND NEXT } else { // // go from grid to grid // currGrid = nextGrid //// if undo //// if(curr instanceof RGrid) { //// person.acquire those next two semaphores in that direction //// personGui.crossRoad(direction); //// move to next //// release roads //// } // else { // //personGui.MoveToNextGrid; // } // print("hello"); personGui.MoveToNextGrid(currGrid); try { gridding.acquire(); } catch (Exception e) { } } } } if (car == true) { currentBuilding.closest.acquireGrid(); currRGrid = currentBuilding.closest; personGui.DoWalkToRGrid(currentBuilding.buildingNumber); // personGui.//acquire the semaphore of the // road(currentBuilding.closest.index1(),currentBuilding.closest.index2()) // then he moves like a bus until he gets to his destinatoin's rgrid, gets off road // then he releases last road semaphore isMoving.drainPermits(); try { isMoving.acquire(); } catch (Exception e) { } System.err.println("hello"); personGui.getInOrOutCar(); personGui.DriveToDestination(destinationBuilding); // personGui.DriveToClosestRGrid(destinationBuilding); **** have similar mechanisms to // busgridbehavior // if person's rgrid is destination.closestRgrid, then, walk to building driving = true; while (driving) { if (gridToAcquire != null) { MoveToGrid(); continue; } // puts this "mini-scheduler" to sleep try { isMoving.acquire(); } catch (Exception e) { } } // remember to release current and previous grids currRGrid.releaseGrid(); prevRGrid.releaseGrid(); gridToAcquire.releaseGrid(); // WALKT TO THE BUILDING NOW currRGrid = currentBuilding.closest; /*currRGrid = currentBuilding.closest; >>>>>>> 0a17ff0b1dfacf5cdfd33fa5a6faac8714cda482 //personGui.; driving = true; while(driving) { try { //.acquire(); } catch(Exception e){} personGui.getInOrOutCar(); //personGui.DriveToClosestRGrid(destinationBuilding); **** have similar mechanisms to busgridbehavior //if person's rgrid is destination.closestRgrid, then, walk to building try { isMoving.acquire(); } catch(Exception e){} driving = false; }*/ // personGui // have similar mechanisms to busgridbehavior // if person's rgrid is destination.closestRgrid, then, walk to building // YOU WILL TURN INTO A ROBOT } if (bus == true) { destinationBusStop = currentBuilding.busStop; personGui.DoGoToBusStop(destinationBusStop); try { isMoving.acquire(); } catch (Exception e) { } currentBusStop = destinationBusStop; destinationBusStop = destinationBuilding.busStop; currentBusStop.msgWaitingAtStop(this, destinationBusStop); try { isMoving.acquire(); } catch (Exception e) { } if (currentBus == null) { try { isMoving.acquire(); } catch (Exception e) { } } personGui.DoGoToBus(currentBus); try { isMoving.acquire(); } catch (Exception e) { } cityData.guis.remove(personGui); currentBus.msgOnBus(); try { isMoving.acquire(); } catch (Exception e) { } cityData.guis.add(personGui); personGui.setXPos(currentBus.getX()); personGui.setYPos(currentBus.getY()); currentBus.msgOnBus(); personGui.DoGoToBusStop(destinationBusStop); // THIS SHOULD ACQUIRE ROAD SEMAPHORE // if it needs to try { isMoving.acquire(); } catch (Exception e) { } } currentBuilding = destinationBuilding; }
protected void goHome() { // int homeNumber = (int)((int)(Math.random()*11)); destinationBuilding = cityData.buildings.get(this.home.buildingNumber); boolean busser = false; boolean driver = false; if (once) { if (bus == true) { busser = true; } if (car == true) { driver = true; } if (bus || car) { walk = true; bus = false; car = false; } } if (once) { if (busser) { bus = true; walk = false; } if (driver) { car = true; walk = false; } } once = false; personGui.DoGoToBuilding( this.home.buildingNumber); // 11 need to be replaced by the person's data of home number try { atBuilding.acquire(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); } currentBuilding = destinationBuilding; personGui.DoGoIntoBuilding(); if (home instanceof Home) { currentBuilding.EnterBuilding(this, ""); } if (home instanceof Apartment) { Apartment a = (Apartment) home; a.EnterBuilding(this, ""); personGui.DoGoToRoom(roomNumber); try { isMoving.acquire(); } catch (InterruptedException e) { // Auto-generated catch block e.printStackTrace(); } a.rooms.get(roomNumber).EnterBuilding(this, ""); } bigState = BigState.atHome; homeState = HomeState.onCouch; // hungerLevel = 10000000; }