Have PosOkPlayer take PlayerStruct as input (#2430)
This commit is contained in:
parent
cb62e7bf2d
commit
8ba3bbb6a4
8 changed files with 173 additions and 186 deletions
|
|
@ -91,7 +91,8 @@ int GetDistance(Point destination, int maxDistance)
|
|||
}
|
||||
|
||||
int8_t walkpath[MAX_PATH_LENGTH];
|
||||
int steps = FindPath([](Point position) { return PosOkPlayer(MyPlayerId, position); }, Players[MyPlayerId].position.future, destination, walkpath);
|
||||
auto &myPlayer = Players[MyPlayerId];
|
||||
int steps = FindPath([&myPlayer](Point position) { return PosOkPlayer(myPlayer, position); }, myPlayer.position.future, destination, walkpath);
|
||||
if (steps > maxDistance)
|
||||
return 0;
|
||||
|
||||
|
|
@ -246,9 +247,11 @@ void FindMeleeTarget()
|
|||
};
|
||||
std::list<SearchNode> queue;
|
||||
|
||||
auto &myPlayer = Players[MyPlayerId];
|
||||
|
||||
{
|
||||
const int startX = Players[MyPlayerId].position.future.x;
|
||||
const int startY = Players[MyPlayerId].position.future.y;
|
||||
const int startX = myPlayer.position.future.x;
|
||||
const int startY = myPlayer.position.future.y;
|
||||
visited[startX][startY] = true;
|
||||
queue.push_back({ startX, startY, 0 });
|
||||
}
|
||||
|
|
@ -269,7 +272,7 @@ void FindMeleeTarget()
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!PosOkPlayer(MyPlayerId, { dx, dy })) {
|
||||
if (!PosOkPlayer(myPlayer, { dx, dy })) {
|
||||
visited[dx][dy] = true;
|
||||
|
||||
if (dMonster[dx][dy] != 0) {
|
||||
|
|
@ -1051,7 +1054,9 @@ bool IsPathBlocked(Point position, Direction dir)
|
|||
if (IsTileNotSolid(leftStep) && IsTileNotSolid(rightStep))
|
||||
return false;
|
||||
|
||||
return !PosOkPlayer(MyPlayerId, leftStep) && !PosOkPlayer(MyPlayerId, rightStep);
|
||||
auto &myPlayer = Players[MyPlayerId];
|
||||
|
||||
return !PosOkPlayer(myPlayer, leftStep) && !PosOkPlayer(myPlayer, rightStep);
|
||||
}
|
||||
|
||||
bool CanChangeDirection(const PlayerStruct &player)
|
||||
|
|
@ -1083,7 +1088,7 @@ void WalkInDir(int playerId, AxisDirection dir)
|
|||
if (CanChangeDirection(player))
|
||||
player._pdir = pdir;
|
||||
|
||||
if (PosOkPlayer(playerId, delta) && IsPathBlocked(player.position.future, pdir))
|
||||
if (PosOkPlayer(player, delta) && IsPathBlocked(player.position.future, pdir))
|
||||
return; // Don't start backtrack around obstacles
|
||||
|
||||
NetSendCmdLoc(playerId, true, CMD_WALKXY, delta);
|
||||
|
|
@ -1521,15 +1526,18 @@ void PerformSecondaryAction()
|
|||
NetSendCmdLocParam1(true, CMD_GOTOAGETITEM, { cursmx, cursmy }, pcursitem);
|
||||
} else if (pcursobj != -1) {
|
||||
NetSendCmdLocParam1(true, CMD_OPOBJXY, { cursmx, cursmy }, pcursobj);
|
||||
} else if (pcursmissile != -1) {
|
||||
MakePlrPath(MyPlayerId, Missiles[pcursmissile].position.tile, true);
|
||||
Players[MyPlayerId].destAction = ACTION_WALK;
|
||||
} else if (pcurstrig != -1) {
|
||||
MakePlrPath(MyPlayerId, trigs[pcurstrig].position, true);
|
||||
Players[MyPlayerId].destAction = ACTION_WALK;
|
||||
} else if (pcursquest != -1) {
|
||||
MakePlrPath(MyPlayerId, Quests[pcursquest].position, true);
|
||||
Players[MyPlayerId].destAction = ACTION_WALK;
|
||||
} else {
|
||||
auto &myPlayer = Players[MyPlayerId];
|
||||
if (pcursmissile != -1) {
|
||||
MakePlrPath(myPlayer, Missiles[pcursmissile].position.tile, true);
|
||||
myPlayer.destAction = ACTION_WALK;
|
||||
} else if (pcurstrig != -1) {
|
||||
MakePlrPath(myPlayer, trigs[pcurstrig].position, true);
|
||||
myPlayer.destAction = ACTION_WALK;
|
||||
} else if (pcursquest != -1) {
|
||||
MakePlrPath(myPlayer, Quests[pcursquest].position, true);
|
||||
myPlayer.destAction = ACTION_WALK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2012,7 +2012,7 @@ void UpdateVileMissPos(int mi, Point dst)
|
|||
int yy = j + dst.y;
|
||||
for (int i = -k; i <= k; i++) {
|
||||
int xx = i + dst.x;
|
||||
if (PosOkPlayer(MyPlayerId, { xx, yy })) {
|
||||
if (PosOkPlayer(Players[MyPlayerId], { xx, yy })) {
|
||||
Missiles[mi].position.tile = { xx, yy };
|
||||
return;
|
||||
}
|
||||
|
|
@ -2061,7 +2061,7 @@ void AddRndTeleport(int mi, Point src, Point dst, int /*midir*/, int8_t mienemy,
|
|||
// BUGFIX: should only run magic circle check if dObject[dx][dy] is non-zero.
|
||||
if (Objects[oi]._otype == OBJ_MCIRCLE1 || Objects[oi]._otype == OBJ_MCIRCLE2) {
|
||||
Missiles[mi].position.tile = dst;
|
||||
if (!PosOkPlayer(MyPlayerId, dst))
|
||||
if (!PosOkPlayer(Players[MyPlayerId], dst))
|
||||
UpdateVileMissPos(mi, dst);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1434,14 +1434,15 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
|
|||
assert(i >= 0 && i < MAXMONSTERS);
|
||||
auto &monster = Monsters[i];
|
||||
assert(monster.MType != nullptr);
|
||||
auto &player = Players[pnum];
|
||||
|
||||
if ((monster._mFlags & MFLAG_TARGETS_MONSTER) != 0) {
|
||||
MonsterAttackMonster(i, pnum, hit, minDam, maxDam);
|
||||
return;
|
||||
}
|
||||
if (Players[pnum]._pHitPoints >> 6 <= 0 || Players[pnum]._pInvincible || (Players[pnum]._pSpellFlags & 1) != 0)
|
||||
if (player._pHitPoints >> 6 <= 0 || player._pInvincible || (player._pSpellFlags & 1) != 0)
|
||||
return;
|
||||
if (monster.position.tile.WalkingDistance(Players[pnum].position.tile) >= 2)
|
||||
if (monster.position.tile.WalkingDistance(player.position.tile) >= 2)
|
||||
return;
|
||||
|
||||
int hper = GenerateRnd(100);
|
||||
|
|
@ -1449,15 +1450,15 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
|
|||
if (debug_mode_dollar_sign || debug_mode_key_inverted_v)
|
||||
hper = 1000;
|
||||
#endif
|
||||
int ac = Players[pnum]._pIBonusAC + Players[pnum]._pIAC;
|
||||
if ((Players[pnum].pDamAcFlags & ISPLHF_ACDEMON) != 0 && monster.MData->mMonstClass == MC_DEMON)
|
||||
int ac = player._pIBonusAC + player._pIAC;
|
||||
if ((player.pDamAcFlags & ISPLHF_ACDEMON) != 0 && monster.MData->mMonstClass == MC_DEMON)
|
||||
ac += 40;
|
||||
if ((Players[pnum].pDamAcFlags & ISPLHF_ACUNDEAD) != 0 && monster.MData->mMonstClass == MC_UNDEAD)
|
||||
if ((player.pDamAcFlags & ISPLHF_ACUNDEAD) != 0 && monster.MData->mMonstClass == MC_UNDEAD)
|
||||
ac += 20;
|
||||
hit += 2 * (monster.mLevel - Players[pnum]._pLevel)
|
||||
hit += 2 * (monster.mLevel - player._pLevel)
|
||||
+ 30
|
||||
- ac
|
||||
- Players[pnum]._pDexterity / 5;
|
||||
- player._pDexterity / 5;
|
||||
if (hit < 15)
|
||||
hit = 15;
|
||||
if (currlevel == 14 && hit < 20)
|
||||
|
|
@ -1467,13 +1468,13 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
|
|||
if (currlevel == 16 && hit < 30)
|
||||
hit = 30;
|
||||
int blkper = 100;
|
||||
if ((Players[pnum]._pmode == PM_STAND || Players[pnum]._pmode == PM_ATTACK) && Players[pnum]._pBlockFlag) {
|
||||
if ((player._pmode == PM_STAND || player._pmode == PM_ATTACK) && player._pBlockFlag) {
|
||||
blkper = GenerateRnd(100);
|
||||
}
|
||||
int blk = Players[pnum]._pDexterity
|
||||
+ Players[pnum]._pBaseToBlk
|
||||
int blk = player._pDexterity
|
||||
+ player._pBaseToBlk
|
||||
- (monster.mLevel * 2)
|
||||
+ (Players[pnum]._pLevel * 2);
|
||||
+ (player._pLevel * 2);
|
||||
if (blk < 0)
|
||||
blk = 0;
|
||||
if (blk > 100)
|
||||
|
|
@ -1481,12 +1482,12 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
|
|||
if (hper >= hit)
|
||||
return;
|
||||
if (blkper < blk) {
|
||||
Direction dir = GetDirection(Players[pnum].position.tile, monster.position.tile);
|
||||
Direction dir = GetDirection(player.position.tile, monster.position.tile);
|
||||
StartPlrBlock(pnum, dir);
|
||||
if (pnum == MyPlayerId && Players[pnum].wReflections > 0) {
|
||||
Players[pnum].wReflections--;
|
||||
if (pnum == MyPlayerId && player.wReflections > 0) {
|
||||
player.wReflections--;
|
||||
int dam = GenerateRnd((maxDam - minDam + 1) << 6) + (minDam << 6);
|
||||
dam += Players[pnum]._pIGetHit << 6;
|
||||
dam += player._pIGetHit << 6;
|
||||
if (dam < 64)
|
||||
dam = 64;
|
||||
int mdam = dam * (GenerateRnd(10) + 20L) / 100;
|
||||
|
|
@ -1510,30 +1511,30 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
|
|||
if (Missiles[mi]._misource == pnum)
|
||||
currentMissileId = mi;
|
||||
}
|
||||
if (Players[pnum]._pMaxHP > 64) {
|
||||
if (Players[pnum]._pMaxHPBase > 64) {
|
||||
Players[pnum]._pMaxHP -= 64;
|
||||
if (Players[pnum]._pHitPoints > Players[pnum]._pMaxHP) {
|
||||
Players[pnum]._pHitPoints = Players[pnum]._pMaxHP;
|
||||
if (player._pMaxHP > 64) {
|
||||
if (player._pMaxHPBase > 64) {
|
||||
player._pMaxHP -= 64;
|
||||
if (player._pHitPoints > player._pMaxHP) {
|
||||
player._pHitPoints = player._pMaxHP;
|
||||
if (currentMissileId >= 0)
|
||||
Missiles[currentMissileId]._miVar1 = Players[pnum]._pHitPoints;
|
||||
Missiles[currentMissileId]._miVar1 = player._pHitPoints;
|
||||
}
|
||||
Players[pnum]._pMaxHPBase -= 64;
|
||||
if (Players[pnum]._pHPBase > Players[pnum]._pMaxHPBase) {
|
||||
Players[pnum]._pHPBase = Players[pnum]._pMaxHPBase;
|
||||
player._pMaxHPBase -= 64;
|
||||
if (player._pHPBase > player._pMaxHPBase) {
|
||||
player._pHPBase = player._pMaxHPBase;
|
||||
if (currentMissileId >= 0)
|
||||
Missiles[currentMissileId]._miVar2 = Players[pnum]._pHPBase;
|
||||
Missiles[currentMissileId]._miVar2 = player._pHPBase;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int dam = (minDam << 6) + GenerateRnd((maxDam - minDam + 1) << 6);
|
||||
dam += (Players[pnum]._pIGetHit << 6);
|
||||
dam += (player._pIGetHit << 6);
|
||||
if (dam < 64)
|
||||
dam = 64;
|
||||
if (pnum == MyPlayerId) {
|
||||
if (Players[pnum].wReflections > 0) {
|
||||
Players[pnum].wReflections--;
|
||||
if (player.wReflections > 0) {
|
||||
player.wReflections--;
|
||||
int mdam = dam * (GenerateRnd(10) + 20L) / 100;
|
||||
monster._mhitpoints -= mdam;
|
||||
dam -= mdam;
|
||||
|
|
@ -1546,7 +1547,7 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
|
|||
}
|
||||
ApplyPlrDamage(pnum, 0, 0, dam);
|
||||
}
|
||||
if ((Players[pnum]._pIFlags & ISPL_THORNS) != 0) {
|
||||
if ((player._pIFlags & ISPL_THORNS) != 0) {
|
||||
int mdam = (GenerateRnd(3) + 1) << 6;
|
||||
monster._mhitpoints -= mdam;
|
||||
if (monster._mhitpoints >> 6 <= 0)
|
||||
|
|
@ -1556,23 +1557,23 @@ void MonsterAttackPlayer(int i, int pnum, int hit, int minDam, int maxDam)
|
|||
}
|
||||
if ((monster._mFlags & MFLAG_NOLIFESTEAL) == 0 && monster.MType->mtype == MT_SKING && gbIsMultiplayer)
|
||||
monster._mhitpoints += dam;
|
||||
if (Players[pnum]._pHitPoints >> 6 <= 0) {
|
||||
if (player._pHitPoints >> 6 <= 0) {
|
||||
if (gbIsHellfire)
|
||||
M_StartStand(monster, monster._mdir);
|
||||
return;
|
||||
}
|
||||
StartPlrHit(pnum, dam, false);
|
||||
if ((monster._mFlags & MFLAG_KNOCKBACK) != 0) {
|
||||
if (Players[pnum]._pmode != PM_GOTHIT)
|
||||
if (player._pmode != PM_GOTHIT)
|
||||
StartPlrHit(pnum, 0, true);
|
||||
|
||||
Point newPosition = Players[pnum].position.tile + monster._mdir;
|
||||
if (PosOkPlayer(pnum, newPosition)) {
|
||||
Players[pnum].position.tile = newPosition;
|
||||
FixPlayerLocation(pnum, Players[pnum]._pdir);
|
||||
Point newPosition = player.position.tile + monster._mdir;
|
||||
if (PosOkPlayer(player, newPosition)) {
|
||||
player.position.tile = newPosition;
|
||||
FixPlayerLocation(pnum, player._pdir);
|
||||
FixPlrWalkTags(pnum);
|
||||
dPlayer[newPosition.x][newPosition.y] = pnum + 1;
|
||||
SetPlayerOld(Players[pnum]);
|
||||
SetPlayerOld(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4933,15 +4934,16 @@ void MissToMonst(int i, Point position)
|
|||
if (monster.MType->mtype != MT_GLOOM && (monster.MType->mtype < MT_INCIN || monster.MType->mtype > MT_HELLBURN)) {
|
||||
MonsterAttackPlayer(m, dPlayer[oldPosition.x][oldPosition.y] - 1, 500, monster.mMinDamage2, monster.mMaxDamage2);
|
||||
if (pnum == dPlayer[oldPosition.x][oldPosition.y] - 1 && (monster.MType->mtype < MT_NSNAKE || monster.MType->mtype > MT_GSNAKE)) {
|
||||
if (Players[pnum]._pmode != PM_GOTHIT && Players[pnum]._pmode != PM_DEATH)
|
||||
auto &player = Players[pnum];
|
||||
if (player._pmode != PM_GOTHIT && player._pmode != PM_DEATH)
|
||||
StartPlrHit(pnum, 0, true);
|
||||
Point newPosition = oldPosition + monster._mdir;
|
||||
if (PosOkPlayer(pnum, newPosition)) {
|
||||
Players[pnum].position.tile = newPosition;
|
||||
FixPlayerLocation(pnum, Players[pnum]._pdir);
|
||||
if (PosOkPlayer(player, newPosition)) {
|
||||
player.position.tile = newPosition;
|
||||
FixPlayerLocation(pnum, player._pdir);
|
||||
FixPlrWalkTags(pnum);
|
||||
dPlayer[newPosition.x][newPosition.y] = pnum + 1;
|
||||
SetPlayerOld(Players[pnum]);
|
||||
SetPlayerOld(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
123
Source/msg.cpp
123
Source/msg.cpp
|
|
@ -45,7 +45,7 @@ struct TMegaPkt {
|
|||
byte data[32000];
|
||||
|
||||
TMegaPkt()
|
||||
: spaceLeft(sizeof(data))
|
||||
: spaceLeft(sizeof(data))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
@ -609,14 +609,14 @@ DWORD OnSyncData(TCmd *pCmd, int pnum)
|
|||
return sync_update(pnum, (const byte *)pCmd);
|
||||
}
|
||||
|
||||
DWORD OnWalk(TCmd *pCmd, int pnum)
|
||||
DWORD OnWalk(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdLoc *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
ClrPlrPath(Players[pnum]);
|
||||
MakePlrPath(pnum, { p->x, p->y }, true);
|
||||
Players[pnum].destAction = ACTION_NONE;
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
ClrPlrPath(player);
|
||||
MakePlrPath(player, { p->x, p->y }, true);
|
||||
player.destAction = ACTION_NONE;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
|
|
@ -670,14 +670,14 @@ DWORD OnAddVitality(TCmd *pCmd, int pnum)
|
|||
return sizeof(*p);
|
||||
}
|
||||
|
||||
DWORD OnGotoGetItem(TCmd *pCmd, int pnum)
|
||||
DWORD OnGotoGetItem(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdLocParam1 *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
MakePlrPath(pnum, { p->x, p->y }, false);
|
||||
Players[pnum].destAction = ACTION_PICKUPITEM;
|
||||
Players[pnum].destParam1 = p->wParam1;
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
MakePlrPath(player, { p->x, p->y }, false);
|
||||
player.destAction = ACTION_PICKUPITEM;
|
||||
player.destParam1 = p->wParam1;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
|
|
@ -736,14 +736,14 @@ DWORD OnGetItem(TCmd *pCmd, int pnum)
|
|||
return sizeof(*p);
|
||||
}
|
||||
|
||||
DWORD OnGotoAutoGetItem(TCmd *pCmd, int pnum)
|
||||
DWORD OnGotoAutoGetItem(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdLocParam1 *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
MakePlrPath(pnum, { p->x, p->y }, false);
|
||||
Players[pnum].destAction = ACTION_PICKUPAITEM;
|
||||
Players[pnum].destParam1 = p->wParam1;
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
MakePlrPath(player, { p->x, p->y }, false);
|
||||
player.destAction = ACTION_PICKUPAITEM;
|
||||
player.destParam1 = p->wParam1;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
|
|
@ -884,15 +884,15 @@ DWORD OnRespawnItem(TCmd *pCmd, int pnum)
|
|||
return sizeof(*p);
|
||||
}
|
||||
|
||||
DWORD OnAttackTile(TCmd *pCmd, int pnum)
|
||||
DWORD OnAttackTile(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdLoc *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
MakePlrPath(pnum, { p->x, p->y }, false);
|
||||
Players[pnum].destAction = ACTION_ATTACK;
|
||||
Players[pnum].destParam1 = p->x;
|
||||
Players[pnum].destParam2 = p->y;
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
MakePlrPath(player, { p->x, p->y }, false);
|
||||
player.destAction = ACTION_ATTACK;
|
||||
player.destParam1 = p->x;
|
||||
player.destParam2 = p->y;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
|
|
@ -996,33 +996,27 @@ DWORD OnTargetSpellTile(TCmd *pCmd, int pnum)
|
|||
return sizeof(*p);
|
||||
}
|
||||
|
||||
DWORD OnOperateObjectTile(TCmd *pCmd, int pnum)
|
||||
DWORD OnOperateObjectTile(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdLocParam1 *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
if (Objects[p->wParam1]._oSolidFlag || Objects[p->wParam1]._oDoorFlag)
|
||||
MakePlrPath(pnum, { p->x, p->y }, false);
|
||||
else
|
||||
MakePlrPath(pnum, { p->x, p->y }, true);
|
||||
Players[pnum].destAction = ACTION_OPERATE;
|
||||
Players[pnum].destParam1 = p->wParam1;
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
MakePlrPath(player, { p->x, p->y }, !Objects[p->wParam1]._oSolidFlag && !Objects[p->wParam1]._oDoorFlag);
|
||||
player.destAction = ACTION_OPERATE;
|
||||
player.destParam1 = p->wParam1;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
}
|
||||
|
||||
DWORD OnDisarm(TCmd *pCmd, int pnum)
|
||||
DWORD OnDisarm(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdLocParam1 *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
if (Objects[p->wParam1]._oSolidFlag || Objects[p->wParam1]._oDoorFlag)
|
||||
MakePlrPath(pnum, { p->x, p->y }, false);
|
||||
else
|
||||
MakePlrPath(pnum, { p->x, p->y }, true);
|
||||
Players[pnum].destAction = ACTION_DISARM;
|
||||
Players[pnum].destParam1 = p->wParam1;
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
MakePlrPath(player, { p->x, p->y }, !Objects[p->wParam1]._oSolidFlag && !Objects[p->wParam1]._oDoorFlag);
|
||||
player.destAction = ACTION_DISARM;
|
||||
player.destParam1 = p->wParam1;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
|
|
@ -1040,29 +1034,29 @@ DWORD OnOperateObjectTelekinesis(TCmd *pCmd, int pnum)
|
|||
return sizeof(*p);
|
||||
}
|
||||
|
||||
DWORD OnAttackMonster(TCmd *pCmd, int pnum)
|
||||
DWORD OnAttackMonster(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdParam1 *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
Point position = Monsters[p->wParam1].position.future;
|
||||
if (Players[pnum].position.tile.WalkingDistance(position) > 1)
|
||||
MakePlrPath(pnum, position, false);
|
||||
Players[pnum].destAction = ACTION_ATTACKMON;
|
||||
Players[pnum].destParam1 = p->wParam1;
|
||||
if (player.position.tile.WalkingDistance(position) > 1)
|
||||
MakePlrPath(player, position, false);
|
||||
player.destAction = ACTION_ATTACKMON;
|
||||
player.destParam1 = p->wParam1;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
}
|
||||
|
||||
DWORD OnAttackPlayer(TCmd *pCmd, int pnum)
|
||||
DWORD OnAttackPlayer(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdParam1 *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
MakePlrPath(pnum, Players[p->wParam1].position.future, false);
|
||||
Players[pnum].destAction = ACTION_ATTACKPLR;
|
||||
Players[pnum].destParam1 = p->wParam1;
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
MakePlrPath(player, Players[p->wParam1].position.future, false);
|
||||
player.destAction = ACTION_ATTACKPLR;
|
||||
player.destParam1 = p->wParam1;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
|
|
@ -1218,14 +1212,14 @@ DWORD OnHealOther(TCmd *pCmd, int pnum)
|
|||
return sizeof(*p);
|
||||
}
|
||||
|
||||
DWORD OnTalkXY(TCmd *pCmd, int pnum)
|
||||
DWORD OnTalkXY(TCmd *pCmd, PlayerStruct &player)
|
||||
{
|
||||
auto *p = (TCmdLocParam1 *)pCmd;
|
||||
|
||||
if (gbBufferMsgs != 1 && currlevel == Players[pnum].plrlevel) {
|
||||
MakePlrPath(pnum, { p->x, p->y }, false);
|
||||
Players[pnum].destAction = ACTION_TALK;
|
||||
Players[pnum].destParam1 = p->wParam1;
|
||||
if (gbBufferMsgs != 1 && currlevel == player.plrlevel) {
|
||||
MakePlrPath(player, { p->x, p->y }, false);
|
||||
player.destAction = ACTION_TALK;
|
||||
player.destParam1 = p->wParam1;
|
||||
}
|
||||
|
||||
return sizeof(*p);
|
||||
|
|
@ -2013,7 +2007,6 @@ Point GetItemPosition(Point position)
|
|||
int xx = position.x + l;
|
||||
if (CanPut({ xx, yy }))
|
||||
return { xx, yy };
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2507,11 +2500,13 @@ DWORD ParseCmd(int pnum, TCmd *pCmd)
|
|||
if (sgwPackPlrOffsetTbl[pnum] != 0 && sbLastCmd != CMD_ACK_PLRINFO && sbLastCmd != CMD_SEND_PLRINFO)
|
||||
return 0;
|
||||
|
||||
auto &player = Players[pnum];
|
||||
|
||||
switch (pCmd->bCmd) {
|
||||
case CMD_SYNCDATA:
|
||||
return OnSyncData(pCmd, pnum);
|
||||
case CMD_WALKXY:
|
||||
return OnWalk(pCmd, pnum);
|
||||
return OnWalk(pCmd, player);
|
||||
case CMD_ADDSTR:
|
||||
return OnAddStrength(pCmd, pnum);
|
||||
case CMD_ADDDEX:
|
||||
|
|
@ -2521,13 +2516,13 @@ DWORD ParseCmd(int pnum, TCmd *pCmd)
|
|||
case CMD_ADDVIT:
|
||||
return OnAddVitality(pCmd, pnum);
|
||||
case CMD_GOTOGETITEM:
|
||||
return OnGotoGetItem(pCmd, pnum);
|
||||
return OnGotoGetItem(pCmd, player);
|
||||
case CMD_REQUESTGITEM:
|
||||
return OnRequestGetItem(pCmd, pnum);
|
||||
case CMD_GETITEM:
|
||||
return OnGetItem(pCmd, pnum);
|
||||
case CMD_GOTOAGETITEM:
|
||||
return OnGotoAutoGetItem(pCmd, pnum);
|
||||
return OnGotoAutoGetItem(pCmd, player);
|
||||
case CMD_REQUESTAGITEM:
|
||||
return OnRequestAutoGetItem(pCmd, pnum);
|
||||
case CMD_AGETITEM:
|
||||
|
|
@ -2541,7 +2536,7 @@ DWORD ParseCmd(int pnum, TCmd *pCmd)
|
|||
case CMD_RESPAWNITEM:
|
||||
return OnRespawnItem(pCmd, pnum);
|
||||
case CMD_ATTACKXY:
|
||||
return OnAttackTile(pCmd, pnum);
|
||||
return OnAttackTile(pCmd, player);
|
||||
case CMD_SATTACKXY:
|
||||
return OnStandingAttackTile(pCmd, pnum);
|
||||
case CMD_RATTACKXY:
|
||||
|
|
@ -2553,15 +2548,15 @@ DWORD ParseCmd(int pnum, TCmd *pCmd)
|
|||
case CMD_TSPELLXY:
|
||||
return OnTargetSpellTile(pCmd, pnum);
|
||||
case CMD_OPOBJXY:
|
||||
return OnOperateObjectTile(pCmd, pnum);
|
||||
return OnOperateObjectTile(pCmd, player);
|
||||
case CMD_DISARMXY:
|
||||
return OnDisarm(pCmd, pnum);
|
||||
return OnDisarm(pCmd, player);
|
||||
case CMD_OPOBJT:
|
||||
return OnOperateObjectTelekinesis(pCmd, pnum);
|
||||
case CMD_ATTACKID:
|
||||
return OnAttackMonster(pCmd, pnum);
|
||||
return OnAttackMonster(pCmd, player);
|
||||
case CMD_ATTACKPID:
|
||||
return OnAttackPlayer(pCmd, pnum);
|
||||
return OnAttackPlayer(pCmd, player);
|
||||
case CMD_RATTACKID:
|
||||
return OnRangedAttackMonster(pCmd, pnum);
|
||||
case CMD_RATTACKPID:
|
||||
|
|
@ -2581,7 +2576,7 @@ DWORD ParseCmd(int pnum, TCmd *pCmd)
|
|||
case CMD_HEALOTHER:
|
||||
return OnHealOther(pCmd, pnum);
|
||||
case CMD_TALKXY:
|
||||
return OnTalkXY(pCmd, pnum);
|
||||
return OnTalkXY(pCmd, player);
|
||||
case CMD_DEBUG:
|
||||
return OnDebug(pCmd);
|
||||
case CMD_NEWLVL:
|
||||
|
|
|
|||
|
|
@ -599,36 +599,37 @@ void multi_process_network_packets()
|
|||
continue;
|
||||
if (pkt->wLen != dwMsgSize)
|
||||
continue;
|
||||
Players[dwID].position.last = { pkt->px, pkt->py };
|
||||
auto &player = Players[dwID];
|
||||
player.position.last = { pkt->px, pkt->py };
|
||||
if (dwID != MyPlayerId) {
|
||||
assert(gbBufferMsgs != 2);
|
||||
Players[dwID]._pHitPoints = pkt->php;
|
||||
Players[dwID]._pMaxHP = pkt->pmhp;
|
||||
player._pHitPoints = pkt->php;
|
||||
player._pMaxHP = pkt->pmhp;
|
||||
bool cond = gbBufferMsgs == 1;
|
||||
Players[dwID]._pBaseStr = pkt->bstr;
|
||||
Players[dwID]._pBaseMag = pkt->bmag;
|
||||
Players[dwID]._pBaseDex = pkt->bdex;
|
||||
if (!cond && Players[dwID].plractive && Players[dwID]._pHitPoints != 0) {
|
||||
if (currlevel == Players[dwID].plrlevel && !Players[dwID]._pLvlChanging) {
|
||||
int dx = abs(Players[dwID].position.tile.x - pkt->px);
|
||||
int dy = abs(Players[dwID].position.tile.y - pkt->py);
|
||||
player._pBaseStr = pkt->bstr;
|
||||
player._pBaseMag = pkt->bmag;
|
||||
player._pBaseDex = pkt->bdex;
|
||||
if (!cond && player.plractive && player._pHitPoints != 0) {
|
||||
if (currlevel == player.plrlevel && !player._pLvlChanging) {
|
||||
int dx = abs(player.position.tile.x - pkt->px);
|
||||
int dy = abs(player.position.tile.y - pkt->py);
|
||||
if ((dx > 3 || dy > 3) && dPlayer[pkt->px][pkt->py] == 0) {
|
||||
FixPlrWalkTags(dwID);
|
||||
Players[dwID].position.old = Players[dwID].position.tile;
|
||||
player.position.old = player.position.tile;
|
||||
FixPlrWalkTags(dwID);
|
||||
Players[dwID].position.tile = { pkt->px, pkt->py };
|
||||
Players[dwID].position.future = { pkt->px, pkt->py };
|
||||
dPlayer[Players[dwID].position.tile.x][Players[dwID].position.tile.y] = dwID + 1;
|
||||
player.position.tile = { pkt->px, pkt->py };
|
||||
player.position.future = { pkt->px, pkt->py };
|
||||
dPlayer[player.position.tile.x][player.position.tile.y] = dwID + 1;
|
||||
}
|
||||
dx = abs(Players[dwID].position.future.x - Players[dwID].position.tile.x);
|
||||
dy = abs(Players[dwID].position.future.y - Players[dwID].position.tile.y);
|
||||
dx = abs(player.position.future.x - player.position.tile.x);
|
||||
dy = abs(player.position.future.y - player.position.tile.y);
|
||||
if (dx > 1 || dy > 1) {
|
||||
Players[dwID].position.future = Players[dwID].position.tile;
|
||||
player.position.future = player.position.tile;
|
||||
}
|
||||
MakePlrPath(dwID, { pkt->targx, pkt->targy }, true);
|
||||
MakePlrPath(player, { pkt->targx, pkt->targy }, true);
|
||||
} else {
|
||||
Players[dwID].position.tile = { pkt->px, pkt->py };
|
||||
Players[dwID].position.future = { pkt->px, pkt->py };
|
||||
player.position.tile = { pkt->px, pkt->py };
|
||||
player.position.future = { pkt->px, pkt->py };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,16 +319,11 @@ void ScrollViewPort(const PlayerStruct &player, _scroll_direction dir)
|
|||
}
|
||||
}
|
||||
|
||||
bool PlrDirOK(int pnum, Direction dir)
|
||||
bool PlrDirOK(const PlayerStruct &player, Direction dir)
|
||||
{
|
||||
if ((DWORD)pnum >= MAX_PLRS) {
|
||||
app_fatal("PlrDirOK: illegal player %i", pnum);
|
||||
}
|
||||
auto &player = Players[pnum];
|
||||
|
||||
Point position = player.position.tile;
|
||||
Point futurePosition = position + dir;
|
||||
if (futurePosition.x < 0 || dPiece[futurePosition.x][futurePosition.y] == 0 || !PosOkPlayer(pnum, futurePosition)) {
|
||||
if (futurePosition.x < 0 || dPiece[futurePosition.x][futurePosition.y] == 0 || !PosOkPlayer(player, futurePosition)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -348,7 +343,7 @@ void HandleWalkMode(int pnum, Displacement vel, Direction dir)
|
|||
auto &player = Players[pnum];
|
||||
const auto &dirModeParams = WalkSettings[dir];
|
||||
SetPlayerOld(player);
|
||||
if (!PlrDirOK(pnum, dir)) {
|
||||
if (!PlrDirOK(player, dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1590,7 +1585,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
|
|||
return;
|
||||
}
|
||||
if (player.destAction == ACTION_ATTACKMON)
|
||||
MakePlrPath(pnum, monster->position.future, false);
|
||||
MakePlrPath(player, monster->position.future, false);
|
||||
break;
|
||||
case ACTION_ATTACKPLR:
|
||||
case ACTION_RATTACKPLR:
|
||||
|
|
@ -1601,7 +1596,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
|
|||
return;
|
||||
}
|
||||
if (player.destAction == ACTION_ATTACKPLR)
|
||||
MakePlrPath(pnum, target->position.future, false);
|
||||
MakePlrPath(player, target->position.future, false);
|
||||
break;
|
||||
case ACTION_OPERATE:
|
||||
case ACTION_DISARM:
|
||||
|
|
@ -2813,7 +2808,7 @@ void InitPlayer(int pnum, bool firstTime)
|
|||
}
|
||||
} else {
|
||||
unsigned i;
|
||||
for (i = 0; i < 8 && !PosOkPlayer(pnum, player.position.tile + Displacement { plrxoff2[i], plryoff2[i] }); i++)
|
||||
for (i = 0; i < 8 && !PosOkPlayer(player, player.position.tile + Displacement { plrxoff2[i], plryoff2[i] }); i++)
|
||||
;
|
||||
player.position.tile.x += plrxoff2[i];
|
||||
player.position.tile.y += plryoff2[i];
|
||||
|
|
@ -3493,11 +3488,10 @@ void ClrPlrPath(PlayerStruct &player)
|
|||
*
|
||||
* This requires an ID instead of a PlayerStruct& to compare with the dPlayer lookup table values.
|
||||
*
|
||||
* @param pnum ID of the player.
|
||||
* @param position Dungeon tile coordinates.
|
||||
* @return False if something (other than the player themselves) is blocking the tile.
|
||||
*/
|
||||
bool PosOkPlayer(int pnum, Point position)
|
||||
bool PosOkPlayer(const PlayerStruct &player, Point position)
|
||||
{
|
||||
if (position.x < 0 || position.x >= MAXDUNX || position.y < 0 || position.y >= MAXDUNY)
|
||||
return false;
|
||||
|
|
@ -3506,16 +3500,8 @@ bool PosOkPlayer(int pnum, Point position)
|
|||
if (!IsTileWalkable(position))
|
||||
return false;
|
||||
if (dPlayer[position.x][position.y] != 0) {
|
||||
int8_t p = -1;
|
||||
if (dPlayer[position.x][position.y] > 0) {
|
||||
p = dPlayer[position.x][position.y] - 1;
|
||||
} else {
|
||||
p = -(dPlayer[position.x][position.y] + 1);
|
||||
}
|
||||
if (p != pnum
|
||||
&& p >= 0
|
||||
&& p < MAX_PLRS
|
||||
&& Players[p]._pHitPoints != 0) {
|
||||
auto &otherPlayer = Players[abs(dPlayer[position.x][position.y]) - 1];
|
||||
if (&otherPlayer != &player && otherPlayer._pHitPoints != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -3535,18 +3521,13 @@ bool PosOkPlayer(int pnum, Point position)
|
|||
return true;
|
||||
}
|
||||
|
||||
void MakePlrPath(int pnum, Point targetPosition, bool endspace)
|
||||
void MakePlrPath(PlayerStruct &player, Point targetPosition, bool endspace)
|
||||
{
|
||||
if ((DWORD)pnum >= MAX_PLRS) {
|
||||
app_fatal("MakePlrPath: illegal player %i", pnum);
|
||||
}
|
||||
auto &player = Players[pnum];
|
||||
|
||||
if (player.position.future == targetPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
int path = FindPath([pnum](Point position) { return PosOkPlayer(pnum, position); }, player.position.future, targetPosition, player.walkpath);
|
||||
int path = FindPath([&player](Point position) { return PosOkPlayer(player, position); }, player.position.future, targetPosition, player.walkpath);
|
||||
if (path == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -3718,19 +3699,19 @@ void SyncInitPlrPos(int pnum)
|
|||
Point position = {};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
position = player.position.tile + Displacement { plrxoff2[i], plryoff2[i] };
|
||||
if (PosOkPlayer(pnum, position)) {
|
||||
if (PosOkPlayer(player, position)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PosOkPlayer(pnum, position)) {
|
||||
if (!PosOkPlayer(player, position)) {
|
||||
bool posOk = false;
|
||||
for (int range = 1; range < 50 && !posOk; range++) {
|
||||
for (int yy = -range; yy <= range && !posOk; yy++) {
|
||||
position.y = yy + player.position.tile.y;
|
||||
for (int xx = -range; xx <= range && !posOk; xx++) {
|
||||
position.x = xx + player.position.tile.x;
|
||||
if (PosOkPlayer(pnum, position) && !PosOkPortal(currlevel, position.x, position.y)) {
|
||||
if (PosOkPlayer(player, position) && !PosOkPortal(currlevel, position.x, position.y)) {
|
||||
posOk = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -447,7 +447,6 @@ void ResetPlayerGFX(PlayerStruct &player);
|
|||
|
||||
/**
|
||||
* @brief Sets the new Player Animation with all relevant information for rendering
|
||||
* @param pnum Player Id
|
||||
* @param graphic What player animation should be displayed
|
||||
* @param dir Direction of the animation
|
||||
* @param numberOfFrames Number of Frames in Animation
|
||||
|
|
@ -486,8 +485,8 @@ void RestartTownLvl(int pnum);
|
|||
void StartWarpLvl(int pnum, int pidx);
|
||||
void ProcessPlayers();
|
||||
void ClrPlrPath(PlayerStruct &player);
|
||||
bool PosOkPlayer(int pnum, Point position);
|
||||
void MakePlrPath(int pnum, Point targetPosition, bool endspace);
|
||||
bool PosOkPlayer(const PlayerStruct &player, Point position);
|
||||
void MakePlrPath(PlayerStruct &player, Point targetPosition, bool endspace);
|
||||
void CalcPlrStaff(PlayerStruct &player);
|
||||
void CheckPlrSpell(bool mouseClick);
|
||||
void SyncPlrAnim(int pnum);
|
||||
|
|
|
|||
|
|
@ -201,28 +201,29 @@ void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl)
|
|||
|
||||
static void PlacePlayer(int pnum)
|
||||
{
|
||||
auto &player = Players[pnum];
|
||||
Point newPosition = {};
|
||||
|
||||
if (Players[pnum].plrlevel == currlevel) {
|
||||
if (player.plrlevel == currlevel) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
newPosition = Players[pnum].position.tile + Displacement { plrxoff2[i], plryoff2[i] };
|
||||
if (PosOkPlayer(pnum, newPosition)) {
|
||||
newPosition = player.position.tile + Displacement { plrxoff2[i], plryoff2[i] };
|
||||
if (PosOkPlayer(player, newPosition)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PosOkPlayer(pnum, newPosition)) {
|
||||
if (!PosOkPlayer(player, newPosition)) {
|
||||
bool done = false;
|
||||
|
||||
int min = -1;
|
||||
for (int max = 1; min > -50 && !done; max++, min--) {
|
||||
for (int y = min; y <= max && !done; y++) {
|
||||
newPosition.y = Players[pnum].position.tile.y + y;
|
||||
newPosition.y = player.position.tile.y + y;
|
||||
|
||||
for (int x = min; x <= max && !done; x++) {
|
||||
newPosition.x = Players[pnum].position.tile.x + x;
|
||||
newPosition.x = player.position.tile.x + x;
|
||||
|
||||
if (PosOkPlayer(pnum, newPosition)) {
|
||||
if (PosOkPlayer(player, newPosition)) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -230,7 +231,7 @@ static void PlacePlayer(int pnum)
|
|||
}
|
||||
}
|
||||
|
||||
Players[pnum].position.tile = newPosition;
|
||||
player.position.tile = newPosition;
|
||||
|
||||
dPlayer[newPosition.x][newPosition.y] = pnum + 1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue