Conversation
Added a new command to UnitEx, allowing cargo trucks to do ore hauling
DanRStevens
left a comment
There was a problem hiding this comment.
Ahh, excellent.
One slightly pedantic note, though not opposed to the change.
| struct cmdCargoRoute | ||
| { | ||
| char numUnits; | ||
| short unitId; | ||
| short numWayPoints; | ||
| long pts[3]; | ||
| short mineWayPointIndex; | ||
| short smelterWayPointIndex; | ||
| short mineUnitId; | ||
| short smelterUnitId; | ||
| }; |
There was a problem hiding this comment.
Hmm, this has a built in assumption of exactly 3 waypoints. More accurate would be to split this struct into two, so that the first struct could accommodate a variable length array at the end.
struct cmdCargoRoute
{
char numUnits;
short unitId;
short numWayPoints;
long pts[1]; // Variable length array (maybe use max size instead of the typical 1?)
}
struct CargoRouteSpecificData { // Name this better
short mineWayPointIndex;
short smelterWayPointIndex;
short mineUnitId;
short smelterUnitId;
};Another somewhat less robust alternative, would be to document the assumptions with default values:
struct cmdCargoRoute
{
char numUnits;
short unitId;
short numWayPoints{3};
long pts[3];
short mineWayPointIndex{0};
short smelterWayPointIndex{1};
short mineUnitId;
short smelterUnitId;
};At any rate, it does meet the requirements for the typical case of a 3 waypoint ore haul route.
There was a problem hiding this comment.
I'm not sure how I would do this, in practice. How would I "combine" the two structs into the packet's data buffer?
There was a problem hiding this comment.
Basically with casting and pointer arithmetic. I suppose that could potentially be easier if the array wasn't part of the struct.
At any rate, if you're building the struct specifically for that one method, it may be easier to just use a single struct, and perhaps default the values that have fixed assumptions.
Might be cleaner if the scope of the struct could be limited to the function that the assumptions are tied to.
Added a new command to UnitEx, allowing cargo trucks to do ore hauling