Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

cribolouf Apr 9th, 2020 235 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onLoad(str_SaveState)
  2.     --Make all objects non-interactable
  3.     for Index, Object in pairs(getAllObjects()) do interactable(Object, false) end
  4.  
  5.     --Initialize battlefield
  6.     BattlefieldSize = 8
  7. end
  8.  
  9. function onPlayerTurnStart(str_PlayerColorStart, str_PlayerColorPrevious)
  10.     --[[Generate a table of all models, and a table of all models that can be
  11.     moved by str_PlayerColorStart, and make them interactable. Make all other
  12.     models non-interactable]]
  13.     Models = {}
  14.     ModelsMoveable = {}
  15.     for Index, Object in pairs(getAllObjects()) do
  16.         if Object.getVar("Controller") then table.insert(Models, Object) end
  17.         if Object.getVar("Controller") == str_PlayerColorStart and Object.getVar("MoveMaximum") then
  18.             table.insert(ModelsMoveable, Object)
  19.             PositionObject = Object.getPosition()
  20.             RotationObject = Object.getRotation()
  21.             Object.setVar("PositionBackupX", PositionObject.x)
  22.             Object.setVar("PositionBackupY", PositionObject.y)
  23.             Object.setVar("PositionBackupZ", PositionObject.z)
  24.             Object.setVar("RotationBackupX", RotationObject.x)
  25.             Object.setVar("RotationBackupY", RotationObject.y)
  26.             Object.setVar("RotationBackupZ", RotationObject.z)
  27.             Object.setVar("HasMoved", false)
  28.             interactable(Object, true)
  29.         else interactable(Object, false)
  30.         end
  31.     end
  32.  
  33.     --Start of Movement Phase
  34.     PickedUnitID = 0
  35.     broadcastToAll("Movement Phase")
  36. end
  37.  
  38. function onObjectPickUp(str_PlayerColor, obj_PickedUpObject)
  39.     --Get the position and rotation of obj_PickedUpObject
  40.     PositionOriginal = obj_PickedUpObject.getPosition()
  41.     RotationOriginal = obj_PickedUpObject.getRotation()
  42.  
  43.     --[[If obj_PickedUpObject is from a unit that was already picked, exit
  44.     function]]
  45.     if obj_PickedUpObject.getVar("UnitID") == PickedUnitID then return end
  46.  
  47.     --Make all models in the previous unit non-interactable
  48.     for Index, Model in pairs(ModelsMoveable) do
  49.         if Model.getVar("UnitID") == PickedUnitID then
  50.             Model.setVar("HasMoved", true)
  51.             interactable(Model, false)
  52.         end
  53.     end
  54.  
  55.     --Declare unit as picked
  56.     PickedUnitID = obj_PickedUpObject.getVar("UnitID")
  57.     PickedUnitName = obj_PickedUpObject.getVar("UnitName")
  58.     PickedUnitModelsMoved = 0
  59.     print(Player[str_PlayerColor].steam_name .. " has picked " .. obj_PickedUpObject.getVar("UnitName") .. " to move.")
  60. end
  61.  
  62. function onObjectDrop(str_PlayerColor, obj_DroppedObject)
  63.     --Find distance that obj_DroppedObject was moved
  64.     DistanceMoved = math.sqrt((obj_DroppedObject.getPosition().x - PositionOriginal.x) ^ 2 + (obj_DroppedObject.getPosition().z - PositionOriginal.z) ^ 2)
  65.  
  66.     --[[Illegal movement cases:
  67.  
  68.     Case 1: obj_DroppedObject was moved less than its Minimum Move characteristic
  69.  
  70.     Case 2: obj_DroppedObject was moved more than its Maximum Move characteristic
  71.  
  72.     Case 3: obj_DroppedObject was moved over the edge of the battlefield
  73.  
  74.     Case 4: obj_DroppedObject was moved onto another model
  75.  
  76.     Case 5: obj_DroppedObject was moved within 1" of an enemy model]]
  77.     if obj_DroppedObject.getVar("MoveMinimum") and DistanceMoved < obj_DroppedObject.getVar("MoveMinimum") then illegalMove(obj_DroppedObject, "A model may not be moved a distance, in inches, less than the Minimum Move characteristic on its datasheet.", str_PlayerColor) return
  78.     elseif DistanceMoved > obj_DroppedObject.getVar("MoveMaximum") then illegalMove(obj_DroppedObject, "A model may not be moved a distance, in inches, greater than the Maximum Move characteristic on its datasheet.", str_PlayerColor) return
  79.     elseif math.abs(obj_DroppedObject.getPosition().x) + obj_DroppedObject.getVar("BaseSize") / 50.8 > BattlefieldSize * 6 or math.abs(obj_DroppedObject.getPosition().z) + obj_DroppedObject.getVar("BaseSize") / 50.8 > 24 then illegalMove(obj_DroppedObject, "A model may not be moved over the edge of the battlefield.", str_PlayerColor) return
  80.     end
  81.     for Index, Model in pairs(Models) do
  82.         if Model.getVar("Controller") ~= obj_DroppedObject.getVar("Controller") and threatRadius(PositionOriginal.x, PositionOriginal.z, obj_DroppedObject.getPosition().x, obj_DroppedObject.getPosition().z, Model.getPosition().x, Model.get_Position().z, 1 + obj_DroppedObject.getVar("BaseSize") / 50.8 + Model.getVar("BaseSize") / 50.8) then illegalMove(obj_DroppedObject, "A model may not be moved within 1\" of enemy models.", str_PlayerColor) return
  83.         elseif Model ~= obj_DroppedObject and threatRadius(PositionOriginal.x, PositionOriginal.z, obj_DroppedObject.getPosition().x, obj_DroppedObject.getPosition().z, Model.getPosition().x, Model.get_Position().z, 0 + obj_DroppedObject.getVar("BaseSize") / 50.8 + Model.getVar("BaseSize") / 50.8) then illegalMove(obj_DroppedObject, "A model may not be moved through other models.", str_PlayerColor) return
  84.         end
  85.     end
  86.  
  87.  
  88.  
  89.     --Declare obj_DroppedObject as moved
  90.     PickedUnitModelsMoved = PickedUnitModelsMoved + 1
  91.     obj_DroppedObject.setVar("HasMoved", true)
  92.     interactable(obj_DroppedObject, false)
  93.     print(Player[str_PlayerColor].steam_name .. " moved " .. obj_DroppedObject.getVar("ModelName") .. " " .. math.floor(math.sqrt((obj_DroppedObject.getPosition().x - PositionOriginal.x) ^ 2 + (obj_DroppedObject.getPosition().z - PositionOriginal.z) ^ 2) * 10 ^ 1 + 0.5) / 10 ^ 1 .. "\".")
  94.  
  95.     --[[Post-movement unit coherence cases:
  96.  
  97.     Case 1: obj_DroppedObject belongs to a unit that consists of only one
  98.     model
  99.  
  100.     Case 2: obj_DroppedObject belongs to a coherent unit
  101.  
  102.     Case 3: obj_DroppedObject is not the last model to be moved in a unit
  103.     that is not coherent
  104.  
  105.     Case 4: obj_DroppedObject is the last model to be moved in a unit that is
  106.     not coherent]]
  107.     if obj_DroppedObject.getVar("NumberOfModelsInUnit") == 1 then return
  108.     elseif unitCoherence(PickedUnitID) then
  109.         for Index, Model in pairs(ModelsMoveable) do
  110.             if Model.getVar("HasMoved") == false then interactable(Model, true) end
  111.         end
  112.     elseif PickedUnitModelsMoved < obj_DroppedObject.getVar("NumberOfModelsInUnit") then
  113.         for Index, Model in pairs(ModelsMoveable) do
  114.             if Model.getVar("UnitID") ~= PickedUnitID then interactable(Model, false) end
  115.         end
  116.     else
  117.         for Index, Model in pairs(modelsInUnit(PickedUnitID)) do
  118.             Model.setPosition({Model.getVar("PositionBackupX"), Model.getVar("PositionBackupY"), Model.getVar("PositionBackupZ")})
  119.             Model.setRotation({Model.getVar("RotationBackupX"), Model.getVar("RotationBackupY"), Model.getVar("RotationBackupZ")})
  120.             Model.setVar("HasMoved", false)
  121.             interactable(Model, true)
  122.         end
  123.         PickedUnitModelsMoved = 0
  124.         broadcastToColor("A unit must finish any sort of move as a group, with every model within 2\" horizontally, and 6\" vertically, of at least one other model from their unit.", str_PlayerColor, "Red")
  125.         print(Player[str_PlayerColor].steam_name .. " must redo the movement of " .. PickedUnitName .. " due to lack of unit coherence.")
  126.     end
  127. end
  128.  
  129. --Sets obj_Object as interactable or non-interactable
  130. function interactable(obj_Object, bool_Interactable)
  131.     if bool_Interactable then
  132.         obj_Object.highlightOn("Green")
  133.         obj_Object.interactable = true
  134.     else
  135.         obj_Object.highlightOff()
  136.         obj_Object.interactable = false
  137.     end
  138. end
  139.  
  140. --Returns a table of models in int_UnitID
  141. function modelsInUnit(int_UnitID)
  142.     ModelsInUnit = {}
  143.     for Index, Model in pairs(Models) do
  144.         if Model.getVar("UnitID") == int_UnitID then table.insert(ModelsInUnit, Model) end
  145.     end
  146.     return ModelsInUnit
  147. end
  148.  
  149. --Moved obj_Model to its original position and rotation
  150. function illegalMove(obj_Model, str_BroadcastMessage, str_PlayerColor)
  151.     obj_Model.setPosition(PositionOriginal)
  152.     obj_Model.setRotation(RotationOriginal)
  153.     broadcastToColor(str_BroadcastMessage, str_PlayerColor, "Red") return
  154. end
  155.  
  156. --Returns true if int_UnitID is coherent, otherwise returns false
  157. function unitCoherence(int_UnitID)
  158.     ModelsInUnit = modelsInUnit(int_UnitID)
  159.     Model1 = ModelsInUnit[1]
  160.     table.remove(ModelsInUnit, 1)
  161.     repeat
  162.         for Index, Model2 in pairs(ModelsInUnit) do
  163.             PositionModel1 = Model1.getPosition()
  164.             PositionModel2 = Model2.getPosition()
  165.             if math.sqrt((PositionModel1.x - PositionModel2.x) ^ 2 + (PositionModel1.z - PositionModel2.z) ^ 2) - Model1.getVar("BaseSize") / 50.8 - Model2.getVar("BaseSize") / 50.8 <= 2 and PositionModel1.y - PositionModel2.y <= 6 then
  166.                 Model1 = Model2
  167.                 table.remove(ModelsInUnit, Index)
  168.                 ModelCoherence = true break
  169.             else ModelCoherence = false
  170.             end
  171.         end
  172.         if not ModelCoherence then return false end
  173.     until not ModelsInUnit[1]
  174.     return true
  175. end
  176.  
  177. --[[Returns true if the line formed by a moving model passes through int_Radius
  178. of another model, otherwise returns false]]
  179. function threatRadius(float_Position1X1, float_Position1Z1, float_Position1X2, float_Position1Z2, float_Position2X, float_Position2Z, float_Radius)
  180.     if ((float_Position2Z - float_Position1Z1) * (float_Position1Z2 - float_Position1Z1) + (float_Position2X - float_Position1X1) * (float_Position1X2 - float_Position1X1)) / ((float_Position1Z2 - float_Position1Z1) * (float_Position1Z2 - float_Position1Z1) + (float_Position1X2 - float_Position1X1) * (float_Position1X2 - float_Position1X1)) >= 0 and ((float_Position2Z - float_Position1Z1) * (float_Position1Z2 - float_Position1Z1) + (float_Position2X - float_Position1X1) * (float_Position1X2 - float_Position1X1)) / ((float_Position1Z2 - float_Position1Z1) * (float_Position1Z2 - float_Position1Z1) + (float_Position1X2 - float_Position1X1) * (float_Position1X2 - float_Position1X1)) <= 1 then
  181.         if math.sqrt(((((float_Position2Z - float_Position1Z1) * (float_Position1Z2 - float_Position1Z1) + (float_Position2X - float_Position1X1) * (float_Position1X2 - float_Position1X1)) / ((float_Position1Z2 - float_Position1Z1) * (float_Position1Z2 - float_Position1Z1) + (float_Position1X2 - float_Position1X1) * (float_Position1X2 - float_Position1X1))) * (float_Position1X2 - float_Position1X1) + float_Position1X1 - float_Position2X) ^ 2 + ((((float_Position2Z - float_Position1Z1) * (float_Position1Z2 - float_Position1Z1) + (float_Position2X - float_Position1X1) * (float_Position1X2 - float_Position1X1)) / ((float_Position1Z2 - float_Position1Z1) * (float_Position1Z2 - float_Position1Z1) + (float_Position1X2 - float_Position1X1) * (float_Position1X2 - float_Position1X1))) * (float_Position1Z2 - float_Position1Z1) + float_Position1Z1 - float_Position2Z) ^ 2) <= float_Radius then return true else return false end
  182.     elseif math.sqrt((float_Position2X - float_Position1X1) ^ 2 + (float_Position2Z - float_Position1Z1) ^ 2) <= float_Radius then return true
  183.     elseif math.sqrt((float_Position2X - float_Position1X2) ^ 2 + (float_Position2Z - float_Position1Z2) ^ 2) <= float_Radius then return true
  184.     end
  185.     return false
  186. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top