BattleManager.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <iostream>
  16. #include <cmath>
  17. #include <OgreEntity.h>
  18. #include <OgreRoot.h>
  19. #include <OgreViewport.h>
  20. #include "core/BattleManager.h"
  21. #include "core/ConfigVar.h"
  22. #include "core/Logger.h"
  23. /**
  24. * Battle manager singleton.
  25. */
  26. template<>BattleManager *Ogre::Singleton<BattleManager>::msSingleton = nullptr;
  27. ConfigVar cv_debug_battle_grid("debug_battle_grid", "Draw debug battle grid", "false");
  28. ConfigVar cv_debug_battle_axis("debug_battle_axis", "Draw debug battle axis", "false");
  29. BattleManager::BattleManager(): paused_(false){
  30. LOG_TRIVIAL("BattleManager created.");
  31. scene_node_ = Ogre::Root::getSingleton().getSceneManager("Scene")
  32. ->getRootSceneNode()->createChildSceneNode("BattleManager");
  33. }
  34. BattleManager::~BattleManager(){
  35. Clear();
  36. Ogre::Root::getSingleton().getSceneManager("Scene")->getRootSceneNode()->removeAndDestroyChild(
  37. "BattleManager"
  38. );
  39. LOG_TRIVIAL("BattleManager destroyed.");
  40. }
  41. void BattleManager::Input(const VGears::Event& event){
  42. // TODO: Change to battle input commands.
  43. //background_2d_.InputDebug(event);
  44. if (paused_ == true) return;
  45. //if (event.type == VGears::ET_KEY_PRESS && event.event == "interact"){
  46. // TODO
  47. //}
  48. }
  49. void BattleManager::Update(){
  50. UpdateDebug();
  51. if (paused_ == true) return;
  52. // TODO: Update all entity scripts
  53. // for (unsigned int i = 0; i < party_.size(); ++ i) party_[i]->Update();
  54. // for (unsigned int i = 0; i < enemy_.size(); ++ i) enemy_[i]->Update();
  55. // TODO: Environment model update
  56. }
  57. void BattleManager::UpdateDebug(){
  58. // TODO: Update all entity scripts
  59. // for (unsigned int i = 0; i < party_.size(); ++ i) party_[i]->UpdateDebug();
  60. // for (unsigned int i = 0; i < enemy_.size(); ++ i) enemy_[i]->UpdateDebug();
  61. // TODO: Environment model update
  62. }
  63. void BattleManager::Clear(){
  64. paused_ = false;
  65. formation_id_ = -1;
  66. next_formation_id_ = -1;
  67. // TODO location_ = null;
  68. // TODO camera_.clear();
  69. initial_camera_ = 0;
  70. layout_ = LAYOUT::NORMAL;
  71. escape_difficulty_ = 0.0f;
  72. arena_battle_ = false;
  73. show_victory_pose_ = true;
  74. show_spoils_ = true;
  75. preemptive_ = true;
  76. money_ = 0;
  77. spoil_.clear();
  78. // TODO enemy_.clear();
  79. // TODO party_.clear();
  80. scene_node_->removeAndDestroyAllChildren();
  81. }
  82. void BattleManager::ScriptSetPaused(const bool paused){paused_ = paused;}
  83. void BattleManager::SetLayout(const LAYOUT layout){
  84. if (layout == LAYOUT::UNKNOWN_0 || layout == LAYOUT::UNKNOWN_1) layout_ = LAYOUT::NORMAL;
  85. else layout_ = layout;
  86. }
  87. void BattleManager::SetFormationId(const int id){
  88. if (id < 0) formation_id_ = -1;
  89. else formation_id_ = id;
  90. }
  91. void BattleManager::SetNextFormationId(const int id){
  92. if (id < 0) next_formation_id_ = -1;
  93. else next_formation_id_ = id;
  94. }
  95. void BattleManager::SetEscapeability(const float difficulty){
  96. if (difficulty < 0.0f || difficulty > 1.0f) escape_difficulty_ = -1.0f;
  97. else escape_difficulty_ = difficulty;
  98. }
  99. void BattleManager::SetSkipVictoryPose(const bool skip){show_victory_pose_ = !skip;}
  100. void BattleManager::SetSkipSpoils(const bool skip){show_spoils_ = !skip;}
  101. void BattleManager::SetLocation(const int id, const Ogre::String name){
  102. // TODO
  103. }
  104. void BattleManager::SetArenaBattle(const bool arena){arena_battle_ = arena;}
  105. void BattleManager::AddCamera(
  106. const unsigned int id, const int x, const int y, const int z,
  107. const int direction_x, const int direction_y, const int direction_z
  108. ){
  109. // TODO
  110. }
  111. void BattleManager::SetInitialCamera(const unsigned int id){initial_camera_ = id;}
  112. void BattleManager::AddEnemy(
  113. const unsigned int id, const int x, const int y, const int z, const bool front_row,
  114. const Ogre::String cover, const bool visible, const bool target, const int script
  115. ){
  116. // TODO
  117. }