in rts/engine/rule_actor.cc [18:90]
void Preload::collect_stats(const GameEnv &env, int player_id, const CmdReceiver &receiver) {
// Clear all data
//
_my_troops.clear();
_enemy_troops.clear();
_enemy_troops_in_range.clear();
_all_my_troops.clear();
_enemy_attacking_economy.clear();
_economy_being_attacked.clear();
_cnt_under_construction.clear();
_num_unit_type = env.GetGameDef().GetNumUnitType();
// Initialize to a given size.
_my_troops.resize(_num_unit_type);
_enemy_troops.resize(_num_unit_type);
_cnt_under_construction.resize(_num_unit_type, 0);
_prices.resize(_num_unit_type, 0);
_result = NOT_READY;
_player_id = player_id;
// Collect ...
const Units& units = env.GetUnits();
//const RTSMap& m = env.GetMap();
const Player& player = env.GetPlayer(_player_id);
// cout << "Looping over units" << endl << flush;
// Get the information of all other troops.
for (auto it = units.begin(); it != units.end(); ++it) {
const Unit *u = it->second.get();
if (u == nullptr) cout << "Unit cannot be nullptr" << endl << flush;
// cout << "unit: " << u->GetProperty().PrintInfo() << endl << flush;
auto &troops = (u->GetPlayerId() == _player_id ? _my_troops : _enemy_troops);
troops[u->GetUnitType()].push_back(u);
if (u->GetPlayerId() == _player_id) {
if (InCmd(receiver, *u, BUILD)) {
const CmdDurative *curr_cmd = receiver.GetUnitDurativeCmd(u->GetId());
if (curr_cmd == nullptr) cout << "Cmd cannot be null! id = " << u->GetId() << endl << flush;
const CmdBuild *curr_cmd_build = dynamic_cast<const CmdBuild *>(curr_cmd);
if (curr_cmd_build == nullptr) cout << "Current cmd cannot be converted to CmdBuild!" << endl << flush;
UnitType ut = curr_cmd_build->build_type();
// if ((int)ut < 0 || (int)ut >= (int)NUM_UNITTYPE) cout << "buidl unit_type is invalid! " << (int)ut << endl << flush;
_cnt_under_construction[ut] ++;
}
_all_my_troops.push_back(u);
// Check damage from
UnitType unit_type = u->GetUnitType();
if (unit_type == WORKER || unit_type == BASE) {
UnitId damage_from = u->GetProperty().GetLastDamageFrom();
if (damage_from != INVALID) {
const Unit *source = env.GetUnit(damage_from);
if (source != nullptr) {
_enemy_attacking_economy.push_back(source);
_economy_being_attacked.push_back(u);
}
}
}
} else {
if (player.FilterWithFOW(*u)) {
// Attack if we have troops.
if (u->GetUnitType() != RESOURCE) {
_enemy_troops_in_range.push_back(u);
}
}
}
}
make_unique(&_enemy_attacking_economy);
make_unique(&_economy_being_attacked);
}