00001
00002
00003
00004
00005
00006
00007
00009
00026 #ifndef __MAP_HEADER__
00027 #define __MAP_HEADER__
00028
00029 #include "defs.h"
00030 #include "utils.h"
00031
00032 #include "mode_manager.h"
00033 #include "script.h"
00034 #include "video.h"
00035 #include "gui.h"
00036
00038 namespace hoa_map {
00039
00041 extern bool MAP_DEBUG;
00042
00044 namespace private_map {
00045
00046
00047
00054 const float SCREEN_COLS = 64.0f;
00055 const float SCREEN_ROWS = 48.0f;
00056 const float HALF_SCREEN_COLS = 32.0f;
00057 const float HALF_SCREEN_ROWS = 24.0f;
00058 const uint16 TILE_COLS = 32;
00059 const uint16 TILE_ROWS = 24;
00060 const uint16 HALF_TILE_COLS = 16;
00061 const uint16 HALF_TILE_ROWS = 12;
00063
00065 const uint32 TILES_PER_TILESET = 256;
00066
00072
00073 const uint8 EXPLORE = 0x01;
00075 const uint8 DIALOGUE = 0x02;
00077 const uint8 OBSERVATION = 0x04;
00079
00083 enum MAP_CONTEXT {
00084 MAP_CONTEXT_01 = 0x00000001,
00085 MAP_CONTEXT_02 = 0x00000002,
00086 MAP_CONTEXT_03 = 0x00000004,
00087 MAP_CONTEXT_04 = 0x00000008,
00088 MAP_CONTEXT_05 = 0x00000010,
00089 MAP_CONTEXT_06 = 0x00000020,
00090 MAP_CONTEXT_07 = 0x00000040,
00091 MAP_CONTEXT_08 = 0x00000080,
00092 MAP_CONTEXT_09 = 0x00000100,
00093 MAP_CONTEXT_10 = 0x00000200,
00094 MAP_CONTEXT_11 = 0x00000400,
00095 MAP_CONTEXT_12 = 0x00000800,
00096 MAP_CONTEXT_13 = 0x00001000,
00097 MAP_CONTEXT_14 = 0x00002000,
00098 MAP_CONTEXT_15 = 0x00004000,
00099 MAP_CONTEXT_16 = 0x00008000,
00100 MAP_CONTEXT_17 = 0x00010000,
00101 MAP_CONTEXT_18 = 0x00020000,
00102 MAP_CONTEXT_19 = 0x00040000,
00103 MAP_CONTEXT_20 = 0x00080000,
00104 MAP_CONTEXT_21 = 0x00100000,
00105 MAP_CONTEXT_22 = 0x00200000,
00106 MAP_CONTEXT_23 = 0x00400000,
00107 MAP_CONTEXT_24 = 0x00800000,
00108 MAP_CONTEXT_25 = 0x01000000,
00109 MAP_CONTEXT_26 = 0x02000000,
00110 MAP_CONTEXT_27 = 0x04000000,
00111 MAP_CONTEXT_28 = 0x08000000,
00112 MAP_CONTEXT_29 = 0x10000000,
00113 MAP_CONTEXT_30 = 0x20000000,
00114 MAP_CONTEXT_31 = 0x40000000,
00115 MAP_CONTEXT_32 = 0x80000000
00116 };
00117
00118
00131 class MapFrame {
00132 public:
00134 int16 starting_col, starting_row;
00135
00137 uint8 num_draw_cols, num_draw_rows;
00138
00140 float tile_x_start, tile_y_start;
00141
00148 float left_edge, right_edge, top_edge, bottom_edge;
00149 };
00150
00151
00158 class PathNode {
00159 public:
00165 int16 row, col;
00167
00169
00170
00171 int16 f_score;
00172
00174 int16 g_score;
00175
00177 int16 h_score;
00179
00180
00181 int16 parent_row, parent_col;
00182
00183 PathNode() :
00184 row(-1), col(-1), f_score(0), g_score(0), h_score(0), parent_row( 0 ), parent_col( 0 ) {}
00185
00186 PathNode(int16 r, int16 c) :
00187 row(r), col(c), f_score(0), g_score(0), h_score(0), parent_row( 0 ), parent_col( 0 ) {}
00188
00190 bool operator==(const PathNode& that) const
00191 { return ((this->row == that.row) && (this->col == that.col)); }
00192
00194 bool operator!=(const PathNode& that) const
00195 { return ((this->row != that.row) || (this->col != that.col)); }
00196
00198 bool operator<(const PathNode& that) const
00199 { return this->f_score > that.f_score; }
00200 };
00201
00202 }
00203
00204
00228 class MapTile {
00229 public:
00235 int16 lower_layer, middle_layer, upper_layer;
00237
00238 MapTile()
00239 { lower_layer = -1; middle_layer = -1; upper_layer = -1; }
00240
00241 MapTile(int16 lower, int16 middle, int16 upper)
00242 { lower_layer = lower; middle_layer = middle; upper_layer = upper; }
00243 };
00244
00270 class MapMode : public hoa_mode_manager::GameMode {
00271 friend class private_map::MapFrame;
00272 friend class private_map::MapObject;
00273 friend class private_map::PhysicalObject;
00274 friend class private_map::VirtualSprite;
00275 friend class private_map::MapSprite;
00276 friend class private_map::EnemySprite;
00277 friend class private_map::DialogueManager;
00278 friend class private_map::MapDialogue;
00279 friend class private_map::SpriteAction;
00280 friend class private_map::ActionPathMove;
00281 friend class private_map::EnemyZone;
00282
00283 friend void hoa_defs::BindEngineToLua();
00284 public:
00285 MapMode(std::string filename);
00286
00287 ~MapMode();
00288
00290 void Reset();
00291
00293 void Update();
00294
00296 void Draw();
00297
00298 private:
00303 static MapMode *_current_map;
00304
00309 static MapMode *_loading_map;
00310
00312 static bool _show_dialogue_icons;
00313
00319 hoa_system::SystemTimer _intro_timer;
00320
00322 std::string _map_filename;
00323
00325 hoa_utils::ustring _map_name;
00326
00328 hoa_video::StillImage _location_graphic;
00329
00331 uint8 _map_state;
00332
00334 uint32 _time_elapsed;
00335
00339 uint16 _num_tile_rows;
00340
00344 uint16 _num_tile_cols;
00345
00350 uint16 _num_grid_rows, _num_grid_cols;
00351
00353 private_map::MapFrame _draw_info;
00354
00359 hoa_script::ReadScriptDescriptor _map_script;
00360
00365 ScriptObject _update_function;
00366
00370
00372
00373
00375
00377 std::vector<std::vector<MapTile> > _tile_grid;
00378
00385 std::vector<std::vector<uint32> > _map_grid;
00386
00392 std::map<uint16, private_map::MapObject*> _all_objects;
00393
00396 uint16 _lastID;
00397
00401 std::vector<private_map::MapObject*> _ground_objects;
00402
00411 std::vector<private_map::MapObject*> _pass_objects;
00412
00418 std::vector<private_map::MapObject*> _sky_objects;
00419
00426 private_map::VirtualSprite* _camera;
00427
00434 private_map::VirtualSprite *_virtual_focus;
00435
00437 std::vector<hoa_video::ImageDescriptor*> _tile_images;
00438
00446 std::vector<hoa_video::AnimatedImage*> _animated_tile_images;
00447
00449 std::vector<hoa_audio::MusicDescriptor> _music;
00450
00452 std::vector<hoa_audio::SoundDescriptor> _sounds;
00453
00455 private_map::DialogueManager* _dialogue_manager;
00456
00458 std::vector<private_map::MapZone*> _zones;
00459
00460
00461
00467 std::vector<hoa_global::GlobalEnemy> _enemies;
00468
00470 void _Load();
00471
00473 void _LoadTiles();
00474
00475
00476
00478 void _HandleInputExplore();
00479
00481 void _HandleInputDialogue();
00482
00492 private_map::MapObject* _FindNearestObject(const private_map::VirtualSprite* sprite);
00493
00509 bool _DetectCollision(private_map::VirtualSprite* sprite);
00510
00522 void _FindPath(const private_map::VirtualSprite* sprite, std::vector<private_map::PathNode>& path, const private_map::PathNode& dest);
00523
00524
00525
00527 void _CalculateDrawInfo();
00528
00529
00536 void _AddGroundObject(private_map::MapObject *obj);
00537
00538 void _AddPassObject(private_map::MapObject *obj);
00539
00540 void _AddSkyObject(private_map::MapObject *obj);
00541
00542 void _AddZone(private_map::MapZone *zone);
00543
00544 uint16 _GetGeneratedObjectID();
00545
00546 void _SetMapState(uint8 state)
00547 { _map_state = state; }
00548
00549 void _SetCameraFocus(private_map::VirtualSprite *sprite)
00550 { _camera = sprite; }
00551
00552 uint8 _GetMapState() const
00553 { return _map_state; }
00554
00555 uint32 _GetTimeElapsed() const
00556 { return _time_elapsed; }
00557
00558 private_map::VirtualSprite* _GetCameraFocus() const
00559 { return _camera; }
00560
00561 static void _ShowDialogueIcons( bool state )
00562 { _show_dialogue_icons = state; }
00563
00564 static bool _IsShowingDialogueIcons()
00565 { return _show_dialogue_icons; }
00567 };
00568
00569 }
00570
00571 #endif