[System] Mode Manager

Level 7
Joined
Dec 3, 2006
Messages
342
JASS:
            loop
                call TriggerRegisterPlayerChatEvent(t,Player(i),MODE_CHARACTER,false)
                exitwhen 0==i
                set i=i-1
            endloop

Add a check to see if the player is playing and a check for if the player is human similar to what purge does a lot like in his scripts like Track.
 
Level 38
Joined
Sep 26, 2009
Messages
8,490
ForceEnumPlayersCounted, according to my best judgment, doesn't stop at just 1 player. It continues to loop through every player (inexplicably). I will test this on battle.net soon though I have been extremely short on time when I've been home lately.

For now I advise changing it. You can still use the ForForce trick, but that takes a code argument which obviously doesn't work with storing it into an array.
 
Updated!
Broke backwards compatibility for the sixth time.

Changes:
- Modes are now static (cannot be destroyed)
- Now uses StringIndexer
- Algorithm optimized (Super efficient now)

The algorithm used to be an O(k*n), so I changed it to an O(n) :3

I also changed the method of function execution from using ForceEnumPlayersCounted to adding conditions in a loop and evaluating a trigger once.
 
Yes, all modes in one line.

The checks for mode disabling are supposed to be done by the user.
I can make them automatic though.

The way you would do it currently is:

JASS:
function ap takes nothing returns nothing
    if not ModeAR.flag then
        set ModeAP.flag = true
        // do mode ap shit
    endif
endfunction

function ar takes nothing returns nothing
    if not ModeAP.flag then
        set ModeAR.flag = true
        // do mode ar shit
    endif
endfunction
 
Well, I could share the algorithm :p
What I'm doing is just moving projectiles by their xVel, their yVel and zVel 32x a second.

For homing missiles, I would only recompute the x,y,zVels.

For bouncing missiles, I would use normal missiles and just give a new target each time.

A missile would be destroyed if bounces == 0 and the the difference between the current and target coordinates is less than the velocity on each axis (xVel, yVel, zVel)

It's very, very simple and incredibly efficient :p
The efficiency is required here because we might end up doing crazy things in the future like using a projectile system for unit attacks xD
 
Level 5
Joined
Jan 23, 2015
Messages
100
JASS:
        method authorize takes integer id returns nothing
            debug if 0 > id or 15 < id then
                debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[Mode Manager]Error: Attempted to authorize an invalid player!")
                debug return
            debug endif
         
            set authorized[this * 12 + id] = true
        endmethod
Well,... shouldn't that 15 be 11? Because if someone will debug code like
JASS:
...
local GameMode m1 = GameMode.create(...) // m1 = x
local GameMode m2 = GameMode.create(...) // m2 = x + 1
call m1.authorize(12) // authorized[12x + 12] = true // <- that's not a smart action since 13th player is definetly not a real player
call m2.authorize(0)   // authorized[12(x + 1)] = true
call m2.unauthorize(0) // authorized[12(x + 1)] = false
if(m1.isPlayerAuthorized(12)) then
    call BJDebugMsg("Something had actually gone not by plan")
endif // because 12(x+1) == 12x + 12, wow
...
- he would not get any errors.
It's just confusing value that could make one mad if he don't understand enough this system.
 
Last edited:

Bannar

Code Reviewer
Level 24
Joined
Mar 19, 2008
Messages
3,137
Needs a patch 1.29 update.
Also, the [this * 12 + id] should be found within private function (will inline anyways) for easy dev-management. Rather than 12 or as it is currently 24, once should use the bj_MAX_PLAYER_SLOTS instead.
 
Last edited:
Top