Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // From Catacomb source:
- {===============================================}
- { }
- { ChaseTHINK }
- { have the current monster go after the player, }
- { either diagonally or straight on }
- { }
- {===============================================}
- procedure chaseTHINK (diagonal:boolean);
- var
- deltax,deltay,i: integer;
- d: array[1..2] of dirtype;
- tdir, olddir, turnaround: dirtype;
- begin
- obj.Stage:=obj.stage and 1; {cancle attack or damaged stage}
- olddir:=obj.dir;
- TurnAround:=opposite[olddir];
- deltax:=o[0].x-obj.x;
- deltay:=o[0].y-obj.y;
- for i:=1 to 2 do
- d[i]:=nodir;
- if deltax>0 then
- d[1]:= east;
- if deltax<0 then
- d[1]:= west;
- if deltay>0 then
- d[2]:=south;
- if deltay<0 then
- d[2]:=north;
- if abs(deltay)>abs(deltax) then
- begin
- tdir:=d[1];
- d[1]:=d[2];
- d[2]:=tdir;
- end;
- for i:=1 to 2 do
- if d[i]=TurnAround then
- d[i]:=nodir;
- if diagonal then
- begin {ramdiagonals try the best dir first}
- if d[1]<>nodir then
- begin
- obj.dir:=d[1];
- if walk or (obj.stage=3) then
- exit; {either moved forward or attacked}
- end;
- if d[2]<>nodir then
- begin
- obj.dir:=d[2];
- if walk or (obj.stage=3) then
- exit;
- end;
- end
- else
- begin {ramstraights try the second best dir first}
- if d[2]<>nodir then
- begin
- obj.dir:=d[2];
- if walk or (obj.stage=3) then
- exit;
- end;
- if d[1]<>nodir then
- begin
- obj.dir:=d[1];
- if walk or (obj.stage=3) then
- exit;
- end;
- end;
- { there is no direct path to the player, so pick another direction }
- obj.dir:=olddir;
- if walk or (obj.stage=3) then
- exit;
- if random(256)>128 then {randomly determine direction of search}
- begin
- for tdir:=north to west do
- if tdir<>TurnAround then
- begin
- obj.dir:=tdir;
- if walk or (obj.stage=3) then
- exit;
- end
- end
- else
- begin
- for tdir:=west downto north do
- if tdir<>TurnAround then
- begin
- obj.dir:=tdir;
- if walk or (obj.stage=3) then
- exit;
- end;
- end;
- obj.dir:=turnaround;
- altkey:=walk; {last chance, don't worry about returned value}
- end;
- // From Doom 3 BFG edition source:
- /*
- ================
- idAI::NewWanderDir
- ================
- */
- bool idAI::NewWanderDir( const idVec3 &dest ) {
- float deltax, deltay;
- float d[ 3 ];
- float tdir, olddir, turnaround;
- move.nextWanderTime = gameLocal.time + ( gameLocal.random.RandomFloat() * 500 + 500 );
- olddir = idMath::AngleNormalize360( ( int )( current_yaw / 45 ) * 45 );
- turnaround = idMath::AngleNormalize360( olddir - 180 );
- idVec3 org = physicsObj.GetOrigin();
- deltax = dest.x - org.x;
- deltay = dest.y - org.y;
- if ( deltax > 10 ) {
- d[ 1 ]= 0;
- } else if ( deltax < -10 ) {
- d[ 1 ] = 180;
- } else {
- d[ 1 ] = DI_NODIR;
- }
- if ( deltay < -10 ) {
- d[ 2 ] = 270;
- } else if ( deltay > 10 ) {
- d[ 2 ] = 90;
- } else {
- d[ 2 ] = DI_NODIR;
- }
- // try direct route
- if ( d[ 1 ] != DI_NODIR && d[ 2 ] != DI_NODIR ) {
- if ( d[ 1 ] == 0 ) {
- tdir = d[ 2 ] == 90 ? 45 : 315;
- } else {
- tdir = d[ 2 ] == 90 ? 135 : 215;
- }
- if ( tdir != turnaround && StepDirection( tdir ) ) {
- return true;
- }
- }
- // try other directions
- if ( ( gameLocal.random.RandomInt() & 1 ) || abs( deltay ) > abs( deltax ) ) {
- tdir = d[ 1 ];
- d[ 1 ] = d[ 2 ];
- d[ 2 ] = tdir;
- }
- if ( d[ 1 ] != DI_NODIR && d[ 1 ] != turnaround && StepDirection( d[1] ) ) {
- return true;
- }
- if ( d[ 2 ] != DI_NODIR && d[ 2 ] != turnaround && StepDirection( d[ 2 ] ) ) {
- return true;
- }
- // there is no direct path to the player, so pick another direction
- if ( olddir != DI_NODIR && StepDirection( olddir ) ) {
- return true;
- }
- // randomly determine direction of search
- if ( gameLocal.random.RandomInt() & 1 ) {
- for( tdir = 0; tdir <= 315; tdir += 45 ) {
- if ( tdir != turnaround && StepDirection( tdir ) ) {
- return true;
- }
- }
- } else {
- for ( tdir = 315; tdir >= 0; tdir -= 45 ) {
- if ( tdir != turnaround && StepDirection( tdir ) ) {
- return true;
- }
- }
- }
- if ( turnaround != DI_NODIR && StepDirection( turnaround ) ) {
- return true;
- }
- // can't move
- StopMove( MOVE_STATUS_DEST_UNREACHABLE );
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement