Alternatively, you could just set (most) units' cargo at creation time.
TethysGame::CreateUnit(Unit1, mapConVec, LOCATION(129, 43), 0,
mapCommandCenter, 0);
TethysGame::CreateUnit(AI.AG1_3, mapTiger, LOCATION(36, 4), AI.numAI1,
mapThorsHammer, 1);
TethysGame::CreateUnit(AI.GP7, mapGuardPost, LOCATION(94,
, 5,
mapLaser, 0);
Doing it for trucks is weird though. Create a truck with no cargo:
TethysGame::CreateUnit(Unit1, mapCargoTruck, LOCATION(40, 12), 0,
mapNone, 0);
Now:
Unit1.SetTruckCargo(truckCommonMetal, 1000);
Where the first argument is the truck's cargo (here, truckCommonMetal), and the second argument is the amount (here, 1000).
Here's a list of all truck cargoes:
truckEmpty (why you'd need to set it to empty is beyond me, but just in case...)
truckCommonMetal
truckRareMetal
truckFood
truckCommonOre
truckRareOre
truckCommonRubble
truckRareRubble
truckSpaceport (Starship modules. Explained below in more detail.)
truckGarbage (Starship wreckage. Explained below in more detail.)
truckUnit (Dunno, but it seems to act like truckSpaceport.)
About truckSpaceport and truckGarbage:
The cargo amount corresponds to the unit ID of the starship part/tech ID of the wreckage. This info can be found in MapIdEnum.h and EnumTechID (or the techtree file you're using) respectively. Make sure you use proper values when you do this. I'm not sure how OP2 would react if you try to launch a Command Center into space, but if you use bad tech ID values for wreckage the game will crash if you try to unload them at the Spaceport.
One final note: There's probably a different way to do this, but if you want a Gene Bank in a cargo truck, set its cargo to be the Ion Drive Module. I say there must be a better way because amount is always set to 5...
Edit: Why can't I bold things inside code tags? I kinda wanted to emphasize the part where the cargo gets set...
PS: By the way, if you want a Garage to start with units, check out
this thread.