home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer 5.14 / 2000-11_-_Disc_5.14.iso / Goodies / 3DGameStudio / Mission / actors.wdl < prev    next >
Text File  |  2000-02-08  |  3KB  |  142 lines

  1. //////////////////////////////////////////////////////////////////////
  2. // WDL prefabs for actors and enemies
  3. //////////////////////////////////////////////////////////////////////
  4. ACTION patrol
  5. {
  6.     IF (MY._FORCE == 0) {  MY._FORCE = 1; }
  7.     IF (MY._MOVEMODE == 0) { MY._MOVEMODE = _MODE_WALKING; }
  8.     IF (MY._WALKFRAMES == 0) { MY._WALKFRAMES = DEFAULT_WALK; }
  9.     IF (MY._RUNFRAMES == 0) { MY._RUNFRAMES = DEFAULT_RUN; }
  10.     IF (MY._WALKSOUND == 0) { MY._WALKSOUND = _SOUND_WALKER; }
  11.     CALL anim_init;
  12.  
  13. // find next start position
  14.     MY._TARGET_X = MY.X;
  15.     MY._TARGET_Y = MY.Y;
  16.     MY._TARGET_Z = MY.Z;
  17.     scan_sector.PAN = 360;
  18.     CALL _scan_target;
  19.  
  20.     WHILE (MY._MOVEMODE > 0)
  21.     {
  22. // find direction
  23.         MY_POS.X = MY._TARGET_X - MY.X;
  24.         MY_POS.Y = MY._TARGET_Y - MY.Y;
  25.         MY_POS.Z = 0;
  26.         TO_ANGLE MY_ANGLE,MY_POS;
  27.  
  28.         IF (MY_ANGLE.Z < 30) {    // near target? Find next
  29.             scan_sector.PAN = 20;
  30.             CALL _scan_target;
  31.         }
  32.  
  33.         force = MY._FORCE * 2;
  34.         CALL actor_turn;    // look to target
  35.  
  36.         force = MY._FORCE;
  37.         IF (ABS(aforce.PAN) > MY._FORCE) {    // reduce speed if turning
  38.             force *= 0.5; }
  39.         IF (MY_ANGLE.Z < 40) {    // reduce speed near target
  40.             force *= 0.5; }
  41.         CALL actor_move;
  42. // Wait one tick, then repeat
  43.         WAIT    1;
  44.     }
  45. }
  46.  
  47. ///////////////////////////////////////////////////////////////////////
  48. // helper actions
  49.  
  50. // move ahead, according to force
  51. ACTION actor_move {
  52.     force.Y = 0;
  53.     force.Z = 0;
  54.  
  55. // find ground below
  56.     CALL scan_floor;
  57.     CALL move_gravity;
  58.     CALL actor_anim;
  59. }
  60.  
  61. ACTION actor_follow
  62. {
  63.     IF (MY._FORCE == 0) {  MY._FORCE = 2; }
  64.     IF (MY._MOVEMODE == 0) { MY._MOVEMODE = _MODE_WALKING; }
  65.     IF (MY._WALKFRAMES == 0) { MY._WALKFRAMES = DEFAULT_WALK; }
  66.     IF (MY._RUNFRAMES == 0) { MY._RUNFRAMES = DEFAULT_RUN; }
  67.     IF (MY._WALKSOUND == 0) { MY._WALKSOUND = _SOUND_WALKER; }
  68.     CALL anim_init;
  69.  
  70.     WHILE (1)
  71.     {
  72. // calculate a direction to walk into
  73.         temp.X = player.X - MY.X;
  74.         temp.Y = player.Y - MY.Y;
  75.         temp.Z = 0;
  76.         TO_ANGLE MY_ANGLE,temp;
  77.  
  78. // turn towards player
  79.         MY_ANGLE.TILT = 0;
  80.         MY_ANGLE.ROLL = 0;
  81.         force = MY._FORCE * 2;
  82.         CALL actor_turn;
  83.  
  84. // walk towards him
  85.         force = MY._FORCE;
  86.         MY._MOVEMODE = _MODE_WALKING;
  87.         CALL actor_move;
  88.  
  89.         WAIT 1;
  90.     }
  91. }
  92.  
  93.  
  94. IFDEF ACKNEX_VERSION414;
  95. ACTION _actor_connect
  96. {
  97.     IF (EVENT_TYPE == EVENT_DISCONNECT) { REMOVE ME; }
  98. }
  99. ENDIF;
  100.  
  101. // turn towards target angle MY_ANGLE, according to force
  102. ACTION actor_turn
  103. {
  104.     aforce.PAN = 0;
  105.     temp = ANG(MY_ANGLE.PAN - MY.PAN);
  106.     IF (temp > 5) {
  107.         aforce.PAN = force;
  108.     } ELSE { IF (temp < -5) {
  109.         aforce.PAN = -force;
  110.     } ELSE {
  111.         aforce.PAN = force*temp*0.25;
  112.     }}
  113.  
  114. // Now accelerate the angular speed, and change MY angles
  115.     ACCEL    MY._ASPEED,aforce,ang_fric;
  116.     MY.PAN += MY._ASPEED_PAN;
  117. }
  118.  
  119. // Find next start position
  120. ACTION _scan_target
  121. {
  122. // scan from old target
  123.     MY_POS.X = MY._TARGET_X;
  124.     MY_POS.Y = MY._TARGET_Y;
  125.     MY_POS.Z = MY._TARGET_Z;
  126.     MY_ANGLE.PAN = MY._TARGET_PAN;
  127.     MY_ANGLE.TILT = 0;
  128.     scan_sector.TILT = 90;
  129.     scan_sector.Z = 2000;
  130.     SCAN_POS MY_POS,MY_ANGLE,scan_sector;
  131.     IF (RESULT > 0) {
  132. // if found, set new target
  133.         MY._TARGET_X = MY_POS.X;
  134.         MY._TARGET_Y = MY_POS.Y;
  135.         MY._TARGET_Z = MY_POS.Z;
  136.         MY._TARGET_PAN = MY_ANGLE.PAN;
  137.         MY._MOVEMODE = _MODE_WALKING;
  138.     } ELSE {
  139.         MY._MOVEMODE = 0;
  140.     }
  141. }
  142. //////////////////////////////////////////////////////////////////////