[go: up one dir, main page]

Menu

[r6]: / grueworld / common.hpp  Maximize  Restore  History

Download this file

129 lines (127 with data), 3.7 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef _COMMON_HPP_
#define _COMMON_HPP_
#include <boost/weak_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <map>
#include <string>
#include <vector>
using boost::shared_ptr;
using boost::weak_ptr;
using std::string;
using std::map;
using std::vector;
class Avatar;
class Container;
enum SENSES{
SEE,
HEAR,
FEEL,
TASTE,
SMELL,
INTUIT,
NUMSENSES
};
typedef int INETsocket;
class Thing{
protected:
string desc;
public:
virtual bool reproduce(Avatar&who, shared_ptr<Thing>&currentLocation){return false;}
virtual void privateMessage(SENSES sense, std::string message);
virtual bool execute(Thing&,Thing&);
virtual bool execute(Thing&);
virtual void tick(shared_ptr<Thing>&location,unsigned int myindex);
const string& description(){return desc;}
virtual bool takeMe(Container& destination, Container& currentLocation);
virtual bool EatMe(Avatar &thing);
virtual ~Thing();
};
class Poison:public Thing{
public:
virtual bool EatMe(Avatar& thing);//nourish? or harm...
Poison() {
static string poison("poison");
desc=poison;
}
};
class Food:public Thing{
public:
virtual bool EatMe(Avatar& thing);//nourish? or harm...
Food() {
static string food("food");
desc=food;
}
};
class Room;
#define MAXHEALTH 100
class Container:public Thing{
protected:
vector<shared_ptr<Thing> >items;
friend class Snark;
friend class Avatar;
public:
virtual float lightness();
Thing*examineItem(unsigned int which);
unsigned int numItems();
void Say(Avatar&speaker, string text);
virtual void tick(shared_ptr<Thing>&location, unsigned int myindex);
virtual map<string, weak_ptr<Room> > *exits();
virtual bool getThing(unsigned int thingindex,Container&previous);
virtual bool addThing(shared_ptr<Thing> thang);
virtual ~Container();
virtual string look(Thing&notthis);//return desc of items at location
};
class Room:public Container{
float light;
map<string, weak_ptr<Room> > links;
public:
virtual float lightness();
Room(float lightness);
void Link(string name, shared_ptr<Room> destination);
virtual map<string, weak_ptr<Room> > *exits();
virtual string look(Thing&notthis);//returns desc of exists then items @ location
};
class GeneticCode{
public:
GeneticCode();//random
GeneticCode(GeneticCode&father, GeneticCode&mother);
string tostring();
};
class Avatar:public Container{
protected:
float health;
float maintenance;
INETsocket sock;
GeneticCode code;
void SendCode();
public:
void Die(int myindex, Container&currentlocation);
Avatar(INETsocket controller);
bool Move (string destination, Container&location, unsigned int myindex);
virtual void privateMessage(SENSES sense, std::string message);
virtual void tick(shared_ptr<Thing>&location, unsigned int myindex);
void addHealth(float health);
virtual bool Eat(string desc);
virtual ~Avatar();
};
class Grue:public Avatar{
public:
static bool canConnect();
Grue (INETsocket controller);
virtual bool getThing(unsigned int thingindex,Container&previous);//make sure it's not another grue and it's dark
virtual bool takeMe(Container& destination, Container& currentLocation);
virtual ~Grue();
virtual bool reproduce(Avatar&who, shared_ptr<Thing>&currentLocation);
};
class Snark:public Avatar{
public:
static bool canConnect();
Snark (INETsocket controller);
virtual bool getThing(unsigned int thingindex,Container&previous);//make sure it's not another container
virtual bool EatMe(Avatar& thing);//nourish? or harm...
virtual bool takeMe(Container& destination, Container& currentLocation);
virtual ~Snark();
virtual bool reproduce(Avatar&who, shared_ptr<Thing>&currentLocation);
};
extern shared_ptr<Container> world;
#endif