Browse Source

Simplify MonsterOperateDoor (#5100)

pull/5106/head
Andrew James 4 years ago committed by GitHub
parent
commit
24c57bf6c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 80
      Source/objects.cpp
  2. 2
      Source/objects.h

80
Source/objects.cpp

@ -4685,51 +4685,43 @@ void RedoPlayerVision()
} }
} }
void MonstCheckDoors(Monster &monster) void MonstCheckDoors(const Monster &monster)
{ {
int mx = monster.position.tile.x; for (Direction dir : { Direction::NorthEast, Direction::SouthWest, Direction::North, Direction::East, Direction::South, Direction::West, Direction::NorthWest, Direction::SouthEast }) {
int my = monster.position.tile.y; Object *object = ObjectAtPosition(monster.position.tile + dir);
if (dObject[mx - 1][my - 1] != 0 if (object == nullptr)
|| dObject[mx][my - 1] != 0 continue;
|| dObject[mx + 1][my - 1] != 0
|| dObject[mx - 1][my] != 0 Object &door = *object;
|| dObject[mx + 1][my] != 0 // Doors use _oVar4 to track open/closed state, non-zero values indicate an open door
|| dObject[mx - 1][my + 1] != 0 // we don't use Object::isDoor since the later conditions will check the object is actually a door anyway.
|| dObject[mx][my + 1] != 0 if (door._oVar4 != 0)
|| dObject[mx + 1][my + 1] != 0) { continue;
for (int i = 0; i < ActiveObjectCount; i++) {
Object &object = Objects[ActiveObjects[i]]; // Strictly speaking these checks shouldn't be required, they're guarding against monsters
if ((object._otype == OBJ_L1LDOOR || object._otype == OBJ_L1RDOOR) && object._oVar4 == 0) { // standing in a wall opening an adjacent door. Shouldn't be possible?
int dpx = abs(object.position.x - mx); if (IsNoneOf(dir, Direction::NorthEast, Direction::SouthWest)) {
int dpy = abs(object.position.y - my); if (door._otype == OBJ_L1LDOOR) {
if (dpx == 1 && dpy <= 1 && object._otype == OBJ_L1LDOOR) OperateL1LDoor(door, true);
OperateL1LDoor(object, true); } else if (door._otype == OBJ_L2LDOOR) {
if (dpx <= 1 && dpy == 1 && object._otype == OBJ_L1RDOOR) OperateL2LDoor(door, true);
OperateL1RDoor(object, true); } else if (door._otype == OBJ_L3RDOOR) {
} // L3 doors are backwards, see OperateL3Door
if ((object._otype == OBJ_L2LDOOR || object._otype == OBJ_L2RDOOR) && object._oVar4 == 0) { OperateL3RDoor(door, true);
int dpx = abs(object.position.x - mx); } else if (door._otype == OBJ_L5LDOOR) {
int dpy = abs(object.position.y - my); OperateL5LDoor(door, true);
if (dpx == 1 && dpy <= 1 && object._otype == OBJ_L2LDOOR)
OperateL2LDoor(object, true);
if (dpx <= 1 && dpy == 1 && object._otype == OBJ_L2RDOOR)
OperateL2RDoor(object, true);
}
if ((object._otype == OBJ_L3LDOOR || object._otype == OBJ_L3RDOOR) && object._oVar4 == 0) {
int dpx = abs(object.position.x - mx);
int dpy = abs(object.position.y - my);
if (dpx == 1 && dpy <= 1 && object._otype == OBJ_L3RDOOR)
OperateL3RDoor(object, true);
if (dpx <= 1 && dpy == 1 && object._otype == OBJ_L3LDOOR)
OperateL3LDoor(object, true);
} }
if ((object._otype == OBJ_L5LDOOR || object._otype == OBJ_L5RDOOR) && object._oVar4 == 0) { }
int dpx = abs(object.position.x - mx); if (IsNoneOf(dir, Direction::NorthWest, Direction::SouthEast)) {
int dpy = abs(object.position.y - my); if (door._otype == OBJ_L1RDOOR) {
if (dpx == 1 && dpy <= 1 && object._otype == OBJ_L5LDOOR) OperateL1RDoor(door, true);
OperateL5LDoor(object, true); } else if (door._otype == OBJ_L2RDOOR) {
if (dpx <= 1 && dpy == 1 && object._otype == OBJ_L5RDOOR) OperateL2RDoor(door, true);
OperateL5RDoor(object, true); } else if (door._otype == OBJ_L3LDOOR) {
// L3 doors are backwards, see OperateL3Door
OperateL3LDoor(door, true);
} else if (door._otype == OBJ_L5RDOOR) {
OperateL5RDoor(door, true);
} }
} }
} }

2
Source/objects.h

@ -301,7 +301,7 @@ void AddObject(_object_id objType, Point objPos);
void OperateTrap(Object &trap); void OperateTrap(Object &trap);
void ProcessObjects(); void ProcessObjects();
void RedoPlayerVision(); void RedoPlayerVision();
void MonstCheckDoors(Monster &monster); void MonstCheckDoors(const Monster &monster);
void ObjChangeMap(int x1, int y1, int x2, int y2); void ObjChangeMap(int x1, int y1, int x2, int y2);
void ObjChangeMapResync(int x1, int y1, int x2, int y2); void ObjChangeMapResync(int x1, int y1, int x2, int y2);
int ItemMiscIdIdx(item_misc_id imiscid); int ItemMiscIdIdx(item_misc_id imiscid);

Loading…
Cancel
Save