Re: Confused about mutually dependant classes

From: H. S. Lahman (h.lahman_at_verizon.net)
Date: 05/20/04


Date: Thu, 20 May 2004 21:05:04 GMT

Responding to Ruderman...

> I'm writing a game (though it isn't a serious project). The game contains
> creatures, each of whom has a number of hit points. Hit points are lost by
> taking damage, and creatures may have various ways of modifying the amount
> of damage they receive. In addition, damage may have other effects
> unrelated to the creature itself. For example, fire damage might destroy a
> creature's flammable possessions.
>
> I'm confused about how to design the classes to support this system. It
> seems appropriate to have a damage class that abstracts the various things
> damage can do, but how do I divide the work of dealing damage between the
> creature class and the damage class? Should damage be aware of the various
> ways it can be resisted? Should creatures be aware of all the things damage
> can do (besides reducing hit points)? Should damage deal itself to
> creatures, or should creatures receive damage? How do I design a mutual
> interface such that only these two classes can use it?

A Damage class is possible, but I am a bit skeptical. A lot more
context information about the game would be needed to determine that.

The reason I am skeptical is that damage would be a result of some
activity that caused the damage. The owner of that activity probably
doesn't care about the resulting damage; it just needs to announce that
the activity took place.

Whoever or whatever gets damaged have an interest in knowing about that
activity. They would understand how to react to that activity by
assessing damage.

So the normal thing would be for whoever executes the activity to send a
message identifying the activity to everyone who might be affected by
the activity, including damage assessment. So we might have something like:

               +------------------+
               | |
               | zaps |
               | 1 |
          [Creature] -------------+
             | 1 1
             |
             |
             | carries
             | *
          [Stuff]

So Creature A zaps Creature B with a flame-thrower. That the zap
mechanism was a flame-thrower could be part of the message data packet
for a generic "zap" message or it could be a unique message, such as
"zapWithFlame".

Handling the [Stuff] carried by Creature B is a matter of context. One
choice is for Creature A to also send the same message to each of
Creature B's Stuff objects. Alternatively, Creature B could decide
whether it should notify any of its Stuff about the flame-thrower in the
course of its own damage assessment.

FWIW, without more context I would be inclined to do the second option
for a couple of reasons. The main one is that Creature A probably
doesn't need to know Creature B is carrying anything; that seems like a
personal issue between B and B's Stuff. A related reason is that it is
likely that Creature B is a better judge of what to do about damage to
itself and its stuff. For example, if Creature B has invested in a
flame-retardant backpack that is likely to affect the damage to Stuff
and Creature A probably isn't in a position to know that.

*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
(888)-OOA-PATH



Relevant Pages

  • Re: Artifact fix ideas
    ... them double damage which is useless against everything else, ... Also, it's a silver saber. ... giants, +2 hit bonus vs. H and others), deal +3d8 damage against large ... it drains levels from any drain-resistant creature, ...
    (rec.games.roguelike.nethack)
  • Re: Vulnerability
    ... the extra effect of a flaming sword on a cold-based creature ... points of fire damage per hit are doubled. ... Current skeletons have immunity to cold because of their lack of fleshy ... So a skeleton would not be affected by the ice portion of an ice storm ...
    (rec.games.frp.dnd)
  • Re: Nethack variant idea
    ...  I would handle it by having regeneration not apply ... the creature is hungry, and stop entirely if the creature is ... Survivability would primarily be ... will probably barely damage a peer if he uses an unenchanted blade. ...
    (rec.games.roguelike.development)
  • Re: Vulnerability
    ... the extra effect of a flaming sword on a cold-based creature ... points of fire damage per hit are doubled. ... Current skeletons have immunity to cold because of their lack of fleshy ... So a skeleton would not be affected by the ice portion of an ice storm ...
    (rec.games.frp.dnd)
  • Re: Perception and AI (and log messages)
    ... Where do the messages that describe events in the game come from? ... In the case of damage reports, ... AIs friendly to the player and the rest ... would make its creature run away if it has too little health, ...
    (rec.games.roguelike.development)