-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.cpp
More file actions
83 lines (76 loc) · 2.17 KB
/
cat.cpp
File metadata and controls
83 lines (76 loc) · 2.17 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
75
76
77
78
79
80
81
82
83
#include <QDebug>
#include "cat.h"
#include "configure.h"
Cat::Cat(int id) : AvatarSpirit(id)
{
_type = CAT;
_color = QColor(250, 81, 143);
bool ok;
float fval = g_config.getValue("AvatarSpirit/Life/Cat").toFloat(&ok);
if (ok)
_life = fval;
else
{
_life = 50; // default
g_config.setValue("AvatarSpirit/Life/Cat", _life);
}
}
Cat::~Cat()
{
}
float Cat::originalPayoff(Agent::State st)
{
Q_UNUSED(st);
float pf = 0.0;
QList<Spirit *> colliding_spirits = collidingSpirits();
if (colliding_spirits.empty())
{
pf = 0.0;
}
else // integrated all the colliding spirits
{
for (QList<Spirit *>::iterator it = colliding_spirits.begin(); it != colliding_spirits.end(); ++it)
{
if ((*it)->spiritType() == CHEESE)
{
qDebug() << "Cat" << id << ": Wow! cheese!";
this->healed(0.3);
pf += 0.3;
}
else if ((*it)->spiritType() == NAIL)
{
qDebug() << "Cat" << id << ": Oops! nail!";
this->injured(0.3);
pf += -0.3;
}
else if ((*it)->spiritType() == BOMB)
{
qDebug() << "Cat" << id << ": BOMB, dead!";
this->injured(this->life()); // instant death
this->setAwake(false); // be blown up unconscious
pf += -99.0;
}
else if ((*it)->spiritType() == MOUSE && dynamic_cast<AvatarSpirit *>(*it)->isAwake())
{
qDebug() << "Cat" << id << ": Mouse! My favorite!";
this->healed(1);
pf += 1.0;
}
else if ((*it)->spiritType() == ELEPHANT && dynamic_cast<AvatarSpirit *>(*it)->isAwake())
{
qDebug() << "Cat" << id << ": Elephant! OMG, run away!";
this->injured(1);
pf += -1.0;
}
else
{
pf += 0.0;
}
}
}
if (pf == 0.0) // curiosity counts only when no direct payoffs
{
pf = payoffByCuriosity(st);
}
return pf;
}