[go: up one dir, main page]

Menu

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

Download this file

107 lines (98 with data), 2.8 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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
#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 (size_t i=0;
i<items.size();
++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)) {
string desc=previous.items[thingindex]->description();
unsigned int numpeople=numItems();
for (unsigned int i=0;i<numpeople;++i) {
this->examineItem(i)->privateMessage(SEE,desc);
}
items.push_back(previous.items[thingindex]);
if (size>1) previous.items[thingindex]=previous.items.back();
previous.items.pop_back();
numpeople=previous.numItems();
for (unsigned int i=0;i<numpeople;++i) {
previous.examineItem(i)->privateMessage(NOTSEE,desc);
}
return true;
}
}
return false;
}
Container::~Container() {
}
string Container::look(Thing&notthis) {
std::string retval;
for (std::vector<shared_ptr<Thing> >::iterator it=items.begin(),end=items.end();
it!=end;
++it) {
if (it->get()!=&notthis) {
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(Thing&notthis) {
string retval;
static string ext("x:");
for (map<string, weak_ptr<Room> >::iterator it=links.begin(),end=links.end();
it!=end;
++it) {
retval+=ext+it->first;
retval+='\n';
}
retval+=this->Container::look(notthis);
int light100=(int)(light*99.9);
if (light100<0) light100=0;
if (light100>100)light100=100;
char lightvalm100='0'+(char)(light100/10)%10;
char lightvalm10='0'+(char)(light100%10);
retval+='l';
retval+=lightvalm100;
retval+='\n';//only have sigfig
//printf ("lr%f\n",light);
return retval;
}
float Room::lightness(){
return light;
}
static map<string,weak_ptr<Room> > emptiness;
map<string,weak_ptr<Room> >* Container::exits(){
return &emptiness;
}