Author Topic: Wave calculation  (Read 1836 times)

Offline Vinraith

  • Hero Member Mark II
  • *****
  • Posts: 806
Wave calculation
« on: August 19, 2010, 08:37:55 pm »
At an earlier point I would swear I'd seen a calculation of wave size on the wiki, but I can't seem to locate it now. Would someone in the know mind sharing? Also, what's the formula for wave timing? More than anything I'm interested in what variables drive these, and how they're weighted.

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Wave calculation
« Reply #1 on: August 19, 2010, 08:50:13 pm »
Well... it's really, REALLY hard to describe in a concise way in terms of the wave size in particular.  There are literally a few hundred lines of code in at least three files that govern this.  Make that four files. 

The basic underlying rules are thus, though:

1. Higher AI Progress leads to larger waves, pretty linearly.
2. Higher AI Difficulty levels lead to larger or smaller waves, not quite linearly.
3. Higher tech levels lead to corresponding drops in wave size (equivalent to the drop in ship cap at those tech levels).
4. The max/min time between waves varies by AI Difficulty level, and is randomized by around 30ish minutes or more (per AI).  The wave size is 1x normal in the middle of that range, and is down to perhaps 0.4x at the lower end, and maybe 3x at the upper end.  Or something along those lines.

The above governs all waves and their size, regardless of anything else.  But on top of that, and where the biggest complexity comes from, is that there are an absolute ton of possible modifiers:

1. Ships with wave bonuses.
2. The actual end cap on wave size per line item (something like 2000).
3. The number of players in the game (it's 1 line item per human player or homeworld per AI, so 2 total in 1 player, 16 total in 8 player, with either 1 or 2 coming at a time in 1 player, and 8 or 16 coming at a time in 8 player).  All the waves from a given AI go to the same planet in multiplayer games, so at most two planets are ever targeted at once.
4. The ship type in use (even in schizophrenic) causes a multiplier.  You see fewer vampires always, but always way more laser gatlings.
5. Sometimes a starship or two are added in, but this sometimes costs the AI smaller ships from the wave (depends on the AI type).
6. Recently, same deal as #5 when it comes to "support ships" like munitions boosters and shield boosters, etc.
7. AI modifiers obviously can alter all this.
8. There are also variances per AI type.  Mad Bombers have something like 3x larger waves, but almost no defenses, for example.


And... I think those are some other variances, but those are the high points. You won't ever be able to predict wave sizes, trust me.  I coded almost all of the variables for it, and I'm not ever able to predict it.  There are too many layers of variables and randomization on top of all that.  Best advice is to keep the AI progress low and to avoid ships with wave modifiers, and that's mostly all that would be actionable data from all that in a given campaign.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Vinraith

  • Hero Member Mark II
  • *****
  • Posts: 806
Re: Wave calculation
« Reply #2 on: August 19, 2010, 08:57:04 pm »
Thanks for the detailed answer, Chris, I hadn't realized just how involved this was. :) I suppose my main point of curiosity is, to isolate this to a single variable, all else being equal how are the wave sizes on difficulty 6 going to compare to those on difficulty 7, or 7.3, or 8?

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Wave calculation
« Reply #3 on: August 19, 2010, 09:15:45 pm »
Well, the time-between waves initial calculation is this, for example (units in seconds):

Code: [Select]
                int originalTime = ( ( 14 - this.AIDifficulty ) * 3 * 60 ).IntValue;
                int timeToWait = originalTime;
                int randomAmount = ( this.AIDifficulty * 30 ).IntValue;
                int timeOffset = Game.Instance.GameRandom.Next( -randomAmount * 2,
                    randomAmount * 4 );
                timeToWait += timeOffset;
                if ( timeToWait < 60 ) //can't be less than 1 minute from now
                    timeToWait = 60;
                int adjustedTime = timeToWait;

                if ( Game.Instance.Options.AIMods.ContainsKey( AIModifier.DoubleWaves ) )
                    timeToWait = timeToWait / 2;
                else if ( Game.Instance.Options.AIMods.ContainsKey( AIModifier.HalfWaves ) )
                    timeToWait = timeToWait * 2;

                if ( this.AIType == AIType.NeinzulYoungster )
                    timeToWait = timeToWait / 2;

That's relatively simple and small by comparison to the wave size calculations, but there are a few other constraints such as that there can't be any waves in the first 3 minutes of gameplay.

Some things I forgot to mention are that AIs of difficulty 8 get one extra wave per wave instance.  So in 1 player games that's 2 waves per AI, in 8 player games it's 9 waves per AI.  On difficulty 9 it's 2 extra waves, and 10 3 extra waves.

In terms of the size of each of those component waves inside the wave event, those scale up more or less linearly, but randomly:

Code: [Select]
                FInt randomBase = FInt.FromParts( 1, 500 ) * (FInt)Player.AIDifficulty;
                randomBase = randomBase + AILoop.Instance.AIRandom.Next( 4, Player.AIDifficulty.IntValue + 4 );
                int numberShips = ( randomBase +
                    ( ( (FInt)AIProgressionLevel / (FInt)10 ) * ( Player.AIDifficulty / (FInt)10 ) ) ).IntValue;

However, it's not really linear because later on there are some caps and divisors that affect the lower difficulties a bit more heavily.  Though the biggest difference between the AI difficulty levels is the frequency of waves, rather than their scale.  The scale does go up on the higher difficulties, especially on 8+, but the frequency is perhaps the biggest killer.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Wave calculation
« Reply #4 on: August 19, 2010, 09:16:37 pm »
My pleasure, by the way.  Now I'm off for the night, just in case a little boy decides to arrive in the wee hours. ;)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline RCIX

  • Core Member Mark II
  • *****
  • Posts: 2,808
  • Avatar credit goes to Spookypatrol on League forum
Re: Wave calculation
« Reply #5 on: August 19, 2010, 10:32:55 pm »
I coded almost all of the variables for it, and I'm not ever able to predict it.  There are too many layers of variables and randomization on top of all that.
Isn't that basically the description of AI war? ;)

My pleasure, by the way.  Now I'm off for the night, just in case a little boy decides to arrive in the wee hours. ;)
Good luck! If at all possible, do try to let us know if he's on the way :)
Avid League player and apparently back from the dead!

If we weren't going for your money, you wouldn't have gotten as much value for it!

Oh, wait... *causation loop detonates*

Offline Vinraith

  • Hero Member Mark II
  • *****
  • Posts: 806
Re: Wave calculation
« Reply #6 on: August 19, 2010, 10:51:35 pm »
My pleasure, by the way.  Now I'm off for the night, just in case a little boy decides to arrive in the wee hours. ;)

Thanks again, with the code that's pretty much crystal clear. Congratulations and best of luck with the new baby, hope everything goes smoothly for you and your wife. :) You'll be missed around here when he comes, but that particular development project clearly has priority. ;D
« Last Edit: August 19, 2010, 10:55:00 pm by Vinraith »

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Wave calculation
« Reply #7 on: August 20, 2010, 10:18:42 am »
Thanks, guys.  And glad that description was a help.

Contractions all night, but still no baby.  Grr.  I don't imagine I'll be able to let folks know when he's on his way, but I'll try to post a picture and such within a day or two of when he arrives.  Just depends on what all is going on, etc, but I'll be notifying bunches of people, and figured I'd also notify The Internets of his arrival. ;)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Vinraith

  • Hero Member Mark II
  • *****
  • Posts: 806
Re: Wave calculation
« Reply #8 on: August 20, 2010, 10:59:10 am »
Contractions all night? Yikes, my condolences to your poor wife.  :-\

Thanks for keeping we random internet people in the loop.  ;D

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Wave calculation
« Reply #9 on: August 20, 2010, 11:15:36 am »
Contractions all night? Yikes, my condolences to your poor wife.  :-\

Fortunately, light enough she could sleep through most of them, but yeah.

Thanks for keeping we random internet people in the loop.  ;D

You bet. :)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!