void G_BotThink( gentity_t *self ) { char buf[MAX_STRING_CHARS]; usercmd_t *botCmdBuffer; vec3_t nudge; botRouteTarget_t routeTarget; self->botMind->cmdBuffer = self->client->pers.cmd; botCmdBuffer = &self->botMind->cmdBuffer; //reset command buffer usercmdClearButtons( botCmdBuffer->buttons ); // for nudges, e.g. spawn blocking nudge[0] = botCmdBuffer->doubleTap != dtType_t::DT_NONE ? botCmdBuffer->forwardmove : 0; nudge[1] = botCmdBuffer->doubleTap != dtType_t::DT_NONE ? botCmdBuffer->rightmove : 0; nudge[2] = botCmdBuffer->doubleTap != dtType_t::DT_NONE ? botCmdBuffer->upmove : 0; botCmdBuffer->forwardmove = 0; botCmdBuffer->rightmove = 0; botCmdBuffer->upmove = 0; botCmdBuffer->doubleTap = dtType_t::DT_NONE; //acknowledge recieved server commands //MUST be done while ( trap_BotGetServerCommand( self->client->ps.clientNum, buf, sizeof( buf ) ) ); BotSearchForEnemy( self ); BotFindClosestBuildings( self ); BotFindDamagedFriendlyStructure( self ); BotCalculateStuckTime( self ); //use medkit when hp is low if ( self->entity->Get<HealthComponent>()->Health() < BOT_USEMEDKIT_HP && BG_InventoryContainsUpgrade( UP_MEDKIT, self->client->ps.stats ) ) { BG_ActivateUpgrade( UP_MEDKIT, self->client->ps.stats ); } //infinite funds cvar if ( g_bot_infinite_funds.integer ) { G_AddCreditToClient( self->client, HUMAN_MAX_CREDITS, true ); } //hacky ping fix self->client->ps.ping = rand() % 50 + 50; if ( !self->botMind->behaviorTree ) { Log::Warn( "NULL behavior tree" ); return; } // always update the path corridor if ( self->botMind->goal.inuse ) { BotTargetToRouteTarget( self, self->botMind->goal, &routeTarget ); trap_BotUpdatePath( self->s.number, &routeTarget, &self->botMind->nav ); //BotClampPos( self ); } self->botMind->behaviorTree->run( self, ( AIGenericNode_t * ) self->botMind->behaviorTree ); // if we were nudged... VectorAdd( self->client->ps.velocity, nudge, self->client->ps.velocity ); self->client->pers.cmd = self->botMind->cmdBuffer; }
bool FindRouteToTarget( gentity_t *self, botTarget_t target, bool allowPartial ) { botRouteTarget_t routeTarget; BotTargetToRouteTarget( self, target, &routeTarget ); return trap_BotFindRoute( self->s.number, &routeTarget, allowPartial ); }