Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function widget:GetInfo()
- return {
- name = "JigokuShoujo",
- desc = "Go to HELL",
- author = "banana_Ai",
- date = "31 Aug 2013",
- license = "GNU GPL v2",
- layer = 0,
- enabled = true, -- loaded by default?
- }
- end
- local localTeamID=Spring.GetLocalTeamID()
- local localAlly=Spring.GetLocalAllyTeamID()
- --------------------------------------------------
- -- options
- local lighnessK=1.8 -- than big this number than lighter will be map when u select units
- local silence=false -- no auto-chat stuff?
- ---------------------------------------------------
- -- quotes
- -- to remove any quote just remove it from the list
- local quotesList={
- -- enemie's comm got killed by your units
- ["enComKilled"]={"Perhaps, it is time to die..."}, -- {"Oh, pitiful shadow lost in the darkness, bringing torment and pain to others,",
- -- "Oh, damned soul wallowing in your sin, Perhaps, it is time to die..."}
- -- you nuke someone
- ["nukeLaunch"]={"SHINY"}
- }
- -- send quote to chat
- local function DisplayMessage(teamID,quoteName)
- if silence then return end
- local playerName=""
- if teamID then
- local _,playerID=Spring.GetTeamInfo(teamID)
- playerName=Spring.GetPlayerInfo(playerID)
- playerName=playerName..": "
- end
- local quote=quotesList[quoteName]
- if quote then
- for i=1,#quote,1 do
- Spring.SendCommands("say "..playerName..quote[i])
- end
- end
- end
- -------------------------------------------------------
- -- SHINY!
- local nukeDefID=UnitDefNames["corsilo"].id
- local lastNuke=0
- function widget:StockpileChanged(unitID, unitDefID, unitTeam, weaponNum, oldCount, newCount)
- if unitTeam==localTeamID and unitDefID==nukeDefID and newCount<oldCount then
- local now=Spring.GetGameSeconds()
- if now-lastNuke>2 then
- DisplayMessage(nil,"nukeLaunch")
- end
- lastNuke=now
- end
- end
- ----------------------------------------------------------
- -- unitName -> true
- local NamesAADefense={
- { "armcir" , true }, --chainsaw
- { "corrl" , true }, --defender
- { "corrazor" , true }, --razorkiss
- { "corflak" , true }, --flak
- { "screamer" , true }, --screamer
- { "missiletower" , true }, --hacksaw
- --mobile AA
- { "amphaa", true },
- { "armaak", true},
- { "armjeth", true},
- { "corarch", true},
- { "corcrash", true},
- { "corsent", true},
- { "gunshipaa", true},
- { "hoveraa", true},
- { "spideraa", true},
- { "vehaa", true},
- }
- -- convert array form unitName -> true to unitDefID -> true
- local function convertUnitsArray(array)
- local endAr={}
- for i=1,#array,1 do
- local p=array[i]
- local ud=UnitDefNames[ p[1] ]
- if ud then
- endAr[ud.id]=p[2]
- --Spring.Echo(p[1].." to "..ud.id)
- end
- end
- return endAr
- end
- local function GetAAWeaponData(ud)
- local dps=0
- local maxrange=0
- local weapData=ud.weapons
- for i=1,#weapData,1 do
- local weaponDef = WeaponDefs[weapData[i].weaponDef]
- if not weaponDef.isShield then
- local maxdmg=0
- local burst=weaponDef.salvoSize or 1
- local projectiles= weaponDef.projectiles or 1
- local reload = weaponDef.reload or 1
- local range=weaponDef.range or 0
- maxrange=math.max(maxrange,range)
- for key, val in pairs(weaponDef.damages) do
- maxdmg=math.max(maxdmg,val)
- end
- dps=dps+maxdmg*burst*projectiles/reload
- end
- end
- return dps,maxrange
- end
- AADefense=convertUnitsArray(NamesAADefense) -- defID -> true
- -- defID -> {dps,range,mobile}
- local maxDPS=0
- for defID,_ in pairs(AADefense) do
- local dps,maxrange=GetAAWeaponData(UnitDefs[defID])
- local canMove=UnitDefs[defID].canMove
- maxDPS=math.max(maxDPS,dps)
- AADefense[defID]={dps=dps,range=maxrange,mobile=canMove}
- end
- local defenseList={} -- unitID -> {defID,ally,pos}
- -- based on code from gui_defenseRange.lua
- -- add unit into defenseList
- local function AddAA(unitID)
- local unitDefID=Spring.GetUnitDefID(unitID)
- if not unitDefID or not AADefense[unitDefID] or defenseList[unitID] then return end
- local data={}
- data.defID=unitDefID
- if Spring.GetUnitAllyTeam(unitID)==localAlly then
- data.ally=true
- end
- local x,y,z=Spring.GetUnitPosition(unitID)
- data.pos={x,y,z}
- -- I do not know what is going on here
- local _,_,_,_,build=Spring.GetUnitHealth(unitID)
- data.complited=(build or 0)==1
- defenseList[unitID]=data
- end
- -----------------------------------------------------
- local mode=Game.gameShortName or Game.modShortName
- local dotaComDefID
- if mode=="zkdota" then
- dotaComDefID=UnitDefNames["custom_com_amp"].id
- end
- local enComsInfo={}
- function widget:UnitEnteredLos(unitID, teamID)
- if Spring.AreTeamsAllied(teamID,Spring.GetMyTeamID()) then return end
- local unitDefID=Spring.GetUnitDefID(unitID)
- if unitDefID then
- -- add AA
- AddAA(unitID)
- -- Add commander
- if mode=="zkdota" and unitDefID==dotaComDefID then
- enComsInfo[unitID]={defID=unitDefID,yoffset=UnitDefs[unitDefID].height+14}
- elseif mode=="ZK" and UnitDefs[unitDefID].customParams.commtype then
- local data={defID=unitDefID,yoffset=UnitDefs[unitDefID].height+14}
- local commModules = WG.GetCommModules and WG.GetCommModules(unitDefID)
- data.modules={}
- if commModules then
- for i=1, #commModules,1 do
- local cmod=commModules[i]
- if cmod=="Personal Cloak" then
- data.modules.pcloak=true
- elseif cmod=="Lazarus Device" then
- data.modules.lazarus=true
- end
- end
- end
- data.weapons={}
- data.dps=0
- data.wdps=0
- data.maxrange=0
- data.range=999999
- data.dmg=0
- data.wdmg=0
- local weapData=UnitDefs[unitDefID].weapons
- for i=1,#weapData,1 do
- local weaponDef = WeaponDefs[weapData[i].weaponDef]
- if not weaponDef.isShield then
- if weaponDef.description=="Disintegrator" then
- data.weapons.disintegrator=true
- elseif weaponDef.description=="Shock Rifle" then
- data.weapons.srifle=(data.weapons.srifle and data.weapons.srifle+1) or 1
- end
- local maxdmg=0
- local burst=weaponDef.salvoSize or 1
- local projectiles= weaponDef.projectiles or 1
- local reload = weaponDef.reload or 1
- local extraDmg= weaponDef.customParams.extra_damage or 0
- local range=weaponDef.range or 0
- data.maxrange=math.max(data.maxrange,range)
- if range>0 then
- data.range=math.min(data.range,range)
- end
- for key, val in pairs(weaponDef.damages) do
- maxdmg=math.max(maxdmg,val)
- end
- if weaponDef.paralyzer then
- data.wdmg=data.wdmg+maxdmg*burst*projectiles*3
- data.dmg=data.dmg+extraDmg*burst*projectiles
- data.wdps=data.wdps+maxdmg*burst*projectiles*3/reload
- data.dps=data.dps+extraDmg*burst*projectiles/reload
- else
- data.dmg=data.dmg+maxdmg*burst*projectiles
- data.dmg=data.dmg+extraDmg*burst*projectiles
- data.dps=data.dps+maxdmg*burst*projectiles/reload
- data.dps=data.dps+extraDmg*burst*projectiles/reload
- end
- end
- end
- enComsInfo[unitID]=data
- end
- end
- end
- function widget:UnitLeftRadar(unitID, unitTeam)
- if defenseList[unitID] then
- local defData=AADefense[defenseList[unitID].defID]
- if defData.mobile==true then
- local x,y,z=Spring.GetUnitPosition(unitID)
- if x and y and z then
- local inLosOrRadar=Spring.GetPositionLosState(x,y,z)
- if not inLosOrRadar then
- defenseList[unitID]=nil
- end
- else
- defenseList[unitID]=nil
- end
- end
- end
- end
- function widget:UnitLeftLos(unitID, unitDefID, teamID)
- enComsInfo[unitID]=nil
- if defenseList[unitID] then
- local defData=AADefense[defenseList[unitID].defID]
- if defData.mobile==true then
- local x,y,z=Spring.GetUnitPosition(unitID)
- if x and y and z then
- local inLosOrRadar=Spring.GetPositionLosState(x,y,z)
- if not inLosOrRadar then
- defenseList[unitID]=nil
- end
- else
- defenseList[unitID]=nil
- end
- end
- end
- end
- function widget:TeamDied(teamID)
- if not Spring.AreTeamsAllied(teamID,Spring.GetMyTeamID()) and teamID~=Spring.GetGaiaTeamID() then
- local _,playerID,dead,_,_,ally=Spring.GetTeamInfo(teamID)
- local teams=Spring.GetTeamList(ally)
- for i=1,#teams,1 do
- local t=teams[i]
- if t~=teamID then
- local _,_,isDead,_,_,_=Spring.GetTeamInfo(t)
- if isDead==false then
- return
- end
- end
- end
- -- AllyTeam is dead
- -- Do whatever u want
- end
- end
- function widget:GameFrame(frame)
- for unitID, data in pairs(enComsInfo) do
- local hp=Spring.GetUnitHealth(unitID)
- if hp then
- if hp<=0 then
- -- Com is DEAD!
- enComsInfo[unitID]=nil
- local attackerID=Spring.GetUnitLastAttacker(unitID)
- if attackerID then
- if Spring.GetUnitTeam(attackerID)==localTeamID then
- DisplayMessage(Spring.GetUnitTeam(unitID),"enComKilled") -- Perhaps, it is time to die...
- end
- end
- end
- end
- end
- if frame%10 then
- -- code based on code from gui_defenseRange.lua
- for unitID,data in pairs(defenseList) do
- local defData=AADefense[data.defID]
- if defData.mobile~=true then
- local x,y,z=data.pos[1],data.pos[2],data.pos[3]
- local inLosOrRadar, inLos, inRadar = Spring.GetPositionLosState(x, y, z)
- if inLos==true then
- if not Spring.GetUnitDefID(unitID) then
- defenseList[unitID]=nil --killed
- elseif not data.complited then
- local _,_,_,_,build=Spring.GetUnitHealth(unitID)
- data.complited=(build or 0)==1
- end
- end
- else
- if not data.complited then
- local _,_,_,_,build=Spring.GetUnitHealth(unitID)
- data.complited=(build or 0)==1
- end
- end
- end
- end
- end
- function widget:UnitCreated(unitID, unitDefID, teamID, builderID)
- AddAA(unitID)
- end
- function widget:UnitDestroyed(unitID)
- defenseList[unitID]=nil
- end
- function widget:TextCommand(command)
- local args={}
- for arg in command:gmatch("%w+") do
- args[#args+1]=arg
- end
- if args[1]=="note" then
- local selectedUnits=Spring.GetSelectedUnits()
- if #selectedUnits>0 then
- local unitID=selectedUnits[1]
- end
- end
- end
- -- draw tip for coms
- local function DrawTip(unitID,data)
- gl.Translate(0, data.yoffset,0)
- gl.Billboard()
- gl.Translate(0, 5 ,0)
- if mode=="zkdota" then
- -- not ready yet
- --local ud=UnitDefs[data.defID]
- elseif mode=="ZK" then
- local str=""
- if data.dmg>0 then
- str=str.." DMG"..data.dmg..":DPS"..data.dps
- end
- if data.wdmg>0 then
- str=str.." DMG"..data.wdmg..":DPS"..data.wdps.."P"
- end
- str=str.." RNG"..data.maxrange..">"..data.range
- if data.modules.pcloak then
- str=str.." PersCloak"
- end
- if data.modules.lazarus then
- str=str.." LazDev"
- end
- if data.weapons.disintegrator then
- str=str.." DG"
- end
- if data.weapons.srifle then
- if data.weapons.srifle==2 then
- str=str.." 2ShockR"
- end
- end
- gl.Text(str, 0, 0, 8, "co")
- end
- end
- local function DrawDecloackRange(r,yoffset)
- gl.Translate(0, data.yoffset,0)
- gl.DrawGroundCircle(0,0,0,r,15)
- end
- local function DrawGroundLine(x1,z1,x2,z2,w)
- local vec={x2-x1,z2-z1}
- local len=math.sqrt(vec[1]*vec[1]+vec[2]*vec[2])
- local a=math.atan2(vec[1],vec[2])
- gl.Utilities.DrawGroundLine(x1+w/2,z1+w/2,w,len,a)
- end
- -- code from gfx_night.lua
- local function DrawNight()
- gl.Blending(GL.ZERO, GL.SRC_COLOR)
- gl.MatrixMode(GL.PROJECTION)
- gl.PushMatrix()
- gl.LoadIdentity()
- gl.MatrixMode(GL.MODELVIEW)
- gl.PushMatrix()
- gl.LoadIdentity()
- gl.Color(0.2*lighnessK, 0.25*lighnessK, 0.3*lighnessK)
- gl.Rect(-1,1,1,-1)
- gl.MatrixMode(GL.PROJECTION)
- gl.PopMatrix()
- gl.MatrixMode(GL.MODELVIEW)
- gl.PopMatrix()
- gl.Color(1, 1, 1, 1)
- gl.Blending(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
- end
- -----
- local function Range2(x1,z1,x2,z2)
- return (x1-x2)*(x1-x2)+(z1-z2)*(z1-z2)
- end
- local function DrawRange(x1,z1,r1,x2,z2,r2,diam)
- local unitDist=math.sqrt(Range2(x1,z1,x2,z2))-r1-r2;
- if unitDist<=diam then
- gl.Color(1,0,0,0.2)
- DrawGroundLine(x1,z1,x2,z2,2)
- elseif unitDist>diam and unitDist<diam*1.3 then
- gl.Color(1,1,0,0.2)
- DrawGroundLine(x1,z1,x2,z2,2)
- elseif unitDist>=diam*1.3 and unitDist<=diam*2 then
- gl.Color(0,1,0,0.2)
- DrawGroundLine(x1,z1,x2,z2,2)
- end
- end
- local function UnitsRangeBetwen(uid,range,units)
- local diam=range*2
- for i=1,#units,1 do
- local ally = Spring.GetUnitAllyTeam(units[i])
- local x1,_,z1 = Spring.GetUnitPosition(units[i])
- local r1 = Spring.GetUnitRadius(units[i])
- if units[i]~=uid and ally~=localAlly and x1 and z1 and r1 then
- for j=1,#units,1 do
- local ally2=Spring.GetUnitAllyTeam(units[j])
- if i~=j and units[j]~=uid and ally2~=localAlly then
- local x2,_,z2=Spring.GetUnitPosition(units[j])
- local r2 = Spring.GetUnitRadius(units[j])
- if x2 and z2 and r2 then
- DrawRange(x1,z1,r1,x2,z2,r2,diam)
- end
- end
- end
- end
- end
- end
- local function DrawCloakRanges(selectedUnits)
- DrawNight()
- local alreadyDrawed={}
- for i=1,#selectedUnits,1 do
- local unitID=selectedUnits[i]
- local unitDefID=Spring.GetUnitDefID(unitID)
- local cloaked=Spring.GetUnitIsCloaked(unitID)
- if cloaked then
- local r=UnitDefs[unitDefID].decloakDistance
- local x,_,z=Spring.GetUnitPosition(unitID)
- gl.Color(0,1,0,0.2)
- gl.Utilities.DrawGroundCircle(x,z,r)
- local enemyID=Spring.GetUnitNearestEnemy(unitID,r*3)
- if enemyID then
- local ex,_,ez=Spring.GetUnitPosition(enemyID)
- if ex and ez then
- local rangeTo=math.sqrt((x-ex)*(x-ex)+(z-ez)*(z-ez))
- if rangeTo>r then
- gl.Color(1,0,0,0.2)
- DrawGroundLine(x,z,ex,ez,5)
- end
- end
- end
- local enUnitsList=Spring.GetUnitsInCylinder(x,z,r*3)
- UnitsRangeBetwen(unitID,r,enUnitsList)
- if enUnitsList then
- for i=1,#enUnitsList,1 do
- local uid=enUnitsList[i]
- if not alreadyDrawed[uid] then
- local ux,_,uz=Spring.GetUnitPosition(uid)
- local ally=Spring.GetUnitAllyTeam(uid)
- local mradious=Spring.GetUnitRadius(uid)
- if mradious and ux and uz and ally~=localAlly then
- gl.Color(0,0,1,0.2)
- gl.Utilities.DrawGroundCircle(ux,uz,mradious)
- alreadyDrawed[uid]=true
- end
- end
- end
- end
- end
- end
- end
- local AAalphaMin=0.03
- local AAalphaMax=0.5
- local dpsK=(AAalphaMax-AAalphaMin)/maxDPS
- local function DrawAAMap()
- DrawNight()
- for unitID,data in pairs(defenseList) do
- if data.complited then
- local defData=AADefense[data.defID]
- local alpha=AAalphaMin + dpsK*defData.dps
- if data.ally then
- gl.Color(0,1.0,0,alpha)
- else
- gl.Color(1,0,0,alpha)
- end
- local x,z
- if defData.mobile then
- x,_,z = Spring.GetUnitPosition(unitID)
- else
- x,z=data.pos[1],data.pos[3]
- end
- if x and z then
- gl.Utilities.DrawGroundCircle(x,z,defData.range)
- end
- end
- end
- end
- function widget:DrawWorldPreUnit()
- local selectedUnits=Spring.GetSelectedUnits()
- for i=1,#selectedUnits,1 do
- local unitID=selectedUnits[i]
- local unitDefID=Spring.GetUnitDefID(unitID)
- if unitDefID then
- if Spring.GetUnitIsCloaked(unitID) then
- DrawCloakRanges(selectedUnits)
- break
- elseif UnitDefs[unitDefID].canFly==true or AADefense[unitDefID] then
- DrawAAMap()
- break
- end
- end
- end
- end
- function widget:DrawWorld()
- if Spring.IsGUIHidden() then return end
- gl.DepthTest(true)
- gl.Color(1, 1, 1)
- --fontHandler.UseDefaultFont()
- for unitID, data in pairs(enComsInfo) do
- gl.DrawFuncAtUnit(unitID, false, DrawTip, unitID,data)
- end
- gl.DepthTest(false)
- end
- -- redefine some gl.Utilities functions
- if (not gl) then
- return
- end
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- -- Exported Functions:
- -- gl.Utilities.DrawMyBox(minX,minY,minZ, maxX,maxY,maxZ)
- -- gl.Utilities.DrawMyCylinder(x,y,z, height,radius,divs)
- -- gl.Utilities.DrawMyHollowCylinder(x,y,z, height,radius,innerRadius,divs)
- -- gl.Utilities.DrawGroundLine(x,z,w,h,a) -- new one
- -- gl.Utilities.DrawGroundCircle(x,z,radius)
- -- gl.Utilities.DrawGroundHollowCircle(x,z,radius,innerRadius)
- -- gl.Utilities.DrawVolume(vol_dlist)
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- VFS.Include("LuaRules/Utilities/glVolumes.lua")
- do
- gl.Utilities = gl.Utilities or {}
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- local glVertex = gl.Vertex
- local box = gl.CreateList(gl.Utilities.DrawMyBox,0,-0.5,0,1,0.5,1)
- local heightMargin = 2000
- local minheight, maxheight = Spring.GetGroundExtremes()
- local averageGroundHeight = (minheight + maxheight) / 2
- local shapeHeight = heightMargin + (maxheight - minheight) + heightMargin
- function gl.Utilities.DrawGroundLine(x,z,w,h,a)
- gl.PushMatrix()
- gl.Translate(x, averageGroundHeight, z)
- gl.Rotate(180*a/math.pi,0,1,0)
- gl.Scale(w, shapeHeight, h)
- gl.Utilities.DrawVolume(box)
- gl.PopMatrix()
- end
- --------------------------------------------------------------------------------
- --------------------------------------------------------------------------------
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement