-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added DoCargoRoute #45
base: master
Are you sure you want to change the base?
Conversation
Added a new command to UnitEx, allowing cargo trucks to do ore hauling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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