mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-12-12 11:03:02 +00:00
Start on better bot position
This commit is contained in:
parent
b9f91cb7ec
commit
46dad4b7dd
3 changed files with 470 additions and 139 deletions
355
src/k_bot.c
355
src/k_bot.c
|
|
@ -1028,87 +1028,27 @@ static void K_BotTrick(player_t *player, ticcmd_t *cmd, line_t *botController)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------
|
/*--------------------------------------------------
|
||||||
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
static INT32 K_HandleBotTrack(player_t *player, ticcmd_t *cmd, botprediction_t *predict)
|
||||||
|
|
||||||
See header file for description.
|
Determines inputs for standard track driving.
|
||||||
|
|
||||||
|
Input Arguments:-
|
||||||
|
player - Player to generate the ticcmd for.
|
||||||
|
cmd - The player's ticcmd to modify.
|
||||||
|
predict - Pointer to the bot's prediction.
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
New value for turn amount.
|
||||||
--------------------------------------------------*/
|
--------------------------------------------------*/
|
||||||
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
static INT32 K_HandleBotTrack(player_t *player, ticcmd_t *cmd, botprediction_t *predict, angle_t destangle)
|
||||||
{
|
{
|
||||||
botprediction_t *predict = NULL;
|
|
||||||
boolean trySpindash = true;
|
|
||||||
UINT8 spindash = 0;
|
|
||||||
INT32 turnamt = 0;
|
|
||||||
line_t *botController = NULL;
|
|
||||||
|
|
||||||
// Can't build a ticcmd if we aren't spawned...
|
|
||||||
if (!player->mo)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove any existing controls
|
|
||||||
memset(cmd, 0, sizeof(ticcmd_t));
|
|
||||||
|
|
||||||
if (
|
|
||||||
gamestate != GS_LEVEL
|
|
||||||
|| player->mo->scale <= 1
|
|
||||||
|| player->playerstate == PST_DEAD
|
|
||||||
|| leveltime <= introtime
|
|
||||||
|| (player->exiting && !(gametyperules & GTR_CIRCUIT))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// No need to do anything else.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Complete override of all ticcmd functionality
|
|
||||||
if (LUAh_BotTiccmd(player, cmd) == true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
botController = K_FindBotController(player->mo);
|
|
||||||
|
|
||||||
if (player->trickpanel != 0)
|
|
||||||
{
|
|
||||||
K_BotTrick(player, cmd, botController);
|
|
||||||
|
|
||||||
// Don't do anything else.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((player->nextwaypoint != NULL
|
|
||||||
&& player->nextwaypoint->mobj != NULL
|
|
||||||
&& !P_MobjWasRemoved(player->nextwaypoint->mobj))
|
|
||||||
|| (botController != NULL))
|
|
||||||
{
|
|
||||||
// Handle steering towards waypoints!
|
// Handle steering towards waypoints!
|
||||||
|
INT32 turnamt = 0;
|
||||||
SINT8 turnsign = 0;
|
SINT8 turnsign = 0;
|
||||||
angle_t destangle, moveangle, angle;
|
angle_t moveangle, angle;
|
||||||
INT16 anglediff;
|
INT16 anglediff;
|
||||||
|
|
||||||
if (botController != NULL && (botController->flags & ML_EFFECT1))
|
I_Assert(predict != NULL);
|
||||||
{
|
|
||||||
const fixed_t dist = (player->mo->radius * 4);
|
|
||||||
|
|
||||||
// X Offset: Movement direction
|
|
||||||
destangle = FixedAngle(sides[botController->sidenum[0]].textureoffset);
|
|
||||||
|
|
||||||
// Overwritten prediction
|
|
||||||
predict = Z_Calloc(sizeof(botprediction_t), PU_STATIC, NULL);
|
|
||||||
|
|
||||||
predict->x = player->mo->x + FixedMul(dist, FINECOSINE(destangle >> ANGLETOFINESHIFT));
|
|
||||||
predict->y = player->mo->y + FixedMul(dist, FINESINE(destangle >> ANGLETOFINESHIFT));
|
|
||||||
predict->radius = (DEFAULT_WAYPOINT_RADIUS / 4) * mapobjectscale;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
predict = K_CreateBotPrediction(player);
|
|
||||||
|
|
||||||
K_NudgePredictionTowardsObjects(predict, player);
|
|
||||||
|
|
||||||
destangle = R_PointToAngle2(player->mo->x, player->mo->y, predict->x, predict->y);
|
|
||||||
}
|
|
||||||
|
|
||||||
moveangle = player->mo->angle;
|
moveangle = player->mo->angle;
|
||||||
angle = (moveangle - destangle);
|
angle = (moveangle - destangle);
|
||||||
|
|
@ -1193,10 +1133,171 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return turnamt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
static INT32 K_HandleBotReverse(player_t *player, ticcmd_t *cmd, botprediction_t *predict)
|
||||||
|
|
||||||
|
Determines inputs for reversing.
|
||||||
|
|
||||||
|
Input Arguments:-
|
||||||
|
player - Player to generate the ticcmd for.
|
||||||
|
cmd - The player's ticcmd to modify.
|
||||||
|
predict - Pointer to the bot's prediction.
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
New value for turn amount.
|
||||||
|
--------------------------------------------------*/
|
||||||
|
static INT32 K_HandleBotReverse(player_t *player, ticcmd_t *cmd, botprediction_t *predict, angle_t destangle)
|
||||||
|
{
|
||||||
|
// Handle steering towards waypoints!
|
||||||
|
INT32 turnamt = 0;
|
||||||
|
SINT8 turnsign = 0;
|
||||||
|
angle_t moveangle, angle;
|
||||||
|
INT16 anglediff;
|
||||||
|
|
||||||
|
if (predict != NULL)
|
||||||
|
{
|
||||||
|
// TODO: Should we reverse through bot controllers?
|
||||||
|
return K_HandleBotTrack(player, cmd, predict, destangle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player->nextwaypoint == NULL
|
||||||
|
|| player->nextwaypoint->mobj != NULL
|
||||||
|
|| P_MobjWasRemoved(player->nextwaypoint->mobj))
|
||||||
|
{
|
||||||
|
// No data available...
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((player->nextwaypoint->prevwaypoints != NULL)
|
||||||
|
&& (player->nextwaypoint->numprevwaypoints > 0U))
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0U; i < player->nextwaypoint->numprevwaypoints; i++)
|
||||||
|
{
|
||||||
|
if (!K_GetWaypointIsEnabled(player->nextwaypoint->prevwaypoints[i]))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
destangle = R_PointToAngle2(
|
||||||
|
player->nextwaypoint->prevwaypoints[i]->mobj->x, player->nextwaypoint->prevwaypoints[i]->mobj->y,
|
||||||
|
player->nextwaypoint->mobj->x, player->nextwaypoint->mobj->y
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moveangle = player->mo->angle;
|
||||||
|
angle = (moveangle - destangle);
|
||||||
|
|
||||||
|
if (angle < ANGLE_180)
|
||||||
|
{
|
||||||
|
turnsign = -1; // Turn right
|
||||||
|
anglediff = AngleFixed(angle)>>FRACBITS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
turnsign = 1; // Turn left
|
||||||
|
anglediff = 360-(AngleFixed(angle)>>FRACBITS);
|
||||||
|
}
|
||||||
|
|
||||||
|
anglediff = abs(anglediff);
|
||||||
|
turnamt = KART_FULLTURN * turnsign;
|
||||||
|
|
||||||
|
if (anglediff > 90)
|
||||||
|
{
|
||||||
|
// We're not facing the track...
|
||||||
|
cmd->forwardmove = 0;
|
||||||
|
cmd->buttons |= BT_ACCELERATE|BT_BRAKE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (anglediff < 10)
|
||||||
|
{
|
||||||
|
turnamt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd->forwardmove = -MAXPLMOVE;
|
||||||
|
cmd->buttons |= BT_BRAKE|BT_LOOKBACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return turnamt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
||||||
|
|
||||||
|
See header file for description.
|
||||||
|
--------------------------------------------------*/
|
||||||
|
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
||||||
|
{
|
||||||
|
botprediction_t *predict = NULL;
|
||||||
|
boolean trySpindash = true;
|
||||||
|
angle_t destangle = 0;
|
||||||
|
UINT8 spindash = 0;
|
||||||
|
INT32 turnamt = 0;
|
||||||
|
line_t *botController = NULL;
|
||||||
|
|
||||||
|
// Can't build a ticcmd if we aren't spawned...
|
||||||
|
if (!player->mo)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any existing controls
|
||||||
|
memset(cmd, 0, sizeof(ticcmd_t));
|
||||||
|
|
||||||
|
if (gamestate != GS_LEVEL
|
||||||
|
|| player->mo->scale <= 1
|
||||||
|
|| player->playerstate == PST_DEAD
|
||||||
|
|| leveltime <= introtime
|
||||||
|
|| !(gametyperules & GTR_BOTS))
|
||||||
|
{
|
||||||
|
// No need to do anything else.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete override of all ticcmd functionality
|
||||||
|
if (LUAh_BotTiccmd(player, cmd) == true)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
botController = K_FindBotController(player->mo);
|
||||||
|
|
||||||
|
if (player->trickpanel != 0)
|
||||||
|
{
|
||||||
|
K_BotTrick(player, cmd, botController);
|
||||||
|
|
||||||
|
// Don't do anything else.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
destangle = player->mo->angle;
|
||||||
|
|
||||||
|
if (botController != NULL && (botController->flags & ML_EFFECT1))
|
||||||
|
{
|
||||||
|
const fixed_t dist = (player->mo->radius * 4);
|
||||||
|
|
||||||
|
// X Offset: Movement direction
|
||||||
|
destangle = FixedAngle(sides[botController->sidenum[0]].textureoffset);
|
||||||
|
|
||||||
|
// Overwritten prediction
|
||||||
|
predict = Z_Calloc(sizeof(botprediction_t), PU_STATIC, NULL);
|
||||||
|
|
||||||
|
predict->x = player->mo->x + FixedMul(dist, FINECOSINE(destangle >> ANGLETOFINESHIFT));
|
||||||
|
predict->y = player->mo->y + FixedMul(dist, FINESINE(destangle >> ANGLETOFINESHIFT));
|
||||||
|
predict->radius = (DEFAULT_WAYPOINT_RADIUS / 4) * mapobjectscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leveltime <= starttime && finishBeamLine != NULL)
|
if (leveltime <= starttime && finishBeamLine != NULL)
|
||||||
{
|
{
|
||||||
|
// Handle POSITION!!
|
||||||
const fixed_t distBase = 384*mapobjectscale;
|
const fixed_t distBase = 384*mapobjectscale;
|
||||||
const fixed_t distAdjust = 64*mapobjectscale;
|
const fixed_t distAdjust = 64*mapobjectscale;
|
||||||
|
|
||||||
|
|
@ -1212,35 +1313,100 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
||||||
// Don't run the spindash code at all until we're in the right place
|
// Don't run the spindash code at all until we're in the right place
|
||||||
trySpindash = false;
|
trySpindash = false;
|
||||||
|
|
||||||
// If you're too far, enable spindash & stay still.
|
#define QuickDebugPrint(input) \
|
||||||
// If you're too close, start backing up.
|
if (player - players == displayplayers[0]) \
|
||||||
|
CONS_Printf(input);
|
||||||
|
|
||||||
if (distToFinish < closeDist)
|
if (distToFinish < closeDist)
|
||||||
{
|
{
|
||||||
// Silly way of getting us to reverse, but it respects the above code
|
// We're too close, we need to start backing up.
|
||||||
// where we figure out what the shape of the track looks like.
|
turnamt = K_HandleBotReverse(player, cmd, predict, destangle);
|
||||||
UINT16 oldButtons = cmd->buttons;
|
QuickDebugPrint("Too close\n");
|
||||||
|
|
||||||
cmd->buttons &= ~(BT_ACCELERATE|BT_BRAKE);
|
|
||||||
|
|
||||||
if (oldButtons & BT_ACCELERATE)
|
|
||||||
{
|
|
||||||
cmd->buttons |= BT_BRAKE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldButtons & BT_BRAKE)
|
|
||||||
{
|
|
||||||
cmd->buttons |= BT_ACCELERATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd->forwardmove = -cmd->forwardmove;
|
|
||||||
}
|
}
|
||||||
else if (distToFinish < farDist)
|
else if (distToFinish < farDist)
|
||||||
{
|
{
|
||||||
// We're in about the right place, spindash now.
|
INT32 bullyTurn = INT32_MAX;
|
||||||
|
|
||||||
|
// We're in about the right place, let's do whatever we want to.
|
||||||
|
|
||||||
|
if (player->kartspeed > 3)
|
||||||
|
{
|
||||||
|
// Faster characters want to spindash.
|
||||||
|
// Slower characters will use their momentum.
|
||||||
|
trySpindash = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for characters to bully.
|
||||||
|
bullyTurn = K_PositionBully(player);
|
||||||
|
if (bullyTurn == INT32_MAX)
|
||||||
|
{
|
||||||
|
// No one to bully, just go for a spindash as anyone.
|
||||||
|
if (predict == NULL)
|
||||||
|
{
|
||||||
|
// Create a prediction.
|
||||||
|
if (player->nextwaypoint != NULL
|
||||||
|
&& player->nextwaypoint->mobj != NULL
|
||||||
|
&& !P_MobjWasRemoved(player->nextwaypoint->mobj))
|
||||||
|
{
|
||||||
|
predict = K_CreateBotPrediction(player);
|
||||||
|
K_NudgePredictionTowardsObjects(predict, player);
|
||||||
|
destangle = R_PointToAngle2(player->mo->x, player->mo->y, predict->x, predict->y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QuickDebugPrint("No one to bully\n");
|
||||||
|
turnamt = K_HandleBotTrack(player, cmd, predict, destangle);
|
||||||
|
cmd->buttons &= ~(BT_ACCELERATE|BT_BRAKE);
|
||||||
cmd->forwardmove = 0;
|
cmd->forwardmove = 0;
|
||||||
trySpindash = true;
|
trySpindash = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QuickDebugPrint("Go get 'em\n");
|
||||||
|
turnamt = bullyTurn;
|
||||||
|
|
||||||
|
trySpindash = false;
|
||||||
|
cmd->buttons |= BT_ACCELERATE;
|
||||||
|
cmd->forwardmove = MAXPLMOVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QuickDebugPrint("Too far\n");
|
||||||
|
// Too far away, we need to just drive up.
|
||||||
|
if (predict == NULL)
|
||||||
|
{
|
||||||
|
// Create a prediction.
|
||||||
|
if (player->nextwaypoint != NULL
|
||||||
|
&& player->nextwaypoint->mobj != NULL
|
||||||
|
&& !P_MobjWasRemoved(player->nextwaypoint->mobj))
|
||||||
|
{
|
||||||
|
predict = K_CreateBotPrediction(player);
|
||||||
|
K_NudgePredictionTowardsObjects(predict, player);
|
||||||
|
destangle = R_PointToAngle2(player->mo->x, player->mo->y, predict->x, predict->y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
turnamt = K_HandleBotTrack(player, cmd, predict, destangle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Handle steering towards waypoints!
|
||||||
|
if (predict == NULL)
|
||||||
|
{
|
||||||
|
// Create a prediction.
|
||||||
|
if (player->nextwaypoint != NULL
|
||||||
|
&& player->nextwaypoint->mobj != NULL
|
||||||
|
&& !P_MobjWasRemoved(player->nextwaypoint->mobj))
|
||||||
|
{
|
||||||
|
predict = K_CreateBotPrediction(player);
|
||||||
|
K_NudgePredictionTowardsObjects(predict, player);
|
||||||
|
destangle = R_PointToAngle2(player->mo->x, player->mo->y, predict->x, predict->y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
turnamt = K_HandleBotTrack(player, cmd, predict, destangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trySpindash == true)
|
if (trySpindash == true)
|
||||||
|
|
@ -1325,4 +1491,3 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
||||||
Z_Free(predict);
|
Z_Free(predict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
15
src/k_bot.h
15
src/k_bot.h
|
|
@ -223,6 +223,21 @@ boolean K_BotHatesThisSector(player_t *player, sector_t *sec, fixed_t x, fixed_t
|
||||||
void K_NudgePredictionTowardsObjects(botprediction_t *predict, player_t *player);
|
void K_NudgePredictionTowardsObjects(botprediction_t *predict, player_t *player);
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
INT32 K_PositionBully(player_t *player)
|
||||||
|
|
||||||
|
Calculates a turn value to reach a player that can be bullied.
|
||||||
|
|
||||||
|
Input Arguments:-
|
||||||
|
player - Bot to run this for.
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
INT32_MAX if couldn't find anything, otherwise a steering value.
|
||||||
|
--------------------------------------------------*/
|
||||||
|
|
||||||
|
INT32 K_PositionBully(player_t *player);
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------
|
/*--------------------------------------------------
|
||||||
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd);
|
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,9 @@ struct globalsmuggle
|
||||||
INT64 avoidAvgX[2], avoidAvgY[2];
|
INT64 avoidAvgX[2], avoidAvgY[2];
|
||||||
UINT32 avoidObjs[2];
|
UINT32 avoidObjs[2];
|
||||||
|
|
||||||
|
fixed_t annoyscore;
|
||||||
|
mobj_t *annoymo;
|
||||||
|
|
||||||
fixed_t closestlinedist;
|
fixed_t closestlinedist;
|
||||||
|
|
||||||
fixed_t eggboxx, eggboxy;
|
fixed_t eggboxx, eggboxy;
|
||||||
|
|
@ -771,3 +774,151 @@ void K_NudgePredictionTowardsObjects(botprediction_t *predict, player_t *player)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
static boolean K_FindPlayersToBully(mobj_t *thing)
|
||||||
|
|
||||||
|
Blockmap search function.
|
||||||
|
Finds players around the bot to bump.
|
||||||
|
|
||||||
|
Input Arguments:-
|
||||||
|
thing - Object passed in from iteration.
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
true continues searching, false ends the search early.
|
||||||
|
--------------------------------------------------*/
|
||||||
|
static boolean K_FindPlayersToBully(mobj_t *thing)
|
||||||
|
{
|
||||||
|
INT16 anglediff;
|
||||||
|
fixed_t fulldist;
|
||||||
|
fixed_t ourweight, theirweight, weightdiff;
|
||||||
|
angle_t ourangle, destangle, angle;
|
||||||
|
|
||||||
|
if (!globalsmuggle.botmo || P_MobjWasRemoved(globalsmuggle.botmo) || !globalsmuggle.botmo->player)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thing->health <= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!thing->player)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globalsmuggle.botmo == thing)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fulldist = R_PointToDist2(globalsmuggle.botmo->x, globalsmuggle.botmo->y, thing->x, thing->y) - thing->radius;
|
||||||
|
|
||||||
|
if (fulldist > globalsmuggle.distancetocheck)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (P_CheckSight(globalsmuggle.botmo, thing) == false)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ourangle = globalsmuggle.botmo->angle;
|
||||||
|
destangle = R_PointToAngle2(globalsmuggle.botmo->x, globalsmuggle.botmo->y, thing->x, thing->y);
|
||||||
|
angle = (ourangle - destangle);
|
||||||
|
|
||||||
|
if (angle < ANGLE_180)
|
||||||
|
{
|
||||||
|
anglediff = AngleFixed(angle)>>FRACBITS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
anglediff = 360-(AngleFixed(angle)>>FRACBITS);
|
||||||
|
}
|
||||||
|
|
||||||
|
anglediff = abs(anglediff);
|
||||||
|
|
||||||
|
ourweight = K_GetMobjWeight(globalsmuggle.botmo, thing);
|
||||||
|
theirweight = K_GetMobjWeight(thing, globalsmuggle.botmo);
|
||||||
|
weightdiff = 0;
|
||||||
|
|
||||||
|
if (anglediff >= 90)
|
||||||
|
{
|
||||||
|
weightdiff = theirweight - ourweight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
weightdiff = ourweight - theirweight;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (weightdiff > mapobjectscale && weightdiff > globalsmuggle.annoyscore)
|
||||||
|
{
|
||||||
|
globalsmuggle.annoyscore = weightdiff;
|
||||||
|
globalsmuggle.annoymo = thing;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
INT32 K_PositionBully(player_t *player)
|
||||||
|
|
||||||
|
See header file for description.
|
||||||
|
--------------------------------------------------*/
|
||||||
|
INT32 K_PositionBully(player_t *player)
|
||||||
|
{
|
||||||
|
INT32 xl, xh, yl, yh, bx, by;
|
||||||
|
|
||||||
|
angle_t ourangle, destangle, angle;
|
||||||
|
INT16 anglediff;
|
||||||
|
|
||||||
|
globalsmuggle.botmo = player->mo;
|
||||||
|
globalsmuggle.distancetocheck = 1024*player->mo->scale;
|
||||||
|
|
||||||
|
globalsmuggle.annoymo = NULL;
|
||||||
|
globalsmuggle.annoyscore = 0;
|
||||||
|
|
||||||
|
xl = (unsigned)(globalsmuggle.botmo->x - globalsmuggle.distancetocheck - bmaporgx)>>MAPBLOCKSHIFT;
|
||||||
|
xh = (unsigned)(globalsmuggle.botmo->x + globalsmuggle.distancetocheck - bmaporgx)>>MAPBLOCKSHIFT;
|
||||||
|
yl = (unsigned)(globalsmuggle.botmo->y - globalsmuggle.distancetocheck - bmaporgy)>>MAPBLOCKSHIFT;
|
||||||
|
yh = (unsigned)(globalsmuggle.botmo->y + globalsmuggle.distancetocheck - bmaporgy)>>MAPBLOCKSHIFT;
|
||||||
|
|
||||||
|
BMBOUNDFIX(xl, xh, yl, yh);
|
||||||
|
|
||||||
|
for (bx = xl; bx <= xh; bx++)
|
||||||
|
{
|
||||||
|
for (by = yl; by <= yh; by++)
|
||||||
|
{
|
||||||
|
P_BlockThingsIterator(bx, by, K_FindPlayersToBully);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globalsmuggle.annoymo == NULL)
|
||||||
|
{
|
||||||
|
return INT32_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
ourangle = globalsmuggle.botmo->angle;
|
||||||
|
destangle = R_PointToAngle2(globalsmuggle.botmo->x, globalsmuggle.botmo->y, globalsmuggle.annoymo->x, globalsmuggle.annoymo->y);
|
||||||
|
angle = (ourangle - destangle);
|
||||||
|
|
||||||
|
if (angle < ANGLE_180)
|
||||||
|
{
|
||||||
|
anglediff = AngleFixed(angle)>>FRACBITS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
anglediff = 360-(AngleFixed(angle)>>FRACBITS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anglediff < 30)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (anglediff < 0)
|
||||||
|
return -KART_FULLTURN;
|
||||||
|
|
||||||
|
return KART_FULLTURN;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue