00001
00002
00003
00004
00005
00006
00007
00009
00021 #ifndef __BATTLE_HEADER__
00022 #define __BATTLE_HEADER__
00023
00024 #include <string>
00025 #include <vector>
00026 #include <deque>
00027 #include <map>
00028
00029 #include "utils.h"
00030 #include "defs.h"
00031 #include "video.h"
00032 #include "audio.h"
00033 #include "global.h"
00034 #include "global_actors.h"
00035 #include "mode_manager.h"
00036 #include "system.h"
00037
00038 #include "battle_windows.h"
00039
00040 namespace hoa_battle {
00041
00042 extern bool BATTLE_DEBUG;
00043
00045 namespace private_battle {
00046
00048 extern BattleMode* current_battle;
00049
00051
00052
00053 const uint32 TILE_SIZE = 64;
00055 const uint32 SCREEN_LENGTH = 16;
00057 const uint32 SCREEN_HEIGHT = 12;
00059
00063 const float MONSTER_LOCATIONS[][2] =
00064 {
00065 { 515.0f, 768.0f - 360.0f },
00066 { 494.0f, 768.0f - 450.0f },
00067 { 510.0f, 768.0f - 550.0f },
00068 { 580.0f, 768.0f - 630.0f },
00069 { 675.0f, 768.0f - 390.0f },
00070 { 655.0f, 768.0f - 494.0f },
00071 { 793.0f, 768.0f - 505.0f },
00072 { 730.0f, 768.0f - 600.0f }
00073 };
00074
00075
00080 const uint32 ACTION_TYPE_ATTACK = 0;
00081 const uint32 ACTION_TYPE_DEFEND = 1;
00082 const uint32 ACTION_TYPE_SUPPORT = 2;
00083 const uint32 ACTION_TYPE_ITEM = 3;
00085
00097 enum CURSOR_STATE {
00098 CURSOR_IDLE = 0,
00099 CURSOR_WAIT = 1,
00100 CURSOR_SELECT_ATTACK_POINT = 2,
00101 CURSOR_SELECT_TARGET = 3,
00102 CURSOR_SELECT_PARTY = 4
00103 };
00104
00106 const uint32 INVALID_BATTLE_ACTOR_INDEX = 999;
00107
00109 const uint32 MAX_INIT_WAIT_TIME = 8000;
00110
00112
00113 const uint32 ITEM_WARM_UP_TIME = 1000;
00114
00116
00117 const bool ACTIVE_BATTLE_MODE = false;
00118
00125 float ComputeAveragePartyLevel();
00126
00132 class ScriptEvent {
00133 public:
00134
00135 ScriptEvent(BattleActor* source, BattleActor* target, hoa_global::GlobalItem* item, hoa_global::GlobalAttackPoint* attack_point = NULL, uint32 warm_up_time = ITEM_WARM_UP_TIME);
00136 ScriptEvent(BattleActor* source, BattleActor* target, hoa_global::GlobalSkill* skill, hoa_global::GlobalAttackPoint* attack_point = NULL);
00137
00138
00139 ~ScriptEvent();
00140
00142 void RunScript();
00143
00145
00146 BattleActor * GetSource()
00147 { return _source; }
00148
00149 inline hoa_system::SystemTimer* GetWarmUpTime()
00150 { return &_warm_up_time; }
00151
00152 inline BattleActor* GetTarget()
00153 { return _target; }
00154
00155 inline hoa_global::GlobalItem* GetItem()
00156 { return _item; }
00157
00158 inline hoa_global::GlobalSkill* GetSkill()
00159 { return _skill; }
00160
00162
00164
00165
00167
00169 void Update();
00170
00171
00172
00173
00174
00176
00177
00178 private:
00180 std::string _script_name;
00181
00183 BattleActor* _source;
00184
00186 hoa_global::GlobalSkill* _skill;
00187
00189 hoa_global::GlobalItem* _item;
00190
00192 hoa_global::GlobalAttackPoint* _attack_point;
00193
00194
00195
00197 BattleActor* _target;
00198
00200
00201
00203 hoa_system::SystemTimer _warm_up_time;
00205 };
00206
00207 }
00208
00222 class BattleMode : public hoa_mode_manager::GameMode {
00223 friend class private_battle::BattleActor;
00224 friend class private_battle::BattleCharacterActor;
00225 friend class private_battle::BattleEnemyActor;
00226 friend class private_battle::ScriptEvent;
00227 friend class private_battle::ActionWindow;
00228 friend class private_battle::FinishWindow;
00229 public:
00230 BattleMode();
00231
00232 ~BattleMode();
00233
00238
00239 void Reset();
00240
00242 void Update();
00243
00245 void Draw();
00247
00254 void AddEnemy(hoa_global::GlobalEnemy new_enemy);
00255
00264 void AddEnemy(uint32 new_enemy_id)
00265 { AddEnemy(hoa_global::GlobalEnemy(new_enemy_id)); }
00266
00273 void AddMusic(std::string music_filename);
00274
00275
00276
00278 bool _IsPerformingScript() const
00279 { return _performing_script; }
00280
00282 void SetPerformingScript(bool is_performing, private_battle::ScriptEvent* se);
00283
00285 void AddScriptEventToQueue(private_battle::ScriptEvent* event)
00286 { _script_queue.push_back(event); }
00287
00289 void RemoveScriptedEventsForActor(hoa_battle::private_battle::BattleActor * actor);
00290
00292 std::deque<private_battle::BattleCharacterActor*> GetCharacters() const
00293 { return _character_actors; }
00294
00296 void FreezeTimers();
00297
00299 void UnFreezeTimers();
00300
00302 bool IsBattleOver() const
00303 { return _battle_over; }
00304
00306 bool IsVictorious() const
00307 { return _victorious_battle; }
00308
00310 void PlayerVictory();
00311
00313 void PlayerDefeat();
00314
00315 uint32 GetNumberOfCharacters() const
00316 { return _character_actors.size(); }
00317
00318 uint32 GetNumberOfEnemies() const
00319 { return _enemy_actors.size(); }
00320
00321 uint32 GetIndexOfFirstAliveEnemy() const;
00322
00323 uint32 GetIndexOfLastAliveEnemy() const;
00324
00325 uint32 GetIndexOfFirstIdleCharacter() const;
00326
00328 uint32 GetIndexOfNextAliveEnemy(bool move_upward) const;
00329
00331 private_battle::BattleCharacterActor * GetPlayerCharacterAt(uint32 index) const
00332 { return _character_actors.at(index); }
00333
00335 private_battle::BattleEnemyActor * GetEnemyActorAt(uint32 index) const
00336 { return _enemy_actors.at(index); }
00337
00339 uint32 GetIndexOfCharacter(private_battle::BattleCharacterActor * const Actor) const;
00340
00342
00343 void SwapCharacters(private_battle::BattleCharacterActor * ActorToRemove, private_battle::BattleCharacterActor * ActorToAdd);
00344
00345
00346
00347 inline private_battle::ScriptEvent* GetActiveScript()
00348 { return _active_se; }
00349
00350 private:
00352 bool _initialized;
00353
00355 bool _performing_script;
00356
00358 private_battle::ScriptEvent* _active_se;
00359
00361 bool _battle_over;
00362
00364 bool _victorious_battle;
00365
00367 uint32 _victory_xp;
00368
00370 uint32 _victory_sp;
00371
00373 uint32 _victory_money;
00374
00376 bool _victory_level;
00377
00379 bool _victory_skill;
00380
00382 std::map<std::string, uint32> _victory_items;
00383
00388 std::vector<hoa_audio::MusicDescriptor> _battle_music;
00389
00391
00392
00393 hoa_video::StillImage _battle_background;
00394
00396 std::vector<hoa_video::ImageDescriptor*> _background_images;
00398
00400
00401
00405 std::deque<hoa_global::GlobalEnemy> _original_enemies;
00406
00411 std::deque<hoa_global::GlobalCharacter> _original_characters;
00412
00419 std::map<uint8, private_battle::BattleActor*> _battle_actors;
00420
00427 std::deque<private_battle::BattleCharacterActor*> _character_actors;
00428
00434 std::deque<private_battle::BattleEnemyActor*> _enemy_actors;
00435
00440 std::deque<private_battle::BattleCharacterActor*> _reserve_characters;
00442
00444
00445
00446 private_battle::CURSOR_STATE _cursor_state;
00447
00448
00449
00450
00455 int32 _selected_character_index;
00456
00458 uint32 _selected_target_index;
00459
00461 private_battle::BattleCharacterActor* _selected_character;
00462
00466 private_battle::BattleActor* _selected_target;
00467
00472 uint32 _selected_attack_point;
00474
00476
00477
00481 private_battle::ActionWindow* _action_window;
00482
00487 private_battle::FinishWindow* _finish_window;
00489
00491
00492
00493 hoa_video::StillImage _bottom_menu_image;
00494
00499 hoa_video::StillImage _actor_selection_image;
00500
00505 hoa_video::AnimatedImage _attack_point_indicator;
00506
00512 hoa_video::StillImage _universal_time_meter;
00513
00518 hoa_video::StillImage _swap_icon;
00519
00525 hoa_video::StillImage _swap_card;
00527
00529
00530
00535 uint8 _current_number_swaps;
00536
00541 int32 _swap_countdown_timer;
00543
00545 uint32 _min_agility;
00546
00548
00549
00550 std::list<private_battle::ScriptEvent*> _script_queue;
00552
00554 int32 _next_monster_location_index;
00555
00557
00562 void _TEMP_LoadTestData();
00563
00564 void _CreateCharacterActors();
00565
00566 void _CreateEnemyActors();
00567
00569 void _Initialize();
00570
00572 void _ShutDown();
00573
00575 void _TallyRewards();
00576
00578 uint32 _NumberEnemiesAlive() const;
00579
00583 uint32 _NumberCharactersAlive() const;
00584
00589
00590 void _UpdateCharacterSelection();
00591
00593 void _UpdateTargetSelection();
00594
00596 void _UpdateAttackPointSelection();
00598
00607 void _DrawBackgroundVisuals();
00608
00613 void _DrawBottomMenu();
00614
00619 void _DrawSprites();
00620
00624 void _DrawTimeMeter();
00626 };
00627
00628 }
00629
00630 #endif // __BATTLE_HEADER__