00001 00002 // Copyright (C) 2004-2007 by The Allacrost Project 00003 // All Rights Reserved 00004 // 00005 // This code is licensed under the GNU GPL version 2. It is free software 00006 // and you may modify it and/or redistribute it under the terms of this license. 00007 // See http://www.gnu.org/copyleft/gpl.html for details. 00009 00016 #ifndef __MAP_SPRITES_HEADER__ 00017 #define __MAP_SPRITES_HEADER__ 00018 00019 #include "utils.h" 00020 #include "defs.h" 00021 #include "video.h" 00022 #include "map_actions.h" 00023 #include "map_dialogue.h" 00024 #include "map_objects.h" 00025 #include "map_zones.h" 00026 00027 namespace hoa_map { 00028 00029 namespace private_map { 00030 00031 // *********************** SPRITE CONSTANTS ************************** 00032 00039 const float VERY_SLOW_SPEED = 200.0f; 00040 const float SLOW_SPEED = 175.0f; 00041 const float NORMAL_SPEED = 150.0f; 00042 const float FAST_SPEED = 125.0f; 00043 const float VERY_FAST_SPEED = 100.0f; 00045 00058 const uint16 NORTH = 0x0001; 00059 const uint16 SOUTH = 0x0002; 00060 const uint16 WEST = 0x0004; 00061 const uint16 EAST = 0x0008; 00062 const uint16 NW_NORTH = 0x0010; 00063 const uint16 NW_WEST = 0x0020; 00064 const uint16 NE_NORTH = 0x0040; 00065 const uint16 NE_EAST = 0x0080; 00066 const uint16 SW_SOUTH = 0x0100; 00067 const uint16 SW_WEST = 0x0200; 00068 const uint16 SE_SOUTH = 0x0400; 00069 const uint16 SE_EAST = 0x0800; 00070 00071 const uint16 NORTHWEST = NW_NORTH | NW_WEST; 00072 const uint16 NORTHEAST = NE_NORTH | NE_EAST; 00073 const uint16 SOUTHWEST = SW_SOUTH | SW_WEST; 00074 const uint16 SOUTHEAST = SE_SOUTH | SE_EAST; 00075 00076 const uint16 FACING_NORTH = NORTH | NW_NORTH | NE_NORTH; 00077 const uint16 FACING_SOUTH = SOUTH | SW_SOUTH | SE_SOUTH; 00078 const uint16 FACING_WEST = WEST | NW_WEST | SW_WEST; 00079 const uint16 FACING_EAST = EAST | NE_EAST | SE_EAST; 00081 00088 const uint32 ANIM_STANDING_SOUTH = 0; 00089 const uint32 ANIM_STANDING_NORTH = 1; 00090 const uint32 ANIM_STANDING_WEST = 2; 00091 const uint32 ANIM_STANDING_EAST = 3; 00092 const uint32 ANIM_WALKING_SOUTH = 4; 00093 const uint32 ANIM_WALKING_NORTH = 5; 00094 const uint32 ANIM_WALKING_WEST = 6; 00095 const uint32 ANIM_WALKING_EAST = 7; 00097 00099 extern hoa_video::AnimatedImage new_dialogue_icon; 00100 00114 class VirtualSprite : public MapObject { 00115 public: 00121 uint16 direction; 00122 00124 float movement_speed; 00125 00130 bool moving; 00131 00137 bool sky_object; 00138 00140 hoa_utils::ustring name; 00141 00143 hoa_video::StillImage* face_portrait; 00144 00146 bool seen_all_dialogue; 00147 00153 int8 current_action; 00154 00155 // TODO: change how forced action work 00156 int8 forced_action; 00157 00159 std::vector<SpriteAction*> actions; 00160 00165 00166 bool _saved; 00167 uint16 _saved_direction; 00168 float _saved_movement_speed; 00169 bool _saved_moving; 00170 hoa_utils::ustring _saved_name; 00171 int8 _saved_current_action; 00173 00175 std::vector<MapDialogue*> dialogues; 00176 00182 int16 _current_dialogue; 00183 00185 bool _show_dialogue_icon; 00186 00188 hoa_video::Color _dialogue_icon_color; 00189 00190 // -------------------- Public methods 00191 00192 VirtualSprite(); 00193 00194 ~VirtualSprite(); 00195 00197 virtual void Update(); 00198 00200 virtual void Draw(); 00201 00212 void SetDirection(uint16 dir); 00213 00214 void SetMovementSpeed(float speed) 00215 { movement_speed = speed; } 00216 00217 uint16 GetDirection() const 00218 { return direction; } 00219 00220 float GetMovementSpeed() const 00221 { return movement_speed; } 00222 00223 void SetFacePortrait(std::string pn); 00225 00229 virtual void SaveState(); 00230 00235 virtual bool LoadState(); 00236 00238 void UpdateSeenDialogue(); 00239 00244 void AddAction(SpriteAction* act) 00245 { act->SetSprite(this); actions.push_back(act); } 00246 00247 void AddDialogue(MapDialogue* md) 00248 { dialogues.push_back(md); md->SetOwner(this); if (md->HasAlreadySeen() == false) seen_all_dialogue = false; } 00249 00250 bool HasDialogue() const 00251 { return (dialogues.size() > 0); } 00252 00253 MapDialogue* GetCurrentDialogue() const 00254 { return dialogues[_current_dialogue]; } 00255 00256 void SetDialogue(const int16 dialogue) 00257 { if (static_cast<uint16>(dialogue) >= dialogues.size()) return; else _current_dialogue = dialogue; } 00258 00259 void NextDialogue() 00260 { _current_dialogue++; if (static_cast<uint16>(_current_dialogue) >= dialogues.size()) _current_dialogue = 0; } 00261 00262 int16 GetNumDialogues() const 00263 { return dialogues.size(); } 00264 00265 void ShowDialogueIcon(bool state) 00266 { _show_dialogue_icon = state; } 00267 00268 bool IsShowingDialogueIcon() const 00269 { return _show_dialogue_icon; } 00271 00275 static uint16 CalculateOppositeDirection(const uint16 direction); 00276 00280 void SetRandomDirection(); 00281 }; // class VirtualSprite : public MapObject 00282 00283 00294 class MapSprite : public VirtualSprite { 00295 public: 00297 bool was_moving; 00298 00303 int8 walk_sound; 00304 00306 uint8 current_animation; 00307 00313 std::vector<hoa_video::AnimatedImage> animations; 00314 00319 bool _saved_was_moving; 00320 int8 _saved_walk_sound; 00321 uint8 _saved_current_animation; 00323 00324 // -------------------------------- Methods -------------------------------- 00325 00326 MapSprite(); 00327 00328 ~MapSprite(); 00329 00334 bool LoadStandardAnimations(std::string filename); 00335 00337 virtual void Update(); 00338 00340 virtual void Draw(); 00341 00347 void SetName(std::string na) 00348 { name = hoa_utils::MakeUnicodeString(na); } 00349 00350 void SetWalkSound(int8 sound) 00351 { walk_sound = sound; } 00352 00353 void SetCurrentAnimation(uint8 anim) 00354 { current_animation = anim; } 00355 00356 int8 GetWalkSound() const 00357 { return walk_sound; } 00358 00359 uint8 GetCurrentAnimation() const 00360 { return current_animation; } 00362 00367 virtual void SaveState(); 00368 00374 virtual bool LoadState(); 00375 }; // class MapSprite : public VirtualSprite 00376 00377 00393 class EnemySprite : public MapSprite { 00394 private: 00396 enum STATE { 00397 SPAWNING, 00398 HOSTILE, 00399 DEAD 00400 }; 00401 00402 public: 00404 EnemySprite(); 00405 00407 EnemySprite(std::string file); 00408 00410 bool Load(); 00411 00413 void Reset(); 00414 00416 virtual void Update(); 00417 00419 virtual void Draw(); 00420 00421 // TODO: eventually I would like the ability for Lua to pass in a table of ints to the AddEnemyParty function, but because I'm not quite 00422 // sure how to do that yet, I'm writing several smaller functions so we can just get this demo released. 00423 00424 // void AddEnemyParty(std::vector<uint32>& party); 00425 00429 void NewEnemyParty() 00430 { _enemy_parties.push_back(std::vector<uint32>()); } 00431 00437 void AddEnemy(uint32 enemy_id); 00438 00440 const std::vector<uint32>& RetrieveRandomParty(); 00441 00443 00444 float GetAggroRange() const 00445 { return _aggro_range; } 00446 00447 uint32 GetTimeToChange() const 00448 { return _time_dir_change; } 00449 00450 uint32 GetTimeToSpawn() const 00451 { return _time_to_spawn; } 00452 00453 std::string GetBattleMusicTheme() const 00454 { return _music_theme; } 00455 00456 bool IsDead() const 00457 { return _state == DEAD; } 00458 00459 bool IsSpawning() const 00460 { return _state == SPAWNING; } 00461 00462 bool IsHostile() const 00463 { return _state == HOSTILE; } 00464 00465 void SetZone(EnemyZone* zone) 00466 { _zone = zone; } 00467 00468 void SetAggroRange(float range) 00469 { _aggro_range = range; } 00470 00471 void SetTimeToChange(uint32 time) 00472 { _time_dir_change = time; } 00473 00474 void SetTimeToSpawn(uint32 time) 00475 { _time_to_spawn = time; } 00476 00477 void SetBattleMusicTheme(const std::string & music_theme) 00478 { _music_theme = music_theme; } 00479 00480 void ChangeStateDead() { 00481 Reset(); 00482 if( _zone ) 00483 _zone->EnemyDead(); 00484 } 00485 00486 void ChangeStateSpawning() 00487 { updatable = true; _state = SPAWNING; no_collision = false; } 00488 00489 void ChangeStateHostile() 00490 { updatable = true; _state = HOSTILE; no_collision = false; _color.SetAlpha(1.0); } 00492 00493 private: 00495 private_map::EnemyZone* _zone; 00496 00498 hoa_video::Color _color; 00499 00501 uint32 _time_elapsed; 00502 00504 STATE _state; 00505 00507 float _aggro_range; 00508 00510 uint32 _time_dir_change; 00511 00513 uint32 _time_to_spawn; 00514 00516 bool _out_of_zone; 00517 00519 std::string _music_theme; 00520 00524 std::vector<std::vector<uint32> > _enemy_parties; 00525 }; // class EnemySprite : public MapSprite 00526 00527 } // namespace private_map 00528 00529 } // namespace hoa_map 00530 00531 #endif // __MAP_SPRITES_HEADER__
1.5.1