Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-25-2012, 04:31 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

A training mission i create for my squad.

In the script i don't use triggers. Only actions to create new Airgroups.
I store enemy planes in a list, and remove a plane if it is destroyed or killed (killed is earlier for example you kill the pilot, the plane is killed, destroyed is after crashing to ground). If the list count is on a low number i create a new Airgroup.

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{

    List<AiAircraft> enemyAircraftsInGame = new List<AiAircraft>();
    const int EnemyArmy = 1; // reds are enemy change to 2 for blues
    const int MinNumberEnemyPlanesAlive = 1; // number of enemy planes left before creating new airgroup 
 
    private Queue<string> ActionQueue = new Queue<string>(new string[] { "createAnsons", "createBlenheims", "createMosquitos" });
                                    
 
    public override void OnBattleStarted()
    {
        base.OnBattleStarted();

        MissionNumberListener = -1;
    }


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

        if (actor is AiAircraft && actor.Army() == EnemyArmy)
            enemyAircraftsInGame.Add(actor as AiAircraft);
    }


    public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftKilled(missionNumber, shortName, aircraft);
        
        enemyAircraftsInGame.RemoveAll(item => item == aircraft);

        if (enemyAircraftsInGame.Count == MinNumberEnemyPlanesAlive)
        {
            string actionName = ActionQueue.Dequeue();
            ActionQueue.Enqueue(actionName);
 
            AiAction action = GamePlay.gpGetAction(actionName);
            if (action != null) action.Do();
        }
    }


    public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
    {
        base.OnActorDead(missionNumber, shortName, actor, damages);


        if (actor is AiAircraft)
        {
            enemyAircraftsInGame.RemoveAll(item => item == actor as AiAircraft);

            if (enemyAircraftsInGame.Count == MinNumberEnemyPlanesAlive)
            {
                string actionName = ActionQueue.Dequeue();
                ActionQueue.Enqueue(actionName);

                AiAction action = GamePlay.gpGetAction(actionName);
                if (action != null) action.Do();
            }
        }
    }
    

    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);

        if (IsActorDestroyable(actor))
            if(actor is AiCart)
             (actor as AiCart).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;
    }
}
Added a multiplayer mission for blue there is a Spawn-Area (Airstart 3500m) the red tragets fly around the island.
Attached Files
File Type: zip shootingRange.zip (2.5 KB, 37 views)
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:44 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.