Blizzard / s2client-api

StarCraft II Client - C++ library supported on Windows, Linux and Mac designed for building scripted bots and research using the SC2API.
MIT License
1.66k stars 281 forks source link

build_time is zero #264

Open ArtaSeify opened 6 years ago

ArtaSeify commented 6 years ago

The build_time attribute of sc2::UnitTypes and sc2::Upgrades always returns 0. How do I go about getting the build_time for each unit/upgrade?

Archiatrus commented 6 years ago

Using auto test = bot->Observation()->GetUnitTypeData()[sc2::UnitTypeID(sc2::UNIT_TYPEID::TERRAN_SCV)]; auto test2 = bot->Observation()->GetUpgradeData()[sc2::UpgradeID(sc2::UPGRADE_ID::STIMPACK)]; gives me scv

ArtaSeify commented 6 years ago

This is the code that I have inside of OnGameStart() of Replay : ReplayObserver

unit_types = Observation()->GetUnitTypeData();

for (int i = 0; i < unit_types.size(); i++) {
    std::cout << unit_types[i].build_time << std::endl;
}

And it returns a build_time of 0 for every index. I tried with several other attributes. Name, mineral_cost, vespene_cost work, but all of the float attributes are returning 0.

alkurbatov commented 6 years ago

Hi, @ArtaSeify I think you are using it in a wrong way. Please take a look at the example provided by @Archiatrus and which value is used as index.

ArtaSeify commented 6 years ago

@alkurbatov I also tried the following code:

    void OnGameStart() final {
        std::cout << Observation()->GetUnitTypeData()[sc2::UnitTypeID(sc2::UNIT_TYPEID::TERRAN_SCV)].build_time << std::endl;
        std::cout << Observation()->GetUpgradeData()[sc2::UpgradeID(sc2::UPGRADE_ID::STIMPACK)].research_time << std::endl;

And it returns 0. I'm not sure what it is that I'm doing wrong.

Archiatrus commented 6 years ago

I used your code and get several non-zero returns. I double checked it also with a replay observer and not agent.

Can you try Observation()->GetUnitTypeData(true)[sc2::UnitTypeID(sc2::UNIT_TYPEID::TERRAN_SCV)].build_time?

What map are you using?

ArtaSeify commented 6 years ago

@Archiatrus It is still returning 0. I am using the replay pack 2 provided by Blizzard, so all of them. It doesn't work for any of them. Does this data come from a JSON file somewhere? Or is it hard coded into the game engine? I'm thinking maybe I am missing a file or something.

Archiatrus commented 6 years ago

I don't know where it is saved and I have no idea why it should not work for you. Are you on windows? Have you tried an up-to-date replay? Just play a one minute game vs AI or download a new pack with this.

Another option or rather a work around might be the hint you can find here under "Other resources":

You can export all balance data from all three expansions as XML. Galaxy Editor --> File > Export Balance Data.

alkurbatov commented 6 years ago

Probably you use old replays and this is backward compatibility issue?

ArtaSeify commented 6 years ago

After trying it on a newer replay, the data all seems to be there. This is very confusing. @alkurbatov @Archiatrus does it work for you with a 3.16.1 replay?

alkurbatov commented 6 years ago

I believe Blizzard changed something in the protocol thus such issue is possible and most likely can be workaround only (e.g. by exposing build times to a file). I've heard about a similar problem regarding MMR values in the replays.