Advertisement
Blzut3

Catacomb, Doom 3 common code

Jun 5th, 2014
22,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. // From Catacomb source:
  2.  
  3. {===============================================}
  4. { }
  5. { ChaseTHINK }
  6. { have the current monster go after the player, }
  7. { either diagonally or straight on }
  8. { }
  9. {===============================================}
  10.  
  11. procedure chaseTHINK (diagonal:boolean);
  12.  
  13. var
  14. deltax,deltay,i: integer;
  15. d: array[1..2] of dirtype;
  16. tdir, olddir, turnaround: dirtype;
  17. begin
  18. obj.Stage:=obj.stage and 1; {cancle attack or damaged stage}
  19. olddir:=obj.dir;
  20. TurnAround:=opposite[olddir];
  21.  
  22. deltax:=o[0].x-obj.x;
  23. deltay:=o[0].y-obj.y;
  24. for i:=1 to 2 do
  25. d[i]:=nodir;
  26.  
  27. if deltax>0 then
  28. d[1]:= east;
  29. if deltax<0 then
  30. d[1]:= west;
  31. if deltay>0 then
  32. d[2]:=south;
  33. if deltay<0 then
  34. d[2]:=north;
  35.  
  36. if abs(deltay)>abs(deltax) then
  37. begin
  38. tdir:=d[1];
  39. d[1]:=d[2];
  40. d[2]:=tdir;
  41. end;
  42.  
  43. for i:=1 to 2 do
  44. if d[i]=TurnAround then
  45. d[i]:=nodir;
  46.  
  47.  
  48. if diagonal then
  49. begin {ramdiagonals try the best dir first}
  50. if d[1]<>nodir then
  51. begin
  52. obj.dir:=d[1];
  53. if walk or (obj.stage=3) then
  54. exit; {either moved forward or attacked}
  55. end;
  56.  
  57. if d[2]<>nodir then
  58. begin
  59. obj.dir:=d[2];
  60. if walk or (obj.stage=3) then
  61. exit;
  62. end;
  63. end
  64. else
  65. begin {ramstraights try the second best dir first}
  66.  
  67. if d[2]<>nodir then
  68. begin
  69. obj.dir:=d[2];
  70. if walk or (obj.stage=3) then
  71. exit;
  72. end;
  73.  
  74. if d[1]<>nodir then
  75. begin
  76. obj.dir:=d[1];
  77. if walk or (obj.stage=3) then
  78. exit;
  79. end;
  80.  
  81. end;
  82.  
  83. { there is no direct path to the player, so pick another direction }
  84.  
  85. obj.dir:=olddir;
  86. if walk or (obj.stage=3) then
  87. exit;
  88.  
  89. if random(256)>128 then {randomly determine direction of search}
  90. begin
  91. for tdir:=north to west do
  92. if tdir<>TurnAround then
  93. begin
  94. obj.dir:=tdir;
  95. if walk or (obj.stage=3) then
  96. exit;
  97. end
  98. end
  99.  
  100. else
  101.  
  102. begin
  103. for tdir:=west downto north do
  104. if tdir<>TurnAround then
  105. begin
  106. obj.dir:=tdir;
  107. if walk or (obj.stage=3) then
  108. exit;
  109. end;
  110. end;
  111.  
  112. obj.dir:=turnaround;
  113. altkey:=walk; {last chance, don't worry about returned value}
  114. end;
  115.  
  116. // From Doom 3 BFG edition source:
  117.  
  118. /*
  119. ================
  120. idAI::NewWanderDir
  121. ================
  122. */
  123. bool idAI::NewWanderDir( const idVec3 &dest ) {
  124. float deltax, deltay;
  125. float d[ 3 ];
  126. float tdir, olddir, turnaround;
  127.  
  128. move.nextWanderTime = gameLocal.time + ( gameLocal.random.RandomFloat() * 500 + 500 );
  129.  
  130. olddir = idMath::AngleNormalize360( ( int )( current_yaw / 45 ) * 45 );
  131. turnaround = idMath::AngleNormalize360( olddir - 180 );
  132.  
  133. idVec3 org = physicsObj.GetOrigin();
  134. deltax = dest.x - org.x;
  135. deltay = dest.y - org.y;
  136. if ( deltax > 10 ) {
  137. d[ 1 ]= 0;
  138. } else if ( deltax < -10 ) {
  139. d[ 1 ] = 180;
  140. } else {
  141. d[ 1 ] = DI_NODIR;
  142. }
  143.  
  144. if ( deltay < -10 ) {
  145. d[ 2 ] = 270;
  146. } else if ( deltay > 10 ) {
  147. d[ 2 ] = 90;
  148. } else {
  149. d[ 2 ] = DI_NODIR;
  150. }
  151.  
  152. // try direct route
  153. if ( d[ 1 ] != DI_NODIR && d[ 2 ] != DI_NODIR ) {
  154. if ( d[ 1 ] == 0 ) {
  155. tdir = d[ 2 ] == 90 ? 45 : 315;
  156. } else {
  157. tdir = d[ 2 ] == 90 ? 135 : 215;
  158. }
  159.  
  160. if ( tdir != turnaround && StepDirection( tdir ) ) {
  161. return true;
  162. }
  163. }
  164.  
  165. // try other directions
  166. if ( ( gameLocal.random.RandomInt() & 1 ) || abs( deltay ) > abs( deltax ) ) {
  167. tdir = d[ 1 ];
  168. d[ 1 ] = d[ 2 ];
  169. d[ 2 ] = tdir;
  170. }
  171.  
  172. if ( d[ 1 ] != DI_NODIR && d[ 1 ] != turnaround && StepDirection( d[1] ) ) {
  173. return true;
  174. }
  175.  
  176. if ( d[ 2 ] != DI_NODIR && d[ 2 ] != turnaround && StepDirection( d[ 2 ] ) ) {
  177. return true;
  178. }
  179.  
  180. // there is no direct path to the player, so pick another direction
  181. if ( olddir != DI_NODIR && StepDirection( olddir ) ) {
  182. return true;
  183. }
  184.  
  185. // randomly determine direction of search
  186. if ( gameLocal.random.RandomInt() & 1 ) {
  187. for( tdir = 0; tdir <= 315; tdir += 45 ) {
  188. if ( tdir != turnaround && StepDirection( tdir ) ) {
  189. return true;
  190. }
  191. }
  192. } else {
  193. for ( tdir = 315; tdir >= 0; tdir -= 45 ) {
  194. if ( tdir != turnaround && StepDirection( tdir ) ) {
  195. return true;
  196. }
  197. }
  198. }
  199.  
  200. if ( turnaround != DI_NODIR && StepDirection( turnaround ) ) {
  201. return true;
  202. }
  203.  
  204. // can't move
  205. StopMove( MOVE_STATUS_DEST_UNREACHABLE );
  206. return false;
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement