Advertisement
Rogue-9

Untitled

Jun 26th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 76.52 KB | None | 0 0
  1. -- X-Wing Automatic Movement - Hera Verito (Jstek), March 2016
  2. -- X-Wing Arch and Range Ruler - Flolania, March 2016
  3. -- X-Wing Auto Dial Integration - Flolania, March 2016
  4. -- X-Wing AI Auto movement - Valadian, April 2016
  5. -- X-Wing temporary AI Autotarget accuracy improvement - Rogue-9, June 2016
  6.  
  7.  
  8. function onload()
  9. --Auto Movement
  10. undolist = {}
  11. undopos = {}
  12. undorot = {}
  13. namelist1 = {}
  14. locktimer = {}
  15.  
  16. --Auto Dials
  17. --dial information
  18. dialpositions = {}
  19.  
  20. -- Auto Actions
  21. focus = 'beca0f'
  22. evade = '4a352e'
  23. stress = 'a25e12'
  24.  
  25. -- AI
  26. aitype = {}
  27. striketarget = nil
  28. aicardguid = '2d84be'
  29. squadleader = {}
  30. squadmove = {}
  31. squadposition = {}
  32. squadrotation = {}
  33. aimove = {}
  34. aiswerved = {}
  35. aitargets = {}
  36. aistressed = {}
  37. -- Auto Setup
  38. missionzone = 'be00ff'
  39. mission_ps = nil
  40. mission_players = nil
  41. players_up_next = {}
  42. players_up_next_delay = 0
  43. ai_stress = false
  44. ai_stress_delay = 0
  45. aicard = getObjectFromGUID(aicardguid)
  46. current = nil
  47. currentPhase = nil
  48. if aicard then
  49. local prebutton = {['click_function'] = 'Action_PreMovePhase', ['label'] = 'Start Turn', ['position'] = {0, 0.3, -1.5}, ['rotation'] = {0, 0, 0}, ['width'] = 1200, ['height'] = 400, ['font_size'] = 250}
  50. aicard.createButton(prebutton)
  51.  
  52. local flipbutton = {['click_function'] = 'Action_MovePhase', ['label'] = 'Activation', ['position'] = {0, 0.3, -0.5}, ['rotation'] = {0, 0, 0}, ['width'] = 1200, ['height'] = 400, ['font_size'] = 250}
  53. aicard.createButton(flipbutton)
  54.  
  55. local attackbutton = {['click_function'] = 'Action_AttackPhase', ['label'] = 'Combat', ['position'] = {0, 0.3, 0.5}, ['rotation'] = {0, 0, 0}, ['width'] = 1200, ['height'] = 400, ['font_size'] = 250}
  56. aicard.createButton(attackbutton)
  57.  
  58. local clearbutton = {['click_function'] = 'Action_ClearAi', ['label'] = 'Clear AI', ['position'] = {0, 0.3, 1.5}, ['rotation'] = {0, 0, 0}, ['width'] = 1200, ['height'] = 400, ['font_size'] = 250}
  59. aicard.createButton(clearbutton)
  60. end
  61. end
  62.  
  63. function PlayerCheck(Color, GUID)
  64. return true
  65. -- local PC = false
  66. -- if getPlayer(Color) ~= nil then
  67. -- HandPos = getPlayer(Color).getPointerPosition()
  68. -- DialPos = getObjectFromGUID(GUID).getPosition()
  69. -- if distance(HandPos['x'],HandPos['z'],DialPos['x'],DialPos['z']) < 2 then
  70. -- PC = true
  71. -- end
  72. -- end
  73. -- return PC
  74. end
  75. function onObjectLeaveScriptingZone(zone, object)
  76. if zone.getGUID() == '183284' and object.tag == 'Card' and object.getName():match '^Mission: (.*)' then
  77. object.clearButtons()
  78. end
  79. if object.tag == 'Card' and object.getDescription() ~= '' then
  80. CardData = dialpositions[CardInArray(object.GetGUID())]
  81. if CardData ~= nil then
  82. obj = getObjectFromGUID(CardData["ShipGUID"])
  83. if obj.getVar('HasDial') == true then
  84. printToColor(CardData["ShipName"] .. ' already has a dial.', object.held_by_color, {0, 0, 1})
  85. else
  86. obj.setVar('HasDial', true)
  87. CardData["Color"] = object.held_by_color
  88.  
  89. local flipbutton = {['click_function'] = 'CardFlipButton', ['label'] = 'Flip', ['position'] = {0, -1, 1}, ['rotation'] = {0, 0, 180}, ['width'] = 750, ['height'] = 550, ['font_size'] = 250}
  90. object.createButton(flipbutton)
  91. local deletebutton = {['click_function'] = 'CardDeleteButton', ['label'] = 'Delete', ['position'] = {0, -1, -1}, ['rotation'] = {0, 0, 180}, ['width'] = 750, ['height'] = 550, ['font_size'] = 250}
  92. object.createButton(deletebutton)
  93.  
  94. object.setVar('Lock',true)
  95. end
  96. else
  97. printToColor('That dial was not saved.', object.held_by_color, {0, 0, 1})
  98. end
  99. end
  100. end
  101.  
  102. function CardInArray(GUID)
  103. CIAPos = nil
  104. for i, card in ipairs(dialpositions) do
  105. if GUID == card["GUID"] then
  106. CIAPos = i
  107. end
  108. end
  109. return CIAPos
  110. end
  111.  
  112. function CardFlipButton(object)
  113. CardData = dialpositions[CardInArray(object.GetGUID())]
  114. if PlayerCheck(CardData["Color"],CardData["GUID"]) == true then
  115. rot = getObjectFromGUID(CardData["ShipGUID"]).getRotation()
  116. object.setRotation({0,rot[2],0})
  117. object.clearButtons()
  118. local movebutton = {['click_function'] = 'CardMoveButton', ['label'] = 'Move', ['position'] = {0, 1, '.9'}, ['rotation'] = {0, 0, 0}, ['width'] = 750, ['height'] = 550, ['font_size'] = 250}
  119. object.createButton(movebutton)
  120. end
  121. end
  122.  
  123.  
  124. function CardMoveButton(object)
  125. CardData = dialpositions[CardInArray(object.GetGUID())]
  126. if PlayerCheck(CardData["Color"],CardData["GUID"]) == true then
  127. check(CardData["ShipGUID"],object.getDescription())
  128. object.clearButtons()
  129.  
  130. local deletebutton = {['click_function'] = 'CardDeleteButton', ['label'] = 'Delete', ['position'] = {'-.35', 1, 1}, ['rotation'] = {0, 0, 0}, ['width'] = 750, ['height'] = 650, ['font_size'] = 250}
  131. object.createButton(deletebutton)
  132.  
  133. local undobutton = {['click_function'] = 'CardUndoButton', ['label'] = 'q', ['position'] = {'-.9', 1, -1}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  134. object.createButton(undobutton)
  135.  
  136. local focusbutton = {['click_function'] = 'CardFocusButton', ['label'] = 'F', ['position'] = {'.9', 1, -1}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  137. object.createButton(focusbutton)
  138.  
  139. local stressbutton = {['click_function'] = 'CardStressButton', ['label'] = 'S', ['position'] = {'.9', 1, 0}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  140. object.createButton(stressbutton)
  141.  
  142. local evadebutton = {['click_function'] = 'CardEvadeButton', ['label'] = 'E', ['position'] = {'.9', 1, 1}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  143. object.createButton(evadebutton)
  144.  
  145. end
  146. end
  147.  
  148. function CardFocusButton(object)
  149. CardData = dialpositions[CardInArray(object.GetGUID())]
  150. if PlayerCheck(CardData["Color"],CardData["GUID"]) == true then
  151. take(focus, CardData["ShipGUID"],-0.3,1,-0.3)
  152. notify(CardData["ShipGUID"],'action','takes a focus token')
  153. end
  154. end
  155.  
  156. function CardStressButton(object)
  157. CardData = dialpositions[CardInArray(object.GetGUID())]
  158. if PlayerCheck(CardData["Color"],CardData["GUID"]) == true then
  159. take(stress, CardData["ShipGUID"],0.3,1,0.3)
  160. notify(CardData["ShipGUID"],'action','takes stress')
  161. end
  162. end
  163.  
  164. function CardEvadeButton(object)
  165. CardData = dialpositions[CardInArray(object.GetGUID())]
  166. if PlayerCheck(CardData["Color"],CardData["GUID"]) == true then
  167. take(evade, CardData["ShipGUID"],-0.5,1,0.5)
  168. notify(CardData["ShipGUID"],'action','takes an evade token')
  169. end
  170. end
  171.  
  172. function CardUndoButton(object)
  173. CardData = dialpositions[CardInArray(object.GetGUID())]
  174. if PlayerCheck(CardData["Color"],CardData["GUID"]) == true then
  175. check(CardData["ShipGUID"],'undo')
  176. object.removeButton(1)
  177. end
  178. end
  179.  
  180. function CardDeleteButton(object)
  181. CardData = dialpositions[CardInArray(object.GetGUID())]
  182. if PlayerCheck(CardData["Color"],CardData["GUID"]) == true then
  183. getObjectFromGUID(CardData["ShipGUID"]).setVar('HasDial',false)
  184. object.Unlock()
  185. object.clearButtons()
  186. object.setPosition (CardData["Position"])
  187. object.setRotation (CardData["Rotation"])
  188. CardData["Color"] = nil
  189. end
  190. end
  191.  
  192. function resetdials(guid,notice)
  193. obj = getObjectFromGUID(guid)
  194. local index = {}
  195. for i, card in ipairs(dialpositions) do
  196. if guid == card["ShipGUID"] then
  197. index[#index + 1] = i
  198. end
  199. end
  200. obj.setVar('HasDial',false)
  201. if notice == 1 then
  202. printToAll(#index .. ' dials removed for ' .. obj.getName() .. '.', {0, 0, 1})
  203. end
  204. for i=#index,1,-1 do
  205. table.remove(dialpositions, index[i])
  206. end
  207. setpending(guid)
  208. end
  209.  
  210. function checkdials(guid)
  211. resetdials(guid,0)
  212. obj = getObjectFromGUID(guid)
  213. count = 0
  214. display = false
  215. error = false
  216. deckerror = false
  217. for i,card in ipairs(getAllObjects()) do
  218. cardpos = card.getPosition()
  219. objpos = obj.getPosition()
  220. if distance(cardpos[1],cardpos[3],objpos[1],objpos[3]) < 5.5 then
  221. if cardpos[3] >= 18 or cardpos[3] <= -18 then
  222. if card.tag == 'Card' and card.getDescription() ~= '' then
  223. CardData = dialpositions[CardInArray(card.getGUID())]
  224. if CardData == nil then
  225. count = count + 1
  226. cardtable = {}
  227. cardtable["GUID"] = card.getGUID()
  228. cardtable["Position"] = card.getPosition()
  229. cardtable["Rotation"] = card.getRotation()
  230. cardtable["ShipGUID"] = obj.getGUID()
  231. cardtable["ShipName"] = obj.getName()
  232. cardtable["Color"] = nil
  233. obj.setVar('HasDial',false)
  234. dialpositions[#dialpositions +1] = cardtable
  235. card.setName(obj.getName())
  236. else
  237. display = true
  238. end
  239. end
  240. if card.tag == 'Deck' then
  241. deckerror = true
  242. end
  243. else
  244. error = true
  245. end
  246. end
  247. end
  248. if display == true then
  249. printToAll('Error: ' .. obj.getName() .. ' attempted to save dials already saved to another ship. Use rd on old ship first.',{0, 0, 1})
  250. end
  251. if deckerror == true then
  252. printToAll('Error: Cannot save dials in deck format.',{0, 0, 1})
  253. end
  254. if error == true then
  255. printToAll('Caution: Cannot save dials in main play area.',{0, 0, 1})
  256. end
  257. if count <= 17 then
  258. printToAll(count .. ' dials saved for ' .. obj.getName() .. '.', {0, 0, 1})
  259. else
  260. resetdials(guid,0)
  261. printToAll('Error: Tried to save to many dials for ' .. obj.getName() .. '.', {0, 0, 1})
  262. end
  263. setpending(guid)
  264. end
  265.  
  266. function distance(x,y,a,b)
  267. x = (x-a)*(x-a)
  268. y = (y-b)*(y-b)
  269. return math.sqrt(math.abs((x+y)))
  270. end
  271.  
  272. function SpawnDialGuide(guid)
  273. shipobject = getObjectFromGUID(guid)
  274. world = shipobject.getPosition()
  275. direction = shipobject.getRotation()
  276. obj_parameters = {}
  277. obj_parameters.type = 'Custom_Model'
  278. obj_parameters.position = {world[1], world[2]+0.15, world[3]}
  279. obj_parameters.rotation = { 0, direction[2], 0 }
  280. DialGuide = spawnObject(obj_parameters)
  281. custom = {}
  282. custom.mesh = 'http://pastebin.com/raw/qPcTJZyP'
  283. custom.collider = 'http://pastebin.com/raw.php?i=UK3Urmw1'
  284.  
  285. DialGuide.setCustomObject(custom)
  286. DialGuide.lock()
  287. DialGuide.scale({'.4','.4','.4'})
  288.  
  289. local button = {['click_function'] = 'GuideButton', ['label'] = 'Remove', ['position'] = {0, 0.5, 0}, ['rotation'] = {0, 270, 0}, ['width'] = 1500, ['height'] = 1500, ['font_size'] = 250}
  290. DialGuide.createButton(button)
  291. shipobject.setDescription('Pending')
  292. checkdials(guid)
  293. end
  294.  
  295. function GuideButton(object)
  296. object.destruct()
  297. end
  298.  
  299. function update ()
  300. for i,ship in ipairs(getAllObjects()) do
  301. if ship.tag == 'Figurine' and ship.name ~= '' then
  302. shipguid = ship.getGUID()
  303. shipname = ship.getName()
  304. shipdesc = ship.getDescription()
  305. checkname(shipguid,shipdesc,shipname)
  306. check(shipguid,shipdesc)
  307. end
  308. if ship.getVar('Lock') == true and ship.held_by_color == nil and ship.resting == true then
  309. ship.setVar('Lock',false)
  310. ship.lock()
  311. end
  312. end
  313. end
  314.  
  315. function round(x)
  316. return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
  317. end
  318.  
  319. function round(num, idp)
  320. if num == nil then return nil end
  321. local mult = 10^(idp or 0)
  322. if num >= 0 then return math.floor(num * mult + 0.5) / mult
  323. else return math.ceil(num * mult - 0.5) / mult end
  324. end
  325.  
  326. function take(parent, guid, xoff, yoff, zoff)
  327. obj = getObjectFromGUID(guid)
  328. objp = getObjectFromGUID(parent)
  329. world = obj.getPosition()
  330. local offset = RotateVector({xoff, yoff, zoff}, obj.getRotation()[2])
  331. local params = {}
  332. params.position = {world[1]+offset[1], world[2]+offset[2], world[3]+offset[3]}
  333. objp.takeObject(params)
  334. end
  335.  
  336. function undo(guid)
  337. if undolist[guid] ~= nil then
  338. obj = getObjectFromGUID(guid)
  339. obj.setPosition(undopos[guid])
  340. obj.setRotation(undorot[guid])
  341. setpending(guid)
  342. else
  343. obj = getObjectFromGUID(guid)
  344. setpending(guid)
  345. end
  346. obj.Unlock()
  347. end
  348.  
  349. function storeundo(guid)
  350. obj = getObjectFromGUID(guid)
  351. direction = obj.getRotation()
  352. world = obj.getPosition()
  353. undolist[guid] = guid
  354. undopos[guid] = world
  355. undorot[guid] = direction
  356. end
  357.  
  358. function registername(guid)
  359. obj = getObjectFromGUID(guid)
  360. name = obj.getName()
  361. namelist1[guid] = name
  362. setlock(guid)
  363. end
  364.  
  365. function checkname(guid,move,name)
  366. if move == 'Pending' then
  367. if namelist1[guid] == nil then
  368. namelist1[guid] = name
  369. end
  370. end
  371. end
  372.  
  373. function fixname(guid)
  374. if namelist1[guid] ~= nil then
  375. obj = getObjectFromGUID(guid)
  376. obj.setName(namelist1[guid])
  377. end
  378. end
  379.  
  380. function setpending(guid)
  381. fixname(guid)
  382. obj = getObjectFromGUID(guid)
  383. obj.setDescription('Pending')
  384. end
  385.  
  386. function setlock(guid)
  387. fixname(guid)
  388. obj = getObjectFromGUID(guid)
  389. obj.setDescription('Locking')
  390. end
  391.  
  392.  
  393. function notify(guid,move,text)
  394. if text == nil then
  395. text = ''
  396. end
  397.  
  398. local obj = getObjectFromGUID(guid)
  399. local name = obj.getName()
  400. local name = string.gsub(name,":","|")
  401. if move == 'q' then
  402. printToAll(name .. ' executed undo.', {0, 1, 0})
  403. elseif move == 'set' then
  404. printToAll(name .. ' set name.', {0, 1, 1})
  405. elseif move == 'r' then
  406. printToAll(name .. ' spawned a ruler.', {0, 0, 1})
  407. elseif move == 'action' then
  408. printToAll(name .. ' ' .. text .. '.', {0.959999978542328 , 0.439000010490417 , 0.806999981403351})
  409. elseif move == 'keep' then
  410. printToAll(name .. ' saved location.', {0, 1, 1})
  411. else
  412. local color = {1,1,1}
  413. if aistressed[guid] then
  414. color = {1, 0, 0}
  415. end
  416. printToAll(name .. ' ' .. text ..' (' .. move .. ').', color)
  417. end
  418. end
  419.  
  420.  
  421. function check(guid,move)
  422. -- Checking for Lock
  423. if move == 'Locking' then
  424. if locktimer[guid] ~= nil or locktimer[guid] == 0 then
  425. if locktimer[guid] > 1 then
  426. locktimer[guid] = locktimer[guid] - 1
  427. elseif locktimer[guid] == 0 then
  428. locktimer[guid] = 100
  429. else
  430. locktimer[guid] = 0
  431. obj = getObjectFromGUID(guid)
  432. obj.lock()
  433. setpending(guid)
  434. end
  435. else
  436. locktimer[guid] = 100
  437. end
  438. end
  439.  
  440. --Ruler
  441. if move == 'r' or move == 'ruler' then
  442. ruler(guid)
  443. end
  444.  
  445. --DialCheck
  446. if move == 'sd' or move == 'storedial' or move == 'storedials' then
  447. if move == 'sd' then
  448. checkdials(guid)
  449. else
  450. SpawnDialGuide(guid)
  451. end
  452. end
  453. if move == 'rd' or move == 'removedial' or move == 'removedials' then
  454. resetdials(guid, 1)
  455. end
  456.  
  457. -- AI Commands
  458. if move == 'ai' then
  459. auto(guid)
  460. end
  461. if move == 'ai strike' then
  462. aitype[guid] = 'strike'
  463. local ship = getObjectFromGUID(guid)
  464. printToAll('AI Type For: ' .. ship.getName() .. ' set to STRIKE',{0, 1, 0})
  465. setpending(guid)
  466. end
  467. if move == 'ai attack' then
  468. aitype[guid] = nil
  469. local ship = getObjectFromGUID(guid)
  470. printToAll('AI Type For: ' .. ship.getName() .. ' set to ATTACK',{0, 1, 0})
  471. setpending(guid)
  472. end
  473. if move == 'ai striketarget' then
  474. striketarget = guid
  475. local ship = getObjectFromGUID(guid)
  476. printToAll('Strike Target Set: ' .. ship.getName(),{0, 0, 1})
  477. setpending(guid)
  478. end
  479. if move:match "ai target (.*)"~=nil then
  480. local target = move:match "ai target (.*)"
  481. if target == "clear" then
  482. aitargets[guid] = nil
  483. printToAll('Cleared target for AI',{0, 1, 0})
  484. else
  485. local players = {}
  486. for i,ship in ipairs(getAllObjects()) do
  487. local matches = string.match(ship.getName(),target)
  488. if not isAi(ship) and isShip(ship) and matches then
  489. table.insert(players, ship)
  490. end
  491. end
  492. if not empty(players) then
  493. aitargets[guid] = players[1]
  494. printToAll('Set target for AI to: ' .. players[1].getName(),{0, 1, 0})
  495. end
  496. end
  497. if currentphase~=nil then
  498. currentGuid = nil
  499. if current~= nil then currentGuid = current.getGUID() end
  500. UpdateNote(currentphase, currentGuid)
  501. end
  502. setpending(guid)
  503. end
  504. if move == "ai pos" then
  505. local ship = getObjectFromGUID(guid)
  506. printToAll('Position '..ship.getPosition()[1].." "..ship.getPosition()[2].." "..ship.getPosition()[3],{0,1,0})
  507. end
  508. if move == "ai next" then
  509. local ship = getObjectFromGUID(guid)
  510. GoToNextMove(ship)
  511. setpending(guid)
  512. end
  513. if move == "ai stress true" or move == "ai stress" then
  514. aistressed[guid] = true
  515. setpending(guid)
  516. end
  517. if move == "ai stress false" or move == "ai stress clear" then
  518. aistressed[guid] = nil
  519. setpending(guid)
  520. end
  521. -- Straight Commands
  522. if move == 's0' then
  523. notify(guid,move,'is stationary')
  524. setpending(guid)
  525. end
  526. if move == 's1' then
  527. straight(guid,2.9,1.45)
  528. notify(guid,move,'flew straight 1')
  529. elseif move == 's2' or move == 'cs' then
  530. if move == 's2' then
  531. straight(guid,4.35,1.45)
  532. notify(guid,move,'flew straight 2')
  533. else
  534. if shipname:match '%LGS$' then
  535. else
  536. straight(guid,4.35,1.45)
  537. notify(guid,move,'decloaked straight 2')
  538. end
  539. end
  540. elseif move == 's3' then
  541. straight(guid,5.79,1.45)
  542. notify(guid,move,'flew straight 3')
  543. elseif move == 's4' then
  544. straight(guid,7.25,1.5)
  545. notify(guid,move,'flew straight 4')
  546. elseif move == 's5' then
  547. straight(guid,8.68,1.45)
  548. notify(guid,move,'flew straight 5')
  549. -- Bank Commands
  550. elseif move == 'br1' then
  551. right(guid,3.33,1.36,45,1.26,0.5)
  552. notify(guid,move,'banked right 1')
  553. elseif move == 'br2' then
  554. right(guid,4.59,1.89,45,1.26,0.5)
  555. notify(guid,move,'banked right 2')
  556. elseif move == 'br3' then
  557. right(guid,5.91032266616821,2.5119037628174,45,1.26,0.5)
  558. notify(guid,move,'banked right 3')
  559. elseif move == 'bl1' or move == 'be1' then
  560. left(guid,3.33,1.36,-45,1.26,0.5)
  561. notify(guid,move,'banked left 1')
  562. elseif move == 'bl2' or move == 'be2' then
  563. left(guid,4.59,1.89,-45,1.26,0.5)
  564. notify(guid,move,'banked left 2')
  565. elseif move == 'bl3' or move == 'be3' then
  566. left(guid,5.91032266616821,2.5119037628174,-45,1.26,0.5)
  567. notify(guid,move,'banked left 3')
  568. -- Turn Commands
  569. elseif move == 'tr1' then
  570. right(guid,1.9999457550049,2.00932357788086,90,0.7,0.75)
  571. notify(guid,move,'turned right 1')
  572. elseif move == 'tr2' then
  573. right(guid,2.9963474273682,2.97769641876221,90,0.7,0.75)
  574. notify(guid,move,'turned right 2')
  575. elseif move == 'tr3' then
  576. right(guid,3.9047927856445,4.052940441535946,90,0.7,0.75)
  577. notify(guid,move,'turned right 3')
  578. elseif move == 'tl1' or move == 'te1' then
  579. left(guid,2.0049457550049,2.02932357788086,270,0.7,0.75)
  580. notify(guid,move,'turned left 1')
  581. elseif move == 'tl2' or move == 'te2' then
  582. left(guid,2.9963474273682,2.97769641876221,270,0.7,0.75)
  583. notify(guid,move,'turned left 2')
  584. elseif move == 'tl3' or move == 'te3' then
  585. left(guid,3.9047927856445,4.052940441535946,270,0.7,0.75)
  586. notify(guid,move,'turned left 3')
  587. -- Koiogran Turn Commands
  588. elseif move == 'k2' then
  589. straightk(guid,4.35,1.45)
  590. notify(guid,move,'koiogran turned 2')
  591. elseif move == 'k3' then
  592. straightk(guid,5.79,1.45)
  593. notify(guid,move,'koiogran turned 3')
  594. elseif move == 'k4' then
  595. straightk(guid,7.25,1.45)
  596. notify(guid,move,'koiogran turned 4')
  597. elseif move == 'k5' then
  598. straightk(guid,8.68,1.45)
  599. notify(guid,move,'koiogran turned 5')
  600. -- Segnor's Loop Commands
  601. elseif move == 'bl2s' or move == 'be2s' then
  602. left(guid,4.59,1.89,135,1.26,0.5)
  603. notify(guid,move,'segnors looped left 2')
  604. elseif move == 'bl3s' or move == 'be3s' then
  605. left(guid,5.91032266616821,2.5119037628174,135,1.26,0.5)
  606. notify(guid,move,'segnors looped left 3')
  607. elseif move == 'br2s' then
  608. right(guid,4.59,1.89,225,1.26,0.5)
  609. notify(guid,move,'segnors looped right 2')
  610. elseif move == 'br3s' then
  611. right(guid,5.91032266616821,2.5119037628174,225,1.26,0.5)
  612. notify(guid,move,'segnors looped right 3')
  613. -- Barrel Roll Commands
  614. elseif move == 'xl' or move == 'xe' then
  615. if shipname:match '%LGS$' then
  616. left(guid,0,0.73999404907227,0,0,2.87479209899903)
  617. else
  618. left(guid,0,2.8863945007324,0,0,0)
  619. end
  620. notify(guid,move,'barrel rolled left')
  621. elseif move == 'xlf' or move == 'xef' or move == 'rolllf' or move == 'rollet' then
  622. if shipname:match '%LGS$' then
  623. left(guid,2.936365485191352/2,0.73999404907227,0,0,2.87479209899903)
  624. else
  625. left(guid,0.73999404907227,2.8863945007324,0,0,0)
  626. end
  627. notify(guid,move,'barrel rolled forward left')
  628. elseif move == 'xlb' or move == 'xeb' or move == 'rolllb' or move == 'rolleb' then
  629. if shipname:match '%LGS$' then
  630. left(guid,-2.936365485191352/2,0.73999404907227,0,0,2.87479209899903)
  631. else
  632. left(guid,-0.73999404907227,2.8863945007324,0,0,0)
  633. end
  634. notify(guid,move,'barrel rolled backwards left')
  635. elseif move == 'xr' or move == 'rollr'then
  636. if shipname:match '%LGS$' then
  637. right(guid,0,0.73999404907227,0,0,2.87479209899903)
  638. else
  639. right(guid,0,2.8863945007324,0,0,0)
  640. end
  641. notify(guid,move,'barrel rolled right')
  642. elseif move == 'xrf' or move == 'rollrf' then
  643. if shipname:match '%LGS$' then
  644. right(guid,2.936365485191352/2,0.73999404907227,0,0,2.87479209899903)
  645. else
  646. right(guid,0.73999404907227,2.8863945007324,0,0,0)
  647. end
  648. notify(guid,move,'barrel rolled forward right')
  649. elseif move == 'xrb' or move == 'rollrb' then
  650. if shipname:match '%LGS$' then
  651. right(guid,-2.936365485191352/2,0.73999404907227,0,0,2.87479209899903)
  652. else
  653. right(guid,-0.73999404907227,2.8863945007324,0,0,0)
  654. end
  655. notify(guid,move,'barrel rolled backwards right')
  656. -- Decloak Commands
  657. elseif move == 'cl' or move == 'ce' then
  658. if shipname:match '%LGS$' then
  659. else
  660. left(guid,0,4.3295917510986,0,0,0)
  661. notify(guid,move,'decloaked left')
  662. end
  663. elseif move == 'clf' or move == 'cef' then
  664. if shipname:match '%LGS$' then
  665. else
  666. left(guid,0.73999404907227,4.3295917510986,0,0,0)
  667. notify(guid,move,'decloaked forward left')
  668. end
  669. elseif move == 'clb' or move == 'ceb' then
  670. if shipname:match '%LGS$' then
  671. else
  672. left(guid,-0.73999404907227,4.3295917510986,0,0,0)
  673. notify(guid,move,'decloaked backwards left')
  674. end
  675. elseif move == 'cr' or move == 'ce' then
  676. if shipname:match '%LGS$' then
  677. else
  678. right(guid,0,4.3295917510986,0,0,0)
  679. notify(guid,move,'decloaked right')
  680. end
  681. elseif move == 'crf' then
  682. if shipname:match '%LGS$' then
  683. else
  684. right(guid,0.73999404907227,4.3295917510986,0,0,0)
  685. notify(guid,move,'decloaked forward right')
  686. end
  687. elseif move == 'crb' then
  688. if shipname:match '%LGS$' then
  689. else
  690. right(guid,-0.73999404907227,4.3295917510986,0,0,0)
  691. notify(guid,move,'decloak backwards right')
  692. end
  693. -- MISC Commands
  694. elseif move == 'checkpos' then
  695. checkpos(guid)
  696. elseif move == 'checkrot' then
  697. checkrot(guid)
  698. elseif move == 'keep' then
  699. storeundo(guid)
  700. notify(guid,'keep')
  701. setpending(guid)
  702. elseif move == 'set' then
  703. registername(guid)
  704. notify(guid,move)
  705. elseif move == 'undo' or move == 'q' then
  706. undo(guid)
  707. notify(guid,'q')
  708. elseif string.starts(move,"q ") then
  709. local nextmove = string.gsub(move,"q ","")
  710. undo(guid)
  711. executeMove(getObjectFromGUID(guid),nextmove)
  712. end
  713. -- if not empty(players_up_next) then
  714. -- if players_up_next_delay>100 then
  715. -- for i,ship in ipairs(players_up_next) do
  716. -- printToAll("PlayersTurn: ",{0,1,1})
  717. -- prettyPrint(ship)
  718. -- end
  719. -- players_up_next = {}
  720. -- players_up_next_delay = 0
  721. -- else
  722. -- players_up_next_delay = players_up_next_delay + 1
  723. -- end
  724. -- end
  725. -- if ai_stress then
  726. --
  727. -- if ai_stress_delay>100 then
  728. --
  729. -- printToAll('[STRESS - No Action]',{1, 0, 0})
  730. -- ai_stress = false
  731. -- ai_stress_delay = 0
  732. -- else
  733. -- ai_stress_delay = ai_stress_delay + 1
  734. -- end
  735. -- end
  736. end
  737. function string.starts(String,Start)
  738. return string.sub(String,1,string.len(Start))==Start
  739. end
  740.  
  741. function checkpos(guid)
  742. setpending(guid)
  743. obj = getObjectFromGUID(guid)
  744. world = obj.getPosition()
  745. for i, v in ipairs(world) do
  746. print(v)
  747. end
  748. end
  749.  
  750. function checkrot(guid)
  751. setpending(guid)
  752. obj = getObjectFromGUID(guid)
  753. world = obj.getRotation()
  754. for i, v in ipairs(world) do
  755. print(v)
  756. end
  757. end
  758.  
  759. function ruler(guid)
  760.  
  761. shipobject = getObjectFromGUID(guid)
  762. shipname = shipobject.getName()
  763. direction = shipobject.getRotation()
  764. world = shipobject.getPosition()
  765. scale = shipobject.getScale()
  766.  
  767. obj_parameters = {}
  768. obj_parameters.type = 'Custom_Model'
  769. obj_parameters.position = {world[1], world[2]+0.28, world[3]}
  770. obj_parameters.rotation = { 0, direction[2] +180, 0 }
  771. newruler = spawnObject(obj_parameters)
  772. custom = {}
  773. if shipname:match '%LGS$' then
  774. custom.mesh = 'http://pastebin.com/raw/3AU6BBjZ'
  775. custom.collider = 'https://paste.ee/r/JavTd'
  776. else
  777. custom.mesh = 'http://pastebin.com/raw/wkfqqnwX'
  778. custom.collider = 'https://paste.ee/r/6jn13'
  779. end
  780. newruler.setCustomObject(custom)
  781. newruler.lock()
  782. newruler.scale(scale)
  783. setpending(guid)
  784. local button = {['click_function'] = 'actionButton', ['label'] = 'Remove', ['position'] = {0, 0.5, 0}, ['rotation'] = {0, 0, 0}, ['width'] = 1500, ['height'] = 1500, ['font_size'] = 250}
  785. newruler.createButton(button)
  786. notify(guid,'r')
  787. end
  788.  
  789. function actionButton(object)
  790. object.destruct()
  791. end
  792.  
  793. function straight(guid,forwardDistance,bsfd)
  794. storeundo(guid)
  795. obj = getObjectFromGUID(guid)
  796. shipname = obj.getName()
  797. if shipname:match '%LGS$' then
  798. forwardDistance = forwardDistance + bsfd
  799. end
  800. direction = obj.getRotation()
  801. world = obj.getPosition()
  802. rotval = round(direction[2])
  803. radrotval = math.rad(rotval)
  804. xDistance = math.sin(radrotval) * forwardDistance * -1
  805. zDistance = math.cos(radrotval) * forwardDistance * -1
  806. setlock(guid)
  807. obj.setPosition( {world[1]+xDistance, world[2]+2, world[3]+zDistance} )
  808. obj.Rotate({0, 0, 0})
  809.  
  810.  
  811. end
  812.  
  813. function straightk(guid,forwardDistance,bsfd)
  814. storeundo(guid)
  815. obj = getObjectFromGUID(guid)
  816. shipname = obj.getName()
  817. if shipname:match '%LGS$' then
  818. forwardDistance = forwardDistance + bsfd
  819. end
  820. direction = obj.getRotation()
  821. world = obj.getPosition()
  822. rotval = round(direction[2])
  823. radrotval = math.rad(rotval)
  824. xDistance = math.sin(radrotval) * forwardDistance * -1
  825. zDistance = math.cos(radrotval) * forwardDistance * -1
  826. setlock(guid)
  827. obj.setPosition( {world[1]+xDistance, world[2]+2, world[3]+zDistance} )
  828. obj.Rotate({0, 180, 0})
  829. end
  830.  
  831. function right(guid,forwardDistance,sidewaysDistance,rotate,bsfd,bssd)
  832. storeundo(guid)
  833. obj = getObjectFromGUID(guid)
  834. shipname = obj.getName()
  835. if shipname:match '%LGS$' then
  836. forwardDistance = forwardDistance + bsfd
  837. sidewaysDistance = sidewaysDistance + bssd
  838. end
  839. direction = obj.getRotation()
  840. world = obj.getPosition()
  841. rotval = round(direction[2])
  842. radrotval = math.rad(rotval)
  843. xDistance = math.sin(radrotval) * forwardDistance * -1
  844. zDistance = math.cos(radrotval) * forwardDistance * -1
  845. radrotval = radrotval + math.rad(90)
  846. xDistance = xDistance + (math.sin(radrotval) * sidewaysDistance * -1)
  847. zDistance = zDistance + (math.cos(radrotval) * sidewaysDistance * -1)
  848. setlock(guid)
  849. obj.setPosition( {world[1]+xDistance, world[2]+2, world[3]+zDistance} )
  850. obj.Rotate({0, rotate, 0})
  851. end
  852.  
  853. function left(guid,forwardDistance,sidewaysDistance,rotate,bsfd,bssd)
  854. storeundo(guid)
  855. obj = getObjectFromGUID(guid)
  856. shipname = obj.getName()
  857. if shipname:match '%LGS$' then
  858. forwardDistance = forwardDistance + bsfd
  859. sidewaysDistance = sidewaysDistance + bssd
  860. end
  861. direction = obj.getRotation()
  862. world = obj.getPosition()
  863. rotval = round(direction[2])
  864. radrotval = math.rad(rotval)
  865. xDistance = math.sin(radrotval) * forwardDistance * -1
  866. zDistance = math.cos(radrotval) * forwardDistance * -1
  867. radrotval = radrotval - math.rad(90)
  868. xDistance = xDistance + (math.sin(radrotval) * sidewaysDistance * -1)
  869. zDistance = zDistance + (math.cos(radrotval) * sidewaysDistance * -1)
  870. setlock(guid)
  871. obj.setPosition( {world[1]+xDistance, world[2]+2, world[3]+zDistance} )
  872. obj.Rotate({0, rotate, 0})
  873. end
  874.  
  875. function auto(guid)
  876. local ai = getObjectFromGUID(guid)
  877. --local tgtGuid
  878. local squad = getAiSquad(ai)
  879. -- if aitype[guid] == 'strike' then
  880. -- tgtGuid = striketarget
  881. -- printToAll(ai.getName() .. " is STRIKE AI",{0,1,0})
  882. -- else
  883. -- tgtGuid = findNearestPlayer(guid)
  884. -- end
  885. local tgt = findAiTarget(guid)
  886. if tgt == nil then
  887. printToAll('Error: AI ' .. ai.getName() .. ' has no target',{0, 0, 1})
  888. setpending(guid)
  889. else
  890. -- local tgt = getObjectFromGUID(tgtGuid)
  891. -- aitargets[guid] = tgt
  892. -- printToAll("--------------------------------------------------",{0,1,0})
  893. -- printToAll(ai.getName().." declares target as [00FF00][u]" .. tgt.getName().."[/u][-]",{0,1,0})
  894. local aiPos = ai.getPosition()
  895. local tgtPos = tgt.getPosition()
  896. local aiForward = getForwardVector(guid)
  897. local tgtForward = getForwardVector(tgt.getGUID())
  898. local offset = {tgtPos[1] - aiPos[1],0,tgtPos[3] - aiPos[3]}
  899. local angle = math.atan2(offset[3], offset[1]) - math.atan2(aiForward[3], aiForward[1])
  900. if angle < 0 then
  901. angle = angle + 2 * math.pi
  902. end
  903. local fleeing = dot(offset,tgtForward)>0
  904. local move = getMove(getAiType(ai),angle,realDistance(guid,tgt.getGUID()),fleeing)
  905. if squad ~= nil then
  906. -- printToAll("Setting move for squad [".. squad.."] ".. move,{1,0,0})
  907. squadleader[squad] = guid
  908. squadmove[squad] = move
  909. squadposition[squad] = aiPos
  910. squadrotation[squad] = ai.getRotation()[2]
  911. end
  912. executeMove(ai, move)
  913. Render_SwerveLeft(ai,move)
  914. Render_SwerveRight(ai,move)
  915. end
  916. end
  917. function findAiTarget(guid)
  918. if aitargets[guid]~=nil then
  919. return aitargets[guid]
  920. end
  921. local ai = getObjectFromGUID(guid)
  922. local tgtGuid
  923. if aitype[guid] == 'strike' then
  924. printToAll(ai.getName() .. " is STRIKE AI",{0,1,0})
  925. tgtGuid = striketarget
  926. else
  927. autotarget(guid)
  928. targeter(ta,tb,tc,td,talla,tallb,tallc,talld,target)
  929.  
  930. targetcorner = target[2]
  931. if talla[target[1]] < targetcorner then
  932. targetcorner = talla[target[1]]
  933. end
  934. if tallb[target[1]] < targetcorner then
  935. targetcorner = tallb[target[1]]
  936. end
  937. if tallc[target[1]] < targetcorner then
  938. targetcorner = tallc[target[1]]
  939. end
  940. if talld[target[1]] < targetcorner then
  941. targetcorner = talld[target[1]]
  942. end
  943.  
  944. tgtGuid = target[1]
  945.  
  946. end
  947. if tgtGuid ~= nil then
  948. local tgt = getObjectFromGUID(tgtGuid)
  949. aitargets[guid] = tgt
  950. return tgt
  951. else
  952. return nil
  953. end
  954. end
  955.  
  956. function AiSquadButton(ai)
  957. local squad = getAiSquad(ai)
  958. if squad == nil then
  959. printToAll("No squad name found (Must be in format '[AI:INT:1] Tie Interceptor Alpha#1')",{1,0,0})
  960. setpending(ai.getGUID())
  961. return
  962. end
  963. if squad ~=nil and squadmove[squad] ~= nil then
  964. -- printToAll("Found previous move for [".. squad.."] ".. squadmove[squad],{1,0,0})
  965. executeMove(ai, squadmove[squad])
  966. State_AIPostMove(ai)
  967. aitargets[ai.getGUID()] = aitargets[squadleader[squad]]
  968. else
  969. printToAll("No Squad Move Found for ".. squad,{1,0,0})
  970. setpending(ai.getGUID())
  971. return
  972. end
  973. local next = FindNextAi(ai.getGUID(),MoveSort)
  974.  
  975. if next ~=nil then
  976. State_AIMove(next)
  977. UpdateNote(MoveSort, next.getGUID())
  978. else
  979. UpdateNote(MoveSort, nil, true)
  980. end
  981. for i,ship in ipairs(getAllObjects()) do
  982. if isAi(ship) and ship.getGUID()~=ai.getGUID() then
  983. if next==nil or ship.getGUID()~=next.getGUID() then
  984. ship.clearButtons()
  985. end
  986. end
  987. end
  988. end
  989. function executeMove(ai, move)
  990. if aiswerved[ai.getGUID()]~=true then
  991. aimove[ai.getGUID()] = move
  992. end
  993. local movestripped = string.gsub(move,"*","")
  994. ai.setDescription(movestripped)
  995.  
  996. if string.find(move,'*') then
  997. aistressed[ai.getGUID()] = true
  998. ai_stress = true
  999. -- printToAll('[STRESS - No Action]',{1, 0, 0})
  1000. end
  1001. end
  1002. function Render_SwerveLeft(object)
  1003. local move = aimove[object.getGUID()]
  1004.  
  1005. local swerves = getSwerve(getAiType(object),move)
  1006. if swerves ~= nil and swerves[1] ~= nil and aiswerved[object.getGUID()]~=true then
  1007. local swerve = {['click_function'] = 'Action_SwerveLeft', ['label'] = swerves[1], ['position'] = {-0.6, 0.3, 1.6}, ['rotation'] = {0, 0, 0}, ['width'] = 400, ['height'] = 300, ['font_size'] = 200}
  1008. object.createButton(swerve)
  1009. end
  1010. end
  1011. function Action_SwerveLeft(object)
  1012. local move = aimove[object.getGUID()]
  1013. local swerves = getSwerve(getAiType(object),move)
  1014. aiswerved[object.getGUID()] = true
  1015. object.setDescription("q "..swerves[1])
  1016. end
  1017. function Render_SwerveRight(object)
  1018. local move = aimove[object.getGUID()]
  1019.  
  1020. local swerves = getSwerve(getAiType(object),move)
  1021. if swerves ~= nil and swerves[2] ~= nil and aiswerved[object.getGUID()]~=true then
  1022. local swerve = {['click_function'] = 'Action_SwerveRight', ['label'] = swerves[2], ['position'] = {0.6, 0.3, 1.6}, ['rotation'] = {0, 0, 0}, ['width'] = 400, ['height'] = 300, ['font_size'] = 200}
  1023. object.createButton(swerve)
  1024. end
  1025. end
  1026. function Action_SwerveRight(object)
  1027. local move = aimove[object.getGUID()]
  1028. local swerves = getSwerve(getAiType(object),move)
  1029. aiswerved[object.getGUID()] = true
  1030. object.setDescription("q "..swerves[2])
  1031. end
  1032.  
  1033. function getMove(type, direction,range,fleeing)
  1034. local i_dir = math.ceil(direction / (math.pi/4) + 0.5)
  1035. if i_dir > 8 then i_dir = i_dir - 8 end
  1036. local i_range = range / 3.7
  1037. local chooseClosing = i_range<=1 or (i_range <=2 and not fleeing)
  1038. local i_roll = math.random(6)
  1039.  
  1040. local closeMoves = {}
  1041. local farMoves = {}
  1042. if type == "TIE" then
  1043. closeMoves[1] = {'bl2','br2','s2','s2','k4*','k4*'}
  1044. closeMoves[2] = {'s2','bl2','bl2','k4*','k4*','tl1'}
  1045. closeMoves[3] = {'tl1','tl1','tl2','tl2','k3*','k4*'}
  1046. closeMoves[4] = {'tl1','tl1','tl2','k3*','k4*','k4*'}
  1047. closeMoves[5] = {'k4*','k3*','k3*','tl3','tr3','s5'}
  1048. closeMoves[6] = {'tr1','tr1','tr2','k3*','k4*','k4*'}
  1049. closeMoves[7] = {'tr1','tr1','tr2','tr2','k3*','k4*'}
  1050. closeMoves[8] = {'s2','br2','br2','k4*','k4*','tr1' }
  1051.  
  1052. farMoves[1] = {'s5','s5','s5','s4','s4','s3'}
  1053. farMoves[2] = {'s3','bl2','bl3','bl3','bl3','tl3'}
  1054. farMoves[3] = {'bl3','tl3','bl2','tl2','tl2','tl1'}
  1055. farMoves[4] = {'k4*','k3*','k3*','tl2','tl2','tl1'}
  1056. farMoves[5] = {'k3*','k3*','k3*','k3*','tl1','tr1'}
  1057. farMoves[6] = {'k4*','k3*','k3*','tr2','tr2','tr1'}
  1058. farMoves[7] = {'br3','tr3','br2','tr2','tr2','tr1'}
  1059. farMoves[8] = {'s3','br2','br3','br3','br3','tr3' }
  1060. end
  1061. if type == "INT" then
  1062. closeMoves[1] = {'bl2','br2','s2','s2','k5*','k5*'}
  1063. closeMoves[2] = {'s2','bl2','bl2','k5*','k5*','tl1'}
  1064. closeMoves[3] = {'tl1','tl1','tl2','tl2','k3*','k5*'}
  1065. closeMoves[4] = {'tl1','tl1','tl2','k3*','k5*','k5*'}
  1066. closeMoves[5] = {'k5*','k3*','k3*','tl3','tr3','s5'}
  1067. closeMoves[6] = {'tr1','tr1','tr2','k3*','k5*','k5*'}
  1068. closeMoves[7] = {'tr1','tr1','tr2','tr2','k3*','k5*'}
  1069. closeMoves[8] = {'s2','br2','br2','k5*','k5*','tr1' }
  1070.  
  1071. farMoves[1] = {'s5','s5','s5','s4','s4','s3'}
  1072. farMoves[2] = {'s3','bl2','bl3','bl3','bl3','tl3'}
  1073. farMoves[3] = {'bl3','tl3','bl2','tl2','tl2','tl1'}
  1074. farMoves[4] = {'k5*','k3*','k3*','tl2','tl2','tl1'}
  1075. farMoves[5] = {'k3*','k3*','k3*','k3*','tl1','tr1'}
  1076. farMoves[6] = {'k5*','k3*','k3*','tr2','tr2','tr1'}
  1077. farMoves[7] = {'br3','tr3','br2','tr2','tr2','tr1'}
  1078. farMoves[8] = {'s3','br2','br3','br3','br3','tr3' }
  1079. end
  1080. if type == "ADV" then
  1081. closeMoves[1] = {'bl1','br1','s2','s2','k4*','k4*'}
  1082. closeMoves[2] = {'s2','bl1','bl1','bl1','k4*','k4*'}
  1083. closeMoves[3] = {'bl1','k4*','k4*','tl2','tl2','tl2'}
  1084. closeMoves[4] = {'k4*','k4*','k4*','tl2','tl2','bl1'}
  1085. closeMoves[5] = {'k4*','k4*','k4*','k4*','tl3','tr3'}
  1086. closeMoves[6] = {'k4*','k4*','k4*','tr2','tr2','br1'}
  1087. closeMoves[7] = {'br1','k4*','k4*','tr2','tr2','tr2'}
  1088. closeMoves[8] = {'s2','br1','br1','br1','k4*','k4*' }
  1089.  
  1090. farMoves[1] = {'s5','s5','s5','s4','s4','s3'}
  1091. farMoves[2] = {'s3','bl2','bl3','bl3','bl3','tl3'}
  1092. farMoves[3] = {'bl1','bl2','tl2','tl2','tl3','tl3'}
  1093. farMoves[4] = {'k4*','k4*','k4*','tl2','tl2','tl2'}
  1094. farMoves[5] = {'k4*','k4*','k4*','k4*','tl2','tr2'}
  1095. farMoves[6] = {'k4*','k4*','k4*','tr2','tr2','tr2'}
  1096. farMoves[7] = {'br1','br2','tr2','tr2','tr3','tr3'}
  1097. farMoves[8] = {'s3','br2','br3','br3','br3','tr3' }
  1098. end
  1099. if type == "BOM" then
  1100. closeMoves[1] = {'bl1','br1','s1','s1','s1','k5*'}
  1101. closeMoves[2] = {'tl3','s1','bl1','bl1','bl1','k5*'}
  1102. closeMoves[3] = {'bl1','tl2*','tl2*','tl3','tl3','tl3'}
  1103. closeMoves[4] = {'k5*','k5*','k5*','tl3','tl3','tl2*'}
  1104. closeMoves[5] = {'k5*','k5*','k5*','k5*','tl3','tr3'}
  1105. closeMoves[6] = {'k5*','k5*','k5*','tr3','tr3','tr2*'}
  1106. closeMoves[7] = {'br1','tr2*','tr2*','tr3','tr3','tr3'}
  1107. closeMoves[8] = {'tr3','s1','br1','br1','br1','k5*' }
  1108.  
  1109. farMoves[1] = {'s4','s4','s4','s3','s3','s2'}
  1110. farMoves[2] = {'s2','bl2','bl3','bl3','bl3','tl3'}
  1111. farMoves[3] = {'bl3','tl2*','tl2*','tl3','tl3','tl3'}
  1112. farMoves[4] = {'k5*','k5*','tl2*','tl2*','tl3','tl3'}
  1113. farMoves[5] = {'k5*','k5*','k5*','k5*','tl2*','tr2*'}
  1114. farMoves[6] = {'k5*','k5*','tr2*','tr2*','tr3','tr3'}
  1115. farMoves[7] = {'br3','tr2*','tr2*','tr3','tr3','tr3'}
  1116. farMoves[8] = {'s2','br2','br3','br3','br3','tr3' }
  1117. end
  1118. if type == "DEF" then
  1119. closeMoves[1] = {'bl1','br1','s2','s2','k4','k4'}
  1120. closeMoves[2] = {'s2','bl1','bl1','k4','k4','tl1*'}
  1121. closeMoves[3] = {'bl1','k4','k4','tl2*','tl1*','tl1*'}
  1122. closeMoves[4] = {'k4','k4','k4','tl2*','tl2*','tl1*'}
  1123. closeMoves[5] = {'k4','k4','k4','k4','tl3','tr3'}
  1124. closeMoves[6] = {'k4','k4','k4','tr2*','tr2*','tr1*'}
  1125. closeMoves[7] = {'br1','k4','k4','tr2*','tr1*','tr1*'}
  1126. closeMoves[8] = {'s2','br1','br1','k4','k4','tr1*' }
  1127.  
  1128. farMoves[1] = {'s5','s5','s5','s4','s4','s3'}
  1129. farMoves[2] = {'s3','bl2','bl3','bl3','bl3','tl3'}
  1130. farMoves[3] = {'bl1','bl2','tl2*','tl3','tl3','tl3'}
  1131. farMoves[4] = {'k4','k4','k4','tl2*','tl2*','tl1*'}
  1132. farMoves[5] = {'k4','k4','k4','k4','tl1*','tr1*'}
  1133. farMoves[6] = {'k4','k4','k4','tr2*','tr2*','tr1*'}
  1134. farMoves[7] = {'br1','br2','tr2*','tr3','tr3','tr3'}
  1135. farMoves[8] = {'s3','br2','br3','br3','br3','tr3' }
  1136. end
  1137. if type == "PHA" then
  1138. closeMoves[1] = {'bl2','br2','s2','k4*','k4*','k4*'}
  1139. closeMoves[2] = {'s2','bl2','k4*','k4*','tl1','tl1'}
  1140. closeMoves[3] = {'tl1','tl1','tl1','tl2','tl2','k4*'}
  1141. closeMoves[4] = {'tl1','tl1','tl2','k3*','k4*','k4*'}
  1142. closeMoves[5] = {'k4*','k3*','k3*','tl3','tr3','s4'}
  1143. closeMoves[6] = {'tr1','tr1','tr2','k3*','k4*','k4*'}
  1144. closeMoves[7] = {'tr1','tr1','tr1','tr2','tr2','k4*'}
  1145. closeMoves[8] = {'s2','br2','k4*','k4*','tr1','tr1' }
  1146.  
  1147. farMoves[1] = {'s4','s4','s4','s3','s3','s2'}
  1148. farMoves[2] = {'s3','bl2','bl3','bl3','bl3','tl3'}
  1149. farMoves[3] = {'tl1','tl1','tl2','tl2','tl3','bl2'}
  1150. farMoves[4] = {'k4*','k3*','k3*','tl2','tl2','tl1'}
  1151. farMoves[5] = {'k3*','k3*','k3*','k3*','tl1','tr1'}
  1152. farMoves[6] = {'k4*','k3*','k3*','tr2','tr2','tr1'}
  1153. farMoves[7] = {'tr1','tr1','tr2','tr2','tr3','br2'}
  1154. farMoves[8] = {'s3','br2','br3','br3','br3','tr3' }
  1155. end
  1156. if type == "DEC" then
  1157. closeMoves[1] = {'s4','s4','bl3','br3','tl3','tr3'}
  1158. closeMoves[2] = {'bl3','br3','br2','tr2','s4','s4'}
  1159. closeMoves[3] = {'bl3','bl3','tl3','bl2','tl2','bl1'}
  1160. closeMoves[4] = {'bl3','bl3','tl2','tl2','bl2','bl1'}
  1161. closeMoves[5] = {'tl3','tr3','tl2','tr2','bl1','br1'}
  1162. closeMoves[6] = {'br3','br3','tr2','tr2','br2','br1'}
  1163. closeMoves[7] = {'br3','br3','tr3','br2','tr2','br1'}
  1164. closeMoves[8] = {'br3','bl3','bl2','tl2','s4','s4' }
  1165.  
  1166. farMoves[1] = {'s4','s4','s4','s3','s3','s2'}
  1167. farMoves[2] = {'s4','bl3','bl3','bl3','bl2','tl3'}
  1168. farMoves[3] = {'bl3','tl3','tl3','tl2','tl2','bl1'}
  1169. farMoves[4] = {'tl2','tl2','tl2','tl3','tl3','bl1'}
  1170. farMoves[5] = {'tl2','tl2','tl2','tr2','tr2','tr2'}
  1171. farMoves[6] = {'tr2','tr2','tr2','tr3','tr3','br1'}
  1172. farMoves[7] = {'br3','tr3','tr3','tr2','tr2','br1'}
  1173. farMoves[8] = {'s4','br3','br3','br3','br2','tr3' }
  1174. end
  1175. if type == "SHU" then
  1176. closeMoves[1] = {'*','*','*','s1','br1','bl1'}
  1177. closeMoves[2] = {'*','s1','bl1','bl1','bl1','tl2*'}
  1178. closeMoves[3] = {'*','tl2*','tl2*','tl2*','bl1','bl2'}
  1179. closeMoves[4] = {'*','tl2*','tl2*','tl2*','bl2','bl3*'}
  1180. closeMoves[5] = {'*','*','tr2*','tl2*','br3*','bl3*'}
  1181. closeMoves[6] = {'*','tr2*','tr2*','tr2*','br2','br3*'}
  1182. closeMoves[7] = {'*','tr2*','tr2*','tr2*','br1','br2'}
  1183. closeMoves[8] = {'*','s1','br1','br1','br1','tr2*' }
  1184.  
  1185. farMoves[1] = {'s3','s3','s3','s2','s2','s1'}
  1186. farMoves[2] = {'s2','bl3*','bl2','bl2','bl2','tl2*'}
  1187. farMoves[3] = {'tl2*','tl2*','tl2*','tl2*','bl2','bl3*'}
  1188. farMoves[4] = {'tl2*','tl2*','tl2*','tl2*','bl1','bl1'}
  1189. farMoves[5] = {'tl2*','tl2*','tl2*','tr2*','tr2*','tr2*'}
  1190. farMoves[6] = {'tr2*','tr2*','tr2*','tr2*','br1','br1'}
  1191. farMoves[7] = {'tr2*','tr2*','tr2*','tr2*','br2','br3*'}
  1192. farMoves[8] = {'s2','br3*','br2','br2','br2','tr2*' }
  1193. end
  1194.  
  1195. local move = ""
  1196. if chooseClosing then
  1197. move = closeMoves[i_dir][i_roll]
  1198. else
  1199. move = farMoves[i_dir][i_roll]
  1200. end
  1201.  
  1202. return move
  1203. end
  1204. function getSwerve(type, move)
  1205. local swerves = {}
  1206. if type == "SHU" then
  1207. swerves["*"] = {nil,nil}
  1208. end
  1209. -- 1
  1210. if type == "TIE" or type == "INT" or type == "PHA" then
  1211. swerves["tl1"] = {nil,"bl2"}
  1212. swerves["tr1"] = {"br2",nil }
  1213. end
  1214. if type == "ADV" then
  1215. swerves["bl1"] = {"tl2","s2"}
  1216. swerves["br1"] = {"s2","tr2" }
  1217. end
  1218. if type == "DEF" then
  1219. swerves["tl1*"] = {nil,"bl1"}
  1220. swerves["bl1"] = {"tl1*","s2"}
  1221. swerves["br1"] = {"s2","tr1*" }
  1222. swerves["tr1*"] = {"br1",nil }
  1223. end
  1224. if type == "BOM" then
  1225. swerves["bl1"] = {"tl2*","s1"}
  1226. swerves["s1"] = {"bl1","br1"}
  1227. swerves["br1"] = {"s1","tr2*" }
  1228. end
  1229. if type == "DEC" then
  1230. swerves["bl1"] = {"tl2","s1"}
  1231. swerves["s1"] = {"bl1","br1"}
  1232. swerves["br1"] = {"s1","tr2" }
  1233. end
  1234. if type == "SHU" then
  1235. swerves["bl1"] = {"tl2*","s1"}
  1236. swerves["s1"] = {"bl1","br1"}
  1237. swerves["br1"] = {"s1","tr2*"}
  1238. end
  1239. -- 2
  1240. if type == "TIE" or type == "INT" or type == "ADV" or type == "PHA" or type == "DEC" then
  1241.  
  1242. swerves["tl2"] = {nil,"bl2"}
  1243. swerves["bl2"] = {"tl2","s2"}
  1244. swerves["s2"] = {"bl2","br2"}
  1245. swerves["br2"] = {"s2","tr2"}
  1246. swerves["tr2"] = {"br2",nil }
  1247. end
  1248. if type == "DEF" or type == "BOM" or type == "SHU" then
  1249. swerves["tl2*"] = {nil,"bl2"}
  1250. swerves["bl2"] = {"tl2*","s2"}
  1251. swerves["s2"] = {"bl2","br2"}
  1252. swerves["br2"] = {"s2","tr2*"}
  1253. swerves["tr2*"] = {"br2",nil }
  1254. end
  1255. -- 3
  1256. if type == "TIE" or type == "INT" or type == "ADV" or type == "PHA" or type == "DEF" or type == "BOM" or type == "DEC" then
  1257. swerves["tl3"] = {nil,"bl3"}
  1258. swerves["bl3"] = {"tl3","s3"}
  1259. swerves["s3"] = {"bl3","br3"}
  1260. swerves["br3"] = {"s3","tr3"}
  1261. swerves["tr3"] = {"br3",nil }
  1262. end
  1263. if type == "SHU" then
  1264. swerves["bl3*"] = {"tl2*","s3"}
  1265. swerves["s3"] = {"bl3*","br3*"}
  1266. swerves["br3*"] = {"s3","tr2*"}
  1267. end
  1268. if type == "TIE" or type == "INT" or type == "PHA" then
  1269. swerves["k3*"] = {"bl3","br3"}
  1270. end
  1271. -- 4
  1272. if type == "TIE" or type == "INT" or type == "ADV" or type == "PHA" or type == "DEF" or type == "BOM" or type == "DEC" then
  1273. swerves["s4"] = {"bl3","br3"}
  1274. end
  1275. if type == "TIE" or type == "ADV" or type == "PHA" then
  1276. swerves["k4*"] = {"bl3","br3" }
  1277. end
  1278. if type == "DEF" then
  1279. swerves["k4"] = {"bl3","br3" }
  1280. end
  1281. --5
  1282. if type == "TIE" or type == "INT" or type == "ADV" or type == "DEF" then
  1283.  
  1284. swerves["s5"] = {"bl3","br3"}
  1285. end
  1286. if type == "INT" or type == "BOM" then
  1287. swerves["k5*"] = {"bl3","br3" }
  1288. end
  1289. return swerves[move]
  1290. end
  1291. function RotateVector(direction, yRotation)
  1292.  
  1293. local rotval = round(yRotation)
  1294. local radrotval = math.rad(rotval)
  1295. local xDistance = math.cos(radrotval) * direction[1] + math.sin(radrotval) * direction[3]
  1296. local zDistance = math.sin(radrotval) * direction[1] * -1 + math.cos(radrotval) * direction[3]
  1297. return {xDistance, direction[2], zDistance}
  1298. end
  1299.  
  1300. function Action_MovePhase()
  1301. -- printToAll("*****************************",{0,1,1})
  1302. -- printToAll("STARTING ACTIVATION PHASE",{0,1,1})
  1303. -- printToAll("*****************************",{0,1,1})
  1304. currentphase = MoveSort
  1305. squadleader = {}
  1306. squadmove = {}
  1307. squadposition = {}
  1308. squadrotation = {}
  1309. aimove = {}
  1310. aiswerved = {}
  1311. aitargets = {}
  1312. aistressed = {}
  1313. -- ListAis(MoveSort)
  1314. for i,ship in ipairs(getAllObjects()) do
  1315. if isAi(ship) then
  1316. ship.clearButtons()
  1317. -- Set MOVE button
  1318. -- State_AIMove(ship)
  1319. end
  1320. end -- [end loop for all ships]
  1321.  
  1322. local first = FindNextAi(nil, MoveSort)
  1323. current = first
  1324. if first ~=nil then
  1325. findAiTarget(first.getGUID())
  1326. State_AIMove(first)
  1327. end
  1328. UpdateNote(MoveSort, nil)
  1329. end
  1330. function Action_ClearAi()
  1331. for i,ship in ipairs(getAllObjects()) do
  1332. if isAi(ship) then
  1333. ship.clearButtons()
  1334. end
  1335. end -- [end loop for all ships]
  1336. end
  1337. function Action_AttackPhase()
  1338. -- printToAll("**************************",{0,1,1})
  1339. -- printToAll("STARTING COMBAT PHASE",{0,1,1})
  1340. -- printToAll("**************************",{0,1,1})
  1341. currentphase = AttackSort
  1342. UpdateNote(AttackSort, nil)
  1343. -- ListAis(AttackSort)
  1344. for i,ship in ipairs(getAllObjects()) do
  1345. if isAi(ship) then
  1346. ship.clearButtons()
  1347. -- Render_Ruler(ship)
  1348. end
  1349. end -- [end loop for all ships]
  1350. local first = FindNextAi(nil, AttackSort)
  1351. current = first
  1352. if first ~=nil then
  1353. Render_Ruler(first)
  1354. Render_AttackButton(first)
  1355. end
  1356. end
  1357. function Render_AttackButton(object)
  1358.  
  1359. local attackbutton = {['click_function'] = 'Action_AiAttack', ['label'] = 'Attack', ['position'] = {0, 0.3, -0.6}, ['rotation'] = {0, 0, 0}, ['width'] = 750, ['height'] = 550, ['font_size'] = 250}
  1360. object.createButton(attackbutton)
  1361. end
  1362. function Action_AiAttack(object)
  1363. object.clearButtons()
  1364. local next = FindNextAi(object.getGUID(),AttackSort)
  1365. current = next
  1366. if next ~=nil then
  1367. Render_Ruler(next)
  1368. Render_AttackButton(next)
  1369. UpdateNote(AttackSort, next.getGUID())
  1370. else
  1371. UpdateNote(AttackSort, nil, true)
  1372. end
  1373. end
  1374. function UpdateNote(sort, next,complete)
  1375. local ai_string = ""
  1376. local ais = {}
  1377. local showPlayers = true
  1378. for i,ship in ipairs(getAllObjects()) do
  1379. if (isAi(ship) or isShip(ship) and showPlayers and getSkill(ship)~=nil) then
  1380. table.insert(ais, ship)
  1381. end
  1382. end -- [end loop for all ships]
  1383. table.sort(ais,sort)
  1384. local first = true
  1385. for i,ship in ipairs(ais) do
  1386. local arrow = ''
  1387. local current = next == nil and not complete and first or next == ship.getGUID()
  1388. if current then
  1389. arrow = "[0080FF][b]Current ---->[/b][-] "
  1390. first = false
  1391. end
  1392. ai_string = ai_string.."\n"..arrow..prettyString(ship,true)
  1393. end
  1394. if complete then
  1395. ai_string = ai_string.."\n".."[0080FF][b][Complete][/b][-]"
  1396. end
  1397. setNotes(ai_string)
  1398. end
  1399. function ListAis(sort)
  1400. printToAll("Sorting AIs, Found:",{0,1,0})
  1401. local ais = {}
  1402. local showPlayers = true
  1403. for i,ship in ipairs(getAllObjects()) do
  1404. if (isAi(ship) or isShip(ship) and showPlayers and getSkill(ship)~=nil) then
  1405. table.insert(ais, ship)
  1406. end
  1407. end -- [end loop for all ships]
  1408. table.sort(ais,sort)
  1409. for i,ship in ipairs(ais) do
  1410. prettyPrint(ship)
  1411. end
  1412. end
  1413. function prettyString(ship,withtarget)
  1414. local skill_colors = {"666666","FF30FF","8030FF","3030FF","3080FF","30FFFF","30FF80","30FF30","80FF30","FFFF30","FF3030" }
  1415. local type_colors = {TIE="666666",INT="600000",ADV="c1440e",BOM="00FFFF",DEF="660066",PHA="2C75FF",DEC="808080",SHU="A0A0A0"}
  1416. local isAi = isAi(ship)
  1417. local skill = tostring(getSkill(ship))
  1418. local skill_color = skill_colors[tonumber(skill)+1]
  1419. if skill_color==nil then skill_color="000000" end
  1420. if isAi then
  1421. local type = tostring(getAiType(ship))
  1422. local type_color = type_colors[type]
  1423. if type_color == nil then type_color = "000000" end
  1424. local squad = getAiSquad(ship)
  1425. if squad == nil then squad = "" end
  1426. local number = tostring(getAiNumber(ship))
  1427. local target = ""
  1428. local stress = ""
  1429. local stress_end = ""
  1430. if aistressed[ship.getGUID()]~=nil then
  1431. --stress = "[800000][*][-] "
  1432. stress = "[C02020]"
  1433. stress_end = "[-]"
  1434. end
  1435. if withtarget and aitargets[ship.getGUID()] then
  1436. local nops = string.gsub(aitargets[ship.getGUID()].getName(),"%[%d+%]%s*","")
  1437. --local stripped_colors = nops:match
  1438. target = " [[00FF00][u]"..nops.."[/u][-]]"
  1439. end
  1440. return stress.."PS["..skill_color.."]"..skill.."[-] ["..type_color.."]"..type.."[-] "..squad.."#"..number..stress_end..target,{0,0,1}
  1441. else
  1442. return "PS["..skill_color.."]"..skill.."[-] [00FF00][u]"..string.gsub(ship.getName(),"%[%d+%]%s*","").."[/u][-]",{0,0,1}
  1443. end
  1444. end
  1445. function stripPS() end
  1446. function prettyPrint(ship)
  1447. printToAll(prettyString(ship),{0,0,1})
  1448. end
  1449. function FindNextAi(guid, sort)
  1450. local ais = {}
  1451. for i,ship in ipairs(getAllObjects()) do
  1452. if isShip(ship) then
  1453. table.insert(ais, ship)
  1454. end
  1455. end -- [end loop for all ships]
  1456. -- for i,ship in ipairs(ais) do
  1457. -- printToAll(ship.getName().." - "..getSkill(ship.getName()).." - "..getAiNumber(ship.getName()),{0,1,0})
  1458. -- end
  1459. table.sort(ais,sort)
  1460. -- if guid==nil then
  1461. -- return ais[1]
  1462. -- else
  1463. local selffound = false
  1464. for i,ship in ipairs(ais) do
  1465. if selffound or guid==nil then
  1466. if isAi(ship) then
  1467. return ship
  1468. else
  1469. table.insert(players_up_next,ship)
  1470. return ship
  1471. end
  1472. end
  1473. if ship.getGUID()==guid then selffound = true end
  1474. end
  1475. -- end
  1476. end
  1477. function AttackSort(a, b)
  1478. local a_ps = tonumber(getSkill(a))
  1479. local a_num = tonumber(getAiNumber(a))
  1480. local b_ps = tonumber(getSkill(b))
  1481. local b_num = tonumber(getAiNumber(b))
  1482. if a_ps ~= b_ps then
  1483. if a_ps == nil or b_ps == nil then
  1484. return a_ps~=nil
  1485. end
  1486. return a_ps > b_ps
  1487. else
  1488. if isAi(a) ~= isAi(b) then
  1489. return isAi(a)
  1490. else
  1491. return a_num<b_num
  1492. end
  1493. end
  1494. end
  1495. function MoveSort(a, b)
  1496. local a_ps = tonumber(getSkill(a))
  1497. local a_num = tonumber(getAiNumber(a))
  1498. local b_ps = tonumber(getSkill(b))
  1499. local b_num = tonumber(getAiNumber(b))
  1500. if a_ps ~= b_ps then
  1501. if a_ps == nil or b_ps == nil then
  1502. return a_ps~=nil
  1503. end
  1504. return a_ps < b_ps
  1505. else
  1506. if isAi(a) ~= isAi(b) then
  1507. return isAi(a)
  1508. else
  1509. return a_num<b_num
  1510. end
  1511. end
  1512. end
  1513. function State_AIMove(object)
  1514. -- Set MOVE button
  1515. local label = 'Move'
  1516. if not isAi(object) then label = 'Next' end
  1517. local movebutton = {['click_function'] = 'Action_AiMove', ['label'] = label, ['position'] = {0, 0.3, -0.6}, ['rotation'] = {0, 0, 0}, ['width'] = 750, ['height'] = 550, ['font_size'] = 250}
  1518. object.createButton(movebutton)
  1519. if isAi(object) and getAiSquad(object)~=nil then
  1520. local squadbutton = {['click_function'] = 'AiSquadButton', ['label'] = 'Squad', ['position'] = {0, 0.3, 0.6}, ['rotation'] = {0, 0, 0}, ['width'] = 750, ['height'] = 550, ['font_size'] = 250}
  1521. object.createButton(squadbutton)
  1522. end
  1523. if getAiType(object) == "PHA" then
  1524. Render_AiDecloak(object)
  1525. end
  1526. end
  1527. function Action_AiMove(object)
  1528. --object.setDescription("ai")
  1529.  
  1530. if isAi(object) then
  1531. auto(object.getGUID())
  1532. end
  1533. GoToNextMove(object)
  1534. end
  1535. function GoToNextMove(object)
  1536. if isAi(object) then
  1537. State_AIPostMove(object)
  1538. else
  1539. object.clearButtons()
  1540. end
  1541. local next = FindNextAi(object.getGUID(),MoveSort)
  1542. current = next
  1543. if next ~=nil then
  1544. findAiTarget(next.getGUID())
  1545. State_AIMove(next)
  1546. UpdateNote(MoveSort, next.getGUID())
  1547. else
  1548. UpdateNote(MoveSort, nil, true)
  1549. end
  1550. for i,ship in ipairs(getAllObjects()) do
  1551. if isAi(ship) and ship.getGUID()~=object.getGUID() then
  1552. if next==nil or ship.getGUID()~=next.getGUID() then
  1553. ship.clearButtons()
  1554. end
  1555. end
  1556. end
  1557. end
  1558. function State_AIPostMove(object)
  1559.  
  1560. object.clearButtons()
  1561. Render_Undo(object)
  1562.  
  1563. Render_AiFocusEvade(object)
  1564.  
  1565. Render_Ruler(object)
  1566.  
  1567. if getAiHasBoost(object) then
  1568. Render_Boost(object)
  1569. end
  1570.  
  1571. if getAiHasBarrelRoll(object) then
  1572. Render_BarrelRoll(object)
  1573. end
  1574. end
  1575.  
  1576.  
  1577. function Render_Undo(object)
  1578. local undobutton = {['click_function'] = 'AiUndoButton', ['label'] = 'q', ['position'] = {-0.9, 0.3, -0.6}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  1579. object.createButton(undobutton)
  1580. end
  1581.  
  1582. function AiUndoButton(object)
  1583. aiswerved[object.getGUID()] = nil
  1584. if squadleader[object.getGUID()]~=nil then
  1585. local squad = getAiSquad(object)
  1586. squadleader[squad] = nil
  1587. squadmove[squad] = nil
  1588. squadposition[squad] = nil
  1589. squadrotation[squad] = nil
  1590. end
  1591. object.clearButtons()
  1592. object.setDescription("q")
  1593.  
  1594. State_AIMove(object)
  1595. end
  1596.  
  1597. function Render_AiUndoBoostBarrel(object)
  1598. local undobutton = {['click_function'] = 'Action_AiUndoBoostBarrel', ['label'] = 'q', ['position'] = {-0.9, 0.3, -0.6}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  1599. object.createButton(undobutton)
  1600. end
  1601.  
  1602. function Action_AiUndoBoostBarrel(object)
  1603.  
  1604. object.clearButtons()
  1605. object.setDescription("q")
  1606.  
  1607. Render_Ruler(object)
  1608.  
  1609. if getAiHasBoost(object) then
  1610. Render_Boost(object)
  1611. end
  1612.  
  1613. if getAiHasBarrelRoll(object) then
  1614. Render_BarrelRoll(object)
  1615. end
  1616. end
  1617.  
  1618. function Render_Ruler(object)
  1619. local rulerbutton = {['click_function'] = 'RulerButton', ['label'] = 'r', ['position'] = {-0.9, 0.3, 0.6}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  1620. object.createButton(rulerbutton)
  1621. end
  1622.  
  1623. function RulerButton(object)
  1624. object.setDescription("r")
  1625. end
  1626.  
  1627. function Render_Boost(object)
  1628.  
  1629. local bl1button = {['click_function'] = 'Action_AiBoostLeft', ['label'] = 'bl1', ['position'] = {-1.1, 0.3, -1.6}, ['rotation'] = {0, 0, 0}, ['width'] = 330, ['height'] = 300, ['font_size'] = 200}
  1630. object.createButton(bl1button)
  1631.  
  1632. local s1button = {['click_function'] = 'Action_AiBoostStraight', ['label'] = 's1', ['position'] = {0, 0.3, -1.6}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 300, ['font_size'] = 200}
  1633. object.createButton(s1button)
  1634.  
  1635. local br1button = {['click_function'] = 'Action_AiBoostRight', ['label'] = 'br1', ['position'] = {1.1, 0.3, -1.6}, ['rotation'] = {0, 0, 0}, ['width'] = 330, ['height'] = 300, ['font_size'] = 200}
  1636. object.createButton(br1button)
  1637. end
  1638.  
  1639. function Render_AiDecloak(object)
  1640. local decloak = {['click_function'] = 'Action_AiDecloak', ['label'] = 'decloak', ['position'] = {0, 0.3, -1.6}, ['rotation'] = {0, 0, 0}, ['width'] = 1000, ['height'] = 300, ['font_size'] = 200}
  1641. object.createButton(decloak)
  1642. end
  1643.  
  1644. function Action_AiDecloak(object)
  1645. local i_roll = math.random(3)
  1646. local options = {"ce","cs","cr" }
  1647. object.setDescription(options[i_roll])
  1648. Render_Undo(object)
  1649. end
  1650.  
  1651. function Action_AiBoostLeft(object)
  1652. object.setDescription("bl1")
  1653. object.clearButtons()
  1654. Render_AiUndoBoostBarrel(object)
  1655. Render_Ruler(object)
  1656. Render_AiFocusEvade(object)
  1657. end
  1658.  
  1659. function Action_AiBoostStraight(object)
  1660. object.setDescription("s1")
  1661. object.clearButtons()
  1662. Render_AiUndoBoostBarrel(object)
  1663. Render_Ruler(object)
  1664. Render_AiFocusEvade(object)
  1665. end
  1666.  
  1667. function Action_AiBoostRight(object)
  1668. object.setDescription("br1")
  1669. object.clearButtons()
  1670. Render_AiUndoBoostBarrel(object)
  1671. Render_Ruler(object)
  1672. Render_AiFocusEvade(object)
  1673. end
  1674.  
  1675. function Render_BarrelRoll(object)
  1676.  
  1677. local xebbutton = {['click_function'] = 'Action_AiBarrelRollLeft', ['label'] = 'xl', ['position'] = {-1.6, 0.3, 0}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 300, ['font_size'] = 200}
  1678. object.createButton(xebbutton)
  1679.  
  1680. local xrbbutton = {['click_function'] = 'Action_AiBarrelRollRight', ['label'] = 'xr', ['position'] = {1.6, 0.3, 0}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 300, ['font_size'] = 200}
  1681. object.createButton(xrbbutton)
  1682. end
  1683.  
  1684. function Action_AiBarrelRollLeft(object)
  1685. object.setDescription("xl")
  1686. object.clearButtons()
  1687. Render_AiUndoBoostBarrel(object)
  1688. Render_Ruler(object)
  1689. Render_AiFocusEvade(object)
  1690. end
  1691.  
  1692. function Action_AiBarrelRollRight(object)
  1693. object.setDescription("xr")
  1694. object.clearButtons()
  1695. Render_AiUndoBoostBarrel(object)
  1696. Render_Ruler(object)
  1697. Render_AiFocusEvade(object)
  1698. end
  1699.  
  1700. function Render_AiFocusEvade(object)
  1701.  
  1702. local focusbutton = {['click_function'] = 'Action_Focus', ['label'] = 'F', ['position'] = {0.9, 0.3, -0.6}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  1703. object.createButton(focusbutton)
  1704.  
  1705. local type = getAiType(object);
  1706. if type == "TIE" or type=="INT" or type == "ADV" or type == "PHA" then
  1707. local evadebutton = {['click_function'] = 'Action_Evade', ['label'] = 'E', ['position'] = {0.9, 0.3, 0.6}, ['rotation'] = {0, 0, 0}, ['width'] = 200, ['height'] = 530, ['font_size'] = 250}
  1708. object.createButton(evadebutton)
  1709. end
  1710. end
  1711.  
  1712.  
  1713. function Action_Focus(object)
  1714. take(focus, object.getGUID(),-0.37,1,-0.37)
  1715. notify(object.getGUID(),'action','takes a focus token')
  1716. end
  1717. function Action_Evade(object)
  1718. take(evade, object.getGUID(),-0.37,1,0.37)
  1719. notify(object.getGUID(),'action','takes an evade token')
  1720. end
  1721.  
  1722. function getForwardVector(guid)
  1723. local this = getObjectFromGUID(guid)
  1724. local direction = this.getRotation()
  1725. local rotval = round(direction[2])
  1726. local radrotval = math.rad(rotval)
  1727. local xForward = math.sin(radrotval) * -1
  1728. local zForward = math.cos(radrotval) * -1
  1729. -- log(guid .. " for x: "..round(xForward,2).." y: "..round(zForward,2))
  1730. return {xForward, 0, zForward}
  1731. end
  1732. function dot(a,b)
  1733. return a[3]*b[3] + a[1]*b[1]
  1734. end
  1735.  
  1736. function autotarget(guid)
  1737. setpending(guid)
  1738. obj = getObjectFromGUID(guid)
  1739. pos = obj.getPosition()
  1740. rot = obj.getRotation()
  1741. mover = obj.getName()
  1742. ta = {}
  1743. tb = {}
  1744. tc = {}
  1745. td = {}
  1746. talla = {}
  1747. tallb = {}
  1748. tallc = {}
  1749. talld = {}
  1750. target={9999999999,9999999999}
  1751. for i,ship in ipairs(getAllObjects()) do
  1752. if ship.tag == 'Figurine' and ship.name ~= '' then
  1753. shipguid = ship.getGUID()
  1754. shipname = ship.getName()
  1755. world = ship.getPosition()
  1756. rot_pl = ship.getRotation()
  1757. headchecks(shipname,pos,world,shipguid,rot_pl,rot,mover)
  1758. end
  1759. end
  1760. end
  1761.  
  1762. function corners(world,rot_pl)
  1763. a = {}
  1764. b = {}
  1765. c = {}
  1766. d = {}
  1767.  
  1768. if rot_pl[2] >= 352.5 and rot_pl[2] <= 360 or rot_pl[2] < 7.5
  1769. or rot_pl[2] >= 262.5 and rot_pl[2] < 277.5
  1770. or rot_pl[2] >= 172.5 and rot_pl[2] < 187.5
  1771. or rot_pl[2] >= 82.5 and rot_pl[2] < 97.5 then
  1772.  
  1773. a[1] = world[1] - 0.725
  1774. a[3] = world[3] - 0.725
  1775.  
  1776. b[1] = world[1] - 0.725
  1777. b[3] = world[3] + 0.725
  1778.  
  1779. c[1] = world[1] + 0.725
  1780. c[3] = world[3] + 0.725
  1781.  
  1782. d[1] = world[1] + 0.725
  1783. d[3] = world[3] - 0.725
  1784.  
  1785.  
  1786. elseif rot_pl[2] >= 337.5 and rot_pl[2] < 352.5
  1787. or rot_pl[2] >= 247.5 and rot_pl[2] < 262.5
  1788. or rot_pl[2] >= 157.5 and rot_pl[2] < 172.5
  1789. or rot_pl[2] >= 67.5 and rot_pl[2] < 82.5 then
  1790.  
  1791. a[1] = world[1] - 0.512652416360247
  1792. a[3] = world[3] - 0.887940031758902
  1793.  
  1794. b[1] = world[1] - 0.887940031758902
  1795. b[3] = world[3] + 0.512652416360247
  1796.  
  1797. c[1] = world[1] + 0.512652416360247
  1798. c[3] = world[3] + 0.887940031758902
  1799.  
  1800. d[1] = world[1] + 0.887940031758902
  1801. d[3] = world[3] - 0.512652416360247
  1802.  
  1803.  
  1804. elseif rot_pl[2] >= 322.5 and rot_pl[2] < 337.5
  1805. or rot_pl[2] >= 232.5 and rot_pl[2] < 247.5
  1806. or rot_pl[2] >= 142.5 and rot_pl[2] < 157.5
  1807. or rot_pl[2] >= 52.5 and rot_pl[2] < 67.5 then
  1808.  
  1809. a[1] = world[1] - 0.265368417743718
  1810. a[3] = world[3] - 0.990368417743718
  1811.  
  1812. b[1] = world[1] - 0.990368417743718
  1813. b[3] = world[3] + 0.265368417743718
  1814.  
  1815. c[1] = world[1] + 0.265368417743718
  1816. c[3] = world[3] + 0.990368417743718
  1817.  
  1818. d[1] = world[1] + 0.990368417743718
  1819. d[3] = world[3] - 0.265368417743718
  1820.  
  1821.  
  1822. elseif rot_pl[2] >= 307.5 and rot_pl[2] < 322.5
  1823. or rot_pl[2] >= 217.5 and rot_pl[2] < 232.5
  1824. or rot_pl[2] >= 127.5 and rot_pl[2] < 142.5
  1825. or rot_pl[2] >= 37.5 and rot_pl[2] < 52.5 then
  1826.  
  1827. a[1] = world[1] - 0
  1828. a[3] = world[3] - 1.02530483272049
  1829.  
  1830. b[1] = world[1] - 1.02530483272049
  1831. b[3] = world[3] + 0
  1832.  
  1833. c[1] = world[1] + 0
  1834. c[3] = world[3] + 1.02530483272049
  1835.  
  1836. d[1] = world[1] + 1.02530483272049
  1837. d[3] = world[3] - 0
  1838.  
  1839.  
  1840. elseif rot_pl[2] >= 292.5 and rot_pl[2] < 307.5
  1841. or rot_pl[2] >= 202.5 and rot_pl[2] < 217.5
  1842. or rot_pl[2] >= 112.5 and rot_pl[2] < 127.5
  1843. or rot_pl[2] >= 22.5 and rot_pl[2] < 37.5 then
  1844.  
  1845. a[1] = world[1] + 0.265368417743718
  1846. a[3] = world[3] - 0.990368417743718
  1847.  
  1848. b[1] = world[1] - 0.990368417743718
  1849. b[3] = world[3] - 0.265368417743718
  1850.  
  1851. c[1] = world[1] - 0.265368417743718
  1852. c[3] = world[3] + 0.990368417743718
  1853.  
  1854. d[1] = world[1] + 0.990368417743718
  1855. d[3] = world[3] + 0.265368417743718
  1856.  
  1857.  
  1858. elseif rot_pl[2] >= 277.5 and rot_pl[2] < 292.5
  1859. or rot_pl[2] >= 187.5 and rot_pl[2] < 202.5
  1860. or rot_pl[2] >= 97.5 and rot_pl[2] < 112.5
  1861. or rot_pl[2] >= 7.5 and rot_pl[2] < 22.5 then
  1862.  
  1863. a[1] = world[1] + 0.512652416360247
  1864. a[3] = world[3] - 0.887940031758902
  1865.  
  1866. b[1] = world[1] - 0.887940031758902
  1867. b[3] = world[3] - 0.512652416360247
  1868.  
  1869. c[1] = world[1] - 0.512652416360247
  1870. c[3] = world[3] + 0.887940031758902
  1871.  
  1872. d[1] = world[1] + 0.887940031758902
  1873. d[3] = world[3] + 0.512652416360247
  1874. end
  1875. end
  1876.  
  1877. function headchecks(shipname,pos,world,shipguid,rot_pl,rot,mover)
  1878. corners(world,rot_pl)
  1879. if shipname:match 'PS:%d$' or shipname:match 'PS: %d$' or shipname:match 'PS:%d LBS$' then
  1880. xa = a[1] - pos[1]
  1881. ya = a[3] - pos[3]
  1882. va = math.sqrt(xa*xa+ya*ya)
  1883. talla[shipguid] = (va)
  1884. if ya >= 0 then
  1885. dirca = 270 - math.deg(math.acos(xa/va))
  1886. elseif ya < 0 and xa>= 0 then
  1887. dirca = 270 + math.deg(math.acos(xa/va))
  1888. elseif ya < 0 and xa < 0 then
  1889. dirca = math.deg(math.acos(xa/va)) - 90
  1890. end
  1891. headchecka = dirca - rot[2]
  1892. if headchecka < 0 then
  1893. headchecka = headchecka + 360
  1894. end
  1895. if mover:match '%LBS$' then
  1896. if va < 12.325 and headchecka > 320 and headchecka < 360
  1897. or va < 12.325 and headchecka < 40 and headchecka > 0 then
  1898. ta[shipguid] = (va)
  1899. end
  1900. else
  1901. if va < 11.6 and headchecka > 320 and headchecka < 360
  1902. or va < 11.6 and headchecka < 40 and headchecka > 0 then
  1903. ta[shipguid] = (va)
  1904. end
  1905. end
  1906.  
  1907. xb = b[1] - pos[1]
  1908. yb = b[3] - pos[3]
  1909. vb = math.sqrt(xb*xb+yb*yb)
  1910. tallb[shipguid] = (vb)
  1911. if yb >= 0 then
  1912. dircb = 270 - math.deg(math.acos(xb/vb))
  1913. elseif yb < 0 and xb>= 0 then
  1914. dircb = 270 + math.deg(math.acos(xb/vb))
  1915. elseif yb < 0 and xb < 0 then
  1916. dircb = math.deg(math.acos(xb/vb)) - 90
  1917. end
  1918. headcheckb = dircb - rot[2]
  1919. if headcheckb < 0 then
  1920. headcheckb = headcheckb + 360
  1921. end
  1922. if mover:match '%LBS$' then
  1923. if vb < 12.325 and headcheckb > 320 and headcheckb < 360
  1924. or vb < 12.325 and headcheckb < 40 and headcheckb > 0 then
  1925. tb[shipguid] = (vb)
  1926. end
  1927. else
  1928. if vb < 11.6 and headcheckb > 320 and headcheckb < 360
  1929. or vb < 11.6 and headcheckb < 40 and headcheckb > 0 then
  1930. tb[shipguid] = (vb)
  1931. end
  1932. end
  1933.  
  1934. xc = c[1] - pos[1]
  1935. yc = c[3] - pos[3]
  1936. vc = math.sqrt(xc*xc+yc*yc)
  1937. tallc[shipguid] = (vc)
  1938. if yc >= 0 then
  1939. dircc = 270 - math.deg(math.acos(xc/vc))
  1940. elseif yc < 0 and xc>= 0 then
  1941. dircc = 270 + math.deg(math.acos(xc/vc))
  1942. elseif yc < 0 and xc < 0 then
  1943. dircc = math.deg(math.acos(xc/vc)) - 90
  1944. end
  1945. headcheckc = dircc - rot[2]
  1946. if headcheckc < 0 then
  1947. headcheckc = headcheckc + 360
  1948. end
  1949. if mover:match '%LBS$' then
  1950. if vc < 12.325 and headcheckc > 320 and headcheckc < 360
  1951. or vc < 12.325 and headcheckc < 40 and headcheckc > 0 then
  1952. tc[shipguid] = (vc)
  1953. end
  1954. else
  1955. if vb < 11.6 and headcheckc > 320 and headcheckc < 360
  1956. or vb < 11.6 and headcheckc < 40 and headcheckc > 0 then
  1957. tc[shipguid] = (vc)
  1958. end
  1959. end
  1960.  
  1961. xd = d[1] - pos[1]
  1962. yd = d[3] - pos[3]
  1963. vd = math.sqrt(xd*xd+yd*yd)
  1964. talld[shipguid] = (vd)
  1965. if yd >= 0 then
  1966. dircd = 270 - math.deg(math.acos(xd/vd))
  1967. elseif yd < 0 and xd>= 0 then
  1968. dircd = 270 + math.deg(math.acos(xd/vd))
  1969. elseif yd < 0 and xd < 0 then
  1970. dircd = math.deg(math.acos(xd/vd)) - 90
  1971. end
  1972. headcheckd = dircd - rot[2]
  1973. if headcheckd < 0 then
  1974. headcheckd = headcheckd + 360
  1975. end
  1976. if mover:match '%LBS$' then
  1977. if vd < 12.325 and headcheckd > 320 and headcheckd < 360
  1978. or vd < 12.325 and headcheckd < 40 and headcheckd > 0 then
  1979. td[shipguid] = (vd)
  1980. end
  1981. else
  1982. if vd < 11.6 and headcheckd > 320 and headcheckd < 360
  1983. or vd < 11.6 and headcheckd < 40 and headcheckd > 0 then
  1984. end
  1985. end
  1986. end
  1987. end
  1988.  
  1989.  
  1990. function targeter(ta,tb,tc,td,talla,tallb,tallc,talld,target)
  1991. if next(ta) == nil
  1992. and next(tb) == nil
  1993. and next(tc) == nil
  1994. and next(td) == nil then
  1995.  
  1996. for k,v in pairs(talla) do
  1997. if target[2]>v then
  1998. target[2]=v
  1999. target[1]=k
  2000. end
  2001. end
  2002. for k,v in pairs(tallb) do
  2003. if target[2]>v then
  2004. target[2]=v
  2005. target[1]=k
  2006. end
  2007. end
  2008. for k,v in pairs(tallc) do
  2009. if target[2]>v then
  2010. target[2]=v
  2011. target[1]=k
  2012. end
  2013. end
  2014. for k,v in pairs(talld) do
  2015. if target[2]>v then
  2016. target[2]=v
  2017. target[1]=k
  2018. end
  2019. end
  2020. end
  2021.  
  2022. if next (ta) ~= nil then
  2023. for k,v in pairs(ta) do
  2024. if target[2]>v then
  2025. target[2]=v
  2026. target[1]=k
  2027. end
  2028. end
  2029. end
  2030. if next (tb) ~= nil then
  2031. for k,v in pairs(tb) do
  2032. if target[2]>v then
  2033. target[2]=v
  2034. target[1]=k
  2035. end
  2036. end
  2037. end
  2038. if next (tc) ~= nil then
  2039. for k,v in pairs(tc) do
  2040. if target[2]>v then
  2041. target[2]=v
  2042. target[1]=k
  2043. end
  2044. end
  2045. end
  2046. if next (td) ~= nil then
  2047. for k,v in pairs(td) do
  2048. if target[2]>v then
  2049. target[2]=v
  2050. target[1]=k
  2051. end
  2052. end
  2053. end
  2054. end
  2055.  
  2056.  
  2057.  
  2058. function findCorners(object)
  2059. local scalar = 0.85
  2060. if object.getName():match '%LGS$' then scalar = 1.63 end
  2061. local forward = getForwardVector(object.getGUID())
  2062. local f = {forward[1] * scalar, 0, forward[3] * scalar}
  2063. local corners = {}
  2064. corners[1] = { f[1] - f[3], 0, f[3] + f[1]}
  2065. corners[2] = { f[1] + f[3], 0, f[3] - f[1]}
  2066. corners[3] = {-f[1] - f[3], 0, -f[3] + f[1]}
  2067. corners[4] = {-f[1] + f[3], 0, -f[3] - f[1] }
  2068. return corners
  2069. end
  2070. function realDistance(guid1, guid2)
  2071. -- Lazy calc to start. need to go from nearest corner to nearest corner
  2072. local a = getObjectFromGUID(guid1)
  2073. local b = getObjectFromGUID(guid2)
  2074. local apos = a.getPosition()
  2075. local bpos = b.getPosition()
  2076. if a == nil or b == nil then return nil end
  2077. local dist = distance(apos[1],apos[3],bpos[1],bpos[3])
  2078. if a.getName():match '%LGS$' then dist = dist - 2.1 else dist = dist - 1.1 end
  2079. if b.getName():match '%LGS$' then dist = dist - 2.1 else dist = dist - 1.1 end
  2080. return dist
  2081. end
  2082.  
  2083. function isShip(ship)
  2084. return ship.tag == 'Figurine' and ship.name ~= '' and isInPlay(ship)
  2085. end
  2086.  
  2087. function isAi(ai)
  2088. local is_ai = ai.getName():match '^%[AI:?%u*:?%d*:?%w*].*'
  2089. return isShip(ai) and is_ai~=nil
  2090. end
  2091.  
  2092. function getAiType(ai)
  2093. local type = ai.getName():match '^%[AI:?(%u*):?%d*].*'
  2094. local validTypes = {"TIE","INT","ADV","BOM","DEF","PHA","DEC","SHU" }
  2095. if contains(validTypes,type) then
  2096. return type
  2097. else
  2098. -- printToAll("Error: "..ai.getName() .. " does not define valid type in format '[AI:{type}:{PS}] Name'",{1,0,0})
  2099. -- printToAll("Error: Implemented Types are: TIE, INT, ADV, BOM, DEF, PHA, DEC, SHU",{1,0,0})
  2100. return "INT"
  2101. end
  2102. end
  2103. function getSkill(ai)
  2104. return ai.getName():match '^%[%a*:?%u*:?(%d*)].*'
  2105. end
  2106. function getAiSquad(ai)
  2107. --return name:match '(%a+)[#%s]?%d+$'
  2108. return ai.getName():match '(%a+)#'
  2109. end
  2110. function getAiNumber(ai)
  2111. local num = ai.getName():match '#(%d+)'
  2112. if num == nil then return "0" else return num end
  2113. end
  2114. function getAiHasBoost(ai)
  2115. local type = getAiType(ai)
  2116. return type == "INT"
  2117. end
  2118. function getAiHasBarrelRoll(ai)
  2119. local type = getAiType(ai)
  2120. return type == "TIE" or type == "INT" or type == "ADV"or type == "BOM" or type == "DEF" or type == "PHA"
  2121. end
  2122. function isInPlay(object)
  2123. return math.abs(object.getPosition()[1])<18 and math.abs(object.getPosition()[3])<18
  2124. end
  2125. function contains(self, val)
  2126. for index, value in ipairs (self) do
  2127. if value == val then
  2128. return true
  2129. end
  2130. end
  2131.  
  2132. return false
  2133. end
  2134. function empty (self)
  2135. for _, _ in pairs(self) do
  2136. return false
  2137. end
  2138. return true
  2139. end
  2140.  
  2141. function log(string)
  2142. printToAll("[" .. os.date("%H:%M:%S") .. "] " .. string,{0, 0, 1})
  2143. end
  2144.  
  2145. function onObjectEnterScriptingZone(zone, object)
  2146. if zone.getGUID() == missionzone and object.tag == 'Card' and object.getName():match '^Mission: (.*)' then
  2147. object.clearButtons()
  2148. local offset = 0
  2149. for i,num in ipairs({1,2,3,4,5,6}) do
  2150. local p = {['click_function'] = 'Action_SetPlayer'..num, ['label'] = num..'P', ['position'] = {-1.5, 0.5, -1.3 + offset}, ['rotation'] = {0, 0, 0}, ['width'] = 250, ['height'] = 250, ['font_size'] = 200}
  2151. object.createButton(p)
  2152. offset = offset + 0.5
  2153. end
  2154. offset = 0
  2155. for i,num in ipairs({2,3,4,5,6,7,8,9,10}) do
  2156. local p = {['click_function'] = 'Action_SetPS'..num, ['label'] = num..'PS', ['position'] = {1.5, 0.5, -1.3 + offset}, ['rotation'] = {0, 0, 0}, ['width'] = 300, ['height'] = 200, ['font_size'] = 150}
  2157. object.createButton(p)
  2158. offset = offset + 0.3125
  2159. end
  2160. local p = {['click_function'] = 'Action_setup', ['label'] = 'Setup', ['position'] = {0, 0.5, -0.2}, ['rotation'] = {0, 0, 0}, ['width'] = 450, ['height'] = 200, ['font_size'] = 180}
  2161. object.createButton(p)
  2162. end
  2163. end
  2164. function Action_SetPlayer1() SetPlayers(1) end
  2165. function Action_SetPlayer2() SetPlayers(2) end
  2166. function Action_SetPlayer3() SetPlayers(3) end
  2167. function Action_SetPlayer4() SetPlayers(4) end
  2168. function Action_SetPlayer5() SetPlayers(5) end
  2169. function Action_SetPlayer6() SetPlayers(6) end
  2170. function SetPlayers(num) mission_players = num printToAll("Setting Number of Players to: "..num,{0,1,1}) end
  2171. function Action_SetPS2() SetPS(2) end
  2172. function Action_SetPS3() SetPS(3) end
  2173. function Action_SetPS4() SetPS(4) end
  2174. function Action_SetPS5() SetPS(5) end
  2175. function Action_SetPS6() SetPS(6) end
  2176. function Action_SetPS7() SetPS(7) end
  2177. function Action_SetPS8() SetPS(8) end
  2178. function Action_SetPS9() SetPS(9) end
  2179. function Action_SetPS10() SetPS(10) end
  2180. function SetPS(num) mission_ps = num printToAll("Setting Average Pilot Skill (PS) of Players to: "..num,{0,1,1}) end
  2181.  
  2182. TIE_SOURCE = '14a332'
  2183. function Action_setup(object)
  2184. if mission_ps == nil or mission_players == nil then
  2185. printToAll("Must select Number of players and Average Player Skill", {1,0,0})
  2186. else
  2187. local mission = object.getName():match '^Mission: (.*)'
  2188. local squads = {}
  2189. if mission == "Local Trouble" then
  2190. printToAll("Setting up: "..mission, {0,1,0})
  2191. table.insert(squads, {name="Alpha",arrival=0,vector=3,ai="Attack",type="TIE",count={1,1,0,1,0,1}})
  2192. table.insert(squads, {name="Beta",arrival=0,vector=4,ai="Attack",type="TIE",count={1,0,1,0,1,0}})
  2193. table.insert(squads, {name="Gamma",arrival=4,vector="1d6",ai="Attack",type="INT",count={1,0,0,1,0,0}})
  2194. table.insert(squads, {name="Delta",arrival=7,vector="1d6",ai="Attack",type="TIE",count={0,1,1,0,1,1}})
  2195. end
  2196. if mission == "Rescue Rebel Operatives" then
  2197.  
  2198. end
  2199. end
  2200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement