#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>¤tLocation){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¬this);//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¬this);//returns desc of exists then items @ location
};
class GeneticCode{
public:
GeneticCode(string);
GeneticCode();//random
bool combine(GeneticCode&father,GeneticCode&mother);//destructive
string tostring();
};
class Grue;
class Snark;
class Avatar:public Container{
protected:
float health;
float maintenance;
INETsocket sock;
GeneticCode code;
void SendCode();
friend class Grue;
friend class Snark;
public:
void Die(int myindex, Container¤tlocation);
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 string Combine(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>¤tLocation);
};
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>¤tLocation);
};
extern shared_ptr<Container> world;
#endif