Let us imagine we want to create a simple role playing game. What can Chomik do for us?
# here we define the enumerations
type race={human, elf, dwarf}, class={fighter, cleric, wizard},
feature={strength, dexterity, intelligence};
expand(1);
# we create a random number stream to generate features (from 1 to 20)
<create new input random number stream "integer" 1 20>;
let my feature stream index = <the created stream index>;
# now create a stream to generate random races:
<create new input random enum stream "race">;
let my race stream index = <the created stream index>;
# now create a stream to generate random classes:
<create new input random enum stream "class">;
let my class stream index = <the created stream index>;
let amount of persons = value integer 0;
let generate for the current person a new feature (FEATURE:feature)=value code
{
let current feature = value feature [(FEATURE:feature)];
let the read from stream source stream index = <my feature stream index>;
<read from stream "integer">;
let my person <current person id> <current feature>=<the read from stream result "integer">;
};
let generate a new random person=value code
{
# we increase the amount of persons
<add "integer" <amount of persons> 1>;
let amount of persons = <the add result "integer">;
# we assign the current person id
let current person id = <amount of persons>;
# get a new race from the random "race" stream
let the read from stream source stream index = <my race stream index>;
<read from stream "race">;
let my person <current person id> race = <the read from stream result "race">;
# get a new class from the random "class" stream
let the read from stream source stream index = <my class stream index>;
<read from stream "class">;
let my person <current person id> class = <the read from stream result "class">;
<generate for the current person a new feature (FEATURE:feature)>;
};
let generate persons (COUNTER:integer)=value code
{
<generate a new random person>;
};
<generate persons (COUNTER:1..10)>; # here we generate 10 persons
let report current person (FEATURE:feature)=value code
{
let current feature = value feature [(FEATURE:feature)];
<print <current feature> "=" <my person <current person id> <current feature>>>;
};
let report persons (ID:integer)=value code
{
let current person id = value integer [(ID:integer)];
<print "Person" <current person id> "-"
<my person <current person id> race> <my person <current person id> class>>;
<report current person (FEATURE:feature)>;
<print>;
};
<report persons (ID:1..<amount of persons>)>;
The output wil be random, but it could look for example as follows:
Person 1 - dwarf fighter strength = 7 dexterity = 17 intelligence = 11 Person 2 - human wizard strength = 20 dexterity = 17 intelligence = 1 Person 3 - elf wizard strength = 9 dexterity = 19 intelligence = 6 Person 4 - dwarf cleric strength = 5 dexterity = 5 intelligence = 7 Person 5 - dwarf wizard strength = 14 dexterity = 12 intelligence = 1 Person 6 - human cleric strength = 8 dexterity = 14 intelligence = 16 Person 7 - elf wizard strength = 7 dexterity = 19 intelligence = 7 Person 8 - dwarf wizard strength = 8 dexterity = 5 intelligence = 8 Person 9 - elf fighter strength = 19 dexterity = 4 intelligence = 20 Person 10 - dwarf fighter strength = 20 dexterity = 9 intelligence = 5
What if we want some heroes to have racial/class bonuses to some features?
# here we define the enumerations
type race={human, elf, dwarf}, class={fighter, cleric, wizard},
feature={strength, dexterity, intelligence};
expand(1);
# here we initialize the race/class bonus default values
let race bonus for (R:race) to (F:feature)=value integer 0;
let class bonus for (C:class) to (F:feature)=value integer 0;
# and here are the actual, game specific bonuses:
let race bonus for dwarf to strength = value integer 2;
let class bonus for wizard to intelligence = value integer 3;
let class bonus for fighter to strength = value integer 2;
#### ....
let generate for the current person a new feature (FEATURE:feature)=value code
{
let current feature = value feature [(FEATURE:feature)];
let the read from stream source stream index = <my feature stream index>;
<read from stream "integer">;
# now we add the bonuses
<add "integer" <the read from stream result "integer"> <class bonus for <my person <current person id> class> to <current feature>>>;
<add "integer" <the add result "integer"> <race bonus for <my person <current person id> race> to <current feature>>>;
let my person <current person id> <current feature>=<the add result "integer">;
};
We could even add bonuses that involve both race and class.