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

Modding Social Policies (from the ground up)

Discussion in 'Civ5 - Creation & Customization' started by Dryhad, Jul 15, 2011.

  1. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    Ok, so some time ago I tried and failed to make a mod in which I deleted the social policies and replaced them with new ones, and after trying several avenues of inquiry and being met with no change whatsoever in the game itself I decided that it was either impossible, or far beyond my knowledge and capabilities at the time. Now, I understand that something of this nature has been done so it is possible, but trying again it proves still beyond my knowledge and capabilities.

    I've had a look at the Polynesian DLC scenario, and replicated it as best I could for my own policies. I suspect the problem may be in the SocialPolicyPopup.xml file of which I can't make head nor tail. Is there anyone here who knows how to do this sort of thing and could give me some basic instructions?
     
  2. Skajaquada

    Skajaquada Crazy Engineer

    Joined:
    Mar 4, 2007
    Messages:
    134
    I don't think the social-policy files are that special. The SocialPolicyPopup.xml is for the UI and it've got all the pictures hard-coded so you need to update the .DDS-file references there to get your own. Also if you want to change the number of policy-branches you need to change that in there as well as it prints them all by name. The file SocialPolicyPopup.lua makes direct references to the policy-branches so if you want to add or remove them you have to replace that one and just update everything. It's all written together with words like "tradition", "piety" etc. so you can't miss it.

    I did it some time ago and I didn't run into any problems. Just make a mod with that SocialPolicyPopup.xml and SocialPolicyPopup.lua and see what kind of references they make. If you don't want to learn how to mod the UI you can't really change the number of branches, then I suggest that you just update the existing ones with new names and remove all the policies and start over with just those. The policies at-least print automatically like the tech-tree if you don't write X- and Y-coordinates that are unreasonable. However there's really no trouble modding the UI.

    If you're new with modding you really need to make sure you're loading everything right and just change some text-strings.
     
  3. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    What he said.

    If you're changing the number of Branches then you'll have to rewrite both the SocialPolicyPopup.lua and the SocialPolicyPopup.xml files. It's a lot of work to get right. (Trust me.)

    If you're keeping 10 branches but changing their names, you can do that easily in XML, but it won't change the background image each branch uses. That requires an edit to SocialPolicyPopup.xml, albeit a pretty simple one.

    If you're keeping 10 branches and keeping their names, but just changing the policies, then you can do that easily in the standard GameData XML. As long as you set the prerequisites and GridX/GridY values, it'll all work just fine. (You'll still need to add custom icons, of course.) GridY is just the row number, from 1 to 3. GridX goes from 1 to 5 but there's overlap; you can't have (1,1) and (1,2), because their buttons would overlap, so on a given row you can only put at most three buttons (1-3-5).

    If you go to the #6 post in my mod's thread (linked in my .sig), I've attached an image that shows how I modified the Policies menu in my own mod to add a special 11th branch of "Super-Finisher" policies. It's quite a bit of work, but it CAN be done.
     
  4. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    After reading your responses and having a tinker around, it seems more and more likely that my problem is not to do with the UI files at all (although I'll have to deal with those eventually) but with a strange problem aluded to in this post but not responded to. Although the Polynesia Scenario does delete all the policies and start again, I'm unable to replicate this. And yes, I am sure that I'm loading it right, and I'm able to load other mods perfectly fine.

    So how do you guys go about rebuilding the policies? Do you delete them and if so how? Do you painstakingly go through each one with an <Update> changing every aspect of them? Because if that is the workaround as the post I linked suggests, that's going to be really annoying when I'm rewriting all of the policies.
     
  5. markusbeutel

    markusbeutel NiGHTS

    Joined:
    Sep 26, 2010
    Messages:
    1,976
    Location:
    Vancouver BC Canada
    Alternatively I suppose you could disable the vanilla policies and then move them out of the screen, (switching the Y axis to something like 20 should do the trick), and then replace them with your own custom policies. This would be less tedious than updating all of the policies.
     
  6. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    Would it? It sounds at least as tedious, if not more.

    Also, I tried a small scale test in which I attempted to update the Tradition tree. No change. Thank you for your help so far, but I'd really like some specific guidance, code examples and that sort of thing. I'm sure there's some simple thing I'm missing because nobody else seems to be having this problem, but it's really hard to figure that out when I can't see examples of anything that works.
     
  7. Skajaquada

    Skajaquada Crazy Engineer

    Joined:
    Mar 4, 2007
    Messages:
    134
    My guess is VFS set to true (if you're updating the SocialPolicyPopup.lua/xml). Apparently every file that replaces one in the game needs to have the VFS option set to true.

    If you create a SQL-file with this content:

    Code:
    UPDATE Language_en_US SET Text='HELLO WORLD' WHERE Tag='TXT_KEY_POLICY_BRANCH_TRADITION_CAP';
    Then set those OnModActivated, UpdateDatabase and name of file (just as in Kael's guide) it should update the Tradition-branch with the text "HELLO WORLD" at the Tradition-header on the policy screen. VFS can be set to false on this one.

    At-least then you should know that your files are loading. The XML-files load the same way. I'd suggest going through the CIV5Policies.xml so you know what fields are in the latest patch then add a new policy next to an existing one. Just search for a key like POLICY_MONARCHY in all the different sets like "prereq" or what they're called and make reasonable entries.

    Also you could post your files if you want people to take a look at them. Preferably in the code-tags so the formatting is kept. Otherwise it really sounds like you're just having trouble loading the files.
     
  8. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    Yeah, fair point. I did your Hello World thing and that worked fine, then I tried these test changes to the Tradition tree which didn't. Presumably the error is somewhere in this code:
    Code:
    	<Policies>
    		<Update>
    			<Set GridX="3"/>
    			<Set GridY="1"/>
    			<Where Type="POLICY_MONARCHY"/>
    		</Update>
    		<Update>
    			<Set GridX="5"/>
    			<Set GridY="1"/>
    			<Where Type="POLICY_LEGALISM"/>
    		</Update>
    		<Update>
    			<Set Description="TXT_KEY_POLICY_NATIONHOOD"/>
    			<Set Civilopedia="TXT_KEY_POLICY_NATIONHOOD_TEXT"/>
    			<Set Help="TXT_KEY_POLICY_NATIONHOOD_HELP"/>
    			<Set GridX="4"/>
    			<Set GridY="2"/>
    			<Set NumFreePolicies="2"/>
    			<Set GarrisonedCityRangeStrikeModifier="0"/>
    			<Set GarrisonFreeMaintenance="false"/>
    			<Where Type="POLICY_OLIGARCHY"/>
    		</Update>
    	</Policies>
    	<Policy_PrereqPolicies>
    		<Delete PolicyType="POLICY_LANDED_ELITE"/>
    		<Delete PolicyType="POLICY_MONARCHY"/>
    		<Row>
    			<PolicyType>POLICY_LANDED_ELITE</PolicyType>
    			<PrereqPolicy>POLICY_ARISTOCRACY</PrereqPolicy>
    		</Row>
    		<Row>
    			<PolicyType>POLICY_LANDED_ELITE</PolicyType>
    			<PrereqPolicy>POLICY_MONARCHY</PrereqPolicy>
    		</Row>
    		<Row>
    			<PolicyType>POLICY_OLIGARCHY</PolicyType>
    			<PrereqPolicy>POLICY_LEGALISM</PrereqPolicy>
    		</Row>
    		<Row>
    			<PolicyType>POLICY_OLIGARCHY</PolicyType>
    			<PrereqPolicy>POLICY_MONARCHY</PrereqPolicy>
    		</Row>
    	</Policy_PrereqPolicies>
    Previously I'd been deleting existing policies and replacing them, which just seems cleaner to me (and easier to make changes later on, this isn't necessarily what I want to be the final output of my mod) but I'm trying <Update> based on the thing I posted earlier. Ideally I'd like to be able to delete as well, but one step at a time.
     
  9. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    When an XML file like that fails to load, just go into your xml.log file. It'll tell you exactly what the mistake was. (Assuming you remembered to turn on the logging in the first place, of course.)
     
  10. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    I turned the logging on, ran my mod, this is what's in xml.log:
    Code:
    [23499.444] **** Validating Game Database *****
    [23500.318] Performing Localization Checks
    [23500.318] Checking Tag Format...
    [23500.318] Note: Tags must only use [A-Z_] characters, start with 'TXT_KEY_', and be under 128 characters long.
    [23500.333] Validating UnitGameplay
    [23500.333] Number of selection sounds doesn't match number of units.
    [23500.333] Validating Notifications
    [23500.333] **** VALIDATION FAILED *****
    [23500.333] Validation Took 0.891570 seconds
    [23500.677] **** Validating Prefetch Process *****
    [23500.677] **** Validation Success *****
    [23500.677] SetGlobalActionInfo
    [23500.677] 
    -- SQLite Memory Statistics --
    Memory Usage:
    		[Cur]		[Max]
    Malloc:		284680		2397080
    PageCache:	3187		3656
    LookAside:	45		1864
    Scratch:	0		1
    
    Static Buffer Overflows:
    		[TooLarge]	[NoSpace]
    PageCache:	0		0
    Scratch:	0		0
    
    Largest Allocations:
    Malloc:		65280
    PageCache:	1160
    Scratch:	5128
    
    Prepared Statements:
    Current:		5
    ------------------------------
    [23529.303] **** Validating Game Database *****
    [23530.130] Performing Localization Checks
    [23530.130] Checking Tag Format...
    [23530.130] Note: Tags must only use [A-Z_] characters, start with 'TXT_KEY_', and be under 128 characters long.
    [23530.145] Validating UnitGameplay
    [23530.145] Number of selection sounds doesn't match number of units.
    [23530.145] Validating Notifications
    [23530.145] **** VALIDATION FAILED *****
    [23530.145] Validation Took 0.828984 seconds
    [23530.442] **** Validating Prefetch Process *****
    [23530.442] **** Validation Success *****
    [23530.442] SetGlobalActionInfo
    [23530.442] 
    -- SQLite Memory Statistics --
    Memory Usage:
    		[Cur]		[Max]
    Malloc:		379560		2397080
    PageCache:	3216		4982
    LookAside:	1363		3182
    Scratch:	0		1
    
    Static Buffer Overflows:
    		[TooLarge]	[NoSpace]
    PageCache:	0		128760
    Scratch:	0		0
    
    Largest Allocations:
    Malloc:		65280
    PageCache:	1160
    Scratch:	5128
    
    Prepared Statements:
    Current:		24
    ------------------------------
    
    Now I don't see anything pertaining to the modifications I made (all of which are in my earlier post)
     
  11. Skajaquada

    Skajaquada Crazy Engineer

    Joined:
    Mar 4, 2007
    Messages:
    134
    If that's your entire file you need GameData-tags around everything.
     
  12. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    Those error messages in the xml.log are normal, the sorts of things you'd get from running the base game. So nothing there.

    At this point, I'd say to attach a zip file containing your entire mod, and we can look to see if anything else was wrong. For instance, if you didn't set up the OnModActivated/UpdateDatabase command correctly, then it wouldn't have any effect.

    If the entire mod is too big, then just attach the .modinfo file and the XML file in question.
     
  13. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    Sorry, those tags are in the mod, I copied everything inside them.

    I don't think it's the UpdateDatabase since it worked on Skajaquada's SQL code and it's really the same command, I just changed the SQL filename to the XML filename. However, I've attached the test mod, and you may also be interested in my earlier thread on the subject, in which I post an earlier version of my full mod.
     

    Attached Files:

  14. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    First of all, you didn't do an UpdateDatabase command for the SQL file, so your little Hello World test won't work. But let's stick with the XML.

    One thing to try first: instead of writing it as
    Code:
    <Update>
      <Set GridX="3"/>
      <Set GridY="1"/>
      <Where Type="POLICY_MONARCHY"/>
    </Update>
    try it as
    Code:
    <Update>
      <Set GridX="3" GridY="1"/>
      <Where Type="POLICY_MONARCHY"/>
    </Update>
    
    The Set and Where commands both use an inherent AND syntax, so you can put multiple Sets on a single line and it'll change all of them. See if that fixes anything.
     
  15. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    I'm aware of that, I already did the Hello World test, and it worked, so I took out the UpdateDatabase command for that one.

    That actually worked, hooray!

    It still sits uneasily with me, though. That's fine for the changes I want to make to Tradition, I guess, but for some of the other trees I want to make, it's just completely different from any existing tree (although I do plan to stick to ten total). Also, if the problem is that it won't let me delete policies, I don't understand how the Polynesia scenario gets away with it. Oh, well, I'll have a tinker around but please, anyone who knows anything, feel free to post your thoughts on the subject.
     
  16. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    It's not that you can't delete policies. It's that the UI elements (SocialPolicyPopup.lua and SocialPolicyPopup.xml) are set explicitly to use 10 boxes named "Tradition", "Liberty", and so on, with the appropriate background images. If you're willing to edit those files, then you can make as many branches as you want, with whatever names you want. In my own mod, for instance, I added an 11th branch that goes between the two rows; there's a screenshot of it over in my mod's thread (see sig), in the 6th post I think.

    Without editing those files, though, there's no way to make the kinds of major changes you're describing. And they're just a lot of work to get things right, believe me.
     
  17. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    Are you sure about that? I tried making the same changes as the test mod I posted but by deleting the Tradition tree and then remaking it. If what you're saying is true, that should have worked perfectly fine, but it didn't. Also, from what I can see from the UI files the "Tradition" and "Liberty" and so forth tags there are essentially arbitrary. By that I mean, the worst that ought to happen is you get the wrong labels applied to things (because the TXT_KEYs are in those UI files) but that the important changes should still happen. For some reason, they don't.
     
  18. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    Yes.

    Then obviously you messed something else up. Maybe the <FreePolicy> stub in the Branch definition now pointed to a policy that no longer existed. Maybe you didn't remove a Prerequisite declaration that required one of the now-deleted policies. Maybe your branch was no longer named POLICY_BRANCH_TRADITION. Any one of those would cause it to break.

    While the word "Tradition" is a simple text key and CAN be edited, the underlying text key for box number 1 must still be tied to TXT_KEY_POLICY_BRANCH_TRADITION, plus the usual _HELP, _CAP, etc. alternates. That's hard-set in the SocialPolicyPopup.xml file.

    Likewise, in the SocialPolicyPopup.lua file, the policy branches have to be explicitly named POLICY_BRANCH_TRADITION, POLICY_BRANCH_LIBERTY, and so on. So if you create a new branch and it's not one of the existing names, then the Lua WILL break. In two separate places, actually; first when setting up the control table for the pipes, and second when setting up the instance manager for the box.

    So you can replace the Tradition branch with the Awesomeness branch, as long as internally the game still sees it as POLICY_BRANCH_TRADITION. If you try making a POLICY_BRANCH_AWESOMENESS, then it WILL break.

    Also, if you delete any branches, then the IDs will no longer line up correctly. That'd also break things.
     
  19. Dryhad

    Dryhad Prince

    Joined:
    Feb 23, 2006
    Messages:
    451
    I didn't alter the Branch at all, and the Prereq changes were exactly the same as those in the test mod I posted. While my track record would suggest some kind of silly mistake of this order, none of those possibilities fit.

    Yes, exactly, that's just text! I have never deleted any text tags, and even if I did the worst that would happen would be ugly "TXT_KEY_POLICY_BRANCH_TRADITION" things all over the policy window.

    This would explain all the issues in my original mod, but not in the test mod! As I previously explained, I did nothing to the PolicyBranches table, I merely deleted all the policies in the Tradition branch (not the branch itself) and added them back in. Would that cause ID problems? If so, is there a way around it?
     
  20. Skajaquada

    Skajaquada Crazy Engineer

    Joined:
    Mar 4, 2007
    Messages:
    134
    If you later want to mod to the UI to contain more than 10 branches it's really not that hard. For testing I added 21 branches with checkboxes to hide / show them in sets of 10, 5 and even 6. If the XML-queries are like some weird SQL-like language the LUA/XML-layout files are just like HTML and JavaScript.

    For example if you add something like this to the SocialPolicyPopup.xml:

    Code:
    <CheckBox Anchor="L,T" Offset="-50,50" Font="TwCenMT20" FontStyle="Shadow" String="TXT_KEY_ONE" IsChecked="1" ID="ButtonOne"/>
    <CheckBox Anchor="L,T" Offset="-50,70" Font="TwCenMT20" FontStyle="Shadow" String="TXT_KEY_TWO" IsChecked="0" ID="ButtonTwo"/>
    <CheckBox Anchor="L,T" Offset="-50,90" Font="TwCenMT20" FontStyle="Shadow" String="TXT_KEY_THREE" IsChecked="0" ID="ButtonThree"/>
    
    <Grid ID="GridOne" Size="1005,768" Anchor="C,C" Offset="0,6" Padding="0,0" Style="Grid9DetailFive140">
    	<!-- Content here. -->
    </Grid>
    <Grid ID="GridTwo" Size="1005,768" Anchor="C,C" Offset="0,6" Padding="0,0" Style="Grid9DetailFive140">
    	<!-- Content here. -->
    </Grid>
    <Grid ID="GridThree" Size="1005,768" Anchor="C,C" Offset="0,6" Padding="0,0" Style="Grid9DetailFive140">
    	<!-- Content here. -->
    </Grid>
    You can define three grids to contain the different policy-branches and three buttons to switch between then. Then just add something like this to the SocialPolicyPopup.lua:

    Code:
    function OnButtonOne( bIsChecked )
    	-- Simulate radio-button
    	if (bIsChecked ~= true) then
    		Controls.ButtonOne:SetCheck( true );
    		return;
    	end
    	Controls.ButtonTwo:SetCheck( false );
    	Controls.ButtonThree:SetCheck( false );
    	-- Show the selected policies and hide the rest
    	Controls.GridOne:SetHide( false );
    	Controls.GridTwo:SetHide( true );
    	Controls.GridThree:SetHide( true );
    end
    Controls.ButtonOne:RegisterCheckHandler( OnButtonOne );
    For each of the ButtonOne, ButtonTwo and ButtonThree. The challange after that was just to adjust the sizes of the grids to fit extra branches but that was just done with the functions SetOffsetVal and SetSize for GridOne, GridTwo and GridThree. It's all very similar to JavaScript where you get an element from it's ID and then set the style and such.
     

Share This Page