PDA

View Full Version : Dynamic Ai spawning model



Salmo
Jul-20-2013, 02:48
Most missions have Ai flights that just spawn-in in some sort of 'regular' manner. Usually, mission builders will simply spawn-in another Ai flight after X time has elapse (say every 20 minutes). This usually results in the Ai spawning-in comparatively infrequently when there are just a few players online. This can be an immersion-killer.

There is a better method. Use a dynamic Ai spawning model. ie Frequent Ai spawning-in when player numbers are low, and reducing numbers of Ai as more players are online. My experience has been that when player numbers are low the Ai need to be spawning-in as often as every 5-10 min. Sounds a lot, but it really isn't. This is what is needed to maintain interest at times when player numbers are low. Sample logistic Ai spawning model below:

Code removed by author ...

RAF74_Buzzsaw
Jul-20-2013, 03:17
Nice work Salmo. :thumbsup:


I've become frustrated with maps where Ai flights just spawn-in in some sort of 'regular' manner. Usually, mission buidlers will simply spawn-in another Ai flight after X time has elapse (say every 20 minutes). This usually results in the Ai spawning-in comparatively infrequently when there are just a few players online. This can be an immersion-killer.

There is a better method. Use a dynamic Ai spawning model. ie Frequent Ai spawning-in when player numbers are low, and reducing numbers of Ai as more players are online. My experience has been that when player numbers are low the Ai need to be spawning-in as often as every 5-10 min. Sounds a lot, but this is needed to maintain player interest at times when player numbers are low. Sample logistic Ai spawning model below:



using System;
using System.Collections;
using maddox.game;
using maddox.game.world;
using part;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;;
using System.Globalization;
using System.IO;
using maddox.GP;

public class Mission : AMission
{
// timers & counters & switches
bool DynamicAiMissionTiming = true; // turn dynamic Ai mission timing on/off
Stopwatch BlueMissionTimer = new Stopwatch();
Stopwatch RedMissionTimer = new Stopwatch();
Random random = new Random();

public override void OnBattleStarted()
{
base.OnBattleStarted();
MissionNumberListener = -1;

RedMissionTimer.Start(); // Ai mission timer
BlueMissionTimer.Start(); // Ai mission timer
}

public override void OnPlayerConnected(Player player)
{
base.OnPlayerConnected(player);
SetAiMissionTiming();
}

public override void OnPlayerDisconnected(Player player, string diagnostic)
{
base.OnPlayerDisconnected(player, diagnostic);
SetAiMissionTiming();
}

public override void OnTickGame()
{
base.OnTickGame();

if (RedMissionTimer.Elapsed.TotalSeconds >= NextRedMission)
{
RedMissionTimer.Restart();
SetAiMissionTiming();
// postmissionload red Ai mission here
}
if (BlueMissionTimer.Elapsed.TotalSeconds >= NextBlueMission)
{
BlueMissionTimer.Restart();
SetAiMissionTiming();
// postmissionload blue Ai mission here
}
}

public void SetAiMissionTiming()
{ // set time for next Ai mission depending on player numbers
if (DynamicAiMissionTiming)
{ // dynamic Ai spawning timing model
Player[] players = GamePlay.gpRemotePlayers();
int TotalPlayers = 0;
TotalPlayers = players.GetUpperBound(0) + 1;

if (TotalPlayers < 1)
{
NextRedMission = 300; // 5 min
NextBlueMission = 300; // 5 min
}
else if (TotalPlayers == 1)
{
NextRedMission = 300; // 5 min
NextBlueMission = 300; // 5 min
}
else if (TotalPlayers == 2)
{
NextRedMission = 300; // 5 min
NextBlueMission = 300; // 5 min
}
else if (TotalPlayers == 3)
{
NextRedMission = 360; // 6 min
NextBlueMission = 360; // 6 min
}
else if (TotalPlayers == 4)
{
NextRedMission = 360; // 6 min
NextBlueMission = 360; // 6 min
}
else if (TotalPlayers == 5)
{
NextRedMission = 420; // 7 min
NextBlueMission = 420; // 7 min
}
else if (TotalPlayers == 6)
{
NextRedMission = 420; // 7 min
NextBlueMission = 420; // 7 min
}
else if (TotalPlayers == 7)
{
NextRedMission = 480; // 8 min
NextBlueMission = 480; // 8 min
}
else if (TotalPlayers == 8)
{
NextRedMission = 480; // 8 min
NextBlueMission = 480; // 8 min
}
else if (TotalPlayers == 9)
{
NextRedMission = 540; // 9 min
NextBlueMission = 540; // 9 min
}
else if (TotalPlayers == 10)
{
NextRedMission = 600; // 10 min
NextBlueMission = 600; // 10 min
}
else if (TotalPlayers == 11)
{
NextRedMission = 672; // 11.2 min
NextBlueMission = 672; // 11.2 min
}
else if (TotalPlayers == 12)
{
NextRedMission = 720; // 12 min
NextBlueMission = 720; // 12 min
}
else if (TotalPlayers > 12)
{ // spawn Ai according to a log curve (the more players the less frequent Ai will spawn-in)
double logcurve = 12 * Math.Log(TotalPlayers, Math.E) - 18;
NextRedMission = RandomDoubleBetween((logcurve - (logcurve * 0.025)), (logcurve + (logcurve * 0.025))); // seconds
NextBlueMission = RandomDoubleBetween((logcurve - (logcurve * 0.025)), (logcurve + (logcurve * 0.025))); // seconds
}
}
else
{ // no dynamic Ai spawning model
NextRedMission = random.Next((20 * 60), (30 * 60)); // random between 20 & 30 min
NextBlueMission = random.Next((20 * 60), (30 * 60)); // random between 20 & 30 min
}
}

double RandomDoubleBetween(double fMin, double fMax)
{
return random.NextDouble() * (fMax - fMax) + fMax;
}
}

