Difference between revisions of "VisibilityUnit (OpenXcom)"

From UFOpaedia
Jump to navigation Jump to search
(Corrected category)
m (Memmaker moved page VisibilityUnit OpenXCom to VisibilityUnit (OpenXcom): Naming conventions)
(No difference)

Revision as of 14:31, 24 December 2019

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 distance in voxels between the two units
  • 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: ???

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();

Description

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.