• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Need some logic to work this problem out

Status
Not open for further replies.
Level 4
Joined
May 16, 2004
Messages
76
Ok just need some advice, ideas to what functions i can use to make this a reality.

  • Tree Growth
    • Events
      • Time - Every 2.25 seconds of game time
    • Conditions
    • Actions
      • Set TempPoint = ((Position of (Random destructible in (Entire map) matching ((Destructible-type of (Matching destructible)) Equal to Summer Tree Wall))) offset by (Random real number between 175.00 and 225.00) towards (Random angle) degrees)
      • Destructible - Create a Summer Tree Wall at TempPoint facing (Random angle) with scale (Random real number between 0.70 and 1.30) and variation (Random integer number between 1 and 10)
      • Set LastTree = (Last created destructible)
      • Animation - Play LastTree's birth animation
      • Animation - Change LastTree's animation speed to 150.00% of its original speed
      • Custom script: call RemoveLocation (udg_TempPoint)
What this does is it makes trees already in the map, have the chance to randomly sprout more trees nearby them. So its like a growing forest. The only problem im having is that often the trees intersect each other with them disregaurding the pathing whatsoever.

How can i keep this growing forest, but at the same time make sure that when new trees grow they will not intersect one another
 
Level 17
Joined
May 6, 2008
Messages
1,598
Are you sure that works?

If you pick a random tree from the map, it can only select the first 64 trees.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Why would it be one of the first 64 trees?
Seriously!
Anyway:
  • Trees
    • Set temp_point = (Position of (Random destructible in (Playable map area) matching ((Destructible-type of (Matching destructible)) Equal to (==) Summer Tree Wall)))
    • Set temp_point2 = (temp_point offset by (Random real number between 175.00 and 225.00) towards (Random angle) degrees)
    • Destructible - Create a Summer Tree Wall at temp_point2 facing (Random angle) with scale 1.00 and variation 0
    • Custom script: call RemoveLocation(udg_temppoint)
    • Custom script: call RemoveLocation(udg_temppoint2)
 
Level 17
Joined
May 6, 2008
Messages
1,598
Because it cant count any larger than that.

Have you tried that trigger in large scales?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
No, I just fixed one leak.
I do not know, yet, if you are correct. But I do know that checking whether there are trees near some location would be kinda hard in GUI.
Ok, now I know that is not true:
  • Trees
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set tre[co] = (Random destructible in (Playable map area) matching ((Destructible-type of (Matching destructible)) Equal to (==) Summer Tree Wall))
      • Set boo = True
      • Do Multiple ActionsFor each (Integer A) from 0 to (co - 1), do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tre[(Integer A)] Equal to (==) tre[co]
            • Then - Actions
              • Set tre[co] = No destructible
              • Set boo = False
            • Else - Actions
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • boo Equal to (==) True
          • Then - Actions
            • Set temp_point = (Position of tre[co])
            • Cinematic - Ping minimap for (All players) at temp_point for 1.00 seconds, using a Simple ping of color (100.00%, 100.00%, 100.00%)
            • Custom script: call BJDebugMsg(I2S(udg_co))
            • Set co = (co + 1)
            • Custom script: call RemoveLocation(udg_temp_point)
          • Else - Actions
That trigger went trough all the trees, not only the first 64.
 
Last edited:
Level 4
Joined
May 16, 2004
Messages
76
thanks for everybodys help so far, i will give you rep if i can once i have solved this.

Secondly, with the checking of the intersecting as you have stated tidusx, im trying to look for a condition that would evaluate a point? such as the one you have stated yet, i cannot find it?
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Well you can find that under "real comparison". Also that condition is leaking points awfully, so I suggest using variables before using it.
  • Set TreeCheckA = (Position of (Last created destructible))
  • Set TreeCheckB = (Position of (Picked destructible)))
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Distance between TreeCheckA and TreeCheckB Less than or equal to 64.00 //Don't know if it's enough but well, not hard to change
      • (Last created destructible) Not equal to (Picked destructible)
    • Then - Actions
      • -------- Do the actions --------
    • Else - Actions
  • Custom script - call RemoveLocation( udg_TreeCheckA )
  • Custom script - call RemoveLocation( udg_TreeCheckB )
 
Level 4
Joined
May 16, 2004
Messages
76
Ok this is what i have got right now, and it still does not work. Keep in mind i havent yet bothered to check for leaks atm.

  • Tree Growth
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • Set TempPoint = (Position of (Random destructible in (Playable map area) matching ((Destructible-type of (Matching destructible)) Equal to Summer Tree Wall)))
      • Set TempPoint2 = (TempPoint offset by (Random real number between 175.00 and 225.00) towards (Random angle) degrees)
      • Destructible - Pick every destructible in (Playable map area) and do (Actions)
        • Loop - Actions
          • Set PointTreeCheck = (Position of (Picked destructible))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between TempPoint2 and PointTreeCheck) Less than or equal to 50.00
        • Then - Actions
          • Trigger - Run (This trigger) (checking conditions)
        • Else - Actions
          • Destructible - Create a Summer Tree Wall at TempPoint2 facing (Random angle) with scale 1.00 and variation 0
          • Set LastTree = (Last created destructible)
          • Animation - Change LastTree's animation speed to 150.00% of its original speed
          • Animation - Play LastTree's birth animation
      • Custom script: call RemoveLocation (udg_TempPoint)
      • Custom script: call RemoveLocation (udg_TempPoint2)

In my first if statement, i believe it is wrong. What im looking for is for it to find every single destructable on the map, find it's point and set it as a variable when calculating the distance between the trees/points. Im thinking this is going to have to use an array? to store each and every tree's point?
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
you got it alittle bit wrong...
This is how it should be

  • Tree Growth
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • Set TempPoint = (Random point in (playable map area))
      • Destructible - Pick every destructible in (Playable map area) and do (Actions)
        • Loop - Actions
          • Set PointTreeCheck = (Position of (Picked destructible))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between TempPoint and PointTreeCheck) Less than or equal to 50.00
        • Then - Actions
          • Trigger - Run (This trigger) (ignoring conditions)
        • Else - Actions
          • Destructible - Create a Summer Tree Wall at TempPoint facing (Random angle) with scale 1.00 and variation 0
          • Set LastTree = (Last created destructible)
          • Animation - Change LastTree's animation speed to 150.00% of its original speed
          • Animation - Play LastTree's birth animation
          • Custom script: call RemoveLocation (udg_PointTreeCheck)
      • Custom script: call RemoveLocation (udg_TempPoint)
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
okay, I guess it is because it runs an infinity loop if the trigger are ran too many times with the "run trigger option" what happends if you "run it checking conditions"?

Otherwise you could add a 0.3 seconds polled-wait action before "run trigger..."
However then I suggest you to change the event time to 1 seconds
 
Level 4
Joined
May 16, 2004
Messages
76
I slowed the tree spawn rate right down to 5 seconds, and it seems that every time a tree is created it lags massively. after about 4 tree spawns it locked up and again crashed, this is after i took out the run trigger command
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
  • Actions
    • Do Multiple ActionsFor each (Integer co) from 1 to 3, do (Actions)
      • Loop - Actions
        • Set temp_point = (Position of (Random destructible in (Playable map area) matching ((Destructible-type of (Matching destructible)) Equal to (==) Summer Tree Wall)))
        • Set temp_point2 = (temp_point offset by 256.00 towards 0.00 degrees)
        • Set co = 3
        • Destructible - Pick every destructible within 256.00 of temp_point2 and do (Actions)
          • Loop - Actions
            • Set co = 0
    • Destructible - Create a Summer Tree Wall at temp_point2 facing (Random angle) with scale 1.00 and variation 0
    • Custom script: call RemoveLocation(udg_temp_point)
    • Custom script: call RemoveLocation(udg_temp_point2)
JUst an example ;)
 
Last edited:
Level 23
Joined
Nov 29, 2006
Messages
2,482
I don't understand what your trigger does :p


Ooooh... It was an example....

And ColdRocker, the lag may be since it it ran so often, and checking so many trees over and over again. The issue could also be, that since it runs the trigger again, the global variables will be overwritten.

