Browse Source

Update BookLever related functions to use Rectangle.

This is mainly to help isolate functionality in the hopes of adding a specialised object class for this type of object as suggested by @julealgon in https://github.com/diasurgical/devilutionX/pull/2344#discussion_r667415019

For example, AddSCambBook performs almost the same logic but uses var6 instead of var8 for the trigger condition/identifier.
pull/2354/head
ephphatha 5 years ago committed by Anders Jenbo
parent
commit
cc3572af81
  1. 4
      Source/loadsave.cpp
  2. 28
      Source/objects.cpp
  3. 22
      Source/objects.h

4
Source/loadsave.cpp

@ -741,7 +741,7 @@ static void LoadObject(LoadHelper *file, int i)
pObject->_oVar4 = file->NextLE<int32_t>();
pObject->_oVar5 = file->NextLE<int32_t>();
pObject->_oVar6 = file->NextLE<uint32_t>();
pObject->_oVar7 = static_cast<_speech_id>(file->NextLE<int32_t>());
pObject->bookMessage = static_cast<_speech_id>(file->NextLE<int32_t>());
pObject->_oVar8 = file->NextLE<int32_t>();
}
@ -1783,7 +1783,7 @@ static void SaveObject(SaveHelper *file, int i)
file->WriteLE<int32_t>(pObject->_oVar4);
file->WriteLE<int32_t>(pObject->_oVar5);
file->WriteLE<uint32_t>(pObject->_oVar6);
file->WriteLE<int32_t>(pObject->_oVar7);
file->WriteLE<int32_t>(pObject->bookMessage);
file->WriteLE<int32_t>(pObject->_oVar8);
}

28
Source/objects.cpp

@ -476,7 +476,16 @@ void AddCandles()
AddObject(OBJ_STORYCANDLE, { tx + 2, ty + 2 });
}
void AddBookLever(int x1, int y1, int x2, int y2, _speech_id msg)
/**
* @brief Attempts to spawn a book somewhere on the current floor which when activated will change a region of the map.
*
* This object acts like a lever and will cause a change to the map based on what quest is active. The exact effect is
* determined by OperateBookLever().
*
* @param affectedArea The map region to be updated when this object is activated by the player.
* @param msg The quest text to play when the player activates the book.
*/
void AddBookLever(Rectangle affectedArea, _speech_id msg)
{
int cnt = 0;
int xp;
@ -509,8 +518,8 @@ void AddBookLever(int x1, int y1, int x2, int y2, _speech_id msg)
AddObject(OBJ_BLOODBOOK, { xp, yp });
}
int ob = dObject[xp][yp] - 1;
Objects[ob].SetMapRange({ x1, y1 }, { x2, y2 }, leverid);
SetBookMsg(ob, msg);
Objects[ob].SetMapRange(affectedArea, leverid);
Objects[ob].bookMessage = msg;
leverid++;
Objects[ob]._oVar6 = Objects[ob]._oAnimFrame + 1;
}
@ -1062,7 +1071,7 @@ void InitObjects()
break;
}
Quests[Q_BLIND]._qmsg = spId;
AddBookLever(setpc_x, setpc_y, setpc_w + setpc_x + 1, setpc_h + setpc_y + 1, spId);
AddBookLever({ { setpc_x, setpc_y }, { setpc_w + 1, setpc_h + 1 } }, spId);
LoadMapObjs("Levels\\L2Data\\Blind2.DUN", { 2 * setpc_x, 2 * setpc_y });
}
if (QuestStatus(Q_BLOOD)) {
@ -1088,7 +1097,7 @@ void InitObjects()
break;
}
Quests[Q_BLOOD]._qmsg = spId;
AddBookLever(setpc_x, setpc_y + 3, setpc_x + 2, setpc_y + 7, spId);
AddBookLever({ { setpc_x, setpc_y + 3 }, { 2, 4 } }, spId);
AddObject(OBJ_PEDISTAL, { 2 * setpc_x + 25, 2 * setpc_y + 32 });
}
InitRndBarrels();
@ -1121,7 +1130,7 @@ void InitObjects()
break;
}
Quests[Q_WARLORD]._qmsg = spId;
AddBookLever(setpc_x, setpc_y, setpc_x + setpc_w, setpc_y + setpc_h, spId);
AddBookLever({ { setpc_x, setpc_y }, { setpc_w, setpc_h } }, spId);
LoadMapObjs("Levels\\L4Data\\Warlord.DUN", { 2 * setpc_x, 2 * setpc_y });
}
if (QuestStatus(Q_BETRAYER) && !gbIsMultiplayer)
@ -1247,11 +1256,6 @@ void SetupObject(int i, Point position, _object_id ot)
Objects[i]._oDoorFlag = false;
}
void SetBookMsg(int i, _speech_id msg)
{
Objects[i]._oVar7 = msg;
}
void AddL1Door(int i, Point position, _object_id objectType)
{
Objects[i]._oDoorFlag = true;
@ -2936,7 +2940,7 @@ void OperateBookLever(int pnum, int i)
}
}
Objects[i]._oAnimFrame = Objects[i]._oVar6;
InitQTextMsg(Objects[i]._oVar7);
InitQTextMsg(Objects[i].bookMessage);
if (pnum == MyPlayerId)
NetSendCmdParam1(false, CMD_OPERATEOBJ, i);
}

22
Source/objects.h

@ -48,7 +48,12 @@ struct ObjectStruct {
int _oVar4;
int _oVar5;
uint32_t _oVar6;
_speech_id _oVar7;
/**
* @brief ID of a quest message to play when this object is activated.
*
* Used by spell book objects which trigger quest progress for Halls of the Blind, Valor, or Warlord of Blood
*/
_speech_id bookMessage;
int _oVar8;
/**
@ -58,16 +63,16 @@ struct ObjectStruct {
* antechamber levers). The coordinates used for this region are based on a 40*40 grid overlaying the central
* 80*80 region of the dungeon.
*
* @param topLeft corner of the map region closest to the origin
* @param bottomRight corner of the map region furthest from the origin
* @param topLeftPosition corner of the map region closest to the origin
* @param bottomRightPosition corner of the map region furthest from the origin
* @param v ID/discriminator for the object type? Needs to be investigated further
*/
constexpr void SetMapRange(Point topLeft, Point bottomRight, int v)
constexpr void SetMapRange(Point topLeftPosition, Point bottomRightPosition, int v)
{
_oVar1 = topLeft.x;
_oVar2 = topLeft.y;
_oVar3 = bottomRight.x;
_oVar4 = bottomRight.y;
_oVar1 = topLeftPosition.x;
_oVar2 = topLeftPosition.y;
_oVar3 = bottomRightPosition.x;
_oVar4 = bottomRightPosition.y;
_oVar8 = v;
}
@ -95,7 +100,6 @@ void AddL1Objs(int x1, int y1, int x2, int y2);
void AddL2Objs(int x1, int y1, int x2, int y2);
void InitObjects();
void SetMapObjects(const uint16_t *dunData, int startx, int starty);
void SetBookMsg(int i, _speech_id msg);
void GetRndObjLoc(int randarea, int *xx, int *yy);
void AddMushPatch();
void AddSlainHero();

Loading…
Cancel
Save