System My Simple Projectile System

Jesus4Lyf

Good Idea™
Reaction score
397
It depends on design, y'know...

You can make an Event struct member, create it when you make the projectile, .chainDestroy() it when you destroy the projectile (instead of destroy, but I should fix that up some time) and then .fire() it when it hits a unit. Before calling fire, store any event responses in global variables and write little wrappers (SPS_GetTriggerProjectile(), SPS_GetProjectileX(proj), etc) that read em.

I would personally go with the module thing with defaults, and then just call the methods directly if they exist. More efficiency, and the data is right there for ya. :)

But this is the system design dilemmar I was speaking of. But I'd definitely do that if I could, it makes lots of sense. :p

Edit:
>EDIT: your edit confused me
I guess it was supposed to. :p
But if you remove the ...'s and implement that module in a struct, and call .startPeriodic() on it, you'll see if will spam call .onHit() 32 times a second if it exists in the struct. Think about the potential. :D
 

Exfyre

hmm...
Reaction score
60
I'm kind of stuck in my coding. You said to make an Event as a struct member, but how would I register that event by calling a public method?

JASS:
library SPS uses T32, Event
//configurables
globals
    private constant integer DUMMYUNIT='h001'
    private constant real GRAVITY = 1000  //How fast the missles fall
    private constant real POWERC = 40  //multiple for power
endglobals
//endconfigurables

globals
    private location L = Location(0,0)
    //private Event onHit
    unit Hurter
    real EndX
    real EndY
    integer AbilId
endglobals

private struct InstanceData
    Event onHit
    unit hurter
    unit dummy
    effect dummyeffect
    real time = 0
    real x
    real y
    real z
    real power
    real angle
    real rotation
    boolean follow
    string post
    integer abilId
    private method FindD takes real power, real angle, real time returns real
        return power*Cos(angle* bj_DEGTORAD)*time
    endmethod

    private method FindX takes real x, real rotation, real power, real angle, real time returns real
        return x + FindD(power, angle, time) * Cos(rotation * bj_DEGTORAD)
    endmethod

    private method FindY takes real y, real rotation, real power, real angle, real time returns real
        return y + FindD(power, angle, time) * Sin(rotation * bj_DEGTORAD)
    endmethod

    private method FindZ takes real power, real angle, real time returns real
        return (power*Sin(angle* bj_DEGTORAD)) * time - ((GRAVITY) * (time*time) / 2.)  //D=(Vi)t+(1/2)(a)(t^2)
    endmethod

    private method IsFalling takes real power, real angle, real time returns boolean
        return 2./time*(FindD(power, angle, time)/time-power)<0
    endmethod
    
    private method periodic takes nothing returns nothing
        local real time = this.time
        local real xx = FindX(this.x, this.rotation, this.power, this.angle, time)
        local real yy = FindY(this.y, this.rotation, this.power, this.angle, time)
        local real zz = FindZ(this.power, this.angle, this.time)
        set this.time = this.time + T32_PERIOD
        call SetUnitPosition(this.dummy, xx, yy)
        call SetUnitFlyHeight(this.dummy, zz, 0.0)
        if (this.follow==true) then
            call PanCameraToWithZ(xx, yy, zz)
        endif
        if zz <= 1 and IsFalling(this.power, this.angle, time) then
            call DestroyEffect(this.dummyeffect)
            call DestroyEffect(AddSpecialEffect(this.post, xx, yy))
            call RemoveUnit(this.dummy)
            set Hurter = this.hurter
            set EndX = this.x
            set EndY = this.y
            set AbilId = this.abilId
            call this.onHit.fire()
            //call onHit.fire()
            call this.stopPeriodic()
            call this.destroy()
            call this.onHit.chainDestroy()
            //call onHit.chainDestroy()
        endif
    endmethod
    private method register takes trigger t returns nothing
        call onHit.register(t)
    endmethod
    implement T32x
    static method create takes integer abilId, unit hurter, real x, real y, real scaling, real power, real angle, real rotation, string model, string post, boolean follow returns thistype
            local thistype this = thistype.allocate()
            set this.hurter = hurter
            set this.x = x
            set this.y = y
            set this.power = power*POWERC
            set this.angle = angle
            set this.rotation = rotation
            set this.post = post
            set this.follow = follow
            set this.abilId = abilId
            set this.dummy = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), DUMMYUNIT, x, y, 0)
            set this.dummyeffect = AddSpecialEffectTarget(model, this.dummy, "origin")
            set this.onHit = Event.create()
            //set onHit = Event.create()
            call SetUnitScale(this.dummy, scaling, scaling, scaling)
            call MoveLocation(L, x, y)
            set this.z = GetLocationZ(L)
            return this
    endmethod
endstruct

public function Add takes integer abilId, unit hurter, real x, real y, integer projectiles, real scaling, real power, real angle, real rotation, string model, string post, real spreadXY, real spreadZ, boolean follow returns nothing
    local InstanceData array d
    local integer i = 1
    loop
        exitwhen i == projectiles+1
        call InstanceData.create(abilId, hurter, x + GetRandomReal(0., spreadXY), y + GetRandomReal(0., spreadXY), scaling, power + (projectiles/2 - i) * spreadZ, angle, rotation, model, post, follow).startPeriodic()
        set i = i + 1
    endloop
endfunction

public function RegisterEvent takes trigger t returns nothing
    //question mark
endfunction

//wrappers
public function GetEndX takes nothing returns real
    return EndX
endfunction

public function GetEndY takes nothing returns real
    return EndY
endfunction

public function GetHurter takes nothing returns unit
    return Hurter
endfunction

public function GetAbilId takes nothing returns integer
    return AbilId
endfunction
//endwrappers
endlibrary
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
function ProjectileRegisterOnHit takes InstanceData p, trigger t returns nothing
    call p.onHit.register(t)
endfunction

That kinda thing. You could do something like LastCreatedProjectileRegisterOnHit if you keep storing the last created projectile in a global. You can see design flaws showing up... ;)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top