Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- function gadget:GetInfo()
- return {
- name = "Laser Designator",
- desc = "",
- author = "quantum",
- date = "May 2010",
- license = "GNU GPL, v2 or later",
- layer = 5,
- enabled = true
- }
- end
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- if gadgetHandler:IsSyncedCode() then
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- local Spring, pairs, ipairs = Spring, pairs, ipairs
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- local damageMult = 1
- local duration = 0.5 * 30 -- in frames
- GG.targets = {}
- local targets = GG.targets
- local designatorWeaponIDs = {}
- for i = 1, #WeaponDefs do
- if WeaponDefs[i].customParams.designator then
- designatorWeaponIDs[WeaponDefs[i].id] = true
- end
- end
- --[[
- local targetingLinks = {}
- local targetDesignators = {}
- --]]
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- local function raiseLaserEvent(eventArgs)
- _G.laserEventArgs = eventArgs
- SendToUnsynced("LaserEvent")
- _G.laserEventArgs = nil
- end
- function gadget:UnitPreDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam)
- if weaponID and designatorWeaponIDs[weaponID] and GG.creeps[unitID] then -- hit by a laser designator
- if not targets[unitID] then
- targets[unitID] = {expiration = Spring.GetGameFrame() + duration}
- raiseLaserEvent{addTarget = true, unitID = unitID}
- for turretID in pairs(GG.turrets) do -- make every turret attack the designated unit
- Spring.SetUnitTarget(turretID, unitID)
- end
- end
- end
- return damage
- end
- function gadget:GameFrame(frame)
- if frame % 23 == 0 then
- for unitID, unitInfo in pairs(targets) do
- if unitInfo.expiration < frame then
- targets[unitID] = nil
- raiseLaserEvent{removeTarget = true, unitID = unitID}
- end
- end
- end
- end
- function gadget:UnitDestroyed(unitID)
- if targets[unitID] then
- targets[unitID] = nil
- raiseLaserEvent{removeTarget = true, unitID = unitID}
- end
- end
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- else
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- --- Unsynced
- --------------------------------------------------------------------------------
- local function drawTarget()
- gl.Color(1, 1, 1, 1)
- gl.PushMatrix()
- gl.Billboard()
- gl.Texture("bitmaps/gpl/point2.png")
- gl.TexRect(-8, -8, 8, 8)
- gl.PopMatrix()
- end
- function gadget:Initialize()
- gadgetHandler:AddSyncAction("LaserEvent", HandleLaserEvent)
- end
- local targets = {}
- function HandleLaserEvent()
- local eventArgs = {}
- for k, v in spairs(SYNCED.laserEventArgs) do
- eventArgs[k] = v
- end
- if eventArgs.addTarget then
- targets[eventArgs.unitID] = true
- elseif eventArgs.removeTarget then
- targets[eventArgs.unitID] = nil
- end
- end
- function gadget:DrawWorld()
- for unitID in pairs(targets) do
- gl.DrawFuncAtUnit(unitID, false, drawTarget)
- end
- end
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement