Browse Source

♻️Pass player to towner by reference instead of index

pull/1884/head
Anders Jenbo 5 years ago
parent
commit
6321bf04d5
  1. 2
      Source/control.cpp
  2. 2
      Source/debug.cpp
  3. 84
      Source/inv.cpp
  4. 9
      Source/inv.h
  5. 23
      Source/items.cpp
  6. 7
      Source/items.h
  7. 2
      Source/loadsave.cpp
  8. 16
      Source/monster.cpp
  9. 53
      Source/objects.cpp
  10. 69
      Source/player.cpp
  11. 12
      Source/player.h
  12. 6
      Source/stores.cpp
  13. 213
      Source/towners.cpp
  14. 5
      Source/towners.h
  15. 4
      test/inv_test.cpp

2
Source/control.cpp

@ -1969,7 +1969,7 @@ void control_remove_gold(int pnum, int goldIndex)
if (plr[pnum].InvList[gi]._ivalue > 0)
SetGoldCurs(pnum, gi);
else
RemoveInvItem(pnum, gi);
plr[pnum].RemoveInvItem(gi);
} else {
int gi = goldIndex - INVITEM_BELT_FIRST;
plr[pnum].SpdList[gi]._ivalue -= dropGoldValue;

2
Source/debug.cpp

@ -76,7 +76,7 @@ void TakeGoldCheat()
for (i = 0; i < NUM_INV_GRID_ELEM; i++) {
ig = plr[myplr].InvGrid[i];
if (ig > 0 && plr[myplr].InvList[ig - 1]._itype == ITYPE_GOLD)
RemoveInvItem(myplr, ig - 1);
plr[myplr].RemoveInvItem(ig - 1);
}
for (i = 0; i < MAXBELTITEMS; i++) {

84
Source/inv.cpp

@ -422,7 +422,7 @@ bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistI
if (beltItem.isEmpty()) {
if (persistItem) {
beltItem = item;
CalcPlrScrolls(playerNumber);
plr[playerNumber].CalcScrolls();
drawsbarflag = true;
}
@ -749,7 +749,7 @@ bool AutoPlaceItemInInventorySlot(int playerNumber, int slotIndex, const ItemStr
plr[playerNumber]._pNumInv++;
AddItemToInvGrid(playerNumber, slotIndex, plr[playerNumber]._pNumInv, itemSize.X, itemSize.Y);
CalcPlrScrolls(playerNumber);
plr[playerNumber].CalcScrolls();
}
return done;
}
@ -1426,7 +1426,7 @@ void CheckInvCut(int pnum, int mx, int my, bool automaticMove)
}
if (!automaticMove || automaticallyMoved) {
RemoveInvItem(pnum, iv - 1, false);
plr[pnum].RemoveInvItem(iv - 1, false);
}
}
}
@ -1492,45 +1492,11 @@ void inv_update_rem_item(int pnum, BYTE iv)
}
}
void RemoveInvItem(int pnum, int iv, bool calcPlrScrolls)
{
int i, j;
iv++;
//Iterate through invGrid and remove every reference to item
for (i = 0; i < NUM_INV_GRID_ELEM; i++) {
if (plr[pnum].InvGrid[i] == iv || plr[pnum].InvGrid[i] == -iv) {
plr[pnum].InvGrid[i] = 0;
}
}
iv--;
plr[pnum]._pNumInv--;
//If the item at the end of inventory array isn't the one we removed, we need to swap its position in the array with the removed item
if (plr[pnum]._pNumInv > 0 && plr[pnum]._pNumInv != iv) {
plr[pnum].InvList[iv] = plr[pnum].InvList[plr[pnum]._pNumInv];
for (j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (plr[pnum].InvGrid[j] == plr[pnum]._pNumInv + 1) {
plr[pnum].InvGrid[j] = iv + 1;
}
if (plr[pnum].InvGrid[j] == -(plr[pnum]._pNumInv + 1)) {
plr[pnum].InvGrid[j] = -(iv + 1);
}
}
}
if (calcPlrScrolls)
CalcPlrScrolls(pnum);
}
void RemoveSpdBarItem(int pnum, int iv)
{
plr[pnum].SpdList[iv]._itype = ITYPE_NONE;
CalcPlrScrolls(pnum);
plr[pnum].CalcScrolls();
force_redraw = 255;
}
@ -1626,36 +1592,36 @@ void CheckQuestItem(int pnum)
}
if (plr[pnum].HoldItem.IDidx == IDI_NOTE1 || plr[pnum].HoldItem.IDidx == IDI_NOTE2 || plr[pnum].HoldItem.IDidx == IDI_NOTE3) {
int mask, idx, item_num;
int n1, n2, n3;
ItemStruct tmp;
mask = 0;
idx = plr[pnum].HoldItem.IDidx;
if (PlrHasItem(pnum, IDI_NOTE1, &n1) != nullptr || idx == IDI_NOTE1)
if (plr[pnum].HasItem(IDI_NOTE1) || idx == IDI_NOTE1)
mask = 1;
if (PlrHasItem(pnum, IDI_NOTE2, &n2) != nullptr || idx == IDI_NOTE2)
if (plr[pnum].HasItem(IDI_NOTE2) || idx == IDI_NOTE2)
mask |= 2;
if (PlrHasItem(pnum, IDI_NOTE3, &n3) != nullptr || idx == IDI_NOTE3)
if (plr[pnum].HasItem(IDI_NOTE3) || idx == IDI_NOTE3)
mask |= 4;
if (mask == 7) {
int n1, n2, n3;
plr[myplr].PlaySpeach(46, 10);
switch (idx) {
case IDI_NOTE1:
PlrHasItem(pnum, IDI_NOTE2, &n2);
RemoveInvItem(pnum, n2);
PlrHasItem(pnum, IDI_NOTE3, &n3);
RemoveInvItem(pnum, n3);
plr[pnum].HasItem(IDI_NOTE2, &n2);
plr[pnum].RemoveInvItem(n2);
plr[pnum].HasItem(IDI_NOTE3, &n3);
plr[pnum].RemoveInvItem(n3);
break;
case IDI_NOTE2:
PlrHasItem(pnum, IDI_NOTE1, &n1);
RemoveInvItem(pnum, n1);
PlrHasItem(pnum, IDI_NOTE3, &n3);
RemoveInvItem(pnum, n3);
plr[pnum].HasItem(IDI_NOTE1, &n1);
plr[pnum].RemoveInvItem(n1);
plr[pnum].HasItem(IDI_NOTE3, &n3);
plr[pnum].RemoveInvItem(n3);
break;
case IDI_NOTE3:
PlrHasItem(pnum, IDI_NOTE1, &n1);
RemoveInvItem(pnum, n1);
PlrHasItem(pnum, IDI_NOTE2, &n2);
RemoveInvItem(pnum, n2);
plr[pnum].HasItem(IDI_NOTE1, &n1);
plr[pnum].RemoveInvItem(n1);
plr[pnum].HasItem(IDI_NOTE2, &n2);
plr[pnum].RemoveInvItem(n2);
break;
}
item_num = itemactive[0];
@ -1925,7 +1891,7 @@ static bool PutItem(int pnum, Point &position)
if (!CanPut(xp, yp))
continue;
position = {xp,yp};
position = { xp, yp };
return true;
}
}
@ -2129,8 +2095,8 @@ void RemoveScroll(int pnum)
if (!plr[pnum].InvList[i].isEmpty()
&& (plr[pnum].InvList[i]._iMiscId == IMISC_SCROLL || plr[pnum].InvList[i]._iMiscId == IMISC_SCROLLT)
&& plr[pnum].InvList[i]._iSpell == plr[pnum]._pRSpell) {
RemoveInvItem(pnum, i);
CalcPlrScrolls(pnum);
plr[pnum].RemoveInvItem(i);
plr[pnum].CalcScrolls();
return;
}
}
@ -2139,7 +2105,7 @@ void RemoveScroll(int pnum)
&& (plr[pnum].SpdList[i]._iMiscId == IMISC_SCROLL || plr[pnum].SpdList[i]._iMiscId == IMISC_SCROLLT)
&& plr[pnum].SpdList[i]._iSpell == plr[pnum]._pSpell) {
RemoveSpdBarItem(pnum, i);
CalcPlrScrolls(pnum);
plr[pnum].CalcScrolls();
return;
}
}
@ -2303,7 +2269,7 @@ bool UseInvItem(int pnum, int cii)
invflag = false;
return true;
}
RemoveInvItem(pnum, c);
plr[pnum].RemoveInvItem(c);
return true;
}

