[go: up one dir, main page]

Menu

[r5]: / grueworld / container.cpp  Maximize  Restore  History

Download this file

86 lines (77 with data), 2.1 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 "common.hpp"
void Container::Say(Avatar&speaker, string text) {
for (std::vector<shared_ptr<Thing> >::iterator it=items.begin(),end=items.end();
it!=end;
++it) {
it->get()->privateMessage(HEAR,text);
}
}
float Container::lightness(){
return 0;
}
void Container::tick(shared_ptr<Thing>&location, unsigned int myindex) {
for (ptrdiff_t i=items.size()-1;
i>=0;
--i) {
int tmp=static_cast<Container*>(location.get())->items.size();
items[i]->tick(static_cast<Container*>(location.get())->items[myindex],i);
}
}
unsigned int Container::numItems() {
return items.size();
}
Thing*Container::examineItem(unsigned int which) {
if (which>=this->numItems()) return NULL;
return items[which].get();
}
bool Container::addThing(shared_ptr<Thing> thang) {
items.push_back(thang);
return true;
}
bool Container::getThing(unsigned int thingindex, Container&previous) {
unsigned int size=previous.items.size();
if (size>thingindex) {
if (previous.items[thingindex]->takeMe(*this,previous)) {
items.push_back(previous.items[thingindex]);
if (size>0) previous.items[thingindex]=previous.items.back();
previous.items.pop_back();
return true;
}
}
return false;
}
Container::~Container() {
}
string Container::look() {
std::string retval;
for (std::vector<shared_ptr<Thing> >::iterator it=items.begin(),end=items.end();
it!=end;
++it) {
retval+=it->get()->description();
retval+='\n';
}
return retval;
}
map<string, weak_ptr<Room> > *Room::exits(){
return &links;
}
Room::Room(float lightness):light(lightness) {
}
string Room::look() {
string retval;
static string ext("exit:");
for (map<string, weak_ptr<Room> >::iterator it=links.begin(),end=links.end();
it!=end;
++it) {
retval+=ext+it->first;
}
retval+=this->Container::look();
return retval;
}
float Room::lightness(){
return light;
}
static map<string,weak_ptr<Room> > emptiness;
map<string,weak_ptr<Room> >* Container::exits(){
return &emptiness;
}