• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Trouble Converting To JASS

Status
Not open for further replies.
So, I have this trigger:
  • Enforce Allies
    • Events
    • Conditions
    • Actions
      • Player Group - Make TeamA treat TeamA as an Ally with shared vision
      • Player Group - Make TeamB treat TeamB as an Ally with shared vision
      • Player Group - Make TeamB treat TeamA as an Enemy
      • Player Group - Make TeamA treat TeamB as an Enemy
And I want to convert it to JASS and remove the BJs from it. The problem is I can't find a workable way to do this as the alliance BJs cover up a lot of code, and the force function used also covers up a nested loop.

This trigger is executed from other places in the code, ideally it'd be nice to have this as a function such as function EnforceAllies takes nothing returns nothing. The teams are allies with each other, but enemies to players of the other team.

The reason behind the trigger is that players can swap teams through a number of ways.

Any help is appreciated!
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Assuming team 1 is players 1-6 and team 2 is players 7-12,
Code:
loop a from 1 to 6
 loop b from 1 to 6
  player - make player a treat player b as an ally with shared vision
 loop b from 7 to 12
  player - make player a treat player b as an enemy
loop a from 7 to 12
 loop b from 7 to 12
  player - make player a treat player b as an ally with shared vision

You could of course also loop through the player group, but that's a little more complex.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
@rulerofiron
sorry for breaking your answer,but currently the code you shown breaks the thread. Im referring to the code's thread in WE.

Sorry for bursting your bubble, but that's what you call pseudo code, and for the assumption mentioned it's fine.

@Zeatherann
In that case you should set them up as player groups, but the logic would still be the same. You'll have to do a nested "for force" function. Not sure exactly what it would look like since I code in GUI.

EDIT: ForForce calls another function, which gets messy.
Add all players of a force to a temp force, then go through them using first of force / random player in group.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
You can create custom functions such as

"function EnforceAllies takes nothing returns nothing"

and call them later, just as common trigger does. You can add arguments to it, like

function EnforceAllies takes plaer playerSource, player playerTarget, returns nothing
make PlayerSource treat PlayerTarget as an enemy.
endfunction

(You get the idea)
 
But the BJs I'm using expand out to these two functions:
JASS:
function SetForceAllianceStateBJ takes force sourceForce, force targetForce, integer allianceState returns nothing
    local integer sourceIndex
    local integer targetIndex

    set sourceIndex = 0
    loop

        if (sourceForce==bj_FORCE_ALL_PLAYERS or IsPlayerInForce(Player(sourceIndex), sourceForce)) then
            set targetIndex = 0
            loop
                if (targetForce==bj_FORCE_ALL_PLAYERS or IsPlayerInForce(Player(targetIndex), targetForce)) then
                    call SetPlayerAllianceStateBJ(Player(sourceIndex), Player(targetIndex), allianceState)
                endif

                set targetIndex = targetIndex + 1
                exitwhen targetIndex == bj_MAX_PLAYER_SLOTS
            endloop
        endif

        set sourceIndex = sourceIndex + 1
        exitwhen sourceIndex == bj_MAX_PLAYER_SLOTS
    endloop
endfunction

function SetPlayerAllianceStateBJ takes player sourcePlayer, player otherPlayer, integer allianceState returns nothing
    // Prevent players from attempting to ally with themselves.
    if (sourcePlayer == otherPlayer) then
        return
    endif

    if allianceState == bj_ALLIANCE_UNALLIED then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_UNALLIED_VISION then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_ALLIED then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_ALLIED_VISION then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_ALLIED_UNITS then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_ALLIED_ADVUNITS then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, true  )
    elseif allianceState == bj_ALLIANCE_NEUTRAL then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
        call SetPlayerAlliance( sourcePlayer, otherPlayer, ALLIANCE_PASSIVE, true )
    elseif allianceState == bj_ALLIANCE_NEUTRAL_VISION then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
        call SetPlayerAlliance( sourcePlayer, otherPlayer, ALLIANCE_PASSIVE, true )
    else
        // Unrecognized alliance state - ignore the request.
    endif
endfunction

Simplifying the SetPlayerAllianceStateBJ is reasy enough since I'm only using two values for it. However the nested loops runs at NumPlayers^2 and I have a feeling it can be reduced. Every player is in a third force called 'Players' (not to be confused with the 'All Players' constant). I am just having issues with getting the loop to work effeciantly.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
That basically turns into this:

JASS:
function EnforceAllies takes player sourcePlayer, player otherPlayer, boolean flag returns nothing
        call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_PASSIVE,       flag)
        call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_HELP_REQUEST,  flag)
        call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_HELP_RESPONSE, flag)
        call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_XP,     flag)
        call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_SPELLS, flag)
        call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_VISION, flag)
        call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_CONTROL, flag)
        call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_ADVANCED_CONTROL, flag)
endfunction

Try to turn your "Pick Every player" loop, into a "For each integer X from 0 to 11" (Remember in JASS player 1 is player 0)

Several of this depends on some stuff... Your teams have limit? 5v5? 6v6? can it be 3vs8? Does team A goes from 1 to 6, and Team B from 7 to 12?
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
- Make the team A
- Make the Team B

- Trigger
Set a = 0
Pick every Player in All Players and do:
If Player is in Team A then
Set a = a+1
Set Players[a] = Picked Player


- Then you save: TeamAMaxPlayerIndex = a

Now your team A, even if it holds players 2, 5, 6, 1, 8, 11, goes from 1 to 6.

- Repeat process for Team B
- Trigger
Set b = TeamAMaxPlayerIndex
Pick every Player in All Players and do:
If Player is in Team B then
Set b = b+1
Set Players = Picked Player

- Now your team B, even if it holds players 3, 4, 7, 9, 10, 12, goes from 7 to 12

Doesn't matter if your team is not paired, It will index players of Team A, and the rest will be player B

So Players[1.2.3] = Team A and Players[4.5.6.7.8] = Team B.

Now i really forgot why i was saying this, but I hope it helps :)
 
Status
Not open for further replies.
Top