Results 1 to 3 of 3

Thread: [Untested] Discharged Veterans System

  1. #1

    Default [Untested] Discharged Veterans System

    No scripting logic exists that deal with how much experience chevrons a unit has. Which means we have to replicate our own. Fortunately, just enough scripting features were introduced in Remastered to allow for us to not only manage how much "fake experience" a unit has, but also integrate it with other scripting to create a Discharged Veterans System.


    Keep in mind that as of writing this, I haven't actually playtested the scripts. Every scripting code you see here is purely theoretical and I'll edit this post once I've tested it or once someone else does.


    campaign_script.txt


    Code:
    
    monitor_event PostBattle TrueCondition ;;; Do armies lead by captains also count?
    	and FactionIsLocal
    	
    	for_each unit in character ;;; Does PostBattle correctly export "character" data?
    		declare_counter experience                                             
    		retrieve_counter unit_experience unit experience ;;; Does "unit" store labels the same way "faction" and "settlement" does?    
    		
    		inc_counter experience 1    
    		store_counter experience unit unit_experience  
    	end_for
    end_monitor

    This is all it takes to have every single unit in an army count the numbers of battles fought. Note that you can remove FactionIsLocal if you want to script stuff for the AI. Also note the ;;; comments because there's a lot of unanswered questions. Anyways, what can we do now that every single unit counts experience? Well, for these veteran units, let's do what so many polities of antiquity did and settle them into veteran colonies!


    campaign_script.txt


    Code:
    
    monitor_event FactionTurnStart TrueCondition 
    	and FactionIsLocal
    	and FactionType thrace ;;; EB1 Epeiros
    	
    	for_each settlement in faction
    	
    		if not HasResource epeirosthessaliancolony
    			and SettlementBuildingExists >= epirote_mercenary_colony
    			
    			declare_counter thessalian_veterancy                                             
    			retrieve_counter settlement_thessalian_veterancy settlement thessalian_veterancy    
    				
    			for_each unit in settlement 
    				if UnitType thessalian merc
    					declare_counter experience                                             
    					retrieve_counter unit_experience unit experience    
    					
    					counter_operation thessalian_veterancy = thessalian_veterancy + experience ;; Is a = a + b allowed or do we need a third variable c to get a = b + c?
    				end_if
    			end_for
    			
    			store_counter thessalian_veterancy settlement settlement_thessalian_veterancy 
    			
    			if I_CompareCounter thessalian_veterancy >= 32
    				
    				add_hidden_resource local epeirosthessaliancolony
    			end_if
    			
    		end_if
    	end_for
    end_monitor

    Every turn, this script will check a settlement for Thessalian Mercenary Cavalry and their experience. Their experience will be added to the settlement's veterancy counter. More experienced Thessalians will contribute more veterancy per turn. Once it exceeds 32, add a hidden resource that enables the recruitment of non-Mercenary Thessalian Cavalry.


    What does this mean for gameplay? Well, the player will be incentivized to fight battles using units whose experience will be used in scripts like these. More veteran units are extremely valuable because they increase the veterancy of whichever settlement's colony building they reside in. Also, it creates immersion because the player will truly feel like he is honorably discharging veterans across various settlements to increase his empire's stability.


    History wise, the Roman veteran colonies are the most well-known application of this script. However another one is how the Ptolemies settled tons of Greek mercenaries in Egypt between 310 BC and 270 BC. Yet more lesser-known ones are the Seleucids and Ptolemies settling veterans in the southern coast of Anatolia, and the Epirotes settling mercenaries in the territories of which they've executed the local elites. The Epirote example in fact inspired me to try to make this mechanic. Thank you Pyrrhus for being a terrible administrator.


    Again, as of writing this, the script is untested so do not just copy and paste it into your mod. I'll try to test it later on and then edit this post.

  2. #2

    Default Re: [Untested] Discharged Veterans System

    Due to what may be a feral bug making it impossible to store counters inside of units despite the documentation saying its possible, this feature is not possible. I'll post my progress here anyway incase anyone finds it useful.

    export_descr_character_traits.txt

    Code:
    	
    ;------------------------------------------
    
    
    Trait VictoriesThisTurn
        Characters family
        Hidden
    
    
        Level Hidden1
            Description Hidden_desc
            EffectsDescription Hidden_effects_desc
            Threshold  1
    
    
        Level Hidden2
            Description Hidden_desc
            EffectsDescription Hidden_effects_desc
            Threshold  2
    
    
        Level Hidden3
            Description Hidden_desc
            EffectsDescription Hidden_effects_desc
            Threshold  3
    
    
        Level Hidden4
            Description Hidden_desc
            EffectsDescription Hidden_effects_desc
            Threshold  4
    		
        Level Hidden5
            Description Hidden_desc
            EffectsDescription Hidden_effects_desc
            Threshold  5
    
    
    Trigger VictoriesThisTurn_Gain
    	WhenToTest PostBattle
    	
        Condition IsGeneral
    		  and CharacterIsLocal
    
    
    	Affects VictoriesThisTurn  1  Chance  100
    campaign_script.txt

    Code:
    monitor_event FactionTurnStart TrueCondition 
    	and FactionIsLocal
    	and FactionType thrace
    	
    	for_each character in faction "thrace"
    	
    		if Trait VictoriesThisTurn > 0
    			
    			declare_counter victories_this_turn
    			set_counter victories_this_turn 0
    			
    			if Trait VictoriesThisTurn = 1
    				set_counter victories_this_turn 1
    				console_command give_trait_points "local" VictoriesThisTurn -1
    			end_if
    			if Trait VictoriesThisTurn = 2
    				set_counter victories_this_turn 2
    				console_command give_trait_points "local" VictoriesThisTurn -2
    			end_if
    			if Trait VictoriesThisTurn = 3
    				set_counter victories_this_turn 3
    				console_command give_trait_points "local" VictoriesThisTurn -3
    			end_if
    			if Trait VictoriesThisTurn = 4
    				set_counter victories_this_turn 4
    				console_command give_trait_points "local" VictoriesThisTurn -4
    			end_if
    			if Trait VictoriesThisTurn = 5
    				set_counter victories_this_turn 5
    				console_command give_trait_points "local" VictoriesThisTurn -5
    			end_if
    			
    			for_each unit in character
    				declare_counter experience                                             
    				retrieve_counter unit_experience unit experience
    
    
    				declare_counter new_experience
    				
    				counter_operation new_experience = victories_this_turn + experience 
    				
    				store_counter new_experience unit unit_experience  
    			end_for
    			
    		end_if
    	end_for
    	
    	for_each settlement in faction "thrace"
    	
    		for_each character in settlement
    			
    			if Trait VictoriesThisTurn > 0
    			
    				declare_counter victories_this_turn
    				set_counter victories_this_turn 0
    				
    				if Trait VictoriesThisTurn = 1
    					set_counter victories_this_turn 1
    					console_command give_trait_points "local" VictoriesThisTurn -1
    				end_if
    				if Trait VictoriesThisTurn = 2
    					set_counter victories_this_turn 2
    					console_command give_trait_points "local" VictoriesThisTurn -2
    				end_if
    				if Trait VictoriesThisTurn = 3
    					set_counter victories_this_turn 3
    					console_command give_trait_points "local" VictoriesThisTurn -3
    				end_if
    				if Trait VictoriesThisTurn = 4
    					set_counter victories_this_turn 4
    					console_command give_trait_points "local" VictoriesThisTurn -4
    				end_if
    				if Trait VictoriesThisTurn = 5
    					set_counter victories_this_turn 5
    					console_command give_trait_points "local" VictoriesThisTurn -5
    				end_if
    				
    				for_each unit in character
    					declare_counter experience                                             
    					retrieve_counter unit_experience unit experience
    
    
    					declare_counter new_experience
    					
    					counter_operation new_experience = victories_this_turn + experience 
    					
    					store_counter new_experience unit unit_experience  
    				end_for
    			
    			end_if
    		end_for
    	end_for
    	
    end_monitor
    
    
    monitor_event FactionTurnStart TrueCondition 
    	and FactionIsLocal
    	and FactionType thrace 
    	
    	declare_counter max_veterancy_per_unit
    	set_counter max_veterancy_per_unit 4
    	
    	declare_counter default_veterancy_per_unit
    	set_counter default_veterancy_per_unit 1
    	
    	declare_counter zero
    	set_counter zero 0
    	
    	for_each settlement in faction
    	
    		if not HasResource epeirosMercenaryThessalian
    			and SettlementBuildingExists >= epirote_mercenary_colony
    			
    			declare_counter thessalian_veterancy                                             
    			retrieve_counter settlement_thessalian_veterancy settlement thessalian_veterancy    
    				
    			for_each unit in settlement 
    				if UnitType thessalian merc
    					declare_counter experience                                             
    					retrieve_counter unit_experience unit experience    
    					
    					declare_counter veterancy_change
    					if I_CompareCounter experience < 4 
    						counter_operation veterancy_change = default_veterancy_per_unit + experience 
    					end_if
    					if I_CompareCounter experience >= 4 
    						counter_operation veterancy_change = default_veterancy_per_unit + max_veterancy_per_unit 
    					end_if
    					
    					declare_counter old_thessalian_veterancy
    					counter_operation old_thessalian_veterancy = thessalian_veterancy + zero
    					
    					counter_operation thessalian_veterancy = veterancy_change + old_thessalian_veterancy
    				end_if
    			end_for
    			
    			store_counter thessalian_veterancy settlement settlement_thessalian_veterancy 
    			
    			if I_CompareCounter thessalian_veterancy >= 4
    				
    				add_hidden_resource local epeirosMercenaryThessalian
    			end_if
    			
    		end_if
    	end_for
    end_monitor
    The gist of this code is that a character winning battles will increase points in a trait that is later used to increment the character's units' experience. When those units stay in a settlement with the right buildings, it increments that settlement's counter regarding the specific unit that's settling there. More veteran units will give more points in the counter per turn. Upon completion, a hidden resource is added activating recruitment.

    The missing link is that "store_counter unit" doesn't seem to actually store anything in the unit. This store_counter command works with settlements and factions, but not units for some reason. Any help is appreciated

  3. #3
    alhoon's Avatar Comes Rei Militaris
    took an arrow to the knee

    Join Date
    Apr 2008
    Location
    Chania, Greece
    Posts
    24,785

    Default Re: [Untested] Discharged Veterans System

    This is good but I am not sure the issue is that the script doesn't store the counter. It could be that, but it could be something else. For example, you declare the counter again every battle. Does this perhaps resets the counter?
    alhoon is not a member of the infamous Hoons: a (fictional) nazi-sympathizer KKK clan. Of course, no Hoon would openly admit affiliation to the uninitiated.
    "Angry Uncle Gordon" describes me well.
    _______________________________________________________
    Beta-tester for Darthmod Empire, the default modification for Empire Total War that does not ask for your money behind patreon.
    Developer of Causa Belli submod for Darthmod, headed by Hammeredalways and a ton of other people.
    Developer of LtC: Random maps submod for Lands to Conquer (that brings a multitude of random maps and other features).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •