Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Smart monsters

> From: Petri Heinil{ <>
> What I thinked was some kind of language like Postscript by object
> oriented features. For example:
> 'StoneDragon 'Dragon {
>   1000 hp
>   500 sp
>   'create { "The Stone Dragon" name } def
>   'destroy { 'DragonSteak create DragonScale create } def
>   ...
>   'give { "Thank you" say } def 
>   ...
> } class
> Here is StoneDragon inherited from Dragon class setted by initial
> hit points and spell points and define constructor and destructor
> for class and so on. More info can be found from book "PostScript
> language  Reference Manual" ISBN 0-201-10174-2.  

With this approach, all monsters will have to be redefined.  This could be
nice to have an object-oriented language to describe monsters, but this is
easier for now to add a set of conditions and corresponding actions to the
existing definitions.  Some monsters could have a special "actions" definition
(name it as you like) when they are put on the map.  The archetype will remain
unchanged and only this particular instance of the monster will be affected
by the "actions".

Here are a few conditions that could be tested :

- hear "<words>"            Just like the "@match" command.  Maybe with
                            regexp matching ?
- has <object> [<number>]   If the player in one of the adjacent squares is
                            carrying some object or a certain amount of it
                            (five gold coins, for example).
- on <number> / off <num>   The number is the same as the one used in the
                            "connect" command for a set of doors and buttons.
- die                       True only if the monster dies.
- any combination of these conditions, with the traditional boolean operators
  ("&&", "||" and "!").

And here are some actions that could be associated with the conditions :

- say "<words>"             Guess what this one does...
- create <object> [<num>]   Create one or several objects.
- destroy <object> [<num>]  Destroy one or several objects in the player's
- set <num>                 Set a flag (open the corresponding doors).
- reset <num>               Clear a flag (close the doors).
- toggle <num>              Toggle a flag (open or close the doors).

Finally, here is an example.  Think of it as if each line of the "actions"
definition began with an "if".  The syntax is not very important here and
could be changed to some PostScript-like descriptions.  I only wanted to
show the principles of what could be done.

arch sage {
  name "Gandalf"
  hp 100000
  actions {
    hear "hello" { say "hi" }
    has ruby 20 && has dagger { destroy dagger
                               destroy ruby 20
                               create Sting
                               say "Here is your new weapon."
    has gold 3 && off 1 { destroy gold 3
                          set 1
                          say "You may enter now."
    has gold 3 && on 1 { destroy gold 3
                         say "Thank you very much."

Dozens of other actions or conditions may be added, like a "random" command
or way to check if the number of objects that the player is carrying is
greater or lower than a given number, and so on...

This method should not add too much overhead in the game : the conditions
need only to be tested when a player comes near the monster or when he says