92 Sqn. Philstyle (QJ-P)
Jul-20-2013, 03:25
Salmo, doesn't this result in the problem with the AI stacking up as their numbers continually increase (they don't de-spawn)?

Salmo
Jul-20-2013, 03:36
Salmo, doesn't this result in the problem with the AI stacking up as their numbers continually increase (they don't de-spawn)?

Of course you'd have to despawn Ai after they land. That's a given. Added aircraft despawn to script above.

No.54 Ghost (KL-G)
Jul-20-2013, 04:46
hey salmo, i know ive seen a wave of 50 + bombers in one of your missions once.
is there something preventing this on the rest of the missions or was it just a test or something.
really got the feeling "where do we start on this!?"

Salmo
Jul-20-2013, 04:55
hey salmo, i know ive seen a wave of 50 + bombers in one of your missions once.
is there something preventing this on the rest of the missions or was it just a test or something.
really got the feeling "where do we start on this!?"

We're talking about dynamic Ai spawning (timing of Ai missions), not the number of Ai perse. I did have larger LW groups in one of my missions. ATAG found that players were getting lag/lockups issue. The number of LW aircraft in a flight was decreased to 9 - 20 aircraft which seemed to reduce the lag problems.

92 Sqn. Philstyle (QJ-P)
Jul-20-2013, 09:35
Of course you'd have to despawn Ai after they land. That's a given. Added aircraft despawn to script above.

Hi, but often AI are not landing.... just flying around and around in circles over their airfields... has this been resolved now Sal?

Salmo
Jul-20-2013, 19:07
Hi, but often AI are not landing.... just flying around and around in circles over their airfields... has this been resolved now Sal?

I've not seen this. The AI in my missions all land or are air-despawned once they reach certain points.

indyscout
Jul-27-2013, 04:15
I give a big thumbs up to this! As a North American player, there is often 2-12 people on during the North American "Peak Hours". This can lead to some really boring game play, as it becomes more of a sight seeing flight than a combat sortie. I would love to see this implemented.