DO/CTL/OpCodes

From Dark Omen Wiki

< DO | CTL
Revision as of 12:18, 5 May 2012 by Ghabry (Talk | contribs)
Jump to: navigation, search

Contents

init_unit (00)

Argument Explanation
unk unknown purpose

This command initializes some data structures of the unit to it's default values. It should be used as the first command called by a unit script.

wait_for_deploy (01)

Blocks the execution of the units script until the deployment phase is finished.

In the deployment phase it sets bit 31 of unit flag 1. At the end of the phase it clears the bit.

reset_call_stack (02)

Resets the units stack. Don't call this when you have to return from a function or are in a loop.

restore_ip (03)

Restores the state saved with save_ip (execution continues after the save_ip call). All events get marked as handled so unhandled events are lost.

save_ip (04)

Stores the current state of the instruction pointer (current function, position in function, number of free stack slots). Note that the stack itself is not saved!

do (05)

Begins a do-loop (pushes position of next opcode on the stack). This loop is always executed at least once.

always (06)

Usually used at the end of a do-loop. Pops from the stack and continues script execution at this position (this is usually the command following the do-statement).

while (07)

Usually used at the end of a do-loop. Pops from the stack and checks the conditional flag:

Condition Result
true Continue execution at stack position
false Continue execution with command after while

whilenot (08)

Usually used at the end of a do-loop. Pops from the stack and checks the conditional flag:

Condition Result
true Continue execution with command after while_not
false Continue execution at stack position

for (09)

Begins a for-loop.

Argument Explanation
num_loops How often the loop shall be executed.

Pushes two elements on the stack: The position of the next opcode and how often loop shall be executed.

next (0A)

Usually used at the end of a for-loop.

Pops the loop counter from the stack and decrements it by one. If it is higher then 0 it's pushed again and the execution continues after the for-command (2nd stack element). Otherwise the 2nd element is popped too and execution continues after the next-command.

goto (0B)

Continues execution at the beginning of a function.

Argument Explanation
func Number of the function to execute

Note that the call stack is not altered. So you shouldn't call this while you are in a loop because it leaves garbage on the stack (call reset_call_stack to clear the stack).

set_return_func (0C)

Overwrites the function return_from_event_handler returns to by setting the "overwrite return"-flag in the control flag but only when the "restart funtion"-bit was not set.

Argument Explanation
func Number of the function to execute

set_return_func_iftrue (0D)

Overwrites the function return_from_event_handler returns to by setting the "overwrite return"-flag in the control flag but only when the "restart funtion"-flag was not set and the conditional flag indicated true.

Argument Explanation
func Number of the function to execute

set_return_func_with_restart (0E)

Overwrites the function return_from_event_handler returns to by setting the "overwrite return"-flag and the "restart function"-flag.

Argument Explanation
func Number of the function to execute

set_return_func_with_restart_iftrue (0F)

Overwrites the function return_from_event_handler returns to by setting the "overwrite return"-flag and the "restart function"-flag if the conditional flag was true.

Argument Explanation
func Number of the function to execute

set_return_func_iffalse (10)

Overwrites the function return_from_event_handler returns to by setting the "overwrite return"-flag in the control flag but only when the "restart funtion"-flag was not set and the conditional flag indicated false.

Argument Explanation
func Number of the function to execute

call (11)

Calls a function (use with return).

Argument Explanation
func Number of the function to execute

Pushes the position of the next opcode and the current function on the stack.

return (12)

Continues execution directly after the call-command (Pops two elements from the stack (function and position)).

Don't call return while you are in a loop because the stack top contains the wrong element!

This function can also be used to return from an event handler (this command ignores the "overwrite return"-flag)

return_from_event_handler (13)

Like return but checks the "overwrite return" and "restart function"-flag of the CTL control flag:

Condition Result
"overwrite return" not set Behaves like a normal return.
"overwrite return" set Returns to the function specified with one of the set_return_function-commands. If the return function is the same as the one on the stack it will behave like a normal return instead.
"overwrite return" and "restart function" set Always returns to the function specified with one of the set_return_function-commands (the stack gets cleaned but the content is ignored).

Don't call return_from_event_handler while you are in a loop because the stack top contains the wrong element!

sleep (15)

Pauses the script execution (script of next unit gets executed). Next time the execution continues with the command after sleep.

sleep_iftrue (16)

Pauses the script execution based on the conditional flag:

Condition Result
true Script of next unit is executed. Next time the execution continues with the command after sleep.
false No sleep. Execution continues with the command after sleep_if_true

skip_iftrue (17)

Skips instructions based on the state of the conditional flag.

Argument Explanation
num_skip How many commands to skip. This value must be 1 + number of arguments. E.g. if you want to skip a function that takes two arguments num_skip must be 3.
Condition Result
true num_skip commands are skipped
false Execution continues with the next command

set_timer (18)

Sets a timer for the unit (or overwrites the old). The timer decrements by 1 when the regiments script starts execution again.

Argument Explanation
timer New value for the timer

test_waiting_for_timer (19)

Sets the conditional flag to true if the timer is not 0.

wait_for_timer (1A)

Pauses script execution until the timer is not 0.

set_x_i (1B)

Sets the value of the unknown local register x (= purpose is unknown).

Argument Explanation
value Sets x to value.

add_x_i (1C)

Adds a value to the unknown local register x (= purpose is unknown).

Argument Explanation
value Adds value to x.

test_x_eq_0 (1D)

Sets the conditional flag to true if the unknown local register x is 0.

set_unit_r_i (1E)

Sets a local register to a value.

Argument Explanation
register Local register to write
value Sets register to value

Every unit has 8 registers, so the register parameter should be from 1 to 8. Other values will overwrite other memory!

add_unit_r_i (1F)

Adds a value to a local registers value.

Argument Explanation
register Local register to write
value value added to value in register

Every unit has 8 registers, so the register parameter should be from 1 to 8. Other values will overwrite other memory!

test_unit_r_eq_i (20)

Sets the conditional flag to true if the value in a units register equals a value.

Argument Explanation
register Register to check
value Value the registers value is compared against

Use register -278 to check against the unit Id.

test_unit_r_eq_r (21)

Sets the conditional flag to true if two local registers contain the same value.

Argument Explanation
register1 First register
register2 Second register

Use register -278 to check against the unit Id.

set_unit_r_random1to10 (22)

Assigns a "random" value (the value changes every second) in a range form 1 to 10 to a local register.

Argument Explanation
register Register to write

Every unit has 8 registers, so the register parameter should range from 1 to 8. Other values will overwrite other memory!

set_global_r_i (23)

Assigns a value to a global register.

Argument Explanation
register Global register to write
value Value to assign to the register

There are 8 registers, so the register parameter should range from 1 to 8. Other values will overwrite other memory!

add_global_r_i (24)

Adds a value to the value in a global register.

Argument Explanation
register Global register to write
value Value to add to the registers value

There are 8 registers, so the register parameter should range from 1 to 8. Other values will overwrite other memory!

test_global_r_eq_i (25)

Sets the conditional flag to true if the value in a global register equals a value.

Argument Explanation
register Global register to test
value Value to test against

move_to_node (28)

The side effects of this function are unknown.

The regiment will move to the node specified.

Argument Explanation
node Node the unit will move to

The node can be retrieved by looking at the "Game Objects"-Chunk of the BTB file by counting the entries downwards (starting from 0).

retreat_to_node (29)

The side effects of this function are unknown.

When the unit is retreating it will move the the node specified.

Argument Explanation
node Node the unit will move to

The node can be retrieved by looking at the "Game Objects"-Chunk of the BTB file by counting the entries downwards (starting from 0).

patrol_to_waypoint (2A)

ToDo.

block_movement (2B)

ToDo. Pauses script execution if some unknown condition is true.

wait_unit_flag1_clear (2C)

Pauses the script execution until all of the bits specified in the bitmask are not set in unit flag 1.

Argument Explanation
bitmask The bitmask unit flag 1 is checked against.

wait_unit_flag1_set (2D)

Pauses the script execution if none of the bits specified in the bitmask is set in unit flag 1.

Argument Explanation
bitmask The bitmask unit flag 1 is checked against.

test_unit_flag1 (2E)

Sets the conditional flag to "true" if any of the bits specified in the bitmask is set in unit flag 1.

Argument Explanation
bitmask The bitmask unit flag 1 is checked against.

set_unit_flag1 (2F)

Sets the bits specified in the bitmask in unit flag 1 (other bits are not changed).

Argument Explanation
bitmask The bitmask that will be used to set bits in unit flag 1.

clear_unit_flag1 (30)

Clears the bits specified in the bitmask in unit flag 1 (other bits are not changed).

Argument Explanation
bitmask The bitmask that will be used to clear bits in unit flag 1.

wait_unit_flag2_clear (31)

Pauses the script execution until all of the bits specified in the bitmask are not set in unit flag 2.

Argument Explanation
bitmask The bitmask unit flag 2 is checked against.

wait_unit_flag1_set (32)

Pauses the script execution if none of the bits specified in the bitmask is set in unit flag 2.

Argument Explanation
bitmask The bitmask unit flag 2 is checked against.

test_unit_flag2 (33)

Sets the conditional flag to "true" if any of the bits specified in the bitmask is set in unit flag 2.

Argument Explanation
bitmask The bitmask unit flag 2 is checked against.

set_unit_flag2 (34)

Sets the bits specified in the bitmask in unit flag 2 (other bits are not changed).

Argument Explanation
bitmask The bitmask that will be used to set bits in unit flag 2.

clear_unit_flag2 (35)

Clears the bits specified in the bitmask in unit flag 2 (other bits are not changed).

Argument Explanation
bitmask The bitmask that will be used to clear bits in unit flag 2.

wait_unit_flag3_clear (36)

Pauses the script execution until all of the bits specified in the bitmask are not set in unit flag 3.

Argument Explanation
bitmask The bitmask unit flag 3 is checked against.

wait_unit_flag3_set (37)

Pauses the script execution if none of the bits specified in the bitmask is set in unit flag 3.

Argument Explanation
bitmask The bitmask unit flag 3 is checked against.

test_unit_flag3 (38)

Sets the conditional flag to "true" if any of the bits specified in the bitmask is set in unit flag 3.

Argument Explanation
bitmask The bitmask unit flag 3 is checked against.

set_ctrl_flag (39)

Sets the bits specified in the bitmask in the CTL control flag (other bits are not changed).

Argument Explanation
bitmask The bitmask that will be used to set bits in the CTL control flag.

clear_ctrl_flag (3A)

Clears the bits specified in the bitmask in the CTL control flag (other bits are not changed).

Argument Explanation
bitmask The bitmask that will be used to clear bits in the CTL control flag.

test_ctrl_flag (3B)

Sets the conditional flag to "true" if any of the bits specified in the bitmask is set in the CTL control flag

Argument Explanation
bitmask The bitmask the CTL control flag is checked against.

set_event_handler (3D)

Assigns a new event handler to the unit. An old event handler will be overwritten. If the game is in deployment phase all events will be marked as handled.

Argument Explanation
func The id of the function that will become the event handler.

set_label (3F)

Assigns a label (identifier) to the unit which can be used by other commands to reference the unit (an old label will be overwritten).

Argument Explanation
label Unique label assigned to the unit.

If another unit already has the same label this call will silently fail!

store_unit_by_label (40)

Saves a reference to a unit. The reference can be used with send_event_to_stored_unit.

Argument Explanation
label Label of the regiment whose reference will be stored for later use.

Only active units are checked. If no unit has the label this call will remove the stored reference.

test_label_exists (41)

Sets the conditional flag to true if any unit has the label.

Argument Explanation
label Label to check.

Only active units are checked.

send_event_to_self_if_label_exists (42)

Sets the conditional flag to true if any unit has the label.

Argument Explanation
event Event to generate.
label Label to check.

