Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: What's the name of the concept of scripting in a Sim/RTS type of game?

  1. #1

    Question What's the name of the concept of scripting in a Sim/RTS type of game?

    Hey peeps,

    I played an Amiga space exploration game in the mid 90' that frustrated me for not being able to finish it.

    It wasn't that good and never got fandom, so I've never been able to find it on emulators. So I decided to redo-it myself.

    I'm at the point where I've got about 70%-80% of the data objects done, but I'm now struggling with one thing:

    How do I avoid having my code littered with IF/THEN blocks for the chain of events that I want the game to have.

    The only word that comes to mind is a script, like in the movies. But there has to be some kind of other name for this kind of thing.

    I'm thinking of something I can emulate with a linked list or a tree or some other nice data concept that avoids a bunch of IF/THEN or even CASE.

    In this game I'll have to research some items. The basic ones will already have an entry to research, but others will depend on time played and planet scanned. On some planets, one can find literature, that once researched will give me new ships/weapons.

    I'm asking here first, and not the Stack Exchange family, because I don't even know how to formulate the question, neither rationalize an effective query to search for it.

    What do you guys suggest?

    Thanks and cheers,
    Gus

  2. #2
    Use an scripting language is a good choice. There are several ones that works on Free Pascal and Delphi as Pascal Script and Lua.

    Create your own simple scripting language isn't as hard as most people think. I'm working in my very own one right now (documented in Spanish only, at the moment). Anyway, here you have a simple (incomplete and untested) interpretor:
    Code:
      TYPE
      (* A helper type. *)
        TWordList = ARRAY OF STRING;
    
    
    
    (* This splits a string in to words separated by spaces. *)
      FUNCTION SplitWords (aText: STRING): TWordList;
      VAR
        CharNdx, WordNdx: INTEGER;
        ResultList: TWordList;
      BEGIN
      { First word. }
        SetLength (Resultlist, 1);  WordNdx := 0;
      { Extract... }
        FOR CharNdx := 1 TO Length (aText) DO
        BEGIN
        { If found space or comma (,), then another word starts. }
          IF aText[CharNdx] IN [' ', ','] THEN
          BEGIN
          { This is to avoid multiple spaces. }
            IF ResultList[WordNdx] <> '' THEN
            BEGIN
              INC (WordNdx);
              SetLength (ResultList, WordNdx + 1)
            END
          END
          ELSE
          { Adds character to word.  Does it uppercase. }
            ResultList[WordNdx] := ResultList[WordNdx] + UpCase (aText[CharNdx])
        END;
        EXIT (ResultList)
      END;
    
    
    
      PROCEDURE MyScriptInterpretor (aScript: TStrings);
      VAR
        CurrentLine, Ndx: INTEGER;
        LineWords: TWordList;
        FullLine: STRING;
      BEGIN
        IF aScript.Count > 0 THEN
          FOR CurrentLine := 0 TO aScript.Count - 1 DO
          BEGIN
          { Extract words. }
            LineWords := SplitWords (aScript.Lines[CurrentLine]);
          { Checks "commands" }
            IF LineWords[0] = 'SAY' THEN
            BEGIN
              IF Length (LineWords) < 3 THEN
                RAISE Exception.CreateFmt ('Not enough parameters on line %d.', [CurrentLine + 1]);
              FullLine := '';
              FOR Ndx := 2 TO HIGH (LineWords) DO
                FullLine := FullLine + ' ' + LineWords[Ndx];
              SomebodySays (LineWords[1], FullLine)
            END
            ELSE IF LineWords[0] = 'WARP' THEN
            BEGIN
              IF Length (LineWords) <> 3 THEN
                RAISE Exception.CreateFmt ('Wrong parameters for WARP on line line %d.', [CurrentLine + 1]);
              Player.SetPosition (StrToInt (LineWords[1]), StrToInt (LineWords[2]))
            END
          END
      END;
    Free Pascal's FCL includes an expression evaluator you can use to add maths to your interpretor too. See this link.

    [edit]
    I've just remembered that my PGD Challenge entry Momen3D includes it's own mission script system, much like the one you're asking for. Download it from here and look at file src/mission.pas, function ParseFile, lines 191...650. It looks big and complex but it is actually quite simple, as it is divided in sub-routines for each task.

    To see how the mission script files looks like, just see file bin/data/missions/default/tuto.md
    Last edited by Ñuño Martínez; 05-02-2017 at 02:22 PM.
    No signature provided yet.

  3. #3

    Red face

    Quote Originally Posted by Ñuño Martínez View Post
    Use an scripting language is a good choice. There are several ones that works on Free Pascal and Delphi as Pascal Script and Lua.
    Thanks Ñuño, anyway.

    Well, I was afraid someone would answer something like this when I used the word script .

    What I meant was a way to put this:
    1. Once x time as passed, archaeologist finds, in some ruins, mention to advance space drive
    2. Once you scanned planet Y and Z time passes, you find old space ship and can improve some other aspect
    3. Once you have plan A and plan B on some research, you can discover FTL travel
    4. etc...


    into a data structure.

    So more like a story kind of script, not a scripting language.

    Is there a pattern or a type of data concept, like linked lists or AVL trees that game programmers regularly use to support this?

    Cheers,
    Gus

  4. #4

    Post

    Quote Originally Posted by gcarreno View Post
    Hey peeps,

    I played an Amiga space exploration game in the mid 90' that frustrated me for not being able to finish it.
    Is that game perhaps Elite or Elite2?? Spent countless of hours playing both of them.. Now to the questions:

    Sounds like using an embedded script language might overshoot the target, could you perhaps settle for some basic database instead? I used Json for something similar (not in pascal, but the principles are the same)

    Json makes it easy to store key/value pairs, and it also has (limited) support for conditional branching.

    A quickie:
    Code:
    {
        "technology": [{
            "id": "hyperdrive_1",
            "name": "Basic FTL drive systems",
            "prereq": ["playtime", 1],
            "researched": true
        }, {
            "id": "wormhole_1",
            "name": "Wormhole Navigation for Dummies",
            "prereq": ["playtime", 2],
            "reserached": false
        }, {
            "id": "wormhole_2",
            "name": "Advanced Wormhole Navigation",
            "prereq": ["wormhole_1", "hyperdrive_1"],
            "researched": false
        }]
    }
    Provided that you're using OPascal, you can then fairly easy map each Json-entry to an object, which you then can store away in an array or linked list.

    I would parse the file like this (in pseudo-code)
    Code:
    Load Json-file
    Get Json-object count
    Make place for them (I've got a sweet spot for dynamic arrays)
    For each Json object do
        TechID:=id
        TechName:=name
        for each req in prereq
            if prereq-field contains "playtime" then parse next field member as integer
            else add TechID;s to list of prerequisits.
        TechResearched:=researched
    This would also make it easy to serialize all the data for saving and loading purposes, the memory footprint of the json-object isn't an issue as long as you're running on anything else then a C64, or a Casio pocket calculator. When you've researched a technology, change the "researched"-field of that object to true, and at the end of the game write the modified Json-file back to disk. Then the next time you load the game you will start from where you left instead of having to research all techs all over again.

  5. #5
    Quote Originally Posted by Rickmeister View Post
    Is that game perhaps Elite or Elite2?? Spent countless of hours playing both of them..
    When I was looking for the game name I had that one suggested and also Master of Orion.

    MoO is turn based, the one I played was Real Time and Elite has a trading and mission aspects that the one I played did not have.

    It was quite simply a Sim for resource mining and resource management. The game ended with a battle with the Martians. Either you won, by having a greater quantity of combat drones, or you loosed. I could never win the bloody thing and could not say if it was open ended or not...

    I don't think the game ever got any recognition. It was very simple and didn't have any mission or trading in it, so probably a bit boring for the more hardcore gamers. But it quite appealed to my like. I don't really like the battle and trading aspect of Sims/RTS. What I really like is the calm, relaxed waiting of resource gathering, level updates and going through a tech tree.

    Ok, in regards to your suggestion: It makes a lot of sense and I've already had some version of it in my mind. I asked here because more experienced programmers in the Sim/RTS genres might have already put something in stone.

    From the looks of it, it seems that it's not something that has really cemented.

    At the moment the Objects I've dished out are still "hook" free. I'll need to devise a way to connect the "scripting" objects to the data objects.

    @Ñuño: I've downloaded your code and will have a look at it. Will report on it later. MANY THANKS!!

  6. #6
    Hey peeps,

    After a little bit of searching on https://gamedev.stackexchange.com I found a mention to Finite State Machines (FSM) and it clicked immediately!!!

    DUH!! Of course that's what I want. Why didn't it occurred to me initially is still a mystery

    Now to learn a bit more in depth on the subject and then onto implementation.

    Many thanks to all that gave me an answer.

    Cheers,
    Gus

  7. #7
    Then I recommend you to read this.

    Anyway you can implement your state machine to use a scripting language. it will be more flexible and allow modding, which is always good. In that case the paper I linked may help you with this too.
    Last edited by Ñuño Martínez; 06-02-2017 at 01:03 PM.
    No signature provided yet.

  8. #8
    Quote Originally Posted by Ñuño Martínez View Post
    Then I recommend you to read this.
    Thanks. I actually ended buying the book for my Kindle. The way it's explained connects very well into the game programming world.

    Other stuff I read about the State pattern gave me more question marks in regards of how to make it work on the game, so this chapter is perfect to get the question marks gone.

    Quote Originally Posted by Ñuño Martínez View Post
    Anyway you can implement your state machine to use a scripting language. it will be more flexible and allow modding, which is always good. In that case the paper I linked may help you with this too.
    Thanks for this also. I'll probably implement some kind of modding in the very FAR future.

    Keep in mind that this is a game I'm making for myself. I don't really think I'll ever publish it or anything. But, never say never, and all that, so I'll keep this handy just in case I do get it out from under "for my pleasure only".

    Cheers,
    Gus

  9. #9
    Quote Originally Posted by Ñuño Martínez View Post
    [edit]
    I've just remembered that my PGD Challenge entry Momen3D includes it's own mission script system, much like the one you're asking for. Download it from here and look at file src/mission.pas, function ParseFile, lines 191...650. It looks big and complex but it is actually quite simple, as it is divided in sub-routines for each task.

    To see how the mission script files looks like, just see file bin/data/missions/default/tuto.md
    I've downloaded your code and
    Code:
    sudo apt install liballegro5
    but for some reason it's not able to initialise the allegro stuff.

    Any hints on how to debug it?

    Cheers,
    Gus

  10. #10
    Quote Originally Posted by gcarreno View Post
    but for some reason it's not able to initialise the allegro stuff.

    Any hints on how to debug it?
    Check the latest post in http://www.pascalgamedevelopment.com...Momen-3d/page5 for possible solution.

Page 1 of 2 12 LastLast

Tags for this Thread

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
  •