Results 1 to 5 of 5

Thread: NPC's in a RPG

  1. #1

    NPC's in a RPG

    I'm currently doing some RPG components containing all the stuff you need to create RPG's like Dialog, Spell and Item handling, Abillities etc.
    The components will be quite easy to use with any graphics engine.

    I have a little nut to crack however. I'm not sure what technique is best to use to keep track of NPC's throughout the world. The way I was thinking, was that the player and NPC's uses the same structure to keep things simple. The structure contains stuff like health and position. The idea is to have the main player search for potential "targets" within a certan distance.

    So, the problem is: how do I keep track of all the NPC's? I thought about using LinkedLists or something, but I could really use some advice from someone more experienced than me. Also, the components should be able to diside what gets drawn. Is this possible while still keeping the "independant graphics engine" principle, or should I just write a graphics engine aswell?
    BK - we.create (tm)

  2. #2

    NPC's in a RPG

    Well, of course you could use linked lists, but I for my part love object orientation and it might make things a lot easier for you. (You could for example have a base object and two inherited objects, one for the player and one for the NPCs).
    You might also want to look at TCollection/TCollectionItem which is what I normally use to keep track of enemies/NPCs. A linked list will probably outperform a TCollection, but so far, I never had any speed problems while using collections.
    Ask me about the xcess game development kit

  3. #3

    NPC's in a RPG

    Thanks for the suggestion

    I need an additional advice: some of my components have to have access to each other, mainly my event handler which needs access to all components and vica versa. I can't figure out a way to do this without getting a circular reference. It won't do any good to add the unit below implementation since that would force me to do a global instance of the event handler (which isn't the end of the world, but it would be neat to avoid it).
    BK - we.create (tm)

  4. #4

    NPC's in a RPG

    You could try to have a reference to a base class instead of the real class. It's a bit hard to explain so I'll just throw in the code:
    [pascal]
    TMyClass = class
    private
    FMyOtherClass: TObject;
    public
    procedure SetMyOtherClass(Value: TObject);
    end;

    implementation

    uses
    someunit;

    procedure TMyClass.SetMyOtherClass;
    begin
    Assert(Value is TMyOtherClass, 'Value need to be a TMyOtherClass reference');
    FMyOtherClass := TMyOtherClass(Value);
    end;
    [/pascal]

    Sometimes it works good by doing it that way other times it don't, all depending on you own special needs.

    As for a global reference. You could use a singleton (which can only have one instance) instead of it. In the end it's the same thing but it looks better and are probably a bit more stable.
    Signature:
    <br />This is a block of text that can be added to posts you make. There is a 255 character limit

  5. #5

    NPC's in a RPG

    Thanks! It lets me link the components just fine. Only one slight problem: I can't access the class I've assigned, only it's parent class.
    IE I can't access my TRPGItems class, only it's parent TComponent.
    BK - we.create (tm)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •