diff --git a/python-api-src/lib_tech_tree.cpp b/python-api-src/lib_tech_tree.cpp index 9df5b8e700b4a95f8f23a4f4362d88b6f1aa3c55..ff9b2d54fd36ce2adbb9a9be065fedb4a0242db0 100644 --- a/python-api-src/lib_tech_tree.cpp +++ b/python-api-src/lib_tech_tree.cpp @@ -21,7 +21,8 @@ void define_tech_tree(py::module & m) .def_readonly("warp_ability", &TypeData::warpAbility, "the ability that creates this item via warp-in") .def_readonly("what_builds", &TypeData::whatBuilds, "any of these units can build the item") .def_readonly("required_units", &TypeData::requiredUnits, "owning ONE of these is required to make") - .def_readonly("required_upgrades", &TypeData::requiredUpgrades, "having ALL of these is required to make"); + .def_readonly("required_upgrades", &TypeData::requiredUpgrades, "having ALL of these is required to make") + .def_readonly("required_addons", &TypeData::requiredAddons, "a unit of this type must be present next to the producer"); py::class_<TechTree>(m, "TechTree") .def("get_data", py::overload_cast<const UnitType &>(&TechTree::getData, py::const_)) diff --git a/src/TechTree.cpp b/src/TechTree.cpp index b0c3fad904775258380fa8652dd701f35aff03c4..d33039f7870d6a5f81cfca68b64238dad091a08d 100644 --- a/src/TechTree.cpp +++ b/src/TechTree.cpp @@ -12,6 +12,39 @@ void TechTree::onStart() { initUnitTypeData(); initUpgradeData(); + + /* As it turns out, some of the hard-coded values are wrong. Instead of + going through each and checking, we fix them with information from a + (hopefully) up to date JSON-file. Sorry in advance, this was the best + solution at the time. Hopefully the JSON-files are still up to date. */ + + TechTreeImproved tree; + tree.LoadData(); + + for (std::pair<const UnitType, TypeData> & pair : m_unitTypeData) + { + TypeData & data = pair.second; + + data.whatBuilds.clear(); + data.requiredUnits.clear(); + // TODO: Support for upgrades, is it possible via JSON? Is the hard coded information correct? + data.requiredUpgrades.clear(); + + const std::vector<BuildDescription> & howToBuild = tree.HowToBuild(pair.first.getAPIUnitType()); + + for (const BuildDescription & description : howToBuild) + { + data.whatBuilds.push_back(UnitType(description.producer_type, m_bot)); + for (sc2::UNIT_TYPEID unit_typeid : description.buildings_needed) + { + data.requiredUnits.push_back(UnitType(unit_typeid, m_bot)); + } + for (sc2::UNIT_TYPEID unit_typeid : description.addons_needed) + { + data.requiredAddons.push_back(UnitType(unit_typeid, m_bot)); + } + } + } } diff --git a/src/TechTree.h b/src/TechTree.h index 5385feb98114809ae09eb1da1cf12833b25bd243..3fda032b524ab44ed33ed9410d48d7546837ce4d 100644 --- a/src/TechTree.h +++ b/src/TechTree.h @@ -25,6 +25,7 @@ struct TypeData std::vector<UnitType> whatBuilds; // any of these units can build the item std::vector<UnitType> requiredUnits; // owning ONE of these is required to make std::vector<CCUpgrade> requiredUpgrades; // having ALL of these is required to make + std::vector<UnitType> requiredAddons; // a unit of this type must be present next to the producer }; class TechTree diff --git a/src/main.cpp b/src/main.cpp index b66d066502181fb8a0e0474d5c89a1a176477e48..d8d3c8654cbd607097c2d9062a5b8330522eca1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,13 +9,6 @@ int main(int argc, char* argv[]) { - TechTreeImproved tree; - tree.LoadData(); - - std::vector<BuildDescription> alts = tree.HowToBuild(sc2::UNIT_TYPEID::TERRAN_GHOST); - - return 0; - sc2::Coordinator coordinator; if (!coordinator.LoadSettings(argc, argv)) {