Vector
A battle vector is an object representing a 2D or 3D position on the battlefield. Once created, battle vectors can be passed as arguments to certain functions in order to specify movement or attack positions.
In battle vector terminology the x co-ordinate represents east to west on the battlefield, the y co-ordinate represents the height from the ground plane, and the z co-ordinate represents north to south. A 2D vector represents an x/z position, whereas a 3D vector's co-ordinates are stored x/y/z - note that the height component is in the middle. A position of 0, 0, 0 would represent the centre of the battlefield at a height of 0 above the water plane.
All battle co-ordinates and distances are specified in metres.
| Loaded in Battle |
|
-
battle_vector:new([numberx], [numbery], [numberz]) -
Creates a new battle_vector object. Initial co-ordinates may optionally be specified.
Parameters:
1
numberoptional, default value=0
x
2
numberoptional, default value=0
y
3
numberoptional, default value=0
z
Returns:
battle_vectorvector
Example:
my_vector = battle_vector:new(100, 0, 100)
Battle vectors can be added, subtracted, multiplied or divided. An equality test can also be performed between vectors.
Example:
vec_a = battle_vector:new(50, 50)
vec_b = battle_vector:new(100, 100)
vec_c = vec_a + vec_b -- [150, 0, 150]
if vec_a == vec_c then
print("Impossible!")
end
-
battle_vector:get_x() -
Returns the x co-ordinate stored by the vector. This is the east-west position.
Returns:
numberx co-ordinate
-
battle_vector:get_y() -
Returns the y co-ordinate stored by the vector. This is the height of the vector position from the water plane.
Returns:
numbery co-ordinate
-
battle_vector:get_z() -
Returns the z co-ordinate stored by the vector. This is the north-south position.
Returns:
numberz co-ordinate
-
battle_vector:length() -
Returns the distance from the origin [0, 0, 0] to the position of this vector in metres.
Returns:
numberlength
-
battle_vector:length_xz() -
Returns the distance from the origin [0, 0] to the position of this vector in metres, disregarding any height differences.
Returns:
number2D length
-
battle_vector:set(objvector or x, numbery, numberz) -
Sets a new position for the vector. The new position may be specified as a single vector argument or as three numeric co-ordinate arguments.
Parameters:
1
objEither a vector specifying the new position, or a number specifying the new x co-ordinate.
2
numberA number specifying the new y co-ordinate. This is not needed if a vector was supplied as the first argument.
3
numberA number specifying the new z co-ordinate. This is not needed if a vector was supplied as the first argument.
Returns:
nil
Example:
vec_a:set(vec_b)
vec_b:set(100, 0, 100)
-
battle_vector:set_x(numberx) -
Sets a new x co-ordinate for the vector.
Parameters:
1
numberx co-ordinate in metres.
Returns:
nil
Example:
vec_a:set_x(100)
-
battle_vector:set_y(numbery) -
Sets a new y co-ordinate for the vector. This is the height of the position from the water plane.
Parameters:
1
numbery co-ordinate in metres.
Returns:
nil
Example:
vec_a:set_y(35)
-
battle_vector:set_z(numberz) -
Sets a new z co-ordinate for the vector. This is the height of the position from the water plane.
Parameters:
1
numberz co-ordinate in metres.
Returns:
nil
Example:
vec_a:set_z(-400)
-
battle_vector:distance(battle_vectorvector) -
Returns the distance from a supplied vector to the subject vector in metres.
Parameters:
1
battle_vectorvector
Returns:
distancein m
Example:
vec_a = battle_vector:new(0, 100, 0)
vec_b = battle_vector:new(0, 200, 0) -- 100m above vec_a
print(vec_a:distance(vec_b))
100
-
battle_vector:distance_xz(battle_vectorvector) -
Returns the distance from a supplied vector to the subject vector in metres, but disregarding any height difference.
Parameters:
1
battle_vectorvector
Returns:
distancein m
Example:
vec_a = battle_vector:new(0, 100, 0)
vec_b = battle_vector:new(0, 200, 0) -- 100m above vec_a
print(vec_a:distance_xz(vec_b))
0