Additionally it adds a message if the label was found:

Argument Explanation
target Caller of the command
event Passed as an argument
source (arg1) Id of the unit with the label

Only active units are checked.

nop_4c (4C)

Does nothing. It's possible that some other function skips to this instruction.

goto_iftrue (4E)

Continues execution at the beginning of a function if the conditional flag is true.

Argument Explanation
func Number of the function to execute
Condition Result
true Script execution continues at the start of the function passed as an argument.
false Script execution continues with the command following goto.

Note that the call stack is not altered. So you shouldn't call this while you are in a loop because it leaves garbage on the stack (call reset_call_stack to clear the stack).

move_rand_in_radius (52)

The side effects of this function are unknown.

The regiments units will randomly move around at a node.

Argument Explanation
node Node referenced by value in <11>

init_teleport (53)

The side effects of this function are unknown.

The unit will pass through wall to the node.

Argument Explanation
node Node the unit will move to

The node can be retrieved by looking at the "Game Objects"-Chunk of the BTB file by counting the entries downwards (starting from 0).

All teleport stuff is unknown, they somehow teleport the regiment to a new location... (often a game object). This function is often used combined with teleport_to, #54 and teleport_to2.

teleport_to (54)

teleport_to2 (55)

charge (5A)

retreat (5C)

hold (65)

send_event_to_self (69)

Send event with id arg to self.

send_event_to_self_iftrue (6A)

send_event_to_self_iffalse (6B)

set_event_id (6D)

Changes id of last retrieved event (with get_event) to arg.

broadcast_event_to_friends (6E)

All friends (same alignment) get a message. Source is the caller.

broadcast_event_to_enemies (6F)

All enemies (different alignment) get a message. Source is the caller.

send_event_to_stored_unit (70)

See store_unit_by_label

teleport_to3 (71)

get_event (72)

test_more_events (73)

on_event (74)

end_event (75)

Checks for next event when arg is 3567, skips to marker otherwise (usually 6844, thats 1ABC. The 1 gets cleared, makes ABC (2748)).

iftrue (76)

iffalse (77)

else (78)

endif (79)

(80)

Generates an enemy sighted event and sends it to the sender of the last event if some unknown condition is met.

test_unit_flag1_and_close_combat (82)

Close combat is already set when the order is given by clicking the enemy unit not when the close combat is really entered. arg: unit flag 1

test_missile_weapon (8D)

If arg1 is -1 return true if there is any leader missile weapon. If arg1 is not -1 return true if leader missile is same as arg1 (use 0 to check for "no leader missile weapon")

nop_90 (90)

nop_91 (91)

nop_92 (92)

test_magic_points_leq_i (93)

Checks if the AI controlled units have: magic points <= i.

add_magic_points (94)

Adds arg magic points to the ai controlled global magic pool.

init_teleport_spell (97)

cast_spell (98)

#98 66, 16384, 1

Necromancer in B4_05 uses this to cast doombolt on the stone.

cast_spell2 (99)

#99 66, 32768, 1: Casts dispell on the caller. Arguments are unknown. Must be called from an event handler

#94 n Adds n magic points to the enemies global magic pool

#93 n Checks if the enemy has at least n magic points

add_spell (9D)

Add spell or magic item.

search_and_attack_enemy (A2)

arg3 is the attribute that should not be set (usually, 4096, thats the steam tank).

search_and_shoot_enemy (AC)

A2 up to AC are all doing similiar stuff. if arg1 != -1 then arg1 is the event (with id arg1) the caller will receive when something was found. About the source I have no idea yet but it could be the id of the unit found.

play_self (AE)

Plays the speech file specified by arg.

play_other (AF)

test_self_afraid (B2)

Units with "Will never rout" or "Never retreats" attribute always fail this test.

test_self_at_node (B3)

True if caller is at the game object specified.

test_any_at_node (B4)

True if any unit is at the game object specified.

test_any_at_node2 (B5)

arg1: Alignment arg2: game object node arg3: these flags must not be set in unit flag 1

send_event_to_unit_with_label (B6)

