// supermarket.C: the supermarketSim class

#include "supermarket.h"
#include "endsimEvent.h"
#include "reportEvent.h"
#include "arrivalEvent.h"

// Simulation constants:
// demand: maximum amount of items needed by a customer
// See Cust constructor.
const double SupermarketSim::itemsBoughtMax = 80;
// service times: constant base time + time per item 
// See Cashier.serviceTime().
const double SupermarketSim::serviceTimeBase = 60;
// time to scan and put in package (per item)
const double SupermarketSim::serviceTimePerItem = 3;
// Total number of cashiers in simulation
const int SupermarketSim::cashierCount = 20;

// Run simulation
void SupermarketSim::start()
{
   // Schedule the required events:
   //   the end of the simulation;
   //   the first progress report;
   //   the arrival of the first customer.
   eventList.insert( new EndOfSimulationEvent( endingTime ) );

   if( reportInterval <= endingTime ) 
      eventList.insert( new ReportEvent( reportInterval ) );

   eventList.insert( new ArrivalEvent( 0 ) );

   stats.printHeaders();

   // The "clock driver" loop
   simulating = true;
   while( simulating ) {
      Event *currentEvent = eventList.takeNextEvent();
      simulationTime = currentEvent->getTime();
      currentEvent->makeItHappen();
   }
}
