Constificiation.
[gemrb.git] / gemrb / core / GameControl.h
blob6bc2b833c5d37a0dbd4f735e9b5ce2162eb513a4
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
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.
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.
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.
20 /**
21 * @file GameControl.h
22 * Declares GameControl widget which is responsible for displaying areas,
23 * interacting with PCs, NPCs and the rest of the game world.
24 * @author The GemRB Project
27 class GameControl;
28 class Window;
30 #ifndef GAMECONTROL_H
31 #define GAMECONTROL_H
33 #include "Control.h"
34 #include "Interface.h"
35 #include "Dialog.h"
36 #include "Map.h"
37 #include "exports.h"
39 //dialog flags
40 #define DF_IN_DIALOG 1
41 #define DF_TALKCOUNT 2
42 #define DF_UNBREAKABLE 4
43 #define DF_FREEZE_SCRIPTS 8
44 #define DF_INTERACT 16
45 #define DF_IN_CONTAINER 32
46 #define DF_OPENCONTINUEWINDOW 64
47 #define DF_OPENENDWINDOW 128
49 //screen flags
50 // !!! Keep these synchronized with GUIDefines.py !!!
51 #define SF_DISABLEMOUSE 1 //no mouse cursor
52 #define SF_CENTERONACTOR 2 //
53 #define SF_ALWAYSCENTER 4
54 #define SF_GUIENABLED 8 //
55 #define SF_LOCKSCROLL 16 //don't scroll
56 #define SF_CUTSCENE 32 //don't push new actions onto the action queue
57 #define SF_TRACKING 64 //draw blue arrows on the edge for creatures
59 // target modes and types
60 // !!! Keep these synchronized with GUIDefines.py !!!
61 #define TARGET_MODE_NONE 0
62 #define TARGET_MODE_TALK 1
63 #define TARGET_MODE_ATTACK 2
64 #define TARGET_MODE_CAST 3
65 #define TARGET_MODE_DEFEND 4
66 #define TARGET_MODE_PICK 5
69 #define TARGET_SELECT 16
70 #define TARGET_NO_DEAD 32
71 #define TARGET_POINT 64
72 #define TARGET_NO_HIDDEN 128
73 #define TARGET_TYPE_NONE 0x000
74 #define TARGET_NO_ALLY 0x100 //0x100
75 #define TARGET_NO_ENEMY 0x200 //0x200
76 #define TARGET_NO_NEUTRAL 0x400
77 #define TARGET_NO_SELF 0x800
78 #define TARGET_TYPE_ALL 0 //(TARGET_TYPE_ALLY | TARGET_TYPE_ENEMY | TARGET_TYPE_NEUTRAL)
81 /**
82 * @class GameControl
83 * Widget displaying areas, where most of the game 'happens'.
84 * It allows for interacting with PCs, NPCs and the rest of the world.
85 * It's also a very core part of GemRB, as some processes are driven from it.
86 * It's always assigned Control index 0.
89 class GEM_EXPORT GameControl : public Control {
90 public:
91 GameControl(void);
92 ~GameControl(void);
93 public:
94 /** Draws the Control on the Output Display */
95 void Draw(unsigned short x, unsigned short y);
96 /** Sets the Text of the current control */
97 int SetText(const char* string, int pos = 0);
98 /** Sets multiple quicksaves flag*/
99 static void MultipleQuickSaves(int arg);
100 void SetTracker(Actor *actor, ieDword dist);
101 private:
102 //Actor* lastActor;
103 //using global ID which is safer
104 ieWord lastActorID;
105 ieWord trackerID;
106 ieDword distance; //tracking distance
107 std::vector< Actor*> highlighted;
108 bool DrawSelectionRect;
109 bool MouseIsDown;
110 bool DoubleClick;
111 Region SelectionRect;
112 short StartX, StartY;
113 //int action;
114 public:
115 Door* overDoor;
116 Container* overContainer;
117 InfoPoint* overInfoPoint;
119 // currently selected targetting type, such as talk, attack, cast, ...
120 int target_mode;
121 // allow targetting allies, enemies and/or neutrals (bitmask)
122 int target_types;
124 private:
125 unsigned char lastCursor;
126 short moveX, moveY;
127 int numScrollCursor;
128 bool scrolling;
129 unsigned short lastMouseX, lastMouseY;
130 int DebugFlags;
131 Point pfs;
132 PathNode* drawPath;
133 unsigned long AIUpdateCounter;
134 int ScreenFlags;
135 int DialogueFlags;
136 char *DisplayText;
137 unsigned int DisplayTextTime;
138 public: //Events
139 /** Key Press Event */
140 void OnKeyPress(unsigned char Key, unsigned short Mod);
141 /** Key Release Event */
142 void OnKeyRelease(unsigned char Key, unsigned short Mod);
143 /** Mouse Over Event */
144 void OnMouseOver(unsigned short x, unsigned short y);
145 /** Global Mouse Move Event */
146 void OnGlobalMouseMove(unsigned short x, unsigned short y);
147 /** Mouse Button Down */
148 void OnMouseDown(unsigned short x, unsigned short y, unsigned short Button,
149 unsigned short Mod);
150 /** Mouse Button Up */
151 void OnMouseUp(unsigned short x, unsigned short y, unsigned short Button,
152 unsigned short Mod);
153 /** Special Key Press */
154 void OnSpecialKeyPress(unsigned char Key);
155 void DisplayTooltip();
156 void UpdateScrolling();
157 void SetScreenFlags(int value, int mode);
158 void SetDialogueFlags(int value, int mode);
159 int GetScreenFlags() { return ScreenFlags; }
160 int GetDialogueFlags() { return DialogueFlags; }
161 /** this function is called from the area when autosave is needed */
162 void AutoSave();
163 void SetDisplayText(char *text, unsigned int time);
164 void SetDisplayText(ieStrRef text, unsigned int time);
165 private:
166 /** this function is called when the user presses 'q' (or equivalent) */
167 void QuickSave();
168 /** this function safely retrieves an Actor by ID */
169 Actor *GetActorByGlobalID(ieWord ID);
170 void CalculateSelection(const Point &p);
171 void ResizeDel(Window* win, int type);
172 void ResizeAdd(Window* win, int type);
173 void HandleWindowHide(const char *WindowName, const char *WindowPosition);
174 void HandleWindowReveal(const char *WindowName, const char *WindowPosition);
175 void ReadFormations();
176 /** Draws an arrow on the edge of the screen based on the point (points at offscreen actors) */
177 void DrawArrowMarker(const Region &screen, Point p, const Region &viewport);
179 private:
180 unsigned char LeftCount, BottomCount, RightCount, TopCount;
181 DialogState* ds;
182 Dialog* dlg;
183 Actor *user; //the user of item or spell
184 public:
185 ieWord speakerID;
186 ieWord targetID;
187 ieWord originalTargetID;
188 //no idea if this is viable
189 Scriptable *targetOB;
190 //using spell or item
191 int spellOrItem; // -1 = item, otherwise the spell type
192 //the user of spell or item
193 Actor *spellUser;
194 int spellSlot, spellIndex; //or inventorySlot/itemHeader
195 int spellCount; //multiple targeting
196 public:
197 Actor *GetTarget();
198 Actor *GetSpeaker();
199 /** Selects one or all PC */
200 void SelectActor(int whom, int type = -1);
201 void SetCutSceneMode(bool active);
202 int HideGUI();
203 int UnhideGUI();
204 void TryToAttack(Actor *source, Actor *target);
205 void TryToBash(Actor *source, Scriptable *tgt);
206 void TryToCast(Actor *source, const Point &p);
207 void TryToCast(Actor *source, Actor *target);
208 void TryToDefend(Actor *source, Actor *target);
209 void TryToTalk(Actor *source, Actor *target);
210 void TryToPick(Actor *source, Actor *tgt);
211 void TryToPick(Actor *source, Door *tgt);
212 void TryToPick(Actor *source, Container *tgt);
213 void TryToDisarm(Actor *source, InfoPoint *tgt);
214 void PerformActionOn(Actor *actor);
216 //containers
217 int GetCursorOverContainer(Container *overContainer);
218 void HandleContainer(Container *container, Actor *actor);
219 //doors
220 int GetCursorOverDoor(Door *overDoor);
221 void HandleDoor(Door *door, Actor *actor);
222 //infopoints
223 int GetCursorOverInfoPoint(InfoPoint *overInfoPoint);
224 bool HandleActiveRegion(InfoPoint *trap, Actor *actor, Point &p);
226 Point GetFormationOffset(ieDword formation, ieDword pos);
227 void MoveToPointFormation(Actor *actor, unsigned int pos, Point src, Point p);
228 /** calls MoveToPoint or RunToPoint */
229 void CreateMovement(Actor *actor, const Point &p);
230 int InitDialog(Scriptable* speaker, Scriptable* target, const char* dlgref);
231 void EndDialog(bool try_to_break=false);
232 void DialogChoose(unsigned int choose);
233 /** Displays a string over an object */
234 void DisplayString(Scriptable* target);
235 /** Displays a string on screen */
236 void DisplayString(const Point &p, const char *Text);
237 Actor *GetLastActor();
238 /** changes map to the current PC */
239 void ChangeMap(Actor *pc, bool forced);
240 /** Returns game screenshot, with or without GUI controls */
241 Sprite2D* GetScreenshot( bool show_gui = 0 );
242 /** Returns current area preview for saving a game */
243 Sprite2D* GetPreview();
244 /** Returns PC portrait for a currently running game */
245 Sprite2D* GetPortraitPreview(int pcslot);
246 /** Sets up targeting with spells or items */
247 void SetupItemUse(int slot, int header, Actor *actor, int targettype, int cnt);
248 /** Page is the spell type + spell level info */
249 void SetupCasting(int type, int level, int slot, Actor *actor, int targettype, int cnt);
250 bool SetEvent(int eventType, const char *handler);
253 #endif