Topic: Configuration and Scripting  (Read 25279 times)

0 Members and 1 Guest are viewing this topic.

Offline [UFP]Exeter

  • Moderator
  • Lt. Commander
  • *
  • Posts: 1080
  • SFC4 Lead Developer
Configuration and Scripting
« on: May 30, 2013, 08:27:04 am »
A key area to discuss is the scripting language, what to script and how.

First, for game configuration data I am leaning toward XML. 

Storage of other game data, could be in XML, an open database or even a scripting language.

The missions will also be done in a scripting language.  The ones discusses so far are LUA, Angelscript and Python.  Anyone with actual experience, please chime in.  Other than needing one we have not decided which.  Personally I prefer Angelscript.  The reason is because it is very easy to implement te parser in code (already done) and the syntax is more like C++, which to me is much easier to write and understand compared to LUA which is C based. 

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #1 on: May 30, 2013, 11:52:42 am »
That's a very interesting topic.
I've looked at angelscript and it seems very straightforward.
The question here, for me, relies on what people want to script if they had a chance to do it right now.

For example:
In SFB, there is scenarios. A mission have a historic background; number of players that participates; a setup about the objects that exist in the area (planets, asteroids, stars, black holes, etc); a setup about the players relations (teams, etc); and theres an objective to achieve.
Some of the things above can be easily achieved, like what is the historic background, the number of player that are going to participate, how the teams are composed, what kind of objects exist in the area of space and where they are. The big question for me relies on the kind of objectives we could have and how to track them.

So, before we enter in the script topic, we could ask to the people here, what they want to be hable to do in a mission, or campaign, like, for example, the ones that exist in SFC.
Then, people could start to talk about a script implemention of those ideias.
Its a start.
So, comunity what you want to be hable to do in a mission (beside, X players of team A destroy Y players of team B  ;D) ?
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline [UFP]Exeter

  • Moderator
  • Lt. Commander
  • *
  • Posts: 1080
  • SFC4 Lead Developer
Re: Configuration and Scripting
« Reply #2 on: May 30, 2013, 12:04:38 pm »
You point is well taken, and it really requires the game to be configured to read that from the script.  Also, the script itself can be a program that runs a mission.

As for what can be configured, everything you mentioned and more.

But to design the script reader we need to decide what to include in the mission script and how it will be handled.

Another reason for AngelScript, I an already to this.

Offline Captain Adam

  • Lt.
  • *
  • Posts: 754
  • Gender: Male
Re: Configuration and Scripting
« Reply #3 on: May 30, 2013, 12:08:51 pm »
.
« Last Edit: April 06, 2016, 01:42:14 pm by Captain Adam »
Odo :    
"Being accused of a crime is not a disgrace, Chief. Some of the great figures of history have shared the honour with you."
to O'Brien
DS9 : Tribunal

Offline Starfox1701

  • Lt. Commander
  • *
  • Posts: 1049
Re: Configuration and Scripting
« Reply #4 on: May 30, 2013, 12:36:44 pm »
This might help us evaluate Lua better. I understand the attraction of Angelscript but am concerned that  the syntax might be more difficult to learn for people without a working understanding C++.

https://dl.dropboxusercontent.com/u/3697428/Programming%20in%20Lua%2C%20Second%20Edition-2010kaiser.pdf

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #5 on: May 30, 2013, 12:50:01 pm »
Quote from: [UFP
Exeter]
But to design the script reader we need to decide what to include in the mission script and how it will be handled.

For example:
We could create a structure with the basic data of the mission (looking to the example i gave) and call a function in the script, passing that object by reference, to get the data.

class PlayerData(
   Race
   WhoIsOnShip (computer/human)
   Kind of ship that can use (of the case of a computer generated player)
   etc
)

class TeamData(
   NumberOfPLayers
   PlayerData Player[]
   etc
)

class MissionData(
   HistoricBackground

   Number of Teams
   TeamData Team[]

   Number Of objects in space
   SpaceObject Objects[]

   MissionStatus

   etc
)

MissionData mission;

script->SetupMission(*mission)

Than, we could use an event based system to track down the mission objectives

int ScanMade(*obj){
    script-> ScanMade(*obj)
}

int ObjectDestroyed(* obj){
   script-> ObjectDestroyed(*obj)
}

etc
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline [UFP]Exeter

  • Moderator
  • Lt. Commander
  • *
  • Posts: 1080
  • SFC4 Lead Developer
