Results 1 to 7 of 7

Thread: SRL Polymorphism with types

  1. #1
    Join Date
    Feb 2016
    Posts
    14
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default SRL Polymorphism with types

    So I'm currently working on a pathfinding algorithm to streamline my scripts when i get round to making some (I actually saw similar objects runemate which gave me the idea to do it this way), but I've run into some issues:
    The plan is to use Dijkstra's algorithm to filter through a number of different points which can be reached across the rs world. So obviously these points have to be connected in order for a path to be found, so i've set up a number of different records to store these vertices.

    Anyway, the issue is, short of making a single record to store all my data ( and therefore take up a bunch more memory and everything) is there any way I can make it so that I can store a number of different vertices in and array of my RSVertexRSEdge record, and still be able to call the sub-record specific values (like CoOrdinateVertexCoOrdinateEdge.path).

    Thanks for any help

    I've attached my work so far so anyone giving input can get an idea of what i might be wanting to achieve.

    Simba Code:
    type
    EdgeMethod = (telePath,itemPath,objectPath,npcPath);
    EdgeDir = (directed, bidirectional);

    levelReq = record
       skill: byte;
       level: byte;
    end

    EdgeReq = record
      items: TIntegerArray;
      skills: array of levelReq;
      quests: TStringArray;

    end

    RSEdge = record
      method:EdgeMethod;
      direction: EdgeDir;
      origin: TPoint;
      target: TPoint;
      req :EdgeReq;
      cost:integer;
    end
    TeleEdge = record(RSEdge)
      spell:string;
      spellbook:string;
    end
    ItemEdge = record(RSEdge)
       item:integer;
       options:TStringArray;
    end
    NPCEdge = record(RSEdge)
      options:TStringArray;
    end
    ObjectEdge = record(RSEdge)
      id:integer;
      options:TStringArray;
    end
    CoOrdinateEdge = record(RSEdge)
      path:TPointArray;
    end

    function RSEdge.isUseable:Boolean;  //should calculate if player meets requirements
    begin
       //self.reqs.items
       //self.reqs.levels
       //self.reqs.quests
    end
    function CoOrdinateEdge.calcCost:integer;
    var
    temp:extended;
    i:integer;
    begin
      temp := 0;
      for i:= 1 to high(self.path) do
        temp := temp+hypot(self.path[i].X-self.path[i-1].X,self.path[i].Y-self.path[i-1].Y);
       result := round(temp);
       self.cost := round(temp);
    end
    Last edited by Wolfskull; 05-06-2016 at 01:13 PM.

  2. #2
    Join Date
    Sep 2014
    Location
    C:\Simba\
    Posts
    565
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    I'm not really sure what you're trying to ask here but if I understood correctly you could do:

    Simba Code:
    var
      ArrayOfRecord : Array of TYourRecordNameGoesHere;
     
    begin
      setLength(ArrayOfRecord, 5); //this is given that the array is static, else you could just change the length accordingly.
      ArrayOfRecord[3].whatEver //notice the 3. It's the fourth index in the array. If these won't be static you could use something to point to the correct index.
    end.

    I would personally not recommend you to use this many records, since it only makes it confusing. I would store it all in one array. And what do you mean by takes up more memory? Given that you store the same amount of information using a record won't magically decrease the memory taken. If anything it will take up more (not noticeable though).
    Feel free to ask me any questions, I will do my best to answer them!

    Previously known as YouPee.

  3. #3
    Join Date
    Feb 2016
    Posts
    14
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    Well essentially what I need is a data structure that can store the following
    • Defining a connection between two points (origin & target in my OP)
    • Describing the connection between those points (VertexMethod in OP)
      Then depending on the type of connection it needs to store other data (These are in the child record in the OP [2 strings for telepath, an integer and some strings for item/npc/object or an array of points for coordinate)
    • Describing the requirements to follow the connects (req/vertexReq in OP)
    • Defining if the connection is directional or can be reverse (vertexDir)


    And While I could do all of these in a single record like below, I feel like that would make the whole thing less efficient as every single instance of that record would now need to allocate memory for all the extra variables it now has.
    Simba Code:
    RSVertex = record
      method:VertexMethod;
      direction: vertexDir;
      origin: TPoint;
      target: TPoint;
      req :VertexReq;
      cost:integer;
      teleport:array[0..1] of string;
      InteractID: integer; //id of interacting thing (npc/item/object)
      options: array[0..4] of string;
      path:TPointArray;
    end

  4. #4
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    I think you're trying to implement nodes. Just make a pointer to an RSVertex in the record. Allocate it and use it when you need to. Or bidirectionally;

    Simba Code:
    Prev, Next : ^RSVertex;
    Last edited by Kasi; 05-06-2016 at 10:40 AM.

  5. #5
    Join Date
    Feb 2016
    Posts
    14
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Kasi View Post
    I think you're trying to implement nodes. Just make a pointer to an RSVertex in the record.
    Correct, for some reason I decided to do the vertices first before the actual nodes lol, I'm planning on having multiple connections so rather than prev/next it'll be and array of them. I've also figured out how to get the functionality I want: I just have to use untyped pointers and then typecast when needed.

    Simba Code:
    type
    VertexMethod = (telePath,itemPath,objectPath,npcPath,walkPath);
    var
    aVt:array of pointer;
    vt1:CoordinatePath;  

    begin
     vt1 := [walkPath,bidirectional,[0,0],[10,10],[[81259,29578,29583],[[15,10]],['Legend''s']],0,[[-10,5],[1,45]]];

    setlength(avt,2);
    Avt[1] := @vt1;  
     for i := 0 to high(avt) do
     if avt[i] <> nil then
     begin
    if RSVertex(avt[i]^).method = walkPath then
       writeln(CoordinateVertex(avt[i]^).path);
       end

    This way I can keep each vertex typed separately like I wanted, just have to make sure typecasting is always done correctly to prevent errors.

  6. #6
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by Wolfskull View Post
    Correct, for some reason I decided to do the vertices first before the actual nodes lol, I'm planning on having multiple connections so rather than prev/next it'll be and array of them. I've also figured out how to get the functionality I want: I just have to use untyped pointers and then typecast when needed.

    This way I can keep each vertex typed separately like I wanted, just have to make sure typecasting is always done correctly to prevent errors.
    Alright, Just a quick tip. Careful about terminology. Bi-directional usually means 2 directions not multiple directions.

  7. #7
    Join Date
    Feb 2016
    Posts
    14
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    Yeah, I was meaning the vertices edges are bidirectional (Can be traveled both ways (that is to say, if I define an origin and a target, they can be reversed))
    but my nodes themselves would be joined by multiple verticesedges, so simply having prev/next doesn't work.

    ...
    I realised I've been using vertices when I've been meaning vectors.
    I'll stick to graph nomenclature of vertices and edges from now on

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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