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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top