public TankController( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitdefhelp = new UnitDefHelp( aicallback );
            unitcontroller = UnitController.GetInstance();
            enemycontroller = EnemyController.GetInstance();
            buildtable = BuildTable.GetInstance();

            enemyselector = new EnemySelector( 110, false, false );

            attackpackcoordinator = new AttackPackCoordinator( TankDefsById );
            spreadsearchpackcoordinator = new SpreadSearchPackCoordinator( TankDefsById );
            movetopackcoordinator = new MoveToPackCoordinator( TankDefsById );
            guardpackcoordinator = new GuardPackCoordinator( TankDefsById );

            packcoordinatorselector = new PackCoordinatorSelector();
            packcoordinatorselector.LoadCoordinator( attackpackcoordinator );
            packcoordinatorselector.LoadCoordinator( spreadsearchpackcoordinator );
            packcoordinatorselector.LoadCoordinator( movetopackcoordinator );
            packcoordinatorselector.LoadCoordinator( guardpackcoordinator );

            logfile.WriteLine( "*TankController Initialized*" );
        }
Exemple #2
0
 TankRush()
 {
     strategycontroller = StrategyController.GetInstance();
     strategycontroller.RegisterStrategy( this.GetType().ToString(), this );
     unitcontroller = UnitController.GetInstance();
     unitcontroller.ExistingUnitEvent += new UnitController.ExistingUnitHandler(unitcontroller_ExistingUnitEvent);
 }
        public TankController( Dictionary< int,IUnitDef>UnitDefsById, IUnitDef typicalunitdef)
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            this.DefsById = UnitDefsById;
            this.typicalunitdef = typicalunitdef;
            
            unitcontroller = UnitController.GetInstance();
            enemycontroller = EnemyController.GetInstance();
            buildtable = BuildTable.GetInstance();

            enemyselector = new EnemySelector2( typicalunitdef.speed * 2, typicalunitdef );
            // speed here is experimental

            attackpackcoordinator = new AttackPackCoordinator(DefsById);
            spreadsearchpackcoordinator = new SpreadSearchPackCoordinator(DefsById);
            movetopackcoordinator = new MoveToPackCoordinator(DefsById);
            guardpackcoordinator = new GuardPackCoordinator(DefsById);
            
            packcoordinatorselector = new PackCoordinatorSelector();
            packcoordinatorselector.LoadCoordinator( attackpackcoordinator );
            packcoordinatorselector.LoadCoordinator( spreadsearchpackcoordinator );
            packcoordinatorselector.LoadCoordinator( movetopackcoordinator );
            packcoordinatorselector.LoadCoordinator( guardpackcoordinator );

            logfile.WriteLine( "*TankController Initialized*" );
        }
Exemple #4
0
        //  int BuildOffsetDistance = 25;
        // protected constructor to enforce Singleton pattern
        CommanderController()
        {
            random = new Random();

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();
            unitcontroller = UnitController.GetInstance();
            buildtable = BuildTable.GetInstance();
            metal = Metal.GetInstance();

            //            factorycontroller = PlayStyleManager.GetInstance().GetCurrentPlayStyle().GetFirstControllerOfType( typeof( IFactoryController ) ) as FactoryController;

            //csai.UnitFinishedEvent += new CSAI.UnitFinishedHandler( UnitFinished );
            //csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler( UnitDestroyed );
            csai.UnitIdleEvent += new CSAI.UnitIdleHandler( UnitIdle );
            //csai.UnitDamagedEvent += new CSAI.UnitDamagedHandler( UnitDamaged );
            csai.TickEvent += new CSAI.TickHandler( Tick );

            unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler( UnitAdded );
            unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler( UnitRemoved );

            csai.RegisterVoiceCommand( "commandermove", new CSAI.VoiceCommandHandler( VoiceCommandMoveCommander ) );
            csai.RegisterVoiceCommand( "commandergetpos", new CSAI.VoiceCommandHandler( VoiceCommandCommanderGetPos ) );
            csai.RegisterVoiceCommand( "commanderbuildat", new CSAI.VoiceCommandHandler( VoiceCommandCommanderBuildAt ) );
            csai.RegisterVoiceCommand( "commanderbuild", new CSAI.VoiceCommandHandler( VoiceCommandCommanderBuild ) );
            csai.RegisterVoiceCommand( "commanderbuildpower", new CSAI.VoiceCommandHandler( VoiceCommandCommanderBuildPower ) );
            csai.RegisterVoiceCommand( "commanderbuildextractor", new CSAI.VoiceCommandHandler( VoiceCommandCommanderBuildExtractor ) );
            csai.RegisterVoiceCommand( "commanderisactive", new CSAI.VoiceCommandHandler( VoiceCommandCommanderIsActive ) );
        }
        LosMap()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitcontroller = UnitController.GetInstance();
            unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler( UnitAdded );
            unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler( UnitRemoved );

            friendlyunitpositionobserver = FriendlyUnitPositionObserver.GetInstance();

            csai.TickEvent += new CSAI.TickHandler( Tick );

            mapwidth = aicallback.GetMapWidth();
            mapheight = aicallback.GetMapHeight();

            logfile.WriteLine( "LosMap, create losarray" );
            LastSeenFrameCount = new int[ mapwidth / 2, mapheight / 2 ];
            logfile.WriteLine( "losarray created, initializing..." );
            for( int y = 0; y < mapheight / 2; y++ )
            {
                for( int x = 0; x < mapwidth / 2; x++ )
                {
                    LastSeenFrameCount[ x, y ] = -1000000;
                }
            }
            logfile.WriteLine( "losarray initialized" );

            if (csai.DebugOn)
            {
                csai.RegisterVoiceCommand("dumplosmap", new CSAI.VoiceCommandHandler(DumpLosMap));
            }
        }
Exemple #6
0
        public RadarController( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitcontroller = UnitController.GetInstance();
            buildtable = BuildTable.GetInstance();
        }
Exemple #7
0
        public FactoryController( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();
            buildtable = BuildTable.GetInstance();
            unitcontroller = UnitController.GetInstance();

            unitdefhelp = new UnitDefHelp( aicallback );

            csai.RegisterVoiceCommand( "dumpfactories", new CSAI.VoiceCommandHandler( DumpFactories ) );
        }
Exemple #8
0
        BuildMap()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitdefhelp = new UnitDefHelp( aicallback );
            unitcontroller = UnitController.GetInstance();

            csai.UnitCreatedEvent += new CSAI.UnitCreatedHandler( UnitCreated );
            csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler( UnitDestroyed );

            unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler( UnitCreated );

            Init();
        }
        // protected constructor to force Singleton instantiation
        Metal()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();
            unitcontroller = UnitController.GetInstance();

            unitdefhelp = new UnitDefHelp( aicallback );

            ExtractorRadius = aicallback.GetExtractorRadius();

            unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler( UnitAdded );
            unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler( UnitRemoved );

            csai.RegisterVoiceCommand( "showmetalspots", new CSAI.VoiceCommandHandler( this.DrawMetalSpotsCommand ) );
        }
       // int terrainwidth;
       // int terrainheight;
        
        public ScoutControllerRaider()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();
            
            random = new Random();

            unitcontroller = UnitController.GetInstance();
           // buildtable = BuildTable.GetInstance();
            enemycontroller = EnemyController.GetInstance();
            
            searchcoordinator = new SpreadSearchPackCoordinatorWithSearchGrid( ScoutUnitDefsById );
            
            logfile.WriteLine( "*ScoutControllerRaider initialized*" );
        }
        public ScoutControllerRandomSearch( IPlayStyle playstyle )
        {
            random = new Random();

            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitcontroller = UnitController.GetInstance();
            buildtable = BuildTable.GetInstance();

            searchcoordinator = new SpreadSearchPackCoordinatorWithSearchGrid( ScoutUnitDefsById );

            logfile.WriteLine( "*ScoutController initialized*" );
        }
Exemple #12
0
        }       // Singleton pattern

        Metal() // protected constructor to force Singleton instantiation
        {
            csai           = CSAI.GetInstance();
            aicallback     = csai.aicallback;
            logfile        = LogFile.GetInstance();
            unitcontroller = UnitController.GetInstance();

            unitdefhelp = new UnitDefHelp(aicallback);

            ExtractorRadius = aicallback.GetExtractorRadius();

            csai.UnitCreatedEvent           += new CSAI.UnitCreatedHandler(UnitAdded);
            unitcontroller.UnitAddedEvent   += new UnitController.UnitAddedHandler(UnitAdded);
            unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler(UnitRemoved);

            csai.RegisterVoiceCommand("showmetalspots", new CSAI.VoiceCommandHandler(this.DrawMetalSpotsCommand));
        }
