Skip to content

Added DoCargoRoute#45

Open
Sirbomber wants to merge 1 commit intoOutpostUniverse:masterfrom
Sirbomber:master
Open

Added DoCargoRoute#45
Sirbomber wants to merge 1 commit intoOutpostUniverse:masterfrom
Sirbomber:master

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