You could do a custom script which removes the temp points in the before the action where you do "run this trigger" again.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
My trigger does almost what he wants ;)
It is an example since not all the values are what he desires(random numbers, range).
It will first pick a location that is # away from an existing tree. Next to that location in range #2 there will be no trees
Places the tree.
But if you do not have any free place, this will cause a crash at some point.
Preventing that is not that hard.
 
Level 4
Joined
May 16, 2004
Messages
76
Ok i have tried your code spiwn and to no avail it has not worked. 1. It spawns trees yes, but they seem to be spawning on top of each other and 2. It causes major lag spikes everytime a tree spawns.

Edit. Secondly by changing your "co" integer number, i found out that it is causing the lag, if that helps.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
I had slipped one "Set co = 3" :D
Try it now.
P.s. I had already edited the trigger.
It will still cause lagg. It is because all the randomness :D
When you pick a random tree, there is no guarantee that there is a "free spot" around it. And the chance the "free spot" being at a precise direction at a precise distance is really really small.
That is more of an example how to check if a spot is free.
I mean, it does the job, but picking random stuff until it suits you lags.
Also note that creating a tree every 0.25 will flood your map really fast.
I can make something that will be a lot less laggy, but it will involve all the trees being in an array.
(but if you are going to destroy trees than some other stress will be put on the cpu).
 
Last edited:
Level 4
Joined
May 16, 2004
Messages
76
Well pretty much all i want is a forest that will continue to grow, and evolve around the players, eventually yes the players will need to clear the trees. Do you think this is a near impossible task for wc3 without it lagging?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
It is possible(as I said).
A I can think of at the moment:
All the trees on the map must be place in an array.
When a new destructible is created it should be added to that array.
So instead of picking random destructible all the time, a random number will be picked. Then a loop should go through all the destructibles in the array starting from that number.
This would reduce lag caused due to this randomness. It will still cause lag, but significantly less, due to the fact that it will still loop until a free spot is found(quite hard, because of the random angle and distance).
But problems will come from destroying trees.
 
Level 4
Joined
May 16, 2004
Messages
76
well i changed the int that it changes to is 3 now, and i have also decided to throw the trees in a region rather then the whole map, and it does not seem to be lagging, nor crashing when it cant find a spot for a tree
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Because when the there are no free spots, the trigger becomes one endless loop and because it is a periodic event, it will fire again without the first instance being done. And again the same. So it might crash at some point.
To prevent crashing:
At the beginning of the trigger disable it, and enable it at the end.
 
Level 4
Joined
May 16, 2004
Messages
76
Thankyou for your help so far, i now have a few questions.

Is it possible to take this to the next level, there are 3 main issues with this system.

1. The trees spread everywhere even on cliffs, is it possible to integrate a mechanism that would prevent this?

2. The trees cannot detect whether they are growing in water, another mechanism could be implemented here?

3. Finally, any buildings, the trees completely ignore and grow inside them.

What do you suggest to fix these 3 problems/ make this tree system awesome?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
About buildings - it is the same thing about destructibles.
RIght after
  • Destructible - Pick every destructible within 256.00 of temp_point2 and do (Actions)
You need to pick all units matching condition classification of matching unit is a structure(and or units).
In the actions part do the same thing as with Destructibles - set co=0

As for water - how do you place water? (There are different methods)

As for cliffs I am a bit uncertain. but there should be something to do the job.

But those are just rather simple customizations, the problem about using random destructible still remains.
 
Level 4
Joined
May 16, 2004
Messages
76
For water im just using the standard shallow water and deepwater terraining tools, so i figure would i have to do sometihng with the height elevation, eg. If tempoint2 height elevation less than 2, then co=0.

would that work?
 
Last edited:
Level 12
Joined
Apr 27, 2008
Messages
1,228
Then this will do it.
P.s. There is another water adding method, which is more realistic, more beautiful (it is used by blizzard in their maps).
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Well, somehow I though you were referring to the x,y IsPointWater trick, that there were another solution:p (which I see it should be IsPointNotWater, but according to Vexorians caster system it is written like that)
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Name doesn't matter, but it is misleading. Someone might think it would return true if the point is water.
 
Status
Not open for further replies.
Top