Sverkerman
Hosted Project: BoW
- Joined
- Feb 28, 2010
- Messages
- 1,325
Sometimes this code affects floating texts which it is not suppose to affect. Why is that?
JASS:
struct FDTPreparation extends FDT
private static method StartPrep takes nothing returns nothing
call .setup(thistype.create())
endmethod
private static method setup takes thistype this returns nothing
call .start(udg_DamageEventAmount,udg_DamageEventSource,udg_DamageEventTarget)
set udg_FDT_PreparationEvent = 0.00
endmethod
stub method onStart takes nothing returns nothing
local integer x = 0
loop
exitwhen GetOwningPlayer(.attackUnit) == Player(x)
set x = x + 1
endloop
if x == 0 then
set .textRed = 255
set .textGreen = 0
set .textBlue = 0
elseif x==1 then
set .textRed = 0
set .textGreen = 0
set .textBlue = 255
elseif x==2 then
set .textRed = 75
set .textGreen = 255
set .textBlue = 170
elseif x==3 then
set .textRed = 60
set .textGreen = 0
set .textBlue = 120
elseif x==4 then
set .textRed = 255
set .textGreen = 255
set .textBlue = 0
elseif x==5 then
set .textRed = 255
set .textGreen = 130
set .textBlue = 0
elseif x==6 then
set .textRed = 0
set .textGreen = 255
set .textBlue = 0
elseif x==7 then
set .textRed = 255
set .textGreen = 95
set .textBlue = 180
elseif x==8 then
set .textRed = 120
set .textGreen = 120
set .textBlue = 120
elseif x==9 then
set .textRed = 0
set .textGreen = 180
set .textBlue = 230
elseif x==10 then
set .textRed = 0
set .textGreen = 75
set .textBlue = 45
elseif x==11 then
set .textRed = 100
set .textGreen = 50
set .textBlue = 0
endif
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerAddAction(t, function thistype.StartPrep)
call TriggerRegisterVariableEvent(t,"udg_FDT_PreparationEvent",EQUAL,1.00)
endmethod
endstruct
JASS:
library FDTSystem
globals
real FDT_EDIT_PERIOD = 0.03125
real FDT_TEXT_LIFESPAN = 1.0
real FDT_TEXT_FADEPOINT = 0.2
integer FDT_TEXT_COLOR_RED = 255
integer FDT_TEXT_COLOR_GREEN = 255
integer FDT_TEXT_COLOR_BLUE = 255
integer FDT_TEXT_COLOR_ALPHA = 255
real FDT_TEXT_HEIGHT = 1.
real FDT_TEXT_FONT = 0.075
real FDT_TEXT_FONT_CHANGE = -0.0004
integer FDT_TEXT_X_VELOCITY_MAX = 85
integer FDT_TEXT_X_VELOCITY_MIN = 45
real FDT_TEXT_Y_VELOCITY = 0.1
real FDT_TEXT_Y_VELOCITY_CHANGE = -0.002
endglobals
module Events
stub method onStart takes nothing returns nothing
endmethod
endmodule
struct FDT
implement Events
//-----------------------------------------------------------------------------------------------------------------
//------------------------------------------------------//
// Values used by the system . SHOULDN'T BE CHANGED //
//------------------------------------------------------//
public integer textRed = FDT_TEXT_COLOR_RED
public integer textGreen = FDT_TEXT_COLOR_GREEN
public integer textBlue = FDT_TEXT_COLOR_BLUE
public integer textAlpha = FDT_TEXT_COLOR_ALPHA
public real textHeight = FDT_TEXT_HEIGHT
public real textFont = FDT_TEXT_FONT
public real textFontChange = FDT_TEXT_FONT_CHANGE
public real textLifespan = FDT_TEXT_LIFESPAN
public real textFadepoint = FDT_TEXT_FADEPOINT
public integer xVelocityMax = FDT_TEXT_X_VELOCITY_MAX
public integer xVelocityMin = FDT_TEXT_X_VELOCITY_MIN
public real yVelocity = FDT_TEXT_Y_VELOCITY
public real yVelocityChange = FDT_TEXT_Y_VELOCITY_CHANGE
readonly unit attackUnit = null
readonly unit targetUnit = null
private real xVelocity = 0.
private texttag textTag = null
private string textString = null
private real textTimeleft = 0.
private integer tick = 0
private real bang = 0.
private static timer t = null //period timer
private static integer count = 0 //instance counter
private boolean active = false //turns true when texttag created begins
private static thistype curText = 0 //equals to the current running instance
private boolean isTextReg = false //turns true when instance registered to the struct list
private thistype next
private thistype prev
private static thistype first
private static thistype last
private static thistype thiss
static method EditTextTag takes nothing returns nothing
local thistype this = thistype.curText
if .textTimeleft > 0.00 then
if .tick == 5 then
set .textFontChange = .textFontChange / 25
endif
set .yVelocity = .yVelocity + .yVelocityChange
set .textFont = .textFont + .textFontChange
call SetTextTagVelocity(.textTag,.xVelocity,.yVelocity)
call SetTextTagText(.textTag,.textString,.textFont)
set .textTimeleft = .textTimeleft - (.textLifespan * FDT_EDIT_PERIOD)
set .tick = .tick + 1
else
set .active = FALSE
endif
endmethod
static method TextList takes nothing returns nothing
local thistype trash
set thistype.thiss = thistype.first.next
loop
exitwhen thistype.thiss == thistype.last
if thistype.thiss.active and thistype.thiss != 0 then
set thistype.curText = thistype.thiss
call thistype.thiss.EditTextTag()
else
if thistype.thiss != 0 then
set thistype.thiss.next.prev = thistype.thiss.prev
set thistype.thiss.prev.next = thistype.thiss.next
set trash = thistype.thiss
set thistype.thiss = thistype.thiss.prev
call trash.destroy()
endif
set thistype.count = thistype.count -1
endif
set thistype.thiss = thistype.thiss.next
endloop
if thistype.count <= 0 then
set thistype.count = 0
call PauseTimer(thistype.t)
endif
endmethod
//-------------------REGISTERING-----LINKING IN THE LIST--------------------
public method start takes real Damage, unit AUnit, unit TUnit returns nothing
local thistype lth = thistype.last
set .attackUnit = AUnit
set .targetUnit = TUnit
call .onStart()
set .textFontChange = .textFontChange * 25
set .textTimeleft = .textLifespan * 2.0
set .textString = I2S(R2I(Damage))
set .bang = .textFont * 0.4
if GetRandomInt(0,1) == 1 then
set .xVelocity = I2R(GetRandomInt(.xVelocityMin,.xVelocityMax))/1000.0 * (-1)
else
set .xVelocity = I2R(GetRandomInt(.xVelocityMin,.xVelocityMax))/1000.0
endif
if GetLocalPlayer() == GetOwningPlayer(AUnit) or IsPlayerAlly(GetLocalPlayer(),GetOwningPlayer(AUnit)) then
set .textTag = CreateTextTag()
call SetTextTagColor(.textTag,.textRed,.textGreen,.textBlue,.textAlpha)
call SetTextTagPermanent(.textTag,false)
call SetTextTagLifespan(.textTag,.textLifespan)
call SetTextTagFadepoint(.textTag,.textFadepoint)
call SetTextTagVelocity(.textTag,.xVelocity,.yVelocity)
call SetTextTagPosUnit(.textTag,TUnit,/*.textHeight*/0.)
call SetTextTagText(.textTag,.textString,.textFont)
endif
if not .isTextReg then
set .active = true
set .isTextReg = true
//this goes here and there and that goes there and here...
set .prev = lth.prev
set .next = lth
set .prev.next = this
set lth.prev = this
set thistype.count = thistype.count + 1
if thistype.count == 1 then
call TimerStart(thistype.t, FDT_EDIT_PERIOD, true, function thistype.TextList)
endif
endif
endmethod
//----------------------------------------------------------------------------------------------------------
//-------------INITIALIZATIONS------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------
private static method onInit takes nothing returns nothing
set thistype.t = CreateTimer()
set thistype.first = .create()
set thistype.last = .create()
set thistype.first.next = thistype.last
set thistype.last.prev = thistype.first
endmethod
endstruct
endlibrary