From 34020a41b8c83c0dc4e512cd24680fcaa3e342d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <davbe125@student.liu.se> Date: Mon, 23 Jul 2018 16:08:18 +0200 Subject: [PATCH] Fill TechTree with data from TechTreeImproved --- python-api-src/lib_tech_tree.cpp | 3 ++- src/TechTree.cpp | 33 ++++++++++++++++++++++++++++++++ src/TechTree.h | 1 + src/main.cpp | 7 ------- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/python-api-src/lib_tech_tree.cpp b/python-api-src/lib_tech_tree.cpp index 9df5b8e70..ff9b2d54f 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 b0c3fad90..d33039f78 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 5385feb98..3fda032b5 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 b66d06650..d8d3c8654 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)) { -- GitLab