1 /* GemRB - Infinity Engine Emulator 2 * Copyright (C) 2003 The GemRB Project 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 * 18 * 19 */ 20 21 #ifndef DOOR_H 22 #define DOOR_H 23 24 #include "PathFinder.h" 25 #include "Polygon.h" 26 #include "Scriptable/Scriptable.h" 27 28 namespace GemRB { 29 30 class TileOverlay; 31 32 //door flags 33 #define DOOR_OPEN 1 34 #define DOOR_LOCKED 2 35 #define DOOR_RESET 4 //reset trap 36 #define DOOR_DETECTABLE 8 //trap detectable 37 #define DOOR_BROKEN 16 //door is broken (force opened) 38 #define DOOR_CANTCLOSE 32 // used in BG1 (at least TotSC). Prevents random closing of doors in CGameDoor::CompressTime. (The random closing is only done when more than a hour of ingame time passed.) 39 #define DOOR_LINKED 64 //info trigger linked to this door, iwd2: DETECTED in the ids 40 #define DOOR_SECRET 128 //door is secret 41 #define DOOR_FOUND 256 //secret door found 42 #define DOOR_TRANSPARENT 512 //obscures vision (LOCKEDINFOTEXT in iwd2) 43 #define DOOR_KEY 1024 //key removed when used (SEETHROUGH in iwd2) 44 #define DOOR_SLIDE 2048 //impeded blocks ignored (WARNINGINFOTEXT in iwd2) 45 #define DOOR_WARNINGTEXTDISPLAYED 0x1000 // iwd2 46 #define DOOR_HIDDEN 8192 // iwd2, ignore the door 47 #define DOOR_USEUPKEY 0x4000 // iwd2, treating as identical to DOOR_KEY 48 #define DOOR_LOCKEDINFOTEXT 0x8000 49 #define DOOR_WARNINGINFOTEXT 0x10000 50 51 class GEM_EXPORT DoorTrigger { 52 WallPolygonGroup openWalls; 53 WallPolygonGroup closedWalls; 54 55 std::shared_ptr<Gem_Polygon> openTrigger; 56 std::shared_ptr<Gem_Polygon> closedTrigger; 57 58 bool isOpen = false; 59 60 public: 61 DoorTrigger(std::shared_ptr<Gem_Polygon> openTrigger, WallPolygonGroup&& openWall, 62 std::shared_ptr<Gem_Polygon> closedTrigger, WallPolygonGroup&& closedWall); 63 64 void SetState(bool open); 65 66 std::shared_ptr<Gem_Polygon> StatePolygon() const; 67 std::shared_ptr<Gem_Polygon> StatePolygon(bool open) const; 68 }; 69 70 class GEM_EXPORT Door : public Highlightable { 71 public: 72 Door(TileOverlay* Overlay, DoorTrigger&& trigger); 73 ~Door(void) override; 74 public: 75 ieVariable LinkedInfo; 76 ieResRef ID; //WED ID 77 TileOverlay* overlay; 78 unsigned short* tiles; 79 int tilecount; 80 ieDword Flags; 81 int closedIndex; 82 //trigger areas 83 DoorTrigger doorTrigger; 84 Region& OpenBBox = BBox; // an alias for the base class BBox 85 Region ClosedBBox; 86 //impeded blocks 87 Point* open_ib; //impeded blocks stored in a Point array 88 int oibcount; 89 Point* closed_ib; 90 int cibcount; 91 92 Point toOpen[2]; 93 ieResRef OpenSound; 94 ieResRef CloseSound; 95 ieResRef LockSound; 96 ieResRef UnLockSound; 97 ieDword DiscoveryDiff; 98 ieDword LockDifficulty; //this is a dword? 99 ieStrRef OpenStrRef; 100 ieStrRef NameStrRef; 101 ieWord hp, ac; //unused???, but learned from IE DEV info 102 private: 103 void ImpedeBlocks(int count, Point *points, PathMapFlags value) const; 104 void UpdateDoor(); 105 bool BlockedOpen(int Open, int ForceOpen) const; 106 public: 107 void ToggleTiles(int State, int playsound = false); 108 void SetName(const char* Name); // sets door ID 109 void SetTiles(unsigned short* Tiles, int count); 110 bool CanDetectTrap() const override; 111 void SetDoorLocked(int Locked, int playsound); 112 void SetDoorOpen(int Open, int playsound, ieDword ID, bool addTrigger = true); 113 int IsOpen() const; 114 bool HitTest(const Point& p) const; 115 void TryPickLock(const Actor *actor); 116 void TryBashLock(Actor* actor) ; 117 bool TryUnlock(Actor *actor); 118 void TryDetectSecret(int skill, ieDword actorID); 119 bool Visible() const; 120 void dump() const; TrapResets()121 int TrapResets() const override { return Flags & DOOR_RESET; } CantAutoClose()122 bool CantAutoClose() const { return Flags & (DOOR_CANTCLOSE | DOOR_LOCKED); } 123 void SetNewOverlay(TileOverlay *Overlay); 124 125 std::shared_ptr<Gem_Polygon> OpenTriggerArea() const; 126 std::shared_ptr<Gem_Polygon> ClosedTriggerArea() const; 127 }; 128 129 } 130 131 #endif 132