void FCajunMaster::NewChaseDir (AActor *actor, ticcmd_t *cmd) { fixed_t deltax; fixed_t deltay; dirtype_t d[3]; int tdir; dirtype_t olddir; dirtype_t turnaround; if (!actor->player->dest) { #ifndef BOT_RELEASE_COMPILE Printf ("Bot tried move without destination\n"); #endif return; } olddir = (dirtype_t)actor->movedir; turnaround = opposite[olddir]; deltax = actor->player->dest->x - actor->x; deltay = actor->player->dest->y - actor->y; if (deltax > 10*FRACUNIT) d[1] = DI_EAST; else if (deltax < -10*FRACUNIT) d[1] = DI_WEST; else d[1] = DI_NODIR; if (deltay < -10*FRACUNIT) d[2] = DI_SOUTH; else if (deltay > 10*FRACUNIT) d[2] = DI_NORTH; else d[2] = DI_NODIR; // try direct route if (d[1] != DI_NODIR && d[2] != DI_NODIR) { actor->movedir = diags[((deltay<0)<<1)+(deltax>0)]; if (actor->movedir != turnaround && TryWalk(actor, cmd)) return; } // try other directions if (pr_botnewchasedir() > 200 || abs(deltay)>abs(deltax)) { tdir=d[1]; d[1]=d[2]; d[2]=(dirtype_t)tdir; } if (d[1]==turnaround) d[1]=DI_NODIR; if (d[2]==turnaround) d[2]=DI_NODIR; if (d[1]!=DI_NODIR) { actor->movedir = d[1]; if (TryWalk (actor, cmd)) return; } if (d[2]!=DI_NODIR) { actor->movedir = d[2]; if (TryWalk(actor, cmd)) return; } // there is no direct path to the player, // so pick another direction. if (olddir!=DI_NODIR) { actor->movedir = olddir; if (TryWalk(actor, cmd)) return; } // randomly determine direction of search if (pr_botnewchasedir()&1) { for ( tdir=DI_EAST; tdir<=DI_SOUTHEAST; tdir++ ) { if (tdir!=turnaround) { actor->movedir = tdir; if (TryWalk(actor, cmd)) return; } } } else { for ( tdir=DI_SOUTHEAST; tdir != (DI_EAST-1); tdir-- ) { if (tdir!=turnaround) { actor->movedir = tdir; if (TryWalk(actor, cmd)) return; } } } if (turnaround != DI_NODIR) { actor->movedir = turnaround; if (TryWalk(actor, cmd)) return; } actor->movedir = DI_NODIR; // can not move }
void DBot::NewChaseDir (ticcmd_t *cmd) { dirtype_t d[3]; int tdir; dirtype_t olddir; dirtype_t turnaround; if (!dest) { #ifndef BOT_RELEASE_COMPILE Printf ("Bot tried move without destination\n"); #endif return; } olddir = (dirtype_t)player->mo->movedir; turnaround = opposite[olddir]; fixedvec2 delta = player->mo->Vec2To(dest); if (delta.x > 10*FRACUNIT) d[1] = DI_EAST; else if (delta.x < -10*FRACUNIT) d[1] = DI_WEST; else d[1] = DI_NODIR; if (delta.y < -10*FRACUNIT) d[2] = DI_SOUTH; else if (delta.y > 10*FRACUNIT) d[2] = DI_NORTH; else d[2] = DI_NODIR; // try direct route if (d[1] != DI_NODIR && d[2] != DI_NODIR) { player->mo->movedir = diags[((delta.y<0)<<1)+(delta.x>0)]; if (player->mo->movedir != turnaround && TryWalk(cmd)) return; } // try other directions if (pr_botnewchasedir() > 200 || abs(delta.y)>abs(delta.x)) { tdir=d[1]; d[1]=d[2]; d[2]=(dirtype_t)tdir; } if (d[1]==turnaround) d[1]=DI_NODIR; if (d[2]==turnaround) d[2]=DI_NODIR; if (d[1]!=DI_NODIR) { player->mo->movedir = d[1]; if (TryWalk (cmd)) return; } if (d[2]!=DI_NODIR) { player->mo->movedir = d[2]; if (TryWalk(cmd)) return; } // there is no direct path to the player, // so pick another direction. if (olddir!=DI_NODIR) { player->mo->movedir = olddir; if (TryWalk(cmd)) return; } // randomly determine direction of search if (pr_botnewchasedir()&1) { for ( tdir=DI_EAST; tdir<=DI_SOUTHEAST; tdir++ ) { if (tdir!=turnaround) { player->mo->movedir = tdir; if (TryWalk(cmd)) return; } } } else { for ( tdir=DI_SOUTHEAST; tdir != (DI_EAST-1); tdir-- ) { if (tdir!=turnaround) { player->mo->movedir = tdir; if (TryWalk(cmd)) return; } } } if (turnaround != DI_NODIR) { player->mo->movedir = turnaround; if (TryWalk(cmd)) return; } player->mo->movedir = DI_NODIR; // can not move }