Thread: [Guide] AI
View Single Post
Old 21.06.2007, 10:52   #12
HF
Архивный участник
 
Join Date: Aug 2005
Posts: 1,531
Default

Example for using branch_false, not_equal (decompiled code If, else)

Note. 'PARTY_ATTACKED' uses if monster see what one from him party has been attacked

Code:
class 1 party_private : party_private_param
...
handler 19 224	//  PARTY_ATTACKED
	variable_begin
		"attacker"
		"private"
		"damage"
		"f0"
		"myself"
		"_choiceN"
		"_code"
		"_from_choice"
	variable_end

	push_event	//  private
	push_const 64
	add
	fetch_i
	push_event	//  myself
	push_const 704
	add
	fetch_i	//  sm
	push_const 544
	add
	fetch_i
	not_equal
	branch_false L10262
L10261

There you have known structure for using function and new command 'branch_false' and working 'add' for multiple events.
Note:
Code:
	add
	fetch_i	// ...
show as additional name for parameter (for server - it working with memory offset)
Code:
	push_event	//  myself
	push_const 704
	add
	fetch_i	//  sm
	push_const 544
is 'myself.sm'
  1. add event 'private' to stack (1)
  2. add 'myself' to stack (2)
  3. add 'sm' to previous value = myself.sm (2)
  4. use logical operation not_equal with use two lastest stack values
    Code:
    private != myself.sm
  5. use logical checking
    Code:
    branch_false L10262
    If last operation is False then made jump (goto) in code to label L10262. If True then work with next code line.

Code:
handler PARTY_ATTACKED (attacker, private, damage, f0)
{
        if (private != myself.sm)
        {
           ...
        }
....
------------
Another example for brench_false without second param.
Code:
class 1 castle_merchant : citizen
...
        push_event      //  myself
        push_const 704
        add
        fetch_i
        push_event      //  talker
        push_const 40
        add
        fetch_i
        func_call 184615062     //  func[IsMyLord]
        shift_sp -1
        branch_false L4128
L4127
        push_event      //  myself
        push_const 704
        add
        fetch_i
        push_event      //  talker
        push_const 40
        add
        fetch_i
        push_parameter fnMyLord
        func_call 184680516     //  func[ShowPage]
        shift_sp -2
        shift_sp -1
show in code like this
Code:
if (myself->IsMyLord(talker))
{
        myself->ShowPage(talker, fnMyLord);
}
but for good understanding it can show like:
Code:
if (myself->IsMyLord(talker) == True)
because all operations must be success/failed results (in server memory)
HF is offline