Re: Configuration and Scripting
« Reply #6 on: May 30, 2013, 12:55:42 pm »
Starfox: LUA is C based, Angelscript is C++ based, which makes angelscript much easier than LUA.  Unless you already know LUA.

d4v1ks:  I agree.  My concern is any scripting will be slow, so we need a robust Mission API, to minimize any runtime scripts.

Captain Adam:  All you mentioned is possible using scripts to control missions.

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #7 on: May 30, 2013, 02:36:50 pm »
Quote from: Exeter
My concern is any scripting will be slow, so we need a robust Mission API, to minimize any runtime scripts.

You could code almost everything in your game, and use the script just to keep track of things.
We could build, for example, event objects and put them in a tree inside of the mission object.
While in the game loop we test if the conditions were met and only call script functions when
the current mission's objective is achieved.

//------------------------------------------------------------------------------------------------------------------
// ingame
//------------------------------------------------------------------------------------------------------------------

SCAN_MADE = 1
BEAM_UP = 2
ENEMY_DESTROYED = 4
LEAVE_HEX = 8

class EventData{
   Conditions
   Goal
   ptrFunction

  EventData Child;
  EventData Brother;
}

class MissionData(
     All things in the last post
                 +
     EventData currentNode;
     EventData eventTree;
)

MissionData currentMission;

GameLoop()
{
   // to be hable to use it inside of the script...
   script->RegisterGlobalFunction(PrintStuffInConsole( *text))
   script->RegisterGlobalFunction(AddEnemyToCurrentGame())

   script->SetupMission(*currentmission)

   currentMission.currentNode = currentmission.eventTree

   do
       //play the game...

   until TestEventTreeConditions(*currentMission.currentNode) = MISSION_DONE   
}

PrintStuffInConsole( *text){
    game->console->print (*text)
}

AddEnemyToCurrentGame(){
    enemies[] = ListEnemies(player)
    enemy = enimies[random]

    game->create(enemy)
    game->add(enemy)
}

TestEventTreeConditions (*node)
{
   do
       if (node.Conditions AND node.ConditionsRequired) == node.ConditionsRequired
       (
           r = script->CallFunctionByPtr(node.functionptr)

           if node.child != NULL (
              node = node.child
              return NEXT_MISSION
           ) else (
              return MISSION_DONE

             game->points += r
           )

       ) else (
           node = node.brother
       )
    until node = NULL

}

