Inheritance Stuff yo.
Moderator: Coders of Rage
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
Inheritance Stuff yo.
I know I spelt that one wrong, but who cares foo. err. Anyway, First off, has any of you guys found it helpful and cool. Do you know of any drawbacks to it. From what I see, it doesn't. But I've never tried it before. I think the ability to draw or delete all enimies or something would be a heck of a lot better then manually deconstructing them.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Yeah, I have a use.
Code: Select all
class Actor {
protected:
map<string, string>loader;
Debug debug; //Used to write debug log messages to the player/NPC log.
Timestamp ts;
string name; //Generally, the name that shows in battle.
string desc;
bool male;
bool useANSI;
//These are for loading and saving, actually.
int coords[2]; //(X, Y, Z). If vnum > -1, coords don't count.
int vnum; //Index [aka vnum] # for 'zones' concept.
RoomInfo* location;
Zone* zone;
World* world;
SolarSystem* system;
Server* srv; //Server access....
int level; //XP = (2*Lv + maxHp + 0.5*maxMp) - PlrLv ?
int maxHp;
int maxMp;
int maxMv;
int hp;
int mp;
int mv;
int ac;
/* lots more ... */
// note this one:
virtual string pickupItem(MultipleItem* item, Actor* fromGive = NULL) = NULL;
/* lots more ... */
};
// next file-----------------------------------
class Client {
private:
int id;
public:
Client();
Client(int handle);
void setId(int pid);
void disconnect();
int getId();
virtual ~Client();
};
class Player : public Actor, public Client {
private:
//Debug debug; //Used to write debug log messages to the player log.
string password; //Duh.
string waitinginputs; //The player's command queue.
bool busy; //Tells doListen to skip this player.
bool ghosted; //Did the player d/c without typing quit?
int rank; //Default 10 = administrator.
bool parsing; //Are the player's commands currently being parsed?
unsigned int hasErrored;
bool saveNameCase;
string prompt;
map<string, string>killSpell;
public:
//Player actions
/* lots more ... */
};
// next file-----------------------------------
class NPCBase : public Actor {
private:
int aggressiveness; // 300-this = delay until monster attacks, in seconds.
//MARFIX: Make the 300 configurable. -1 = no aggro.
int index;
string filename;
NPCManifest* owner;
public:
virtual RoomInfo* move(string direction); //Move direction
/* lots more ... */
};
// next file-----------------------------------
// actorclasses.cpp
/* ... */
void Actor::setHp(int php) {
hp = php;
}
void Actor::setMp(int pmp) {
mp = pmp;
}
void Actor::setMv(int pmv) {
mv = pmv;
}
/* lots more ... */
// next file-----------------------------------
// playerclasses.cpp
string Player::pickupItem(MultipleItem* item, Actor* fromGive) {
// send "you got a"/"you got another"/"you cant get that" messages
// to the player and stuff
/* ... */
}
// next file-----------------------------------
// enemyclasses.cpp
string NPCBase::pickupItem(MultipleItem* item, Actor* fromGive) {'
// just get the item (can't send messages over a socket to an npc --
// they aren't connected to the server, they're part of it.)
}
// next file-----------------------------------
// serverclasses.cpp
// yes npcs can talk too -- so this can check to see if an npc or a player
// can use the channel. (i can't make just an actor and fill it in, because
// it has virtual functions set to NULL inside.)
bool Server::canUseChannel(Actor* test, int whichChannel) {
/* ... */
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Try looking at the code. It's not hard to understand code. Let's see. I define Actor, I define some stuff that inherits from Actor, NPCBase and Player (which inherits from both Actor and Client) and then show some functions that are shared, Actor::setHp() setMp() etc, show a virtual function from Actor that is defined differently in NPCBase and Player, and then show a Server function that can take either NPCBase* or Player* as a parameter because its parameter is Actor*.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON