Differentiate between which side an object is on

This means that if there's objects on both sides of the bot, then the tie is broken by which side has the most objects. Before, it would average out to the middle, so they wouldn't swerve at all, which is kind of stupid for rings, but can ruin the bot's performance for dodging items & players especially!
This commit is contained in:
Sally Coolatta 2021-02-26 04:26:50 -05:00
parent 6142963ff9
commit ffaa4e2aa2

View file

@ -34,11 +34,11 @@ struct globalsmuggle
botprediction_t *predict; botprediction_t *predict;
fixed_t distancetocheck; fixed_t distancetocheck;
INT64 gotoAvgX, gotoAvgY; INT64 gotoAvgX[2], gotoAvgY[2];
UINT32 gotoObjs; UINT32 gotoObjs[2];
INT64 avoidAvgX, avoidAvgY; INT64 avoidAvgX[2], avoidAvgY[2];
UINT32 avoidObjs; UINT32 avoidObjs[2];
fixed_t closestlinedist; fixed_t closestlinedist;
@ -439,6 +439,7 @@ static boolean K_FindObjectsForNudging(mobj_t *thing)
INT16 anglediff; INT16 anglediff;
fixed_t fulldist; fixed_t fulldist;
angle_t destangle, angle, predictangle; angle_t destangle, angle, predictangle;
UINT8 side = 0;
if (!globalsmuggle.botmo || P_MobjWasRemoved(globalsmuggle.botmo) || !globalsmuggle.botmo->player) if (!globalsmuggle.botmo || P_MobjWasRemoved(globalsmuggle.botmo) || !globalsmuggle.botmo->player)
{ {
@ -478,6 +479,7 @@ static boolean K_FindObjectsForNudging(mobj_t *thing)
else else
{ {
anglediff = 360-(AngleFixed(angle)>>FRACBITS); anglediff = 360-(AngleFixed(angle)>>FRACBITS);
side = 1;
} }
anglediff = abs(anglediff); anglediff = abs(anglediff);
@ -491,6 +493,9 @@ static boolean K_FindObjectsForNudging(mobj_t *thing)
globalsmuggle.avoidAvgX += thing->x / mapobjectscale; \ globalsmuggle.avoidAvgX += thing->x / mapobjectscale; \
globalsmuggle.avoidAvgY += thing->y / mapobjectscale; \ globalsmuggle.avoidAvgY += thing->y / mapobjectscale; \
globalsmuggle.avoidObjs++; globalsmuggle.avoidObjs++;
globalsmuggle.avoidAvgX[side] += thing->x / mapobjectscale; \
globalsmuggle.avoidAvgY[side] += thing->y / mapobjectscale; \
globalsmuggle.avoidObjs[side]++; \
#define PlayerAttackSteer(botcond, thingcond) \ #define PlayerAttackSteer(botcond, thingcond) \
if ((botcond) && !(thingcond)) \ if ((botcond) && !(thingcond)) \
@ -521,7 +526,7 @@ static boolean K_FindObjectsForNudging(mobj_t *thing)
AddDodgeObj(thing) AddDodgeObj(thing)
break; break;
case MT_RANDOMITEM: case MT_RANDOMITEM:
if (anglediff >= 60) if (anglediff >= 45)
{ {
break; break;
} }
@ -532,7 +537,7 @@ static boolean K_FindObjectsForNudging(mobj_t *thing)
} }
break; break;
case MT_EGGMANITEM: case MT_EGGMANITEM:
if (anglediff >= 60) if (anglediff >= 45)
{ {
break; break;
} }
@ -553,7 +558,7 @@ static boolean K_FindObjectsForNudging(mobj_t *thing)
} }
break; break;
case MT_FLOATINGITEM: case MT_FLOATINGITEM:
if (anglediff >= 60) if (anglediff >= 45)
{ {
break; break;
} }
@ -565,7 +570,7 @@ static boolean K_FindObjectsForNudging(mobj_t *thing)
break; break;
case MT_RING: case MT_RING:
case MT_FLINGRING: case MT_FLINGRING:
if (anglediff >= 60) if (anglediff >= 45)
{ {
break; break;
} }
@ -647,7 +652,7 @@ static boolean K_FindObjectsForNudging(mobj_t *thing)
} }
break; break;
case MT_BOTHINT: case MT_BOTHINT:
if (anglediff >= 60) if (anglediff >= 45)
{ {
break; break;
} }
@ -687,16 +692,22 @@ void K_NudgePredictionTowardsObjects(botprediction_t *predict, player_t *player)
fixed_t nudgeDist = 0; fixed_t nudgeDist = 0;
angle_t nudgeDir = 0; angle_t nudgeDir = 0;
SINT8 gotoSide = -1;
UINT8 i;
globalsmuggle.botmo = player->mo; globalsmuggle.botmo = player->mo;
globalsmuggle.predict = predict; globalsmuggle.predict = predict;
globalsmuggle.distancetocheck = R_PointToDist2(player->mo->x, player->mo->y, predict->x, predict->y); globalsmuggle.distancetocheck = R_PointToDist2(player->mo->x, player->mo->y, predict->x, predict->y);
globalsmuggle.gotoAvgX = globalsmuggle.gotoAvgY = 0; for (i = 0; i < 2; i++)
globalsmuggle.gotoObjs = 0; {
globalsmuggle.gotoAvgX[i] = globalsmuggle.gotoAvgY[i] = 0;
globalsmuggle.gotoObjs[i] = 0;
globalsmuggle.avoidAvgX = globalsmuggle.avoidAvgY = 0; globalsmuggle.avoidAvgX[i] = globalsmuggle.avoidAvgY[i] = 0;
globalsmuggle.avoidObjs = 0; globalsmuggle.avoidObjs[i] = 0;
}
xl = (unsigned)(globalsmuggle.botmo->x - globalsmuggle.distancetocheck - bmaporgx)>>MAPBLOCKSHIFT; xl = (unsigned)(globalsmuggle.botmo->x - globalsmuggle.distancetocheck - bmaporgx)>>MAPBLOCKSHIFT;
xh = (unsigned)(globalsmuggle.botmo->x + globalsmuggle.distancetocheck - bmaporgx)>>MAPBLOCKSHIFT; xh = (unsigned)(globalsmuggle.botmo->x + globalsmuggle.distancetocheck - bmaporgx)>>MAPBLOCKSHIFT;
@ -713,17 +724,27 @@ void K_NudgePredictionTowardsObjects(botprediction_t *predict, player_t *player)
} }
} }
if (globalsmuggle.avoidObjs > 0) // Handle dodge characters
if (globalsmuggle.avoidObjs[1] > 0 || globalsmuggle.avoidObjs[0] > 0)
{ {
avgX = (globalsmuggle.avoidAvgX / globalsmuggle.avoidObjs) * mapobjectscale; if (globalsmuggle.avoidObjs[1] > globalsmuggle.avoidObjs[0])
avgY = (globalsmuggle.avoidAvgY / globalsmuggle.avoidObjs) * mapobjectscale; {
gotoSide = 1;
}
else
{
gotoSide = 0;
}
avgX = (globalsmuggle.avoidAvgX[gotoSide] / globalsmuggle.avoidObjs[gotoSide]) * mapobjectscale;
avgY = (globalsmuggle.avoidAvgY[gotoSide] / globalsmuggle.avoidObjs[gotoSide]) * mapobjectscale;
avgDist = R_PointToDist2( avgDist = R_PointToDist2(
avgX, avgY, avgX, avgY,
predict->x, predict->y predict->x, predict->y
); );
// Light-weight characters dodge better // High handling characters dodge better
nudgeDist = ((9 - globalsmuggle.botmo->player->kartweight) + 1) * baseNudge; nudgeDist = ((9 - globalsmuggle.botmo->player->kartweight) + 1) * baseNudge;
if (nudgeDist > predict->radius) if (nudgeDist > predict->radius)
@ -741,10 +762,33 @@ void K_NudgePredictionTowardsObjects(botprediction_t *predict, player_t *player)
predict->y += FixedMul(nudgeDist, FINESINE(nudgeDir >> ANGLETOFINESHIFT)); predict->y += FixedMul(nudgeDist, FINESINE(nudgeDir >> ANGLETOFINESHIFT));
} }
if (globalsmuggle.gotoObjs > 0) if (gotoSide == -1)
{ {
avgX = (globalsmuggle.gotoAvgX / globalsmuggle.gotoObjs) * mapobjectscale; // Pick a side here if there were no objects to dodge.
avgY = (globalsmuggle.gotoAvgY / globalsmuggle.gotoObjs) * mapobjectscale; // We don't want to pick contradictory sides, so keep the old side otherwise,
// even if there's more to grab on the other side.
if (globalsmuggle.gotoObjs[1] > globalsmuggle.gotoObjs[0])
{
gotoSide = 1;
}
else
{
gotoSide = 0;
}
}
// Check if our side is invalid, if so, don't do the code below.
if (gotoSide != -1 && globalsmuggle.gotoObjs[gotoSide] == 0)
{
// Do not use a side
gotoSide = -1;
}
if (gotoSide != -1)
{
avgX = (globalsmuggle.gotoAvgX[gotoSide] / globalsmuggle.gotoObjs[gotoSide]) * mapobjectscale;
avgY = (globalsmuggle.gotoAvgY[gotoSide] / globalsmuggle.gotoObjs[gotoSide]) * mapobjectscale;
avgDist = R_PointToDist2( avgDist = R_PointToDist2(
predict->x, predict->y, predict->x, predict->y,