1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ULTIMA8_WORLD_CAMERAPROCESS_H
24 #define ULTIMA8_WORLD_CAMERAPROCESS_H
25 
26 #include "ultima/ultima8/kernel/process.h"
27 #include "ultima/ultima8/usecode/intrinsics.h"
28 #include "ultima/ultima8/misc/classtype.h"
29 
30 namespace Ultima {
31 namespace Ultima8 {
32 
33 /**
34 * The camera process. This works in 4 ways:
35 *
36 * It can be set to stay where it currently is
37 * It can be set to follow an item.
38 * It can be set to scroll to an item
39 * It can be set to stay at a location
40 */
41 class CameraProcess : public Process {
42 public:
43 	CameraProcess();
44 	CameraProcess(uint16 itemnum);                          // Follow item/Do nothing
45 	CameraProcess(int32 x, int32 y, int32 z);               // Goto location
46 	CameraProcess(int32 x, int32 y, int32 z, int32 time);   // Scroll to location
47 
48 	~CameraProcess() override;
49 
50 	ENABLE_RUNTIME_CLASSTYPE()
51 
52 	void run() override;
53 
54 	// You will notice that this isn't the same as how Item::GetLerped works
55 	void GetLerped(int32 &x, int32 &y, int32 &z, int32 factor, bool noupdate = false);
56 
57 	//! Find the roof above the camera.
58 	//! \param factor Interpolation factor for this frame
59 	//! \return 0 if no roof found, objid of roof if found
60 	uint16 findRoof(int32 factor);
61 
62 	/**
63 	 * Move the existing camera process to a new location.  If the current process is focused on
64 	 * an item, remove that focus.
65 	 *
66 	 * This is not the same as setting a new process, because execution order will not change,
67 	 * so other pending events will all happen before the fast area is updated
68 	 */
69 	void moveToLocation(int32 x, int32 y, int32 z);
70 
71 	INTRINSIC(I_setCenterOn);
72 	INTRINSIC(I_moveTo);
73 	INTRINSIC(I_scrollTo);
74 	INTRINSIC(I_startQuake);
75 	INTRINSIC(I_stopQuake);
76 	INTRINSIC(I_getCameraX);
77 	INTRINSIC(I_getCameraY);
78 	INTRINSIC(I_getCameraZ);
79 
80 	static void             GetCameraLocation(int32 &x, int32 &y, int32 &z);
GetCameraProcess()81 	static CameraProcess   *GetCameraProcess() {
82 		return _camera;
83 	}
84 
85 	/**
86 	 * Set the current camera process. Adds process and returns PID.
87 	 * The new process will go on the front of the process queue, so the fast area
88 	 * will be updated before any other pending actions occur.
89 	 */
90 	static uint16           SetCameraProcess(CameraProcess *);
91 	static void             ResetCameraProcess();
92 
SetEarthquake(int32 e)93 	static void             SetEarthquake(int32 e) {
94 		_earthquake = e;
95 		if (!e)  _eqX = _eqY = 0;
96 	}
97 
98 	/** Notify the Camera that the target item has moved */
99 	void itemMoved();
100 
101 	void terminate() override;   // Terminate NOW!
102 
103 	bool loadData(Common::ReadStream *rs, uint32 version);
104 	void saveData(Common::WriteStream *ws) override;
105 
getTrackedItem()106 	uint16 getTrackedItem() const {
107 		return _itemNum;
108 	}
109 
110 private:
111 	int32 _sx, _sy, _sz;
112 	int32 _ex, _ey, _ez;
113 	int32 _time;
114 	int32 _elapsed;
115 	uint16 _itemNum;
116 
117 	int32 _lastFrameNum;
118 
119 	static CameraProcess *_camera;
120 	static int32 _earthquake;
121 	static int32 _eqX, _eqY;
122 };
123 
124 } // End of namespace Ultima8
125 } // End of namespace Ultima
126 
127 #endif
128