From SEWiki
Jump to: navigation, search

The templatizer is a utility written by Ed Kolis designed to make the creation of families of components, facilities, etc. easier by means of mathematical formulas, as will be done in SE5. Versions 1 through 4 of the templatizer used a text format similar to that of SE4's data files and required execution of a conversion program to turn the "template" files (containing the formulas defining the components, etc.) into game data files; another version, Templatizer-XSLT, used XML for input and XSLT to transform the template files into game data files, allowing generation to be done using a standard web browser, but it has only basic functionality.

The latest version of the templatizer uses the original text format, but with scripting done in Python, with the full power of the language at your fingertips!

Here is an example component template (from the Low Tech Mod) to illustrate how the templatizer works (the parts after the // marks are not part of the template; they're commentary added for illustration purposes - the templatizer currently does not currently accept comments other than in the Python code sections!):

{{{ // this marks the beginning of "global code", which stays in scope until the end of the file
# global "tech level" shortcut // this is a Python comment (it begins with #)
def l(): // this is how you define a function in Python
	return levels[0] // this is how you return a value in Python - note that levels is a built-in templatizer array to get all the "tech-grid" levels of the current iteration of a record

# miniaturization/advancement
def linear(initial, advance_ratio): // this function takes some parameters
	return int(round(initial + (advance_ratio * (l() - 1) * initial))) // doing some calculations

# roman numeral shortcut
def r():
	return roman(l()) // roman is a function built into the templatizer, useful for generating those roman numerals!
}}} // this ends the global code section
{{ // this marks the beginning of a "local code" section, which expires at the end of the record (at the first blank line)
minlevels = [1] // minlevels and maxlevels are built into the templatizer; they specify the min and max levels of all "tech grid areas"
maxlevels = [3]	// you can have as many tech grid areas as you like (separated by commas, e.g. maxlevels = [5, 10, 3])
}} // this ends the local code section
Name                  := Ice Native Gas Colony Module {r()} // here begins our record proper; the {} specify that the templatizer is to run some code here and insert the return value, in this case a roman numeral
Description           := Materials needed to start a colony inside a gas giant. // this is a plain old field, no calculations take place here
Pic Num               := 108
Tonnage Space Taken   := {linear(800, -0.05)} // calling the function we defined above to miniaturize the colony module
Tonnage Structure     := 800
Cost Minerals         := {linear(10000, -0.05)} // calling the function we defined above to reduce the cost of the colony module
Cost Organics         := {linear(8000, -0.025)} // this colony module's organics cost goes down slower than its minerals cost
Cost Radioactives     := {linear(6000, -0.075)} // but its rads cost goes down faster
Vehicle Type          := Ship
Supply Amount Used    := 0
Restrictions          := One Per Vehicle
General Group         := Colonizing
Family                := 2003
Roman Numeral         := {l()} // a common mistake is to use the roman function here - remember, that generates the actual roman numeral but what we want is the number
Custom Group          := 0
Number of Tech Req    := 1
Tech Area Req 1       := Gas Giant Colonization - Ice Natives
Tech Level Req 1      := {l()} // for the tech gridding
Number of Abilities   := 2
Ability 1 Type        := Colonize Planet - Gas
Ability 1 Descr       := Can colonize a gas giant.
Ability 1 Val 1       :=
Ability 1 Val 2       :=
Ability 2 Type        := Cargo Storage
Ability 2 Descr       := Provides {linear(200, 0.5)}kT worth of cargo space. // calling our function again, this time to increase the amount of storage space provided with each tech advance
Ability 2 Val 1       := {linear(200, 0.5)} // gotta remember to actually specify the ability value too!
Ability 2 Val 2       := 0
Weapon Type           := None