1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  4. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  5. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Snippet] [Needs work] Projectile Utils

Discussion in 'Graveyard' started by Bribe, Aug 24, 2010.

  1. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Bribe I have updated my submission with version 2.1, it includes a member for target height-offset which may make your life a little bit easier.
     
  2. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    OK, more changes have been implemented. I have stripped some existing features so that future systems will have a more readable API. It was not very easy to determine functions which take different parameters.

    SetProjectileImpactEvent
    takes a projectile as its first parameter, yet it looks similar to
    SetProjectileOffsets
    , which, by looking at it, could also appear to take a projectile as its first parameter.

    The new API makes a handy distinction;

    SetProjectileVisualsById - takes a unit id as a first parameter
    SetProjectileOffsetsById - takes a unit id...
    SetProjectileImpactEvent - takes a projectile.

    LastCreatedProjectile is no longer a variable, but I don't think it was that useful. Users can still reference that same thing via GetLastCreatedProjectile(). The variable now uses a shorter name internally for readability.

    Impact offsets have been reduced to a single height-offset. WarCraft III projectiles do not factor in collision size, so to make things simple, more efficient and compatible, this library now only has the three launch-offsets and an impact-height offset.

    The two functions SetProjectileImpactOffsets and SetProjectileLaunchOffsets have been consolidated into SetProjectileOffsetsById.

    The 'Table' library is now a requirement. I could make this script look even uglier and make it optional with static-ifs, but it's a great library to have in your map anyway.
     
  3. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,221
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    You could make a chain module, that would be really great.
     
  4. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    What do you mean specifically by a chain module, and how would it relate to this system? I'm completely uninformed on that one.
     
  5. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,221
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Chain module = A module that extends Projectile and gives the user the functionality to cast chain lightnings.
     
  6. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    That isn't really Projectile Utilities though, it would be pretty easy to sequentially launch a projectile once it executes the
    onFinish
    method and keep
    toDestroy
    as false until the last target.

    Alright so you've convinced me to update Projectile again; this time I've removed the flag that disallows a projectile from "finishing" twice (not even sure why I implemented this in the first place) which will make it easier to do what you've described Anachron, being able to launch a projectile from within its
    onFinish
    callback response method in conjunction with deactivating the
    toDestroy
    member.

    I'll update the submission thread shortly.
     
  7. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Yeah, having a projectile bounce would require a lot of parameters. Should there be an on-bounce event? How many bounces? The max range? Does the damage reduce per hit? What kind of unit qualifies the check? I could implement it, though. I like a challenge.
     
  8. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Another thing you could do that would be a much better option is a projectile factory >.>... when I see all of these parameters and all of the things you can do with projectiles I automatically think that the factory design pattern should be used, but that's just me.
     
  9. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Factory design pattern?
     
  10. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    google it

    Only thing is you might want to pull it off using triggers so that your factory is highly extensible and so that you don't have a huge chain of elseifs.
     
  11. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    From what I've gathered, a factory method pattern lets a person choose which struct to instanciate. I can't find a practical application for using a hub in this library just to select a child struct, when the user could have just selected their own specific child struct in the first place.

    Unless I am getting you wrong.

    EDIT: Adding yet another parameter to FireProjectile could accomplish this, but is that really what you want?
     
  12. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    OK, added a new function, FireProjectile2. This has fewer parameters though it requires the user to do more things manually.

    Four basic parameters -
    unit from, unit to, real speed, real arc
    . Work the same as FireProjectile. A new parameter,
    onCreateFunc func
    allows the user to put in the create method of a struct of his/her own choice, so whatever struct that is will be instanciated instead of the generic struct I have in the library. A user will inherit all of the methods from the projectile struct, but with the auto-vectors this library offers.

    I can see how this would be useful, so thanks again, Nestharus :)
     
  13. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    The Factory Design Pattern implies you (or other programmers) are in some way going to be extending and interfacing an internal class - if the user is even capable of this then I have hints of this "Factory Design Pattern" in my code, and it is easier for the user to just extend the projectile struct as I outline in the first post of my submission thread.

    The purpose of this is to supply the user with a predefined pattern of projectiles that simply handles certain internal work so that the user does not have to.

    What Bribe is doing is taking the vJass projectile interface that I laid out in my engine and simplifying it to a more basic JASS syntax. Let's take a closer look at this
    FireProjectile
    function. It takes parameters that cover various areas of my projectile engine, from the projectile arc/speed which is required to launch a projectile in addition to a damage amount (this isn't even included in my engine) and the source/target of the fired projectile.

    I don't really see how this has truly made things any easier.
     
  14. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    I was thinking more in response to the chained projectile module (and other possible modules). Rather than having it all be separate modules, I was thinking an extensible factory design would be a better choice. Maybe not quite a factory design pattern but more of a sort of Composite Pattern (that's why factory came to mind, putting the different pieces together to form an object). Like rather than a chain, bounce, and etc projectile module, you could just have an ambiguous system of projectiles that can support all of that if you get what I mean and each projectile could be in some sort of State Pattern.
     
    Last edited: Sep 6, 2010
  15. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I have significantly upgraded the format, so anyone (like me) who had trouble reading or understanding the previous versions should now have a much easier time.
     
  16. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    More new features;

    Code (vJASS):

    SetProjectileDamage(projectile p, real damage)
    GetProjectileDamage(projectile p)
     


    Since Projectile lacks a "damage" member, these variables will appropriately store an retrieve damage associated with a projectile instance.

    SetProjectileImpactEvent
    now overrides the normal impact-event used by
    FireProjectile
    , which was what prompted me to include a
    GetProjectileDamage
    function. If this function is called by the user, the projectile will not deal damage the normal way (the user would have to handle that himself).
     
  17. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Added an extension library called SplashingProjectile which deals splash-damage on-impact.

    A useful new function has been added to the fray called FireProjectileXY. This impacts once it reaches ground-level at the specified coordinates. The need for such a thing arose when I just wanted to have a splashing-projectile target a general area.

    I have eliminated FireProjectile2 because I feel it strays from the direction this library should take.

    I will soon include another add-on library (BouncingProjectile) to handle some more dirty work.
     
  18. azlier

    azlier

    Joined:
    Oct 3, 2008
    Messages:
    354
    Resources:
    4
    JASS:
    4
    Resources:
    4
    Approved.
     
  19. Laiev

    Laiev

    Joined:
    Oct 11, 2008
    Messages:
    273
    Resources:
    1
    Template:
    1
    Resources:
    1
    static method create takes unit source, real x2, real y2, string modelpath returns projectile



    returns projectile? :vw_wtf:

    other thing...

    constant native IsUnitInRange takes unit whichUnit, unit otherUnit, real distance returns boolean


    Code (vJASS):
    //
    if (IsUnitInRange(g_target, g_x, g_y, g_radius * MED_DAMAGE_POINT)) then
                    call inflict(g_damage)
                   
                elseif (IsUnitInRange(g_target, g_x, g_y, g_radius * MIN_DAMAGE_POINT)) then
                    call inflict(g_damage * MED_DAMAGE_FACTOR)
                   
                elseif (IsUnitInRange(g_target, g_x, g_y, g_radius)) then
                    call inflict(g_damage * MIN_DAMAGE_FACTOR)
                endif


    >>

    constant native IsUnitInRangeXY takes unit whichUnit, real x, real y, real distance returns boolean


    Code (vJASS):
    //
    if (IsUnitInRangeXY(g_target, g_x, g_y, g_radius * MED_DAMAGE_POINT)) then
                    call inflict(g_damage)
                   
                elseif (IsUnitInRangeXY(g_target, g_x, g_y, g_radius * MIN_DAMAGE_POINT)) then
                    call inflict(g_damage * MED_DAMAGE_FACTOR)
                   
                elseif (IsUnitInRangeXY(g_target, g_x, g_y, g_radius)) then
                    call inflict(g_damage * MIN_DAMAGE_FACTOR)
                endif


    :vw_death:

    Code (vJASS):
        function FireProjectile takes unit source, unit target, real damage, real speed, real arc, boolean homing, string modelpath returns projectile
            set object.create(source, GetUnitX(target), GetUnitY(target), modelpath).target=target
            set g_impactVec.z=g_impactVec.z + GetUnitFlyHeight(target) + height
     


    Code (vJASS):
    set g_proj.targetZOffset=height


    height? where's it?
     
  20. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,156
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Thank you, fixed.