VisibilityUnit (OpenXcom)

From UFOpaedia
Revision as of 20:55, 17 January 2020 by Yankes (talk | contribs) (Add some more info)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Script attached to Armor of the observing unit

Important pre-set local variables of the script hook:

  • observer_unit: The unit currently looking around.
  • target_unit: The unit that could potentially be spotted. If you return a value greater than zero, then this unit has been seen by observer_unit.
  • current_visibility / default_visibility (currently always the same value): The currently pre-calculated visibility. For a no-operation script hook you can just return this value and get vanilla behaviour.
  • distance: The adjusted visible distance of the observer_unit. Takes into account smoke.
  • distance_max: The maximum viewing distance of observer_unit in the current environment lighting
  • fire_density: Cumulative fire density in the line of sight over all the voxels.
  • smoke_density: Cumulative smoke density in the line of sight over all the voxels. A grenade has a smoke density of around 15 per tile.
  • visibility_mode aka BattleUnitVisibility.Tag: Helper tags for script to implement different visibility modes, e.g. camouflage script should affect only normal visibility not infra-red or some other exotic versions.

Script return values:

  1. current_visibility: integer
  2. visibility_mode aka BattleUnitVisibility.Tag: integer

Source Code script call:

ModScript::VisibilityUnit::Output arg{ visibilityQuality, visibilityQuality, ScriptTag<BattleUnitVisibility>::getNullTag() };
ModScript::VisibilityUnit::Worker worker{ currentUnit, tile->getUnit(), visibleDistanceVoxels, visibleDistanceMaxVoxel, densityOfSmoke * smokeDensityFactor / 100, densityOfFire };

Source Code usage of return values:

unitSeen = 0 < arg.getFirst();


Gets called to check if one unit from one faction can see another unit from another faction. Won’t get called for units in the same faction because they can always see each other.

Currently (2019-12-24) only the first return value is used by the engine and only in a boolean check.

If the first return value (current_visibility) is greater than zero (> 0) then the observer unit has seen the target_unit. This hook can be used to alter the visibility of a battle unit on the fly. You can take into account the given information and decide for yourself if the unit has been spotted or not.