Class CityNavigation
Utility class to help with mobile spawning and navigation in town environments. The navigation component is intended to be used by wandering NPCs. Mobile enemies will use normal steering behaviour to follow player. Combines inverse of automap to carve out navgrid then sets weighting by tile type.
Namespace: DaggerfallWorkshop.Game.Utility
Assembly: Assembly-CSharp.dll
Syntax
[RequireComponent(typeof(DaggerfallLocation))]
public class CityNavigation : MonoBehaviour
Fields
| Improve this Doc View SourceDaggerfallUnitsPerTile
Declaration
public const int DaggerfallUnitsPerTile = 64
Field Value
| Type | Description |
|---|---|
| Int32 |
HalfTile
Declaration
public const float HalfTile = 0.8F
Field Value
| Type | Description |
|---|---|
| Single |
Properties
| Improve this Doc View SourceCityHeight
Gets RMB height of city from format time.
Declaration
public int CityHeight { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
CityWidth
Gets RMB width of city from format time.
Declaration
public int CityWidth { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
LocationName
Gets location name of this navgrid.
Declaration
public string LocationName { get; }
Property Value
| Type | Description |
|---|---|
| String |
NavGridHeight
Gets navgrid height in tiles.
Declaration
public int NavGridHeight { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
NavGridWidth
Gets navgrid width in tiles.
Declaration
public int NavGridWidth { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
RegionName
Gets region name of this navgrid.
Declaration
public string RegionName { get; }
Property Value
| Type | Description |
|---|---|
| String |
Methods
| Improve this Doc View SourceClearFlags(DFPosition, CityNavigation.TileFlags)
Clear navgrid tile flags. Does nothing if outside navgrid area.
Declaration
public void ClearFlags(DFPosition localPosition, CityNavigation.TileFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | localPosition | Local navgrid position. |
| CityNavigation.TileFlags | flags | Flags to unset. |
ClearFlags(Int32, Int32, CityNavigation.TileFlags)
Clears navgrid tile flags. Does nothing if outside navgrid area.
Declaration
public void ClearFlags(int x, int y, CityNavigation.TileFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | x | X position inside navgrid. |
| Int32 | y | Y position inside navgrid. |
| CityNavigation.TileFlags | flags | Flags to unset. |
FormatNavigation(String, String, Int32, Int32)
Format the navigation grid based on town width*height in RMB blocks. A max-size city like Daggerfall is 8x8 RMB blocks.
Declaration
public void FormatNavigation(string regionName, string locationName, int cityWidth, int cityHeight)
Parameters
| Type | Name | Description |
|---|---|---|
| String | regionName | |
| String | locationName | |
| Int32 | cityWidth | City RMB blocks wide. Range 1-8. |
| Int32 | cityHeight | City RMB blocks high. Range 1-8. |
GetNavGridUV(DFPosition)
Gets UV coordinates of world position inside navgrid.
Declaration
public Vector2 GetNavGridUV(DFPosition worldPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | worldPosition | World coordinates to test. |
Returns
| Type | Description |
|---|---|
| Vector2 | UV coordinates inside navgrid - will be clamped to 0-1 range. |
GetNavGridWeightLocal(DFPosition)
Gets weight of tile at local DFPosition inside navgrid array. Safe to query outside navgrid area, will just return 0.
Declaration
public int GetNavGridWeightLocal(DFPosition localPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | localPosition | Local navgrid position. |
Returns
| Type | Description |
|---|---|
| Int32 | Weight of position or 0. |
GetNavGridWeightLocal(Int32, Int32)
Gets weight of tile at local X, Y position inside navgrid array. Safe to query outside navgrid area, will just return 0.
Declaration
public int GetNavGridWeightLocal(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | x | X position inside navgrid. |
| Int32 | y | Y position inside navgrid. |
Returns
| Type | Description |
|---|---|
| Int32 | Weight of position or 0. |
GetNavGridWeightWorld(DFPosition)
Gets weight of tile at world position inside navgrid.
Declaration
public int GetNavGridWeightWorld(DFPosition worldPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | worldPosition | World position to test. |
Returns
| Type | Description |
|---|---|
| Int32 | Weight of tile inside navgrid - will be clamped to valid range. |
GetRandomSpawnPosition(DFPosition, out DFPosition, Int32, Int32)
Gets a random navgrid spawn point up to radius tiles around origin.
Declaration
public bool GetRandomSpawnPosition(DFPosition origin, out DFPosition positionOut, int radius = 64, int maxAttempts = 10)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | origin | Origin point for spawn. Will be clamped inside navgrid area. |
| DFPosition | positionOut | Found position. Will be -1,-1 if no position found. |
| Int32 | radius | Radius of spawn range around origin. |
| Int32 | maxAttempts | Maximum attempts to find a valid random spawn point. |
Returns
| Type | Description |
|---|---|
| Boolean | True if position found. |
GetRawNavGridValueLocal(DFPosition)
Gets raw unclamped tile value at navgrid position. Position must be inside valid range or will throw exception.
Declaration
public int GetRawNavGridValueLocal(DFPosition localPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | localPosition | Local navgrid position. |
Returns
| Type | Description |
|---|---|
| Int32 | Raw value from navgrid array. |
HasFlags(DFPosition, CityNavigation.TileFlags)
Checks navgrid tile flags. Returns false is outside navgrid area.
Declaration
public bool HasFlags(DFPosition localPosition, CityNavigation.TileFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | localPosition | Local navgrid position. |
| CityNavigation.TileFlags | flags | Flags to check. |
Returns
| Type | Description |
|---|---|
| Boolean | True if flags set, otherwise false. |
HasFlags(Int32, Int32, CityNavigation.TileFlags)
Checks navgrid tile flags. Returns false is outside navgrid area.
Declaration
public bool HasFlags(int x, int y, CityNavigation.TileFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | x | X position inside navgrid. |
| Int32 | y | Y position inside navgrid. |
| CityNavigation.TileFlags | flags |
Returns
| Type | Description |
|---|---|
| Boolean | True if flags set, otherwise false. |
NavGridToWorldPosition(DFPosition)
Convert local navgrid position into a world position. Precision loss expected converting between world and navgrid.
Declaration
public DFPosition NavGridToWorldPosition(DFPosition localPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | localPosition | Local position inside navgrid. |
Returns
| Type | Description |
|---|---|
| DFPosition | World DFPosition. |
SaveTestRawImage(String)
Save navgrid as a raw image.
Declaration
public void SaveTestRawImage(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| String | path |
SceneToWorldPosition(Vector3)
Convert a scene position back into virtual world space. This is specific to the peered location due to floating origin.
Declaration
public DFPosition SceneToWorldPosition(Vector3 scenePosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | scenePosition | Scene position to convert to nearest point in world space. |
Returns
| Type | Description |
|---|---|
| DFPosition | World DFPosition. |
SetFlags(DFPosition, CityNavigation.TileFlags)
Sets navgrid tile flags. Does nothing if outside navgrid area.
Declaration
public void SetFlags(DFPosition localPosition, CityNavigation.TileFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | localPosition | Local navgrid position. |
| CityNavigation.TileFlags | flags | Flags to set. |
SetFlags(Int32, Int32, CityNavigation.TileFlags)
Sets navgrid tile flags. Does nothing if outside navgrid area.
Declaration
public void SetFlags(int x, int y, CityNavigation.TileFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | x | X position inside navgrid. |
| Int32 | y | Y position inside navgrid. |
| CityNavigation.TileFlags | flags | Flags to set. |
SetRMBData(in DFBlock, Int32, Int32)
Set block data in navgrid. This is done during StreamingWorld location layout when this data is available.
Declaration
public void SetRMBData(in DFBlock blockData, int xBlock, int yBlock)
Parameters
| Type | Name | Description |
|---|---|---|
| DFBlock | blockData | RMB block data. |
| Int32 | xBlock | X block to set. |
| Int32 | yBlock | Y block to set. |
WorldToNavGridPosition(DFPosition)
Convert world position to local navgrid position. Precision loss expected converting between world and navgrid.
Declaration
public DFPosition WorldToNavGridPosition(DFPosition worldPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | worldPosition | World position - will be clamped inside location area. |
Returns
| Type | Description |
|---|---|
| DFPosition | Local navgrid DFPosition. |
WorldToScenePosition(DFPosition, Boolean)
Convert a virtual world position back into scene space. This is specific to the peered location due to floating origin. Some precision loss is expected converting back to scene space.
Declaration
public Vector3 WorldToScenePosition(DFPosition worldPosition, bool refineY = true)
Parameters
| Type | Name | Description |
|---|---|---|
| DFPosition | worldPosition | World location to convert to nearest point in scene space. |
| Boolean | refineY | Attempt to refine Y position to actual terrain data. |
Returns
| Type | Description |
|---|---|
| Vector3 | Scene Vector3 position. |