Table of Contents

Struct GridLocation

Namespace
Uncreated.Warfare.Locations
Assembly
Uncreated.Warfare.dll

Handles translating coordinates to/from grid coordinates.

[JsonConverter(typeof(GridLocationConverter))]
[TypeConverter(typeof(GridLocationTypeConverter))]
public readonly struct GridLocation : ITranslationArgument, IEquatable<GridLocation>, IComparable<GridLocation>, IFormattable
Implements
Inherited Members
Extension Methods

Constructors

GridLocation(byte, byte, byte)

Create a grid location from an X-coordinate, a Y-coordinate, and a subgrid index.

[JsonConstructor]
public GridLocation(byte x, byte y, byte index)

Parameters

x byte
y byte
index byte

Exceptions

ArgumentOutOfRangeException

GridLocation(char, byte, byte)

Create a grid location from an X-coordinate letter, a Y-coordinate, and a subgrid index.

public GridLocation(char x, byte y, byte index)

Parameters

x char
y byte
index byte

Exceptions

ArgumentOutOfRangeException

GridLocation(in Vector3)

Create a GridLocation from any given point inside a grid and subgrid.

public GridLocation(in Vector3 pos)

Parameters

pos Vector3

Exceptions

NotSupportedException

Not ran on an active server.

Fields

BorderPercentage

What percentage of the image is border for the grid?

public const float BorderPercentage = 0.033333335

Field Value

float

OptimalGridSizeWorldScale

The preferred distance between grids in meters. This will be scaled slightly to ensure the grid looks squared.

public const int OptimalGridSizeWorldScale = 150

Field Value

int

SubgridAmount

Square root of the amount of subgrids in a grid. Ex. in a 3x3 = 9 subgrid, this value will be 3.

public const int SubgridAmount = 3

Field Value

int

Remarks

Must be within the interval [1, 9].

Properties

Center

The center of the referenced grid or sub-grid.

[JsonIgnore]
[JsonIgnore]
public Vector2 Center { get; }

Property Value

Vector2

Exceptions

NotSupportedException

Not ran on an active server.

Index

The sub-grid index of in the current grid.

[JsonPropertyName("index")]
[JsonProperty("index")]
public byte Index { get; }

Property Value

byte

IsChecked

Was this grid location verified to be a valid location? This will always be true unless the GridLocation hasn't been initialized by a constructor.

[JsonIgnore]
[JsonIgnore]
public bool IsChecked { get; }

Property Value

bool

IsValid

Is this a valid GridLocation? This will always be true unless the GridLocation hasn't been initialized by a constructor.

[JsonIgnore]
[JsonIgnore]
public bool IsValid { get; }

Property Value

bool

LetterX

The captialized letter of the current X coordinate of the grid.

[JsonIgnore]
[JsonIgnore]
public char LetterX { get; }

Property Value

char

X

The X coordinate of the grid.

[JsonPropertyName("x")]
[JsonProperty("x")]
public byte X { get; }

Property Value

byte

Y

The Y coordinate of the grid.

[JsonPropertyName("y")]
[JsonProperty("y")]
public byte Y { get; }

Property Value

byte

Methods

CompareTo(GridLocation)

Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.

public int CompareTo(GridLocation other)

Parameters

other GridLocation

Returns

int

Equals(object?)

Check if two locations are in the same grid and sub-grid.

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

Equals(GridLocation)

Check if two locations are in the same grid and sub-grid.

public bool Equals(GridLocation other)

Parameters

other GridLocation

Returns

bool

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

GetLegacyBorderSize(ELevelSize)

Get the size of the map's border based on a legacy size.

public static int GetLegacyBorderSize(ELevelSize size)

Parameters

size ELevelSize

Returns

int

GetLegacyGridSize(ELevelSize)

Get the ideal grid size from a legacy size.

public static int GetLegacyGridSize(ELevelSize size)

Parameters

size ELevelSize

Returns

int

GetLegacyMapSize(ELevelSize)

Get the size of the map's image (and total size) based on a legacy size.

public static int GetLegacyMapSize(ELevelSize size)

Parameters

size ELevelSize

Returns

int

GetLegacySizeFromMapSize(int)

Get the expected legacy size from a map's image size (or total size), or null if it doesn't match any legacy sizes.

public static ELevelSize? GetLegacySizeFromMapSize(int mapSize)

Parameters

mapSize int

Returns

ELevelSize?

GetMapMetrics(ELevelSize, out int, out double, out double)

Only works with maps without a cartography volume.

public static void GetMapMetrics(ELevelSize size, out int gridSize, out double sectionWidth, out double borderSize)

Parameters

size ELevelSize
gridSize int
sectionWidth double

world scale

borderSize double

world scale

GetMapMetrics(int, int, out int, out int, out double, out double, out double)

Only works with maps with a cartography volume.

public static void GetMapMetrics(int imgSizeX, int imgSizeY, out int gridSizeX, out int gridSizeY, out double sectionWidthX, out double sectionWidthY, out double borderSize)

Parameters

