Skip to content
Snippets Groups Projects
Select Git revision
  • a42d1514aa980772151ff595ad816e0548aea09f
  • main default protected
  • leveleditor
  • david-author
  • clang-tidy-cleanup
  • architecture-refactoring
  • cleanUpMenus
  • doxygen-cleanup
  • project-structure-refactoring
  • interpolation
  • buildingFeatures
  • win_end_screen
  • helpMenu
  • leveleditor-placement
  • text-rendering
  • updated_unit_contextmenu
  • level-from-commandline
  • unit_contextmenu
  • player
  • engine-scaling
  • clang-tidy
21 results

config.cpp

Blame
  • config.cpp 7.37 KiB
    #include <boost/property_tree/ptree.hpp>
    #include <boost/property_tree/xml_parser.hpp>
    #include <unordered_map>
    #include <string>
    #include <iostream>
    #include <stdexcept> // Für die Ausnahmebehandlung
    #include "unit.hpp"  // Include für UnitId
    #include "config.hpp"
    namespace pt = boost::property_tree;
    
    namespace advanced_wars
    {
    
        Config::Config(MatchupTabel_secondaryweapon& secWeapon, MatchupTabel_primaryweapon& primWeapon)
            : secondary_weapon_damage(secWeapon), primary_weapon_damage(primWeapon)
        {
            // Initialisierung hier wenn nötig
        }
        void Config::loadFromXML(const char *filename)
        {
            pt::ptree tree;
            pt::read_xml(filename, tree);
    
            for (const auto &unit : tree.get_child("Units"))
            {
                if (unit.first == "Unit")
                {
                    std::string unitKey = unit.second.get<std::string>("<xmlattr>.key");
    
                    UnitId unitId;
                    if (unitKey == "infantry")
                    {
                        unitId = UnitId::INFANTERY;
                    }
                    else if (unitKey == "Mech")
                    {
                        unitId = UnitId::MECHANIZED_INFANTERY;
                    }
                    else
                    {
                        continue; // Überspringt nicht unterstützte Einheiten
                    }
    
                    int cost = unit.second.get<int>("Cost");
                    int movementPoints = unit.second.get<int>("MovementPoints");
                    int ammo = unit.second.get<int>("Ammo");
                    int minRange = unit.second.get<int>("minRange", 0);
                    int maxRange = unit.second.get<int>("maxRange", 0);
    
                    unit_costs[unitId] = cost;
                    unit_movementPoints[unitId] = movementPoints;
                    unit_ammo[unitId] = ammo;
                    unit_minRange[unitId] = minRange;
                    unit_maxRange[unitId] = maxRange;
    
                    for (const auto &weapon : unit.second.get_child("Weapons"))
                    {
                        if (weapon.first == "PrimaryWeapon")
                        {
                            std::string weaponName = weapon.second.get<std::string>("<xmlattr>.name");
                            unit_primaryweapon[unitId] = weaponName;
                        }
                        else if (weapon.first == "SecondaryWeapon")
                        {
                            std::string weaponName = weapon.second.get<std::string>("<xmlattr>.name");
                            unit_secondaryweapon[unitId] = weaponName;
                        }
                    }
    
                    for (const auto &weapon : unit.second.get_child("Weapons"))