making factions always at war...

Users who are viewing this thread

HokieBT

Grandmaster Knight
Ok, I need the Rebel Alliance and Galactic Empire always to be at war in my Star Wars mod.... I have attempted to force these factions to always be at war many times in the past without any success, so am looking for other suggestions...

previously I had tried this concept...

added to "game_start" in module_scripts.py
Code:
	  #SW - uncommented so kingdom1 will always start at war with kingdom2 (added a 1 at the end to fixed script error, since its the war/peace flag)
		#(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_1", "fac_kingdom_2",1),


the bottom of "randomly_start_war_peace" in module_scripts.py looks like this so they couldn't randomly declare peace
Code:
				#------------------------------------------------------------------------------------------------------
				#SW - trying to make it so empire and rebel can't declare peace
				(try_begin),
					(eq, ":cur_kingdom", fac_kingdom_1),
					(eq, ":cur_kingdom_2", fac_kingdom_2),
						(assign, ":continue", 0),
				(try_end),
				(try_begin),
					(eq, ":cur_kingdom", fac_kingdom_2),
					(eq, ":cur_kingdom_2", fac_kingdom_1),
						(assign, ":continue", 0),
				(try_end),				
				#------------------------------------------------------------------------------------------------------

              (try_end),
              (eq, ":continue", 1),
              (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),


However, this doesn't seem to work 100% correctly....?  does the logic in the code I added to flip the continue flag seem ok?


For the next release of my mod I'm thinking about trying some other concepts....

1) switch the declare war from game_start to once the game is loaded by adding the following to module_triggers.py
Code:
  (0.2, 0, ti_once, [(map_free,0)], [
										#SW - added so kingdom1 will always start at war with kingdom2 (added a 1 at the end to fixed script error, since its the war/peace flag)
										(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_1", "fac_kingdom_2",1)
									]),


2) I'm thinking about adding a trigger every 24 hours to lower the relationship between those two factions?  does anybody know what the code for this would be or how much I should lower the relationship every time?  Or should I check the current relationship and lower it if it is greater then -0.5 or something like that?


3) I also want to add a trigger every 24 hours that will check if they are not at war and declare one if necessary.  I tried adding the following code to module_simple_triggers.py but it gave a popup every 24 hours, so that doesn't work so I'd need to determine if they are currently at war and then only trigger that script if necessary....

Code:
#  #SW - make sure faction1 (empire) and faction2 (rebel) are always at war (popup appears every time unfortunately, even if they are at war)
#  (24,
#   [
#     (call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_1", "fac_kingdom_2",1),
#    ])


4) I was thinking about completely eliminating the logic in the "randomly_start_war_peace" in module_scripts.py since I only have 3 factions and two of them should always be at war.  So I could make it really simple and just give a random chance of the 3rd faction declaring war/peace with one of the other two factions.... ?    But I'd probably need a way to check if that 3rd faction was already at war with somebody since it doesn't make sense for them to start a 2nd war....  It looks like the top part of the code for this script would be helpful since it calculates the number of ongoing wars.  So I could use this type of code to check how many wars they currently had going on and declare one if necessary.  But I don't know if I'm going to mess up the AI if I eliminate all the other logic in this script.....

Code:
      (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
 ##       (neq, ":cur_kingdom", "fac_player_supporters_faction"),
        (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
        (assign, ":num_ongoing_wars", 0),
        (try_for_range, ":other_kingdom", kingdoms_begin, kingdoms_end),
          (faction_slot_eq, ":other_kingdom", slot_faction_state, sfs_active),
          (store_relation, ":other_relation", ":cur_kingdom", ":other_kingdom"),
          (lt, ":other_relation", 0),
          (val_add, ":num_ongoing_wars", 1),
        (try_end),


Anyway, my coding skill aren't great and I'm at a loss here on the best way to fix this issue.  any suggestions would be appreciated.  thanks!

 
I think you're on the right track.  Sorry for the wall 'o text.

I'm surprised that your code changes in randomly_start_war_peace didn't work (you might try putting the faction names in quotes; dunno if it'll do the right bitmath on those).  Taking out the trigger that calls randomly_start_war_peace should be fine (with the normal caveats of dealing with triggers, anyway).  Hacking it up to do what you want is also probably OK.  I don't believe that function sets anything up for the AI directly. 

Adding a trigger that keeps relations low would ensure that they never get back to peace but it might not be necessary.  Faction relations are between -100 and 100 as far as I know.  Set war/peace in game_start rather than a map trigger.  There's already a place where they start random wars.

If it were me, I'd hack up the randomly_start_war_peace function to do exactly what I wanted.  Checking to see if two factions are at war is as simple as checking to see if their faction relation is less than zero.  Other than player interaction, I don't think that faction relation changes all that much outside of war/peace declarations. 
 
ok, I tried to hack up script_randomly_start_war_peace....  My python skill is very limited, this compiles and seems like it should work, but if somebody can read it and let me know if there are any logic errors or I can make it more efficient then let me know.  :wink:

My concept is basically
- there is a trigger that calls this script once a week
- there are only 3 factions in my mod (empire=1, rebel=2, hutt=3)
- if empire & rebel are at peace then a war is always declared
- if hutt is fighting 2 wars then peace is declared with one of the factions
- if hutt is fighting 1 war then there is a 25% chance of peace
- if hutt is fighting 0 wars then there is a 25% chance of war

Code:
  # script_randomly_start_war_peace
  # Input: arg1 = initializing_war_peace_cond (1 = true, 0 = false)
  # Output: none
  ("randomly_start_war_peace",
    [
	
	#-----------------------------------------------------------------------------------------------------------------------------	  
	#SW new (more basic) randomly_start_war_peace script (faction_1 = empire, faction_2 = rebel, faction_3 = hutt)
	
	#workaround to prevent script errors?
	(store_script_param_1, ":initializing_war_peace_cond"),
	(assign, ":initializing_war_peace_cond", 1),
	
	#get current faction relations
	(store_relation,":empire_rebel_relation","fac_kingdom_1","fac_kingdom_2"),
	(store_relation,":hutt_empire_relation","fac_kingdom_3","fac_kingdom_1"),
	(store_relation,":hutt_rebel_relation","fac_kingdom_3","fac_kingdom_2"),
	
	#rebel/empire code
	(try_begin),
	  (ge, ":empire_rebel_relation", 0),		#make sure empire and rebel are always at war
	  (call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_1", "fac_kingdom_2",":initializing_war_peace_cond"),
	(try_end),
	
	#hutt faction code
	#get total wars
	(assign, ":num_hutt_ongoing_wars", 0),
	(try_begin),
		(lt, ":hutt_empire_relation", 0),
		(val_add, ":num_hutt_ongoing_wars", 1),		
	(try_end),
	(try_begin),
		(lt, ":hutt_rebel_relation", 0),
		(val_add, ":num_hutt_ongoing_wars", 1),		
	(try_end),
	
	#hutt war/peace logic
	(try_begin),
		(ge, ":num_hutt_ongoing_wars", 2),	#hutt is small and can't handle two wars at once, force peace
		(store_random_in_range, ":random_no", 0, 100),
		(try_begin),
			(le, ":random_no", 50), 	#50% chance of forced peace with empire
			(call_script, "script_diplomacy_start_peace_between_kingdoms", "fac_kingdom_3", "fac_kingdom_1",":initializing_war_peace_cond"),
		(else_try),
			#60% chance of forced peace with rebel
			(call_script, "script_diplomacy_start_peace_between_kingdoms", "fac_kingdom_3", "fac_kingdom_2",":initializing_war_peace_cond"),
		(try_end),
	(else_try),
		(eq, ":num_hutt_ongoing_wars", 1),	#hutt is small and may want to make peace with the faction they are at war with
		(store_random_in_range, ":random_no", 0, 100),
		(try_begin),
			(le, ":random_no", 25), 	#25% chance of peace
			(try_begin),
				(lt, ":hutt_empire_relation", 0),
				(call_script, "script_diplomacy_start_peace_between_kingdoms", "fac_kingdom_3", "fac_kingdom_1",":initializing_war_peace_cond"),
			(try_end),
			(try_begin),
				(lt, ":hutt_rebel_relation", 0),
				(call_script, "script_diplomacy_start_peace_between_kingdoms", "fac_kingdom_3", "fac_kingdom_2",":initializing_war_peace_cond"),
			(try_end),	
		(try_end),
	(else_try),
		# hutt is small but has a chance of declaring war on a faction
		(store_random_in_range, ":random_no", 0, 100),
		(try_begin),
			(le, ":random_no", 25), 	#25% chance of war
			(store_random_in_range, ":random_no", 0, 100),
			(try_begin),
				(le, ":random_no", 50),		#50% chance of war with empire
				(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_3", "fac_kingdom_1",":initializing_war_peace_cond"),
			(else_try),
				(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_3", "fac_kingdom_2",":initializing_war_peace_cond"),			
			(try_end),
		(try_end),
		
	#-----------------------------------------------------------------------------------------------------------------------------
  ]),
 
That looks pretty good (bonus points for commenting your intentions).  I'm not seeing anything obviously wrong with it, though I'll point out a stylistic thing.

Assuming the rebels and empire start at war, I'd probably change your rebel/empire war block to just set the faction relation to -40 if they ever get above that.  I'm not sure what would even change that value beyond player muckery.  This way you wouldn't get a weird "the Empire and the Rebel Alliance are now at war!" message unexpectedly.
 
LordOfShadows said:
on the same idea would it be possible to make it that two or three specific factions shouldn't fight each other?
Yes.  If you hack up randomly_start_war_peace, you should be able to get it to do whatever you want.
 
thanks for the comments.  Empire & Rebel should start at war, but I think there are a few spots in the code where they might be able to make peace that I haven't taken out yet (like quests).  So this is somewhat a safety where if they make peace somehow, then this would fix it a week later...  I tested this by added some display messages and running the trigger every hour of game time and it seems to work fine (I had one spelling error in my code I fixed in the above code).  The only issue seems to be the "store_random_in_range" doesn't seem to be all that random (which I think people have discussed before), since 25% seem to happen quite often.  So I lowered it to 5-10% range and it seems to be working well enough....

 
HokieBT said:
the bottom of "randomly_start_war_peace" in module_scripts.py looks like this so they couldn't randomly declare peace
Code:
				#------------------------------------------------------------------------------------------------------
				#SW - trying to make it so empire and rebel can't declare peace
				(try_begin),
					(eq, ":cur_kingdom", fac_kingdom_1),
					(eq, ":cur_kingdom_2", fac_kingdom_2),
						(assign, ":continue", 0),
				(try_end),
				(try_begin),
					(eq, ":cur_kingdom", fac_kingdom_2),
					(eq, ":cur_kingdom_2", fac_kingdom_1),
						(assign, ":continue", 0),
				(try_end),				
				#------------------------------------------------------------------------------------------------------

              (try_end),
              (eq, ":continue", 1),
              (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
When it Compile it Says
http://oi52.tinypic.com/2hdbix3.jpg
 
Back
Top Bottom