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;
}