Appendice
Global variables
This section is created for fast reference to available external
procedures and global variables. However the second term wasn't explained yet.
Once you read Tier 3 you should be familiar with variables. They act
exactly like variables expect one thing: There are only 5 global registers
given to the object. They are indexed from 0 to 4. There is an exception but
read Cheats section in that case. The global registers have special meaning
and cannot be used as temporary variables. To access them call either:
- PushReg - pushes global register on stack, or
- PopReg - pops global register from stack
For now I know very few of them but they aren't used especially often in the BUILD.EMC.
- Reg 0 - If set to 1 the building has been destroyed.
- Reg 4 - Contains ID of the unit that is attached or zero
Reference for external routines
Below you will find all the info that is needed to use them ie. arguments and the return code,
how they work and where to use them.
- Delay()
- Input: number of ticks where one tick is 1/60 of second in ideal environment.
- Delays the script for some time while no command is executed.
- Reveal()
- Reveals the terrain around structure.
- Explode()
- Shows explode animation. Does not hurt the building.
- Destroy()
- Destroys building. Also stops the script.
- Text()
- Input: text number to use and 3 arguments that replace % entries.
- Shows text. Note that the text must be in TEXT chunk of EMC file (not supported by version 1.0 of emcc).
- PlaySfx()
- Input: sound number to play.
- Plays sound effect. Note that some sound numbers have special meaning.
- SetFrame()
- Input: state number to set.
- Sets state number (aka frame). What is this? Here's a brief answer:
- If set to -1 means buildup frame (displayed when the building is placed).
- If set to 0 means normal frame.
- If set to 1 means f.e. unit is heading to structure.
- If set to 2 means unit is in structure.
- GetFrame()
- Output: state number.
- Gets current state number. Used to obtain the state of the structure.
- RefineSpice()
- Output: returns TRUE if the harvester is empty.
- Refines 1% of cargo. Use this in loop to obtain whole cargo.
- GetTarget()
- Input: range of the turret. to calc this argument multiply 256 by number of cells.
- Output: ID of the unit found or zero.
- Seeks target for the turret in specified range.
- GetAngle()
- Input: ID of the unit.
- Output: angle between turret and the target.
- Returns the angle between turret and the target.
- SetAngle()
- Input: destiny angle.
- Output: returns TRUE if the target is aimed.
- Rotates the turret a bit. Use this in loop with short delays (f.e. 60 ticks) to aim the target.
- ShootTarget()
- Input: ID of the unit to shoot, obtained by GetTarget().
- Shoots at target. The turret should already aim the target.
- Attach()
- Input: Type of the unit, 0 for Carryall.
- Outpur: ID of the unit.
- Finds the unit of that type. If the structure is surrounded
and there is no unit of that type, new one is created.
Note: you must store the return code in global register 4, to actually
attach this unit. Attached unit will head to the structure.
- Disattach()
- Input: ID of the unit.
- As opposite to above it disattaches the unit. Call this when attached
unit is no longer needed.
- Deploy()
- Deploys unit from structure (factory, repair facility or refinery).
- VerifyAtch()
- Output: ID of attached unit that is heading to structure.
- This can be used to obtain ID of attached unit and also to remove obsolete attachments.
Note: you can obtain ID of attached unit also by accessing global register 4.
The best method to get to know how to use these procedures is to check the original script.
For example to get units back on battlefield from Repair Facility without need to surround the structure
you can copy part of script from refinery (Harvesters are always picked-up first). The main issue
is to replace Deploy() and Attach() call order.
Cheats
Yes. EMC has some features that are illegal to use, but very powerful.
Note that it's risky to use them because it will affect private data that are used
elsewhere within the game. All cheats are based on fact that the place when global registers are stored
is located close to other data related to the object and the register position is obtained on offset.
So you can give some special values to Push/PopReg in order to access them. They are:
- -15 - index of object
- -14 - type of object
- -13 - flags of object
- -11 - house of object (higher byte)
- -10 - Y position in pixels
- -9 - X position in pixels
- -8 - hitpoints (dmg)