Macro language

GComm has a built-in expression and macros analyzer. It can be used for filtering, to query the lists,and to write macro functions.
Note that most of the GV query/filter language is supported.

In the current version, 3 lists are available:

The elements of the lists can be referred to by a prefix. For example: Race.Wpn or ShipGroup.Weight.

To write filters and queries, one needs to specify an expression. Expressions consist of operands and operations.

Operands are string or scalar constants, list fields and macro function calls.

The operations may be unary or binary.

There are 2 unary operations: unary minus,  and boolean not. All others (+,-,*,/, and, or, >, <, >=, <=, <>, =, ==, &, |) are binary. Operation == is used for register-independent string comparisons..

The un-naming operation '^' deserves a special mention: this operation allows to refer to a necessary planet. The plant name is the left operand, and the right one is the arbitrary reference to the planet's fields. So, to find the size of the planet #1 one can write '#1'^.size , 'MyHW'^size or var1^.size, where the value of var1 is equal to the name or number of the planet. In the ship list, the fields dest and from can also be operands here. For example, to filter our the ships that are on the same planet with the ships of a given race, one may use a filter  dest^.fleet('RaceName')>0.

In addition to the un-naming operation, there is an additional possibility to refer not only to a planet, but also to a race or a ship. To do so, the macro language has operators of choosing a record from a list WithRace, WithPlanet, WithGroup, that have the following syntax:

WithRace <expression> [ as 'name'] do {<operator>;} EndWith;

When this operator is executed, the value of the <expression> is searched in the list, and the result is a new list that consists of 1 record. The race should be addressed by name, the ship by number. The operators are executed on the new list, and all the fields will refer to the fields of the new list. Name - an optional parameter , it will name the new list and one will be able to refer to the list by that name afterwards.

Example:

macro GetDrive;
begin
  WithRace me  as 'mytable' do
     result:=mytable.drv;
  EndWith;
end;

It returns the drive tech of the main race.

If one wants to form a new list with several records, one should use  the same operators WithRaces, WithPlanets, WithGroups. The syntax is the same, and the expression is a filter that will be used to create the new list.

Example (a slower GetDrive analog):

macro GetDrive;
begin
  WithRaces 'name="'+me+'"' do do
     result:=drv;
  EndWith;
end;

String constants are given in "-s or '-s, it is possible to enclose one into the others. All comparison operations are register-sensitive, i.e. 'World'<>'WorLD'.

Example: “Normal 'string' constant”

The numeric values can be given in the exponential or fixed-point form:

Example: 1e-3, 0.001

The name of a field in any list is the same as its name on the display. It is not register-sensitive.

Reserved constants:

#NL – new line

Additional fields:

Race list fields
 
Name
race name
Drv
Drive tech
Wpn
Weapons tech
Shld
Shield tech
Crg
Cargo tech
Pop
Total POP
Ind
Total IND
#
Number of planets
State
Status
Votes
Votes (G+), in other versions POP/1000
Rating
Simple rating
Level
Complex rating
Team
Team, for G+ Team series games 
VisiblePlanets
1, if at least one planet of the race is visible, otherwise 0
VisibleShips
1, if at least one ship of the race is visible, otherwise 0
DDrv
Change in the Drive tech during the last turn
DWpn
Change in the Weapons tech during the last turn
DShld
Change in the Shields tech during the last turn
DCrg
Change in the Cargo tech during the last turn
DPop
Change in the POP during the last turn
DInd
Change in the IND during the last turn
D#
Change in the number of planets during the last turn
DVotes
Change in the votes during the last turn

Planets list
 
Num
Number (G+, NG: O GPLUS)
Name
Name
Size
Size
Pop
POP
Ind
IND
Res
RES
Production
Production
$
CAP
Mat
MAT
Col
COL
L
L = 0.25*POP+0.75*IND
Race
Owner (may be Uninhabited or Unidentified)
Qlty
Ship weight the planet could produce if it had POP=Size and IND=Size
OutCap
CAP production 
OutWgt
Mass produced in a turn
Battle
Size of the battle at he planet, 0 in no battle happened
BestETA
Time until the planet is observed. 0 if there are your ships at the planets, and -1 if none of your ships are en route to the planet.
YourFleet
Total weight of your fleet at the planet
FriendFleet
Total weight of allied fleet at the planet
AlienFleet
Total weight of enemy fleet at the planet
DestTo(Pl)
Distance to another given planet (string parameter)
Ships(Race),

Fleet(Race)

Weight of the Race's fleet at the planet
Team
Team, in G+ Team series games

Ship list
 
Grp
Group number, -1 if the group is not yours
#
Number of ships in the group
Name
Ship type name
Drv
Drv tech
Gun
Guns
Wpn
Weapons tech
Shld
Shield tech
Crg
Cargo tech
Attack
Effective attack
Defence
Effective defense
Cargo
Cargo bay size
Q
Amount of cargo
Typ
Cargo type 
Dest
Destination planet
From
Source planet
R
Distance to destination (0 if in orbit)
Weight
Ship weight
Fleet
Fleet name (or "" if none)
State
ship status
Speed
Speed with current cargo load
ESpeed
Empty speed 
CSpeed
Speed with full cargo
D
Drive mass
W
Weapons mass
S
Shields mass
C
Cargo mass
Race
Owner
Bomb
Bombing of one ship in the group (G+)
WarShip
1 if a mobile military ship, 0 otherwise
Waitl
1 if the group is ready to be launched (in orbit, has engines, and the total weight is >2).
ETA
Estimated time to arrival
CanSendTo(Planet)
ETA if sent to Planet, -1 if out of range (G+)
Team
Team, G+ team series

Also, every list has a Count field and a function Current(NewPos). Count is the number of records in the list, numeration is 0 to Count. Current allows to jump to a new record.
For example, sum(#*Weight) may be rewritten as follows:

macro mysum;
var
  summa, i;
begin
  summa:=0;
  for i:=0 to shipgroup.count do
     shipgroup.current(i);
     summa:=summa+shipgroup.#*shipgroup.Weight;
  endfor;
  result:=summa;
end;

it can be run in any query window since it does not depend on the current list.
 
 

Macro language syntax

The descriptions of all the macros should be written into gcomm.mac file, in hte same directory with gcomm.exe.
 

Macro definition:

Macro <ident>[(<ident>{,<ident>})];

Var <ident>{,<ident>};

Begin

{<operator>;}

End;

Where in VAR part one lists all the variables. The variable type is determined during execution and can be dynamically changed.

Also, there is a reserved variable result, that determines the function return value.

Operators' syntax:

<operator> ::=

if <expression> then {<operator>;} [else {<operator>;}] endif

for <ident>:= <expression> to <expression> do {<operator>;} endfor

while <expression> do {<operator>;} endwhile

<ident>:=<expression>

<function call>
 
 

One can use recursion as well.

Macro language functions
 
PlanetDest("Planet1", "Planet2")
Distance between two planets
sum(<expression>)
<expression> is evaluated for every line in the list, and the sum of the results is returned
avg(<expression
>)
<expression> is evaluated for every line in the list, and the average of the results is returned
count
Number of lines in a list
me
Name of the race in the master report
FloatToStr(<digital>[,<N>,<D>])
Number to string conversion, number of numbers (N) and number of decimal points (D) can be specified. 
Default is N=10, D=2.
sqrt, sqr, sin, cos, ln, exp, round, trunc
mathematical functions with one real argument
AddCommand("command")
The command is executed and added to the order
StrPos(<substring>,<string>)
First instance of the substring in the string, result is the position in the string or 0 if not found
StrChar(<string>, N)
Quick: Nth symbol in the string
StrCopy(<string>, P,N)
Substring, starting from position P and of length N
StrLen(<string>)
String length
StrCut(<string>, P,N)
Removing a substring, starting from position P and of length N

 

back