Advertisement
Guest User

Untitled

a guest
Jul 29th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. ---------------------------------------------------------------------------------------------------------
  2. ---------------------------------------------------------------------------------------------------------
  3. ----- Name:         Havie Commander Satisfaction
  4. ----- Description:  Adds a loyalty modifier to those who wish to command an army, and those who already are
  5. -----              
  6. -----           Had to use global table to do so
  7. ---------------------------------------------------------------------------------------------------------
  8. ---------------------------------------------------------------------------------------------------------
  9.  
  10. local function CusLog(text)
  11.     if type(text) == "string" then
  12.         local file = io.open("@sat_havie_commander.txt", "a")
  13.         local temp = os.date("*t") -- now ?
  14.         local time= ("["..tostring(temp.min)..":"..tostring(temp.sec)..tostring(os.clock() - startTime1).."] ")
  15.         local line= time..text
  16.         local header=" (sat_commander): "
  17.         local line= time..header..text
  18.         file:write(line.."\n")
  19.         file:close()
  20.         ModLog(header..text)
  21.     end
  22. end
  23.  
  24.  
  25.  
  26.  
  27.  local commander_personalities  = {
  28.     ["3k_main_ceo_trait_personality_ambitious"] = true,
  29.     ["3k_main_ceo_trait_personality_determined"] = true,
  30.     ["3k_main_ceo_trait_personality_greedy"] = true,
  31.     ["3k_main_ceo_trait_personality_brave"] = true,
  32.     ["3k_main_ceo_trait_personality_competative"] = true,
  33.     ["3k_main_ceo_trait_personality_direct"] = true,
  34.     ["3k_main_ceo_trait_personality_distinguished"] = true,
  35.     ["3k_main_ceo_trait_personality_reckless"] = true,
  36.     ["3k_main_ceo_trait_personality_dutiful"] = true,
  37.     ["3k_main_ceo_trait_personality_vengeful"] = true
  38.  
  39. }
  40.  
  41. local function WhosCommandingListener()
  42.     CusLog("### WhosCommandingListener loading ###")
  43.     core:add_listener(
  44.         "WhosCommanding",
  45.         "FactionTurnEnd",
  46.         function(context)
  47.             return context:faction():military_force_list():num_items() >1
  48.         end,
  49.         function(context)
  50.             local desires_command = {}
  51.             local commanders = {}
  52.             --First we get all the current commanders
  53.             for i=0 , context:faction():military_force_list():num_items() -1 do
  54.                 local m_force= context:faction():military_force_list():item_at(i)
  55.                 if not (m_force:is_armed_citizenry()) then
  56.                    local qgeneral= m_force:character_list():item_at(0) --this guys a commander, so add him to the list of total commanders
  57.                     commanders[tostring(qgeneral:cqi())] =true
  58.                 end
  59.             end
  60.             --Second we find who desires command
  61.             for i=0, context:faction():character_list():num_items()-1 do
  62.                 local qgeneral= context:faction():character_list():item_at(i)
  63.                 local ceo_manager= qgeneral:ceo_management()
  64.                 for i=0, ceo_manager:all_ceos_for_category("3k_main_ceo_category_traits_personality"):num_items()-1 do
  65.                     local trait= ceo_manager:all_ceos_for_category("3k_main_ceo_category_traits_personality"):item_at(i):ceo_data_key()
  66.                     local should_add=false;
  67.                     if commander_personalities[tostring(trait)] and desires_command[tostring(qgeneral:cqi())] ~= true then
  68.                         should_add=true
  69.                     elseif qgeneral:character_subtype_key() =="3k_general_earth" and desires_command[tostring(qgeneral:cqi())] ~= true then
  70.                         -- chance earth generals auto desire command
  71.                         local rolled_value = cm:random_number( 0, 6 );
  72.                         should_add= rolled_value >2
  73.                     end
  74.                     if should_add then
  75.                         table.insert(desires_command,tostring(qgeneral:cqi())); --add this commander to our list
  76.                      end
  77.                 end
  78.  
  79.             end
  80.  
  81.             for key, v in pairs(desires_command) do
  82.                 local mchar = cm:modify_character(tonumber(key))
  83.                 if commanders[tostring(key)] then
  84.                     if not (mchar:is_null_interface()) then
  85.                         mchar:add_loyalty_effect("command_pos");
  86.                     end
  87.                 else
  88.                     if not (mchar:is_null_interface()) then
  89.                         mchar:add_loyalty_effect("command_neg");
  90.                     end
  91.                    
  92.                 end
  93.             end
  94.         end,
  95.         true
  96.     )
  97. end
  98.  
  99.  
  100. -- when the game loads run these functions:
  101. cm:add_first_tick_callback(
  102.     function(context)
  103.         WhosCommandingListener()
  104.     end
  105. )
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement