1 /**
2  ** Mappatch.h - Patches to the game map.
3  **
4  ** Written: 10-18-2001
5  **/
6 
7 /*
8 Copyright (C) 2001 The Exult Team
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 */
24 
25 #ifndef INCL_MAPPATCH
26 #define INCL_MAPPATCH   1
27 
28 #include <map>
29 #include <list>
30 #include <memory>
31 #include "tiles.h"
32 
33 class Game_object;
34 
35 /*
36  *  Specify an object by location, shape, etc.
37  */
38 class Object_spec {
39 public:
40 	Tile_coord loc;         // Where it is.
41 	int shapenum;           // Shape #, or -359 for 'dont care'.
42 	int framenum;           // Frame #, or -359.
43 	int quality;            // Quality, or -359.
44 	Object_spec(Tile_coord const &t, int shnum = c_any_shapenum,
45 	            int frnum = c_any_framenum, int qual = c_any_qual)
loc(t)46 		: loc(t), shapenum(shnum), framenum(frnum), quality(qual)
47 	{  }
48 };
49 
50 /*
51  *  Base class for map patches:
52  */
53 class Map_patch {
54 	Object_spec spec;       // Specifies object to modify.
55 public:
56 	friend class Map_patch_collection;
Map_patch(Object_spec s)57 	Map_patch(Object_spec s) : spec(s)
58 	{  }
59 	virtual ~Map_patch() = default;
60 	Game_object *find();        // Find matching object.
61 	virtual bool apply() = 0;   // Perform action.
62 };
63 
64 // Sigh, this is needed to prevent compiler error with MSVC
65 using Map_patch_list = std::list<std::unique_ptr<Map_patch>>;
66 using Map_patch_map = std::map<int, Map_patch_list>;
67 
68 /*
69  *  Remove an object.
70  */
71 class Map_patch_remove : public Map_patch {
72 	bool all;           // Delete all matching.
73 public:
Map_patch(s)74 	Map_patch_remove(Object_spec s, bool a = false) : Map_patch(s), all(a)
75 	{  }
76 	bool apply() override;       // Perform action.
77 };
78 
79 /*
80  *  Move/modify an object.
81  */
82 class Map_patch_modify : public Map_patch {
83 	Object_spec mod;        // Modification.
84 public:
Map_patch_modify(Object_spec s,Object_spec m)85 	Map_patch_modify(Object_spec s, Object_spec m) : Map_patch(s), mod(m)
86 	{  }
87 	bool apply() override;       // Perform action.
88 };
89 
90 /*
91  *  Here's a collection of patches, organized by superchunk.
92  */
93 class Map_patch_collection {
94 	Map_patch_map patches;
95 public:
96 	void add(std::unique_ptr<Map_patch> p);     // Add a patch.
97 	void apply(int schunk);     // Apply for given superchunk.
98 };
99 
100 #endif
101