While unfinished work is probably the biggest time waste for many programmers, I have taken the view that any time spent working on my project is constructive. Any ideas that make it into the program are successes and the failed ones are lessons.
So, this week I have been working a lot IRL so my time has been spent planning the Table Service aspect of my game. Working with time in Java was an initial hurdle but didn't require too much googling to ensure I was getting the numbers I needed in the format that worked for me. Each guest will be able to generate a set of times which state how long an aspect of their stay will take. John might take two minutes to eat, but Sally might take twenty five. Using this knowledge, the game is able to check for an "all ready" like state, by comparing the state of each guest and acting when all of them match. Using this system requires a set of enum types for the Guest and also for the Table to use as state markers which can be looked at by the other Entities. States in this way happen to be far more effective for the long list of possible states than boolean values had been, as rather than turning one value to true and another to false, the overall state simply switches. This makes a list of instructions much more safe to run as the state can only be one at a time, and no accidentally crosslined booleans will throw me off.
if(!isActive){
return;
}
elapsedTime = timeSat + System.currentTimeMillis();
if(state == guestState.sat){
if(startOrderTimer <= 0) startOrderTimer = System.currentTimeMillis();
if(startDrinkOrderTimer <= 0){
startDrinkOrderTimer = System.currentTimeMillis();
}
if(System.currentTimeMillis() - startDrinkOrderTimer > drinkOrderTime){
state = guestState.drinkOrderReady;
}
} else {
return;
}
if(state == guestState.drinkOrderReady){
// when Orders system implemented, fill in order creation here
}
if(state == guestState.drinkOrderTaken){
if(startOrderTimer <= 0){
startOrderTimer = System.currentTimeMillis();
}
if(System.currentTimeMillis() - startOrderTimer >= orderTime){
state = guestState.foodOrderReady;
}
}
In this early example of a guests update method you can see that the state is modified when criteria are met such as an elapsed time and manage progression through a typical service by acting as flags that the table can look for in each guest to create a Task that can then be acted upon by a Staff entity.The table itself is able to scan through any number of occupying guests in order to check that all guests are in the same state, as shown here.
private void getGuestStates() {
if(guests[0].getState() == guestState.sat){
return;
}
Guest.guestState[] states = new Guest.guestState[guests.length];
for (int i = 0; i < guests.length; i++) {
states[i] = guests[i].getState();
}
Guest.guestState temp1 = guests[0].getState();
for (Guest.guestState state : states) {
Guest.guestState temp = state;
if (temp1 == temp) {
temp1 = temp;
} else {
return;
}
System.out.println("Table has determined that all guests' states match: " + state);
}
}
The initial state of guestState.sat will progress from within the Guest so if this state is in place then we save cpu time by exiting the getGuestStates() method. Checking against a fixed array index guests[0] is not a problem as a guests array is not able to have fewer than 1 entry, as 1 is the minimum number of guests in a group (which seems redundant to have a group of 1, but this is simply a container for the guests to proceed into the restaurant queuing system).Once the basic framework for the states is finished I will make all new table placeholder sprites to help show the state visually. This may be a layered approach using the base table and then an "items on table" type layer such as is used in RPGMaker, but that will come in its own time. I have 3 days booked off this coming week and hope to spend a good chunk of them coding. Until then!