Пример #1
0
        // protected constructor to force Singleton instantiation
        BuildTable()
        {
            CSAI = CSAI.GetInstance();
            aicallback = CSAI.aicallback;
            logfile = LogFile.GetInstance();

            modname = aicallback.GetModName();

            int numunitdefs = aicallback.GetNumUnitDefs();
            logfile.WriteLine( "calling GetUnitDefList, for " + numunitdefs + " units ... " );
            //availableunittypes = aicallback.GetUnitDefList();
            availableunittypes = new IUnitDef[numunitdefs + 1];
            for (int i = 1; i <= numunitdefs; i++)
            {
                availableunittypes[i] = aicallback.GetUnitDefByTypeId(i);
                logfile.WriteLine( i + " " + availableunittypes[i].name + " " + availableunittypes[i].humanName );
            }
            logfile.WriteLine( "... done" );

            if( !LoadCache( modname ) )
            {
                aicallback.SendTextMsg( "Creating new cachefile for mod " + modname, 0 );
                GenerateBuildTable( modname );
                SaveCache( modname );
            }
        }
Пример #2
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 ) );
        }
Пример #3
0
        // protected constructor to force Singleton instantiation
        BuildTable()
        {
            CSAI = CSAI.GetInstance();
            aicallback = CSAI.aicallback;
            logfile = LogFile.GetInstance();

            modname = aicallback.GetModName();

            logfile.WriteLine( "calling GetUnitDefList... " );
            List<IUnitDef> unittypeslist = new List<IUnitDef>();
            int numunittypes = aicallback.GetNumUnitDefs();
            for (int i = 1; i <= numunittypes; i++)
            {
                unittypeslist.Add( aicallback.GetUnitDefByTypeId( i ) );
            }
            availableunittypes = unittypeslist.ToArray();
            logfile.WriteLine( "... done" );

            if( !LoadCache( modname ) )
            {
                aicallback.SendTextMsg( "Creating new cachefile for mod " + modname, 0 );
                GenerateBuildTable( modname );
                SaveCache( modname );
            }
        }
        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*" );
        }
Пример #5
0
        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));
            }
        }
        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*" );
        }
Пример #7
0
        public PlayStyle()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            PlayStyleManager.GetInstance().RegisterPlayStyle( this );
        }
Пример #8
0
        Ownership()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = logfile.GetInstance();

            csai.UnitCreatedEvent += new CSAI.UnitCreatedHandler(csai_UnitCreatedEvent);
        }
        public MovementMaps()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            GenerateMaps();
        }
Пример #10
0
        public void Go()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            csai.RegisterVoiceCommand( "dumppoints", new CSAI.VoiceCommandHandler( this.DumpPoints ) );
            csai.RegisterVoiceCommand( "drawradii", new CSAI.VoiceCommandHandler( this.DrawRadii ) );
        }
Пример #11
0
        // string defaultplaystylename = "tankrush";
        PlayStyleManager()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            csai.RegisterVoiceCommand( "showplaystyles", new CSAI.VoiceCommandHandler( this.VoiceCommandListPlayStyles ) );
            csai.RegisterVoiceCommand( "chooseplaystyle", new CSAI.VoiceCommandHandler( this.VoiceCommandChoosePlayStyle ) );
        }
        public MobileFusionController()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            UnitController.GetInstance().UnitAddedEvent += new UnitController.UnitAddedHandler(MobileFusionController_UnitAddedEvent);
            UnitController.GetInstance().AllUnitsLoaded += new UnitController.AllUnitsLoadedHandler(MobileFusionController_AllUnitsLoaded);
        }
Пример #13
0
        public RadarController( IPlayStyle playstyle )
        {
            this.playstyle = playstyle;

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

            unitcontroller = UnitController.GetInstance();
            buildtable = BuildTable.GetInstance();
        }
Пример #14
0
        public Workflow()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            if (csai.DebugOn)
            {
                csai.RegisterVoiceCommand("dumpworkflow", new CSAI.VoiceCommandHandler(DumpWorkFlow));
            }
        }
Пример #15
0
        BuildPlanner()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            unitdefhelp = new UnitDefHelp( aicallback );

            mapwidth = aicallback.GetMapWidth();
            mapheight = aicallback.GetMapHeight();
        }
Пример #16
0
        //public delegate void AttackPackDeadHandler();
        //public event AttackPackDeadHandler AttackPackDeadEvent;
        // can pass in pointer to a hashtable in another class if we want
        // ie other class can directly modify our hashtable
        public AttackPackCoordinatorUseGroup( Hashtable UnitDefListByDeployedId )
        {
            this.UnitDefListByDeployedId = UnitDefListByDeployedId;

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

            debugon = csai.DebugOn;

            csai.TickEvent += new CSAI.TickHandler( this.Tick );
        }
        //public delegate void AttackPackDeadHandler();
        //public event AttackPackDeadHandler AttackPackDeadEvent;
        // can pass in pointer to a hashtable in another class if we want
        // ie other class can directly modify our hashtable
        public AttackPackCoordinator(Dictionary<int, IUnitDef> UnitDefListByDeployedId)
        {
            this.UnitDefListByDeployedId = UnitDefListByDeployedId;

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

            debugon = csai.DebugOn;

            csai.TickEvent += new CSAI.TickHandler( this.Tick );
        }
        List<CommandInfo> recentcommands = new List<CommandInfo>(); // for debugging, logging

        #endregion Fields

        #region Constructors

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

            csai.TickEvent += new CSAI.TickHandler(csai_TickEvent);
            if (csai.DebugOn)
            {
                csai.RegisterVoiceCommand("dumporders", new CSAI.VoiceCommandHandler(DumpOrders));
            }
        }
        // can pass in pointer to a hashtable in another class if we want
        // ie other class can directly modify our hashtable
        public SpreadSearchPackCoordinator( Hashtable UnitDefListByDeployedId )
        {
            this.UnitDefListByDeployedId = UnitDefListByDeployedId;

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

            debugon = csai.DebugOn;

            csai.TickEvent += new CSAI.TickHandler( this.Tick );
            csai.UnitIdleEvent += new CSAI.UnitIdleHandler( UnitIdle );
        }
Пример #20
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 ) );
        }
        public EnemySelector( double maxenemyspeed, bool WaterOk, bool BadTerrainOk )
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

               // csai.EnemyEntersLOSEvent += new CSAI.EnemyEntersLOSHandler( EnemyEntersLOS );

            enemycontroller = EnemyController.GetInstance();
            unitdefhelp = new UnitDefHelp( aicallback );

            this.maxenemyspeed = maxenemyspeed;
            this.WaterOk = WaterOk;
            this.BadTerrainOk = BadTerrainOk;
        }
Пример #22
0
        // do we need this???  handled by specific controllers???
        //IntArrayList commanders = new IntArrayList();
        //IntArrayList constructors = new IntArrayList();
        //IntArrayList metalcollectors = new IntArrayList();
        //IntArrayList energycollectors = new IntArrayList();
        //IntArrayList groundattack = new IntArrayList();
        
        UnitController()
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();
            unitdefhelp = new UnitDefHelp( aicallback );
            
            csai.UnitFinishedEvent += new CSAI.UnitFinishedHandler( this.NewUnitFinished );
            csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler( this.UnitDestroyed );   

            csai.RegisterVoiceCommand( "killallfriendly", new CSAI.VoiceCommandHandler( this.VoiceCommandKillAllFriendly ) );
            csai.RegisterVoiceCommand( "countunits", new CSAI.VoiceCommandHandler( this.VoiceCommandCountUnits ) );
            
            logfile.WriteLine ("*UnitController initialized*");
        }
Пример #23
0
        Dictionary<int, OwnershipOrder> ordersbyconstructorid = new Dictionary<int, OwnershipOrder>(); // index of orders by constructorid, to allow removal later

        #endregion Fields

        #region Constructors

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

            csai.UnitCreatedEvent += new CSAI.UnitCreatedHandler(csai_UnitCreatedEvent);
            csai.UnitDestroyedEvent += new CSAI.UnitDestroyedHandler(csai_UnitDestroyedEvent);
            csai.UnitFinishedEvent += new CSAI.UnitFinishedHandler(csai_UnitFinishedEvent);

            if (csai.DebugOn)
            {
                csai.RegisterVoiceCommand("dumpownership", new CSAI.VoiceCommandHandler(DumpOwnership));
            }
        }
Пример #24
0
        // 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 ) );
        }
Пример #25
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();
        }
        // can pass in pointer to a hashtable in another class if we want
        // ie other class can directly modify our hashtable
        public SpreadSearchPackCoordinatorWithSearchGrid(Dictionary<int, IUnitDef> UnitDefListByDeployedId)
        {
            this.UnitDefListByDeployedId = UnitDefListByDeployedId;

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

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

            debugon = csai.DebugOn;

            csai.TickEvent += new CSAI.TickHandler( this.Tick );
            csai.UnitIdleEvent += new CSAI.UnitIdleHandler( UnitIdle );
        }
       // 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*" );
        }
Пример #28
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 SpreadSearchPackCoordinatorWithSearchGrid( ScoutUnitDefsById );

            logfile.WriteLine( "*ScoutController initialized*" );
        }
        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 );
        }
Пример #30
0
        public EnemySelector2(double maxenemyspeed, IUnitDef typicalunitdef)
        {
            csai = CSAI.GetInstance();
            aicallback = csai.aicallback;
            logfile = LogFile.GetInstance();

            // csai.EnemyEntersLOSEvent += new CSAI.EnemyEntersLOSHandler( EnemyEntersLOS );

            enemycontroller = EnemyController.GetInstance();
            unitdefhelp = new UnitDefHelp(aicallback);

            this.maxenemyspeed = maxenemyspeed;
            this.WaterOk = WaterOk;
            this.BadTerrainOk = BadTerrainOk;

            this.typicalunitdef = typicalunitdef;
            //    startarea = MovementMaps.GetInstance().GetArea(typicalunitdef, startpos);
        }
Пример #31
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);
        }
Пример #32
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*");
        }
Пример #33
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);
            }
        }
Пример #34
0
 MetalController()
 {
     csai       = CSAI.GetInstance();
     aicallback = csai.aicallback;
     logfile    = LogFile.GetInstance();
 }
 UnitCommandCache()
 {
     csai       = CSAI.GetInstance();
     aicallback = csai.aicallback;
     logfile    = LogFile.GetInstance();
 }
Пример #36
0
 StrategyController()
 {
     csai            = CSAI.GetInstance();
     logfile         = LogFile.GetInstance();
     csai.TickEvent += new CSAI.TickHandler(Tick);
 }
Пример #37
0
 public static TimeSpan GetGameTime()
 {
     IAICallback aicallback = CSAI.GetInstance().aicallback;
     int frames = aicallback.GetCurrentFrame();
     return TimeSpan.FromSeconds((double)frames / 30);
 }
Пример #38
0
        // note: need to check compatible area
        public Float3 GetNearestUnseen(Float3 currentpos, IUnitDef unitdef, int unseensmeansthismanyframes)
        {
            LosMap      losmap     = LosMap.GetInstance();
            IAICallback aicallback = CSAI.GetInstance().aicallback;
            int         mapwidth   = aicallback.GetMapWidth();
            int         mapheight  = aicallback.GetMapHeight();

            int currentunitarea = MovementMaps.GetInstance().GetArea(unitdef, currentpos);
            int losmapwidth     = losmap.LastSeenFrameCount.GetUpperBound(0) + 1;
            int losmapheight    = losmap.LastSeenFrameCount.GetUpperBound(0) + 1;
            int maxradius       = (int)Math.Sqrt(losmapheight * losmapheight + losmapwidth * losmapwidth);
            int unitlosradius   = (int)unitdef.losRadius; // this is in map / 2 units, so it's ok

            Int2[] circlepoints   = CreateCirclePoints(unitlosradius);
            int    bestradius     = 10000000;
            int    bestarea       = 0;
            Float3 bestpos        = null;
            int    unitmapx       = (int)(currentpos.x / 16);
            int    unitmapy       = (int)(currentpos.y / 16);
            int    thisframecount = aicallback.GetCurrentFrame();

            // step around in unitlosradius steps
            for (int radiuslosunits = unitlosradius * 2; radiuslosunits <= maxradius; radiuslosunits += unitlosradius)
            {
                // calculate angle for a unitlosradius / 2 step at this radius.
                // DrawingUtils.DrawCircle(currentpos, radiuslosunits * 16);

                double anglestepradians = 2 * Math.Asin((double)unitlosradius / 2 / (double)radiuslosunits);
                //csai.DebugSay("anglestepradians: " + anglestepradians);
                //return null;
                for (double angleradians = 0; angleradians <= Math.PI * 2; angleradians += anglestepradians)
                {
                    int unseenarea = 0;
                    int searchmapx = unitmapx + (int)((double)radiuslosunits * Math.Cos(angleradians));
                    int searchmapy = unitmapy + (int)((double)radiuslosunits * Math.Sin(angleradians));
                    if (searchmapx >= 0 && searchmapy >= 0 && searchmapx < (mapwidth / 2) && searchmapy < (mapheight / 2))
                    {
                        // if (csai.DebugOn)
                        //  {
                        //      int groupnumber = DrawingUtils.DrawCircle(new Float3(searchmapx * 16, 50 + aicallback.GetElevation( searchmapx * 16, searchmapy * 16 ), searchmapy * 16), unitlosradius * 16);
                        //     aicallback.SetFigureColor(groupnumber, 1, 1, 0, 0.5);
                        // }

                        int thisareanumber = MovementMaps.GetInstance().GetArea(unitdef, new Float3(searchmapx * 16, 0, searchmapy * 16));
                        if (thisareanumber == currentunitarea)
                        {//
                            //if (csai.DebugOn)
                            // {
                            //     int groupnumber = DrawingUtils.DrawCircle(new Float3(searchmapx * 16, 100, searchmapy * 16), unitlosradius * 16);
                            //     aicallback.SetFigureColor(groupnumber, 1, 1, 0, 0.5);
                            // }
                            foreach (Int2 point in circlepoints)
                            {
                                int thismapx = searchmapx + point.x;
                                int thismapy = searchmapy + point.y;
                                if (thismapx >= 0 && thismapy >= 0 && thismapx < mapwidth / 2 && thismapy < mapheight / 2)
                                {
                                    if (thisframecount - losmap.LastSeenFrameCount[thismapx, thismapy] > unseensmeansthismanyframes)
                                    {
                                        unseenarea++;
                                    }
                                }
                            }
                            if (unseenarea >= (circlepoints.GetUpperBound(0) + 1) * 8 / 10)
                            {
                                int groupnumber = DrawingUtils.DrawCircle(new Float3(searchmapx * 16, 100 * aicallback.GetElevation(searchmapx * 16, searchmapy * 16), searchmapy * 16), unitlosradius * 16);
                                aicallback.SetFigureColor(groupnumber, 1, 0, 1, 0.5);
                                return(new Float3(searchmapx * 16, 0, searchmapy * 16));
                            }
                            // return new Float3(searchmapx * 16, 0, searchmapy * 16); // for debugging, remove later
                        }
                    }
                }
            }
            return(null);
        }
Пример #39
0
 BuildTree()
 {
     csai       = CSAI.GetInstance();
     aicallback = csai.aicallback;
     logfile    = LogFile.GetInstance();
 }
Пример #40
0
 public SlopeMap()
 {
     csai       = CSAI.GetInstance();
     aicallback = csai.aicallback;
     logfile    = LogFile.GetInstance();
 }
Пример #41
0
 StartPosition()
 {
     CSAI.GetInstance().UnitCreatedEvent += new CSAI.UnitCreatedHandler(UnitCreatedEvent);
 }