Inheritance Stuff yo.

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Inheritance Stuff yo.

Post 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.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post 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?)
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post 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) {
/* ... */
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Err.... I don't know what all that does, but it looks inheritancy-ish. :mrgreen:
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post 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*.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post 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.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Post Reply