-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatusCommand.cpp
More file actions
74 lines (56 loc) · 2.4 KB
/
Copy pathStatusCommand.cpp
File metadata and controls
74 lines (56 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Company.h"
#include "Language.h"
#include "StatusCommand.h"
#include "Market.h"
#include "MasterState.h"
#include "Platform.h"
#include "Project.h"
#include <stdio.h>
#include <vector>
using std::vector;
#include <map>
using std::map;
#include <string>
using std::string;
StatusCommand::StatusCommand(MasterState *masterState) : CommandFunctor(masterState, "status", "Get a summary of how you are doing. No time passes.") {
}
void StatusCommand::executeCommand(const char *line) {
Company *playerCompany = this->_masterState->getPlayerCompany();
int money = playerCompany->getMoney();
vector<Person *> *employees = playerCompany->getEmployees();
vector<Project *> *projects = playerCompany->getProjects();
map<Platform *, int> *platformSkills = playerCompany->getPlatformSkills();
char message[100];
sprintf(message, "You currently have %d money", money);
this->_masterState->addMessage(message);
sprintf(message, "You have %lu employees", employees->size());
this->_masterState->addMessage(message);
sprintf(message, "You have %lu projects", projects->size());
this->_masterState->addMessage(message);
map<string, int> *score = new map<string, int>();
for (vector<Project *>::iterator it = projects->begin(); it != projects->end(); ++it) {
Project *p = *it;
Platform *platform = p->getPlatform();
map<string, int> *requirements = platform->getRequires();
for (map<string, int>::iterator it2 = requirements->begin(); it2 != requirements->end(); ++it2) {
(*score)[it2->first] -= it2->second;
}
map<string, int> *provides = platform->getProvides();
for(map<string, int>::iterator it2 = provides->begin(); it2 != provides->end(); ++it2) {
(*score)[it2->first] += it2->second;
}
sprintf(message, "\t%s-based %s for %s\n", platform->getFullName(), p->getLanguage()->getFullName(), p->getMarket()->getFullName());
this->_masterState->addMessage(message);
for(map<string, int>::iterator it2 = score->begin(); it2 != score->end(); ++it2) {
sprintf(message, "\t%s: %d\n", it2->first.c_str(), it2->second);
this->_masterState->addMessage(message);
}
}
this->_masterState->addMessage("Your skills in platforms are as follows:");
for (map<Platform *, int>::iterator it = platformSkills->begin(); it != platformSkills->end(); ++it) {
sprintf(message, "\t%s: %d", it->first->getName().c_str(), it->second);
this->_masterState->addMessage(message);
}
}
StatusCommand::~StatusCommand() {
}