Friday, 15 January 2016

Customer

Brief Description

In this section of the blog I have many things to explain so you'll fully comprehend and understand what I've achieved therefore I hope you'll be patient as I will explain everything in detail eventually. 

My customers walk using a node based, four directional, algorithm I developed. The customer spawns at a randomly placed door in the scene and will quickly identify an unoccupied table. The customer will travel t'wards the table using the shortest possible route.

If there aren't any unoccupied tables the customer will wander randomly about the restaurant for a duration of thirty seconds before leaving. If a table becomes unoccupied during this thirty second period, the customers timer will be paused and they'll travel t'wards the table. If, unluckily, the table becomes occupied as they're travelling t'wards it the customers timer will resume and they'll wander randomly once again.

The customer doesn't contain advanced AI allowing them to navigate around objects. This is a necessity I hope to implement soon and will keep the blog updated of my attempts. 

Once the customer occupies a table they'll order, at random, a meal from the menu and then wait for a period of thirty seconds to be served. If they aren't served within thirty seconds they'll leave. If they're served within thirty seconds they'll wait for their meal, eat the meal, pay and then leave.

Node based Pathfinding

I mentioned in my opening description that my customer's artificial intelligence follows a node based, four directional, pathfinding algorithm. This means I've placed nodes throughout the game, one per tile, invisible to the user which contains positional data essential for my code.

'Four directional' pathfinding means the customer can only move in four directions. The customer can move forward, backwards, left and right. I wrote my code this way to provide a tile based looking game as I want my game to appear two dimensional.

My code works by reading in the active waypoints, finding an unoccupied table, locating the node which shares the same X and Z position and finally setting the waypoint as the target. 

Next, I find the nodes right, left, forward and backwards from the customers position and identify the closest node to the target. The customer travels t'wards the closest node and repeats this step until the target is found.

At the beginning of every cycle I check the target's occupancy. If the target is occupied the customer locates a random active waypoint to travel t'wards. If thirty seconds have passed without sitting at an unoccupied table or the customer has finished their meal the code sets the target to a random door and leaves. Once at the door the customers are destroyed.

Waiting for a Meal

When a customer sits at the table it first changes the tables occupancy to occupied. It achieves this by finding the script opponent attached to the table and then sets it's occupied value to true.

Next, to alert waiters they're ready to order the customer has to create and add an order to the list of orders. The order will contain a meal, selected at random from the database of unlocked recipes, and the table's name. The customer will then start it's waiting graphic which shows the user the time remaining before they leave. 
Figure 1a
 Figure 1b

Figure 1b is displayed just above the customer's head to provide the user with visual representation of the customer's waiting time. I'm hoping the user will use this to note the average waiter response time and decide whether they need more staff. 

The green bar is placed over the red and the width is decreased one thirtieth of it's size per second. Once the bar reaches zero they leave and the graphic is removed. If the waiter takes the order before the timer reaches zero, the timer is stopped and the graphic is removed.

Eating a Meal

Eating the meal is essentially a lot like waiting for a meal however the duration in which it takes to consume a meal is dependant on the meal itself. Each recipe, when added to the recipe database, requires a time in which it takes the customer to consume. I take the time from the recipe and apply it to my eating graphic.

Figure 2a
 Figure 2b

Once the timer on the eating graphic reaches zero the cost of the meal, also added to the recipe when added to the recipe database, is added to the users coin count. 

No comments:

Post a Comment