- Moved bot related variables from player_t into a new FBot class.

This commit is contained in:
ChillyDoom 2014-10-13 18:40:25 +01:00
commit 83d84eaae9
20 changed files with 325 additions and 344 deletions

View file

@ -28,13 +28,13 @@ void FCajunMaster::Think (AActor *actor, ticcmd_t *cmd)
{
memset (cmd, 0, sizeof(*cmd));
if (actor->player->enemy && actor->player->enemy->health <= 0)
actor->player->enemy = NULL;
if (actor->player->Bot.enemy && actor->player->Bot.enemy->health <= 0)
actor->player->Bot.enemy = NULL;
if (actor->health > 0) //Still alive
{
if (teamplay || !deathmatch)
actor->player->mate = Choose_Mate (actor);
actor->player->Bot.mate = Choose_Mate (actor);
angle_t oldyaw = actor->angle;
int oldpitch = actor->pitch;
@ -52,17 +52,17 @@ void FCajunMaster::Think (AActor *actor, ticcmd_t *cmd)
actor->pitch = oldpitch - (cmd->ucmd.pitch << 16) * ticdup;
}
if (actor->player->t_active) actor->player->t_active--;
if (actor->player->t_strafe) actor->player->t_strafe--;
if (actor->player->t_react) actor->player->t_react--;
if (actor->player->t_fight) actor->player->t_fight--;
if (actor->player->t_rocket) actor->player->t_rocket--;
if (actor->player->t_roam) actor->player->t_roam--;
if (actor->player->Bot.t_active) actor->player->Bot.t_active--;
if (actor->player->Bot.t_strafe) actor->player->Bot.t_strafe--;
if (actor->player->Bot.t_react) actor->player->Bot.t_react--;
if (actor->player->Bot.t_fight) actor->player->Bot.t_fight--;
if (actor->player->Bot.t_rocket) actor->player->Bot.t_rocket--;
if (actor->player->Bot.t_roam) actor->player->Bot.t_roam--;
//Respawn ticker
if (actor->player->t_respawn)
if (actor->player->Bot.t_respawn)
{
actor->player->t_respawn--;
actor->player->Bot.t_respawn--;
}
else if (actor->health <= 0)
{ // Time to respawn
@ -80,17 +80,17 @@ void FCajunMaster::ThinkForMove (AActor *actor, ticcmd_t *cmd)
int r;
b = actor->player;
if (!b->isbot)
if (!b->Bot.isbot)
return;
stuck = false;
dist = b->dest ? P_AproxDistance(actor->x-b->dest->x, actor->y-b->dest->y) : 0;
dist = b->Bot.dest ? P_AproxDistance(actor->x-b->Bot.dest->x, actor->y-b->Bot.dest->y) : 0;
if (b->missile &&
((!b->missile->velx || !b->missile->vely) || !Check_LOS(actor, b->missile, SHOOTFOV*3/2)))
if (b->Bot.missile &&
((!b->Bot.missile->velx || !b->Bot.missile->vely) || !Check_LOS(actor, b->Bot.missile, SHOOTFOV*3/2)))
{
b->sleft = !b->sleft;
b->missile = NULL; //Probably ended its travel.
b->Bot.sleft = !b->Bot.sleft;
b->Bot.missile = NULL; //Probably ended its travel.
}
if (actor->pitch > 0)
@ -99,35 +99,35 @@ void FCajunMaster::ThinkForMove (AActor *actor, ticcmd_t *cmd)
actor->pitch += 80;
//HOW TO MOVE:
if (b->missile && (P_AproxDistance(actor->x-b->missile->x, actor->y-b->missile->y)<AVOID_DIST)) //try avoid missile got from P_Mobj.c thinking part.
if (b->Bot.missile && (P_AproxDistance(actor->x-b->Bot.missile->x, actor->y-b->Bot.missile->y)<AVOID_DIST)) //try avoid missile got from P_Mobj.c thinking part.
{
Pitch (actor, b->missile);
actor->player->angle = R_PointToAngle2(actor->x, actor->y, b->missile->x, b->missile->y);
cmd->ucmd.sidemove = b->sleft ? -SIDERUN : SIDERUN;
Pitch (actor, b->Bot.missile);
actor->player->Bot.angle = R_PointToAngle2(actor->x, actor->y, b->Bot.missile->x, b->Bot.missile->y);
cmd->ucmd.sidemove = b->Bot.sleft ? -SIDERUN : SIDERUN;
cmd->ucmd.forwardmove = -FORWARDRUN; //Back IS best.
if ((P_AproxDistance(actor->x-b->oldx, actor->y-b->oldy)<50000)
&& b->t_strafe<=0)
if ((P_AproxDistance(actor->x-b->Bot.oldx, actor->y-b->Bot.oldy)<50000)
&& b->Bot.t_strafe<=0)
{
b->t_strafe = 5;
b->sleft = !b->sleft;
b->Bot.t_strafe = 5;
b->Bot.sleft = !b->Bot.sleft;
}
//If able to see enemy while avoiding missile, still fire at enemy.
if (b->enemy && Check_LOS (actor, b->enemy, SHOOTFOV))
if (b->Bot.enemy && Check_LOS (actor, b->Bot.enemy, SHOOTFOV))
Dofire (actor, cmd); //Order bot to fire current weapon
}
else if (b->enemy && P_CheckSight (actor, b->enemy, 0)) //Fight!
else if (b->Bot.enemy && P_CheckSight (actor, b->Bot.enemy, 0)) //Fight!
{
Pitch (actor, b->enemy);
Pitch (actor, b->Bot.enemy);
//Check if it's more important to get an item than fight.
if (b->dest && (b->dest->flags&MF_SPECIAL)) //Must be an item, that is close enough.
if (b->Bot.dest && (b->Bot.dest->flags&MF_SPECIAL)) //Must be an item, that is close enough.
{
#define is(x) b->dest->IsKindOf (PClass::FindClass (#x))
#define is(x) b->Bot.dest->IsKindOf (PClass::FindClass (#x))
if (
(
(actor->health < b->skill.isp &&
(actor->health < b->Bot.skill.isp &&
(is (Medikit) ||
is (Stimpack) ||
is (Soulsphere) ||
@ -143,75 +143,75 @@ void FCajunMaster::ThinkForMove (AActor *actor, ticcmd_t *cmd)
(b->ReadyWeapon == NULL || b->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON)
)
&& (dist < GETINCOMBAT || (b->ReadyWeapon == NULL || b->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON))
&& Reachable (actor, b->dest))
&& Reachable (actor, b->Bot.dest))
#undef is
{
goto roam; //Pick it up, no matter the situation. All bonuses are nice close up.
}
}
b->dest = NULL; //To let bot turn right
b->Bot.dest = NULL; //To let bot turn right
if (b->ReadyWeapon != NULL && !(b->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON))
actor->flags &= ~MF_DROPOFF; //Don't jump off any ledges when fighting.
if (!(b->enemy->flags3 & MF3_ISMONSTER))
b->t_fight = AFTERTICS;
if (!(b->Bot.enemy->flags3 & MF3_ISMONSTER))
b->Bot.t_fight = AFTERTICS;
if (b->t_strafe <= 0 &&
(P_AproxDistance(actor->x-b->oldx, actor->y-b->oldy)<50000
if (b->Bot.t_strafe <= 0 &&
(P_AproxDistance(actor->x-b->Bot.oldx, actor->y-b->Bot.oldy)<50000
|| ((pr_botmove()%30)==10))
)
{
stuck = true;
b->t_strafe = 5;
b->sleft = !b->sleft;
b->Bot.t_strafe = 5;
b->Bot.sleft = !b->Bot.sleft;
}
b->angle = R_PointToAngle2(actor->x, actor->y, b->enemy->x, b->enemy->y);
b->Bot.angle = R_PointToAngle2(actor->x, actor->y, b->Bot.enemy->x, b->Bot.enemy->y);
if (b->ReadyWeapon == NULL ||
P_AproxDistance(actor->x-b->enemy->x, actor->y-b->enemy->y) >
P_AproxDistance(actor->x-b->Bot.enemy->x, actor->y-b->Bot.enemy->y) >
b->ReadyWeapon->MoveCombatDist)
{
// If a monster, use lower speed (just for cooler apperance while strafing down doomed monster)
cmd->ucmd.forwardmove = (b->enemy->flags3 & MF3_ISMONSTER) ? FORWARDWALK : FORWARDRUN;
cmd->ucmd.forwardmove = (b->Bot.enemy->flags3 & MF3_ISMONSTER) ? FORWARDWALK : FORWARDRUN;
}
else if (!stuck) //Too close, so move away.
{
// If a monster, use lower speed (just for cooler apperance while strafing down doomed monster)
cmd->ucmd.forwardmove = (b->enemy->flags3 & MF3_ISMONSTER) ? -FORWARDWALK : -FORWARDRUN;
cmd->ucmd.forwardmove = (b->Bot.enemy->flags3 & MF3_ISMONSTER) ? -FORWARDWALK : -FORWARDRUN;
}
//Strafing.
if (b->enemy->flags3 & MF3_ISMONSTER) //It's just a monster so take it down cool.
if (b->Bot.enemy->flags3 & MF3_ISMONSTER) //It's just a monster so take it down cool.
{
cmd->ucmd.sidemove = b->sleft ? -SIDEWALK : SIDEWALK;
cmd->ucmd.sidemove = b->Bot.sleft ? -SIDEWALK : SIDEWALK;
}
else
{
cmd->ucmd.sidemove = b->sleft ? -SIDERUN : SIDERUN;
cmd->ucmd.sidemove = b->Bot.sleft ? -SIDERUN : SIDERUN;
}
Dofire (actor, cmd); //Order bot to fire current weapon
}
else if (b->mate && !b->enemy && (!b->dest || b->dest==b->mate)) //Follow mate move.
else if (b->Bot.mate && !b->Bot.enemy && (!b->Bot.dest || b->Bot.dest==b->Bot.mate)) //Follow mate move.
{
fixed_t matedist;
Pitch (actor, b->mate);
Pitch (actor, b->Bot.mate);
if (!Reachable (actor, b->mate))
if (!Reachable (actor, b->Bot.mate))
{
if (b->mate == b->dest && pr_botmove.Random() < 32)
if (b->Bot.mate == b->Bot.dest && pr_botmove.Random() < 32)
{ // [RH] If the mate is the dest, pick a new dest sometimes
b->dest = NULL;
b->Bot.dest = NULL;
}
goto roam;
}
actor->player->angle = R_PointToAngle2(actor->x, actor->y, b->mate->x, b->mate->y);
actor->player->Bot.angle = R_PointToAngle2(actor->x, actor->y, b->Bot.mate->x, b->Bot.mate->y);
matedist = P_AproxDistance(actor->x - b->mate->x, actor->y - b->mate->y);
matedist = P_AproxDistance(actor->x - b->Bot.mate->x, actor->y - b->Bot.mate->y);
if (matedist > (FRIEND_DIST*2))
cmd->ucmd.forwardmove = FORWARDRUN;
else if (matedist > FRIEND_DIST)
@ -221,33 +221,33 @@ void FCajunMaster::ThinkForMove (AActor *actor, ticcmd_t *cmd)
}
else //Roam after something.
{
b->first_shot = true;
b->Bot.first_shot = true;
/////
roam:
/////
if (b->enemy && Check_LOS (actor, b->enemy, SHOOTFOV*3/2)) //If able to see enemy while avoiding missile , still fire at it.
if (b->Bot.enemy && Check_LOS (actor, b->Bot.enemy, SHOOTFOV*3/2)) //If able to see enemy while avoiding missile , still fire at it.
Dofire (actor, cmd); //Order bot to fire current weapon
if (b->dest && !(b->dest->flags&MF_SPECIAL) && b->dest->health < 0)
if (b->Bot.dest && !(b->Bot.dest->flags&MF_SPECIAL) && b->Bot.dest->health < 0)
{ //Roaming after something dead.
b->dest = NULL;
b->Bot.dest = NULL;
}
if (b->dest == NULL)
if (b->Bot.dest == NULL)
{
if (b->t_fight && b->enemy) //Enemy/bot has jumped around corner. So what to do?
if (b->Bot.t_fight && b->Bot.enemy) //Enemy/bot has jumped around corner. So what to do?
{
if (b->enemy->player)
if (b->Bot.enemy->player)
{
if (((b->enemy->player->ReadyWeapon != NULL && b->enemy->player->ReadyWeapon->WeaponFlags & WIF_BOT_EXPLOSIVE) ||
(pr_botmove()%100)>b->skill.isp) && b->ReadyWeapon != NULL && !(b->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON))
b->dest = b->enemy;//Dont let enemy kill the bot by supressive fire. So charge enemy.
if (((b->Bot.enemy->player->ReadyWeapon != NULL && b->Bot.enemy->player->ReadyWeapon->WeaponFlags & WIF_BOT_EXPLOSIVE) ||
(pr_botmove()%100)>b->Bot.skill.isp) && b->ReadyWeapon != NULL && !(b->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON))
b->Bot.dest = b->Bot.enemy;//Dont let enemy kill the bot by supressive fire. So charge enemy.
else //hide while b->t_fight, but keep view at enemy.
b->angle = R_PointToAngle2(actor->x, actor->y, b->enemy->x, b->enemy->y);
b->Bot.angle = R_PointToAngle2(actor->x, actor->y, b->Bot.enemy->x, b->Bot.enemy->y);
} //Just a monster, so kill it.
else
b->dest = b->enemy;
b->Bot.dest = b->Bot.enemy;
//VerifFavoritWeapon(actor->player); //Dont know why here.., but it must be here, i know the reason, but not why at this spot, uh.
}
@ -272,42 +272,42 @@ void FCajunMaster::ThinkForMove (AActor *actor, ticcmd_t *cmd)
item = it.Next();
}
firstthing = item;
b->dest = item;
b->Bot.dest = item;
}
}
else if (b->mate && (r < 179 || P_CheckSight(actor, b->mate)))
else if (b->Bot.mate && (r < 179 || P_CheckSight(actor, b->Bot.mate)))
{
b->dest = b->mate;
b->Bot.dest = b->Bot.mate;
}
else if ((playeringame[(r&(MAXPLAYERS-1))]) && players[(r&(MAXPLAYERS-1))].mo->health > 0)
{
b->dest = players[(r&(MAXPLAYERS-1))].mo;
b->Bot.dest = players[(r&(MAXPLAYERS-1))].mo;
}
}
if (b->dest)
if (b->Bot.dest)
{
b->t_roam = MAXROAM;
b->Bot.t_roam = MAXROAM;
}
}
if (b->dest)
if (b->Bot.dest)
{ //Bot has a target so roam after it.
Roam (actor, cmd);
}
} //End of movement main part.
if (!b->t_roam && b->dest)
if (!b->Bot.t_roam && b->Bot.dest)
{
b->prev = b->dest;
b->dest = NULL;
b->Bot.prev = b->Bot.dest;
b->Bot.dest = NULL;
}
if (b->t_fight<(AFTERTICS/2))
if (b->Bot.t_fight<(AFTERTICS/2))
actor->flags |= MF_DROPOFF;
b->oldx = actor->x;
b->oldy = actor->y;
b->Bot.oldx = actor->x;
b->Bot.oldy = actor->y;
}
//BOT_WhatToGet
@ -324,7 +324,7 @@ void FCajunMaster::WhatToGet (AActor *actor, AActor *item)
#define typeis(x) item->IsKindOf (PClass::FindClass (#x))
if ((item->renderflags & RF_INVISIBLE) //Under respawn and away.
|| item == b->prev)
|| item == b->Bot.prev)
{
return;
}
@ -366,21 +366,21 @@ void FCajunMaster::WhatToGet (AActor *actor, AActor *item)
else if (item->IsKindOf (RUNTIME_CLASS(AHealth)) && actor->health >= deh.MaxHealth /*MAXHEALTH*/)
return;
if ((b->dest == NULL ||
!(b->dest->flags & MF_SPECIAL)/* ||
if ((b->Bot.dest == NULL ||
!(b->Bot.dest->flags & MF_SPECIAL)/* ||
!Reachable (actor, b->dest)*/)/* &&
Reachable (actor, item)*/) // Calling Reachable slows this down tremendously
{
b->prev = b->dest;
b->dest = item;
b->t_roam = MAXROAM;
b->Bot.prev = b->Bot.dest;
b->Bot.dest = item;
b->Bot.t_roam = MAXROAM;
}
}
void FCajunMaster::Set_enemy (AActor *actor)
{
AActor *oldenemy;
AActor **enemy = &actor->player->enemy;
AActor **enemy = &actor->player->Bot.enemy;
if (*enemy
&& (*enemy)->health > 0
@ -397,7 +397,7 @@ void FCajunMaster::Set_enemy (AActor *actor)
// and we already have an existing enemy.
if (deathmatch || !*enemy)
{
actor->player->allround = !!*enemy;
actor->player->Bot.allround = !!*enemy;
*enemy = NULL;
*enemy = Find_enemy(actor);
if (!*enemy)