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:
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
|
race name |
|
Drive tech |
|
Weapons tech |
|
Shield tech |
|
Cargo tech |
|
Total POP |
|
Total IND |
|
Number of planets |
|
Status |
|
Votes (G+), in other versions POP/1000 |
|
Simple rating |
|
Complex rating |
|
Team, for G+ Team series games |
|
1, if at least one planet of the race is visible, otherwise 0 |
|
1, if at least one ship of the race is visible, otherwise 0 |
|
Change in the Drive tech during the last turn |
|
Change in the Weapons tech during the last turn |
|
Change in the Shields tech during the last turn |
|
Change in the Cargo tech during the last turn |
|
Change in the POP during the last turn |
|
Change in the IND during the last turn |
|
Change in the number of planets during the last turn |
|
Change in the votes during the last turn |
Planets list
|
Number (G+, NG: O GPLUS) |
|
Name |
|
Size |
|
POP |
|
IND |
|
RES |
|
Production |
|
CAP |
|
MAT |
|
COL |
|
L = 0.25*POP+0.75*IND |
|
Owner (may be Uninhabited or Unidentified) |
|
Ship weight the planet could produce if it had POP=Size and IND=Size |
|
CAP production |
|
Mass produced in a turn |
|
Size of the battle at he planet, 0 in no battle happened |
|
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. |
|
Total weight of your fleet at the planet |
|
Total weight of allied fleet at the planet |
|
Total weight of enemy fleet at the planet |
|
Distance to another given planet (string parameter) |
Fleet(Race) |
Weight of the Race's fleet at the planet |
|
Team, in G+ Team series games |
Ship list
|
Group number, -1 if the group is not yours |
|
Number of ships in the group |
|
Ship type name |
|
Drv tech |
|
Guns |
|
Weapons tech |
|
Shield tech |
|
Cargo tech |
|
Effective attack |
|
Effective defense |
|
Cargo bay size |
|
Amount of cargo |
|
Cargo type |
|
Destination planet |
|
Source planet |
|
Distance to destination (0 if in orbit) |
|
Ship weight |
|
Fleet name (or "" if none) |
|
ship status |
|
Speed with current cargo load |
|
Empty speed |
|
Speed with full cargo |
|
Drive mass |
|
Weapons mass |
|
Shields mass |
|
Cargo mass |
|
Owner |
|
Bombing of one ship in the group (G+) |
|
1 if a mobile military ship, 0 otherwise |
|
1 if the group is ready to be launched (in orbit, has engines, and the total weight is >2). |
|
Estimated time to arrival |
|
ETA if sent to Planet, -1 if out of range (G+) |
|
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> ::=
for <ident>:= <expression> to <expression> do {<operator>;} endfor
while <expression> do {<operator>;} endwhile
<ident>:=<expression>
<function call>
Macro language functions
|
Distance between two planets |
|
<expression> is evaluated for every line in the list, and the sum of the results is returned |
|
<expression> is evaluated for every line in the list, and the average of the results is returned |
|
Number of lines in a list |
|
Name of the race in the master report |
|
Number to string conversion, number of numbers
(N) and number of decimal points (D) can be specified.
Default is N=10, D=2. |
|
mathematical functions with one real argument |
|
The command is executed and added to the order |
|
First instance of the substring in the string, result is the position in the string or 0 if not found |
|
Quick: Nth symbol in the string |
|
Substring, starting from position P and of length N |
|
String length |
|
Removing a substring, starting from position P and of length N |