Template [cJass] Chain Spell

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Or just make a [cJass] prefix.

I don't think that this will make everyone happy. Well maybe some cJass coder are forced to code in vJass if they want to submit sth., but imagine half of the "better" JASS coders start to code cJass and no vJass anymore. People using several systems will have to use cJass AND vJass in their maps which would just overcomplicate the whole thing particulary for the mapping beginners.

This cJass spell template uses a vJass system. cJass is easy to install and fully compatible. I don't see how it could overcomplicate anything. Beginners already have to install NewGen, this is just another click, it isn't a big deal. My spell even includes a link to the post containing the download, which would be a Good Idea™ to not overcomplicate things. When J4L sees this thread, he'll staple me to a train for sure...
 

Nestharus

o-o
Reaction score
84
This will hopefully start pointing you in the right direction.. I just put down the formatting, but I'm not going to recode the entire thing for you =P.

JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_types_priv.j"
include "cj_typesEx_priv.j"

library ChainSpell initializer init uses Recycle {
    public keyword Chain
    private player casterPlayer
    
    //distance formula variables
    private real distanceX1, distanceX2, distanceY1, distanceY2, distance
    
    private group array bouncedGroup; group bounceGroup = CreateGroup()
    private unit currentUnit, casterUnit
    private boolexpr bounceEnumeration
    private int bounceCount = 0
    private Chain array chainStack
    private int chainStackIndex = 0
    private int chainIndex = 0

    private bool Filt() {
        currentUnit = GetFilterUnit()

        if IsUnitEnemy(currentUnit, casterPlayer) && !IsUnitType(currentUnit,UNIT_TYPE_STRUCTURE) && !(IsUnitType(currentUnit, UNIT_TYPE_DEAD) || GetUnitTypeId(currentUnit) == 0) {
            /*if (!IsUnitInGroup(u,immune)) {
                //calculates distance between the picked unit and the last unit hit by the spell
                x2 = GetUnitX(u) - x1
                y2 = GetUnitY(u) - y1
                if (x2*x2 + y2*y2 < DISTANCE) { //is this unit the closest one in the group?
                    //sets DISTANCE to the distance to the closest unit
                    DISTANCE = x2*x2 + y2*y2
                    t = u
                }
            }*/
        }
        return false
    }
    
    public struct ChainProperties extends array {
        int numberOfBounces, spellId
        real bounceRange, bouncePeriod, damage
    }

    public struct Chain extends array {
        public delegate ChainProperties chainProperties
        
        void jumpTo(unit target) {
            /*UnitDamageTarget(this.caster,target,damage,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_FIRE,null)
            bounceCount++ //jumping to a new unit, so add 1 to bounces.
            this.u = target //stores the target for the next bounce (comparing unit distances)
            GroupAddUnit(this.immune,target)*/
        }
        static thistype create(unit caster, unit target) {
            local thistype this
            if chainIndex != 0 { this = chainStack[--chainStackIndex] }
            else { this = ++chainIndex }
            .numberOfBounces = thistype(0).chainProperties.numberOfBounces
            /*D.caster = caster
            D.u = caster
            D.immune = Group.get()
            D.jumpTo(target)
            D.castingPlayer = GetOwningPlayer(caster)
            return D*/
            return this
        }

        /*private static thistype create(unit caster, unit target, int abilLevel){
            thistype D = thistype.allocate()
            D.bounces = 1
            D.maxBounces = abilLevel * 2//By default, bounces 2x the ability level
            D.caster = caster
            D.u = caster
            D.immune = Group.get()
            D.jumpTo(target)
            D.castingPlayer = GetOwningPlayer(caster)
            return D
        }*/

        /*void onDestroy(){
            Group.release(this.immune)
            this.immune = null
            this.caster = null
            this.u = null
        }*/
    }


    /*private bool Cond(){
        return GetSpellAbilityId() == SPELL_ID
    }

    private bool TimerCallback(){ //This function performs a bounce each PERIOD
    ChainTemplate D = KT_GetData()

        //Sets distance to square of bounce_range (efficiency)
        DISTANCE = BOUNCE_RANGE * BOUNCE_RANGE
        FILTER_PLAYER = D.castingPlayer
        x1 = GetUnitX(D.u)
        y1 = GetUnitY(D.u)
        immune = D.immune
        loop
            unit u; u = FirstOfGroup(immune)
            exitwhen u == null
            BJDebugMsg("|cffff0000" + GetUnitName(u) + "|r")
            GroupRemoveUnit(immune,u)
        endloop
        GroupEnumUnitsInRange(g,x1,y1,BOUNCE_RANGE,filterFunction)
        GroupClear(immune)
        g = null
        if (t == null) { //if there is no unit to jump to, end the spell
            t = null //just in case, heard that this was still needed anyway
            D.destroy()
            return true
        }
        D.jumpTo(t)
        if (D.bounces >= D.maxBounces) { //max bounces reached, end the spell.
            D.destroy()
            return true
        }
        return false
    }

    private void Act(){
        ChainTemplate D = ChainTemplate.create(GetTriggerUnit(),GetSpellTargetUnit())
        //ChainTemplate D = ChainTemplate.create(GetTriggerUnit(),GetSpellTargetUnit(), GetUnitAbilityLevel(GetTriggerUnit(),SPELL_ID))
        //uncomment the line above if using the ability level
        KT_Add(function TimerCallback,D, PERIOD)
    }*/

    private void init() {
        //printf(I2S(Test2.create(null, null).numberOfBounces))
    /*trigger t = CreateTrigger()
    int i = 0
    filterFunction = Condition(function Filt)

        loop {
            TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            exitwhen i >= 11
            i += 1
        }
        TriggerAddCondition(t,Condition(function Cond))
        TriggerAddAction(t,function Act)*/
    }
}
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I don't get what that formatting does. It seems a lot more complicated than what I want the spell to do. I just want people to slap it in, add whatever they want to the jumpTo method and the filter function, and be done with it.

