Lets think for a moment on how it would work with professions.
We make one tank unit, which works kind of like a treasure unit, except it can't move. It can only be transported by other units, such as drivers and trains. It might be possible to capture it, but we should forget about capturing units for now.
Next we have a tank driver profession. It has one cargo slot and once assigning the profession, it picks up a tank unit and places it in that cargo slot. This will solve the problem of linking driver and vehicle units into one.
When unit changes profession, the tank unit reappears on the map.
Health:
When picking up the tank, the unit gets the same health as the tank (percentage of full health)
When dropping the tank, the tank gains the same health as the driver (still percentage)
This will ensure that you can't cheat and make a heavily damaged driver drop the tank and an unharmed driver takes over.
Linking units:
I wonder if we could make a new cargo hold just for the vehicle unit. This one will not be visible in a city and stuff like that. That will allow a vehicle with driver and normal cargo hold. The normal cargo hold can then be used for fuel and ammo and whatever. It should also allow us to extend this system to (cargo) ships.
We can then alter certain functions to work like:
Code:
int CvUnit::getMove()
{
if (vehicle_slot != NULL)
{
return vehicle_slot->getMove();
}
return m_moves;
}
This is example code,
not copied from the real code. In fact I think it reads from UnitInfo rather than the unit itself. This could make it even easier to implement. We just have two pointers to UnitInfo, both pointing to the same location and it will not matter which one we use. When we have a vehicle, we just change that pointer and automatically everything using that pointer will be updated. This mean instead of checking for carrying a vehicle at runtime, we just at compiletime sets which of the two pointers it uses. That way we can keep the code simple (less bugs) and not losing any performance at all from linking units like that.
This will allow a single driver profession to gain different abilities from different tanks and the power, graphics and such will be set in the tank unit. We will likely need some "is vehicle" bool in the tank info to give it moves, yet being unable to move.