It would be nice to be able to add or subtract LOCATION structures from each other using a standard operator function like + or -.
For example, you could place structures relative to each other like this:
Unit unit;
TethysGame::CreateUnit(unit, map_id::mapCommandCenter, LOCATION(20 + X_, 15 + Y_), 0, map_id::mapNone, UnitDirection::East);
TethysGame::CreateUnit(unit, map_id::mapAgridome, unit.Location() + LOCATION(7, 0), 0, map_id::mapNone, UnitDirection::East);
TethysGame::CreateUnit(unit, map_id::mapStandardLab, unit.Location() - LOCATION(-7, 0), 0, map_id::mapNone, UnitDirection::East);
I don't think the definition of the structure LOCATION can be modified, so the operator functions have to be declared globally instead of being declared as members of LOCATION. (I think the definition of LOCATION is being pulled directly from Outpost 2 code, but not sure).
I added the following declarations and definitions to a local copy of the SDK and tested it. I'm still new to C++, so please take it with a discerning eye.
OP2Helper.h AdditionLOCATION operator+ (LOCATION &loc1, LOCATION &loc2);
LOCATION operator- (LOCATION &loc1, LOCATION &loc2);
OP2Helper.cpp Addition/*Global Operator Functions for structure LOCATION.
* This allows LOCATION loc = LOCATION(10, 10) + LOCATION(5, 0)
* Or LOCATION loc = LOCATION(10, 10) - LOCATION(5, 0)*/
LOCATION operator+ (LOCATION &loc1, LOCATION &loc2)
{
LOCATION newLoc;
newLoc.x = loc1.x + loc2.x;
newLoc.y = loc1.y + loc2.y;
return newLoc;
}
LOCATION operator- (LOCATION &loc1, LOCATION &loc2)
{
LOCATION newLoc;
newLoc.x = loc1.x - loc2.x;
newLoc.y = loc1.y - loc2.y;
return newLoc;
}
Attached files with modifications included.