--

Game Editors

One of the exciting new features of SV4 GALAXIAE is the ability to program your own Scenarios and Computer Brains using the built in scripting language.  The SV4 GALAXIAE scripting language is similar to the Pascal programming language.  Scenario scripts and Computer Brain scripts have their own function extensions.

Click the Game Editors button to enter the scripting interface.  Here you can load and examine existing Scenario and Computer Brain scripts, modify them, or write your own from scratch.  Use the Compile option to test the script for errors before saving it.

A library of SV4 GALAXIAE script files will be archived at www.galaxiae.org , so if you create any good scripts, please forward them so others can download and enjoy them.

If you decide to write Computer Brain scripts, you can test your Brains by having them fight the Brains that are provided.  Just set the number of human Players in a new game to zero.  Your Brains will fight it out, and you’ll have a complete view of all of the action, with everything visible to you.

Computer Brain scripts are executed once every 10 Impulses, and the different Players alternate the Impulses in which their scripts are executed.

SV4 GALAXIAE Scripting Language

This document contains some example script code the illustrate the basic structure of the scripting language.

{FOR loop}
y := 0;
z := 0;
for x := 1 to 10 do
   begin
      y := y + 1;
      z := z + y * 2;
   end;
print (x); print (y); print (z);

{While loop}
y := 30; z := 1;
while y > 0 do begin

z := z * 2;
 y := y - 1;
end;
print (y); print (z);

f := 0.0;
if (z > 0) and (z < 4) xor (y >= 0) or (y <= 4) and (x <> 0) then 
   x := x mod 5 div 2;

if z = f then
   begin
     x := (((((y * 2) div 3) + 2) - (8 mod 1234)) + 3);
   end
else
   begin
      f := (3.1415926 / 23) * 2.345435E-2;
      f := f + 3 - $100;
      f := f + 2E2;
     print (f);
   end;

The following built-in functions can be used in both Scenario and Computer Brain scripts.

Array (var array, int)
- Assigns to the variable in PAR1 an array with PAR2 elements
- If the variable in PAR1 contains already an array then array is resized.
Round (float) : integer
Trunc (float) : integer
Int (float) : float
Frac (float) : float
Insert (string, var string, integer)
Delete (var string, integer, integer)
Copy (string, integer, integer)
Pos (string, string)
StrToInt (string) : integer
IntToStr (integer) : string
- Converts string to integer and integer to string-
--

Scenario Script Functions

The following function extensions can be used when creating Scenario scripts:

Version( version: float )
Use this function to specify what version this script was intended for.  SV4 GALAXIAE will not accept a script that was written for a higher version number.

SetMapSize( x: integer, y: integer )
Use this function to establish the size of the game map for the Scenario.

CreateStarCluster( Stars: integer, X1: integer, Y1: integer, X2: integer, Y2: integer, Radius: integer, Density: integer )

Use this function to create a star cluster with the specified number of stars, radius and density.  The cluster will be created along a line determined by the points X1, Y1 to X2, Y2.

Random( From: integer, To: integer ): integer
Returns a random number between From and To.

CreateNebula( X: integer, Y: integer, Arms: integer, Cells: integer )
Creates a Nebula starting at X and Y, with the specified number of Arms and Cells.  The more Arms and Cells specified, the thicker and larger the Nebula will be.

SetNebula( X: integer, Y: integer, Value: boolean )
Causes the specified map location to contain a Nebula, or clear a Nebula if one was already there.

CreateWormhole( X: integer, Y: integer, DestX: integer, DestY: integer )
Creates a Wormhole at the specified location, with the specified destination.

SetDescription( Description: string )
Use this function to set the description of the Scenario that appears when the Scenario file is selected in the Game Settings screen.

AssignCapital( Player: integer, X1: integer, Y1: integer, X2: integer, Y2: integer )
Attempts to assign a StarSystem within the area specified by X1,Y1 – X2-Y2 as the Capital for the specified Player.  If no StarSystem can be found in this area, the Player’s Capital is assigned randomly.

CreateStarSystem( X: integer, Y: integer, Name: string, Value: integer, Shields: integer, Scanners: integer, Resources: integer, Owner: integer, Capital: boolean )

Allows you to create a StarSystem explicitly.  You can assign the StarSystem a name, or pass “?” to have the name randomly generated.  Pass –1 in the Owner parameter to have the StarSystem be independent.

SetVictoryConditions( Victory: integer, StarSystemName: string, Value: integer )
Allows you to establish alternate victory conditions for the scenario.  The following victory condition values are supported:
1 - Hold the StarSystem specified by name for the number of Impulses specified in Value.

2 - Horde a number of Resources specified by Value at the StarSystem specified.  Leave StarSystemName blank to have this condition apply to the Players’ Capitals.
3 - Blockade the specified StarSystem for a number of Impulses specified in Value.  A StarSystem is considered blockaded if enemy StarShips completely surround it.

SetStarSystemBonus( StarSystemName: string, BonusShipType: integer, BonusValue: integer )
Allows you to specify the bonus value of a particular StarSystem.  You must have first created the StarSystem with the CreateStarSystem function.  BonusShipType indicates which StarShip type to grant a bonus to.  See the BuildStarShip function in the next section for possible values.  The BonusValue ranges from 1 to 100, and indicates the percentage bonus that the StarSystem will have when building StarShips of its bonus type.  For example, if the StarSystem has a WarShip bonus of 20, and it is building a WarShip that would normally cost 100 Resources, the cost would be 20% less, or 80 Resources.

--
Computer Brain Script Functions

The following function extensions can be used when creating Computer Brain scripts.  Remember, the Brain script executes every 10 Impulses.

General Purpose Functions


Version( Version: float )
Use this function to specify what version this script was intended for.  SV4 GALAXIAE will not accept a script that was written for a higher version number.

Random( From: integer, To: integer ): integer
Returns a random number between From and To.

GetStarSystemCount( void ): integer
Returns the number of StarSystems.  Brains access StarSystems by an index number that ranges from 0 to GetStarSystemCount – 1.

GetStarShipCount( void ): integer
Returns the number of StarShips that the Brain can currently see.  Brains access StarShips by an index number that ranges from 0 to GetStarShipCount – 1;

GetCurrentPlayer( void ): integer
Returns the Player number that this Brain represents.  The range is 0-9.

StarSystem Information Functions

GetStarSystemX( integer ): integer
Returns the X position of the specified StarSystem.

GetStarSystemY( integer ): integer
Returns the Y position of the specified StarSystem.

GetStarSystemOwner( integer ): integer
Returns the Owner of the specified StarSystem (Player 0-9) or –1 if it is independent.

GetStarSystemValue( integer ): integer
Returns the Value of the specified StarSystem.

GetStarSystemShields( integer ): integer
Returns the Shields of the specified StarSystem.

GetStarSystemScanners( integer ): integer
Returns the Scanners of the specified StarSystem.

GetStarSystemResources( integer ): integer
Returns the Resources of the specified StarSystem.

IsStarSystemVisible( integer ): boolean
Returns whether or not the specified StarSystem is visible to the Brain.  StarSystems that are not visible will return 0 for all of the information functions mentioned above, except for the position functions, and GetStarSystemOwner, which will return –1.

IsStarSystemCapital( integer ): boolean
Returns whether or not the StarSystem is a Capital.

StarSystem Order Functions

BuildShields( integer, Number: integer )
Builds the specified number of Shields at the specified StarSystem, Resources permitting.

BuildScanners( integer, Number: integer )
Builds the specified number of Scanners at the specified StarSystem, Resources permitting.

BuildStarShip( integer, ShipType: integer, Engines: integer, AdditionalSystem: integer, Cloaked: boolean )

Builds the specified type of StarShip at the specified StarSystem, Resources permitting.  Use the following codes for StarShip types:
0-WarShip  1-ScanShip  2-Drone   3-Emine
4-SpyShip  5-Freighter  6-InkSpot  7-CloakDetector
8-Tug   9-HijackShip  10-ShieldGenerator 11-CommandShip
12-DoppleShip  13-RepairShip  14-DoomMissile  15-NukeMissile
16-MineSweeper 17-GravShip  18-StarTillery  19-TechShip
20-JumpGateShip 21-BattleStation

StarShip Information Functions

GetStarShipX( integer ): integer

Returns the X position of the specified StarShip.

GetStarShipY( integer ): integer

Returns the Y position of the specified StarShip.

GetStarShipCode( integer ): string

Returns the unique 3 letter code of the specified StarShip.  You can use this code in the Brain Data functions to track StarShip-specific information.

GetStarShipOwner( integer ): integer

Returns the Owner of the specified StarShip (Player 0-9).

GetStarShipType( integer ): integer

Returns the StarShip type of the specified StarShip.  See the BuildStarShip function above for a listing of StarShip types.

GetStarShipEngines( integer ): integer

Returns the number of Engines of the specified StarShip.

GetStarShipValue( integer ): integer

Returns the value of the specified StarShip’s Additional System (Weapons, Scanners, etc.), if present.

GetStarShipCloaked( integer ): boolean

Returns whether or not the specified StarShip is cloaked.

IsStarShipKnown( integer ): boolean

Returns whether or not the Brain “knows” the StarShip type and details of the specified StarShip.  If the location only is knows, the values of the other information functions will return 0.

IsStarShipTugging( integer ): boolean

Returns whether or not the specified StarShip is a Tug and is currently tugging another StarShip.

IsStarShipDragging( integer ): boolean

Returns whether or not the specified StarShip is a GravShip and is currently dragging a StarSystem.

IsStarShipPulsing( integer ): boolean

Returns whether or not the specified StarShip is a CloakDetector, and is currently pulsing (indicating that cloaked StarShips are within its Detector Range).

StarShip Order Functions

OrderMove( integer, X: integer, Y: integer )

Gives the specified StarShip an order to Move to the specified location.

OrderTargetStarShip( integer, TargetIndex: integer )

Gives the specified StarShip an order to Target the StarSystem specified in TargetIndex.

OrderTargetStarSystem( integer, TargetIndex: integer )

Gives the specified StarShip an order to Target the StarSystem specified in TargetIndex.

OrderDefendStarShip( integer, TargetIndex: integer )

Gives the specified StarShip an order to Defend the StarSystem specified in TargetIndex.

OrderDefendStarSystem( integer, TargetIndex: integer )

Gives the specified StarShip an order to Defend the StarSystem specified in TargetIndex.

OrderAttackAdjacent( integer, Value: boolean )

Controls whether or not the StarShip attacks adjacent enemy StarShips.

OrderEscort( integer, TargetIndex: integer )

Gives the specified StarShip an order to Escort the StarSystem specified in TargetIndex.

OrderTransport( integer, FromIndex: integer, ToIndex: integer )

Gives the specified Freighter an order to transport Resources between the two specified StarSystems.

OrderTug( integer, TargetIndex: integer )

Gives the specified Tug an order to Tug the StarSystem specified in TargetIndex.

OrderRelease( integer )

Gives the specified StarShip an order to Release the currently tugged StarShip (for Tugs) or dragged StarSystem (for GravShips).

OrderDrag( integer, TargetIndex: integer )

Gives the specified GravShip an order to Drag the StarSystem specified in TargetIndex.

OrderCreateGate( integer )

Gives the specified JumpGateShip an order to create a JumpGate at its current location.

OrderGenerateShields( integer, TargetIndex: integer )

Gives the specified ShieldGenerator an order to generate Shields at the StarSystem specified in TargetIndex.

OrderRepair( integer, TargetIndex: integer )

Gives the specified RepairShip an order to Repair the StarShip specified in TargetIndex.

Brain Information Functions

You can use these functions to store persistent data between executions of the Brain scripts.  Use this feature if you need to keep track of information relating to individual StarSystems or StarShips.  Make sure each of the “variables” you are creating has a unique DataName.

GetBrainData( DataName: string ): string

Retrieves the persistent data content of a data item named DataName.

SetBrainData( DataName: string, Value: string )

Stores the specified Value into a persistent data item named DataName.

Utility Functions

FindClosestStarSystem( X: integer, Y: integer, MaxDistance: integer, Friendly: boolean, IncludeNonVisible: boolean ): integer

Returns the closest StarSystem to X, Y that meets the specifications.  MaxDistance refers to the maximum distance to allow.  Friendly determines whether to return friendly or enemy StarSystems.  IncludeNonVisible determines whether to include StarSystems that are not yet seen.  If no StarSystems meet the criteria, the function returns –1.

FindClosestStarShip( X: integer, Y: integer, MaxDistance: integer, Friendly: boolean ): integer

Returns the closest StarShip to X, Y that meets the specifications.  MaxDistance refers to the maximum distance to allow.  Friendly determines whether to return friendly or enemy StarShips.  If no StarShips meet the criteria, the function returns –1.

Distance( X1: integer, Y1: integer, X2: integer, Y2: integer ): float

Returns the distance between the two specified points.

FindStarShipCode( Code: string ): integer

Returns the index of the StarShip with the specified Code, if any.  If no StarShip is found, the function returns –1.

--

 

To be continued and optimized ...

 

 

 

 




STUELKEN, www.stuelken.com