 |
|
 |
|
Next: Whirlwind Music Missing
|
| Author |
Message |
External

Since: Oct 08, 2006 Posts: 4
|
(Msg. 1) Posted: Mon Oct 16, 2006 9:14 pm
Post subject: Value of inheritance in Object-oriented programming Archived from groups: rec>games>roguelike>development (more info?)
|
|
|
I'm wondering what would be a more speed and memory efficient way of
classing objects in RLs like items, monsters, players, and NPCs.
Would an approach that stresses hierarchical inheritance be effective,
like this:
pseudo-code class definitions:
class object:
definitions like location of map...
class item(inheriting object):
definitions like type and inventory...
class actor(inheriting object):
methods like intrinsics, abilities...
class trap(inheriting object):
methods like deal damage...
class monster(inheriting actor):
methods like move, attack, AI
class player (inheriting actor):
definitions and methods unique to player
class shopkeeper(inheriting actor):
special class of actor with different rules
class warrior(inheriting player):
methods describing abilities only warriors can use and mages can't
class mage(inheriting player):
methods describing abilities only mages can use and warriors can't
....But I think what this approach makes up for in initialization speed
and memory allocation, it gains back by spreading out class definitions
over multiple objects, making them less freely accessible to the
processor. I'm kind of new to programming, but I would like to hear
everyone's opinions about this. Also, I'm using Python, so that might
make a difference in the speed of function calls being dealt with, etc. >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Feb 23, 2005 Posts: 577
|
(Msg. 2) Posted: Mon Oct 16, 2006 9:31 pm
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Pointless wrote:
> I'm wondering what would be a more speed and memory efficient way of
> classing objects in RLs like items, monsters, players, and NPCs.
>
> Would an approach that stresses hierarchical inheritance be effective,
> like this:
>
> pseudo-code class definitions:
>
> class object:
> definitions like location of map...
>
> class item(inheriting object):
> definitions like type and inventory...
> class actor(inheriting object):
> methods like intrinsics, abilities...
> class trap(inheriting object):
> methods like deal damage...
>
> class monster(inheriting actor):
> methods like move, attack, AI
> class player (inheriting actor):
> definitions and methods unique to player
> class shopkeeper(inheriting actor):
> special class of actor with different rules
>
> class warrior(inheriting player):
> methods describing abilities only warriors can use and mages can't
> class mage(inheriting player):
> methods describing abilities only mages can use and warriors can't
>
> ...But I think what this approach makes up for in initialization speed
> and memory allocation, it gains back by spreading out class definitions
> over multiple objects, making them less freely accessible to the
> processor. I'm kind of new to programming, but I would like to hear
> everyone's opinions about this. Also, I'm using Python, so that might
> make a difference in the speed of function calls being dealt with, etc.
I think you'll find issues of performance are not relevant here. The
real performance bottlenecks of your program will not relate to
class/function definitions at all. They will relate to the algorithms
you use for things like LOS, pathfinding, AI, and possibly drawing
graphics if you code it badly.
Forget about initialization speed here; choose an approach that aptly
models your conceptual structure and allows powerful development of
game features.
A. >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Jul 13, 2005 Posts: 373
|
(Msg. 3) Posted: Mon Oct 16, 2006 11:55 pm
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Pointless kirjoitti:
> I'm wondering what would be a more speed and memory efficient way of
> classing objects in RLs like items, monsters, players, and NPCs.
Don't worry about the speed. The class structure isn't going to affect
that much anyway. What you need to think is how to structure the
classes and inheritance. I have learned a good rule: don't use
inheritance unless you absolutely need it. For example I think it's
not neccessary to split monsters from some base class:
class Orc : public Actor
class Elf : public Actor
This is too fine tuned for the purpose and you end up having
zillions of classes which means more maintaining. >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Aug 21, 2006 Posts: 111
|
(Msg. 4) Posted: Mon Oct 16, 2006 11:56 pm
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Pointless のメッセージ:
> I'm wondering what would be a more speed and memory efficient way of
> classing objects in RLs like items, monsters, players, and NPCs.
There are two ways to approach this.
A) Efficient code is at odds with human readable code, readability
takes
priority unless efficiency is breaking the program.
B) Complier optimization is good enough these days. Don't worry about
it.
They both amount to focus on writing your game and worry about speed
and memory problems when they become problems.
-Brendan >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Jun 01, 2004 Posts: 260
|
(Msg. 5) Posted: Tue Oct 17, 2006 2:10 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Pointless wrote:
> I'm wondering what would be a more speed and memory efficient way of
> classing objects in RLs like items, monsters, players, and NPCs.
>
I advocate avoiding any unnecessary multiplication of classes.
Write the clearest, cleanest code you can write in your
language of choice. Use OO design if you feel that it's
the right thing to do, or consider something else if you
want to experiment or feel that something else is the right
thing to do. Subclass something only when it becomes
clear that you cannot use the base class itself without
modification.
Use class members whenever possible rather than subclasses.
For example, you can have "actors" (a class that takes in
both the PC and the monsters) have a member of the "AI" class,
and subclass AI into monster_AI and player_IO rather than
subclassing "actors" into "players" and "monsters."
The point there is that all the important AI functions (taking
messages about the dungeon and doing something useful, making
combat or other decisions, etc) cleave along a single line -
players use IO functions and monsters use AI functions. Nothing
else is (or at least nothing else needs to be) different about
your actors.
This pays off when you have several different class members -
it saves you a very complicated hierarchy.
Bear >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Jul 13, 2005 Posts: 373
|
(Msg. 6) Posted: Tue Oct 17, 2006 6:41 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Timofei Shatrov wrote:
> A complicated hierarchy of classes is better than code full of switches and ifs.
Don't be such a fool. At least you should tell -why- it is better,
before
trolling like that. I know from experience that it's perfecly
acceptable
to extend the base class with some methods that aren't needed for
all instances of the object. In some cases it's easier than making
a new class.
Let me tell an example. I have Tileset class which set up tiles and
draws them. Now, I need to manually create shadows for items.
Instead of inheriting something like Shadowed_Tiles:Tileset I just
wrote five helper functions that create shadows. If I need to set
the shadows for the instance of a Tileset I call:
items->Shadowize();
This will not confuse another tilesets even those functions are
present. I'm probably careful enough not to call Shadowize for
other tilesets. >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: May 18, 2005 Posts: 38
|
(Msg. 7) Posted: Tue Oct 17, 2006 7:15 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
DarkGod wrote:
[clip]
> What ray advocates(and so do I) is really not a switch/if code, but rather a
> data/properties driven model.
> A monster(or object or whatever) is some base thing(like a monster, or an
> actor)
> with a list of properties.
> If you are doing OO you sure can have properties by a class hierarchy, so you
> can do something like:
> for property in actor.properties do property.run(actor) end
> No if anywhere to be seen and yet the power to construct complex and unique
> beings
> easily.
[clip]
I agree completely with this approach. After having lots of attempts
at failed engines, this is something that became quite clear - having
the initial game objects be as "flat" as possible helps. Everything
else is a property/member of that. The properties make great places
for inheritence. A game object needing an AI would make one type of
IController (BasicAIController), while a player would have a
PC_Controller, and the guard would have a GuardAIController (Which may
be derived from BasicAIController). You can do the same thing to
simplify inventory.
I'm using this approach for item-specific information, in case I ever
need to have multi-purpose items in a situation. FoodInfo,
ContainerInfo, WeaponInfo, etc , are all separate properties that are
not required.
> This is the way T-Engine works and we can have thousands of different monsters
> all sharing some properties but all have some unique ones.
>
I'll have to look at T-Engine again - I didn't know that. >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Dec 14, 2005 Posts: 119
|
(Msg. 8) Posted: Tue Oct 17, 2006 9:49 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Oct 17, 9:48 am, g... RemoveThis @mail.ru (Timofei Shatrov) wrote:
> On Tue, 17 Oct 2006 13:42:56 +0000 (UTC), DarkGod <dark... RemoveThis @t-o-m-e.net> tried to
> confuse everyone with this message:
>
> >> x.method();
>
> >> and introduce 3 new classes P1 (containing all xs such that property(x)=1), P2
> >> and P3 where method does A1, A2 and A3 respectively.
>
> >> Makes for much clearer code.
>
> >What when you want to have a P4 which A4 uses some things og A1 and A2 but does
> >more too ?
> >You copy the code ?Inherit both classes and call those methods. Nothing a good object system can't
> do.
Multiple inheritance just screws things up. If you need to do multiple
inheritance you know your clear and concise model is lost.
>
> >> >Use class members whenever possible rather than subclasses.
> >> >For example, you can have "actors" (a class that takes in
> >> >both the PC and the monsters) have a member of the "AI" class,
> >> >and subclass AI into monster_AI and player_IO rather than
> >> >subclassing "actors" into "players" and "monsters."
> >> What's the difference? Looks like the same amount of new classes are created.
> >> And AI looks more like a method than a class to me.
>
> >Not a method, a property of the actor.
> >In you system what happens the day you want a monster to be able
> >to swicth form on AI to an other ?
> >Like your monster walks in staright line and then the player throws
> >a potion of booze at him, now he must walk in a drunken way.
> A good OO approach is that every changeable property is related to a method
> (accessor function), so properties and methods are basically the same thing. A
> property x.ai is equivalent to a pair of methods: x.get-ai() and
> x.set-ai(new-state).
This has got nothing to do with what Bear means; if you subclass an
actor just because of refining its AI (for example, to make a goblin
archer act different from a standard goblin, or anything), you will
then be unable to change this behaviour.
That's why defining AI modules (in this case) as a changeable property
is important.
> I don't buy that data-driven stuff. It makes much cleaner code, when you write:
>
> player = make-instance(player-class)
>
> instead of
>
> player = make-instance(actor-class);
> player.ai = player-IO;
> player.hp = 20
> player.mp = 10
> <another 132 assignments of properties snipped>
However, all these 133 assignements can be stored on a handy XML or
flat archive file, which makes up for easy mantainance, as you just
need to create a parser object.
This 'data-driven stuff', is where we all get after toying around with
overcomplicated class hierachies, when we finally get to try to fill
the game with content.
>
> --
> |Don't believe this - you're not worthless ,gr---------.ru
> |It's us against millions and we can't take them all... | ue il |
> |But we can take them on! | @ma |
> | (A Wilhelm Scream - The Rip) |______________|
--
Slash >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Nov 22, 2004 Posts: 250
|
(Msg. 9) Posted: Tue Oct 17, 2006 9:55 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Tue, 17 Oct 2006 02:10:52 -0700, Ray Dillinger <bear DeleteThis @sonic.net> tried to
confuse everyone with this message:
>Pointless wrote:
>> I'm wondering what would be a more speed and memory efficient way of
>> classing objects in RLs like items, monsters, players, and NPCs.
>>
>
>I advocate avoiding any unnecessary multiplication of classes.
I advocate completely opposite: use a class for every set of objects which have
some common property.
>Write the clearest, cleanest code you can write in your
>language of choice. ... Subclass something only when it becomes
>clear that you cannot use the base class itself without
>modification.
Isn't the purpose of subclassing to modify a base class somewhat without using
switches and similar ugly-looking code? The cleanest code is what I call "linear
programming" (yeah, I know this term is already reserved for something entirely
different), which has no control flow constructs at all: all ifs and switches
are replaced by dispatching based on class.
For example, replace
switch (property(x))
case 1: do A1
case 2: do A2
case 3: do A3
end switch
with
x.method();
and introduce 3 new classes P1 (containing all xs such that property(x)=1), P2
and P3 where method does A1, A2 and A3 respectively.
Makes for much clearer code.
>Use class members whenever possible rather than subclasses.
>For example, you can have "actors" (a class that takes in
>both the PC and the monsters) have a member of the "AI" class,
>and subclass AI into monster_AI and player_IO rather than
>subclassing "actors" into "players" and "monsters."
What's the difference? Looks like the same amount of new classes are created.
And AI looks more like a method than a class to me.
>
>The point there is that all the important AI functions (taking
>messages about the dungeon and doing something useful, making
>combat or other decisions, etc) cleave along a single line -
>players use IO functions and monsters use AI functions. Nothing
>else is (or at least nothing else needs to be) different about
>your actors.
What if monsters don't have inventories for example, or have simplified LOS
implementation? Monsters also don't have 50 skills that player has and these
skills don't need to be checked when monster steps on a trap or something like
that.
>This pays off when you have several different class members -
>it saves you a very complicated hierarchy.
A complicated hierarchy of classes is better than code full of switches and ifs.
--
|Don't believe this - you're not worthless ,gr---------.ru
|It's us against millions and we can't take them all... | ue il |
|But we can take them on! | @ma |
| (A Wilhelm Scream - The Rip) |______________| >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Jun 01, 2004 Posts: 260
|
(Msg. 10) Posted: Tue Oct 17, 2006 9:55 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Timofei Shatrov wrote:
> On Tue, 17 Oct 2006 02:10:52 -0700, Ray Dillinger <bear.DeleteThis@sonic.net> tried to
> confuse everyone with this message:
>>Use class members whenever possible rather than subclasses.
>>For example, you can have "actors" (a class that takes in
>>both the PC and the monsters) have a member of the "AI" class,
>>and subclass AI into monster_AI and player_IO rather than
>>subclassing "actors" into "players" and "monsters."
>
>
> What's the difference? Looks like the same amount of new classes are created.
> And AI looks more like a method than a class to me.
The difference is that I'm not mixing up the AI hierarchy
with the species hierarchy. This allows me to have monsters
of the same species that behave differently (for example
goblin archers vs. goblin fighters) without creating new
species classes.
As for AI being a method rather than a class, different
design decisions lead to different consequences. Most
messages that the interface delivers to the player are
AI methods. You call the method to deliver the message
to the actor. The AI class keeps track of messages, then
when it gets its "your_turn" call it decides what it needs
to do and picks an action. Most decision points that
actors can make are AI methods, too. Pick up the sword
you're passing, or leave it? Pick the door that leads
to the big dead-end room with a lot of comrades, or the
door that leads to an escape route? etc.
You can do this with a lot of code where monsters get
special accessors to discover things that players only
get through messages, or code that checks to see whether
something is a monster or the player before deciding to
send it a message, etc, but I think it's better just to
have the parallel design.
Bear >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Dec 14, 2005 Posts: 119
|
(Msg. 11) Posted: Tue Oct 17, 2006 9:57 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Oct 17, 8:01 am, g....RemoveThis@mail.ru (Timofei Shatrov) wrote:
> On Tue, 17 Oct 2006 02:10:52 -0700, Ray Dillinger <b....RemoveThis@sonic.net> tried to
> confuse everyone with this message:
>
> >Pointless wrote:
> >> I'm wondering what would be a more speed and memory efficient way of
> >> classing objects in RLs like items, monsters, players, and NPCs.
>
> >I advocate avoiding any unnecessary multiplication of classes.
> I advocate completely opposite: use a class for every set of objects which have
> some common property.
This gets out of programmer hands too quiclky
> >Write the clearest, cleanest code you can write in your
> >language of choice. ... Subclass something only when it becomes
> >clear that you cannot use the base class itself without
> >modification.
> Isn't the purpose of subclassing to modify a base class somewhat without using
> switches and similar ugly-looking code?
No!
The main purpose, IMO, is to allow specialization and thus object
polymorphism.
> The cleanest code is what I call "linear
> programming" (yeah, I know this term is already reserved for something entirely
> different), which has no control flow constructs at all: all ifs and switches
> are replaced by dispatching based on class.
Having a program with no flow constructs at all would be impossible,
also, unnecesary, there is a reason they exist for!
SNIP
>
> >The point there is that all the important AI functions (taking
> >messages about the dungeon and doing something useful, making
> >combat or other decisions, etc) cleave along a single line -
> >players use IO functions and monsters use AI functions. Nothing
> >else is (or at least nothing else needs to be) different about
> >your actors.
> What if monsters don't have inventories for example, or have simplified LOS
> implementation? Monsters also don't have 50 skills that player has and these
> skills don't need to be checked when monster steps on a trap or something like
> that.
Yes, that's what inheritance is for, the one important thing is you
must keep it shallow. You usually wont need more than an Actor:Monster,
Actor:Player, Actor:Object inheritance tree. Anything beyond that can
be treated via attributes and properties.
> >This pays off when you have several different class members -
> >it saves you a very complicated hierarchy.
>A complicated hierarchy of classes is better than code full of switches and ifs.
No!
>
> --
> |Don't believe this - you're not worthless ,gr---------.ru
> |It's us against millions and we can't take them all... | ue il |
> |But we can take them on! | @ma |
> | (A Wilhelm Scream - The Rip) |______________|
--
Slash >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Jul 13, 2005 Posts: 373
|
(Msg. 12) Posted: Tue Oct 17, 2006 10:28 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Timofei Shatrov wrote:
> I don't know how hard is to create a new class in C++, but I reckon it shouldn't
> be too hard...
Creating new things is easy, maintaining them is hard.
> That said, I would've made Item class handle the shadowing, and tile->Shadowize
> just calls item->Shadowize for each item in tile.
What the hell? Man, you are confused! You can't do that! I'm keeping
the
object classes and drawing classes separate. Tileset has no idea what
objects are, it's just drawing tile(s) from a tileset, like item tiles
or ground
tiles. >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Nov 22, 2004 Posts: 250
|
(Msg. 13) Posted: Tue Oct 17, 2006 11:56 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On 17 Oct 2006 06:41:43 -0700, "Krice" <paulkp.TakeThisOut@mbnet.fi> tried to confuse
everyone with this message:
>Timofei Shatrov wrote:
>> A complicated hierarchy of classes is better than code full of switches and ifs.
>
>Don't be such a fool. At least you should tell -why- it is better,
>before
>trolling like that. I know from experience that it's perfecly
>acceptable
>to extend the base class with some methods that aren't needed for
>all instances of the object. In some cases it's easier than making
>a new class.
I don't know how hard is to create a new class in C++, but I reckon it shouldn't
be too hard...
>Let me tell an example. I have Tileset class which set up tiles and
>draws them. Now, I need to manually create shadows for items.
>Instead of inheriting something like Shadowed_Tiles:Tileset I just
>wrote five helper functions that create shadows. If I need to set
>the shadows for the instance of a Tileset I call:
>
>items->Shadowize();
>
>This will not confuse another tilesets even those functions are
>present. I'm probably careful enough not to call Shadowize for
>other tilesets.
Now if you did create a new class, your compiler would catch the error if you're
not careful enough. Self-documenting code is a good thing. Linear code is also a
good thing. Ifs are a mess.
That said, I would've made Item class handle the shadowing, and tile->Shadowize
just calls item->Shadowize for each item in tile.
--
|Don't believe this - you're not worthless ,gr---------.ru
|It's us against millions and we can't take them all... | ue il |
|But we can take them on! | @ma |
| (A Wilhelm Scream - The Rip) |______________| >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: Nov 22, 2004 Posts: 250
|
(Msg. 14) Posted: Tue Oct 17, 2006 11:56 am
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Tue, 17 Oct 2006 13:42:56 +0000 (UTC), DarkGod <darkgod.DeleteThis@t-o-m-e.net> tried to
confuse everyone with this message:
>> x.method();
>>
>> and introduce 3 new classes P1 (containing all xs such that property(x)=1), P2
>> and P3 where method does A1, A2 and A3 respectively.
>>
>> Makes for much clearer code.
>
>What when you want to have a P4 which A4 uses some things og A1 and A2 but does
>more too ?
>You copy the code ?
Inherit both classes and call those methods. Nothing a good object system can't
do.
>> >Use class members whenever possible rather than subclasses.
>> >For example, you can have "actors" (a class that takes in
>> >both the PC and the monsters) have a member of the "AI" class,
>> >and subclass AI into monster_AI and player_IO rather than
>> >subclassing "actors" into "players" and "monsters."
>> What's the difference? Looks like the same amount of new classes are created.
>> And AI looks more like a method than a class to me.
>
>Not a method, a property of the actor.
>In you system what happens the day you want a monster to be able
>to swicth form on AI to an other ?
>Like your monster walks in staright line and then the player throws
>a potion of booze at him, now he must walk in a drunken way.
A good OO approach is that every changeable property is related to a method
(accessor function), so properties and methods are basically the same thing. A
property x.ai is equivalent to a pair of methods: x.get-ai() and
x.set-ai(new-state).
I don't buy that data-driven stuff. It makes much cleaner code, when you write:
player = make-instance(player-class)
instead of
player = make-instance(actor-class);
player.ai = player-IO;
player.hp = 20
player.mp = 10
<another 132 assignments of properties snipped>
--
|Don't believe this - you're not worthless ,gr---------.ru
|It's us against millions and we can't take them all... | ue il |
|But we can take them on! | @ma |
| (A Wilhelm Scream - The Rip) |______________| >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
External

