Re: Modeling events that occur in a game world
- From: "Aaron J. M." <ajmacd@xxxxxxxxxxxxxxx>
- Date: 25 Apr 2007 13:58:26 -0700
On Apr 23, 5:20 am, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
This is why the event abstraction is not that good for more or less
elaborated physics. It would make the design of objects way too complex.
When an object is thrown, it is not a collaboration between it and the
thrower. It just flies, it need not to know what has thrown it.
Yes, the actual motion of a thrown creature needs no collaboration
with the
thrower or anything like that. But what about the AI controlling the
creature?
To be an effective AI, it needs to
1) Tell that the creature was thrown in the first place.
2) Tell who the thrower was, so that it knows who to retaliate
against.
Basically, I don't need events for the creatures or other game objects
themselves, but for the AIs controlling them. I need the AIs be able
to
know when things in the world happen. This has more to do with
capturing
the semantic information of what caused something to happen and who
were
involved. Two Creatures attacking each other is fairly
straightforward.
Allowing the AI controlling Creature X be able to tell that Creature Y
has
attacked its friend Creature Z which should make the AI tell X to
attack Y
is what I'm having trouble with.
This discussion is turning a little too abstract for my taste, so
here's
some pseudo-code. This will ignore the player and graphics system.
Maps are a set of locations (Loc objects), where one Creature may be
at any
location. It knows what Creatures are at what locations on it, and
Creatures may be placed at or removed from certain locations.
class Map
{
list<Creature> getAllCreatures()
Creature getCreature(Loc loc)
void removeCreature(Loc loc)
void addCreature(Creature cr, Loc loc)
}
Creatures are things that exist on a Map, have statistics (health,
attack,
etc.) and interact with each other. It also knows where it is in the
world
for the benefit of its AI (though I haven't finalized how this
relationship
will work yet, so the movement code here may not be the best design).
class Creature
{
private int health, attack
public Loc getLoc()
public Map getMap()
public void takeDamage(int atck)
{
this.health -= atck
if this.health <= 0:
getMap().removeCreature(getLoc())
}
public void attack(Creature target)
{
target.takeDamage(attack)
}
public void move(Map m, Loc loc)
}
AIs encapsulate all the decision-making behavior for a Creature. They
look
at the map their "body" is on and choose an action for it.
class AI
{
private Creature body
public void takeAction()
{
if toManyEnemies( body.getMap() ):
body.move( aPlaceThatIsFarAwayFromTheNasties( body.getMap() ) )
else if somethingHereToHunt( body.getMap() ):
body.attack( aGoodTarget( body.getMap() ) )
}
private bool toManyEnemies(Map map)
private Loc aPlaceThatIsFarAwayFromTheNasties(Map map)
private bool somethingHereToHunt(Map map)
private Creature aGoodTarget(Map map)
}
Game is a container for all the Maps (which have Creatures), and AIs,
and
controls in what order the AIs act (the main loop).
class Game
{
private list<Map> allMaps
private list<AI> allAIs
public void loop()
{
while gameNotOver():
for a in allAIs:
a.takeAction()
}
private bool gameNotOver()
}
The missing link has to do with AIs knowing things that have happened
to
their own Creatures or to any other Creatures they'd be interested in.
This information does not have to do with Creature actions like
attacks
themselves, but with AIs being able to infer what has happened and who
were
involved so that they know who to blame.
Sorry if I sound a bit dense, but I'm really trying to understand what
you
people are saying, and I would really like to solve this problem.
Thanks
for bearing with me.
.
- References:
- Modeling events that occur in a game world
- From: Aaron J. M.
- Re: Modeling events that occur in a game world
- From: Alvin Ryder
- Modeling events that occur in a game world
- Prev by Date: Re: Design question: Multiplying singletons
- Next by Date: Re: Modeling events that occur in a game world
- Previous by thread: Re: Modeling events that occur in a game world
- Next by thread: Re: Modeling events that occur in a game world
- Index(es):
Relevant Pages
|