AI and fog of war?

Started by MTops, September 16, 2010, 03:09:00 AM

Previous topic - Next topic

MTops

I am working on my AI being as smart as possible regarding enemy unit/building positions without using a scouting cheat. However, this is made extremely difficult because of the lack of functions that obey the fog of war. As far as I know.

The only function I have discovered that obeys the fog of war is AIKnownUnitCount, which returns an amount the AI thinks a player has based on what he has scouted.

But when I want to know the static defense status of the enemy to decide which expansion to harass, knowing how many there are is not enough, I need to know WHERE they are.

I haven't been able to find another function that could help with this in any way. AIFindUnits doesn't obey the fog of war, it simply returns the current situation. So I am currently forced to manually scan and store information about static defenses which means a huge performance hit.

Has anyone found a better method?

MTops

Hah, did some extensive digging and found something that will help:

bool libNtve_gf_UnitIsVisibleToPlayer (unit lp_unit, int lp_player) {
    // Implementation
    return UnitFilterMatch(lp_unit, lp_player, UnitFilter((1 << c_targetFilterVisible), 0, 0, 0));
}

This function exists in NativeLib.galaxy. Apparently the UnitFilter tag "Visible" is based on the fog of war.

So now I can tell which building has been "spotted" without having to check the sight range of every unit the AI controls.