:-object step_scriptlib : [ bcilib ].

script(walk(Agent, X,Y,Z,Rfront,Rback), ActionList) :-
    ActionList = [
      parallel([
        turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,Rback),very_fast),
        turn(Agent,r_hip,rotation(1.0,0.0,0.0,Rfront),very_fast),
        move(Agent,increment(X,Y,Z),very_fast),
        turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,Rfront),very_fast),
        turn(Agent,l_hip,rotation(1.0,0.0,0.0,Rback),very_fast)]),
      parallel([
        turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,Rback),very_fast),
        turn(Agent,l_hip,rotation(1.0,0.0,0.0,Rfront),very_fast),
        move(Agent,increment(X,Y,Z),very_fast),
        turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,Rfront),very_fast),
        turn(Agent,r_hip,rotation(1.0,0.0,0.0,Rback),very_fast)])
    ],
    !.

script(grabWalk(Agent, X,Y,Z,Rfront,Rback), ActionList) :-
    ActionList = [
      parallel([
        turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,Rback),very_fast),
        turn(Agent,r_hip,rotation(1.0,0.0,0.0,Rfront),very_fast),
        move(Agent,increment(X,Y,Z),very_fast),
     %   turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,Rfront),very_fast),
        turn(Agent,l_hip,rotation(1.0,0.0,0.0,Rback),very_fast)]),
      parallel([
      %  turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,Rback),very_fast),
        turn(Agent,l_hip,rotation(1.0,0.0,0.0,Rfront),very_fast),
        move(Agent,increment(X,Y,Z),very_fast),
        turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,Rfront),very_fast),
        turn(Agent,r_hip,rotation(1.0,0.0,0.0,Rback),very_fast)])
    ],
    !.

script(rotate_left(Agent, R, Rback,Rfront), ActionList) :-
    ActionList = [
      parallel([
        turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,Rback),very_fast),
        turn(Agent,r_hip,rotation(1.0,0.0,0.0,Rfront),very_fast),
        turn(Agent, humanoidroot, rotation(0.0,1.0,0.0,R),very_fast),
        turn(Agent, skullbase, rotation(0.0,1.0,0.0,0.0), very_fast),
        turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,Rfront),very_fast),
        turn(Agent,l_hip,rotation(1.0,0.0,0.0,Rback),very_fast)
      ]),
      parallel([
        turn(Agent,l_shoulder, down, very_fast),
        turn(Agent,l_hip, down, very_fast),
        turn(Agent,r_shoulder, down, very_fast),
        turn(Agent,r_hip, down, very_fast)
      ])
    ],
    !.

script(rotate_right(Agent, R, Rback,Rfront), ActionList) :-
    ActionList = [
      parallel([
        turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,Rback),very_fast),
        turn(Agent,l_hip,rotation(1.0,0.0,0.0,Rfront),very_fast),
        turn(Agent, humanoidroot, rotation(0.0,1.0,0.0,R), very_fast),
        turn(Agent, skullbase, rotation(0.0,1.0,0.0,0.0), very_fast),
        turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,Rfront),very_fast),
        turn(Agent,r_hip,rotation(1.0,0.0,0.0,Rback),very_fast)
      ]),
      parallel([
        turn(Agent,r_shoulder, down, very_fast),
        turn(Agent,r_hip, down, very_fast),
        turn(Agent,l_shoulder, down, very_fast),
        turn(Agent,l_hip, down ,very_fast)
      ])
    ],
    !.

script(rotate(Agent, R), ActionList) :-
    ActionList = [
      parallel([
        turn(Agent, humanoidroot, rotation(0.0,1.0,0.0,R), very_fast),
        turn(Agent, skullbase, rotation(0.0,1.0,0.0,0.0), very_fast)
      ])
    ],
    !.
        
script(stand(Agent), ActionList) :-
    ActionList = [
      parallel([
        turn(Agent,l_shoulder,down,fast),
        turn(Agent,r_shoulder,down,fast),
        turn(Agent,l_hip,down,fast),
        turn(Agent,r_hip,down,fast)
      ])
    ],
    !.
    
script(grabStand(Agent), ActionList) :-
    ActionList = [
      parallel([
%        turn(Agent,l_shoulder,down,fast),
        turn(Agent,r_shoulder,down,fast),
        turn(Agent,l_hip,down,fast),
        turn(Agent,r_hip,down,fast)
      ])
    ],
    !.

script(point(Agent, R), ActionList) :-
  ActionList = [
    turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,R),fast)
  ],
  !.
    
script(grab_right(Agent, [ObjectRef], Object, R,R1), ActionList) :-
    ActionList = [
      turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,R),fast),
      do(setSFInt32(Object, whichChoice, -1)),
      do(setRotation(ObjectRef, 1.0,0.0,0.0,R)),
      do(addChildren('hanim_r_hand_site', [ObjectRef])),
      turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,R1),fast)
    ],
    !.
    
script(grab_left(Agent, [ObjectRef], Object, R,R1), ActionList) :-
    ActionList = [
      turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,R),fast),
      do(setSFInt32(Object, whichChoice, -1)),
      do(setRotation(ObjectRef, 1.0,0.0,0.0,R)),
      do(addChildren('hanim_l_hand_site', [ObjectRef])),
      turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,R1),fast)
    ],
    !.