Did some code updates and added a test map. It's staying in this form until I can get that pesky filter function to work.
 

Viikuna

No Marlo no game.
Reaction score
265
That cJass indeed looks quite strange.

I didnt really read the code too much, but at least your group usage sucks terribly.

( I really feel again like I should write a tutorial about group usage. I just hate writing tutorials,
cant you do it, Jesus4Lyf, or someone? )

Anyways, go to wc3c.net and get GroupUtils and learn how to use it.

Also you should use TriggerRegisterAnyUnitEventBJ, it does all that looping for you, so you dont have to type it yourself.

edit. Oh yea, read those other posts. You are using that Recycle thingy, and you just havent updated the first post. All right then. So immune group gets recycled, thats good, but you still should use somekind of ENUM_GROUP for GroupEnums.
 

Nestharus

o-o
Reaction score
84
Viikuna, actually looping through all players when they may not all be in the map is a bad practice =).
 

Viikuna

No Marlo no game.
Reaction score
265
Well, no one really cares about that, since it has no significant negative effects at all.


What matters is that one liner BJ looks better here than some loop thingy, that does exactly the same, but takes many lines.

Then again, you also probably need some system like SpellEvent, because Blizzards event responses that dont always work when you need them, so using system for event stuff is ultimately the best way to do it since it also looks pretty nice. ( You dont even have to use triggers directly, because function interfaces do that stuff for you )
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Have you seen this?

Just curious.

Nope.

Viikuna, I'll look into GroupUtils. I know the group usage isn't the best. I first tried to move the whole [ljass]FirstOfGroup[/ljass] into the filter, by using a global group and a global unit to transfer the data back to the main function:

[ljass]group immune = CreateGroup()[/ljass]
[ljass]unit closestUnit[/ljass]

JASS:
immune = D.immune
GroupEnumUnitsInRange(g,....)

//filter function
IsUnitInGroup(GetFilterUnit(),immune) == false //this ran into problems, would just keep bouncing to same unit.
closestUnit = GetFilterUnit() 

//back inside the main function

D.jumpTo(closestUnit)

//inside jumpTo

void jumpTo(unit u){
GroupAddUnit(this.immune,u)


It would work on the first jump, but never on the second jump. I'm assuming it was something with the global unit variable, but after a few hours of trying other things, I reverted back to the [ljass]FirstOfGroup[/ljass] loop. If you do make that group tutorial, please tell me about it. Otherwise any help will be accepted. The above is conceptual freehand.
 

Nestharus

o-o
Reaction score
84
And we really need some sort of cJASS vs vJASS/Zinc thread where this can properly be duked out. I'm seeing these disputes all over the place where they don't belong =).

Maybe I shall start one up : o.
 

Romek

Super Moderator
Reaction score
963
> Maybe I shall start one up : o.
No.

The staff is currently discussing what to do with all these new languages in the staff forum. We've somewhat come to a verdict. I'll place a sticky soon.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Could someone go through and delete all the "debate" posts? I haven't been able to solve the problem because my thread has been hijacked :( I've been trying to solve it a lot on my own, but to no avail.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top