May 17, 2021, 09:31:21 AM

Author Topic: AI and fog of war?  (Read 777 times)

MTops

  • New Member
  • *
  • Posts: 7
    • View Profile
AI and fog of war?
« on: September 16, 2010, 04:09:00 AM »
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

  • New Member
  • *
  • Posts: 7
    • View Profile
Re: AI and fog of war?
« Reply #1 on: September 16, 2010, 09:14:59 AM »
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.