Here's some info on a collection of very small code additions which you may use in your own mod.
An overview of the items in this document:


  CHANGING UNIT OWNERSHIP
  REMOTE VIEWING / SCRYING TWEAKS
  FACTORY ROLLOFF DELAY
  PICKY LOYALIST MISSILE DEFLECTION 
  BOMBER INACCURACY
  RESTRICTING WEAPONS
  CUSTOM TRANSPORT UNITS - FORCED ATTACH POINTS


----------------------------------------------------------------------------------------------------------
CHANGING UNIT OWNERSHIP

To cure a bug I made a function that makes a unit retain most of it's stats when it's given to another player
(through diplomacy or capturing or otherwise). It retains the units health, enhancements, shield health & status,
number of missiles (TML, SML, SMD), fuel, unit kills and veteran level / bonus. It won't retain build progress.
If you need to give a unit to another player I recommend you always use this particular function.

It is called "TransferUnitsOwnership" and can be found in the file "SimUtils.lua". So if you want to use this
use this code:


    local SimUtils = import('/lua/SimUtils.lua')

    ...

    local UnitsToTransfer = { <some units>  }
    local NewOwner = <some army index>
    local TransferedUnits = SimUtils.TransferUnitsOwnership( UnitsToTransfer, NewOwner )


The local variable "UnitsToTransfer" is a table containing the unit(s) you which to transfer to another player. If
done succesfully all units in this table will no longer exist as the game will replace the units. The local 
variable "TransferedUnits" will contain the units after their ownership has been changed. The local variable 
"NewOwner" indicates what player will receive ownership of the units. This should be a value between 1 (for 
player 1) to 8 (for player 8).

----------------------------------------------------------------------------------------------------------
REMOTE VIEWING / SCRYING TWEAKS

I've added 4 parameters which are put in the blueprint of a unit. With the first parameters you can set how long
the unit reveals the area, e.g. after x seconds the remote viewing is turned off. The second parameter can remove
the buttons used for remote viewing for y seconds so during this period the unit can't be used to reveal anything.
The third and fourth parameters are for growing (or shrinking) the viewing radius over time.

It requires the unit to be derived from the remote viewing class. This is the case with the Aeons quantum optics 
facility so you can use that as an example / test case.

These parameters go in the units blueprint, in the "Intel" section:

Viewtime = xx,                  (where xx is the number of seconds that the revealing effect lasts)
Cooldown = yy,                  (where yy is the number of seconds during which the remote viewing is disabled)
RemoteViewingRadiusFinal = zz,  (where zz is the final viewing radius)
RadiusGrowStepSize = qq,        (where qq is the rate at which the radius grows per tick, defaults to 0.2)

----------------------------------------------------------------------------------------------------------
FACTORY ROLLOFF DELAY

It's possible to make a factory have a rolloff delay. During this time the factory cannot start construction of a
new unit. Land factories and naval factories have a natural rolloff delay, while the unit moves away from the
factory. Air factories do not have this but it (and the other factories can be made to have a (longer) rolloff
delay using this single parameter in the units blueprint.

These parameters go in the units blueprint, in the "General" section:

RolloffDelay = xx,           (where xx is the time it takes before the unit can rolloff the factory, in seconds)

----------------------------------------------------------------------------------------------------------
PICKY LOYALIST MISSILE DEFLECTION

The script for the missile deflector on the Loyalist was modified slightly. It is now possible to indicate in the
Loyalists blueprint what missiles it's allowed to deflect. Refer to the Loyalists blueprint in this mod for an
example on how to use. It's very straight-forward.

----------------------------------------------------------------------------------------------------------
BOMBER INACCURACY

The CBFP v4 contains a routine that calculates bomb drops. This routine does a (much) better job at accurately
calculating bomb drops. It is designed to overwrite the engines bomb drop routine but it's not automatically
used for all bomber units.
To use it in a custom unit you'll have to add a variable to the Bomb weapon in the Weapon section of the 
units blueprint:

    FixBombTrajectory = true,

This signals that the projectiles dropped from this unit should be calculated with the new routine.
For examples check out the blueprint of some of the bombers in the CBFP.

----------------------------------------------------------------------------------------------------------
RESTRICTING WEAPONS

The CBFP v3 disables nukes when the appropriate restriction is enabled. In v4 this functionality is expanded to
allow mod makers to define their own restrictions, although you'll still have to check if the weapon is
restricted and if so, disable it.

The function you should call is in file game.lua and is called WeaponRestricted with as argument the weapon label.
If you call this function the weapon label is checked against the items listen in 
/lua/ui/lobby/restrictedUnitsData.lua . In this file the CBFP adds a variable to some restrictions that indicates
what weapons to disable. If the weapon label passed to WeaponRestricted() is found then the function returns true
which means you should disable the weapon.

Check the function DisableRestrictedWeapons in /lua/sim/Unit.lua for an example. Here nukes are blocked if the
corresponding unit restriction is enabled.

An easy way to check if a unit type is restricted can also be found in game.lua (function UnitRestricted).

----------------------------------------------------------------------------------------------------------
CUSTOM TRANSPORT UNITS - FORCED ATTACH POINTS

If a unit is categorized as a transport the engine decides to force attach points on the model instead of using
the one specified in the model. This can cause frustration for unit creators. The CBFP v4 contains a code that
can cancel this engine behaviour. To make use of this add the line below to the Transport section in the
units blueprint file.

    DontUseForcedAttachPoints = true,

The game now makes use of the bones you added in the model.

----------------------------------------------------------------------------------------------------------

