So.. Thinking out loud here. This is more like a scratch pad of possibly bad ideas, so bear with me.
I have this idea that it might be useful to add more types of barge cargo, specifically, cargo that we could treat like components required to build complex things like aircraft. Off the top of my head, I can imagine things like:
- Jet Turbines
- AI cores
- Communications hardware
And maybe more. The point being that, what if we could transport these things around the map via barges, produce them on islands, consume them on islands to build bigger things like aircraft or ships.
How?
We can’t actually invent or re-purpose any of the existing inventory items. For one thing, you can’t unload any of them onto islands, for another, we can’t just create them.
But, afterall, what is this kind of thing really? Barges have a list of cargo items, so do islands. We just need to implement our own list.
We can store these lists in waypoint data!
Waypoint Data hack
Originally discovered by QuantX as a means to share the holomap cursor with operator screens using the drydock waypoint list. It is possible for lua scripts on the bridge to create waypoints for most friendly units.

Rev 1.6 already maintains several counters and flags using the waypoint hack:
- holomap cursor (1 waypoint per team)
- stored as 2x 16bit x/y coordinate values stored as a waypoint altitude value. Eg, the x-coordinate and y-coordinate divided by 10 is stored, giving us a holomap cursor location square of about 650km
- fog of war “scouted” (1 waypoint per island)
- We store a new flag waypoint for every island our team has been near
- factory damaged (1 waypoint per island)
- Similar to fog of war, but we store a timer that when expired allows the factory to be used again
- holomap markers (4 waypoints per team)
- same method as the cursor, we store WXYZ waypoint
So, for a normal 2 team game using about 30 islands, this is between 1 and 34 waypoints, or 1 and 64 for a game with fog of war, and up to 94 waypoints if every single island factory gets bombed at least once.
For a cargo system we’d need to do more of the above, but potentially a LOT more. We would need:
- 1 waypoint per island for each new cargo type
- 1 waypoint per barge for each new cargo type
This could quickly mount up. Rarely would we in the normal case get to 94. But, if we were to use this idea for just 1 new cargo type, we’re going to HUGELY increase the number of waypoints. This is a problem because it isnt just data, it all takes longer and longer to iterate through to find things, lua is fairly quick, but this WILL lag the game a lot. For 5 cargos, 30 islands and 2 barges, this would be 32×5 = 160 waypoints!!!
So.. what if we had a different idea. The aim being to have fewer waypoints that are easy to update and iterate through.
Brainstorm!
We don’t need the full 32bit altitude value to store each cargo item, we’re never going to have 4.3 billion items.

So, what if we limit ourselves to 6 bits for each cargo. That gives us a max of 64 items for up to 5 cargo types. And leaves us 2 bits spare to do something else with.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| cargo1 | cargo2 | cargo3 | cargo4 | cargo5 | ? |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Yeah! now we’re cooking. With this, we can store the total for all 5 of our cargos in 1 waypoint.
We’re still going to need one of these for each island. Iterating though 64 of these things is going to be a drain. Plus one for each barge..
But maybe we don’t need to iterate very often, maybe we can cache some things once at startup.
When we add a waypoint, we get given it’s id number, when we want to read it, we can do:
local wpt = drydock:get_waypoint_by_id(w_id)
Which gives us the whole waypoint, including its x/y position, hold flags and attack/load orders. We can do:
local alt_value = wpt:get_altitude()
So as long as each lua script caches the waypoint ID used for each island and each barge, we can obtain our inventory state in only 2 calls (plus the island id to waypoint id lookup in a table) We dont need to loop around large numbers of waypoint objects.
We also do not need to do this very often, only when a barge is near an island and is loading or unloading, or when someone places a cargo order or when an island “produces” some cargo!



One response to “Brain Dump: New Cargo”
[…] my earlier post Brain Dump: New Cargo I mentioned the idea of having more cargo types. In CC2 this isn’t as simple as adding […]
LikeLike