struct shadow
readonly real x
readonly real y
readonly real centrex
readonly real centrey
readonly real width
readonly real height
readonly integer r
readonly integer g
readonly integer b
readonly integer a
readonly unit u
readonly string path
readonly image i
readonly boolean enabled = true
readonly boolean deadunit = false
readonly integer position //position in relation to struct stack
static method Create takes unit u, real centrex, real centrey, real width, real height, integer alpha, string path returns shadow
local shadow s = shadow.create()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
set s.x = x
set s.y = y
set s.width = width
set s.height = height
set s.a = alpha
set s.u = u
set s.centrex = centrex
set s.centrey = centrey
set s.path = path
if path == "normal" or path == "Normal" or path == "NORMAL" or path == "Shadow" or path == "shadow" or path == "SHADOW" then
set s.path = "ReplaceableTextures\\Shadows\\Shadow.blp"
elseif path == "flyer" or path == "Flyer" or path == "FLYER" or path == "ShadowFlyer" or path == "shadowflyer" or path == "SHADOWFLYER" then
set s.path = "Textures\\Shadow.blp"
elseif path == "none" or path == "None" or path == "NONE" then
set s.path = ""
endif
set s.i = CreateImage(s.path, width, height, 0, x - (width / 2), y - (height / 2), 0, centrex, centrey, 0, 2) // image type indicator
call SetImageRenderAlways(s.i, true)
call ShowImage(s.i, true)
call SetImageColor(s.i,255,255,255,alpha)
set s.r = 255
set s.g = 255
set s.b = 255
set s.a = 180
//Update Struct Stack
if s_StructFreeNumber<0 then
set s.position = s_StructNumber
set s_StructStack[s_StructNumber] = s
set s_StructNumber = s_StructNumber+1
else
set s.position = s_StructFreeStack[s_StructFreeNumber]
set s_StructStack[s.position] = s
set s_StructFreeStack[s_StructFreeNumber] = -1
set s_StructFreeNumber = s_StructFreeNumber-1
endif
//! runtextmacro AMHS_StoreStructShadow("s.u","s")
return s
endmethod
public method ChangeDeadUnit takes boolean flag returns nothing
set this.deadunit = flag
endmethod
method GetShadowPath takes nothing returns string
return this.path
endmethod
method GetShadowAlpha takes nothing returns integer
return this.a
endmethod
method GetShadowRed takes nothing returns integer
return this.r
endmethod
method GetShadowGreen takes nothing returns integer
return this.g
endmethod
method GetShadowBlue takes nothing returns integer
return this.b
endmethod
method GetShadowCentreX takes nothing returns real
return this.centrex
endmethod
method GetShadowCentreY takes nothing returns real
return this.centrey
endmethod
method GetShadowHeight takes nothing returns real
return this.height
endmethod
method GetShadowWidth takes nothing returns real
return this.width
endmethod
method GetShadowUnit takes nothing returns unit
return this.u
endmethod
method GetDefaultShadowCentreX takes nothing returns real
local string s = UnitId2String(GetUnitTypeId(this.u))
if GetStoredBoolean(fp_datacache,s,"exist") == true then
return GetStoredReal(fp_datacache,s,"centrex")
else
return I2R(0)
endif
endmethod
method GetDefaultShadowCentreY takes nothing returns real
local string s = UnitId2String(GetUnitTypeId(this.u))
if GetStoredBoolean(fp_datacache,s,"exist") == true then
return GetStoredReal(fp_datacache,s,"centrey")
else
return I2R(0)
endif
endmethod
method GetDefaultShadowHeight takes nothing returns real
local string s = UnitId2String(GetUnitTypeId(this.u))
if GetStoredBoolean(fp_datacache,s,"exist") == true then
return GetStoredReal(fp_datacache,s,"height")
else
return I2R(0)
endif
endmethod
method GetDefaultShadowWidth takes nothing returns real
local string s = UnitId2String(GetUnitTypeId(this.u))
if GetStoredBoolean(fp_datacache,s,"exist") == true then
return GetStoredReal(fp_datacache,s,"width")
else
return I2R(0)
endif
endmethod
method GetDefaultShadowPath takes nothing returns string
local string s = UnitId2String(GetUnitTypeId(this.u))
if GetStoredBoolean(fp_datacache,s,"exist") == true then
return GetStoredString(fp_datacache,s,"path")
else
return ""
endif
endmethod
method SetShadowColor takes integer red, integer green, integer blue, integer alpha returns nothing
call SetImageColor(this.i,red,green,blue,alpha)
set this.r = red
set this.g = green
set this.b = blue
set this.a = alpha
endmethod
method SetShadowAlpha takes integer alpha returns nothing
call SetImageColor(this.i,this.r,this.g,this.b,alpha)
set this.a = alpha
endmethod
method SetShadowVisibility takes boolean visibility returns nothing
call ShowImage(this.i,visibility)
set this.enabled = visibility
endmethod
method SetShadowImage takes string path returns nothing
local string truepath = path
call DestroyImage(this.i)
set this.i = null
if path == "normal" or path == "Normal" or path == "NORMAL" then
set truepath = "ReplaceableTextures\\Shadows\\Shadow.blp"
elseif path == "flyer" or path == "Flyer" or path == "FLYER" then
set truepath = "Textures\\Shadow.blp"
elseif path == "none" or path == "None" or path == "NONE" then
set truepath = ""
endif
set this.i = CreateImage(truepath, this.width, this.height, 0, this.x - (this.width / 2), this.y - (this.height / 2), 0, this.centrex, this.centrey, 0, 2) // image type indicator
set this.path = truepath
call SetImageRenderAlways(this.i, true)
call ShowImage(this.i, true)
call SetImageColor(this.i,this.r,this.g,this.b,this.a)
endmethod
method SetShadowImageEx takes string path, real centrex, real centrey, real width, real height returns nothing
local string truepath = path
call DestroyImage(this.i)
set this.i = null
if path == "normal" or path == "Normal" or path == "NORMAL" then
set truepath = "ReplaceableTextures\\Shadows\\Shadow.blp"
elseif path == "flyer" or path == "Flyer" or path == "FLYER" then
set truepath = "Textures\\Shadow.blp"
elseif path == "none" or path == "None" or path == "NONE" then
set truepath = ""
endif
set this.i = CreateImage(truepath, width, height, 0, this.x - (width / 2), this.y - (height / 2), 0, centrex, centrey, 0, 2) // image type indicator
set this.path = truepath
set this.centrex = centrex
set this.centrey = centrey
set this.width = width
set this.height = height
call SetImageRenderAlways(this.i, true)
call ShowImage(this.i, true)
call SetImageColor(this.i,this.r,this.g,this.b,this.a)
endmethod
method SetShadowDimeansions takes real centrex, real centrey, real width, real height returns nothing
call DestroyImage(this.i)
set this.i = null
set this.i = CreateImage(this.path, width, height, 0, this.x - (width / 2), this.y - (height / 2), 0, centrex, centrey, 0, 2) // image type indicator
set this.centrex = centrex
set this.centrey = centrey
set this.width = width
set this.height = height
call SetImageRenderAlways(this.i, true)
call ShowImage(this.i, true)
call SetImageColor(this.i,this.r,this.g,this.b,this.a)
endmethod
method onDestroy takes nothing returns nothing
call DestroyImage(this.i)
set this.i = null
set s_StructStack[this.position] = -1
if (this.position>=(s_StructNumber-1)) then
set s_StructNumber = s_StructNumber-1
else
set s_StructFreeNumber = s_StructFreeNumber+1
set s_StructFreeStack[s_StructFreeNumber] = this.position
endif
//! runtextmacro AMHS_DestroyStructShadow("this.u")
set this.u = null
set this.position = -1
endmethod
endstruct