Exemple #13
0
        public ScoutControllerRandomSearch(IPlayStyle playstyle)
        {
            random = new Random();

            this.playstyle = playstyle;

            csai       = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile    = LogFile.GetInstance();

            unitcontroller = UnitController.GetInstance();
            buildtable     = BuildTable.GetInstance();

            searchcoordinator = new SpreadSearchPackCoordinator(ScoutUnitDefsById);

            logfile.WriteLine("*ScoutController initialized*");
        }
Exemple #14
0
        FriendlyUnitPositionObserver()
        {
            csai       = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile    = LogFile.GetInstance();

            //csai.UnitFinishedEvent += new CSAI.UnitFinishedHandler( this.NewUnitFinished );
            //csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler( this.UnitDestroyed );

            csai.TickEvent += new CSAI.TickHandler(Tick);

            unitcontroller = UnitController.GetInstance();
            unitcontroller.UnitAddedEvent   += new UnitController.UnitAddedHandler(UnitAdded);
            unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler(UnitRemoved);

            unitdefhelp = new UnitDefHelp(aicallback);
        }
        FriendlyUnitPositionObserver()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            //csai.UnitFinishedEvent += new CSAI.UnitFinishedHandler( this.NewUnitFinished );
            //csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler( this.UnitDestroyed );

            csai.TickEvent += new CSAI.TickHandler( Tick );

            unitcontroller = UnitController.GetInstance();
            unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler( UnitAdded );
            unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler( UnitRemoved );

            unitdefhelp = new UnitDefHelp( aicallback );
        }
Exemple #16
0
        public ConstructorController(IPlayStyle playstyle)
        {
            this.playstyle = playstyle;

            csai       = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile    = LogFile.GetInstance();

            ShowNextBuildSite = csai.DebugOn;

            unitcontroller = UnitController.GetInstance();
            // factorycontroller = FactoryController.GetInstance();
            buildtable = BuildTable.GetInstance();
            metal      = Metal.GetInstance();

            ShowNextBuildSite = csai.DebugOn;
            logfile.WriteLine("ConstructorController::ConstructorController() finished");
        }
        public ConstructorController( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            ShowNextBuildSite = csai.DebugOn;

            unitcontroller = UnitController.GetInstance();
            // factorycontroller = FactoryController.GetInstance();
            buildtable = BuildTable.GetInstance();
            metal = Metal.GetInstance();

            ShowNextBuildSite = csai.DebugOn;
            logfile.WriteLine("ConstructorController::ConstructorController() finished" );
        }
Exemple #18
0
        bool BuildMex(int constructorid)
        {
            if (!BuildTree.GetInstance().CanBuild(UnitController.GetInstance().UnitDefByDeployedId[constructorid].name.ToLower(),
                                                  "armmex"))
            {
                return(false);
            }
            IUnitDef unitdef   = BuildTable.GetInstance().UnitDefByName["armmex"];
            Float3   buildsite = Metal.GetInstance().GetNearestMetalSpot(aicallback.GetUnitPos(constructorid));

            buildsite = aicallback.ClosestBuildSite(unitdef, buildsite, 100, 0);
            if (!ActiveConstructors.Contains(constructorid))
            {
                ActiveConstructors.Add(constructorid);
            }
            //aicallback.GiveOrder(constructorid, new Command(-unitdef.id, buildsite.ToDoubleArray()));
            GiveOrderWrapper.GetInstance().BuildUnit(constructorid, unitdef.name, buildsite);
            return(true);
        }
        public void Activate()
        {
            if (!started)
            {
                started            = true;
                restartedfrompause = true;

                groupid = aicallback.CreateGroup("", 0);
                logfile.WriteLine("ATCUG created group id " + groupid);

                unitcontroller = UnitController.GetInstance();

                unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler(UnitAdded);
                //unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler( UnitRemoved );
                //ScoutUnitDefsById.Clear(); // note, dont just make a new one, because searchpackcoordinator wont get new one
                unitcontroller.RefreshMyMemory(new UnitController.UnitAddedHandler(UnitAdded));

                Recoordinate();
            }
        }
