- floatification of bot code.

This commit is contained in:
Christoph Oelckers 2016-03-26 00:34:56 +01:00
commit e42b0171b3
17 changed files with 197 additions and 231 deletions

View file

@ -35,21 +35,21 @@ extern dirtype_t diags[4];
//which can be a weapon/enemy/item whatever.
void DBot::Roam (ticcmd_t *cmd)
{
int delta;
if (Reachable(dest))
{ // Straight towards it.
angle = player->mo->__f_AngleTo(dest);
Angle = player->mo->AngleTo(dest);
}
else if (player->mo->movedir < 8) // turn towards movement direction if not there yet
{
angle &= (angle_t)(7<<29);
delta = angle - (player->mo->movedir << 29);
// no point doing this with floating point angles...
unsigned angle = Angle.BAMs() & (unsigned)(7 << 29);
int delta = angle - (player->mo->movedir << 29);
if (delta > 0)
angle -= ANG45;
Angle -= 45;
else if (delta < 0)
angle += ANG45;
Angle += 45;
}
// chase towards destination.
@ -61,7 +61,7 @@ void DBot::Roam (ticcmd_t *cmd)
bool DBot::Move (ticcmd_t *cmd)
{
fixed_t tryx, tryy;
double tryx, tryy;
bool try_ok;
int good;
@ -71,8 +71,8 @@ bool DBot::Move (ticcmd_t *cmd)
if ((unsigned)player->mo->movedir >= 8)
I_Error ("Weird bot movedir!");
tryx = player->mo->_f_X() + 8*xspeed[player->mo->movedir];
tryy = player->mo->_f_Y() + 8*yspeed[player->mo->movedir];
tryx = player->mo->X() + 8*xspeed[player->mo->movedir];
tryy = player->mo->Y() + 8*yspeed[player->mo->movedir];
try_ok = bglobal.CleanAhead (player->mo, tryx, tryy, cmd);
@ -148,18 +148,18 @@ void DBot::NewChaseDir (ticcmd_t *cmd)
olddir = (dirtype_t)player->mo->movedir;
turnaround = opposite[olddir];
fixedvec2 delta = player->mo->_f_Vec2To(dest);
DVector2 delta = player->mo->Vec2To(dest);
if (delta.x > 10*FRACUNIT)
if (delta.X > 10)
d[1] = DI_EAST;
else if (delta.x < -10*FRACUNIT)
else if (delta.X < -10)
d[1] = DI_WEST;
else
d[1] = DI_NODIR;
if (delta.y < -10*FRACUNIT)
if (delta.Y < -10)
d[2] = DI_SOUTH;
else if (delta.y > 10*FRACUNIT)
else if (delta.Y > 10)
d[2] = DI_NORTH;
else
d[2] = DI_NODIR;
@ -167,19 +167,19 @@ void DBot::NewChaseDir (ticcmd_t *cmd)
// try direct route
if (d[1] != DI_NODIR && d[2] != DI_NODIR)
{
player->mo->movedir = diags[((delta.y<0)<<1)+(delta.x>0)];
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 (pr_botnewchasedir() > 200
|| fabs(delta.Y) > fabs(delta.X))
{
tdir = d[1];
d[1] = d[2];
d[2] = (dirtype_t)tdir;
}
if (d[1]==turnaround)
d[1]=DI_NODIR;
@ -260,7 +260,7 @@ void DBot::NewChaseDir (ticcmd_t *cmd)
// This is also a traverse function for
// bots pre-rocket fire (preventing suicide)
//
bool FCajunMaster::CleanAhead (AActor *thing, fixed_t x, fixed_t y, ticcmd_t *cmd)
bool FCajunMaster::CleanAhead (AActor *thing, double x, double y, ticcmd_t *cmd)
{
FCheckPosition tm;
@ -272,14 +272,14 @@ bool FCajunMaster::CleanAhead (AActor *thing, fixed_t x, fixed_t y, ticcmd_t *cm
if (tm.ceilingz - tm.floorz < thing->Height)
return false; // doesn't fit
double maxmove = FIXED2FLOAT(MAXMOVEHEIGHT);
double maxmove = MAXMOVEHEIGHT;
if (!(thing->flags&MF_MISSILE))
{
if(tm.floorz > (thing->Sector->floorplane._f_ZatPointF(x, y)+maxmove)) //Too high wall
if(tm.floorz > (thing->Sector->floorplane.ZatPoint(x, y)+maxmove)) //Too high wall
return false;
//Jumpable
if(tm.floorz > (thing->Sector->floorplane._f_ZatPointF(x, y)+thing->MaxStepHeight))
if(tm.floorz > (thing->Sector->floorplane.ZatPoint(x, y)+thing->MaxStepHeight))
cmd->ucmd.buttons |= BT_JUMP;
@ -289,7 +289,7 @@ bool FCajunMaster::CleanAhead (AActor *thing, fixed_t x, fixed_t y, ticcmd_t *cm
// jump out of water
// if((thing->eflags & (MF_UNDERWATER|MF_TOUCHWATER))==(MF_UNDERWATER|MF_TOUCHWATER))
// maxstep=37*FRACUNIT;
// maxstep=37;
if ( !(thing->flags & MF_TELEPORT) &&
(tm.floorz - thing->Z() > thing->MaxStepHeight) )
@ -327,11 +327,11 @@ void DBot::TurnToAng ()
if(enemy)
if(!dest) //happens when running after item in combat situations, or normal, prevents weak turns
if(player->ReadyWeapon->ProjectileType == NULL && !(player->ReadyWeapon->WeaponFlags & WIF_MELEEWEAPON))
if(Check_LOS(enemy, SHOOTFOV+5*ANGLE_1))
if(Check_LOS(enemy, SHOOTFOV+5))
maxturn = 3;
}
DAngle distance = deltaangle(player->mo->Angles.Yaw, ANGLE2DBL(angle));
DAngle distance = deltaangle(player->mo->Angles.Yaw, Angle);
if (fabs (distance) < OKAYRANGE && !enemy)
return;
@ -348,8 +348,8 @@ void DBot::Pitch (AActor *target)
double aim;
double diff;
diff = target->_f_Z() - player->mo->_f_Z();
aim = g_atan(diff / (double)player->mo->AproxDistance(target));
diff = target->Z() - player->mo->Z();
aim = g_atan(diff / player->mo->Distance2D(target));
player->mo->Angles.Pitch = ToDegrees(aim);
}