diff --git a/src/Campaign.java b/src/Campaign.java index db488a5..3dfe0c7 100644 --- a/src/Campaign.java +++ b/src/Campaign.java @@ -12,6 +12,7 @@ public class Campaign { private Route route; private ArrayList vehicles = new ArrayList<>(); + private ArrayList arrivedVehicles = new ArrayList<>(); private Date timeToLeaveToDest; private Date timeToLeaveToHousing; @@ -32,8 +33,8 @@ public class Campaign { public void busArived(Bus bus) { if(numberOfAriivedBuses < vehicles.size()) + arrivedVehicles.add(bus); numberOfAriivedBuses++; - //Check if it is in list before increment? } public boolean isDone() { @@ -49,7 +50,8 @@ public class Campaign { for (Vehicle vehicle : vehicles) { vehicle.setRoute(route); } - //since a route is set, reset buses. + //since a route is set, reset buses and clear arrivedBussesList + this.arrivedVehicles.clear(); this.numberOfAriivedBuses = 0; } @@ -83,6 +85,15 @@ public class Campaign { return busses; } + public int getNumberOfArrivedBuses() { + return getArrivedVehicles().size(); + } + + //Use this in Makkah to optimize later + public ArrayList getArrivedVehicles() { + return arrivedVehicles; + } + public ArrayList getVehicles() { return vehicles; } diff --git a/src/Vehicle.java b/src/Vehicle.java index 22f9044..77836af 100644 --- a/src/Vehicle.java +++ b/src/Vehicle.java @@ -1,4 +1,5 @@ import java.util.Date; +import java.util.HashMap; public abstract class Vehicle { @@ -11,6 +12,10 @@ public abstract class Vehicle { private boolean moving; private Date timeStartedMoving; private Date timeOfArrival; + private Date timeStartedOnCurrentStreet; + + //Map Street to Minutes + private HashMap routeTimeHistory = new HashMap<>(); public abstract int getMaxSpeed(); @@ -84,6 +89,7 @@ public abstract class Vehicle { this.currentStreet = currentStreet; if (this.currentStreet != null) this.currentStreet.addVehicle(this); + this.timeStartedOnCurrentStreet = MakkahCity.getTimeMan().getCurrentTime(); } public void setCurrentLocation(double currentLocation) { @@ -131,6 +137,7 @@ public abstract class Vehicle { } public void moveToNextStreet() { + this.routeTimeHistory.put(this.currentStreet, MakkahCity.getTimeMan().getCurrentTime().getTime() - timeStartedOnCurrentStreet.getTime()); int nxtIndex = route.indexOf(this.getCurrentStreet()) + 1; if (nxtIndex <= route.getStreets().length - 1) { if (this.getRoute().getStreets()[nxtIndex].capcityPoint(0, 1000) < 1) {