[go: up one dir, main page]

Menu

[r3]: / grueworld / avatar.cpp  Maximize  Restore  History

Download this file

93 lines (84 with data), 2.5 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
84
85
86
87
88
89
90
91
92
#include "common.hpp"
#include <iostream>
Avatar::Avatar(INETsocket controller){
sock=controller;
health=(float)0x100;
}
bool Avatar::Move(string destination, Container&location, unsigned int myindex) {
map<string,weak_ptr<Room> >* links=location.exits();
map<string,weak_ptr<Room> >::iterator where=links->find(destination);
if (where!=links->end()) {
where->second.lock()->getThing(myindex,location);
return true;
}
return false;
}
void Avatar::privateMessage(SENSES sense,std::string message) {
//FIXME
}
void Avatar::tick(Container&location, unsigned int myindex) {
Container::tick(location,myindex);
health-=1.0f/1024.0f;
//FIXME do hunger
//FIXME send update to client
//FIXME process client commands
}
void Avatar::addHealth(float health) {
this->health+=health;
if (health>0) {
//FIXME reward
}else {
//FIXME punish
}
}
bool Avatar::Eat(string desc) {
for (std::vector<shared_ptr<Thing> >::iterator it=items.begin(),end=items.end();
it!=end;
++it) {
if (desc==it->get()->description()) {
if (it->get()->EatMe(*this)) {
*it=items.back();
items.pop_back();
return true;
}
}
}
return false;
}
Avatar::~Avatar() {
std::cout << description()<<" died\n";
}
Grue::~Grue(){}
Snark::~Snark(){}
bool Grue::getThing(unsigned int thingindex, Container&previous) {
Thing* item=previous.examineItem(thingindex);
Grue * tmp=dynamic_cast<Grue*> (item);
if (tmp) return false;
Avatar * tmp1=dynamic_cast<Avatar*> (item);
if (tmp1&&previous.lightness()>.5) {
return false;
}
if (!tmp1) return false;//carnivore
return this->Avatar::getThing(thingindex,previous);
}
bool Grue::takeMe(Container& destination, Container& currentLocation) {
return false;///impervious to attack
}
bool Snark::EatMe(Avatar& thing) {
thing.addHealth(100);
}
bool Snark::getThing(unsigned int thingindex, Container&previous) {
Thing* item=previous.examineItem(thingindex);
Avatar * tmp=dynamic_cast<Avatar*> (item);
if (tmp)return false;
return Avatar::getThing(thingindex,previous);
}
bool Snark::takeMe(Container& destination, Container& currentLocation) {
for (std::vector<shared_ptr<Thing> >::iterator it=currentLocation.items.begin(),end=currentLocation.items.end();
it!=end;
++it) {
Thing*tmp=it->get();
if (dynamic_cast<Snark*>(tmp)) return false;
}
return Avatar::takeMe(destination,currentLocation);
}