Browse Source

Combine duplicated initialisation logic for quest book objects

pull/2354/head
ephphatha 5 years ago committed by Anders Jenbo
parent
commit
a842d07dab
  1. 17
      Source/objects.cpp
  2. 56
      Source/objects.h
  3. 27
      Source/setmaps.cpp

17
Source/objects.cpp

@ -518,10 +518,8 @@ void AddBookLever(Rectangle affectedArea, _speech_id msg)
AddObject(OBJ_BLOODBOOK, { xp, yp });
}
int ob = dObject[xp][yp] - 1;
Objects[ob].SetMapRange(affectedArea, leverid);
Objects[ob].bookMessage = msg;
Objects[ob].InitializeQuestBook(affectedArea, leverid, msg);
leverid++;
Objects[ob]._oVar6 = Objects[ob]._oAnimFrame + 1;
}
void InitRndBarrels()
@ -757,7 +755,7 @@ void LoadMapObjects(const char *path, Point start, Rectangle mapRange, int lever
if (objectId != 0) {
Point mapPos = start + Displacement { i, j };
AddObject(ObjTypeConv[objectId], mapPos);
ObjectAtPosition(mapPos).SetMapRange(mapRange, leveridx);
ObjectAtPosition(mapPos).InitializeLoadedObject(mapRange, leveridx);
}
}
}
@ -1269,15 +1267,6 @@ void AddL1Door(int i, Point position, _object_id objectType)
Objects[i]._oVar4 = 0;
}
void AddSCambBook(int i)
{
Objects[i]._oVar1 = setpc_x;
Objects[i]._oVar2 = setpc_y;
Objects[i]._oVar3 = setpc_w + setpc_x + 1;
Objects[i]._oVar4 = setpc_h + setpc_y + 1;
Objects[i]._oVar6 = Objects[i]._oAnimFrame + 1;
}
void AddChest(int i, int t)
{
if (GenerateRnd(2) == 0)
@ -1732,7 +1721,7 @@ void AddObject(_object_id objType, Point objPos)
AddL3Door(oi, objPos, objType);
break;
case OBJ_BOOK2R:
AddSCambBook(oi);
Objects[oi].InitializeBook({ { setpc_x, setpc_y }, { setpc_w + 1, setpc_h + 1 } });
break;
case OBJ_CHEST1:
case OBJ_CHEST2:

56
Source/objects.h

@ -63,28 +63,64 @@ 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 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
* @param topLeftPosition corner of the map region closest to the origin.
* @param bottomRightPosition corner of the map region furthest from the origin.
*/
constexpr void SetMapRange(Point topLeftPosition, Point bottomRightPosition, int v)
constexpr void SetMapRange(Point topLeftPosition, Point bottomRightPosition)
{
_oVar1 = topLeftPosition.x;
_oVar2 = topLeftPosition.y;
_oVar3 = bottomRightPosition.x;
_oVar4 = bottomRightPosition.y;
_oVar8 = v;
}
/**
* @brief Convenience function for SetMapRange(Point, Point, int)
* @param mapRange A rectangle defining the top left corner and size of the affected region
* @param v Object subtype/discriminator
* @brief Convenience function for SetMapRange(Point, Point).
* @param mapRange A rectangle defining the top left corner and size of the affected region.
*/
constexpr void SetMapRange(Rectangle mapRange, int v)
constexpr void SetMapRange(Rectangle mapRange)
{
SetMapRange(mapRange.position, mapRange.position + Displacement { mapRange.size }, v);
SetMapRange(mapRange.position, mapRange.position + Displacement { mapRange.size });
}
/**
* @brief Sets up a generic quest book which will trigger a change in the map when activated.
*
* Books of this type use a generic message (see OperateSChambBook()) compared to the more specific quest books
* initialized by IntializeQuestBook().
*
* @param mapRange The region to be updated when this object is activated.
*/
constexpr void InitializeBook(Rectangle mapRange)
{
SetMapRange(mapRange);
_oVar6 = _oAnimFrame + 1; // Save the frame number for the open book frame
}
/**
* @brief Initializes this object as a quest book which will cause further changes and play a message when activated.
* @param mapRange The region to be updated when this object is activated.
* @param leverID An ID (distinct from the object index) to identify the new objects spawned after updating the map.
* @param message The quest text to play when this object is activated.
*/
constexpr void InitializeQuestBook(Rectangle mapRange, int leverID, _speech_id message)
{
InitializeBook(mapRange);
_oVar8 = leverID;
bookMessage = message;
}
/**
* @brief Marks an object which was spawned from a sublevel in response to a lever activation.
* @param mapRange The region which was updated to spawn this object.
* @param leverID The id (*not* an object ID/index) of the lever responsible for the map change.
*/
constexpr void InitializeLoadedObject(Rectangle mapRange, int leverID)
{
SetMapRange(mapRange);
_oVar8 = leverID;
}
};
extern ObjectStruct Objects[MAXOBJECTS];

27
Source/setmaps.cpp

@ -94,25 +94,30 @@ ObjectStruct &ObjectAtPosition(Point position)
void AddSKingObjs()
{
ObjectAtPosition({ 64, 34 }).SetMapRange({ 20, 7 }, { 23, 10 }, 1);
ObjectAtPosition({ 64, 59 }).SetMapRange({ 20, 14 }, { 21, 16 }, 2);
ObjectAtPosition({ 27, 37 }).SetMapRange({ 8, 1 }, { 15, 11 }, 3);
ObjectAtPosition({ 46, 35 }).SetMapRange({ 8, 1 }, { 15, 11 }, 3);
ObjectAtPosition({ 49, 53 }).SetMapRange({ 8, 1 }, { 15, 11 }, 3);
ObjectAtPosition({ 27, 53 }).SetMapRange({ 8, 1 }, { 15, 11 }, 3);
constexpr Rectangle region1 { { 20, 7 }, { 3, 3 } };
ObjectAtPosition({ 64, 34 }).InitializeLoadedObject(region1, 1);
constexpr Rectangle region2 { { 20, 14 }, { 1, 2 } };
ObjectAtPosition({ 64, 59 }).InitializeLoadedObject(region2, 2);
constexpr Rectangle region3 { { 8, 1 }, { 7, 10 } };
ObjectAtPosition({ 27, 37 }).InitializeLoadedObject(region3, 3);
ObjectAtPosition({ 46, 35 }).InitializeLoadedObject(region3, 3);
ObjectAtPosition({ 49, 53 }).InitializeLoadedObject(region3, 3);
ObjectAtPosition({ 27, 53 }).InitializeLoadedObject(region3, 3);
}
void AddSChamObjs()
{
ObjectAtPosition({ 37, 30 }).SetMapRange({ 17, 0 }, { 21, 5 }, 1);
ObjectAtPosition({ 37, 46 }).SetMapRange({ 13, 0 }, { 16, 5 }, 2);
ObjectAtPosition({ 37, 30 }).InitializeLoadedObject({ { 17, 0 }, { 4, 5 } }, 1);
ObjectAtPosition({ 37, 46 }).InitializeLoadedObject({ { 13, 0 }, { 3, 5 } }, 2);
}
void AddVileObjs()
{
ObjectAtPosition({ 26, 45 }).SetMapRange({ 1, 1 }, { 9, 10 }, 1);
ObjectAtPosition({ 45, 46 }).SetMapRange({ 11, 1 }, { 20, 10 }, 2);
ObjectAtPosition({ 35, 36 }).SetMapRange({ 7, 11 }, { 13, 18 }, 3);
ObjectAtPosition({ 26, 45 }).InitializeLoadedObject({ { 1, 1 }, { 8, 9 } }, 1);
ObjectAtPosition({ 45, 46 }).InitializeLoadedObject({ { 11, 1 }, { 9, 9 } }, 2);
ObjectAtPosition({ 35, 36 }).InitializeLoadedObject({ { 7, 11 }, { 6, 7 } }, 3);
}
void DRLG_SetMapTrans(const char *path)

Loading…
Cancel
Save