Using Heroes with Plans: HeroPlanAttach

Location: Data/Scripts/GameObject

Heroes in EAW that are specified with only the LandHero or SpaceHero category masks will not be added to vanilla TaskForces unless the LandHero/SpaceHero categories are specified. Instead, heroes can be "attached" to plans based on their cost (in credits). Heroes can be prevented from this behaviour by using DenyHeroAttach in the plan TaskForce definition.

The basis for this is the script HeroPlanAttach. It uses PGCommands as a require to call Base_Definitions and set the service rate to once every 10s. It also runs the functions HeroService (in hero scripts) and calculates target contrast weights.

=== Hero Script ===

For a hero to attach, its Lua script needs to require("HeroPlanAttach"). In Definitions, MinPlanAttachCost and MaxPlanAttachCost define the minimum and maximum plan cost (in credits) that the hero will attach to. This makes a big difference if your mod has changed unit costs significantly from vanilla.

Following that, Attack and Escort tables are created to determine what units the hero should be used against and what it should avoid; as well as what units it should prefer TaskForces with. See below for an example. Note the use of the BAD_WEIGHT global variable. You can weight different unit types differently.

The hero script must also include two other functions:

These shouldn't change from hero to hero.

Modding Notes
If your hero is defined as a Unique Unit without a hero company container, and it has any additional category mask (e.g. Fighter | SpaceHero), it will join TaskForces as though it were a normal unit.