ForbodingAngel

Untitled

Feb 21st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. --------------------------------------------------------------------------------
  3.  
  4. -- Automatically generated local definitions
  5.  
  6. local CMDTYPE_ICON = CMDTYPE.ICON
  7. local CMD_STOP = CMD.STOP
  8. local spDestroyUnit = Spring.DestroyUnit
  9. local spGetGameFrame = Spring.GetGameFrame
  10. local spGetLocalAllyTeamID = Spring.GetLocalAllyTeamID
  11. local spGetSpectatingState = Spring.GetSpectatingState
  12. local spGetUnitAllyTeam = Spring.GetUnitAllyTeam
  13. local spGetUnitBasePosition = Spring.GetUnitBasePosition
  14. local spGetUnitDefID = Spring.GetUnitDefID
  15. local spGetUnitHeight = Spring.GetUnitHeight
  16. local spGetUnitTeam = Spring.GetUnitTeam
  17. local spInsertUnitCmdDesc = Spring.InsertUnitCmdDesc
  18.  
  19. --------------------------------------------------------------------------------
  20. --------------------------------------------------------------------------------
  21.  
  22. function gadget:GetInfo()
  23. return {
  24. name = "sell",
  25. desc = "press buton, reciev moniez",
  26. author = "KDR_11k (David Becker)",
  27. date = "2008-06-12",
  28. license = "Public Domain",
  29. layer = 300,
  30. enabled = true
  31. }
  32. end
  33.  
  34. local refundFactor = .5 --How much of the original price is returned
  35. local sellFactor = 1 --Factor for the buildtime
  36. local CMD_SELL = 39867
  37.  
  38. if (gadgetHandler:IsSyncedCode()) then
  39.  
  40. --SYNCED
  41.  
  42. local GetGameFrame = spGetGameFrame
  43. local min = math.min
  44.  
  45. local sellDesc = {
  46. name="Sell",
  47. tooltip="Sell the building for a partial refund",
  48. action="sell",
  49. type=CMDTYPE_ICON,
  50. texture="bitmaps/ui/command_buttons/cmd_sell.png",
  51. id=CMD_SELL,
  52. }
  53.  
  54. local saleTime={}
  55.  
  56. local resources
  57. local unitCost
  58. local capacity
  59. local resCount
  60.  
  61. function gadget:AllowCommand(u, ud, team, cmd, param, opt)
  62. if cmd == CMD_SELL then
  63. if (not UnitDefs[ud].canMove or UnitDefs[ud].isFactory == true) and not UnitDefs[ud].customParams.nosale then
  64. if not saleTime[u] then
  65. saleTime[u]=GetGameFrame() + UnitDefs[ud].buildTime * 30 * sellFactor
  66. elseif opt.right then
  67. saleTime[u]=nil
  68. end
  69. end
  70. return false
  71. end
  72. if cmd == CMD_STOP and saleTime[u] then --Let a stop command abort the sale
  73. saleTime[u]=nil
  74. return false
  75. end
  76. return true
  77. end
  78.  
  79. function gadget:UnitCreated(u, ud, team)
  80. if (not UnitDefs[ud].canMove or UnitDefs[ud].isFactory == true) and not UnitDefs[ud].customParams.nosale then
  81. spInsertUnitCmdDesc(u, sellDesc)
  82. end
  83. end
  84.  
  85. --function gadget:CommandFallback(u, ud, team, cmd, param, opt)
  86. -- if cmd == CMD_SELL then
  87. -- saleTime[u]=GetGameFrame() + UnitDefs[ud].buildTime * 30
  88. -- return true, true
  89. -- end
  90. -- return false
  91. --end
  92.  
  93. function gadget:UnitDestroyed(u, ud, team)
  94. saleTime[u]=nil
  95. end
  96.  
  97.  
  98. function gadget:GameFrame(f)
  99. if f % 12 < .1 then
  100. for u,t in pairs(saleTime) do
  101. if t < f then
  102. local ud = spGetUnitDefID(u)
  103. local team = spGetUnitTeam(u)
  104. spDestroyUnit(u, false, true)
  105. for i = 1,resCount do
  106. resources[team][i] = min(resources[team][i] + (unitCost[ud][i] or 0) * refundFactor, capacity[team][i])
  107. end
  108. end
  109. end
  110. end
  111. end
  112.  
  113. function gadget:Initialize()
  114. resources = GG.resources
  115. unitCost = GG.unitCost
  116. capacity = GG.capacities
  117. resCount = GG.resCount
  118. _G.unitsBeingSold=saleTime
  119. end
  120.  
  121. else
  122.  
  123. --UNSYNCED
  124.  
  125. local glBillboard = gl.Billboard
  126. local glColor = gl.Color
  127. local glPopMatrix = gl.PopMatrix
  128. local glPushMatrix = gl.PushMatrix
  129. local glTexRect = gl.TexRect
  130. local glText = gl.Text
  131. local glTexture = gl.Texture
  132. local glTranslate = gl.Translate
  133.  
  134. local Texture = glTexture
  135. local PushMatrix = glPushMatrix
  136. local Translate = glTranslate
  137. local Billboard = glBillboard
  138. local TexRect = glTexRect
  139. local PopMatrix = glPopMatrix
  140. local Text = glText
  141. local Color = glColor
  142.  
  143. local GetUnitAllyTeam = spGetUnitAllyTeam
  144. local GetUnitBasePosition = spGetUnitBasePosition
  145. local GetUnitHeight = spGetUnitHeight
  146. local GetLocalAllyTeamID = spGetLocalAllyTeamID
  147. local GetSpectatingState = spGetSpectatingState
  148. local GetGameFrame = spGetGameFrame
  149. local ceiling = math.ceil
  150.  
  151. function gadget:DrawWorld()
  152. local team = GetLocalAllyTeamID()
  153. local _,_,spec = GetSpectatingState()
  154. local f = GetGameFrame()
  155. for u,b in spairs(SYNCED.unitsBeingSold) do
  156. if GetUnitAllyTeam(u) == team or spec then
  157. PushMatrix()
  158. local x,y,z = GetUnitBasePosition(u)
  159. Translate(x,y + 80 + GetUnitHeight(u),z)
  160. Billboard()
  161. Texture("bitmaps/icons/selling.png") --Sale icon goes here
  162. TexRect(-20,-20,20,20)
  163. Text(ceiling((b - f)/30.0), 0, -25, 16, "oc")
  164. PopMatrix()
  165. end
  166. end
  167. Texture(false)
  168. end
  169.  
  170. end
Advertisement
Add Comment
Please, Sign In to add comment