How to organize the following boolean

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
How to organize so that you have a 'boolean' for every player to find out if that player can 1) ally 2) war 3) neutral another player.


X CAN ALLY Y = TRUE
X CAN WAR Y = TRUE
X CAN NA Y = TRUE

12*12*3

Any suggestions?

One way would be creating player groups.

Group canAlly[X] contains all players that can ally player X.
Group canWar[X] same as above but for war.
Group canNeutral[x] same as above but for na.

1-144 for can ally? 145-289 for can war etc.? It's kind of hard to keep track of things though...
 
Last edited:
You want an alliance system...

Well there are some things about how stuff is made but that is totally up to you.
First of all, it is a vicious circle.
You can set your reputation to another player worse but not better. Both players have to agree for that.

So CAN_WAR is always true.
CAN_NEUTRAL is only true if the players are not in war with each other.
CAN_ALLY is never true. This must be set by both players if they want that.

So basically you have an integer for each player towards each player:

Player 1Player 2Player 3Player 4Player 5Player 6Player 7Player 8Player 9Player 10Player 11Player 12

Player 1
SelfAllied(1)Allied(1)Enemy(3)Neutral(2)

Player 2
Allied(1)SelfAllied(1)Neutral(2)

Player 3
Allied(1)Allied(1)SelfNeutral(2)

Player 4
Enemy(3)SelfNeutral(2)

Player 5
SelfNeutral(2)

Player 6
SelfNeutral(2)

Player 7
SelfNeutral(2)

Player 8
SelfAllied(1)Neutral(2)

Player 9
Allied(1)SelfNeutral(2)

Player 10
SelfNeutral(2)

Player 11
SelfNeutral(2)

Player 12
Neutral(2)Neutral(2)Neutral(2)Neutral(2)Neutral(2)Neutral(2)Neutral(2)Neutral(2)Neutral(2)Neutral(2)Neutral(2)Self

Now you need something so players can change their "reputation" to another player.
A player can change:
- From neutral to war.
- From allied to neutral.
- From allied to war.
A player can request:
- From war to neutral.
- From war to allied.
- From neutral to allied.
If a player requests that, and the other has already requested that, it will be changed.

That is in concept how most custom alliance stuff is done.
In this you have an integer array with 144 slots. (132 slots if you add some more calculations to remove the self stuff.)

But if you really want those booleans then yes you have to do it in an array just like you said.
 
vJass supports 2d arrays. Basically, this is how you do it:

JASS:
globals
    boolean array canAlly[11][11]
    //DECLARES A 2D BOOLEAN ARRAY WITH 11 ROWS AND 11 COLS
endglobals

function setCanAlly takes player a, player b, boolean flag returns nothing
    local integer pa = GetPlayerId(a)
    local integer pb = GetPlayerId(b)
    
    set canAlly[pa][pb] = flag
endfunction

function canPlayersAlly takes player a, player b returns boolean
    local integer pa = GetPlayerId(a)
    local integer pb = GetPlayerId(b)
    return canAlly[pa][pb]
endfunction

//TO CALL THE FUNCTION, JUST ADD THIS IN CUSTOM SCRIPT

call setCanAlly(Player(0), Player(1), true) //ENABLES ALLIANCE FLAG FOR PLAYERS

set udg_someBoolean = canPlayersAlly(Player(0), Player(1)) //WILL SET THE VARIABLE TO THE BOOLEAN WE SAVED

Note that this only stores information about wether two players can ally, it does not actually enforce it!

The second option is to use a hashtable with the first players id as the parent key, and the second players id as the child key. Then, you can store the boolean using those two keys.
 
Status
Not open for further replies.
Back
Top