-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompany.cpp
199 lines (168 loc) · 5.77 KB
/
Company.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "Company.h"
#include "Language.h"
#include "Person.h"
#include "Platform.h"
#include "Trait.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Company::Company(const char *name, int money) {
this->_name = (char *)malloc(strlen(name) + 1);
strcpy(this->_name, name);
this->_money = money;
this->_employees = new vector<Person *>();
this->_knownPeople = new vector<Person *>();
this->_platformSkills = new map<Platform *, int>();
this->_languageSkills = new map<Language *, int>();
this->_allProjects = new vector<Project *>();
}
vector<Project *> *Company::getProjects() {
return this->_allProjects;
}
void Company::addProject(Project *p) {
this->_allProjects->push_back(p);
}
void Company::addEmployee(Person *person) {
this->_employees->push_back(person);
this->recomputeCompanySkills();
for (vector<Person *>::iterator it = this->_knownPeople->begin(); it != this->_knownPeople->end(); ++it) {
Person *p = *it;
if (p == person) {
this->_knownPeople->erase(it);
return;
}
}
}
/**
* Companies, just like people have skills. The skill of a company is based on
* the skill of the employees, but it's not a simple summing. No no, here's
* where some OMG biting comentary comes in. The formula is actually thus:
*
* average(maximum + average)
*
* That is, I take the average skill across all employees, add it to the maximum
* skill of all employees, and divide by two. This isn't *exactly* what I want,
* but it's the closest simple formula I've found. It satisfies my two biggest
* desires for this function:
*
* 1) Adding an idiot lowers the skill level, not increases it.
* 2) Adding someone smarter than all other employees raises the skill level.
*/
void Company::recomputeCompanySkills() {
map<Platform *, int> tmpSkillListTotals;
map<Platform *, int> highestSkill;
for (vector<Person *>::iterator it = this->_employees->begin(); it != this->_employees->end(); ++it) {
Person *employee = *it;
map<Platform *, int> *employeePlatformSkills = employee->getPlatformSkills();
for (map<Platform *, int>::iterator it2 = employeePlatformSkills->begin(); it2 != employeePlatformSkills->end(); ++it2) {
int existingSkill = tmpSkillListTotals[it2->first];
existingSkill += it2->second;
tmpSkillListTotals[it2->first] = existingSkill;
if (it2->second > highestSkill[it2->first])
highestSkill[it2->first] = it2->second;
}
}
for (map<Platform *, int>::iterator it3 = tmpSkillListTotals.begin(); it3 != tmpSkillListTotals.end(); ++it3) {
(*this->_platformSkills)[it3->first] = ((it3->second / this->_employees->size()) + highestSkill[it3->first]) / 2;
}
map<Language *, int> tmpLanguageListTotals;
map<Language *, int> highestLanguage;
for (vector<Person *>::iterator it = this->_employees->begin(); it != this->_employees->end(); ++it) {
Person *employee = *it;
map<Language *, int> *employeeLanguageSkills = employee->getLanguageSkills();
for (map<Language *, int>::iterator it2 = employeeLanguageSkills->begin(); it2 != employeeLanguageSkills->end(); ++it2) {
int existingSkill = tmpLanguageListTotals[it2->first];
existingSkill += it2->second;
tmpLanguageListTotals[it2->first] = existingSkill;
if (it2->second > highestLanguage[it2->first])
highestLanguage[it2->first] = it2->second;
}
}
for (map<Language *, int>::iterator it3 = tmpLanguageListTotals.begin(); it3 != tmpLanguageListTotals.end(); ++it3) {
(*this->_languageSkills)[it3->first] = ((it3->second / this->_employees->size()) + highestLanguage[it3->first]) / 2;
}
}
map<Platform *, int> *Company::getPlatformSkills() {
return this->_platformSkills;
}
map<Language *, int> *Company::getLanguageSkills() {
return this->_languageSkills;
}
void Company::advanceTime(int time) {
this->learnAboutEmployees();
}
void Company::learnAboutEmployees() {
for (vector<Person *>::iterator it = this->_knownPeople->begin(); it != this->_knownPeople->end(); ++it) {
Person *person = *it;
if (rand() % 10 == 0) {
list<Trait *> *allTraits = person->getRealTraits();
for (list<Trait *>::iterator it2 = allTraits->begin(); it2 != allTraits->end(); ++it2) {
Trait *t = *it2;
if (rand() % 10 == 0) {
t->discoverMore();
}
}
}
}
}
vector<Person *> *Company::getKnownPeople() {
return this->_knownPeople;
}
void Company::addKnownPerson(Person *person) {
for (vector<Person *>::iterator it = this->_employees->begin(); it != this->_employees->end(); ++it) {
Person *p = *it;
if (p == person)
return;
}
this->_knownPeople->push_back(person);
}
void Company::doPayments(int time) {
// Every two weeks, pay your people.
int totalPayout = 0;
if (time % 14 == 0) {
for (vector<Person *>::iterator it = this->_employees->begin(); it != this->_employees->end(); ++it) {
int salary = (int)((*it)->getCurrentSalary() / 26.0);
this->payWages(salary);
(*it)->addMoney(salary);
totalPayout += salary;
}
}
int overheadCost = this->getOverheadCost();
this->payOverhead(overheadCost);
}
const char *Company::getName() {
return this->_name;
}
vector<Person *> *Company::getEmployees() {
return this->_employees;
}
void Company::payWages(int wages) {
this->_money -= wages;
}
void Company::payOverhead(int overhead) {
this->_money -= overhead;
}
int Company::getOverheadCost() {
// No matter what, you cannot get away scot free.
int overhead = 1;
overhead += this->_employees->size() * 10;
// Every 10 days something random happens.
// The higher your everyday costs, the more
// an occurence costs.
if (rand() % 10 == 0)
overhead *= (rand() % 100) / 50.0;
return overhead;
}
int Company::getMoney() {
return this->_money;
}
Company::~Company() {
free(this->_name);
this->_name = NULL;
delete this->_employees;
this->_employees = NULL;
delete this->_platformSkills;
this->_platformSkills = NULL;
delete this->_knownPeople;
this->_knownPeople = NULL;
}