From 31198d05693d1b3d8589b7583822ad60d36f6a11 Mon Sep 17 00:00:00 2001 From: mwydmuch Date: Wed, 4 Jul 2018 09:26:23 +0200 Subject: [PATCH] Added playersAfk, playersLastActionTic, playersLastKillTic fields to ServerState --- CMakeLists.txt | 2 +- include/ViZDoomTypes.h | 3 +++ src/lib/ViZDoomController.cpp | 12 ++++++++++++ src/lib/ViZDoomController.h | 4 +++- src/lib/ViZDoomGame.cpp | 3 +++ src/lib/ViZDoomSharedMemory.h | 3 +++ src/lib_python/ViZDoomGamePython.cpp | 11 ++++++++++- src/lib_python/ViZDoomGamePython.h | 3 +++ src/lib_python/ViZDoomPythonModule.cpp | 5 ++++- src/vizdoom/src/viz_game.cpp | 8 ++++++++ src/vizdoom/src/viz_game.h | 3 +++ src/vizdoom/src/viz_main.cpp | 1 + 12 files changed, 54 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c746b47c4..ed26930a5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ project(ViZDoom) set(ViZDoom_MAJOR_VERSION 1) set(ViZDoom_MINOR_VERSION 1) -set(ViZDoom_PATCH_VERSION 5) +set(ViZDoom_PATCH_VERSION 6) set(ViZDoom_VERSION ${ViZDoom_MAJOR_VERSION}.${ViZDoom_MINOR_VERSION}.${ViZDoom_PATCH_VERSION}) set(ViZDoom_VERSION_STR ${ViZDoom_VERSION}) set(ViZDoom_VERSION_ID ${ViZDoom_MAJOR_VERSION}${ViZDoom_MINOR_VERSION}${ViZDoom_PATCH_VERSION}) diff --git a/include/ViZDoomTypes.h b/include/ViZDoomTypes.h index d6f0f517a..26d396006 100644 --- a/include/ViZDoomTypes.h +++ b/include/ViZDoomTypes.h @@ -88,6 +88,9 @@ namespace vizdoom{ bool playersInGame[MAX_PLAYERS]; int playersFrags[MAX_PLAYERS]; std::string playersNames[MAX_PLAYERS]; + bool playersAfk[MAX_PLAYERS]; + unsigned int playersLastActionTic[MAX_PLAYERS]; + unsigned int playersLastKillTic[MAX_PLAYERS]; }; typedef std::shared_ptr ServerStatePtr; diff --git a/src/lib/ViZDoomController.cpp b/src/lib/ViZDoomController.cpp index 23c775930..5b289fcb1 100644 --- a/src/lib/ViZDoomController.cpp +++ b/src/lib/ViZDoomController.cpp @@ -987,6 +987,18 @@ namespace vizdoom { return playerNumber < MAX_PLAYERS ? std::string(this->gameState->PLAYER_N_NAME[playerNumber]) : ""; } + bool DoomController::isPlayerAfk(unsigned int playerNumber){ + return playerNumber < MAX_PLAYERS ? this->gameState->PLAYER_N_AFK[playerNumber] : false; + } + + unsigned int DoomController::getPlayerLastActionTic(unsigned int playerNumber){ + return playerNumber < MAX_PLAYERS ? this->gameState->PLAYER_N_LAST_ACTION_TIC[playerNumber] : 0; + } + + unsigned int DoomController::getPlayerLastKillTic(unsigned int playerNumber){ + return playerNumber < MAX_PLAYERS ? this->gameState->PLAYER_N_LAST_KILL_TIC[playerNumber] : 0; + } + /* Protected and private functions */ /*----------------------------------------------------------------------------------------------------------------*/ diff --git a/src/lib/ViZDoomController.h b/src/lib/ViZDoomController.h index 58cd731ed..aeabebfa7 100644 --- a/src/lib/ViZDoomController.h +++ b/src/lib/ViZDoomController.h @@ -242,7 +242,9 @@ namespace vizdoom { bool isPlayerInGame(unsigned int playerNumber); int getPlayerFrags(unsigned int playerNumber); std::string getPlayerName(unsigned int playerNumber); - + bool isPlayerAfk(unsigned int playerNumber); + unsigned int getPlayerLastActionTic(unsigned int playerNumber); + unsigned int getPlayerLastKillTic(unsigned int playerNumber); private: diff --git a/src/lib/ViZDoomGame.cpp b/src/lib/ViZDoomGame.cpp index 9e5b7847c..e2006cece 100644 --- a/src/lib/ViZDoomGame.cpp +++ b/src/lib/ViZDoomGame.cpp @@ -284,6 +284,9 @@ namespace vizdoom { serverState->playersInGame[i] = this->doomController->isPlayerInGame(i); serverState->playersNames[i] = this->doomController->getPlayerName(i); serverState->playersFrags[i] = this->doomController->getPlayerFrags(i); + serverState->playersAfk[i] = this->doomController->isPlayerAfk(i); + serverState->playersLastActionTic[i] = this->doomController->getPlayerLastActionTic(i); + serverState->playersLastKillTic[i] = this->doomController->getPlayerLastKillTic(i); } return serverState; diff --git a/src/lib/ViZDoomSharedMemory.h b/src/lib/ViZDoomSharedMemory.h index 4751ca964..5fc73f6cf 100644 --- a/src/lib/ViZDoomSharedMemory.h +++ b/src/lib/ViZDoomSharedMemory.h @@ -154,6 +154,9 @@ namespace vizdoom { bool PLAYER_N_IN_GAME[MAX_PLAYERS]; char PLAYER_N_NAME[MAX_PLAYERS][MAX_PLAYER_NAME_LENGTH]; int PLAYER_N_FRAGCOUNT[MAX_PLAYERS]; + bool PLAYER_N_AFK[MAX_PLAYERS]; + unsigned int PLAYER_N_LAST_ACTION_TIC[MAX_PLAYERS]; + unsigned int PLAYER_N_LAST_KILL_TIC[MAX_PLAYERS]; //LABELS unsigned int LABEL_COUNT; diff --git a/src/lib_python/ViZDoomGamePython.cpp b/src/lib_python/ViZDoomGamePython.cpp index f83b57055..171c1f09c 100644 --- a/src/lib_python/ViZDoomGamePython.cpp +++ b/src/lib_python/ViZDoomGamePython.cpp @@ -120,15 +120,24 @@ namespace vizdoom { pyServerState->tic = this->doomController->getMapTic(); pyServerState->playerCount = this->doomController->getPlayerCount(); - pyb::list pyPlayersInGame, pyPlayersNames, pyPlayersFrags; + + pyb::list pyPlayersInGame, pyPlayersNames, pyPlayersFrags, + pyPlayersAfk, pyPlayersLastActionTic, pyPlayersLastKillTic; for(int i = 0; i < MAX_PLAYERS; ++i) { pyPlayersInGame.append(this->doomController->isPlayerInGame(i)); pyPlayersNames.append(pyb::str(this->doomController->getPlayerName(i).c_str())); pyPlayersFrags.append(this->doomController->getPlayerFrags(i)); + pyPlayersAfk.append(this->doomController->isPlayerAfk(i)); + pyPlayersLastActionTic.append(this->doomController->getPlayerLastActionTic(i)); + pyPlayersFrags.append(this->doomController->getPlayerLastKillTic(i)); } + pyServerState->playersInGame = pyPlayersInGame; pyServerState->playersNames = pyPlayersNames; pyServerState->playersFrags = pyPlayersFrags; + pyServerState->playersAfk = pyPlayersAfk; + pyServerState->playersLastActionTic = pyPlayersLastActionTic; + pyServerState->playersLastKillTic = pyPlayersLastKillTic; return pyServerState; } diff --git a/src/lib_python/ViZDoomGamePython.h b/src/lib_python/ViZDoomGamePython.h index 72d773244..63246648f 100644 --- a/src/lib_python/ViZDoomGamePython.h +++ b/src/lib_python/ViZDoomGamePython.h @@ -114,6 +114,9 @@ namespace vizdoom { pyb::list playersInGame; pyb::list playersFrags; pyb::list playersNames; + pyb::list playersAfk; + pyb::list playersLastActionTic; + pyb::list playersLastKillTic; }; class DoomGamePython : public DoomGame { diff --git a/src/lib_python/ViZDoomPythonModule.cpp b/src/lib_python/ViZDoomPythonModule.cpp index f86a0454c..341265c97 100644 --- a/src/lib_python/ViZDoomPythonModule.cpp +++ b/src/lib_python/ViZDoomPythonModule.cpp @@ -401,7 +401,10 @@ PYBIND11_MODULE(vizdoom, vz){ .def_readonly("player_count", &ServerStatePython::playerCount) .def_readonly("players_in_game", &ServerStatePython::playersInGame) .def_readonly("players_names", &ServerStatePython::playersNames) - .def_readonly("players_frags", &ServerStatePython::playersFrags); + .def_readonly("players_frags", &ServerStatePython::playersFrags) + .def_readonly("players_afk", &ServerStatePython::playersAfk) + .def_readonly("players_last_action_tic", &ServerStatePython::playersLastActionTic) + .def_readonly("players_last_kill_tic", &ServerStatePython::playersLastKillTic); /* DoomGame */ diff --git a/src/vizdoom/src/viz_game.cpp b/src/vizdoom/src/viz_game.cpp index e26288608..9852ffb0e 100644 --- a/src/vizdoom/src/viz_game.cpp +++ b/src/vizdoom/src/viz_game.cpp @@ -45,6 +45,7 @@ EXTERN_CVAR (Bool, viz_automap) EXTERN_CVAR (Bool, viz_loop_map) EXTERN_CVAR (Bool, viz_override_player) EXTERN_CVAR (Bool, viz_spectator) +EXTERN_CVAR (Int, viz_afk_delay) EXTERN_CVAR (Float, timelimit) VIZGameState *vizGameStateSM = NULL; @@ -343,11 +344,18 @@ void VIZ_GameStateUpdate(){ vizGameStateSM->PLAYER_N_IN_GAME[i] = true; strncpy(vizGameStateSM->PLAYER_N_NAME[i], players[i].userinfo.GetName(), VIZ_MAX_PLAYER_NAME_LEN); vizGameStateSM->PLAYER_N_FRAGCOUNT[i] = players[i].fragcount; + if(players[i].cmd.ucmd.buttons != 0) + vizGameStateSM->PLAYER_N_LAST_ACTION_TIC[i] = (unsigned int)gametic; + vizGameStateSM->PLAYER_N_AFK[i] = vizGameStateSM->PLAYER_N_LAST_ACTION_TIC[i] < ((unsigned int)gametic - *viz_afk_delay); + vizGameStateSM->PLAYER_N_LAST_KILL_TIC[i] = players[i].lastkilltime; } else{ //strncpy(vizGameStateSM->PLAYER_N_NAME[i], players[i].userinfo.GetName(), VIZ_MAX_PLAYER_NAME_LEN); vizGameStateSM->PLAYER_N_IN_GAME[i] = false; vizGameStateSM->PLAYER_N_FRAGCOUNT[i] = 0; + vizGameStateSM->PLAYER_N_AFK[i] = false; + vizGameStateSM->PLAYER_N_LAST_ACTION_TIC[i] = 0; + vizGameStateSM->PLAYER_N_LAST_KILL_TIC[i] = 0; } } } diff --git a/src/vizdoom/src/viz_game.h b/src/vizdoom/src/viz_game.h index e1141d5ba..bd4eadb3c 100644 --- a/src/vizdoom/src/viz_game.h +++ b/src/vizdoom/src/viz_game.h @@ -151,6 +151,9 @@ struct VIZGameState{ bool PLAYER_N_IN_GAME[VIZ_MAX_PLAYERS]; char PLAYER_N_NAME[VIZ_MAX_PLAYERS][VIZ_MAX_PLAYER_NAME_LEN]; int PLAYER_N_FRAGCOUNT[VIZ_MAX_PLAYERS]; + bool PLAYER_N_AFK[VIZ_MAX_PLAYERS]; + unsigned int PLAYER_N_LAST_ACTION_TIC[VIZ_MAX_PLAYERS]; + unsigned int PLAYER_N_LAST_KILL_TIC[VIZ_MAX_PLAYERS]; // LABELS unsigned int LABEL_COUNT; diff --git a/src/vizdoom/src/viz_main.cpp b/src/vizdoom/src/viz_main.cpp index 526dd0a54..031734c12 100755 --- a/src/vizdoom/src/viz_main.cpp +++ b/src/vizdoom/src/viz_main.cpp @@ -103,6 +103,7 @@ CVAR (Bool, viz_loop_map, false, CVAR_NOSET | CVAR_SERVERINFO) CVAR (Bool, viz_nocheat, false, CVAR_NOSET | CVAR_SERVERINFO) CVAR (Int, viz_respawn_delay, 1, CVAR_DEMOSAVE | CVAR_SERVERINFO) CVAR (Bool, viz_spectator, false, CVAR_DEMOSAVE | CVAR_USERINFO) // players[playernum].userinfo.GetSpectator() +CVAR (Int, viz_afk_delay, 2100, CVAR_DEMOSAVE | CVAR_SERVERINFO) CCMD(viz_set_seed){ viz_seed.CmdSet(argv[1]);