script(release(Agent, [ObjectRef], Object, X,Y,Z, R,R1,RO), ActionList) :-
  ActionList = [
    turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,R),fast),
    do(removeChildren('hanim_l_hand_site', [ObjectRef])),
    do(setPosition(Object, X,Y,Z)),
    do(setRotation(ObjectRef, 1.0,0.0,0.0,0.0)),
    do(setRotation(Object, 0.0,1.0,0.0,RO)),
    do(setSFInt32(Object, whichChoice, 0)),
    turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,R1),fast)
  ],
  !.
  
script(drop(Agent, [ObjectRef], R), ActionList) :-
  ActionList = [
    parallel([
      turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,R),fast),
      do(removeChildren('hanim_r_hand_site', [ObjectRef]))
    ])
  ],
  !.

script(open(Agent, Object, Shoulder, X,Z, Rfront,Rback, R, R1), ActionList) :-
  ActionList = [
    turn(Agent, Shoulder, rotation(1.0,0.0,0.0,R),fast),
    turn(Agent, Shoulder, rotation(1.0,0.0,0.0,R1),fast),
    do(setSFBool(Object, touch, true)),
    parallel([
      turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,Rfront),fast),
      turn(Agent,r_hip,rotation(1.0,0.0,0.0,Rback),fast),
      move(Agent,increment(X,0.0,Z),very_fast),
      turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,Rback),fast),
      turn(Agent,l_hip,rotation(1.0,0.0,0.0,Rfront),fast)
    ]),
    parallel([
      turn(Agent,l_shoulder,down,fast),
      turn(Agent,l_hip,down,fast),
      move(Agent,increment(X,0.0,Z),very_fast),
      turn(Agent,r_shoulder,down,fast),
      turn(Agent,r_hip,down,fast)
    ])
  ],
  !.

script(close(Agent, Object, Shoulder, X,Z, Rfront,Rback, RO, R, R1), ActionList) :-
  ActionList = [
    turn(Agent, Shoulder, rotation(1.0,0.0,0.0,R),fast),
    turn(Agent, Shoulder, rotation(1.0,0.0,0.0,R1),fast),
    do(setSFBool(Object, touch, true)),
    parallel([
      seq([
        parallel([
          turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,Rfront),fast),
          turn(Agent,r_hip,rotation(1.0,0.0,0.0,Rback),fast),
          move(Agent,increment(X,0.0,Z),very_fast),
          turn(Agent,l_shoulder,rotation(1.0,0.0,0.0,Rback),fast),
          turn(Agent,l_hip,rotation(1.0,0.0,0.0,Rfront),fast)
        ]),
        parallel([
          turn(Agent,l_shoulder,down,fast),
          turn(Agent,l_hip,down,fast),
          move(Agent,increment(X,0.0,Z),very_fast),
          turn(Agent,r_shoulder,down,fast),
          turn(Agent,r_hip,down,fast)
        ])
      ]),
      turn(Agent, humanoidroot, rotation(0.0,1.0,0.0,RO),fast)
    ])
  ],
  !. 
  
script(switch(Agent, Object, R), ActionList) :-
    ActionList = [
      turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,R),fast),
      do(setSFBool(Object, touch, true)),
      turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,0.0),fast)
    ],
    !.

script(push_button(Agent, Object, R), ActionList) :-
    ActionList = [
      turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,R),fast),
      do(setSFBool(Object, isActive, true)),
      turn(Agent,r_shoulder,rotation(1.0,0.0,0.0,0.0),fast)
    ],
    !.
  
script(sit(Agent, X,Height,Z), ActionList) :-
    ActionList = [
      parallel([
        turn(Agent, r_shoulder,up,fast),
        turn(Agent, l_shoulder,up,fast),
        move(Agent, increment(0.0,Height,0.0), fast),
        turn(Agent, r_hip,front,fast),
        turn(Agent, l_hip,front,fast)
      ]),
      parallel([
        turn(Agent, r_shoulder,down,fast),
        turn(Agent, l_shoulder,down,fast),
        move(Agent, increment(X,0.0,Z), fast)
      ])
    ],
    !.

script(lay(Agent, _), ActionList) :-
  ActionList = [
    parallel([
      turn(Agent, humanoidroot, up, fast),
      turn(Agent, r_hip, down, fast),
      turn(Agent, l_hip, down, fast)
    ])
  ],
  !.
  
script(get_of(Agent, X,Down,Z), ActionList) :-
  ActionList = [
    parallel([
      turn(Agent, r_shoulder,up,fast),
      turn(Agent, l_shoulder,up,fast),
      move(Agent, increment(X,0.0,Z), fast)
    ]),
    parallel([
      turn(Agent, r_shoulder,down,fast),
      turn(Agent, l_shoulder,down,fast),
      turn(Agent, r_hip,down,fast),
      turn(Agent, l_hip,down,fast),
      move(Agent, increment(0.0,Down,0.0), fast)
    ])
  ],
  !.

script(get_up(Agent, _), ActionList) :-
  ActionList = [
    parallel([
      turn(Agent, humanoidroot, front, fast),
      turn(Agent, r_hip, front, fast),
      turn(Agent, l_hip, front, fast)
    ])
  ],
  !.
     
script(push(Agent, Object, R), ActionList) :-
    ActionList = [
      turn(Agent, r_shoulder,rotation(1.0,0.0,0.0,R),fast),
      do(getSFTime(Object, time, Time)),
      do(setSFTime(Object, touchTime, Time))
    ],
    !.

script(look(Agent, R), ActionList) :-
  ActionList = [
    turn(Agent, skullbase, rotation(0.0,1.0,0.0,R), very_fast)
  ],
  !.
    
script(ScriptAction, _):-
  format('cannot find the script action ~w in the script libraries~n',[ScriptAction]).

:-end_object step_scriptlib.
