s2client-api
s2client-api copied to clipboard
shield_max, energy_max, and weapon_cooldown are always zero (for replays)
I am looking a replay as observer (player_id = 0). During onStep() is called, I read the following values of all units:
- health
- health_max
- shield
- shield_max
- energy
- energy_max
- weapon_cooldown
For the replayes I watched the values shield_max, energy_max, and weapon_cooldown are always zero. Although shield and energy are not always zero. Is this a bug related to replays or observers? Can you fix it?
I just tested this and I'm not seeing the same issue.
Could you possibly provide code to reproduce the issue?
Here is a minimal example. Maybe the problem is specific to the replay I used...
#include <sc2api/sc2_api.h>
#include <iostream>
class MyObserver : public sc2::ReplayObserver {
public:
bool firstShield = true;
bool firstEnergy = true;
void OnStep() final {
auto obs = Observation();
for (auto it : obs->GetUnits()) {
if (firstShield && (it->shield > 0) && (it->shield_max == 0)) {
std::cout << obs->GetGameLoop() << ": Found invalid shield values!" << std::endl;
firstShield = false;
}
if (firstEnergy && (it->energy > 0) && (it->energy_max == 0)) {
std::cout << obs->GetGameLoop() << ": Found invalid energy values!" << std::endl;
firstEnergy = false;
}
}
}
bool IgnoreReplay(const sc2::ReplayInfo& replay_info, uint32_t& player_id) final {
player_id = 0;
return false;
}
};
int main(int argc, char* argv[]) {
sc2::Coordinator coordinator;
coordinator.LoadSettings(argc, argv);
const char* kReplayFolder = R"(D:\path\to\replaypack1\0b5f25278d983edbe980a6ea723de75d281b90b21a2ac60286091ffcec9a5fb3.SC2Replay)";
if (!coordinator.SetReplayPath(kReplayFolder)) {
std::cout << "Unable to find replay." << std::endl;
return 1;
}
MyObserver myObserver;
coordinator.AddReplayObserver(&myObserver);
while (coordinator.Update());
return 0;
}
If I compile and run the program, I get the following output:
... 1: Found invalid shield values! 2985: Found invalid energy values!
Thanks for your help. I start to have the bad feeling that the problem is in front of my computer ;)