Log in

View Full Version : patch changes-is it now possible to let ground vehicles&trains disappear(destroy)


David198502
05-08-2012, 08:55 AM
is it now possible with the patch, that groundvehicles and trains get destroyed(disappear) when they reach their last waypoint???

im really looking forward for that possibility, as it would spice up my missions.

FG28_Kodiak
05-08-2012, 09:37 AM
At the moment it works good for Planes, but i get no Handle to the Waypoitnts of GroundActors nor is GetCurrentWayPoint() working for GroundGroups, at the moment, so its not possible to check if a Groundactor reached it last waypoint. :???:

David198502
05-08-2012, 09:39 AM
thx for your testing and answering Kodiak...a bit disappointing though..hope this will soon be possible, as i would really like to implement "random" life on the ground...

Ataros
05-08-2012, 10:19 AM
onTaskCompleted 'works' on last waypoint as I was told. For aircraft at least, have no idea about ground units.

David198502
05-08-2012, 10:20 AM
according to Kodiak, it doesnt for ground vehicles

FG28_Kodiak
05-08-2012, 10:26 AM
GetCurrentWayPoint() is always 0 by Groundactors:

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

AiGroundGroup Group = GamePlay.gpGroundGroups(1)[0];

if (Group != null)
GamePlay.gpHUDLogCenter(null, "Waypointnr: {0}", new object[] { Group.GetCurrentWayPoint() });

}


OnActorTaskCompleted often deliver strange results. But will testing it again. Maybe it works now.

David198502
05-08-2012, 10:34 AM
but what can be considered as task?do the ground objects have to destroy something, or is reaching a waypoint considered as task as well?

FG28_Kodiak
05-08-2012, 10:54 AM
Groundactors seems are only counted if reached endpoint.

Ok seems to work, but not for trailers. :\


public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
{
base.OnActorTaskCompleted(missionNumber, shortName, actor);

if (actor is AiGroundGroup)
{
foreach (AiActor ac in (actor as AiGroundGroup).GetItems())
{
(ac as AiCart).Destroy();
}
}
}

Smokeynz
05-08-2012, 12:45 PM
For ground vehicles I've had success with Onactorceated and a Timeout period then destroy

I set about 10-15 minutes longer than units take to reach endoint.

probably still wont remove the trailer though

David198502
06-18-2012, 07:41 AM
Groundactors seems are only counted if reached endpoint.

Ok seems to work, but not for trailers. :\


public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
{
base.OnActorTaskCompleted(missionNumber, shortName, actor);

if (actor is AiGroundGroup)
{
foreach (AiActor ac in (actor as AiGroundGroup).GetItems())
{
(ac as AiCart).Destroy();
}
}
}


hey kodiak,.....i dont know, but for me, it doesnt seem to work.

i created a mission, with a train, a tank and another vehicle, and neither of them seem to get destroyed if they reach their last waypoint....:confused:
Ps:what do you mean with trailers?

FG28_Kodiak
06-18-2012, 08:21 AM
Yes OnActorTaskComplete sometimes have strange results (not triggered correctly). Additional problem is that it's not possible to get GetWay() on a Groundgroup to work, it's always returns null. So its not possible to check which Waypoint is reached. :(. The workaround is to create a Area (TPassthrou Trigger or defined in code) and if a GroundActor reached it then destroy it.

David198502
06-18-2012, 08:27 AM
ah ok thats why.....
damn it, i really hope that this is possible soon
but thx for your answer

moggel
06-18-2012, 09:30 AM
thx for your testing and answering Kodiak...a bit disappointing though..hope this will soon be possible, as i would really like to implement "random" life on the ground...


Hey David,

I've written a solution for random life on the ground but it's collecting dust at the moment as I'm buzy writing "Fighter Command" (will be uses to simulate Chain Home and Observer corps in online sessions).

I call the solution "Live Map" and if you're willing to be my tester I would love to send it to you. Currently it's written for offline use but I'm gonna upgrade it for online when I see it works as expected. Are you thinking online or single player for this?

LiveMap works by loading and running "sub missions" as you fly over the country side. Most actors that gets activated below will get removed after a set time (I also couldn't get any even when they reached their last waypoint) to reduce workload. There's a few exceptions to that rule. Ships and trains do not get removed as they're much more visible and you'd expect to see them lumbering along somewhere if you return to the region some time after you saw them last.

The solution means you'll need to piece together those sub missions for regions you intend to fly over. It's not alot of work and you only need to do it once. The sub missions just gets thrown into a sub folder and you're good to go.

Let me know if you're interested.

David198502
06-18-2012, 09:35 AM
hey moggel!
nice to see you on the forum as well!
man i would love to be your crash test dummy!
my main aim is, to make that work for a coop mission, but it would be fine for offline use as well first!

regarding the submissions.....
i would like to introduce some random life on ground in my mission, which generates flights out of a pool of submissions as well...
my problem is mainly, that if i just put ground vehicles into my submissions, the longer the mission runs, the more vehicles will be on the ground, that in the end they are that many, that its not playable anymore because of performance decrease...
have a look, this is my script.....right now, there are no moving ground object placed in the submissions, only in the main mission template, there are static objects, and a few ships(its the ACG map template)....

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{
Stopwatch MissionTimer = new Stopwatch();

public override void OnBattleStarted()
{
base.OnBattleStarted();
MissionTimer.Start();
MissionNumberListener = -1;
}
public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
{
base.OnActorCreated(missionNumber, shortName, actor);

if (actor is AiAircraft)
{
switch ((actor as AiAircraft).InternalTypeName())
{

case "bob:Aircraft.He-111P-2":
case "bob:Aircraft.BlenheimMkIV":

Timeout(3000, () => // Time in Seconds
{
(actor as AiAircraft).Destroy();
});
break;
}
}
}

public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);


if(IsActorDestroyable(aircraft))
aircraft.Destroy();
}


public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);

