forked from leiterboss/hybrid-biology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBodyPart.cpp
100 lines (85 loc) · 2.64 KB
/
BodyPart.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
/*
* BodyPart.cpp
*
* Created on: Feb 4, 2012
* Author: leiterboss
*/
#include "BodyPart.h"
/*
BodyPart::BodyPart() {
// TODO Auto-generated constructor stub
}*/
BodyPart::~BodyPart() {
// TODO Auto-generated destructor stub
}
void BodyPart::setNames(string names) {
stringstream ss(names);
string s, sold;
getline(ss, s, ','); // s <- noun singular
this->setName(s); sold = s;
getline(ss, s, ','); // s <- noun plural
if (s.compare(sold) != 0) {
this->setNamePlural(s); sold = s;
getline(ss, s, ','); // s <- definite article (i.e. "an")
if (s.compare(sold) != 0)
this->setArticle(s);
else this->setArticle("a");
}
else {
this->setNamePlural(s + "s");
this->setArticle((isVowel(this->getName()[0])?"an":"a"));
}
}
string BodyPart::getDescription() {
ostringstream os;
bool multipleNum = (this->getNumber() > 1);
bool hasSkills = (this->getSkills()->size() > 0);
if (!multipleNum) {
os << "The " << this->getName() << " is made of " << this->getMaterial().getColor() <<
" " << this->getMaterial().getName();
}
else { //TODO: Fix plurals
os << "The " << this->getNamePlural() << " are made of " << this->getMaterial().getColor() <<
" " << this->getMaterial().getName();
}
if (!hasSkills && this->parts.size() == 0) os << ". ";
else os << ", ";
if (hasSkills) {
if (!multipleNum) os << "and it grants ";
if (hasSkills && multipleNum) os << "and they grant ";
vector<Skill::RatedSkill>* rs = this->getSkills();
if (rs->size() )
for(unsigned int i = 0; i < rs->size(); i++) {
string adj = Skill::getRatingAdjective(rs->at(i).rating, Skill::isMovementSkill(rs->at(i).skill->getID()));
string sep = (adj.length() > 0?" ":"");
os << adj << sep << rs->at(i).skill->getActionName();
if (i + 2 < rs->size()) os << ", ";
if (i + 2 == rs->size()) os << " and ";
}
os << ". ";
}
if (this->parts.size() > 0) {
if (hasSkills) os << ((this->getNumber()==1)?"The ":"Each ") << this->getName() << " has ";
else os << "and " << ((this->getNumber()==1)?"it ":"each ") << "has ";
for(unsigned int i = 0; i < this->parts.size(); i++) {
if (this->parts.at(i)->getNumber() > 1) {
os << this->parts.at(i)->getNumber() << " " << this->parts.at(i)->getNamePlural();
}
else {
os << this->parts.at(i)->getArticle() << " " << this->parts.at(i)->getName();
}
if (i + 2 < this->parts.size()) os << ", ";
if (i + 2 == this->parts.size()) os << " and ";
}
os << ". ";
for(unsigned int i = 0; i < this->parts.size(); i++) {
os << this->parts.at(i)->getDescription();
}
}
return os.str();
}
/*
string name;
vector<Skill::RatedSkill> skills;
struct Material material;
unsigned short num;*/