- Joined
- Sep 12, 2008
- Messages
- 657
Hey.. before i took a break from WC for a while,
i used Parabola formula to determinate ARC for projectiles,
well now i fail at it
and besides, i made it calculate all the ARC values in a seperate function, so i found another bug doing that,
whenever my real "arcValue" is not equal to 0, whether im calling the calculation or not,
my all code stops working, and it wont collide with any enemy, and extra to that, the bullet just falls down, and vanishes.
when its equal to 0, the bullet just flies straight to the point its meant to go to, and then hits anything in its way.. right now i cant find the problem :/
heres the code:
thanks in advance.
edit: sorry, gah, i forgot its jass, so i wrote code/trigger in bracelets ;/
i used Parabola formula to determinate ARC for projectiles,
well now i fail at it
and besides, i made it calculate all the ARC values in a seperate function, so i found another bug doing that,
whenever my real "arcValue" is not equal to 0, whether im calling the calculation or not,
my all code stops working, and it wont collide with any enemy, and extra to that, the bullet just falls down, and vanishes.
when its equal to 0, the bullet just flies straight to the point its meant to go to, and then hits anything in its way.. right now i cant find the problem :/
heres the code:
JASS:
library MissleSystem initializer onInit requires /*
*/ Vector /* [url]www.wc3c.net/showthread.php?t=87027[/url]
*/ ArmorUtils /* [url]www.wc3c.net/showthread.php?t=105849[/url]
*/ GroupUtils /* [url]http://www.wc3c.net/showthread.php?t=104464[/url]
*/
struct Missle
public static thistype t = 0
public static thistype t2 = 0
public static location D_Loc = Location(0, 0)
public static real TimerInterval = 0.032
public static integer Dummy_Unit = 'e000'
public static integer flight_ability = 'Amrf'
//---------------------------------------------------------------------------------
public unit Object = null
public unit Target = null
public player Owner = null
public vector Start = 0
public vector Pos = 0
public vector Reach = 0
public real Velocity = 0
public real Damage = 0
public real Angle = 0
public real ArcCurve = 0
public real passedDistance = 0
public boolean ignoreArmor = false
public effect Model
public static method create takes player owner, real x, real y, string SFX, string attachPoint returns thistype
set t = t + 1
set t2 = t2 + 1
call MoveLocation(D_Loc, x, y)
set t.Object = CreateUnit(owner, Dummy_Unit, x, y, 0)
set t.Pos = vector.create(x, y, GetLocationZ(D_Loc))
set t.Start = t.Pos
set t.Owner = owner
set t.Model = AddSpecialEffectTarget(SFX, t.Object, attachPoint)
set t.Velocity = 0
set t.Damage = 0
set t.Angle = 0
set t.ArcCurve = 0
set t.passedDistance = 0
set t.ignoreArmor = false
call t.allowHeight()
return t
endmethod
private static method DistanceBetweenVectors takes vector a, vector b returns real
local real dx = b.x - a.x
local real dy = b.y - a.y
return SquareRoot(dx * dx + dy * dy)
endmethod
private static method JumpParabola takes real dist, real maxdist,real curve returns real
// This function calculates the unit Z for a parabolic arc, by Shadow1500
local real t = (dist*2)/maxdist-1
return (-t*t+1)*(maxdist/curve)
endmethod
private static method GetUnitZ takes unit u returns real
// finds a unit location Z, instead using another location.
return GetCoordinateZ(GetUnitX(u), GetUnitY(u))
endmethod
private static method GetCoordinateZ takes real x, real y returns real
// finds x/y location Z using a re-used dummy.
call MoveLocation(D_Loc, x, y)
return GetLocationZ(D_Loc)
endmethod
private static method GetZFactor takes real NewX, real NewY, real OldX, real OldY returns real
// this function caculates the Z offset of 2 locations.
// this function is by Inferior from hiveworkshop.com
local real z = 0
call MoveLocation(D_Loc, NewX, NewY)
set z = GetLocationZ(D_Loc)
call MoveLocation(D_Loc, OldX, OldY)
return z - GetLocationZ(D_Loc)
endmethod
private method CaculateArc takes nothing returns nothing
local real dx = 0
local real dy = 0
local real dx2 = 0
local real dy2 = 0
local real md = Reach
local real height = 0
set dx = Start.x - Pos.x
set dy = Start.y - Pos.y
set dx2 = Reach.x
set dy2 = Reach.y
set height = JumpParabola(SquareRoot(dx * dx + dy * dy), SquareRoot(dx2 * dx2 + dy2 * dy2), ArcCurve)
call SetUnitFlyHeight(Object, height, 0)
endmethod
public method allowHeight takes nothing returns nothing
call UnitAddAbility(Object, flight_ability)
call UnitRemoveAbility(Object, flight_ability)
endmethod
public method destroy takes nothing returns nothing
call SetUnitExploded(Object, true)
set Object = null
set Target = null
set Owner = null
set Pos = 0
set Reach = 0
set passedDistance = 0
set Velocity = 0
call DestroyEffect(Model)
set Model = null
set ignoreArmor = false
set t2 = t2 - 1
endmethod
public method TimeToDistance takes real time returns real
return time * (Velocity / TimerInterval)
endmethod
public method SetDestinationTime takes real time returns nothing
local real a = TimeToDistance(time)
set Reach = vector.create(Pos.x + a, Pos.y + a, GetCoordinateZ(Pos.x + a, Pos.y + a))
set Angle = GetUnitFacing(Object)
endmethod
public method SetDestinationXY takes real x, real y returns nothing
set Reach = vector.create(x, y, GetCoordinateZ(x, y))
set Angle = Atan2(Reach.y - Pos.y, Reach.x - Pos.x)
endmethod
public method SetDestination takes real distance returns nothing
set Reach = vector.create(Pos.x + distance, Pos.y + distance, GetCoordinateZ(Pos.x + distance, Pos.y + distance))
set Angle = GetUnitFacing(Object)
endmethod
private method DummyBer takes nothing returns boolean
return GetUnitState(Target, UNIT_STATE_LIFE) > 0 and not IsUnitOwnedByPlayer(Target, Owner)
endmethod
public method onLoop takes nothing returns nothing
local real armor = 0
local real damage = 0
local group g = NewGroup()
call GroupUnitsInArea(g, Pos.x, Pos.y, 75)
set Target = FirstOfGroup(g)
if not (Target == null) and DummyBer() then
set armor = GetUnitArmor(Target)
if ignoreArmor == false then
set damage = GetReducedDamage(Damage, armor)
else
set damage = GetFullDamage(Damage, armor)
endif
call UnitDamageTarget(Object, Target, damage, true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
call destroy()
endif
set Pos.x = GetUnitX(Object) + Velocity * Cos (Angle)
set Pos.y = GetUnitY(Object) + Velocity * Sin (Angle)
call SetUnitX(Object, Pos.x)
call SetUnitY(Object, Pos.y)
//call CaculateArc()
if passedDistance >= Reach then
call destroy()
else
set passedDistance = passedDistance + Velocity
endif
call ReleaseGroup(g)
endmethod
endstruct
private function loopHandler takes nothing returns nothing
local integer i = 0
local integer end = s__Missle_t
if end > 0 then
loop
set i = i + 1
call s__Missle_onLoop(i)
exitwhen i == end
endloop
endif
endfunction
private function onInit takes nothing returns nothing
call TimerStart(CreateTimer(), s__Missle_TimerInterval, true, function loopHandler)
endfunction
endlibrary
thanks in advance.

edit: sorry, gah, i forgot its jass, so i wrote code/trigger in bracelets ;/