I use this to remove statics:
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using maddox.GP;
using maddox.game;
using maddox.game.world;
public class Mission : AMission
{
private static string userdocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
private static string FILE_PATH = userdocpath + @"\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Test\";
private static string MISSION = FILE_PATH + "StaticTestSub.mis";
Dictionary<GroundStationary, int> StationaryMisRelation = new Dictionary<GroundStationary, int>();
public override void OnBattleStarted()
{
base.OnBattleStarted();
MissionNumberListener = -1;
}
public override void OnMissionLoaded(int missionNumber)
{
base.OnMissionLoaded(missionNumber);
GamePlay.gpLogServer(null, "OnMissionLoaded: {0}", new object[] { missionNumber });
foreach (GroundStationary gs in GamePlay.gpGroundStationarys())
{
if (!StationaryMisRelation.ContainsKey(gs))
StationaryMisRelation[gs] = missionNumber;
}
}
private void RemoveStationary(int missionNumber)
{
List<GroundStationary> KeysToRemove = new List<GroundStationary>();
foreach (KeyValuePair<GroundStationary, int> kvp in StationaryMisRelation)
{
if (kvp.Value == missionNumber)
{
kvp.Key.Destroy();
KeysToRemove.Add(kvp.Key);
}
}
foreach (GroundStationary groundStationary in KeysToRemove)
{
StationaryMisRelation.Remove(groundStationary);
}
}
public override void OnTrigger(int missionNumber, string shortName, bool active)
{
base.OnTrigger(missionNumber, shortName, active);
if (shortName.Equals("MisLoad"))
{
GamePlay.gpLogServer(null, "MisLoad: {0}", new object[] { MISSION });
GamePlay.gpPostMissionLoad(MISSION);
}
if (shortName.Equals("Trigger"))
{
foreach (KeyValuePair<GroundStationary, int> kvp in StationaryMisRelation)
{
GamePlay.gpLogServer(null, "Stationary: {0}; MissNr.: {1}", new object[] {kvp.Key.Title, kvp.Value});
}
}
if (shortName.Equals("DeleteTrigger")) // from submission
{
GamePlay.gpLogServer(null, "DeleteTrigger MissionNr.: {0}", new object[] { missionNumber });
RemoveStationary(missionNumber);
}
}
}
Explanation:
I store the GroundStationary with the missionNumber in a Dictionary. If a new (sub)mission is loaded i check in OnMissionLoaded if there are new Stationaries created if so i store them in the dictionary with their missionNumber.
If the submission triggers (in this example) the "DeleteTrigger" i remove all statics with this missionNumber.