imgSizeX int
imgSizeY int
gridSizeX int
gridSizeY int
sectionWidthX double
sectionWidthY double
borderSize double

Remarks

Used by grid generator in Discord bot.

GridEquals(GridLocation)

Check if two locations are in the same grid.

public bool GridEquals(GridLocation other)

Parameters

other GridLocation

Returns

bool

Parse(ReadOnlySpan<char>)

Parse a case-insensitive string representing a GridLocation, ignoring whitespace.

public static GridLocation Parse(ReadOnlySpan<char> value)

Parameters

value ReadOnlySpan<char>

Returns

GridLocation

Exceptions

FormatException

Parse(ReadOnlySpan<char>, IFormatProvider?)

Parse a case-insensitive string representing a GridLocation, ignoring whitespace.

[Obsolete]
public static GridLocation Parse(ReadOnlySpan<char> s, IFormatProvider? provider)

Parameters

s ReadOnlySpan<char>
provider IFormatProvider

Returns

GridLocation

Exceptions

FormatException

Parse(string, IFormatProvider?)

Parse a case-insensitive string representing a GridLocation, ignoring whitespace.

[Obsolete]
public static GridLocation Parse(string s, IFormatProvider? provider)

Parameters

s string
provider IFormatProvider

Returns

GridLocation

Exceptions

FormatException

ReadLocation(ByteReader)

Read a location from a DanielWillett.SpeedBytes.ByteReader.

public static GridLocation ReadLocation(ByteReader reader)

Parameters

reader ByteReader

Returns

GridLocation

ToString()

Convert this grid location to a string representation, formatted like A1-1.

public override string ToString()

Returns

string

ToString(byte, byte, byte)

Convert a grid location with the given x, y, and index to a string representation, formatted like A1-1.

public static string ToString(byte x, byte y, byte index)

Parameters

x byte
y byte
index byte

Returns

string

ToString(string?, IFormatProvider?)

Formats the value of the current instance using the specified format.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format to use.
-or-
A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

formatProvider IFormatProvider

The provider to use to format the value.
-or-
A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns

string

The value of the current instance in the specified format.

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Convert this grid location to a string representation, formatted like A1-1.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

destination Span<char>
charsWritten int
format ReadOnlySpan<char>
provider IFormatProvider

Returns

bool

TryParse(ReadOnlySpan<char>, IFormatProvider?, out GridLocation)

Parse a case-insensitive string representing a GridLocation, ignoring whitespace.

[Obsolete]
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out GridLocation result)

Parameters

s ReadOnlySpan<char>
provider IFormatProvider
result GridLocation

Returns

bool

True if a valid GridLocation was parsed, otherwise false.

TryParse(ReadOnlySpan<char>, out GridLocation)

Parse a case-insensitive string representing a GridLocation, ignoring whitespace.

public static bool TryParse(ReadOnlySpan<char> value, out GridLocation location)

Parameters

value ReadOnlySpan<char>
location GridLocation

Returns

bool

True if a valid GridLocation was parsed, otherwise false.

TryParse(string?, IFormatProvider?, out GridLocation)

Parse a case-insensitive string representing a GridLocation, ignoring whitespace.

[Obsolete]
public static bool TryParse(string? s, IFormatProvider? provider, out GridLocation result)

Parameters

s string
provider IFormatProvider
result GridLocation

Returns

bool

True if a valid GridLocation was parsed, otherwise false.

Write(ByteWriter)

Write this location to a DanielWillett.SpeedBytes.ByteWriter.

public void Write(ByteWriter writer)

Parameters

writer ByteWriter

WriteLocation(ByteWriter, GridLocation)

Write a location to a DanielWillett.SpeedBytes.ByteWriter.

public static void WriteLocation(ByteWriter writer, GridLocation gridLocation)

Parameters

writer ByteWriter
gridLocation GridLocation

Operators

operator ==(GridLocation, GridLocation)

Check if two locations are in the same grid and sub-grid.

public static bool operator ==(GridLocation left, GridLocation right)

Parameters

left GridLocation
right GridLocation

Returns

bool

operator >(GridLocation, GridLocation)

Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.

public static bool operator >(GridLocation left, GridLocation right)

Parameters

left GridLocation
right GridLocation

Returns

bool

operator >=(GridLocation, GridLocation)

Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.

public static bool operator >=(GridLocation left, GridLocation right)

Parameters

left GridLocation
right GridLocation

Returns

bool

operator !=(GridLocation, GridLocation)

Check if two locations are in the same grid and sub-grid.

public static bool operator !=(GridLocation left, GridLocation right)

Parameters

left GridLocation
right GridLocation

Returns

bool

operator <(GridLocation, GridLocation)

Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.

public static bool operator <(GridLocation left, GridLocation right)

Parameters

left GridLocation
right GridLocation

Returns

bool

operator <=(GridLocation, GridLocation)

Compare two locations to each other. Sorted from most significant to least significant: IsChecked, X, Y, Index.

public static bool operator <=(GridLocation left, GridLocation right)

Parameters

left GridLocation
right GridLocation

Returns

bool