Map Coordinates
From OPU Wiki
Outpost 2 uses an odd coordinate system in the code. This means that location (0,0) on the map is not (0,0) in code.
To convert real cords (in game) to code cords, take the real cords, and:
- Add 31 to the X coordinate
- Subtract 1 from the Y coordinate
You can do this directly in the code, however starting with the mission SDK version 2, there are macros that can automatically convert cords for LOCATIONs, MAP_RECTs, and functions where the x and y values are specified as inline parameters, making it much easier to look at locations.
Coordinate Conversion Macros
Inside OP2Helper.h there are four macros defined:
#define MkXY(x,y) (LOCATION((x)+31,(y)-1)) #define MkRect(x1,y1,x2,y2) (MAP_RECT(LOCATION((x1)+31,(y1)-1),LOCATION((x2)+31,(y2)-1))) #define XYPos(x,y) (x)+31,(y)-1 #define RectPos(x1,y1,x2,y2) (x1)+31,(y1)-1,(x2)+31,(y2)-1
In calls that require a single LOCATION or MAP_RECT var, such as TethysGame::CreateUnit() and FightGroup.SetRect(), use the MkXY() and MkRect() macros to define your cords.
For example LOCATION(31,-1) can become MkXY(0,0).
In calls that require x and y coordinates in line, as separate params, such as TethysGame::CreateBeacon, use the XYPos() and RectPos() macros.
So TethysGame::CreateBeacon(mapMiningBeacon, 31, -1, ...
becomes TethysGame::CreateBeacon(mapMiningBeacon, XYPos(0,0), ... (two parameters become one with the XYPos, 4 become one with RectPos)
Why?
I believe the reason for the coordinate offsets is because there is some padding along the left, right, and top edges of the map. (This is how the AI can "enter" the map, instead of just appearing in the visible part). In any case the bottom of the map isn't usable because it's all impassable (and must stay that way, to prevent crashes when a unit travels into that area).
Hopefully this helps with mission coding!
