HiKitty

Create a gridID for shield grids with Zero-K's lua gadgets

Jul 12th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. ### Conclusion: ###
  2.  
  3. I want a gridID for every shield grid in a game like http://Zero-K.info.
  4.  
  5. BUT
  6.  
  7. Grids
  8. * can get decimated by a single shield at a time
  9. * can grow by adding new shields
  10. * removed at once or by a random percentage by atomar nukes
  11. * split into a random number of grids
  12. * created from a new shield unit and a random number of grids
  13. * can have only 1 shield
  14.  
  15.  
  16. ### Numbers and Table-sizes ###
  17.  
  18. IMPORTANT:
  19. Above the following specifications, lags are possible and caused by boring or Epic_Shore-games.
  20. If you get over these specifications, the rest of the code would lag anyway.
  21.  
  22. Unit ids:
  23. 1 to 500 (extreme cases like chicken games)
  24.  
  25. Teams:
  26. 1-4 (extreme cases like FFA)
  27.  
  28. Max shields per team:
  29. 250 shields *2 teams
  30. 125 shields *4 teams
  31.  
  32. Worst case(s):
  33. 190 in the biggest group and 20 single groups with up to 3 entries each (per team)
  34. 250 shields in 150 groups
  35.  
  36.  
  37. ### Code structures ###
  38.  
  39. Original code source: http://code.google.com/p/zero-k/source/browse/trunk/mods/zk/LuaRules/Gadgets/unit_shield_link.lua
  40.  
  41. AdjustLinks() is called every Second from gadget:GameFrame
  42.  
  43.  
  44. ### Table structures ###
  45.  
  46. shieldUnit = {
  47.     -- shield unit created:
  48.     capacity = max charge
  49.     regen = charge+
  50.     regenEfficiency = charge+ / energy-
  51.  
  52.     -- AdjustLinks() re-generates every second:
  53.     link = { [unitID] = shieldUnit, ... } --each shieldUnit of a grid has the same table
  54.     x, y, z = unit position
  55.     linkable = not inbuild and not stunned and not active == false and valid unit position
  56.  
  57.     --[[
  58.         --su = shieldUnit = customTable --every Spring unit which got a shield has one customTable
  59.         --id = UnitID from Spring
  60.         if  su5 connects su(1&2) with su(3&4)
  61.         then  su(1..5).link == { id5=su5, id1=su1, id2=su2, id3=su3, id4=su4 }
  62.     --]]
  63. }
  64.  
  65. shieldConnections[teamID] = { --created by AdjustLinks()
  66.     [unitID1]=(adjacent unitID2),
  67.     --NEVER [unitID2]=unitID1,
  68.     [unitID3]=(adjacent unitID4),
  69.     ...
  70. }
  71.  
  72.  
  73. And lua-tables are not sorted in the order you added the entries if you don't assign values to incremental keys
  74. * It might get out as 3,1,5,2,4
Advertisement
Add Comment
Please, Sign In to add comment