[BNW] Workers to units and back

yepzer

Chieftain
Joined
Jan 12, 2006
Messages
32
Location
Denmark
As with Civ4 (old mod, 14 years ago :shifty: ) 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. :twitch:

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>
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:
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);
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. :wallbash:
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
For future versions:
  • Promotion with Rifling: free pillaging, defensive bonus etc
  • More types of armed workers: Spear, Gun, Rifle
  • Custom unit graphics for armed workers
 

Attachments

  • Call of the Mortherland (v 2).zip
    17.1 KB · Views: 84
Absolutely amazing work! Would this be multiplayer compatible though?
 
The Ai never use units with combat power to do 'worker' or 'settler' things. You will never see an AI Samauri create a fishing boat, for example. Spanish Conquistadors don't found cities.

I believe but am not sure the two popular DLL mods VMC by William Howard and CP (for the Vox Populi system) by Gazebo et al cure this issue but I am not 100% sure they do.
 
I fixed both of those quoted and also Rome's legions building roads/forts
 
Absolutely amazing work! Would this be multiplayer compatible though?
Thank you for your nice feedback. yes, I would think this mod works for multiplayers too. Given that all have the mod. Be cautious when your enemy has workers at the borders though. :D

Thank you both LeeS & whoward69 - I have read much of your work to get this far. :thumbsup:

BTW: I have seen the AI use this reasonably well, upgrading workers to the armed work type, then back to worker. And the worker continued to do worker stuff. The armed worker upgrade was mostly used in defensive situations.
 
Top Bottom