if (IsActorDestroyable(aircraft))
aircraft.Destroy();
}


private bool IsActorDestroyable(AiActor actor)
{
bool actorDestroyable = true;

//Check if actor is empty (no Player)
if (actor is AiAircraft)
{
if ((actor as AiAircraft).ExistCabin(0))
for (int i = 0; i < (actor as AiAircraft).Places(); i++)
{
if ((actor as AiAircraft).Player(i) != null)
{
actorDestroyable = false;
break;
}
}
}
else if (actor is AiGroundActor)
{
if ((actor as AiGroundActor).ExistCabin(0))
for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
{
if ((actor as AiGroundActor).Player(i) != null)
{
actorDestroyable = false;
break;
}
}
}

return actorDestroyable;
}

// to remove GroundActors after their Task is completed
public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
{
base.OnActorTaskCompleted(missionNumber, shortName, actor);

if (actor is AiGroundActor)
if (IsActorDestroyable(actor))
(actor as AiGroundActor).Destroy();
}

public int GetSumAllPlanes()
{
int planeCount = 0;
List<AiAirGroup> allAirgroups = new List<AiAirGroup>();

if (GamePlay.gpAirGroups(1) != null)
allAirgroups.AddRange(GamePlay.gpAirGroups(1));

if (GamePlay.gpAirGroups(2) != null)
allAirgroups.AddRange(GamePlay.gpAirGroups(2));


allAirgroups.ForEach(item =>
{
foreach (AiAircraft ac in item.GetItems())
{
planeCount++;
}
});

return planeCount;
}

public override void OnTickGame()
{

if(MissionTimer.Elapsed.TotalSeconds >= 130 && GetSumAllPlanes() < 30) //Loads a mission every 130s and only if the sum of all planes < 30
{
Random ZufaelligeMission = new Random();

MissionTimer.Restart(); // Sets timer to 0 and start again

switch (ZufaelligeMission.Next(1,34))
{
case 1:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission1.mis");
break;
case 2:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission2.mis");
break;
case 3:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission3.mis");
break;
case 4:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission4.mis");
break;
case 5:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission5.mis");
break;
case 6:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission6.mis");
break;
case 7:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission7.mis");
break;
case 8:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission8.mis");
break;
case 9:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission9.mis");
break;
case 10:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission10.mis");
break;
case 11:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission11.mis");
break;
case 12:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission12.mis");
break;
case 13:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission13.mis");
break;
case 14:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission14.mis");
break;
case 15:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission15.mis");
break;
case 16:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission16.mis");
break;
case 17:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission17.mis");
break;
case 18:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission18.mis");
break;
case 19:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission19.mis");
break;
case 20:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission20.mis");
break;
case 21:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission21.mis");
break;
case 22:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission22.mis");
break;
case 23:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission23.mis");
break;
case 24:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission24.mis");
break;
case 25:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission25.mis");
break;
case 26:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission26.mis");
break;
case 27:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission27.mis");
break;
case 28:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission28.mis");
break;
case 29:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission29.mis");
break;
case 30:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission30.mis");
break;
case 31:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission31.mis");
break;
case 32:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission32.mis");
break;
case 33:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission33.mis");
break;
case 34:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission34.mis");
break;

}
}
}
}

ps: to be honest, that is not my script,actually every single line was written by Kodiak(thx again)

moggel
06-18-2012, 10:00 AM
hey moggel!
nice to see you on the forum as well!
man i would love to be your crash test dummy!
my main aim is, to make that work for a coop mission, but it would be fine for offline use as well first!

regarding the submissions.....
i would like to introduce some random life on ground in my mission, which generates flights out of a pool of submissions as well...
my problem is mainly, that if i just put ground vehicles into my submissions, the longer the mission runs, the more vehicles will be on the ground, that in the end they are that many, that its not playable anymore because of performance decrease...
have a look, this is my script.....right now, there are no moving ground object placed in the submissions, only in the main mission template, there are static objects, and a few ships(its the ACG map template)....

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{
Stopwatch MissionTimer = new Stopwatch();

public override void OnBattleStarted()
{
base.OnBattleStarted();
MissionTimer.Start();
MissionNumberListener = -1;
}
public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
{
base.OnActorCreated(missionNumber, shortName, actor);

if (actor is AiAircraft)
{
switch ((actor as AiAircraft).InternalTypeName())
{

case "bob:Aircraft.He-111P-2":
case "bob:Aircraft.BlenheimMkIV":

Timeout(3000, () => // Time in Seconds
{
(actor as AiAircraft).Destroy();
});
break;
}
}
}

public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);


