Example Code: Convert Position To Map Grid: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
= Problem =
= Problem =


How to get map's grid from object's position. For example get "Fe 26" from [10987.8, 15092.8, 0.0017395].
How to get map's grid from object's position? For example: how to get "Fe 26" from [10987.8, 15092.8, 0.0017395].


= Solution =
= Solution =


nothing at this time.
Simgle small grid has size of 200*200. Moreover position [0,0,0] is somewhere in the middle of second big grid on Y axis. Fractions of coordinates and Z axis are also useless. So at the begining we need to adjuct our position.
 
<pre>_this = [floor ((_this select 0) / 200), floor (((_this select 1) + 520) / 200)]</pre>
 
The result is id of X and Y grids.
 
* Getting X axis grid
 
Notice that for marking X grids engine uses letters from A to J (ten symbols). So to get string id from numeric id we can simply exchange 0 on A, 1 on B etc.
 
<pre>?_t == 0: _str = _str + "A"
?_t == 1: _str = _str + "B"
?_t == 2: _str = _str + "C"
?_t == 3: _str = _str + "D"
?_t == 4: _str = _str + "E"
?_t == 5: _str = _str + "F"
?_t == 6: _str = _str + "G"
?_t == 7: _str = _str + "H"
?_t == 8: _str = _str + "I"
?_t == 9: _str = _str + "J"</pre>
 
First number is exact division of X grid id by ten:
 
<pre>_t = floor ((this select 0) / 10)</pre>
 
Second number is then remainder of the division of X grid id by ten
 
<pre>_t = (this select 0) mod 10</pre>
 
* Getting Y axis grind
 
Notice that the begining of coordinate system is in SE corner of map but counting Y grid begins from NE corner. So proper Y grid is substraction beetwen grinds count (100) and actual grid id.
 
<pre>_y = 100 - (_this select 1)</pre>


= Implementations =
= Implementations =
Line 13: Line 46:
Arguments: [[Position]]
Arguments: [[Position]]


<pre>_str = ""
<pre>_this = [floor ((_this select 0) / 200), floor (((_this select 1) - 280) / 200)]
 
_str = str _this + "\n"


;OX
;OX
_x = floor ((_this select 0) / 200)
_x = _this select 0
_t = floor (_x / 10)
_t = floor (_x / 10)
?_t == 0: _str = _str + "A"
?_t == 0: _str = _str + "A"
Line 43: Line 78:


;OY
;OY
_str = _str + str (104 - floor (((_this select 1) + 520) / 200))
_str = _str + str (100 - (_this select 1))


Hint _str</pre>
Hint _str</pre>

Revision as of 15:01, 23 September 2007

Problem

How to get map's grid from object's position? For example: how to get "Fe 26" from [10987.8, 15092.8, 0.0017395].

Solution

Simgle small grid has size of 200*200. Moreover position [0,0,0] is somewhere in the middle of second big grid on Y axis. Fractions of coordinates and Z axis are also useless. So at the begining we need to adjuct our position.

_this = [floor ((_this select 0) / 200), floor (((_this select 1) + 520) / 200)]

The result is id of X and Y grids.

  • Getting X axis grid

Notice that for marking X grids engine uses letters from A to J (ten symbols). So to get string id from numeric id we can simply exchange 0 on A, 1 on B etc.

?_t == 0: _str = _str + "A"
?_t == 1: _str = _str + "B"
?_t == 2: _str = _str + "C"
?_t == 3: _str = _str + "D"
?_t == 4: _str = _str + "E"
?_t == 5: _str = _str + "F"
?_t == 6: _str = _str + "G"
?_t == 7: _str = _str + "H"
?_t == 8: _str = _str + "I"
?_t == 9: _str = _str + "J"

First number is exact division of X grid id by ten:

_t = floor ((this select 0) / 10)

Second number is then remainder of the division of X grid id by ten

_t = (this select 0) mod 10
  • Getting Y axis grind

Notice that the begining of coordinate system is in SE corner of map but counting Y grid begins from NE corner. So proper Y grid is substraction beetwen grinds count (100) and actual grid id.

_y = 100 - (_this select 1)

Implementations

  • SQS Script

Arguments: Position

_this = [floor ((_this select 0) / 200), floor (((_this select 1) - 280) / 200)]

_str = str _this + "\n"

;OX
_x = _this select 0
_t = floor (_x / 10)
?_t == 0: _str = _str + "A"
?_t == 1: _str = _str + "B"
?_t == 2: _str = _str + "C"
?_t == 3: _str = _str + "D"
?_t == 4: _str = _str + "E"
?_t == 5: _str = _str + "F"
?_t == 6: _str = _str + "G"
?_t == 7: _str = _str + "H"
?_t == 8: _str = _str + "I"
?_t == 9: _str = _str + "J"
_t = _x mod 10
?_t == 0: _str = _str + "a"
?_t == 1: _str = _str + "b"
?_t == 2: _str = _str + "c"
?_t == 3: _str = _str + "d"
?_t == 4: _str = _str + "e"
?_t == 5: _str = _str + "f"
?_t == 6: _str = _str + "g"
?_t == 7: _str = _str + "h"
?_t == 8: _str = _str + "i"
?_t == 9: _str = _str + "j"

_str = _str + " "

;OY
_str = _str + str (100 - (_this select 1))

Hint _str