ScummVM API documentation
level.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on the CRAB engine
24  *
25  * Copyright (c) Arvind Raja Yadav
26  *
27  * Licensed under MIT
28  *
29  */
30 
31 #ifndef CRAB_LEVEL_H
32 #define CRAB_LEVEL_H
33 
34 #include "common/multimap.h"
35 #include "crab/PathfindingGrid.h"
36 #include "crab/animation/sprite.h"
37 #include "crab/level/level_objects.h"
38 #include "crab/level/talknotify.h"
39 #include "crab/TMX/TMXMap.h"
40 
41 namespace Crab {
42 
43 namespace pyrodactyl {
44 namespace level {
45 class Level {
46  // The .tmx file to import terrain from
47  TMX::TMXMap _terrain;
48 
49  // The pathfinding grid for the level
50  PathfindingGrid _pathfindingGrid;
51 
52  // The area we display to the player
53  Rect _camera;
54 
55  // The player sprite location in the object list
56  uint _playerIndex;
57 
58  // The order in which to draw the sprites
60 
61  // The file index which contains the fighting moves of all characters
63 
64  // The movement sets for sprites in levels
66 
67  // These sprites are only for animated objects and cannot be interacted with
69 
70  // These sprites fly across the screen randomly
72 
73  // The id of the music track being played
74  MusicInfo _music;
75 
76  // Is the world map accessible from this level?
77  MapVis _showmap;
78 
79  // We disable exits when player is fighting enemies - this is used to check if we are in an exit area WHILE fighting enemies
80  // If we are fighting inside exit area, the level switch is delayed until we walk out of exit and back in
81  // to prevent instant level switch as soon as you beat all enemies
82  bool _insideExit;
83 
84  bool _firstHit;
85 
86  // Default sprite parameters
88 
89  // Protected level functions
90  bool collidingWithObject(pyrodactyl::event::Info &info, Common::String &id);
91  bool collidingWithLevel(pyrodactyl::event::Info &info, pyrodactyl::anim::Sprite &s);
92  bool playerInCombat(pyrodactyl::event::Info &info);
93  void battleAlert(pyrodactyl::event::Info &info);
94 
95  void sortObjectsToDraw();
96  void moveObject(pyrodactyl::event::Info &info, pyrodactyl::anim::Sprite &s);
97 
100 
101  void drawObjects(pyrodactyl::event::Info &info);
102  void setCamera();
103 
104  bool layerVisible(pyrodactyl::anim::Sprite *obj);
105 
106 public:
107  // The objects in the level, and the player character
109 
110  // The notification text drawn if the player is able to talk to a sprite
111  TalkNotify _talkNotify;
112 
113  // Used for drawing the destination marker for point and click movement
114  PlayerDestMarker _destMarker;
115 
116  // The location of this level on the world map
117  Vector2i _mapLoc;
118 
119  // The clip revealed by this level on the world map
120  struct MapClip {
121  // Which world map is this clip added to?
122  int _id;
123 
124  // The clip itself
125  Rect _rect;
126 
127  MapClip() {
128  _id = 0;
129  }
130  } _mapClip;
131 
132  // Used to draw ambient dialog
134 
135  // The path of the preview image
136  Common::Path _previewPath;
137 
138  // A full rendered image of the level
140 
141  Level() : _playerIndex(0) {
142  reset();
143  }
144 
145  ~Level() {
146  reset();
147  }
148 
149  void reset();
150 
151  void Camera(int x, int y, int w, int h) {
152  _camera.x = x;
153  _camera.y = y;
154  _camera.w = w;
155  _camera.h = h;
156  }
157 
158  Rect camera() {
159  return _camera;
160  }
161 
162  void playerStop() {
163  _objects[_playerIndex].stop();
164  }
165 
166  const Common::String &playerId() {
167  return _objects[_playerIndex].id();
168  }
169 
170  void playerId(const Common::String &ID, const int &x, const int &y);
171 
172  void showMap(bool val) {
173  _showmap._normal = val;
174  }
175 
176  bool showMap() {
177  return _showmap._current;
178  }
179 
180  bool operator()(int i, int j);
181 
182  // This calculates the unlocked moves for each sprite in the level, and the visibility of objects
183  void calcProperties(pyrodactyl::event::Info &info);
184 
185  // Loading function
186  void load(const Common::Path &filename, pyrodactyl::event::Info &info, pyrodactyl::event::TriggerSet &gameOver,
187  const int &playerX = -1, const int &playerY = -1);
188 
189  // One time load called first-time
190  void loadMoves(const Common::Path &filename);
191  void loadConst(const Common::Path &filename);
192 
193  // Used to see if a sprite collides with a rectangle
194  void calcTrigCollide(pyrodactyl::event::Info &info);
195 
196  // See if a player clicked on the sprite in contact
197  bool containsClick(const Common::String &id, const Common::Event &event);
198 
199  // Get index of a sprite in the object array
200  pyrodactyl::anim::Sprite *getSprite(const Common::String &id);
201 
202  void handleEvents(pyrodactyl::event::Info &info, const Common::Event &event);
204  Common::Array<pyrodactyl::event::EventSeqInfo> &endSeq, bool eventInProgress);
205 
206  void preDraw();
207  void preDrawObjects(Graphics::ManagedSurface *surf);
208  void draw(pyrodactyl::event::Info &info);
209 
210  void saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root);
211  void loadState(rapidxml::xml_node<char> *node);
212 
213  void setUI();
214 };
215 } // End of namespace level
216 } // End of namespace pyrodactyl
217 
218 } // End of namespace Crab
219 
220 #endif // CRAB_LEVEL_H
Definition: managed_surface.h:51
Definition: sprite.h:49
Definition: str.h:59
Definition: TMXMap.h:47
Definition: Rectangle.h:42
Definition: ParagraphData.h:40
Definition: LevelResult.h:44
Definition: PathfindingGrid.h:43
Definition: level_objects.h:56
Definition: path.h:52
Definition: GameEventInfo.h:44
Definition: multimap.h:34
Definition: SpriteConstant.h:57
Definition: level_objects.h:42
Definition: Image.h:51
Definition: talknotify.h:40
Definition: events.h:199
Definition: triggerset.h:40
Definition: moveeffect.h:37
Definition: level.h:45
Definition: MusicArea.h:41