10000 Improve finding obelisk entitynum for bot AI · Turtle-Arena/turtle-arena-code@af0abe2 · GitHub
[go: up one dir, main page]

Skip to content

Commit af0abe2

Browse files
committed
Improve finding obelisk entitynum for bot AI
BotSetEntityNumForGoal() was checking all entities that are not team_redobelisk (which is the obelisk visual entity) to find the untitled obelisk collision entity. This may fail in rare cases where there is an another entity within 10 units of the obelisk origin. Failing to find the correct entity may cause bots to not attack the obelisk. Instead add BotSetEntityNumForGoalWithActivator() for looking for the obelisk collision entity by activator classname (team_redobelisk) which should be less likely to find the wrong entity. This doesn't affect official Team Arena maps (unknown if it affects any others). Reversed strcmp check was reported by Thomas Köppe.
1 parent 64733d6 commit af0abe2

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

code/game/ai_dmq3.c

+32-6
Original file line numberDiff line numberDiff line change
@@ -5739,7 +5739,33 @@ void BotSetEntityNumForGoal(bot_goal_t *goal, char *classname) {
57395739
if ( !ent->inuse ) {
57405740
continue;
57415741
}
5742-
if ( !Q_stricmp(ent->classname, classname) ) {
5742+
if ( Q_stricmp(ent->classname, classname) != 0 ) {
5743+
continue;
5744+
}
5745+
VectorSubtract(goal->origin, ent->s.origin, dir);
5746+
if (VectorLengthSquared(dir) < Square(10)) {
5747+
goal->entitynum = i;
5748+
return;
5749+
}
5750+
}
5751+
}
5752+
5753+
/*
5754+
==================
5755+
BotSetEntityNumForGoalWithActivator
5756+
==================
5757+
*/
5758+
void BotSetEntityNumForGoalWithActivator(bot_goal_t *goal, char *classname) {
5759+
gentity_t *ent;
5760+
int i;
5761+
vec3_t dir;
5762+
5763+
ent = &g_entities[0];
5764+
for (i = 0; i < level.num_entities; i++, ent++) {
5765+
if ( !ent->inuse || !ent->activator ) {
5766+
continue;
5767+
}
5768+
if ( Q_stricmp(ent->activator->classname, classname) != 0 ) {
57435769
continue;
57445770
}
57455771
VectorSubtract(goal->origin, ent->s.origin, dir);
@@ -5823,21 +5849,21 @@ void BotSetupDeathmatchAI(void) {
58235849
else if (gametype == GT_OBELISK) {
58245850
if (BotGetLevelItemGoal(-1, "Red Obelisk", &redobelisk) < 0)
58255851
BotAI_Print(PRT_WARNING, "Overload without Red Obelisk\n");
5826-
BotSetEntityNumForGoal(&redobelisk, "team_redobelisk");
5852+
BotSetEntityNumForGoalWithActivator(&redobelisk, "team_redobelisk");
58275853
if (BotGetLevelItemGoal(-1, "Blue Obelisk", &blueobelisk) < 0)
58285854
BotAI_Print(PRT_WARNING, "Overload without Blue Obelisk\n");
5829-
BotSetEntityNumForGoal(&blueobelisk, "team_blueobelisk");
5855+
BotSetEntityNumForGoalWithActivator(&blueobelisk, "team_blueobelisk");
58305856
}
58315857
else if (gametype == GT_HARVESTER) {
58325858
if (BotGetLevelItemGoal(-1, "Red Obelisk", &redobelisk) < 0)
58335859
BotAI_Print(PRT_WARNING, "Harvester without Red Obelisk\n");
5834-
BotSetEntityNumForGoal(&redobelisk, "team_redobelisk");
5860+
BotSetEntityNumForGoalWithActivator(&redobelisk, "team_redobelisk");
58355861
if (BotGetLevelItemGoal(-1, "Blue Obelisk", &blueobelisk) < 0)
58365862
BotAI_Print(PRT_WARNING, "Harvester without Blue Obelisk\n");
5837-
BotSetEntityNumForGoal(&blueobelisk, "team_blueobelisk");
5863+
BotSetEntityNumForGoalWithActivator(&blueobelisk, "team_blueobelisk");
58385864
if (BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0)
58395865
BotAI_Print(PRT_WARNING, "Harvester without Neutral Obelisk\n");
5840-
BotSetEntityNumForGoal(&neutralobelisk, "team_neutralobelisk");
5866+
BotSetEntityNumForGoalWithActivator(&neutralobelisk, "team_neutralobelisk");
58415867
}
58425868
#endif
58435869

0 commit comments

Comments
 (0)
0