Page 1 of 1
Inheritance Stuff yo.
Posted: Mon Sep 20, 2004 7:45 am
by JS Lemming
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.
Posted: Mon Sep 20, 2004 1:46 pm
by Falco Girgis
Holy crap, for a second I thought you were talking about stuff you like inherited from your dead grandfather or something... I was freaked out.
I personally have not found a need for inheritance in all of my C/C++ programming days... (What, 4 months now?)
Posted: Mon Sep 20, 2004 8:34 pm
by MarauderIIC
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) {
/* ... */
}
Posted: Tue Sep 21, 2004 7:26 am
by JS Lemming
Err.... I don't know what all that does, but it looks inheritancy-ish.
Posted: Tue Sep 21, 2004 7:06 pm
by MarauderIIC
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*.
Posted: Wed Sep 22, 2004 3:41 pm
by JS Lemming
It's not that, I just haven't studied that area of classes long enough to visualize in my head what's going on.