9
Source/inv.h

@ -95,15 +95,6 @@ bool AutoPlaceItemInBelt(int playerNumber, const ItemStruct &item, bool persistI
bool GoldAutoPlace(int pnum);
void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff);
void inv_update_rem_item(int pnum, BYTE iv);
/**
* @brief Remove an item from player inventory
* @param pnum Player index
* @param iv invList index of item to be removed
* @param calcPlrScrolls If true, CalcPlrScrolls() gets called after removing item
*/
void RemoveInvItem(int pnum, int iv, bool calcPlrScrolls = true);
void RemoveSpdBarItem(int pnum, int iv);
void CheckInvItem(bool isShiftHeld = false);
void CheckInvScrn(bool isShiftHeld);

23
Source/items.cpp

@ -906,27 +906,6 @@ void CalcPlrItemVals(int p, bool Loadgfx)
drawhpflag = true;
}
void CalcPlrScrolls(int p)
{
int i, j;
plr[p]._pScrlSpells = 0;
for (i = 0; i < plr[p]._pNumInv; i++) {
if (!plr[p].InvList[i].isEmpty() && (plr[p].InvList[i]._iMiscId == IMISC_SCROLL || plr[p].InvList[i]._iMiscId == IMISC_SCROLLT)) {
if (plr[p].InvList[i]._iStatFlag)
plr[p]._pScrlSpells |= GetSpellBitmask(plr[p].InvList[i]._iSpell);
}
}
for (j = 0; j < MAXBELTITEMS; j++) {
if (!plr[p].SpdList[j].isEmpty() && (plr[p].SpdList[j]._iMiscId == IMISC_SCROLL || plr[p].SpdList[j]._iMiscId == IMISC_SCROLLT)) {
if (plr[p].SpdList[j]._iStatFlag)
plr[p]._pScrlSpells |= GetSpellBitmask(plr[p].SpdList[j]._iSpell);
}
}
EnsureValidReadiedSpell(plr[p]);
}
void CalcPlrStaff(int p)
{
plr[p]._pISpells = 0;
@ -1062,7 +1041,7 @@ void CalcPlrInv(int p, bool Loadgfx)
CalcPlrItemMin(p);
if (p == myplr) {
CalcPlrBookVals(p);
CalcPlrScrolls(p);
plr[p].CalcScrolls();
CalcPlrStaff(p);
if (p == myplr && currlevel == 0)
RecalcStoreStats();

7
Source/items.h

@ -173,9 +173,9 @@ struct ItemStruct {
Point position;
bool _iAnimFlag;
CelSprite *_iAnimData; // PSX name -> ItemFrame
uint8_t _iAnimLen; // Number of frames in current animation
uint8_t _iAnimFrame; // Current frame of animation.
bool _iDelFlag; // set when item is flagged for deletion, deprecated in 1.02
uint8_t _iAnimLen; // Number of frames in current animation
uint8_t _iAnimFrame; // Current frame of animation.
bool _iDelFlag; // set when item is flagged for deletion, deprecated in 1.02
uint8_t _iSelFlag;
bool _iPostDraw;
bool _iIdentified;
@ -377,7 +377,6 @@ bool IsUniqueAvailable(int i);
void InitItemGFX();
void InitItems();
void CalcPlrItemVals(int p, bool Loadgfx);
void CalcPlrScrolls(int p);
void CalcPlrStaff(int p);
void CalcPlrInv(int p, bool Loadgfx);
void SetPlrHandItem(ItemStruct *h, int idata);

2
Source/loadsave.cpp

@ -965,7 +965,7 @@ void RemoveEmptyInventory(int pnum)
for (int i = NUM_INV_GRID_ELEM; i > 0; i--) {
int idx = plr[pnum].InvGrid[i - 1];
if (idx > 0 && plr[pnum].InvList[idx - 1].isEmpty()) {
RemoveInvItem(pnum, idx - 1);
plr[pnum].RemoveInvItem(idx - 1);
}
};
}

16
Source/monster.cpp

@ -5372,24 +5372,22 @@ int PreSpawnSkeleton()
void TalktoMonster(int i)
{
MonsterStruct *Monst;
int pnum, itm;
assurance((DWORD)i < MAXMONSTERS, i);
Monst = &monster[i];
pnum = Monst->_menemy;
MonsterStruct *Monst = &monster[i];
int pnum = Monst->_menemy;
Monst->_mmode = MM_TALK;
if (Monst->_mAi == AI_SNOTSPIL || Monst->_mAi == AI_LACHDAN) {
if (QuestStatus(Q_LTBANNER) && quests[Q_LTBANNER]._qvar1 == 2 && PlrHasItem(pnum, IDI_BANNER, &itm)) {
RemoveInvItem(pnum, itm);
int itm;
if (QuestStatus(Q_LTBANNER) && quests[Q_LTBANNER]._qvar1 == 2 && plr[pnum].HasItem(IDI_BANNER, &itm)) {
plr[pnum].RemoveInvItem(itm);
quests[Q_LTBANNER]._qactive = QUEST_DONE;
Monst->mtalkmsg = TEXT_BANNER12;
Monst->_mgoal = MGOAL_INQUIRING;
}
if (QuestStatus(Q_VEIL) && Monst->mtalkmsg >= TEXT_VEIL9) {
if (PlrHasItem(pnum, IDI_GLDNELIX, &itm)) {
RemoveInvItem(pnum, itm);
if (plr[pnum].HasItem(IDI_GLDNELIX, &itm)) {
plr[pnum].RemoveInvItem(itm);
Monst->mtalkmsg = TEXT_VEIL11;
Monst->_mgoal = MGOAL_INQUIRING;
}

53
Source/objects.cpp

@ -3288,36 +3288,37 @@ void OperateL3Door(int pnum, int i, bool sendflag)
void OperatePedistal(int pnum, int i)
{
int iv;
if (numitems >= MAXITEMS) {
return;
}
if (object[i]._oVar6 != 3 && PlrHasItem(pnum, IDI_BLDSTONE, &iv) != nullptr) {
RemoveInvItem(pnum, iv);
object[i]._oAnimFrame++;
object[i]._oVar6++;
if (object[i]._oVar6 == 1) {
if (!deltaload)
PlaySfxLoc(LS_PUDDLE, object[i].position.x, object[i].position.y);
ObjChangeMap(setpc_x, setpc_y + 3, setpc_x + 2, setpc_y + 7);
SpawnQuestItem(IDI_BLDSTONE, 2 * setpc_x + 19, 2 * setpc_y + 26, 0, true);
}
if (object[i]._oVar6 == 2) {
if (!deltaload)
PlaySfxLoc(LS_PUDDLE, object[i].position.x, object[i].position.y);
ObjChangeMap(setpc_x + 6, setpc_y + 3, setpc_x + setpc_w, setpc_y + 7);
SpawnQuestItem(IDI_BLDSTONE, 2 * setpc_x + 31, 2 * setpc_y + 26, 0, true);
}
if (object[i]._oVar6 == 3) {
if (!deltaload)
PlaySfxLoc(LS_BLODSTAR, object[i].position.x, object[i].position.y);
ObjChangeMap(object[i]._oVar1, object[i]._oVar2, object[i]._oVar3, object[i]._oVar4);
LoadMapObjs("Levels\\L2Data\\Blood2.DUN", 2 * setpc_x, 2 * setpc_y);
SpawnUnique(UITEM_ARMOFVAL, 2 * setpc_x + 25, 2 * setpc_y + 19);
object[i]._oSelFlag = 0;
}
int iv;
if (object[i]._oVar6 == 3 || !plr[pnum].HasItem(IDI_BLDSTONE, &iv)) {
return;
}
plr[pnum].RemoveInvItem(iv);
object[i]._oAnimFrame++;
object[i]._oVar6++;
if (object[i]._oVar6 == 1) {
if (!deltaload)
PlaySfxLoc(LS_PUDDLE, object[i].position.x, object[i].position.y);
ObjChangeMap(setpc_x, setpc_y + 3, setpc_x + 2, setpc_y + 7);
SpawnQuestItem(IDI_BLDSTONE, 2 * setpc_x + 19, 2 * setpc_y + 26, 0, true);
}
if (object[i]._oVar6 == 2) {
if (!deltaload)
PlaySfxLoc(LS_PUDDLE, object[i].position.x, object[i].position.y);
ObjChangeMap(setpc_x + 6, setpc_y + 3, setpc_x + setpc_w, setpc_y + 7);
SpawnQuestItem(IDI_BLDSTONE, 2 * setpc_x + 31, 2 * setpc_y + 26, 0, true);
}
if (object[i]._oVar6 == 3) {
if (!deltaload)
PlaySfxLoc(LS_BLODSTAR, object[i].position.x, object[i].position.y);
ObjChangeMap(object[i]._oVar1, object[i]._oVar2, object[i]._oVar3, object[i]._oVar4);
LoadMapObjs("Levels\\L2Data\\Blood2.DUN", 2 * setpc_x, 2 * setpc_y);
SpawnUnique(UITEM_ARMOFVAL, 2 * setpc_x + 25, 2 * setpc_y + 19);
object[i]._oSelFlag = 0;
}
}

69
Source/player.cpp

@ -201,6 +201,69 @@ const char *const ClassPathTbl[] = {
"Warrior",
};
void PlayerStruct::CalcScrolls()
{
_pScrlSpells = 0;
for (int i = 0; i < _pNumInv; i++) {
if (!InvList[i].isEmpty() && (InvList[i]._iMiscId == IMISC_SCROLL || InvList[i]._iMiscId == IMISC_SCROLLT)) {
if (InvList[i]._iStatFlag)
_pScrlSpells |= GetSpellBitmask(InvList[i]._iSpell);
}
}
for (int j = 0; j < MAXBELTITEMS; j++) {
if (!SpdList[j].isEmpty() && (SpdList[j]._iMiscId == IMISC_SCROLL || SpdList[j]._iMiscId == IMISC_SCROLLT)) {
if (SpdList[j]._iStatFlag)
_pScrlSpells |= GetSpellBitmask(SpdList[j]._iSpell);
}
}
EnsureValidReadiedSpell(*this);
}
bool PlayerStruct::HasItem(int item, int *idx) const
{
for (int i = 0; i < _pNumInv; i++) {
if (InvList[i].IDidx == item) {
*idx = i;
true;
}
}
return false;
}
void PlayerStruct::RemoveInvItem(int iv, bool calcScrolls)
{
iv++;
//Iterate through invGrid and remove every reference to item
for (int i = 0; i < NUM_INV_GRID_ELEM; i++) {
if (InvGrid[i] == iv || InvGrid[i] == -iv) {
InvGrid[i] = 0;
}
}
iv--;
_pNumInv--;
//If the item at the end of inventory array isn't the one we removed, we need to swap its position in the array with the removed item
if (_pNumInv > 0 && _pNumInv != iv) {
InvList[iv] = InvList[_pNumInv];
for (int j = 0; j < NUM_INV_GRID_ELEM; j++) {
if (InvGrid[j] == _pNumInv + 1) {
InvGrid[j] = iv + 1;
}
if (InvGrid[j] == -(_pNumInv + 1)) {
InvGrid[j] = -(iv + 1);
}
}
}
if (calcScrolls)
CalcScrolls();
}
int PlayerStruct::GetBaseAttributeValue(CharacterAttribute attribute) const
{
switch (attribute) {
@ -1947,7 +2010,7 @@ void DropHalfPlayersGold(int pnum)
hGold = 0;
} else {
hGold -= plr[pnum].InvList[i]._ivalue;
RemoveInvItem(pnum, i);
plr[pnum].RemoveInvItem(i);
SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &plr[pnum].HoldItem);
SetPlrHandGoldCurs(&plr[pnum].HoldItem);
@ -1972,7 +2035,7 @@ void DropHalfPlayersGold(int pnum)
hGold = 0;
} else {
hGold -= plr[pnum].InvList[i]._ivalue;
RemoveInvItem(pnum, i);
plr[pnum].RemoveInvItem(i);
SetPlrHandItem(&plr[pnum].HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &plr[pnum].HoldItem);
SetPlrHandGoldCurs(&plr[pnum].HoldItem);
@ -3379,7 +3442,7 @@ void CheckNewPath(int pnum)
break;
case ACTION_TALK:
if (pnum == myplr) {
TalkToTowner(pnum, plr[pnum].destParam1);
TalkToTowner(plr[pnum], plr[pnum].destParam1);
}
break;
default:

12
Source/player.h

@ -309,6 +309,18 @@ struct PlayerStruct {
byte *_pDData;
byte *_pBData;
void CalcScrolls();
bool HasItem(int item, int *idx = nullptr) const;
/**
* @brief Remove an item from player inventory
* @param pnum Player index
* @param iv invList index of item to be removed
* @param calcScrolls If true, CalcScrolls() gets called after removing item
*/
void RemoveInvItem(int iv, bool calcScrolls = true);
/**
* @brief Gets the most valuable item out of all the player's items that match the given predicate.
* @param itemPredicate The predicate used to match the items.

6
Source/stores.cpp

@ -1425,7 +1425,7 @@ void StoreSellItem()
idx = stextvhold + ((stextlhold - stextup) / 4);
if (storehidx[idx] >= 0)
RemoveInvItem(myplr, storehidx[idx]);
plr[myplr].RemoveInvItem(storehidx[idx]);
else
RemoveSpdBarItem(myplr, -(storehidx[idx] + 1));
cost = storehold[idx]._iIvalue;
@ -2637,7 +2637,7 @@ void TakePlrsMoney(int cost)
cost = 0;
} else {
cost -= plr[myplr].InvList[i]._ivalue;
RemoveInvItem(myplr, i);
plr[myplr].RemoveInvItem(i);
i = -1;
}
}
@ -2651,7 +2651,7 @@ void TakePlrsMoney(int cost)
cost = 0;
} else {
cost -= plr[myplr].InvList[i]._ivalue;
RemoveInvItem(myplr, i);
plr[myplr].RemoveInvItem(i);
i = -1;
}
}

213
Source/towners.cpp

@ -144,7 +144,7 @@ namespace {
/** Specifies the active sound effect ID for interacting with cows. */
_sfx_id CowPlaying = SFX_NONE;
void CowSFX(int pnum)
void CowSFX(PlayerStruct &player)
{
if (CowPlaying != -1 && effect_is_playing(CowPlaying))
return;
@ -160,9 +160,9 @@ void CowSFX(int pnum)
}
} else {
if (sgdwCowClicks >= 8) {
PlaySfxLoc(TSFX_COW1, plr[pnum].position.tile.x, plr[pnum].position.tile.y + 5);
PlaySfxLoc(TSFX_COW1, player.position.tile.x, player.position.tile.y + 5);
sgdwCowClicks = 4;
CowPlaying = snSFX[sgnCowMsg][static_cast<std::size_t>(plr[pnum]._pClass)]; /* snSFX is local */
CowPlaying = snSFX[sgnCowMsg][static_cast<std::size_t>(player._pClass)]; /* snSFX is local */
sgnCowMsg++;
if (sgnCowMsg >= 3)
sgnCowMsg = 0;
@ -171,7 +171,7 @@ void CowSFX(int pnum)
}
}
PlaySfxLoc(CowPlaying, plr[pnum].position.tile.x, plr[pnum].position.tile.y);
PlaySfxLoc(CowPlaying, player.position.tile.x, player.position.tile.y);
}
int GetActiveTowner(int t)
@ -497,16 +497,15 @@ void FreeTownerGFX()
void TownCtrlMsg(int i)
{
int p;
int dx, dy;
if (i == -1)
return;
if (towners[i]._tbtcnt) {
p = towners[i]._tTalkingToPlayer;
dx = abs(towners[i].position.x - plr[p].position.tile.x);
dy = abs(towners[i].position.y - plr[p].position.tile.y);
PlayerStruct *player = towners[i]._tTalkingToPlayer;
dx = abs(towners[i].position.x - player->position.tile.x);
dy = abs(towners[i].position.y - player->position.tile.y);
if (dx >= 2 || dy >= 2) {
towners[i]._tbtcnt = false;
qtextflag = false;
@ -700,16 +699,6 @@ void ProcessTowners()
}
}
ItemStruct *PlrHasItem(int pnum, int item, int *i)
{
for (*i = 0; *i < plr[pnum]._pNumInv; (*i)++) {
if (plr[pnum].InvList[*i].IDidx == item)
return &plr[pnum].InvList[*i];
}
return nullptr;
}
void TownerTalk(int first)
{
sgdwCowClicks = 0;
@ -718,15 +707,15 @@ void TownerTalk(int first)
InitQTextMsg(first);
}
static void TalkToBarOwner(int p, TownerStruct &barOwner)
static void TalkToBarOwner(PlayerStruct &player, TownerStruct &barOwner)
{
if (!plr[p]._pLvlVisited[0] && !barOwner._tMsgSaid) {
if (!player._pLvlVisited[0] && !barOwner._tMsgSaid) {
barOwner._tbtcnt = true;
barOwner._tTalkingToPlayer = p;
barOwner._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_INTRO);
barOwner._tMsgSaid = true;
}
if ((plr[p]._pLvlVisited[2] || plr[p]._pLvlVisited[4]) && quests[Q_SKELKING]._qactive != QUEST_NOTAVAIL) {
if ((player._pLvlVisited[2] || player._pLvlVisited[4]) && quests[Q_SKELKING]._qactive != QUEST_NOTAVAIL) {
if (quests[Q_SKELKING]._qactive != QUEST_NOTAVAIL) {
if (quests[Q_SKELKING]._qvar2 == 0 && !barOwner._tMsgSaid) {
quests[Q_SKELKING]._qvar2 = 1;
@ -736,7 +725,7 @@ static void TalkToBarOwner(int p, TownerStruct &barOwner)
quests[Q_SKELKING]._qvar1 = 1;
}
barOwner._tbtcnt = true;
barOwner._tTalkingToPlayer = p;
barOwner._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_KING2);
barOwner._tMsgSaid = true;
NetSendCmdQuest(true, Q_SKELKING);
@ -746,14 +735,14 @@ static void TalkToBarOwner(int p, TownerStruct &barOwner)
quests[Q_SKELKING]._qvar2 = 2;
quests[Q_SKELKING]._qvar1 = 2;
barOwner._tbtcnt = true;
barOwner._tTalkingToPlayer = p;
barOwner._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_KING4);
barOwner._tMsgSaid = true;
NetSendCmdQuest(true, Q_SKELKING);
}
}
if (!gbIsMultiplayer) {
if (plr[p]._pLvlVisited[3] && quests[Q_LTBANNER]._qactive != QUEST_NOTAVAIL) {
if (player._pLvlVisited[3] && quests[Q_LTBANNER]._qactive != QUEST_NOTAVAIL) {
if ((quests[Q_LTBANNER]._qactive == QUEST_INIT || quests[Q_LTBANNER]._qactive == QUEST_ACTIVE) && quests[Q_LTBANNER]._qvar2 == 0 && !barOwner._tMsgSaid) {
quests[Q_LTBANNER]._qvar2 = 1;
if (quests[Q_LTBANNER]._qactive == QUEST_INIT) {
@ -762,18 +751,18 @@ static void TalkToBarOwner(int p, TownerStruct &barOwner)
}
quests[Q_LTBANNER]._qlog = true;
barOwner._tbtcnt = true;
barOwner._tTalkingToPlayer = p;
barOwner._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_BANNER2);
barOwner._tMsgSaid = true;
}
int i;
if (quests[Q_LTBANNER]._qvar2 == 1 && PlrHasItem(p, IDI_BANNER, &i) != nullptr && !barOwner._tMsgSaid) {
if (quests[Q_LTBANNER]._qvar2 == 1 && player.HasItem(IDI_BANNER, &i) && !barOwner._tMsgSaid) {
quests[Q_LTBANNER]._qactive = QUEST_DONE;
quests[Q_LTBANNER]._qvar1 = 3;
RemoveInvItem(p, i);
player.RemoveInvItem(i);
SpawnUnique(UITEM_HARCREST, barOwner.position.x, barOwner.position.y + 1);
barOwner._tbtcnt = true;
barOwner._tTalkingToPlayer = p;
barOwner._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_BANNER3);
barOwner._tMsgSaid = true;
}
@ -787,18 +776,18 @@ static void TalkToBarOwner(int p, TownerStruct &barOwner)
}
}
static void TalkToDeadguy(int p, TownerStruct &deadguy)
static void TalkToDeadguy(PlayerStruct &player, TownerStruct &deadguy)
{
if (quests[Q_BUTCHER]._qactive == QUEST_ACTIVE && quests[Q_BUTCHER]._qvar1 == 1) {
deadguy._tbtcnt = true;
deadguy._tTalkingToPlayer = p;
deadguy._tTalkingToPlayer = &player;
quests[Q_BUTCHER]._qvar1 = 1;
plr[p].PlaySpecificSpeach(8);
player.PlaySpecificSpeach(8);
deadguy._tMsgSaid = true;
} else if (quests[Q_BUTCHER]._qactive == QUEST_DONE && quests[Q_BUTCHER]._qvar1 == 1) {
quests[Q_BUTCHER]._qvar1 = 1;
deadguy._tbtcnt = true;
deadguy._tTalkingToPlayer = p;
deadguy._tTalkingToPlayer = &player;
deadguy._tMsgSaid = true;
} else if (quests[Q_BUTCHER]._qactive == QUEST_INIT || (quests[Q_BUTCHER]._qactive == QUEST_ACTIVE && quests[Q_BUTCHER]._qvar1 == 0)) {
quests[Q_BUTCHER]._qactive = QUEST_ACTIVE;
@ -806,17 +795,17 @@ static void TalkToDeadguy(int p, TownerStruct &deadguy)
quests[Q_BUTCHER]._qmsg = TEXT_BUTCH9;
quests[Q_BUTCHER]._qvar1 = 1;
deadguy._tbtcnt = true;
deadguy._tTalkingToPlayer = p;
deadguy._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_BUTCH9);
deadguy._tMsgSaid = true;
NetSendCmdQuest(true, Q_BUTCHER);
}
}
static void TalkToBlackSmith(int p, TownerStruct &blackSmith)
static void TalkToBlackSmith(PlayerStruct &player, TownerStruct &blackSmith)
{
if (!gbIsMultiplayer) {
if (plr[p]._pLvlVisited[4] && quests[Q_ROCK]._qactive != QUEST_NOTAVAIL) {
if (player._pLvlVisited[4] && quests[Q_ROCK]._qactive != QUEST_NOTAVAIL) {
if (quests[Q_ROCK]._qvar2 == 0) {
quests[Q_ROCK]._qvar2 = 1;
quests[Q_ROCK]._qlog = true;
@ -825,24 +814,24 @@ static void TalkToBlackSmith(int p, TownerStruct &blackSmith)
quests[Q_ROCK]._qvar1 = 1;
}
blackSmith._tbtcnt = true;
blackSmith._tTalkingToPlayer = p;
blackSmith._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_INFRA5);
blackSmith._tMsgSaid = true;
}
int i;
if (quests[Q_ROCK]._qvar2 == 1 && PlrHasItem(p, IDI_ROCK, &i) != nullptr && !blackSmith._tMsgSaid) {
if (quests[Q_ROCK]._qvar2 == 1 && player.HasItem(IDI_ROCK, &i) && !blackSmith._tMsgSaid) {
quests[Q_ROCK]._qactive = QUEST_DONE;
quests[Q_ROCK]._qvar2 = 2;
quests[Q_ROCK]._qvar1 = 2;
RemoveInvItem(p, i);
player.RemoveInvItem(i);
SpawnUnique(UITEM_INFRARING, blackSmith.position.x, blackSmith.position.y + 1);
blackSmith._tbtcnt = true;
blackSmith._tTalkingToPlayer = p;
blackSmith._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_INFRA7);
blackSmith._tMsgSaid = true;
}
}
if (plr[p]._pLvlVisited[9] && quests[Q_ANVIL]._qactive != QUEST_NOTAVAIL) {
if (player._pLvlVisited[9] && quests[Q_ANVIL]._qactive != QUEST_NOTAVAIL) {
if ((quests[Q_ANVIL]._qactive == QUEST_INIT || quests[Q_ANVIL]._qactive == QUEST_ACTIVE) && quests[Q_ANVIL]._qvar2 == 0 && !blackSmith._tMsgSaid) {
if (quests[Q_ROCK]._qvar2 == 2 || (quests[Q_ROCK]._qactive == QUEST_ACTIVE && quests[Q_ROCK]._qvar2 == 1)) {
quests[Q_ANVIL]._qvar2 = 1;
@ -852,21 +841,21 @@ static void TalkToBlackSmith(int p, TownerStruct &blackSmith)
quests[Q_ANVIL]._qvar1 = 1;
}
blackSmith._tbtcnt = true;
blackSmith._tTalkingToPlayer = p;
blackSmith._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_ANVIL5);
blackSmith._tMsgSaid = true;
}
}
int i;
if (quests[Q_ANVIL]._qvar2 == 1 && PlrHasItem(p, IDI_ANVIL, &i) != nullptr) {
if (quests[Q_ANVIL]._qvar2 == 1 && player.HasItem(IDI_ANVIL, &i)) {
if (!blackSmith._tMsgSaid) {
quests[Q_ANVIL]._qactive = QUEST_DONE;
quests[Q_ANVIL]._qvar2 = 2;
quests[Q_ANVIL]._qvar1 = 2;
RemoveInvItem(p, i);
player.RemoveInvItem(i);
SpawnUnique(UITEM_GRISWOLD, blackSmith.position.x, blackSmith.position.y + 1);
blackSmith._tbtcnt = true;
blackSmith._tTalkingToPlayer = p;
blackSmith._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_ANVIL7);
blackSmith._tMsgSaid = true;
}
@ -881,51 +870,49 @@ static void TalkToBlackSmith(int p, TownerStruct &blackSmith)
}
}
static void TalkToWitch(int p, TownerStruct &witch)
static void TalkToWitch(PlayerStruct &player, TownerStruct &witch)
{
int i;
if (quests[Q_MUSHROOM]._qactive == QUEST_INIT && PlrHasItem(p, IDI_FUNGALTM, &i) != nullptr) {
RemoveInvItem(p, i);
if (quests[Q_MUSHROOM]._qactive == QUEST_INIT && player.HasItem(IDI_FUNGALTM, &i)) {
player.RemoveInvItem(i);
quests[Q_MUSHROOM]._qactive = QUEST_ACTIVE;
quests[Q_MUSHROOM]._qlog = true;
quests[Q_MUSHROOM]._qvar1 = QS_TOMEGIVEN;
witch._tbtcnt = true;
witch._tTalkingToPlayer = p;
witch._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_MUSH8);
witch._tMsgSaid = true;
} else if (quests[Q_MUSHROOM]._qactive == QUEST_ACTIVE) {
if (quests[Q_MUSHROOM]._qvar1 >= QS_TOMEGIVEN && quests[Q_MUSHROOM]._qvar1 <= QS_MUSHPICKED) {
int i;
if (PlrHasItem(p, IDI_MUSHROOM, &i) != nullptr) {
RemoveInvItem(p, i);
if (player.HasItem(IDI_MUSHROOM, &i)) {
player.RemoveInvItem(i);
quests[Q_MUSHROOM]._qvar1 = QS_MUSHGIVEN;
Qtalklist[TOWN_HEALER][Q_MUSHROOM] = TEXT_MUSH3;
Qtalklist[TOWN_WITCH][Q_MUSHROOM] = TEXT_NONE;
witch._tbtcnt = true;
witch._tTalkingToPlayer = p;
witch._tTalkingToPlayer = &player;
quests[Q_MUSHROOM]._qmsg = TEXT_MUSH10;
InitQTextMsg(TEXT_MUSH10);
witch._tMsgSaid = true;
} else if (quests[Q_MUSHROOM]._qmsg != TEXT_MUSH9) {
witch._tbtcnt = true;
witch._tTalkingToPlayer = p;
witch._tTalkingToPlayer = &player;
quests[Q_MUSHROOM]._qmsg = TEXT_MUSH9;
InitQTextMsg(TEXT_MUSH9);
witch._tMsgSaid = true;
}
} else {
int i;
ItemStruct *Item = PlrHasItem(p, IDI_SPECELIX, &i);
if (Item != nullptr) {
if (player.HasItem(IDI_SPECELIX)) {
witch._tbtcnt = true;
witch._tTalkingToPlayer = p;
witch._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_MUSH12);
quests[Q_MUSHROOM]._qactive = QUEST_DONE;
witch._tMsgSaid = true;
AllItemsList[Item->IDidx].iUsable = true;
} else if (PlrHasItem(p, IDI_BRAIN, &i) != nullptr && quests[Q_MUSHROOM]._qvar2 != TEXT_MUSH11) {
AllItemsList[IDI_SPECELIX].iUsable = true;
} else if (player.HasItem(IDI_BRAIN) && quests[Q_MUSHROOM]._qvar2 != TEXT_MUSH11) {
witch._tbtcnt = true;
witch._tTalkingToPlayer = p;
witch._tTalkingToPlayer = &player;
quests[Q_MUSHROOM]._qvar2 = TEXT_MUSH11;
InitQTextMsg(TEXT_MUSH11);
witch._tMsgSaid = true;
@ -940,10 +927,9 @@ static void TalkToWitch(int p, TownerStruct &witch)
}
}
static void TalkToBarmaid(int p, TownerStruct &barmaid)
static void TalkToBarmaid(PlayerStruct &player, TownerStruct &barmaid)
{
int i;
if (!plr[p]._pLvlVisited[21] && PlrHasItem(p, IDI_MAPOFDOOM, &i) != nullptr) {
if (!player._pLvlVisited[21] && player.HasItem(IDI_MAPOFDOOM)) {
quests[Q_GRAVE]._qactive = QUEST_ACTIVE;
quests[Q_GRAVE]._qlog = true;
quests[Q_GRAVE]._qmsg = TEXT_GRAVE8;
@ -966,10 +952,10 @@ static void TalkToDrunk()
}
}
static void TalkToHealer(int p, TownerStruct &healer)
static void TalkToHealer(PlayerStruct &player, TownerStruct &healer)
{
if (!gbIsMultiplayer) {
if (plr[p]._pLvlVisited[1] || (gbIsHellfire && plr[p]._pLvlVisited[5])) {
if (player._pLvlVisited[1] || (gbIsHellfire && player._pLvlVisited[5])) {
if (!healer._tMsgSaid) {
if (quests[Q_PWATER]._qactive == QUEST_INIT) {
quests[Q_PWATER]._qactive = QUEST_ACTIVE;
@ -977,13 +963,13 @@ static void TalkToHealer(int p, TownerStruct &healer)
quests[Q_PWATER]._qmsg = TEXT_POISON3;
quests[Q_PWATER]._qvar1 = 1;
healer._tbtcnt = true;
healer._tTalkingToPlayer = p;
healer._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_POISON3);
healer._tMsgSaid = true;
} else if (quests[Q_PWATER]._qactive == QUEST_DONE && quests[Q_PWATER]._qvar1 != 2) {
quests[Q_PWATER]._qvar1 = 2;
healer._tbtcnt = true;
healer._tTalkingToPlayer = p;
healer._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_POISON5);
SpawnUnique(UITEM_TRING, healer.position.x, healer.position.y + 1);
healer._tMsgSaid = true;
@ -991,8 +977,8 @@ static void TalkToHealer(int p, TownerStruct &healer)
}
}
int i;
if (quests[Q_MUSHROOM]._qactive == QUEST_ACTIVE && quests[Q_MUSHROOM]._qmsg == TEXT_MUSH10 && PlrHasItem(p, IDI_BRAIN, &i) != nullptr) {
RemoveInvItem(p, i);
if (quests[Q_MUSHROOM]._qactive == QUEST_ACTIVE && quests[Q_MUSHROOM]._qmsg == TEXT_MUSH10 && player.HasItem(IDI_BRAIN, &i)) {
player.RemoveInvItem(i);
SpawnQuestItem(IDI_SPECELIX, healer.position.x, healer.position.y + 1, 0, false);
InitQTextMsg(TEXT_MUSH4);
quests[Q_MUSHROOM]._qvar1 = QS_BRAINGIVEN;
@ -1015,15 +1001,15 @@ static void TalkToBoy()
}
}
static void TalkToStoryteller(int p, TownerStruct &storyteller)
static void TalkToStoryteller(PlayerStruct &player, TownerStruct &storyteller)
{
if (!gbIsMultiplayer) {
int i;
if (quests[Q_BETRAYER]._qactive == QUEST_INIT && PlrHasItem(p, IDI_LAZSTAFF, &i) != nullptr) {
RemoveInvItem(p, i);
if (quests[Q_BETRAYER]._qactive == QUEST_INIT && player.HasItem(IDI_LAZSTAFF, &i)) {
player.RemoveInvItem(i);
quests[Q_BETRAYER]._qvar1 = 2;
storyteller._tbtcnt = true;
storyteller._tTalkingToPlayer = p;
storyteller._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_VILE1);
storyteller._tMsgSaid = true;
quests[Q_BETRAYER]._qactive = QUEST_ACTIVE;
@ -1031,7 +1017,7 @@ static void TalkToStoryteller(int p, TownerStruct &storyteller)
} else if (quests[Q_BETRAYER]._qactive == QUEST_DONE && quests[Q_BETRAYER]._qvar1 == 7) {
quests[Q_BETRAYER]._qvar1 = 8;
storyteller._tbtcnt = true;
storyteller._tTalkingToPlayer = p;
storyteller._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_VILE3);
storyteller._tMsgSaid = true;
quests[Q_DIABLO]._qlog = true;
@ -1040,7 +1026,7 @@ static void TalkToStoryteller(int p, TownerStruct &storyteller)
if (gbIsMultiplayer) {
if (quests[Q_BETRAYER]._qactive == QUEST_ACTIVE && !quests[Q_BETRAYER]._qlog) {
storyteller._tbtcnt = true;
storyteller._tTalkingToPlayer = p;
storyteller._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_VILE1);
storyteller._tMsgSaid = true;
quests[Q_BETRAYER]._qlog = true;
@ -1048,7 +1034,7 @@ static void TalkToStoryteller(int p, TownerStruct &storyteller)
} else if (quests[Q_BETRAYER]._qactive == QUEST_DONE && quests[Q_BETRAYER]._qvar1 == 7) {
quests[Q_BETRAYER]._qvar1 = 8;
storyteller._tbtcnt = true;
storyteller._tTalkingToPlayer = p;
storyteller._tTalkingToPlayer = &player;
InitQTextMsg(TEXT_VILE3);
storyteller._tMsgSaid = true;
NetSendCmdQuest(true, Q_BETRAYER);
@ -1064,27 +1050,26 @@ static void TalkToStoryteller(int p, TownerStruct &storyteller)
}
}
static void TalkToFarmer(int p, TownerStruct &farmer)
static void TalkToFarmer(PlayerStruct &player, TownerStruct &farmer)
{
_speech_id qt = TEXT_FARMER1;
bool t2 = true;
int i;
switch (quests[Q_FARMER]._qactive) {
case QUEST_NOTAVAIL:
if (PlrHasItem(p, IDI_RUNEBOMB, &i) != nullptr) {
if (player.HasItem(IDI_RUNEBOMB)) {
qt = TEXT_FARMER2;
quests[Q_FARMER]._qactive = QUEST_ACTIVE;
quests[Q_FARMER]._qvar1 = 1;
quests[Q_FARMER]._qlog = true;
quests[Q_FARMER]._qmsg = TEXT_FARMER1;
break;
} else if (!plr[p]._pLvlVisited[9] && plr[p]._pLevel < 15) {
} else if (!player._pLvlVisited[9] && player._pLevel < 15) {
qt = TEXT_FARMER8;
if (plr[p]._pLvlVisited[2])
if (player._pLvlVisited[2])
qt = TEXT_FARMER5;
if (plr[p]._pLvlVisited[5])
if (player._pLvlVisited[5])
qt = TEXT_FARMER7;
if (plr[p]._pLvlVisited[7])
if (player._pLvlVisited[7])
qt = TEXT_FARMER9;
} else {
qt = TEXT_FARMER1;
@ -1097,27 +1082,27 @@ static void TalkToFarmer(int p, TownerStruct &farmer)
break;
}
case QUEST_ACTIVE:
if (PlrHasItem(p, IDI_RUNEBOMB, &i) != nullptr)
if (player.HasItem(IDI_RUNEBOMB))
qt = TEXT_FARMER2;
else
qt = TEXT_FARMER3;
break;
case QUEST_INIT:
if (PlrHasItem(p, IDI_RUNEBOMB, &i) != nullptr) {
if (player.HasItem(IDI_RUNEBOMB)) {
qt = TEXT_FARMER2;
quests[Q_FARMER]._qactive = QUEST_ACTIVE;
quests[Q_FARMER]._qvar1 = 1;
quests[Q_FARMER]._qmsg = TEXT_FARMER1;
quests[Q_FARMER]._qlog = true;
} else if (!plr[p]._pLvlVisited[9] && plr[p]._pLevel < 15) {
} else if (!player._pLvlVisited[9] && player._pLevel < 15) {
qt = TEXT_FARMER8;
if (plr[p]._pLvlVisited[2]) {
if (player._pLvlVisited[2]) {
qt = TEXT_FARMER5;
}
if (plr[p]._pLvlVisited[5]) {
if (player._pLvlVisited[5]) {
qt = TEXT_FARMER7;
}
if (plr[p]._pLvlVisited[7]) {
if (player._pLvlVisited[7]) {
qt = TEXT_FARMER9;
}
} else {
@ -1157,20 +1142,20 @@ static void TalkToFarmer(int p, TownerStruct &farmer)
}
}
static void TalkToCowFarmer(int p, TownerStruct &cowFarmer)
static void TalkToCowFarmer(PlayerStruct &player, TownerStruct &cowFarmer)
{
_speech_id qt = TEXT_JERSEY1;
bool t2 = true;
int i;
if (PlrHasItem(p, IDI_GREYSUIT, &i) != nullptr) {
if (player.HasItem(IDI_GREYSUIT, &i)) {
qt = TEXT_JERSEY7;
RemoveInvItem(p, i);
} else if (PlrHasItem(p, IDI_BROWNSUIT, &i) != nullptr) {
player.RemoveInvItem(i);
} else if (player.HasItem(IDI_BROWNSUIT, &i)) {
SpawnUnique(UITEM_BOVINE, cowFarmer.position.x + 1, cowFarmer.position.y);
RemoveInvItem(p, i);
player.RemoveInvItem(i);
qt = TEXT_JERSEY8;
quests[Q_JERSEY]._qactive = QUEST_DONE;
} else if (PlrHasItem(p, IDI_RUNEBOMB, &i) != nullptr) {
} else if (player.HasItem(IDI_RUNEBOMB)) {
qt = TEXT_JERSEY5;
quests[Q_JERSEY]._qactive = QUEST_ACTIVE;
quests[Q_JERSEY]._qvar1 = 1;
@ -1198,7 +1183,7 @@ static void TalkToCowFarmer(int p, TownerStruct &cowFarmer)
quests[Q_JERSEY]._qactive = QUEST_HIVE_ACTIVE;
break;
case QUEST_HIVE_ACTIVE:
if (!plr[p]._pLvlVisited[9] && plr[p]._pLevel < 15) {
if (!player._pLvlVisited[9] && player._pLevel < 15) {
switch (GenerateRnd(4)) {
case 0:
qt = TEXT_JERSEY9;
@ -1241,12 +1226,11 @@ static void TalkToCowFarmer(int p, TownerStruct &cowFarmer)
}
}
static void TalkToGirl(int p, TownerStruct &girl)
static void TalkToGirl(PlayerStruct &player, TownerStruct &girl)
{
_speech_id qt = TEXT_GIRL1;
bool t2 = false;
int i;
if (PlrHasItem(p, IDI_THEODORE, &i) == nullptr || quests[Q_GIRL]._qactive == QUEST_DONE) {
if (!player.HasItem(IDI_THEODORE) || quests[Q_GIRL]._qactive == QUEST_DONE) {
switch (quests[Q_GIRL]._qactive) {
case 0:
qt = TEXT_GIRL2;
@ -1278,7 +1262,7 @@ static void TalkToGirl(int p, TownerStruct &girl)
}
} else {
qt = TEXT_GIRL4;
RemoveInvItem(p, i);
player.RemoveInvItem(i);
CreateAmulet(girl.position, 13, false, true);
quests[Q_GIRL]._qlog = false;
quests[Q_GIRL]._qactive = QUEST_DONE;
@ -1296,11 +1280,12 @@ static void TalkToGirl(int p, TownerStruct &girl)
}
}
void TalkToTowner(int p, int t)
void TalkToTowner(PlayerStruct &player, int t)
{
auto &towner = towners[t];
int dx = abs(plr[p].position.tile.x - towner.position.x);
int dy = abs(plr[p].position.tile.y - towner.position.y);
int dx = abs(player.position.tile.x - towner.position.x);
int dy = abs(player.position.tile.y - towner.position.y);
#ifdef _DEBUG
if (!debug_mode_key_d)
#endif
@ -1319,43 +1304,43 @@ void TalkToTowner(int p, int t)
switch (towner._ttype) {
case TOWN_TAVERN:
TalkToBarOwner(p, towner);
TalkToBarOwner(player, towner);
break;
case TOWN_DEADGUY:
TalkToDeadguy(p, towner);
TalkToDeadguy(player, towner);
break;
case TOWN_SMITH:
TalkToBlackSmith(p, towner);
TalkToBlackSmith(player, towner);
break;
case TOWN_WITCH:
TalkToWitch(p, towner);
TalkToWitch(player, towner);
break;
case TOWN_BMAID:
TalkToBarmaid(p, towner);
TalkToBarmaid(player, towner);
break;
case TOWN_DRUNK:
TalkToDrunk();
break;
case TOWN_HEALER:
TalkToHealer(p, towner);
TalkToHealer(player, towner);
break;
case TOWN_PEGBOY:
TalkToBoy();
break;
case TOWN_STORY:
TalkToStoryteller(p, towner);
TalkToStoryteller(player, towner);
break;
case TOWN_COW:
CowSFX(p);
CowSFX(player);
break;
case TOWN_FARMER:
TalkToFarmer(p, towner);
TalkToFarmer(player, towner);
break;
case TOWN_COWFARM:
TalkToCowFarmer(p, towner);
TalkToCowFarmer(player, towner);
break;
case TOWN_GIRL:
TalkToGirl(p, towner);
TalkToGirl(player, towner);
break;
}
}

5
Source/towners.h

@ -59,7 +59,7 @@ struct TownerStruct {
bool _tSelFlag;
bool _tMsgSaid;
int8_t _tAnimOrder;
int8_t _tTalkingToPlayer;
PlayerStruct *_tTalkingToPlayer;
bool _tbtcnt;
_talker_id _ttype;
};
@ -69,8 +69,7 @@ extern TownerStruct towners[NUM_TOWNERS];
void InitTowners();
void FreeTownerGFX();
void ProcessTowners();
ItemStruct *PlrHasItem(int pnum, int item, int *i);
void TalkToTowner(int p, int t);
void TalkToTowner(PlayerStruct &player, int t);
extern _speech_id Qtalklist[NUM_TOWNER_TYPES][MAXQUESTS];

4
test/inv_test.cpp

@ -149,7 +149,7 @@ TEST(Inv, RemoveInvItem)
plr[myplr].InvGrid[1] = -1;
plr[myplr].InvList[0]._itype = ITYPE_MISC;
RemoveInvItem(myplr, 0);
plr[myplr].RemoveInvItem(0);
EXPECT_EQ(plr[myplr].InvGrid[0], 0);
EXPECT_EQ(plr[myplr].InvGrid[1], 0);
EXPECT_EQ(plr[myplr]._pNumInv, 0);
@ -169,7 +169,7 @@ TEST(Inv, RemoveInvItem_other_item)
plr[myplr].InvGrid[2] = 2;
plr[myplr].InvList[1]._itype = ITYPE_RING;
RemoveInvItem(myplr, 0);
plr[myplr].RemoveInvItem(0);
EXPECT_EQ(plr[myplr].InvGrid[0], 0);
EXPECT_EQ(plr[myplr].InvGrid[1], 0);
EXPECT_EQ(plr[myplr].InvGrid[2], 1);

Loading…
Cancel
Save