As with Civ4 (old mod, 14 years ago ) I wanted the option to change workers to units, and back again.... Swords to Plow shears, wartime call to arms, Worker boom when returning from war - or as I ended up calling it: Call of the Motherland... attached below.
Here's my experiences...
First though was to let workers upgrade to musketman, and musketman to worker. Don't do that. Each unit(class) can only upgrade to one thing. So no more upgrades from musketman to rifleman for that unit. Also this disabled the upgrade for the Civs with unique musket units. So I created a new UnitClass and cloned the musketman to that "armed worker" unit. Workers could now upgrade to "armed worker" and back.
There's a trap though - that the AI falls in, and you can too. Discover an upgradeable unit - upgrade it - new turn discover a upgradable unit - upgrade it ... etc until you run out of cash.
Since the upgrade works on unit classes, I figured I could have 3 era-based armed workers: Spear, Gun, Rifle. The issue is, that you can only upgrade to one thing based on the UnitClass default unit set in the XML. So I put together a LUA to update this runtime:
The code works fine and updates the default unit - but it doesn't update the game. Yeah, you can't update this at runtime, the database is read-only.
I have chosen just to show the worker on the map with a musket icon (see below). I can do some reskinning using Gimp, but not new 3D models or good icons....
Other ways?
I explored the option of a new mission based on DLL - Custom Missions via XML and Lua by S3rgeus. But I couldn't disable the mission for all units, and would have to look into killing the original and adding promotions to the new one. That's a lot of lua, that can go wrong.
Similarly I considered to have the LUA event above find all armed workers with spear and convert them to the gun unit - but that could easily add performance issues.
Perhaps promotions for the worker units could do the same - by adding attack and defense modifiers? I tried adding a promotion for the Armed Worker to kick in with TECH_RIFLING, but never seemed to work for me. Perhaps a wonder to trigger the war promotion (or upgrade ability) could be another approach.
Result:
Upgrade workers to Armed Workers and back to workers:
Here's my experiences...
First though was to let workers upgrade to musketman, and musketman to worker. Don't do that. Each unit(class) can only upgrade to one thing. So no more upgrades from musketman to rifleman for that unit. Also this disabled the upgrade for the Civs with unique musket units. So I created a new UnitClass and cloned the musketman to that "armed worker" unit. Workers could now upgrade to "armed worker" and back.
There's a trap though - that the AI falls in, and you can too. Discover an upgradeable unit - upgrade it - new turn discover a upgradable unit - upgrade it ... etc until you run out of cash.
HTML:
<Unit_ClassUpgrades>
<Row>
<UnitType>UNIT_WORKER</UnitType>
<UnitClassType>UNITCLASS_COTM_ARMEDWORKER</UnitClassType>
</Row>
<Row>
<UnitType>UNIT_COTM_ARMEDWORKER</UnitType>
<UnitClassType>UNITCLASS_WORKER</UnitClassType>
</Row>
</Unit_ClassUpgrades>
PHP:
print("Loaded: Update Default Unit")
print("Default: "..GameInfo.UnitClasses["UNITCLASS_COTM_ARMEDWORKER"].DefaultUnit)
function UpdateDefaultUnit(iTeam, iTech, bAdopted)
if (iTech == GameInfo.Technologies["TECH_GUNPOWDER"].ID) then
GameInfo.UnitClasses["UNITCLASS_COTM_ARMEDWORKER"].DefaultUnit = "UNIT_COTM_ARMEDWORKER_GUN"
print("Updated: "..GameInfo.UnitClasses["UNITCLASS_COTM_ARMEDWORKER"].DefaultUnit)
end
end;
GameEvents.TeamTechResearched.Add(UpdateDefaultUnit);
I have chosen just to show the worker on the map with a musket icon (see below). I can do some reskinning using Gimp, but not new 3D models or good icons....
Other ways?
I explored the option of a new mission based on DLL - Custom Missions via XML and Lua by S3rgeus. But I couldn't disable the mission for all units, and would have to look into killing the original and adding promotions to the new one. That's a lot of lua, that can go wrong.
Similarly I considered to have the LUA event above find all armed workers with spear and convert them to the gun unit - but that could easily add performance issues.
Perhaps promotions for the worker units could do the same - by adding attack and defense modifiers? I tried adding a promotion for the Armed Worker to kick in with TECH_RIFLING, but never seemed to work for me. Perhaps a wonder to trigger the war promotion (or upgrade ability) could be another approach.
Result:
Upgrade workers to Armed Workers and back to workers:
- Available from Gunpowder to Replaceable Parts
- Hidden in the pedia (but shown on the gunpowder tech)
- Low cost, low strength, no cost (like workers)
- Armed Workers cannot be built, only upgraded to/from
- Promotion with Rifling: free pillaging, defensive bonus etc
- More types of armed workers: Spear, Gun, Rifle
- Custom unit graphics for armed workers