ScanMade(){
   currentMission.currentNode.conditions OR= SCAN_MADE
{

BeamUp(){
   currentMission.currentNode.conditions OR= BEAM_UP
{

EnemyDestroyed(){
   currentMission.currentNode.conditions OR= ENEMY_DESTROYED
}

OtherStuff(){
   currentMission.currentNode.conditions OR= OTHER_STUFF
}


//------------------------------------------------------------------------------------------------------------------
// on the script
//------------------------------------------------------------------------------------------------------------------


SetupMission(*mission)
{
   setup all the things in the last post...

  // 1º scan planet
  CreateEvent(mission.eventTree,
              SCAN _MADE,
              *ScanMade
  )


  // 2º beam up resources
  CreateEvent(mission.eventTree.Child,
              BEAM_UP,
              *ResourcesOnboard
  )


  // 3.1º evade current hex map AND Destroy enemy incomings
  CreateEvent(mission.eventTree.Child.Child,
              LEAVE_HEX & ENEMY_DESTROYED,
              *MissionComplete
  )

  // 3.2º evade current hex map
  CreateEvent(mission.eventTree.Child.Child.Brother,
              LEAVE_HEX,
              *MissionEvaded
  )
}

CreateEvent(*node, Goal, *ptrFunction){
    node = new EventData

    node.Goal = Goal
    node.prtFunction = *ptrFunction
}

ScanMade()
{
    PrintStuffInConsole("The planet seems to have the resources you want")
}

ResourcesOnboard()
{
    PrintStuffInConsole("Comander the resources are onboard already")
    AddEnemyToCurrentGame()
}

MissionComplete()
{
    return 5 points;
}

MissionEvaded()
{
    return 1 points;
}
« Last Edit: May 30, 2013, 03:12:20 pm by d4v1ks »
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #8 on: May 30, 2013, 02:56:07 pm »
from the scripter perspective we have something like:


Mission:
     Background:
          Your mission is to scan the planet and beam up the medical resources that your crew need.
          If you enconter any enemy resistance you have the option to destroy them.
          Leave the hex when you are done.

     Setup:
          1 human player
          1 enemy AI
          1 star
          1 Planet


                          Scan the planet
                                    |
                                    |
        Use the transporters to beam up the resources
  (add a enemy of the player if the operation is suceeded)
                                    |
                                    |
                                    |----------------------------------------------------+
                                    |                                                                 |
                                    |                                                                 |
                      Leave the space hex                           Destroy all the enemy incomings and leave the hex
                             (1 point)                                                       (5 points)
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #9 on: May 30, 2013, 03:39:11 pm »
After this we could use our imagination and go further.
Why not create a tree of missions and call that a campaign?
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline [UFP]Exeter

  • Moderator
  • Lt. Commander
  • *
  • Posts: 1080
  • SFC4 Lead Developer
Re: Configuration and Scripting
« Reply #10 on: May 30, 2013, 03:52:29 pm »
We will also me using a Fixed State Manager for AI, so the states, what they do and what causes changes to other states could be coded into the AI.  This would be mission specific and the AI will have a FSM already created in the game.  Plus I am considering saving history to be used for the FSM to learn.  For example if could learn a particular strategy does not work, so it does not use it.

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #11 on: May 30, 2013, 04:03:55 pm »
Learning:

That kind of aprouch has a downside.
Cause, we can give to AI a false image of sucess.
Just imagine people teaching the AI bad strategies, by loosing on purposely. Just to mess it up
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline [UFP]Exeter

  • Moderator
  • Lt. Commander
  • *
  • Posts: 1080
  • SFC4 Lead Developer
Re: Configuration and Scripting
« Reply #12 on: May 30, 2013, 04:11:01 pm »
Very true.  but there are ways to compensate.

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #13 on: May 30, 2013, 04:18:39 pm »
Quote from: Starfox1701
(...) but am concerned that  the syntax might be more difficult to learn for people without a working understanding C++.

That's not always true...
The programmer can encapsulate much of the code that people will use.
So in the end you will script things like

AddThis();
AddThat();

Mission1 = CreateMission(this, that, bla, bla);
Mission2 = CreateMission(this, that, bla, bla);

Mission1.Next = Mission2;

etc...

So in the end it could be easy to code and add things on those scripts.
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline [UFP]Exeter

  • Moderator
  • Lt. Commander
  • *
  • Posts: 1080
  • SFC4 Lead Developer
Re: Configuration and Scripting
« Reply #14 on: May 30, 2013, 04:38:57 pm »
Regretfully, something I was hoping to avoid, for then the scripts are running the game.  Performance bottleneck.  And puts game control in the hands of a script.    It may be because I do not know how to script, but I see for a mission load the game loads the starting script for a mission and start the AI.  The AI works with states, if we wish to give the script control over the AI, how do we do this?

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #15 on: May 30, 2013, 05:04:05 pm »
What kind of control you were thinking? Cause, beside setting the AI dificulty in the script don't see why you need to control the AI in a script
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline [UFP]Exeter

  • Moderator
  • Lt. Commander
  • *
  • Posts: 1080
  • SFC4 Lead Developer
Re: Configuration and Scripting
« Reply #16 on: May 30, 2013, 05:12:10 pm »
That is the point.  How far do we go with the script?

I think we need a verbose AI API, and allow many many parameters for creating missions.  Including defining what AI state is called in certain situations.  But the code do do this is built in the game, rather than run code in script.  And given this, in theory we could use a text file of XML.  But using a scripting language allows us to expand the game.

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #17 on: May 30, 2013, 05:15:43 pm »
So, you are thinking in giving to AI some mission objectives or priorities? And script that?
Illustrating, in mission A, the players will need to do this and AI will try to do that?
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #18 on: May 30, 2013, 05:19:17 pm »
Lol, just imagined...
How would it be like, if we could script a AI to do the missions or campaigns that are available to the players?
That would be the ultimate AI test.
"But he isn't wearing anything at all!" (The Emperor's New Clothes)

Offline d4v1ks

  • D.Net VIP
  • Lt.
  • *
  • Posts: 788
  • Gender: Male
Re: Configuration and Scripting
« Reply #19 on: May 30, 2013, 05:23:33 pm »
The only way i see to do that is just by setting the AI objectives in a script once, and then running everything in the game without acessing scripts again.
Like in the Robocop movie. He had PRIME DIRECTIVES that ruled his behavior.
"But he isn't wearing anything at all!" (The Emperor's New Clothes)