XmlFormationFile.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "core/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. if (GetInt(node, "escapable") == 1)
  29. BattleManager::getSingleton().SetEscapeability(GetFloat(node, "escape_difficulty"));
  30. else BattleManager::getSingleton().SetEscapeability(-1.0f);
  31. BattleManager::getSingleton().SetSkipVictoryPose(GetInt(node, "skip_victory_pose") == 1);
  32. BattleManager::getSingleton().SetSkipSpoils(GetInt(node, "skip_spoils") == 1);
  33. node = node->FirstChild();
  34. while (node != nullptr){
  35. // Location data.
  36. if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "location"){
  37. int id = GetInt(node, "id");
  38. Ogre::String name(GetString(node, "name"));
  39. BattleManager::getSingleton().SetLocation(id, name);
  40. }
  41. else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "arena"){
  42. bool is_arena = GetInt(node, "is_arena") == 1;
  43. BattleManager::getSingleton().SetArenaBattle(is_arena);
  44. if (is_arena){
  45. // TODO: Read more info for arena battles
  46. }
  47. }
  48. else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "camera"){
  49. BattleManager::getSingleton().SetInitialCamera(GetInt(node, "initial"));
  50. TiXmlNode* camera_node = node->FirstChild();
  51. while (camera_node != nullptr){
  52. int id = GetInt(camera_node, "id");
  53. Ogre::Vector3 pos = Ogre::Vector3(
  54. GetInt(camera_node, "x"), GetInt(camera_node, "y"), GetInt(camera_node, "z")
  55. );
  56. Ogre::Vector3 dir = Ogre::Vector3(
  57. GetInt(camera_node, "direction_x"), GetInt(camera_node, "direction_y"),
  58. GetInt(camera_node, "direction_z")
  59. );
  60. BattleManager::getSingleton().AddCamera(id, pos, dir);
  61. camera_node = camera_node->NextSibling();
  62. }
  63. }
  64. else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "enemies"){
  65. TiXmlNode* enemy_node = node->FirstChild();
  66. while (enemy_node != nullptr){
  67. int id = GetInt(enemy_node, "id");
  68. Ogre::Vector3 pos = Ogre::Vector3(
  69. GetInt(enemy_node, "x"), GetInt(enemy_node, "y"), GetInt(enemy_node, "z")
  70. );
  71. bool front = GetInt(enemy_node, "row") == 1;
  72. bool visible = GetInt(enemy_node, "visible") == 1;
  73. bool targeteable = GetInt(enemy_node, "targeteable") == 1;
  74. bool active = GetInt(enemy_node, "main_script_active") == 1;
  75. std::string cover = GetString(enemy_node, "cover");
  76. BattleManager::getSingleton().AddEnemy(
  77. id, pos, front, visible, targeteable, active, cover
  78. );
  79. enemy_node = enemy_node->NextSibling();
  80. }
  81. }
  82. node = node->NextSibling();
  83. }
  84. }