Skip to content

Commit

Permalink
Merged bot AI enhancement by TheDoctor
Browse files Browse the repository at this point in the history
Thank you for your help

git-svn-id: https://smokinguns.svn.sourceforge.net/svnroot/smokinguns/trunk@657 07eb42f0-b032-4355-afd3-42b1f3832223
  • Loading branch information
sg_tequila committed Dec 15, 2012
1 parent 036053b commit ea44711
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 247 deletions.
20 changes: 14 additions & 6 deletions code/botlib/be_ai_goal.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2005-2010 Smokin' Guns
Copyright (C) 2005-2012 Smokin' Guns
This file is part of Smokin' Guns.
Expand Down Expand Up @@ -239,11 +239,9 @@ void BotInterbreedGoalFuzzyLogic(int parent1, int parent2, int child)
//===========================================================================
void BotSaveGoalFuzzyLogic(int goalstate, char *filename)
{
bot_goalstate_t *gs;

// bot_goalstate_t *gs;

//gs =
BotGoalStateFromHandle(goalstate);
gs = BotGoalStateFromHandle(goalstate);

//WriteWeightConfig(filename, gs->itemweightconfig);
} //end of the function BotSaveGoalFuzzyLogic
Expand Down Expand Up @@ -1480,8 +1478,13 @@ int BotChooseNBGItem(int goalstate, vec3_t origin, int *inventory, int travelfla
//if the bot is in solid or if the area the bot is in has no reachability links
if (!areanum || !AAS_AreaReachability(areanum))
{
#ifdef DEBUG
botimport.Print(PRT_MESSAGE, "bot is in solid or area has no reachability links: %d %d\n",areanum,gs->lastreachabilityarea);
#endif
//use the last valid area the bot was in
areanum = gs->lastreachabilityarea;
if (gs->lastreachabilityarea>0) {
areanum = gs->lastreachabilityarea;
}
} //end if
//remember the last area with reachabilities the bot was in
gs->lastreachabilityarea = areanum;
Expand Down Expand Up @@ -1569,7 +1572,12 @@ int BotChooseNBGItem(int goalstate, vec3_t origin, int *inventory, int travelfla
bestweight = weight;
bestitem = li;
} //end if
}
#ifdef DEBUG
else {
botimport.Print(PRT_MESSAGE, "can't reach %d\n", li->entitynum);
} //end if
#endif
} //end if
} //end if
} //end for
Expand Down
24 changes: 15 additions & 9 deletions code/botlib/be_ai_move.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2005-2010 Smokin' Guns
Copyright (C) 2005-2012 Smokin' Guns
This file is part of Smokin' Guns.
Expand Down Expand Up @@ -656,10 +656,11 @@ int BotAvoidSpots(vec3_t origin, aas_reachability_t *reach, bot_avoidspot_t *avo

switch(reach->traveltype & TRAVELTYPE_MASK)
{
// TheDoctor: put priority on ladder travel
case TRAVEL_LADDER: checkbetween = qtrue; break;
case TRAVEL_WALK: checkbetween = qtrue; break;
case TRAVEL_CROUCH: checkbetween = qtrue; break;
case TRAVEL_BARRIERJUMP: checkbetween = qtrue; break;
case TRAVEL_LADDER: checkbetween = qtrue; break;
case TRAVEL_WALKOFFLEDGE: checkbetween = qfalse; break;
case TRAVEL_JUMP: checkbetween = qfalse; break;
case TRAVEL_SWIM: checkbetween = qtrue; break;
Expand Down Expand Up @@ -1492,6 +1493,7 @@ bot_moveresult_t BotTravel_BarrierJump(bot_movestate_t *ms, aas_reachability_t *
//===========================================================================
bot_moveresult_t BotFinishTravel_BarrierJump(bot_movestate_t *ms, aas_reachability_t *reach)
{
float dist;
vec3_t hordir;
bot_moveresult_t_cleared( result );

Expand All @@ -1501,7 +1503,7 @@ bot_moveresult_t BotFinishTravel_BarrierJump(bot_movestate_t *ms, aas_reachabili
hordir[0] = reach->end[0] - ms->origin[0];
hordir[1] = reach->end[1] - ms->origin[1];
hordir[2] = 0;
VectorNormalize(hordir);
dist = VectorNormalize(hordir);
//
BotCheckBlocked(ms, hordir, qtrue, &result);
//
Expand Down Expand Up @@ -1578,6 +1580,7 @@ bot_moveresult_t BotTravel_WaterJump(bot_movestate_t *ms, aas_reachability_t *re
bot_moveresult_t BotFinishTravel_WaterJump(bot_movestate_t *ms, aas_reachability_t *reach)
{
vec3_t dir, pnt;
float dist;
bot_moveresult_t_cleared( result );

//botimport.Print(PRT_MESSAGE, "BotFinishTravel_WaterJump\n");
Expand All @@ -1593,7 +1596,7 @@ bot_moveresult_t BotFinishTravel_WaterJump(bot_movestate_t *ms, aas_reachability
dir[0] += crandom() * 10;
dir[1] += crandom() * 10;
dir[2] += 70 + crandom() * 10;
VectorNormalize(dir);
dist = VectorNormalize(dir);
//elemantary actions
EA_Move(ms->client, dir, 400);
//set the ideal view angles
Expand Down Expand Up @@ -2877,15 +2880,15 @@ bot_moveresult_t BotFinishTravel_WeaponJump(bot_movestate_t *ms, aas_reachabilit
//===========================================================================
bot_moveresult_t BotTravel_JumpPad(bot_movestate_t *ms, aas_reachability_t *reach)
{
float speed;
float dist, speed;
vec3_t hordir;
bot_moveresult_t_cleared( result );

//first walk straight to the reachability start
hordir[0] = reach->start[0] - ms->origin[0];
hordir[1] = reach->start[1] - ms->origin[1];
hordir[2] = 0;
VectorNormalize(hordir);
dist = VectorNormalize(hordir);
//
BotCheckBlocked(ms, hordir, qtrue, &result);
speed = 400;
Expand Down Expand Up @@ -2933,10 +2936,11 @@ int BotReachabilityTime(aas_reachability_t *reach)
{
switch(reach->traveltype & TRAVELTYPE_MASK)
{
// TheDoctor: put priority on ladder travel
case TRAVEL_LADDER: return 6;
case TRAVEL_WALK: return 5;
case TRAVEL_CROUCH: return 5;
case TRAVEL_BARRIERJUMP: return 5;
case TRAVEL_LADDER: return 6;
case TRAVEL_WALKOFFLEDGE: return 5;
case TRAVEL_JUMP: return 5;
case TRAVEL_SWIM: return 5;
Expand Down Expand Up @@ -3325,10 +3329,11 @@ void BotMoveToGoal(bot_moveresult_t *result, int movestate, bot_goal_t *goal, in
#endif //DEBUG
switch(reach.traveltype & TRAVELTYPE_MASK)
{
// TheDoctor: put priority on ladder travel
case TRAVEL_LADDER: *result = BotTravel_Ladder(ms, &reach); break;
case TRAVEL_WALK: *result = BotTravel_Walk(ms, &reach); break;
case TRAVEL_CROUCH: *result = BotTravel_Crouch(ms, &reach); break;
case TRAVEL_BARRIERJUMP: *result = BotTravel_BarrierJump(ms, &reach); break;
case TRAVEL_LADDER: *result = BotTravel_Ladder(ms, &reach); break;
case TRAVEL_WALKOFFLEDGE: *result = BotTravel_WalkOffLedge(ms, &reach); break;
case TRAVEL_JUMP: *result = BotTravel_Jump(ms, &reach); break;
case TRAVEL_SWIM: *result = BotTravel_Swim(ms, &reach); break;
Expand Down Expand Up @@ -3434,10 +3439,11 @@ void BotMoveToGoal(bot_moveresult_t *result, int movestate, bot_goal_t *goal, in
//
switch(reach.traveltype & TRAVELTYPE_MASK)
{
// TheDoctor: put priority on ladder travel
case TRAVEL_LADDER: *result = BotTravel_Ladder(ms, &reach); break;
case TRAVEL_WALK: *result = BotTravel_Walk(ms, &reach); break;//BotFinishTravel_Walk(ms, &reach); break;
case TRAVEL_CROUCH: /*do nothing*/ break;
case TRAVEL_BARRIERJUMP: *result = BotFinishTravel_BarrierJump(ms, &reach); break;
case TRAVEL_LADDER: *result = BotTravel_Ladder(ms, &reach); break;
case TRAVEL_WALKOFFLEDGE: *result = BotFinishTravel_WalkOffLedge(ms, &reach); break;
case TRAVEL_JUMP: *result = BotFinishTravel_Jump(ms, &reach); break;
case TRAVEL_SWIM: *result = BotTravel_Swim(ms, &reach); break;
Expand Down
73 changes: 63 additions & 10 deletions code/game/ai_dmnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.
Copyright (C) 2000-2003 Iron Claw Interactive
Copyright (C) 2005-2010 Smokin' Guns
Copyright (C) 2005-2012 Smokin' Guns
This file is part of Smokin' Guns.
Expand Down Expand Up @@ -805,8 +805,12 @@ int BotGetItemLongTermGoal(bot_state_t *bs, int tfl, bot_goal_t *goal) {
// break the loop if there is no real goal
if(count >= 10){
// bot "needs" time to buy something
if(bs->buytime > level.time)
if(bs->buytime > level.time) {
#ifdef DEBUG
BotAI_Print(PRT_MESSAGE, "wait buy %d>%d.", bs->buytime, level.time);
#endif
return qfalse;
}

BotAI_LookForNodes(bs, goal, vec_money[0], vec_money[1]);
trap_BotEmptyGoalStack(bs->gs);
Expand All @@ -816,9 +820,14 @@ int BotGetItemLongTermGoal(bot_state_t *bs, int tfl, bot_goal_t *goal) {
//choose a new goal
if (trap_BotChooseLTGItem(bs->gs, bs->origin, bs->inventory, tfl)) {
bs->ltg_time = FloatTime() + 20;
#ifdef DEBUG
BotAI_Print(PRT_MESSAGE, "new goal.");
#endif
}
else {//the bot gets sorta stuck with all the avoid timings, shouldn't happen though

#ifdef DEBUG
BotAI_Print(PRT_MESSAGE, "avoid stuck.");
#endif
//reset the avoid goals and the avoid reach
trap_BotResetAvoidGoals(bs->gs);
trap_BotResetAvoidReach(bs->ms);
Expand All @@ -828,10 +837,16 @@ int BotGetItemLongTermGoal(bot_state_t *bs, int tfl, bot_goal_t *goal) {

valid = (goal->entitynum >= 0 && goal->entitynum < MAX_GENTITIES);

if(!valid)
if(!valid) {
#ifdef DEBUG
BotAI_Print(PRT_MESSAGE, "invalid.");
#endif
continue;

}
if(valid){
#ifdef DEBUG
BotAI_Print(PRT_MESSAGE, "valid.");
#endif
/*if(g_gametype.integer == GT_BR && bs->cur_ps.persistant[PERS_ROBBER] &&
!Q_stricmp(g_entities[goal->entitynum].classname, "item_money") &&
!(g_entities[goal->entitynum].r.svFlags & SVF_NOCLIENT)){
Expand Down Expand Up @@ -877,7 +892,9 @@ int BotGetItemLongTermGoal(bot_state_t *bs, int tfl, bot_goal_t *goal) {
continue;
}*/
}

#ifdef DEBUG
BotAI_Print(PRT_MESSAGE, "grabbable %d.", BG_CanItemBeGrabbed(g_gametype.integer, &g_entities[goal->entitynum].s, &bs->cur_ps));
#endif
} while (!valid || (bs->flags & BFL_AVOID) ||
!Q_stricmp(g_entities[goal->entitynum].classname, "freed") ||
!Q_stricmp(g_entities[goal->entitynum].classname, "player") ||
Expand Down Expand Up @@ -1009,7 +1026,7 @@ int BotGetLongTermGoal(bot_state_t *bs, int tfl, int retreat, bot_goal_t *goal)
if (DotProduct(dir, dir2) > 0.7) {
// back up
BotSetupForMovement(bs);
trap_BotMoveInDirection(bs->ms, dir2, 400, MOVE_WALK);
//trap_BotMoveInDirection(bs->ms, dir2, 400, MOVE_WALK);
}
}
}
Expand Down Expand Up @@ -2166,6 +2183,10 @@ int AINode_Seek_ActivateEntity(bot_state_t *bs) {
bsp_trace_t bsptrace;
aas_entityinfo_t entinfo;

#ifdef DEBUG
BotAI_Print(PRT_MESSAGE, "Seek_ActivateEntity\n");
#endif

if (BotIsObserver(bs)) {
BotClearActivateGoalStack(bs);
AIEnter_Observer(bs, "active entity: observer");
Expand Down Expand Up @@ -2288,7 +2309,7 @@ int AINode_Seek_ActivateEntity(bot_state_t *bs) {
if (trap_BotTouchingGoal(bs->origin, goal)) {
#ifdef DEBUG
BotAI_Print(PRT_MESSAGE, "touched button or trigger\n");
#endif //DEBUG
#endif
bs->activatestack->time = 0;
}
}
Expand Down Expand Up @@ -2426,6 +2447,9 @@ int AINode_Seek_NBG(bot_state_t *bs) {
#ifdef SMOKINGUNS
qboolean override = ((bs->flags & BFL_AVOID )||( bs->flags & BFL_ESCAPE));
#endif
#ifdef DEBUG
Com_Printf("seek NBG:\n");
#endif

if (BotIsObserver(bs)) {
AIEnter_Observer(bs, "seek nbg: observer");
Expand Down Expand Up @@ -2493,8 +2517,13 @@ int AINode_Seek_NBG(bot_state_t *bs) {
return qfalse;
}
//predict obstacles
if (BotAIPredictObstacles(bs, &goal))
if (BotAIPredictObstacles(bs, &goal)) {
#ifdef DEBUG
Com_Printf("some obstacle\n");
#endif
return qfalse;
}

//initialize the movement state
BotSetupForMovement(bs);

Expand Down Expand Up @@ -2601,15 +2630,24 @@ AINode_Seek_LTG
*/
int AINode_Seek_LTG(bot_state_t *bs)
{
#ifdef DEBUG
vec3_t oldOrigin, diff;
#endif
bot_goal_t goal;
vec3_t target, dir;
bot_moveresult_t moveresult;
int range;

#ifdef SMOKINGUNS
qboolean override = ((bs->flags & BFL_AVOID )||( bs->flags & BFL_ESCAPE));
#endif
//char buf[128];
//bot_goal_t tmpgoal;
#ifdef DEBUG
Com_Printf("AINode_Seek_LTG\n");

VectorCopy(bs->origin,oldOrigin);
#endif

if (BotIsObserver(bs)) {
AIEnter_Observer(bs, "seek ltg: observer");
Expand Down Expand Up @@ -2674,10 +2712,16 @@ int AINode_Seek_LTG(bot_state_t *bs)
}
//
BotTeamGoals(bs, qfalse);
#ifdef DEBUG
Com_Printf("longtermgoal.\n");
#endif
//get the current long term goal
if (!BotLongTermGoal(bs, bs->tfl, qfalse, &goal)) {
return qtrue;
}
#ifdef DEBUG
Com_Printf("goal: %d. nearbygoal.\n", goal.number);
#endif
//check for nearby goals periodicly
#ifndef SMOKINGUNS
if (bs->check_time < FloatTime()) {
Expand Down Expand Up @@ -2723,9 +2767,14 @@ int AINode_Seek_LTG(bot_state_t *bs)
return qfalse;
}
}

//predict obstacles
if (BotAIPredictObstacles(bs, &goal))
if (BotAIPredictObstacles(bs, &goal)) {
#ifdef DEBUG
Com_Printf("Some obstacle\n");
#endif
return qfalse;
}
//initialize the movement state
BotSetupForMovement(bs);

Expand Down Expand Up @@ -2790,6 +2839,10 @@ int AINode_Seek_LTG(bot_state_t *bs)
//if the weapon is used for the bot movement
if (moveresult.flags & MOVERESULT_MOVEMENTWEAPON) bs->weaponnum = moveresult.weapon;
//
#ifdef DEBUG
VectorSubtract(oldOrigin,bs->origin,diff);
BotAI_Print(PRT_MESSAGE, "movement %d %d %d\n", moveresult.blockentity,moveresult.blocked,moveresult.flags);
#endif
return qtrue;
}

Expand Down
Loading

0 comments on commit ea44711

Please sign in to comment.