Exemple #20
0
        BuildMap()
        {
            csai       = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile    = LogFile.GetInstance();

            unitdefhelp    = new UnitDefHelp(aicallback);
            unitcontroller = UnitController.GetInstance();

            csai.UnitCreatedEvent   += new CSAI.UnitCreatedHandler(UnitCreated);
            csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler(UnitDestroyed);

            unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler(UnitCreated);

            if (csai.DebugOn)
            {
                csai.RegisterVoiceCommand("dumpbuildmap", new CSAI.VoiceCommandHandler(DumpBuildMap));
            }

            Init();
        }
Exemple #21
0
        EnemyController()
        {
            csai       = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile    = LogFile.GetInstance();

            autoshowenemies = csai.DebugOn;

            unitcontroller = UnitController.GetInstance();

            csai.TickEvent            += new CSAI.TickHandler(Tick);
            csai.EnemyEnterRadarEvent += new CSAI.EnemyEnterRadarHandler(this.EnemyEnterRadar);
            csai.EnemyEnterLOSEvent   += new CSAI.EnemyEnterLOSHandler(this.EnemyEnterLOS);
            csai.EnemyLeaveRadarEvent += new CSAI.EnemyLeaveRadarHandler(this.EnemyLeaveRadar);
            csai.EnemyDestroyedEvent  += new CSAI.EnemyDestroyedHandler(this.EnemyDestroyed);

            csai.RegisterVoiceCommand("enemiescount", new CSAI.VoiceCommandHandler(VoiceCommandCountEnemies));
            csai.RegisterVoiceCommand("showenemies", new CSAI.VoiceCommandHandler(VoiceCommandShowEnemies));
            csai.RegisterVoiceCommand("autoshowenemieson", new CSAI.VoiceCommandHandler(VoiceCommandAutoShowEnemiesOn));
            csai.RegisterVoiceCommand("autoshowenemiesoff", new CSAI.VoiceCommandHandler(VoiceCommandAutoShowEnemiesOff));

            unitdefhelp = new UnitDefHelp(aicallback);
        }
        EnemyController()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            autoshowenemies = csai.DebugOn;

            unitcontroller = UnitController.GetInstance();

            csai.TickEvent += new CSAI.TickHandler( Tick );
            csai.EnemyEnterRadarEvent += new CSAI.EnemyEnterRadarHandler( this.EnemyEnterRadar );
            csai.EnemyEnterLOSEvent += new CSAI.EnemyEnterLOSHandler( this.EnemyEnterLOS );
            csai.EnemyLeaveRadarEvent += new CSAI.EnemyLeaveRadarHandler( this.EnemyLeaveRadar );
            csai.EnemyDestroyedEvent += new CSAI.EnemyDestroyedHandler( this.EnemyDestroyed );

            csai.RegisterVoiceCommand( "enemiescount", new CSAI.VoiceCommandHandler( VoiceCommandCountEnemies ) );
            csai.RegisterVoiceCommand( "showenemies", new CSAI.VoiceCommandHandler( VoiceCommandShowEnemies ) );
            csai.RegisterVoiceCommand( "autoshowenemieson", new CSAI.VoiceCommandHandler( VoiceCommandAutoShowEnemiesOn ) );
            csai.RegisterVoiceCommand( "autoshowenemiesoff", new CSAI.VoiceCommandHandler( VoiceCommandAutoShowEnemiesOff ) );

            unitdefhelp = new UnitDefHelp( aicallback );
        }
Exemple #23
0
        public void Activate()
        {
            UnitController.GetInstance();
            EnemyController.GetInstance();
            FriendlyUnitPositionObserver.GetInstance();

            MovementMaps.GetInstance();
            BuildMap.GetInstance();
            Metal.GetInstance().Init();
            LosMap.GetInstance();
            BuildPlanner.GetInstance();

            BuildTable.GetInstance();

            CommanderList.GetInstance();
            Level1ConstructorList.GetInstance();
            Level1FactoryList.GetInstance();

            tankcontroller = new TankController(TankList.GetInstance().defbyid, BuildTable.GetInstance().UnitDefByName["arm_stumpy"]);
            tankcontroller.Activate();
            helicoptercontroller = new TankController(HelicopterList.GetInstance().defbyid, BuildTable.GetInstance().UnitDefByName["arm_brawler"]);
            helicoptercontroller.Activate();
            scoutcontroller = new ScoutControllerRaider();
            scoutcontroller.Activate();

            UnitController.GetInstance().LoadExistingUnits();
            EnemyController.GetInstance().LoadExistingUnits();

            CheckIdleUnits();

            //HeightMapPersistence.GetInstance();

            //BuildSolarCell(CommanderList.GetInstance().defbyid.Keys.GetEnumerator().Current);

            csai.UnitIdleEvent += new CSAI.UnitIdleHandler(csai_UnitIdleEvent);
            csai.TickEvent     += new CSAI.TickHandler(csai_TickEvent);
        }
Exemple #24
0
        // int terrainwidth;
        // int terrainheight;

        public ScoutControllerRaider(IPlayStyle playstyle)
        {
            this.playstyle = playstyle;

            csai       = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile    = LogFile.GetInstance();

            random = new Random();

            //terrainwidth = aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE;
            // terrainheight = aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE;

            //int[,] sectorlastcheckedtickcount = new int[ terrainwidth, terrainheight ];
            // bool[,] sectorispriority = new bool[ terrainwidth, terrainheight ];;

            unitcontroller  = UnitController.GetInstance();
            buildtable      = BuildTable.GetInstance();
            enemycontroller = EnemyController.GetInstance();

            searchcoordinator = new SpreadSearchPackCoordinatorWithSearchGrid(ScoutUnitDefsById);

            logfile.WriteLine("*ScoutControllerRaider initialized*");
        }
Exemple #25
0
        Float3 BuildUnit(int constructorid, string targetunitname)
        {
            csai.DebugSay("workflow, building " + targetunitname);
            IUnitDef targetunitdef  = BuildTable.GetInstance().UnitDefByName[targetunitname];
            IUnitDef constructordef = UnitController.GetInstance().UnitDefByDeployedId[constructorid];

            if (new UnitDefHelp(aicallback).IsMobile(constructordef))
            {
                logfile.WriteLine("constructor is mobile");
                Float3 constructorpos = aicallback.GetUnitPos(constructorid);
                Float3 buildsite      = BuildPlanner.GetInstance().ClosestBuildSite(targetunitdef,
                                                                                    constructorpos,
                                                                                    3000, 2);
                buildsite = aicallback.ClosestBuildSite(targetunitdef, buildsite, 1400, 0);
                logfile.WriteLine("constructor location: " + constructorpos.ToString() + " Buildsite: " + buildsite.ToString() + " target item: " + targetunitdef.humanName);
                if (!ActiveConstructors.Contains(constructorid))
                {
                    ActiveConstructors.Add(constructorid);
                }
                aicallback.DrawUnit(targetunitname.ToUpper(), buildsite, 0.0, 200, aicallback.GetMyAllyTeam(), true, true);
                GiveOrderWrapper.GetInstance().BuildUnit(constructorid, targetunitname, buildsite);
                return(buildsite);
            }
            else
            {
                Float3 factorypos = aicallback.GetUnitPos(constructorid);
                logfile.WriteLine("factory location: " + factorypos.ToString() + " target item: " + targetunitdef.humanName);
                if (!ActiveConstructors.Contains(constructorid))
                {
                    ActiveConstructors.Add(constructorid);
                }
                aicallback.DrawUnit(targetunitdef.name.ToUpper(), factorypos, 0.0, 200, aicallback.GetMyAllyTeam(), true, true);
                GiveOrderWrapper.GetInstance().BuildUnit(constructorid, targetunitname);
                return(factorypos);
            }
        }
Exemple #26
0
 public BuildEconomyController(IPlayStyle playstyle)
 {
     this.playstyle = playstyle;
     UnitController.GetInstance();
 }
Exemple #27
0
        public static Float3 GetNearestReclaim(Float3 mypos, int constructorid)
        {
            if (CSAI.GetInstance().aicallback.GetCurrentFrame() == 0) // check ticks first, beacuse metal shows as zero at start
            {
                return(null);
            }
            LogFile     logfile    = LogFile.GetInstance();
            IAICallback aicallback = CSAI.GetInstance().aicallback;
            IUnitDef    unitdef    = UnitController.GetInstance().UnitDefByDeployedId[constructorid];

            if (!new UnitDefHelp(aicallback).IsMobile(unitdef))
            {
                return(null);
            }
            //Float3 mypos = aicallback.GetUnitPos( constructorid );
            MovementMaps movementmaps = MovementMaps.GetInstance();
            int          currentarea  = movementmaps.GetArea(unitdef, mypos);
            //double nearestreclaimdistancesquared = 1000000;
            //Float3 nearestreclaimpos = null;
            double bestmetaldistanceratio = 0;
            int    bestreclaimid          = 0;
            int    metalspace             = (int)(aicallback.GetMetalStorage() - aicallback.GetMetal());

            logfile.WriteLine("available space in metal storage: " + metalspace);
            int[] nearbyfeatures = aicallback.GetFeatures(mypos, maxreclaimradius);
            bool  reclaimfound   = false;

            foreach (int feature in nearbyfeatures)
            {
                IFeatureDef featuredef = aicallback.GetFeatureDef(feature);
                if (featuredef.metal > 0 && featuredef.metal <= metalspace)
                {
                    Float3 thisfeaturepos         = aicallback.GetFeaturePos(feature);
                    double thisdistance           = Math.Sqrt(Float3Helper.GetSquaredDistance(thisfeaturepos, mypos));
                    double thismetaldistanceratio = featuredef.metal / thisdistance;
                    if (thismetaldistanceratio > bestmetaldistanceratio && movementmaps.GetArea(unitdef, thisfeaturepos) == currentarea)
                    {
                        logfile.WriteLine("Potential reclaim, distance = " + thisdistance + " metal = " + featuredef.metal + " ratio = " + thismetaldistanceratio);
                        bestmetaldistanceratio = thismetaldistanceratio;
                        bestreclaimid          = feature;
                        //         nearestreclaimpo
                        reclaimfound = true;
                    }
                }
            }
            if (reclaimfound && (bestmetaldistanceratio > (1.0 / (100 * reclaimradiusperonehundredmetal))))
            {
                Float3 reclaimpos = aicallback.GetFeaturePos(bestreclaimid);
                logfile.WriteLine("Reclaim found, pos " + reclaimpos.ToString());
                if (CSAI.GetInstance().DebugOn)
                {
                    aicallback.DrawUnit("ARMMEX", reclaimpos, 0.0f, 200, aicallback.GetMyAllyTeam(), true, true);
                }
                return(reclaimpos);
                //aicallback.GiveOrder( constructorid, new Command( Command.CMD_RECLAIM,
                //    new double[]{ reclaimpos.x, reclaimpos.y, reclaimpos.z, 10 } ) );
            }
            else
            {
                //logfile.WriteLine( "No reclaim within parameters" );
                return(null);
            }
        }
Exemple #28
0
        //int numOfUnits = 0;
        //IUnitDef[] unitList;
        //IUnitDef solarcollectordef;

        public void InitAI(IAICallback aicallback, int team)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

            this.aicallback = aicallback;
            try{
                this.Team = team;
                logfile   = LogFile.GetInstance().Init(team);
                logfile.WriteLine("C# AI started v" + AIVersion + ", team " + team + " ref " + reference + " map " + aicallback.GetMapName() + " mod " + aicallback.GetModName());

                if (File.Exists("AI/CSAI/debug.flg"))    // if this file exists, activate debug mode; saves manually changing this for releases
                {
                    logfile.WriteLine("Toggling debug on");
                    DebugOn = true;
                }

                if (DebugOn)
                {
                    new Testing.RunTests().Go();
                }

                InitCache();

                PlayStyleManager.GetInstance();
                LoadPlayStyles.Go();

                metal = Metal.GetInstance();
                CommanderController.GetInstance();
                BuildTable.GetInstance();
                UnitController.GetInstance();
                EnemyController.GetInstance();

                EnergyController.GetInstance();

                MovementMaps.GetInstance();
                BuildMap.GetInstance();

                //FactoryController.GetInstance();
                //RadarController.GetInstance();
                //TankController.GetInstance();
                //ScoutController.GetInstance();
                //ConstructorController.GetInstance();

                metal.Init();
                BuildPlanner.GetInstance();

                UnitController.GetInstance().LoadExistingUnits();  // need this if we're being reloaded in middle of a game, to get already existing units
                EnemyController.GetInstance().LoadExistingUnits();

                StrategyController.GetInstance();
                LoadStrategies.Go();

                PlayStyleManager.GetInstance().ChoosePlayStyle("tankrush");

                if (aicallback.GetModName().ToLower().IndexOf("aass") == 0 || aicallback.GetModName().ToLower().IndexOf("xtape") == 0)
                {
                    aicallback.SendTextMsg("C# AI initialized v" + AIVersion + ", team " + team, 0);
                    aicallback.SendTextMsg("Please say '.csai help' for available commands", 0);

                    PlayStyleManager.GetInstance().ListPlayStyles();

                    //CommanderController.GetInstance().CommanderBuildPower();
                }
                else
                {
                    aicallback.SendTextMsg("Warning: CSAI needs AA2.23  or XTA7 to run correctly at this time", 0);
                    logfile.WriteLine("*********************************************************");
                    logfile.WriteLine("*********************************************************");
                    logfile.WriteLine("****                                                                                           ****");
                    logfile.WriteLine("**** Warning: CSAI needs AA2.23 or XTA7 to run correctly at this time ****");
                    logfile.WriteLine("****                                                                                           ****");
                    logfile.WriteLine("*********************************************************");
                    logfile.WriteLine("*********************************************************");
                }
            }
            catch (Exception e)
            {
                logfile.WriteLine("Exception: " + e.ToString());
                aicallback.SendTextMsg("Exception: " + e.ToString(), 0);
            }
        }
        // int terrainwidth;
        // int terrainheight;
        public ScoutControllerRaider( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            random = new Random();

            //terrainwidth = aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE;
               // terrainheight = aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE;

            //int[,] sectorlastcheckedtickcount = new int[ terrainwidth, terrainheight ];
               // bool[,] sectorispriority = new bool[ terrainwidth, terrainheight ];;

            unitcontroller = UnitController.GetInstance();
            buildtable = BuildTable.GetInstance();
            enemycontroller = EnemyController.GetInstance();

            searchcoordinator = new SpreadSearchPackCoordinatorWithSearchGrid( ScoutUnitDefsById );

            logfile.WriteLine( "*ScoutControllerRaider initialized*" );
        }
Exemple #30
0
        void csai_UnitIdleEvent(int deployedunitid)
        {
            IUnitDef unitdef = UnitController.GetInstance().UnitDefByDeployedId[deployedunitid];

            if (!unitdef.canBuild)
            {
                //logfile.WriteLine("cantbuild");
                return;
            }
            logfile.WriteLine("unitidleevent " + deployedunitid + " " + unitdef.name + " " + unitdef.humanName);
            if (ActiveConstructors.Contains(deployedunitid))
            {
                ActiveConstructors.Remove(deployedunitid);
            }
            Ownership.GetInstance().SignalConstructorIsIdle(deployedunitid);
            double       highestpriority = 0;
            List <Order> bestorders      = new List <Order>();

            foreach (Order order in orders)
            {
                double thispriority = order.priority;
                if (thispriority >= highestpriority)
                {
                    int currentunits = order.unitsunderconstruction.Count;
                    if (UnitController.GetInstance().UnitDefsByName.ContainsKey(order.unitname))
                    {
                        currentunits += UnitController.GetInstance().UnitDefsByName[order.unitname].Count;
                    }
                    if (currentunits < order.quantity)
                    {
                        if (BuildTree.GetInstance().CanBuild(unitdef.name.ToLower(), order.unitname))
                        {
                            //if( CanBuild(deployedunitid,
                            if (thispriority > highestpriority)
                            {
                                highestpriority = thispriority;
                                bestorders      = new List <Order>();
                                bestorders.Add(order);
                                csai.DebugSay("Possible order: " + order.ToString());
                            }
                            else if (thispriority == highestpriority)
                            {
                                bestorders.Add(order);
                                csai.DebugSay("Possible order: " + order.ToString());
                            }
                        }
                    }
                }
            }
            //if (bestorders.Count == 0)
            //  {
            //      csai.DebugSay("No orders found");
            //      return;
            //  }
            List <Order> possibleorders = new List <Order>(); // get orders this unit can build
            bool         metalneeded    = false;
            bool         energyneeded   = false;
            IUnitDef     deftobuild     = null;

            foreach (Order order in bestorders)
            {
                csai.DebugSay("bestorder " + order.unitname);
                //if( BuildTree.GetInstance().CanBuild( unitdef.name.ToLower(), order.unitname ) )
                //{
                deftobuild = BuildTable.GetInstance().UnitDefByName[order.unitname];
                if (MetalController.GetInstance().CanBuild(deftobuild))
                {
                    if (EnergyController.GetInstance().CanBuild(deftobuild))
                    {
                        possibleorders.Add(order);
                        csai.DebugSay("possible: " + order.unitname);
                    }
                    else
                    {
                        csai.DebugSay("needs energy");
                        energyneeded = true;
                    }
                }
                else
                {
                    csai.DebugSay("needs metal");
                    metalneeded = true;
                }
                //}
            }
            if (possibleorders.Count == 0)
            {
                if (Level1ConstructorList.GetInstance().defbyid.Count < 1 &&
                    !UnitController.GetInstance().UnitDefsByName.ContainsKey("armcom"))
                {
                    if (BuildConstructionVehicle(deployedunitid, unitdef))
                    {
                        return;
                    }
                }

                if (energyneeded || aicallback.GetEnergy() < aicallback.GetEnergyStorage() / 5)
                {
                    if (BuildSolarCell(deployedunitid))
                    {
                        logfile.WriteLine("building solarcell");
                        if (AssistingConstructors.ContainsKey(deployedunitid))
                        {
                            AssistingConstructors.Remove(deployedunitid);
                        }
                        return;
                    }
                }
                if (metalneeded || aicallback.GetMetal() < aicallback.GetMetalStorage() / 5)
                {
                    Float3 reclaimpos = ReclaimHelper.GetNearestReclaim(aicallback.GetUnitPos(deployedunitid), deployedunitid);
                    if (reclaimpos != null)
                    {
                        GiveOrderWrapper.GetInstance().Reclaim(deployedunitid, reclaimpos, 100);
                        return;
                    }
                    if (BuildMex(deployedunitid))
                    {
                        logfile.WriteLine("building mex");
                        if (AssistingConstructors.ContainsKey(deployedunitid))
                        {
                            AssistingConstructors.Remove(deployedunitid);
                        }
                        return;
                    }
                }


                logfile.WriteLine("offering assistance");
                OfferAssistance(deployedunitid);
                return;
            }
            Order ordertodo = possibleorders[random.Next(0, possibleorders.Count)];

            if (ordertodo.unitname == "armmex")
            {
                BuildMex(deployedunitid);
                if (AssistingConstructors.ContainsKey(deployedunitid))
                {
                    AssistingConstructors.Remove(deployedunitid);
                }
            }
            else
            {
                //ordertodo.unitsunderconstruction += 1;
                deftobuild = BuildTable.GetInstance().UnitDefByName[ordertodo.unitname];
                Float3           pos            = BuildUnit(deployedunitid, ordertodo.unitname);
                Ownership.IOrder ownershiporder = Ownership.GetInstance().RegisterBuildingOrder(this,
                                                                                                deployedunitid,
                                                                                                deftobuild, pos);
                logfile.WriteLine("building: " + ordertodo.unitname);
                ordertodo.unitsunderconstruction.Add(ownershiporder);
                if (AssistingConstructors.ContainsKey(deployedunitid))
                {
                    AssistingConstructors.Remove(deployedunitid);
                }
            }
        }
 CommanderList()
 {
     UnitController.GetInstance().UnitAddedEvent   += new UnitController.UnitAddedHandler(UnitAddedEvent);
     UnitController.GetInstance().UnitRemovedEvent += new UnitController.UnitRemovedHandler(UnitRemovedEvent);
 }
Exemple #32
0
 TankRush()
 {
     strategycontroller = StrategyController.GetInstance();
     strategycontroller.RegisterStrategy( this.GetType().ToString(), this );
     unitcontroller = UnitController.GetInstance();
 }
        public void Activate()
        {
            if( !started )
            {
                started = true;
                restartedfrompause = true;

                groupid = aicallback.CreateGroup( "", 0 );
                logfile.WriteLine( "ATCUG created group id " + groupid );

                unitcontroller = UnitController.GetInstance();

                unitcontroller.UnitAddedEvent += new UnitController.UnitAddedHandler( UnitAdded );
                //unitcontroller.UnitRemovedEvent += new UnitController.UnitRemovedHandler( UnitRemoved );
                //ScoutUnitDefsById.Clear(); // note, dont just make a new one, because searchpackcoordinator wont get new one
                unitcontroller.RefreshMyMemory( new UnitController.UnitAddedHandler( UnitAdded ) );

                Recoordinate();
            }
        }
Exemple #34
0
 Level1FactoryList()
 {
     UnitController.GetInstance().UnitAddedEvent   += new UnitController.UnitAddedHandler(Level1FactoryList_UnitAddedEvent);
     UnitController.GetInstance().UnitRemovedEvent += new UnitController.UnitRemovedHandler(Level1FactoryList_UnitRemovedEvent);
 }
Exemple #35
0
 TankRush()
 {
     strategycontroller = StrategyController.GetInstance();
     strategycontroller.RegisterStrategy(this.GetType().ToString(), this);
     unitcontroller = UnitController.GetInstance();
 }