MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / OnPlayerJoinLevel

Function OnPlayerJoinLevel

Source/msg.cpp:2064–2115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2062}
2063
2064size_t OnPlayerJoinLevel(const TCmd *pCmd, size_t pnum)
2065{
2066 const auto &message = *reinterpret_cast<const TCmdLocParam2 *>(pCmd);
2067 const Point position { message.x, message.y };
2068
2069 if (gbBufferMsgs == 1) {
2070 SendPacket(pnum, &message, sizeof(message));
2071 return sizeof(message);
2072 }
2073
2074 const uint16_t playerLevel = SDL_SwapLE16(message.wParam1);
2075 bool isSetLevel = message.wParam2 != 0;
2076 if (!IsValidLevel(playerLevel, isSetLevel) || !InDungeonBounds(position)) {
2077 return sizeof(message);
2078 }
2079
2080 Player &player = Players[pnum];
2081
2082 player._pLvlChanging = false;
2083 if (player._pName[0] != '\0' && !player.plractive) {
2084 ResetPlayerGFX(player);
2085 player.plractive = true;
2086 gbActivePlayers++;
2087 EventPlrMsg(fmt::format(fmt::runtime(_("Player '{:s}' (level {:d}) just joined the game")), player._pName, player._pLevel));
2088 }
2089
2090 if (player.plractive && &player != MyPlayer) {
2091 player.position.tile = position;
2092 SetPlayerOld(player);
2093 if (isSetLevel)
2094 player.setLevel(static_cast<_setlevels>(playerLevel));
2095 else
2096 player.setLevel(playerLevel);
2097 ResetPlayerGFX(player);
2098 if (player.isOnActiveLevel()) {
2099 SyncInitPlr(player);
2100 if ((player._pHitPoints >> 6) > 0) {
2101 StartStand(player, Direction::South);
2102 } else {
2103 player._pgfxnum &= ~0xFU;
2104 player._pmode = PM_DEATH;
2105 NewPlrAnim(player, player_graphic::Death, Direction::South);
2106 player.AnimInfo.currentFrame = player.AnimInfo.numberOfFrames - 2;
2107 dFlags[player.position.tile.x][player.position.tile.y] |= DungeonFlag::DeadPlayer;
2108 }
2109
2110 ActivateVision(player.position.tile, player._pLightRad, player.getId());
2111 }
2112 }
2113
2114 return sizeof(message);
2115}
2116
2117size_t OnActivatePortal(const TCmd *pCmd, size_t pnum)
2118{

Callers 1

ParseCmdFunction · 0.85

Calls 14

IsValidLevelFunction · 0.85
InDungeonBoundsFunction · 0.85
ResetPlayerGFXFunction · 0.85
EventPlrMsgFunction · 0.85
formatFunction · 0.85
SetPlayerOldFunction · 0.85
SyncInitPlrFunction · 0.85
StartStandFunction · 0.85
NewPlrAnimFunction · 0.85
ActivateVisionFunction · 0.85
setLevelMethod · 0.80
isOnActiveLevelMethod · 0.80

Tested by

no test coverage detected