1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[BNW] Workers to units and back

Discussion in 'Civ5 - Creation & Customization' started by yepzer, Jan 9, 2021.

  1. yepzer

    yepzer Chieftain

    Joined:
    Jan 12, 2006
    Messages:
    31
    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(iTeamiTechbAdopted)
        if (
    iTech == GameInfo.Technologies["TECH_GUNPOWDER"].IDthen
            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
     

    Attached Files:

    Lt_Karan likes this.
  2. Lt_Karan

    Lt_Karan Chieftain

    Joined:
    Jan 24, 2021
    Messages:
    34
    Absolutely amazing work! Would this be multiplayer compatible though?
     
  3. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,176
    Location:
    Illinois, USA
    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.
     
    Lt_Karan likes this.
  4. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,537
    Location:
    Near Portsmouth, UK
    I fixed both of those quoted and also Rome's legions building roads/forts
     
    Lt_Karan likes this.
  5. yepzer

    yepzer Chieftain

    Joined:
    Jan 12, 2006
    Messages:
    31
    Location:
    Denmark
    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.
     
    Lt_Karan likes this.

Share This Page