HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Help] Keeping a lightning in a damn box

04-29-2009, 08:15 AM#1
Tide-Arc Ephemera
Collapse JASS:
function Trig_Attacks_Actions takes nothing returns nothing
    local integer ATTACK_TYPE = GetSpellAbilityId()
    local unit attacker = GetTriggerUnit()
    local unit attacked = GetSpellTargetUnit()
    local real x1 = GetUnitX(attacker)
    local real y1 = GetUnitY(attacker)
    local real x2 = GetUnitX(attacked)
    local real y2 = GetUnitY(attacked)
    local real x3 = 0
    local real y3 = 0
    local real grad = 0
    local real r = 0
    local integer i = 0
    if ATTACK_TYPE == 'A000' then // Laser attack
         loop
             set i = i + 1
         exitwhen i == udg_LASER_Max or udg_LASER_InUse[i] == false
         endloop
         set udg_LocSPFX = Location(0,0)
         set udg_LASER_Bolt[i] = AddLightningLoc( udg_LASER_Type[GetUnitAbilityLevel(attacker,ATTACK_TYPE)], udg_LocSPFX, udg_LocSPFX )
         set udg_LASER_Fade1[i] = 1.5
         set udg_LASER_Fade2[i] = 0.02
         set udg_LASER_FadeHold[i] = 0
         set udg_LASER_Full[i] = 1.0
         set udg_LASER_InUse[i] = true
         set udg_LASER_R[i] = 1.0
         set udg_LASER_G[i] = 1.0
         set udg_LASER_B[i] = 1.0
         set grad = (y2 - y1) / (x2 - x1)
         set r = y1 - grad * x1
         if x2 < x1 then
             set x3 = GetRectMinX(udg_PlayerRegion[GetPlayerId(GetOwningPlayer(attacker))])
             set y3 = (grad * x3) + r
         else
             set x3 = GetRectMaxX(udg_PlayerRegion[GetPlayerId(GetOwningPlayer(attacker))])
             set y3 = (grad * x3) + r
         endif
         call SetLightningColorBJ( udg_LASER_Bolt[i], 0.25, 1., 1., 1 )
         call MoveLightningEx( udg_LASER_Bolt[i], true, x1, y1, 50, x3, y3, 50 )
    endif
endfunction

//===========================================================================
function InitTrig_Attacks takes nothing returns nothing
    set gg_trg_Attacks = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Attacks, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_Attacks, function Trig_Attacks_Actions )
endfunction

The issue with the highlighted section is that it confines stuff into an infinite rectangle involving the maximum and minimum Y, but not into a finite square involving the maximum and minimum X.

What the problem is:
I have a square and I have several laser-shooting units inside it. The laser is confined with a maximum distance to the left and right, but there are no constrictions for the top and bottom.

What I need to fix it is:
Solved - An accurate formula that gets a line going through 2 points, starting from the "first one" of them, but still staying inside the square
- A way of "closing" the laser from going through the top and bottom boundaries of the square

Old info

What I need is:
- How to confine it to inside the square

Another big problem:
The accuracy of my "angler" is way off, it worked before but for some reason not now.

04-29-2009, 11:11 AM#2
Bobo_The_Kodo
[jass]
known:x1,x2,y1,y2

local real m = (y2-y1)/(x2-x1)
local real b = y1 - m * x1
04-29-2009, 11:56 AM#3
Tide-Arc Ephemera
Okay, that fixes the accuracy PERFECTLY. Now all I need is a how-to-confine-into-box-along-the-y-axes.
04-30-2009, 05:55 AM#4
Tide-Arc Ephemera
Bump.

EDIT!
Explanatory diagram attached.
Attached Images
File type: jpgUntitled-1.jpg (98.8 KB)