if(IsActorDestroyable(aircraft))
aircraft.Destroy();
}


public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);

if (IsActorDestroyable(aircraft))
aircraft.Destroy();
}


private bool IsActorDestroyable(AiActor actor)
{
bool actorDestroyable = true;

//Check if actor is empty (no Player)
if (actor is AiAircraft)
{
if ((actor as AiAircraft).ExistCabin(0))
for (int i = 0; i < (actor as AiAircraft).Places(); i++)
{
if ((actor as AiAircraft).Player(i) != null)
{
actorDestroyable = false;
break;
}
}
}
else if (actor is AiGroundActor)
{
if ((actor as AiGroundActor).ExistCabin(0))
for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
{
if ((actor as AiGroundActor).Player(i) != null)
{
actorDestroyable = false;
break;
}
}
}

return actorDestroyable;
}

// to remove GroundActors after their Task is completed
public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
{
base.OnActorTaskCompleted(missionNumber, shortName, actor);

if (actor is AiGroundActor)
if (IsActorDestroyable(actor))
(actor as AiGroundActor).Destroy();
}

public int GetSumAllPlanes()
{
int planeCount = 0;
List<AiAirGroup> allAirgroups = new List<AiAirGroup>();

if (GamePlay.gpAirGroups(1) != null)
allAirgroups.AddRange(GamePlay.gpAirGroups(1));

if (GamePlay.gpAirGroups(2) != null)
allAirgroups.AddRange(GamePlay.gpAirGroups(2));


allAirgroups.ForEach(item =>
{
foreach (AiAircraft ac in item.GetItems())
{
planeCount++;
}
});

return planeCount;
}

public override void OnTickGame()
{

if(MissionTimer.Elapsed.TotalSeconds >= 130 && GetSumAllPlanes() < 30) //Loads a mission every 130s and only if the sum of all planes < 30
{
Random ZufaelligeMission = new Random();

MissionTimer.Restart(); // Sets timer to 0 and start again

switch (ZufaelligeMission.Next(1,34))
{
case 1:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission1.mis");
break;
case 2:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission2.mis");
break;
case 3:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission3.mis");
break;
case 4:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission4.mis");
break;
case 5:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission5.mis");
break;
case 6:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission6.mis");
break;
case 7:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission7.mis");
break;
case 8:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission8.mis");
break;
case 9:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission9.mis");
break;
case 10:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission10.mis");
break;
case 11:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission11.mis");
break;
case 12:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission12.mis");
break;
case 13:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission13.mis");
break;
case 14:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission14.mis");
break;
case 15:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission15.mis");
break;
case 16:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission16.mis");
break;
case 17:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission17.mis");
break;
case 18:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission18.mis");
break;
case 19:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission19.mis");
break;
case 20:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission20.mis");
break;
case 21:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission21.mis");
break;
case 22:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission22.mis");
break;
case 23:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission23.mis");
break;
case 24:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission24.mis");
break;
case 25:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission25.mis");
break;
case 26:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission26.mis");
break;
case 27:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission27.mis");
break;
case 28:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission28.mis");
break;
case 29:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission29.mis");
break;
case 30:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission30.mis");
break;
case 31:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission31.mis");
break;
case 32:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission32.mis");
break;
case 33:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission33.mis");
break;
case 34:
GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission34.mis");
break;

}
}
}
}

ps: to be honest, that is not my script,actually every single line was written by Kodiak(thx again)

Well, LiveMap deals with resource housekeeping and makes sure the same sub mission doesn't get loaded when already running. As you (or any pilot in the online context) flies into a "region" LiveMap looks for a sub mission linied to that same region, using simple naming rules. As the sub mission loads and runs all actors are tracked and as they time out (configurable, default is ten minutes if I remember it correctly) they'll get destroyed, yes, even if they haven't reached their final destination.

There's certainly room for improvement, especially in making the "life" appear more random, but my tests show they work quite fine.

I don't think it's all that much code that needs to be modified to make it work on a server in the online context but I need to clean away the "dust" and get back into the code. I'll give it a look this week and send you my private e-mail so we can link up.

~S~
Mog

David198502
06-18-2012, 10:02 AM
that sounds great moggel!

salmo
10-06-2012, 08:10 AM
At the moment it works good for Planes, but i get no Handle to the Waypoitnts of GroundActors nor is GetCurrentWayPoint() working for GroundGroups, at the moment, so its not possible to check if a Groundactor reached it last waypoint. :???:

Trying to do some waypoint scripting & just came across this error. I confirm that GetCurrentWayPoint is STILL not working for aiGroundGroups :( :( How does Luthier expect us to develop content for his wonderful "sandbox" (his words) when there are fundemental components that are broken with no prospect of getting them fixed :evil: