XmlFormationFile.cpp 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "core/XmlFormationFile.h"
  16. #include "core/BattleManager.h"
  17. #include "common/Logger.h"
  18. XmlFormationFile::XmlFormationFile(const Ogre::String& file): XmlFile(file){}
  19. XmlFormationFile::~XmlFormationFile(){}
  20. void XmlFormationFile::LoadFormation(){
  21. TiXmlNode* node = file_.RootElement();
  22. if (node == nullptr || node->ValueStr() != "formation"){
  23. LOG_ERROR(file_.ValueStr() + " is not a valid fields map file! No <formation> in root.");
  24. return;
  25. }
  26. BattleManager::getSingleton().SetFormationId(GetInt(node, "id"));
  27. BattleManager::getSingleton().SetNextFormationId(GetInt(node, "next"));
  28. BattleManager::getSingleton().SetLayout(
  29. static_cast<BattleManager::LAYOUT>(GetInt(node, "layout"))
  30. );
  31. BattleManager::getSingleton().SetPreemptiveDisabled(GetInt(node, "preemptive_disabled") == 1);
  32. if (GetInt(node, "escapable") == 1)
  33. BattleManager::getSingleton().SetEscapeability(GetFloat(node, "escape_difficulty"));
  34. else BattleManager::getSingleton().SetEscapeability(-1.0f);
  35. BattleManager::getSingleton().SetSkipVictoryPose(GetInt(node, "skip_victory_pose") == 1);
  36. BattleManager::getSingleton().SetSkipSpoils(GetInt(node, "skip_spoils") == 1);
  37. node = node->FirstChild();
  38. while (node != nullptr){
  39. // Location data.
  40. if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "location"){
  41. int id = GetInt(node, "id");
  42. Ogre::String name(GetString(node, "name"));
  43. BattleManager::getSingleton().SetLocation(id, name);
  44. }
  45. else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "arena"){
  46. bool is_arena = GetInt(node, "is_arena") == 1;
  47. BattleManager::getSingleton().SetArenaBattle(is_arena);
  48. if (is_arena){
  49. // TODO: Read more info for arena battles
  50. }
  51. }
  52. else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "camera"){
  53. BattleManager::getSingleton().SetInitialCamera(GetInt(node, "initial"));
  54. BattleManager::getSingleton().SetIntroCamera(GetInt(node, "intro", -1));
  55. TiXmlNode* camera_node = node->FirstChild();
  56. while (camera_node != nullptr){
  57. int id = GetInt(camera_node, "id");
  58. Ogre::Vector3 pos = Ogre::Vector3(
  59. GetFloat(camera_node, "x"), GetFloat(camera_node, "y"), GetFloat(camera_node, "z")
  60. );
  61. Ogre::Vector3 dir = Ogre::Vector3(
  62. GetFloat(camera_node, "direction_x"), GetFloat(camera_node, "direction_y"),
  63. GetFloat(camera_node, "direction_z")
  64. );
  65. BattleManager::getSingleton().AddCamera(id, pos, dir);
  66. camera_node = camera_node->NextSibling();
  67. }
  68. }
  69. else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "enemies"){
  70. TiXmlNode* enemy_node = node->FirstChild();
  71. while (enemy_node != nullptr){
  72. int id = GetInt(enemy_node, "id");
  73. Ogre::Vector3 pos = Ogre::Vector3(
  74. GetInt(enemy_node, "x"), GetInt(enemy_node, "y"), GetInt(enemy_node, "z")
  75. );
  76. bool front = GetInt(enemy_node, "row") == 1;
  77. bool visible = GetInt(enemy_node, "visible") == 1;
  78. bool targeteable = GetInt(enemy_node, "targeteable") == 1;
  79. bool active = GetInt(enemy_node, "main_script_active") == 1;
  80. std::string cover = GetString(enemy_node, "cover");
  81. BattleManager::getSingleton().AddEnemy(
  82. id, pos, front, visible, targeteable, active, cover
  83. );
  84. enemy_node = enemy_node->NextSibling();
  85. }
  86. }
  87. node = node->NextSibling();
  88. }
  89. }