Since: May 30, 2005 Posts: 45
|
(Msg. 15) Posted: Tue Oct 17, 2006 1:42 pm
Post subject: Re: Value of inheritance in Object-oriented programming [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
> x.method();
>
> and introduce 3 new classes P1 (containing all xs such that property(x)=1), P2
> and P3 where method does A1, A2 and A3 respectively.
>
> Makes for much clearer code.
What when you want to have a P4 which A4 uses some things og A1 and A2 but does
more too ?
You copy the code ?
> >Use class members whenever possible rather than subclasses.
> >For example, you can have "actors" (a class that takes in
> >both the PC and the monsters) have a member of the "AI" class,
> >and subclass AI into monster_AI and player_IO rather than
> >subclassing "actors" into "players" and "monsters."
> What's the difference? Looks like the same amount of new classes are created.
> And AI looks more like a method than a class to me.
Not a method, a property of the actor.
In you system what happens the day you want a monster to be able
to swicth form on AI to an other ?
Like your monster walks in staright line and then the player throws
a potion of booze at him, now he must walk in a drunken way.
> What if monsters don't have inventories for example, or have simplified LOS
> implementation? Monsters also don't have 50 skills that player has and these
> skills don't need to be checked when monster steps on a trap or something like
> that.
All this things can (and should be) properties.
Having this or that skill, or having inventory does not define what a monster
is.
> >This pays off when you have several different class members -
> >it saves you a very complicated hierarchy.
>
> A complicated hierarchy of classes is better than code full of switches and ifs.
A code full of switches is unreadable(or so some want to believe;), a code full
of complicated classes hierarchies is also unreadable.
What ray advocates(and so do I) is really not a switch/if code, but rather a
data/properties driven model.
A monster(or object or whatever) is some base thing(like a monster, or an
actor)
with a list of properties.
If you are doing OO you sure can have properties by a class hierarchy, so you
can
do something like:
for property in actor.properties do property.run(actor) end
No if anywhere to be seen and yet the power to construct complex and unique
beings
easily.
This is the way T-Engine works and we can have thousands of different monsters
all sharing some properties but all have some unique ones.
Or your properties can just be booleans and then you need to switch on them when
you
do something but that's still quite acceptable.
A complex class hierarchy can be very useful, but not in all cases and like ray
I do not
believe it is here.
--
DarkGod comes from | Do not meddle in the affairs of wizards
the hells for YOU !  | because they are subtle and quick to anger.
-----------------------+----------------------------------------------
ToME power! http://t-o-m-e.net >> Stay informed about: Value of inheritance in Object-oriented programming |
|
| Back to top |
|
 |  |
| Related Topics: | 7DRL: Invader - Well, I've talked myself into attempting a game for the 7DRL challenge. :-) Invader will be a sci-fi RL where the player is the planet's only hope of stopping a dread alien invasion ship. The character's base of operations will be their docked ship. ....
7DRL: TBA! :P - I'm going to throw my hat into the 7drl arena by taking on a project I've wanted to do for ages. I think it will get me past the mental block of actually getting started. My concept is based around the remains of a post apocalyptic world with gang..
7DRL : Commander - It is 13.40 in my time zone (GMT +100). Time to start my 7DRL project: Commander. I will do it in Free Pascal. Plans are quite big so there is real danger of failure. Good luck to all participants of 7DRL contest. -- Michal ''Ancient'' Bielinski
7DRL : Valley of Ge-Hinnom - Info : @ goes chase to Moloch, java, using my library, so if I fail at least I can post an updated library. T.
7DRL - Deserted... - Okay, Here's to learning new things :) I am beginning work on my 7DRL, Deserted. Everybody loves waking up on a desert island, right? C++, dev-cpp, minGW... no curses.. I'm just beginning to dip into that. So, everyone get ready for a monochromatic.. |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
 |
|
|