Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Sirbomber
Copy link
Contributor

Added a new command to UnitEx, allowing cargo trucks to do ore hauling

Added a new command to UnitEx, allowing cargo trucks to do ore hauling
Copy link
Member

@DanRStevens DanRStevens left a 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.

Comment on lines +68 to +78
struct cmdCargoRoute
{
char numUnits;
short unitId;
short numWayPoints;
long pts[3];
short mineWayPointIndex;
short smelterWayPointIndex;
short mineUnitId;
short smelterUnitId;
};
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants