diff --git a/src/log/Colleague.cpp b/src/log/Colleague.cpp index d6d58bb..aa85f59 100644 --- a/src/log/Colleague.cpp +++ b/src/log/Colleague.cpp @@ -19,7 +19,7 @@ void Colleague::notify(std::vectorcars, Race* r) { void Colleague::notify(eng::Car *broken, Race *r) { std::vector brokenCar; brokenCar.push_back(broken); - logisticsDept->sendCarToFactory(brokenCar, r, true) + logisticsDept->sendCarToFactory(brokenCar, r, true); } diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index e630920..2000ed2 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -20,6 +20,9 @@ using namespace lg; // TODO : @jo Implement and check accuracy of pop and push for cars +// IDEA : approach budget people in the middle to ask for raise? +// IDEA : use up the budget +// TODO : @both fix memleaks /** * @author Jo @@ -31,7 +34,6 @@ Logistics::Logistics(int numDriverCarPairs) { carsInSeasonIDs.reserve(numDriverCarPairs); seasonPointTally.reserve(numDriverCarPairs); transportManager = nullptr; - raceIterator = nullptr; racingCalendar = nullptr; europeanContainer = nullptr; currentTeamStrategy = nullptr; @@ -39,7 +41,16 @@ Logistics::Logistics(int numDriverCarPairs) { budget = -1; } -Logistics::~Logistics() = default; +// TODO : @jo finish destructor +Logistics::~Logistics(){ + if (transportManager) delete transportManager; + if (racingCalendar) { + //delete accordingly + } + if (europeanContainer) delete europeanContainer; + if (currentTeamStrategy) delete currentTeamStrategy; + if (tyreSpecs) delete tyreSpecs; +}; /** * @status completed @@ -67,6 +78,7 @@ void Logistics::doYearPlanning() { //2. Hire emplpoyees: each department for (auto const&[key, val] : departments) { + //TODO : check by departemente - kan julle dit hanteer dat ons re-hire gegewe 'n tweede seisoen? val->hireEmployees(budget); } @@ -178,14 +190,11 @@ void Logistics::simulateEvent(Race *r) { } //2. Transport Drivers + //IDEA : add fly functionality for drivers pr::Doc::detail("The two drivers are transported in a luxury mode of transport to "); pr::Doc::detail(r->getLocation()); - //Transport drivers - //IDEA : add fly functionality for drivers - //3. get correct container, transport and fly and fly - transportManager->transport(r->prevRace(), r); if (r->isRaceEuropean()) { callRacingDept()->preRaceArrival(carClipboard, drivers, r, getEuropeanContainer(), tyreSpecs); @@ -218,7 +227,7 @@ void Logistics::simulateEvent(Race *r) { /** * @author Jo - * @status nearly there + * @status I wash my hands off this one */ void Logistics::putRacesIntoCalender() { racingCalendar = new RacesList; @@ -257,8 +266,13 @@ void Logistics::putRacesIntoCalender() { void Logistics::raceSeason() { //And the season starts pr::Doc::summary("And the season begins!"); + int developTracker = 0; for (RaceIterator t = racingCalendar->begin(); !(t == racingCalendar->end()); ++t) { simulateEvent(t.currentItem()); + developTracker++; + if (developTracker==7 || developTracker==14) { //third of the way through + carsInDevIDs.push_back(callEngDept()->buildCar(budget)); + } } } @@ -371,13 +385,14 @@ void Logistics::driverBootCamp() { } } -void Logistics::sponsoredBudget(int sumPositions) { +void Logistics::sponsoredBudget(int sumPositions) { //default is 0 pr::Doc::summary("Approaching sponsors to negotiate a new budget\n"); - if (budget == 0) { //default argument + if (budget == -1) { //default argument in constructor budget = abs(rand() % 100 + 1); } else { + //todolist : check accuracy at runtime if (sumPositions >= 3) { pr::Doc::detail("Rolex is the team's next sponsor! Budget increases wildly\n"); budget = max((int) ((double) budget * 1.5), (100 - (int) ((double) budget * 0.5))); @@ -403,6 +418,7 @@ void Logistics::sponsoredBudget(int sumPositions) { void Logistics::sendCarToFactory(std::vector cars, Race *r, bool isBroken) { if (isBroken) { for (int i = 0; i < cars.size(); ++i) { + // TODO: @marike descriptionality of the rush to get the car fixed transportManager->transport(r, nullptr, cars[0]); callEngDept()->carArrivesAtFactory(cars[0]); callEngDept()->fixCar(cars[0]->getId()); diff --git a/src/log/Logistics.h b/src/log/Logistics.h index 3ad6445..2dc0df5 100644 --- a/src/log/Logistics.h +++ b/src/log/Logistics.h @@ -64,9 +64,9 @@ namespace lg { std::vector drivers; TransportHandler *transportManager; //Won't be holding a handle to car as will always be passing directly from one place to another - RaceIterator *raceIterator; RacesList *racingCalendar; std::vector carsInSeasonIDs; + std::vector carsInDevIDs; std::vector nonEuropeanContainers; //lots of containers for non-European Container *europeanContainer; //1 container for European rce::CreateStrategy *currentTeamStrategy; diff --git a/src/log/races/Race.cpp b/src/log/races/Race.cpp index 638c02d..ce0d0f9 100644 --- a/src/log/races/Race.cpp +++ b/src/log/races/Race.cpp @@ -102,6 +102,8 @@ int Race::getTrackID() { return id; } +Race::~Race() = default; + /*std::ostream &lg::operator<<(std::ostream &os, const Race &rc) { os << rc.location << '/nEurope: ' << rc.isInEurope << '/nNumLaps: ' << rc.numLaps << std::endl; return os; diff --git a/src/log/races/Race.h b/src/log/races/Race.h index c61f678..787054b 100644 --- a/src/log/races/Race.h +++ b/src/log/races/Race.h @@ -26,6 +26,8 @@ namespace lg { Race(std::string, int complexity, bool inEU, int laps, Race *next = nullptr, Race *prev = nullptr); + ~Race(); + void setNextRace(Race *); void setPrevRace(Race *); diff --git a/src/log/races/RaceIterator.cpp b/src/log/races/RaceIterator.cpp index 9d07846..ef34d14 100644 --- a/src/log/races/RaceIterator.cpp +++ b/src/log/races/RaceIterator.cpp @@ -21,7 +21,6 @@ void RaceIterator::first() { current = head; } -//RaceIterator RaceIterator::operator++() { void RaceIterator::operator++() { if (this != nullptr) { this->current = this->current->nextRace(); diff --git a/src/log/races/RacesList.cpp b/src/log/races/RacesList.cpp index 2c7df0c..3cca13a 100644 --- a/src/log/races/RacesList.cpp +++ b/src/log/races/RacesList.cpp @@ -7,6 +7,7 @@ #include "Doc.h" namespace lg { + // TODO : find suitable spot for this function std::string convertComplexityToString(TrackComplexity t) { switch (t) { case Easy: @@ -28,6 +29,15 @@ RacesList::RacesList() { numRaces = 0; } +RacesList::~RacesList() { + for (RaceIterator t = begin(); !(t == end()); ) { + Race* temp = t.currentItem(); + ++t; + delete temp; + } + +} + //IS DONE? void RacesList::addRace(Race *race) { if (isEmpty()) { diff --git a/src/log/races/RacesList.h b/src/log/races/RacesList.h index 154679b..9226873 100644 --- a/src/log/races/RacesList.h +++ b/src/log/races/RacesList.h @@ -10,18 +10,16 @@ #include "RaceIterator.h" namespace lg { -//class RacesList : public Aggregate { class RacesList { friend class RaceIterator; public: -// RaceIterator createIterator() override; RacesList(); - //RaceIterator createIterator(); + ~RacesList(); + void addRace(Race *); - //Race* removeRace(); Race *getHeadRace() const; bool isEmpty(); diff --git a/src/main.cpp b/src/main.cpp index 9158838..889b58d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "ppl/factories/KidnapStudent.h" #include "eng/EngTeam.h" #include "rce/RacingDep.h" @@ -18,23 +19,52 @@ int pr::Doc::transparency = 1; void logDeptTesting(); void engTeamTesting(); -void seasonRun(); +void seasonRun(lg::Logistics*); void testTyres(); - +void proto_FinalMain(); int main() { - //logDeptTesting(); + logDeptTesting(); //engTeamTesting(); - seasonRun(); + //seasonRun(); + // proto_FinalMain(); // testTyres(); + + } -void logDeptTesting() { +void proto_FinalMain() { auto* racingDept = new rce::RacingDep(); auto* engDept = new eng::EngTeam; + auto* logDept = new lg::Logistics; + + srand(time(0)); + logDept->registerNotifier(racingDept); + logDept->registerNotifier(engDept); + + seasonRun(logDept); + + delete racingDept; + delete engDept; + delete logDept; + +} + + +void seasonRun(lg::Logistics* a) { + a->doYearPlanning(); + a->preSeasonPreparation(); + a->raceSeason(); + a->postSeasonDebrief(); +} + +void logDeptTesting() { + //Testing containers + /* auto* racingDept = new rce::RacingDep(); + auto* engDept = new eng::EngTeam; auto* a = new lg::Logistics; lg::TransportHandler* curator = new lg::Road; @@ -53,33 +83,17 @@ void logDeptTesting() { delete racingDept; delete engDept; - delete a; + delete a;*/ + //Testing racingCalender destructor + lg::RacesList* r = new lg::RacesList; + r->addRace(new lg::Race("Australia", 0, 0,12)); + r->addRace(new lg::Race("Benoni", 1, 1,21)); + r->addRace(new lg::Race("Cambridge", 2, 0,112)); + r->addRace(new lg::Race("Dallas", 0, 1,212)); + r->printList(); + delete r; } -void seasonRun() { - auto* racingDept = new rce::RacingDep(); - auto* engDept = new eng::EngTeam; - auto* a = new lg::Logistics; - a->registerNotifier(racingDept); - a->registerNotifier(engDept); - a->doYearPlanning(); - a->preSeasonPreparation(); - a->raceSeason(); - a->postSeasonDebrief(); - delete racingDept; - delete engDept; - delete a; - /*engDept->hireEmployees(50); - engDept->resetTickets(); - engDept->setRiskLevel(lg::Aggressive); - int id = engDept->buildCar(50); - eng::Car* car = engDept->checkCarOutOfFactory(id); - car->print();*/ - - engDept. - - -} void engTeamTesting() { auto *e = new eng::EngTeam();