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 WEDIMPORTER_H
22 #define WEDIMPORTER_H
23 
24 #include "Polygon.h"
25 #include "TileMapMgr.h"
26 
27 #include <vector>
28 
29 namespace GemRB {
30 
31 struct Overlay {
32 	ieWord  Width;
33 	ieWord  Height;
34 	ieResRef TilesetResRef;
35 	ieWord UniqueTileCount; // nNumUniqueTiles in the original (currently unused)
36 	ieWord MovementType; // nMovementType in the original (currently unused)
37 	ieDword TilemapOffset;
38 	ieDword TILOffset;
39 };
40 
41 class WEDImporter : public TileMapMgr {
42 private:
43 	std::vector<Overlay> overlays;
44 	DataStream* str = nullptr;
45 	ieDword OverlaysCount = 0;
46 	ieDword DoorsCount = 0;
47 	ieDword OverlaysOffset = 0;
48 	ieDword SecHeaderOffset = 0;
49 	ieDword DoorsOffset = 0;
50 	ieDword DoorTilesOffset = 0;
51 	ieDword WallPolygonsCount = 0;
52 	ieDword PolygonsOffset = 0;
53 	ieDword VerticesOffset = 0;
54 	ieDword WallGroupsOffset = 0;
55 	ieDword PLTOffset = 0;
56 	ieDword DoorPolygonsCount = 0;
57 	//these will change as doors are being read, so get them in time!
58 	ieWord OpenPolyCount = 0, ClosedPolyCount = 0;
59 	ieDword OpenPolyOffset = 0, ClosedPolyOffset = 0;
60 	bool ExtendedNight = false;
61 
62 	WallPolygonGroup polygonTable;
63 
64 private:
65 	void GetDoorPolygonCount(ieWord count, ieDword offset);
66 	int AddOverlay(TileMap *tm, const Overlay *overlays, bool rain) const;
67 	void ReadWallPolygons();
68 	WallPolygonGroup MakeGroupFromTableEntries(size_t idx, size_t cnt) const override;
69 
70 public:
71 	WEDImporter(void);
72 	~WEDImporter(void) override;
73 	bool Open(DataStream* stream) override;
74 	//if tilemap already exists, don't create it
75 	TileMap* GetTileMap(TileMap *tm) const override;
76 	ieWord* GetDoorIndices(char* ResRef, int* count, bool& BaseClosed) override;
77 
78 	std::vector<WallPolygonGroup> GetWallGroups() const override;
79 
80 	WallPolygonGroup OpenDoorPolygons() const override;
81 	WallPolygonGroup ClosedDoorPolygons() const override;
SetExtendedNight(bool night)82 	void SetExtendedNight(bool night) override { ExtendedNight = night; }
83 };
84 
85 }
86 
87 #endif
88