Calculating Total Income from a Bunch of Sources

Nogusta

New Member
Reaction score
1
Hey guys, really solvable problem, which I'm having problems figuring out in GUI. I have a space map where you colonize planets one by one. When a planet is colonized, it's added to a Unit Group Array (PlanetID[player#]) where the index is the player number.

Each planet is a hero and generates income based on their strength stat. The income can be increased by 30% per upgrade of a levelable hero ability each planet has. I've got each planet contributing income properly but...

I can't seem to figure out how to calculate the combined total income of all the planets and store it in a global variable:

Code:
Total Income
    Events
        Player - Player 1 (Red) types a chat message containing test2 as An exact match
    Conditions
    Actions
        For each (Integer A) from 1 to (Number of players), do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Number of units in PlanetID[(Integer A)]) Less than 1
                    Then - Actions
                        Set TotalIncome[(Integer A)] = 0
                    Else - Actions
                        For each (Integer B) from 1 to (Number of units in PlanetID[(Integer A)]), do (Actions)
                            Loop - Actions
                                Set TotalIncome[(Integer A)] = ((Strength of (Picked unit) (Include bonuses)) + (Integer(((Real((Strength of (Picked unit) (Include bonuses)))) x (0.30 x (Real((Level of Economy  for (Picked unit)))))))))


This trigger is obviously incomplete. The thing is, I realized I don't know how to go through each unit in a unitgroup (in this case PlanetID) and add its individual income to the TotalIncome variable using GUI

I stopped triggering at the end when I realized I couldn't get around it by declaring a 2D array because... I can't do it in GUI.

I've seen this simple sum of incomes done so many times before, any ideas?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Code:
                        For each (Integer B) from 1 to (Number of units in PlanetID[[color=red](Integer B)[/color]]), do (Actions)
There's no (Integer B) yet ;) !
 

Nogusta

New Member
Reaction score
1
Code:
                        For each (Integer B) from 1 to (Number of units in PlanetID[[color=red](Integer B)[/color]]), do (Actions)
There's no (Integer B) yet ;) !

Uhhh errr, that's a bug, it's actually Integer A I put there, lets just edit that... Still though, I don't know how to finish the trigger cause I don't know how to pick each unit in a unit group 1 by 1 and calculate the income each gives, then add it to the global variable.
 

perkeyone

something clever
Reaction score
71
theres a trick to get around 2d arrays..
lets say we want to make a 2d array
or matrix that has...
one index for each players
and another index for up to 20 units
so a 12 by 20 matrix
well we make a 1d array but set the max to 240 (12 x 20)
then when you set the variables, do something like this.
Code:
Set array_name[((((Index 1) - 1) x 20) + (Index 2))] = (Last created unit)
you have to subtract one from the first index and multiply it by the maximum value of the second index. then add the second index.
hopefully this was more helpful than confusing
 

Nogusta

New Member
Reaction score
1
That's an excellent idea, I'll try it out, but I really think there must be a simpler way.
 
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