• 🏆 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!

[Trigger] How to check for multi-indexed timers?

Status
Not open for further replies.
Level 3
Joined
Feb 3, 2016
Messages
43
After defining the multi-indexed timer [for up to 2 buildings that provide income every so often under the control of the same player in a game with up to 4 different players (hence the multi-indexing)] in a multi-trigger situation (one activates the other, for ex. when a timer is started and defined, another trigger that checks for its expiration is needed) I can't have multi-indexed timer variable in the activated trigger's event (it can't have more than 1 index and it can't be from a variable) which is needed for my vision of the income generator to work. It works with 1 building per player, but going more than that is impossible as it seems...or is it? here's the code of the main trigger:

  • Incomev2
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Farm
    • Actions
      • Set Income_Player_Number = (Player number of (Owner of (Constructed structure)))
      • Set Income_Farm_Count[Income_Player_Number] = (Income_Farm_Count[Income_Player_Number] + 1)
      • -------- Number of farms of player x are now = farms of player x + 1 --------
      • Set Farm_Position[Income_Farm_Count[Income_Player_Number]] = (Position of (Constructed structure))
      • -------- Variable is now position of the most recently built farm by player x (for ex. Farm_Position[1[1]] points to the position of the first farm player 1 built; Farm_Position[2[1]] to the position of the second farm player 1 built) --------
      • Countdown Timer - Start Income_Timer[Income_Farm_Count[Income_Player_Number]] as a Repeating timer that will expire in 5.00 seconds
      • -------- A timer is started that will be unique to each farm constructed, for ex. If a player 1 builds his first farm, the name of this variable timer is Income_timer[1[1]] --------
      • Set Income_Timer[Income_Farm_Count[Income_Player_Number]] = (Last started timer)
      • Player - Limit training of Farm to 2 for (Owner of (Constructed structure))
      • Trigger - Turn on incomev2P1 <gen>
      • Trigger - Turn on incomev2P2 <gen>
      • Trigger - Turn on incomev2P3 <gen>
      • Trigger - Turn on incomev2P4 <gen>
If needed I can post the others (the activated triggers that check for expirations) but it is simple: i can't have variable-indexed timers in their events, for ex.
  • Time - Income_Timer[1] expires
is okay, but
  • Time - Income_Timer[1[1]] expires
i can't seem to find a way to implement that.
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
-------- Variable is now position of the most recently built farm by player x (for ex. Farm_Position[1[1]] points to the position of the first farm player 1 built; Farm_Position[2[1]] to the position of the second farm player 1 built) --------

that's not correct. Farm_Position only has one index.
Farm_Position[Income_Farm_Count[Income_Player_Number]] = (Position of (Constructed structure))
Income_Player_Number: player number of the newly created building
Income_Farm_Count[Income_Player_Number] number of farms of that player
this is your index in your array, so if player one builds his 3rd farm you will have
Farm_Position[3] = pos of constructed unit
After that player 2 builds his 3rd farm, so Income_Farm_Count[Income_Player_Number] is again 3.
Farm_Position[3] = pos of constructed unit
You will overwrite the previous value.
An array has only one index, so you probably use a hashtable instead.

There are no multi-dimensional arrays in warcraft.
 
Level 3
Joined
Feb 3, 2016
Messages
43
-------- Variable is now position of the most recently built farm by player x (for ex. Farm_Position[1[1]] points to the position of the first farm player 1 built; Farm_Position[2[1]] to the position of the second farm player 1 built) --------

that's not correct. Farm_Position only has one index.
Farm_Position[Income_Farm_Count[Income_Player_Number]] = (Position of (Constructed structure))
Income_Player_Number: player number of the newly created building
Income_Farm_Count[Income_Player_Number] number of farms of that player
this is your index in your array, so if player one builds his 3rd farm you will have
Farm_Position[3] = pos of constructed unit
After that player 2 builds his 3rd farm, so Income_Farm_Count[Income_Player_Number] is again 3.
Farm_Position[3] = pos of constructed unit
You will overwrite the previous value.
An array has only one index, so you probably use a hashtable instead.

There are no multi-dimensional arrays in warcraft.
Completely forgot about hashtables...thanks! Now to learn more about hastables :D
 
It would be a lot more complex in GUI than in JASS to simulate 2-D arrays without using hashtables.

To check for multi-indexed timers, you (might) need a stack (Array search) or use hashtables directly (safer).
Here's some pseudo-code run-ins:

Code:
// Remember that this is pseudo-code, it may not compile. If it did, it was purely coincidental.
struct Timers
{
    static Timers maxInt = 0;
    timer timer

    // The array search I was talking about
    static method search(timer which) -> Timers
    {
        Timers this = 1;
        while ~(this > maxInt)
        {
            if (this.timer == which)
            {
                break;
            }
            end
            this++;
        }
        --> this;
    }

    static method create() -> Timers
    {
        Timers this = allocate();
        maxInt = IMaxBJ(this, maxInt);
        --> this;
    }
}

Hashtable:
  • Hashtable: Save (Last Created Timer) as <newIndex> of <parentIndex> in <hashtable>
  • ...
  • set indexTimer = Load <newIndex> of <parentIndex> in <hashtable>
 
Level 10
Joined
Oct 5, 2008
Messages
355
At this space i would be more interested to ask: why do you need to have a 2d array anyway? You can just chain all farms into a single array and have an integer array which stores the owning player number. It would be kinda slower to iterate through all of them, seeking fir the right integer, but that shouldnt be a problem, even more with just 2 farms for 4 players.
 
Status
Not open for further replies.
Top