static int CBaseCombatWeapon___tostring (lua_State *L) { CBaseCombatWeapon *pWeapon = lua_toweapon(L, 1); if (pWeapon == NULL) lua_pushstring(L, "NULL"); else lua_pushfstring(L, "CBaseCombatWeapon: %d %s", pWeapon->entindex(), pWeapon->GetClassname()); return 1; }
void CAI_StandoffBehavior::UpdateTranslateActivityMap() { struct ActivityMapping { AI_Posture_t posture; Activity activity; const char * pszWeapon; Activity translation; }; static ActivityMapping mappings[] = { { AIP_CROUCHING, ACT_IDLE, NULL, ACT_COVER_LOW }, { AIP_CROUCHING, ACT_WALK, NULL, ACT_WALK_CROUCH }, { AIP_CROUCHING, ACT_RUN, NULL, ACT_RUN_CROUCH }, { AIP_CROUCHING, ACT_WALK_AIM, NULL, ACT_WALK_CROUCH_AIM }, { AIP_CROUCHING, ACT_RUN_AIM, NULL, ACT_RUN_CROUCH_AIM }, { AIP_CROUCHING, ACT_RELOAD_PISTOL, NULL, ACT_RELOAD_PISTOL_LOW }, { AIP_CROUCHING, ACT_RELOAD_SMG1, NULL, ACT_RELOAD_SMG1_LOW }, //---- { AIP_STANDING, ACT_COVER_LOW, NULL, ACT_IDLE }, //---- { AIP_PEEKING, ACT_IDLE, "weapon_smg1", ACT_RANGE_AIM_SMG1_LOW }, { AIP_PEEKING, ACT_COVER_LOW, "weapon_smg1", ACT_RANGE_AIM_SMG1_LOW }, { AIP_PEEKING, ACT_IDLE, "weapon_pistol", ACT_RANGE_AIM_PISTOL_LOW }, { AIP_PEEKING, ACT_COVER_LOW, "weapon_pistol", ACT_RANGE_AIM_PISTOL_LOW }, { AIP_PEEKING, ACT_IDLE, "weapon_ar2", ACT_RANGE_AIM_AR2_LOW }, { AIP_PEEKING, ACT_COVER_LOW, "weapon_ar2", ACT_RANGE_AIM_AR2_LOW }, { AIP_PEEKING, ACT_RANGE_ATTACK_PISTOL, NULL, ACT_RANGE_ATTACK_PISTOL_LOW }, { AIP_PEEKING, ACT_RANGE_ATTACK_SMG1, NULL, ACT_RANGE_ATTACK_SMG1_LOW }, { AIP_PEEKING, ACT_RELOAD_PISTOL, NULL, ACT_RELOAD_PISTOL_LOW }, { AIP_PEEKING, ACT_RELOAD_SMG1, NULL, ACT_RELOAD_SMG1_LOW }, }; m_ActivityMap.RemoveAll(); CBaseCombatWeapon *pWeapon = GetOuter()->GetActiveWeapon(); const char *pszWeaponClass = ( pWeapon ) ? pWeapon->GetClassname() : ""; for ( int i = 0; i < ARRAYSIZE(mappings); i++ ) { if ( !mappings[i].pszWeapon || stricmp( mappings[i].pszWeapon, pszWeaponClass ) == 0 ) { if ( HaveSequenceForActivity( mappings[i].translation ) ) m_ActivityMap.Insert( MAKE_ACTMAP_KEY( mappings[i].posture, mappings[i].activity ), mappings[i].translation ); } } }
/** * Plant the bomb. */ void PlantBombState::OnUpdate( CCFBot *me ) { CBaseCombatWeapon *gun = me->GetActiveWeapon(); bool holdingC4 = false; if (gun) { if (FStrEq( gun->GetClassname(), "weapon_c4" )) holdingC4 = true; } // if we aren't holding the C4, grab it, otherwise plant it if (holdingC4) me->PrimaryAttack(); else me->SelectItem( "weapon_c4" ); // if we time out, it's because we slipped into a non-plantable area const float timeout = 5.0f; if (gpGlobals->curtime - me->GetStateTimestamp() > timeout) me->Idle(); }
void CAI_MappedActivityBehavior_Temporary::UpdateTranslateActivityMap() { AI_ActivityMapping_t mappings[] = // This array cannot be static, as some activity values are set on a per-map-load basis { { AIP_CROUCHING, ACT_IDLE, NULL, ACT_COVER_LOW, }, { AIP_CROUCHING, ACT_IDLE_ANGRY, NULL, ACT_COVER_LOW, }, { AIP_CROUCHING, ACT_WALK, NULL, ACT_WALK_CROUCH, }, { AIP_CROUCHING, ACT_RUN, NULL, ACT_RUN_CROUCH, }, { AIP_CROUCHING, ACT_WALK_AIM, NULL, ACT_WALK_CROUCH_AIM, }, { AIP_CROUCHING, ACT_RUN_AIM, NULL, ACT_RUN_CROUCH_AIM, }, { AIP_CROUCHING, ACT_RELOAD, NULL, ACT_RELOAD_LOW, }, { AIP_CROUCHING, ACT_RANGE_ATTACK_SMG1, NULL, ACT_RANGE_ATTACK_SMG1_LOW, }, { AIP_CROUCHING, ACT_RANGE_ATTACK_AR2, NULL, ACT_RANGE_ATTACK_AR2_LOW, }, //---- { AIP_PEEKING, ACT_IDLE, NULL, ACT_RANGE_AIM_LOW, }, { AIP_PEEKING, ACT_IDLE_ANGRY, NULL, ACT_RANGE_AIM_LOW, }, { AIP_PEEKING, ACT_COVER_LOW, NULL, ACT_RANGE_AIM_LOW, }, { AIP_PEEKING, ACT_RANGE_ATTACK1, NULL, ACT_RANGE_ATTACK1_LOW, }, { AIP_PEEKING, ACT_RELOAD, NULL, ACT_RELOAD_LOW, }, }; m_ActivityMap.RemoveAll(); CBaseCombatWeapon *pWeapon = GetOuter()->GetActiveWeapon(); const char *pszWeaponClass = ( pWeapon ) ? pWeapon->GetClassname() : ""; for ( int i = 0; i < ARRAYSIZE(mappings); i++ ) { if ( !mappings[i].pszWeapon || stricmp( mappings[i].pszWeapon, pszWeaponClass ) == 0 ) { if ( HaveSequenceForActivity( mappings[i].translation ) || HaveSequenceForActivity( GetOuter()->Weapon_TranslateActivity( mappings[i].translation ) ) ) { Assert( m_ActivityMap.Find( MAKE_ACTMAP_KEY( mappings[i].posture, mappings[i].activity ) ) == m_ActivityMap.InvalidIndex() ); m_ActivityMap.Insert( MAKE_ACTMAP_KEY( mappings[i].posture, mappings[i].activity ), mappings[i].translation ); } } } }
void CAI_ExpresserHost_NPC_DoModifyOrAppendCriteria( CAI_BaseNPC *pSpeaker, AI_CriteriaSet& set ) { // Append current activity name const char *pActivityName = pSpeaker->GetActivityName( pSpeaker->GetActivity() ); if ( pActivityName ) { set.AppendCriteria( "activity", pActivityName ); } static const char *pStateNames[] = { "None", "Idle", "Alert", "Combat", "Scripted", "PlayDead", "Dead" }; if ( (int)pSpeaker->m_NPCState < ARRAYSIZE(pStateNames) ) { set.AppendCriteria( "npcstate", UTIL_VarArgs( "[NPCState::%s]", pStateNames[pSpeaker->m_NPCState] ) ); } if ( pSpeaker->GetEnemy() ) { set.AppendCriteria( "enemy", pSpeaker->GetEnemy()->GetClassname() ); set.AppendCriteria( "timesincecombat", "-1" ); } else { if ( pSpeaker->GetLastEnemyTime() == 0.0 ) set.AppendCriteria( "timesincecombat", "999999.0" ); else set.AppendCriteria( "timesincecombat", UTIL_VarArgs( "%f", gpGlobals->curtime - pSpeaker->GetLastEnemyTime() ) ); } set.AppendCriteria( "speed", UTIL_VarArgs( "%.3f", pSpeaker->GetSmoothedVelocity().Length() ) ); CBaseCombatWeapon *weapon = pSpeaker->GetActiveWeapon(); if ( weapon ) { set.AppendCriteria( "weapon", weapon->GetClassname() ); } else { set.AppendCriteria( "weapon", "none" ); } CBasePlayer *pPlayer = AI_GetSinglePlayer(); if ( pPlayer ) { Vector distance = pPlayer->GetAbsOrigin() - pSpeaker->GetAbsOrigin(); set.AppendCriteria( "distancetoplayer", UTIL_VarArgs( "%f", distance.Length() ) ); } else { set.AppendCriteria( "distancetoplayer", UTIL_VarArgs( "%i", MAX_COORD_RANGE ) ); } if ( pSpeaker->HasCondition( COND_SEE_PLAYER ) ) { set.AppendCriteria( "seeplayer", "1" ); } else { set.AppendCriteria( "seeplayer", "0" ); } if ( pPlayer && pPlayer->FInViewCone( pSpeaker ) && pPlayer->FVisible( pSpeaker ) ) { set.AppendCriteria( "seenbyplayer", "1" ); } else { set.AppendCriteria( "seenbyplayer", "0" ); } }
void AppendPlayerInformation(ISteamHTTP *pSteamHttp, HTTPRequestHandle httpRequest, CSteamAPIContext *pSteamAPIContext, CBasePlayer *pPlayer, bool bAnonymous) { // Local DS time_t rawtime; struct tm* timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); char* local_ds = asctime(timeinfo); char* newLine = strstr(local_ds, "\n"); if (newLine) { *newLine = 0; } pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "localdatetime", local_ds); // Build DS char build_ds[64]; Q_snprintf(build_ds, sizeof(build_ds), "%s,%s", __DATE__, __TIME__); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "builddatetime", build_ds); // DxLevel pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "dxlevel", ConVarRef("mat_dxlevel").GetString()); if (pPlayer) { // Position char player_position[32]; Vector player_pos = pPlayer->GetLocalOrigin(); Q_snprintf(player_position, sizeof(player_position), "%.2f,%.2f,%.2f", player_pos.x, player_pos.y, player_pos.z); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "position", player_position); // Angles char player_angles[32]; QAngle player_ang = pPlayer->GetLocalAngles(); Q_snprintf(player_angles, sizeof(player_angles), "%.2f,%.2f,%.2f", player_ang.x, player_ang.y, player_ang.z); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "angles", player_angles); // Health char player_health[16]; Q_snprintf(player_health, sizeof(player_health), "%i", pPlayer->GetHealth()); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "health", player_health); // Weapon CBaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if (pWeapon) { pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "weapon", pWeapon->GetClassname()); } } // Cheats char cheats_enabled[8]; Q_snprintf(cheats_enabled, sizeof(cheats_enabled), "%i", (ConVarRef("sv_cheats").GetBool() || ConVarRef("developer").GetBool())); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "cheats", cheats_enabled); // Map #ifdef CLIENT_DLL char mapname[256]; V_FileBase(engine->GetLevelName(), mapname, sizeof(mapname)); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "level", mapname); #else pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "level", gpGlobals->mapname.ToCStr()); #endif if (pSteamAPIContext) { // Language pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "language", pSteamAPIContext->SteamUtils()->GetSteamUILanguage()); } // Platform char * platform = "unknown"; if (IsPC()) platform = "pc"; if (IsOSX()) platform = "osx"; if (IsLinux()) platform = "linux"; if (IsX360()) platform = "360"; if (IsPS3()) platform = "ps3"; pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "platform", platform); // Player ID if (bAnonymous == false) { if (ae_uniqueplayerid.GetInt() == 0) GenerateUniquePlayerId(pSteamAPIContext); pSteamHttp->SetHTTPRequestGetOrPostParameter(httpRequest, "playerid", ae_uniqueplayerid.GetString()); } }