arg1: label arg2: eventId (sender will be caller)

send_event_to_source (B7)

Sends an event with id arg to the source of the last event (retrieved with get_event). Sender will be caller.

test_event_from_enemy (B8)

test_event_from_close_combat (B9)

True if sender is the one you are currently fighting (or want to fight by selecting it as a target with the mouse)

test_unit_class (BA)

See Unit Type Bitfield

change_unit_class (BD)

See Unit Type Bitfield

spawn_regiment (BF)

arg1: 1: Fanatics, 2: Zombie (same as spell) arg2: CTL Function to execute arg3: unknown arg4: looks like some offset

test_members_alive_geq_i (C0)

Members means the single units that are part of a regiment.

Returns true if alive members in the regiment >= arg.

test_label_eq_i (C1)

True if caller has arg1 as label

test_event_source_eq_i (C2)

Source is usually the unit that generated the event... but not always :) The id needed for arg1 can be calculated by counting all allied regiments allowed on the current map (starting with 0) continueing with the enemy regiments. If dead units get an id is not tested yet, if not this command is garbage because the ids would change...

Better command: test_event_from_unit

test_game_status (C3)

1: Deployment 2: Battle

test_objective (C4)

Somehow related to the objectives specified in the BTB. Valid arguments are 1 to 12 and 25.

clear_event_queue (C7)

Marks all events of the unit as handled

clear_last_event (C9)

Clears the last event (retrieved with get_event)

test_attribute_set (CD)

Tests if any of the attributes in the bitmask is set.

set_attribute (CE)

Sets the bitmask.

clear_attribute (CF)

Clears the bitmask.

test_event_arg3 (D3)

No idea what arg3 usually is, often just 0.

test_units_alive_le_i (D5)

arg1: alignment arg2: compared against the counted units. if (counted >= arg2) false flag is set, true otherwise.

It counts the unit if it is active (unitflag1 & 1), the alignment matches and unitFlag2 & 2048 is not set and it has at least one alive unit. If the unit was counted unitflag2 & 0x100 is set.

test_boss_defeated (D7)

Checks your game if you defeated Carstein (n = 1), Hand of Nagash (n = 2) or Black Grail (n = 3).

test_unit_alive (D8)

True if a unit with unitId arg is active.

test_user_action (D9)

Used to detect input in the tutorial

ui_indicate (DA)

arg1: x pos arg2: y pos arg3: size

Display 4 arrows that are placed around a rectangle If x and y are -1, size is the unit_id

(DB) and (DC)

Also something for use in tutorial...

set_unit_r_direction (DD)

arg1: unit id arg2: register where direction of arg1 is written to.

Useful in the tutorial only.

test_unit_at_node (DE)

Tests if unit with unitId arg1 is at arg2 (game object).

Some unknown value is checked too, so this description could be partly wrong.

test_unit_at_node2 takes the same arguments but does not check this unknown value.

test_unit_attacking (DF)

True if unit with unitId arg1 attacks unit with unitId arg2.

test_other_unit_flag2 (E0)

arg1: unitId arg2: bitmask for unit flag 2

True if at least one bit is set.

test_other_unit_flag3 (E1)

arg1: unitId arg2: bitmask for unit flag 3

True if at least one bit is set.

test_unit_selected (E2)

True if unit with unitId arg is selected.

test_any_spell_selected (E3)

True if any spell / magic item is selected.

test_mapmode (E6)

True if overworld map (spacebar) was activated.

test_unit_at_node2 (E7)

Tests if unit with unitId arg1 is at arg2 (game object).

See: test_unit_at_node

test_sound_playing (EA)

Tutorial stuff...

test_other_unit_flag1 (EB)

arg1: unitId arg2: bitmask for unit flag 1

test_other_unit_r_eq_i (EC)

arg1: unitId where to read from arg2: register to read arg3: value register is checked against

end_mission (ED)

Displays the mission ended message

test_event_from_unit (EE)

True if the events source is a unit with unitId arg. Will crash if event arg1 was no valid source.

Personal tools
communication