Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.62 KB | None | 0 0
  1. function refrence(path, file)
  2.     local explodedPath = explode([[\]], path)
  3.    
  4.     local ref = file.GameData
  5.     local refT = file._TYPE.GameData
  6.     for i = 1, table.getn(explodedPath) do
  7.         if type(ref[explodedPath[i]] == "table") then
  8.             ref = ref[explodedPath[i]]
  9.             refT = refT[explodedPath[i]]
  10.         else
  11.             print("false")
  12.         end
  13.     end
  14.     return {ref, refT}
  15. end
  16.  
  17. function Shorten(file)
  18.     return file.GameData, file._TYPE.GameData
  19. end
  20.  
  21.  
  22. function insert_entry(path, openFile, info, refFile, baseFile)
  23.     if not runInit then
  24.         runInit = 0
  25.     end
  26.     runInit = runInit + 1
  27.     local exist = 0
  28.     for k,v in pairs(openFile[1]) do
  29.         if k == info[1] then
  30.             exist = exist + 1
  31.         end
  32.     end
  33.     local name
  34.     if exist > 0 then
  35.        
  36.         name = [[&]] .. info[1] .. [[_]] .. exist
  37.     else
  38.         name = info[1]
  39.     end
  40.     print(name)
  41.     openFile[1][name] = refrence(path, refFile)[1]
  42.     openFile[2][name] = refrence(path, refFile)[2]
  43.    
  44.     for k,v in pairs(info) do
  45.         if type(k) ~= "number" then
  46.             print(k)
  47.             openFile[1][name][k] = v
  48.         end
  49.     end
  50.    
  51. end
  52.  
  53.  
  54.  
  55. function explode(div, str)
  56.     if (div=='') then return false end
  57.     local pos,arr = 0,{}
  58.     -- run for each divider found
  59.     for st,sp in function() return string.find(str,div,pos,true) end do
  60.         table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
  61.         pos = sp + 1 -- Jump past current divider
  62.     end
  63.     table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
  64.     return arr
  65. end
  66.  
  67. loadfile([[C:\Program Files\Steam\steamapps\common\dawn of war 2\test\Macros\lua\utils.lua]])
  68.  
  69. modname = [[test]]
  70. base = compiler_get_source_dir() .. modname .. [[\DataAttrib\simulation\attrib\]]
  71. -- table with all details in it
  72. local UCS_start = 0
  73. local tier2 = [[upgrade\_game\menu\tier_2]]
  74. local tier3 = [[upgrade\_game\menu\tier_3]]
  75. local backIcon = [[icon]]
  76.  
  77. local t =
  78. {
  79.     Menus =
  80.     {
  81.         top_level =
  82.         {
  83.             baseSavePath = base .. [[sbps\_game\menu\]],
  84.             relativePath = [[_game\menu\]],
  85.             iconPath = [[]],
  86.             {"hq", tier1, 1, [[icon]]},
  87.             {"troop",tier1, 2, [[icon]]},
  88.             {"elite",tier1, 3, [[icon]]},
  89.             {"fast_attack",tier1, 4, [[icon]]},
  90.             {"heavy_support",tier1, 5, [[icon]]},
  91.         },
  92.     },
  93.     Units = {
  94.     space_marines =
  95.     {
  96.         basePath = base .. [[sbps\_space_marines\menu]],
  97.         iconPath = [[]],
  98.         {"tactical_space_marines", "troop"},
  99.         {"scout_marines", "troop"},
  100.         {"captain", "hq"},
  101.     },
  102. },
  103. }
  104. local ucs = {}
  105.  
  106. -- load up the refrence file
  107. ref = compiler_load_rbf([[::simulation\attrib\refrence.rbf]])
  108.  
  109.  
  110.  
  111. function create_base_squad_file(file)
  112.     -- add the tables we need
  113.     local top = file.GameData
  114.     local topT = file._TYPE.GameData
  115.    
  116.     -- squad_loadout_ext
  117.     top.squad_loadout_ext = refrence([[squad_extentions\squad_loadout_ext]], ref)[1]
  118.     topT.squad_loadout_ext = refrence([[squad_extentions\squad_loadout_ext]], ref)[2]
  119.    
  120.     -- adding the unit
  121.     local info = {"squad_loadout_unit_entry" ,["type"] = [[ebps\_game\invisible_entity]]}
  122.     local files = {top.squad_loadout_ext.unit_list, topT.squad_loadout_ext.unit_list}
  123.     insert_entry([[entries\unit_list\squad_loadout_unit_entry]], files, info, ref)
  124.    
  125.     -- squad requirments
  126.     top.squad_requirement_ext = refrence([[squad_extentions\squad_requirement_ext]], ref)[1]
  127.     topT.squad_requirement_ext = refrence([[squad_extentions\squad_requirement_ext]], ref)[2]
  128.    
  129.     -- squad_UI
  130.     top.squad_ui_ext = refrence([[squad_extentions\squad_ui_ext]], ref)[1]
  131.     topT.squad_ui_ext = refrence([[squad_extentions\squad_ui_ext]], ref)[2]
  132. end
  133.  
  134. function create_base_lock_out_upgrade(file)
  135.     local top = file.GameData
  136.     local topT = file._TYPE.GameData
  137.    
  138.     -- load the bag
  139.     top.upgrade_bag = refrence([[bags\upgrade_bag]], ref)[1]
  140.     topT.upgrade_bag = refrence([[bags\upgrade_bag]], ref)[2]
  141. end
  142.  
  143.  
  144.  
  145. local UCS1, UCS2
  146. local openUPGS = {}
  147. -- first make the menus
  148. for k,v in pairs(t.Menus) do
  149.     for i = 1, table.getn(v) do
  150.         -- first we need to make ALL the open upgs
  151.         -- load blank file
  152.         openUpgrade = compiler_load_rbf([[::simulation\attrib\blank_file.rbf]])
  153.         -- create the base file
  154.         create_base_lock_out_upgrade(openUpgrade)
  155.         -- create its path
  156.         local upgRelative = [[upgrade\]] .. v.relativePath .. v[i][1] .. [[_open]]
  157.         local upgSavePath = base .. upgRelative .. [[.rbf]]
  158.        
  159.         -- insert into table
  160.         openUPGS[v[i][1]] = {save = upgSavePath, relative = upgRelative}
  161.         -- create upg
  162.         compiler_make_rbf(openUpgrade, upgSavePath)
  163.        
  164.         -- create ability that removes upg
  165.         -- *********************TO DO!!!!!!!!!!!!!!!!!**************************
  166.     end
  167.     for i = 1, table.getn(v) do
  168.         if not UCS2 then
  169.             UCS1 = UCS_start
  170.             UCS2 = UCS1 + 1
  171.         else
  172.             UCS1 = UCS2 + 1
  173.             UCS2 = UCS1 + 1
  174.         end
  175.        
  176.         -- load up the blank_file
  177.         squadFile = compiler_load_rbf([[::simulation\attrib\blank_file.rbf]])
  178.         -- create the base
  179.         create_base_squad_file(squadFile)
  180.        
  181.         local top = squadFile.GameData
  182.         local topT = squadFile._TYPE.GameData
  183.         -- add the tier requirement if needed
  184.         if v[i][2] then
  185.            
  186.         end
  187.        
  188.         -- add icon path
  189.         top.squad_ui_ext.icon_name = v[i][4]
  190.         -- add UCS entries
  191.         top.squad_ui_ext.squad_name = UCS1
  192.         top.squad_ui_ext.screen_name = UCS1
  193.         top.squad_ui_ext.help_text = UCS2
  194.        
  195.        
  196.         -- loop through the created open UPGS and have it require NON of them to be present
  197.         for menuName,value in pairs(openUPGS) do
  198.             print(value.relative)
  199.             -- insert a requirement into the sbps
  200.             local info =
  201.             {
  202.                 "required_player_upgrade",
  203.                 is_present = false,
  204.                 reason = [[display_and_usage_and_produce]],
  205.                 upgrade_name = value.relative
  206.             }
  207.             local files = {top.squad_requirement_ext.requirement_table, topT.squad_requirement_ext.requirement_table}
  208.             insert_entry([[requirements\required_player_upgrade]], files, info, ref)
  209.         end
  210.        
  211.         -- create file
  212.         local savePath = v.baseSavePath .. v[i][1] .. [[.rbf]]
  213.         compiler_make_rbf(squadFile, savePath)
  214.        
  215.         -- create back squad
  216.         --- ****** TO DO *!!!!!!************************
  217.     end
  218. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement