Пример #1
0
        void UpdateLosForUnit(int unitid, IUnitDef unitdef)
        {
            int    thisframecount = aicallback.GetCurrentFrame();
            Float3 pos            = friendlyunitpositionobserver.PosById[unitid] as Float3;
            int    seenmapx       = (int)(pos.x / 16);
            int    seenmapy       = (int)(pos.z / 16);
            // int radius = (int)( unitdef.losRadius / 8 / 2 );
            int radius = (int)unitdef.losRadius;

            if (csai.DebugOn)
            {
                //aicallback.SendTextMsg( "Updating los for " + unitid + " " + unitdef.humanName + " los radius " + radius, 0 );
                DrawingUtils.DrawCircle(pos, radius * 16);
            }
            logfile.WriteLine("Updating los for " + unitid + " " + unitdef.humanName + " los radius " + radius + " pos " + pos.ToString());
            // go line by line, determine positive and negative extent of line, mark lostime
            for (int deltay = -radius; deltay <= radius; deltay++)
            {
                int xextent = (int)Math.Sqrt(radius * radius - deltay * deltay);
                for (int deltax = -xextent; deltax <= xextent; deltax++)
                {
                    int thisx = seenmapx + deltax;
                    int thisy = seenmapy + deltay;
                    if (thisx >= 0 && thisx < mapwidth / 2 && thisy >= 0 && thisy < mapheight / 2)
                    {
                        LastSeenFrameCount[thisx, thisy] = thisframecount;
                    }
                }
                // in progress
            }
            LastLosRefreshFrameCountByUnitId[unitid] = thisframecount;
            PosAtLastRefreshByUnitId[unitid]         = pos;
            logfile.WriteLine("...done");
        }
Пример #2
0
 void BuildAt( int constructorid, IUnitDef unitdef, Float3 buildsite )
 {
     IUnitDef placeholder;
     /*
     if( unitdef.name.ToLower() == "armmex" ) // use smaller placeholder for mexes so fit closer to intended metalspot
     {
         placeholder = buildtable.UnitDefByName[ "ARMMOHO".ToLower() ] as IUnitDef;
     }
     else
     {
         placeholder = buildtable.UnitDefByName[ "CORGANT".ToLower() ] as IUnitDef;
     }
     buildsite = aicallback.ClosestBuildSite( placeholder, buildsite, 1400.0, 2 );            
     buildsite = aicallback.ClosestBuildSite( unitdef, buildsite, 1400.0, 2 );            
     */
     if( unitdef.name == BuildTable.ArmMex )
     {
         placeholder = buildtable.UnitDefByName[ BuildTable.ArmMoho ] as IUnitDef;
         buildsite = aicallback.ClosestBuildSite( placeholder, buildsite, 1400.0, 2 );            
         buildsite = aicallback.ClosestBuildSite( unitdef, buildsite, 1400.0, 2 );            
     }
     else
     {
         buildsite = BuildPlanner.GetInstance().ClosestBuildSite( unitdef, buildsite, 3000 );
         buildsite.y = aicallback.GetElevation( buildsite.x, buildsite.z );
         buildsite = aicallback.ClosestBuildSite( unitdef, buildsite, 1400, 2 );            
     }
     
     logfile.WriteLine( "building " + unitdef.name + " at " + buildsite.ToString() );
     if( ShowNextBuildSite )
     {
         aicallback.DrawUnit(unitdef.name, buildsite, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true);
     }
     aicallback.GiveOrder( constructorid, new Command( - unitdef.id, buildsite.ToDoubleArray() ) );
 }
        UnitInfo[] GetClosestUnits(Hashtable UnitDefListByDeployedId, Float3 targetpos, int numclosestunits)
        {
            UnitInfo[] closestunits = new UnitInfo[numclosestunits];
            double     worsttopfivesquareddistance = 0; // got to get better than this to enter the list
            int        numclosestunitsfound        = 0;

            foreach (DictionaryEntry de in UnitDefListByDeployedId)
            {
                int      deployedid          = (int)de.Key;
                IUnitDef unitdef             = de.Value as IUnitDef;
                Float3   unitpos             = aicallback.GetUnitPos(deployedid);
                double   unitsquareddistance = Float3Helper.GetSquaredDistance(unitpos, targetpos);
                if (numclosestunitsfound < numclosestunits)
                {
                    UnitInfo unitinfo = new UnitInfo(deployedid, unitpos, unitdef, unitsquareddistance);
                    InsertIntoArray(closestunits, unitinfo, numclosestunitsfound);
                    numclosestunitsfound++;
                    worsttopfivesquareddistance = closestunits[numclosestunitsfound - 1].squareddistance;
                }
                else if (unitsquareddistance < worsttopfivesquareddistance)
                {
                    UnitInfo unitinfo = new UnitInfo(deployedid, unitpos, unitdef, unitsquareddistance);
                    InsertIntoArray(closestunits, unitinfo, numclosestunits);
                    worsttopfivesquareddistance = closestunits[numclosestunits - 1].squareddistance;
                }
            }
            return(closestunits);
        }
Пример #4
0
        public void InitAI(IAICallback aicallback, int team)
        {
            this.aicallback = aicallback;
            this.team       = team;
            aicallback.SendTextMsg("Hello from Mono AbicWrappers", 0);
            aicallback.SendTextMsg("The map name is: " + aicallback.GetMapName(), 0);
            aicallback.SendTextMsg("Our ally team is: " + aicallback.GetMyTeam(), 0);

            //int features[10000 + 1];
            //int numfeatures = IAICallback_GetFeatures( aicallback, features, 10000 );
            //sprintf( buffer, "Num features is: %i", numfeatures );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            //const FeatureDef *featuredef = IAICallback_GetFeatureDef( aicallback, features[0] );
            //sprintf( buffer, "First feature: %s", FeatureDef_get_myName( featuredef ) );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            IUnitDef unitdef = aicallback.GetUnitDefByTypeId(34);

            aicallback.SendTextMsg("gotunitdef", 0);
            aicallback.SendTextMsg("type id 34 is " + unitdef.name, 0);
            aicallback.SendTextMsg("human name: " + unitdef.humanName, 0);
            aicallback.SendTextMsg("id: " + unitdef.id, 0);

            IMoveData movedata = unitdef.movedata;

            //IAICallback_SendTextMsg( aicallback, "movedata is null? " + ( movedata == 0 );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            //IAICallback_SendTextMsg( aicallback, "movetype: %i" + MoveData_get_movetype( movedata ) );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            aicallback.SendTextMsg("maxslope: " + movedata.maxSlope, 0);
        }
 public UnitInfo(int deployedid, Float3 pos, IUnitDef unitdef, double squareddistance)
 {
     this.deployedid      = deployedid;
     this.pos             = pos;
     this.unitdef         = unitdef;
     this.squareddistance = squareddistance;
 }
Пример #6
0
        void AddUnit(int friendlyunit)
        {
            IUnitDef unitdef = aicallback.GetUnitDef(friendlyunit);

            if (!UnitDefByDeployedId.Contains(friendlyunit))
            {
                UnitDefByDeployedId.Add(friendlyunit, unitdef);

                /*
                 * if( unitdef.isCommander )
                 * {
                 *  commanders.Add( friendlyunit );
                 * }
                 * if(  unitdefhelp.IsConstructor( unitdef ) )
                 * {
                 *  constructors.Add( friendlyunit );
                 * }
                 */

                if (UnitAddedEvent != null)
                {
                    UnitAddedEvent(friendlyunit, unitdef);
                }
            }
            else
            {
                logfile.WriteLine("UnitController.AddUnit: unit id " + friendlyunit.ToString() + " " + unitdef.humanName + " already exists");
            }
        }
Пример #7
0
        void BuildSomething(int factoryid)
        {
            double         highestpriority    = 0;
            IUnitRequester requestertosatisfy = null;
            IUnitDef       factorydef         = FactoryUnitDefByDeployedId[factoryid] as IUnitDef;

            foreach (object requesterobject in Requesters)
            {
                IUnitRequester requester             = requesterobject as IUnitRequester;
                double         thisrequesterpriority = requester.DoYouNeedSomeUnits(new Factory(factoryid, factorydef));
                if (thisrequesterpriority > 0 && thisrequesterpriority > highestpriority)
                {
                    requestertosatisfy = requester;
                    highestpriority    = thisrequesterpriority;
                    logfile.WriteLine("Potential requester to use " + requestertosatisfy.ToString() + " priority: " + highestpriority);
                }
            }

            if (requestertosatisfy != null)
            {
                IUnitDef unitdef = requestertosatisfy.WhatUnitDoYouNeed(new Factory(factoryid, factorydef));
                logfile.WriteLine("factorycontroller factory " + factoryid + " going with request from " + requestertosatisfy.ToString() + " for " + unitdef.humanName);
                requestertosatisfy.WeAreBuildingYouA(unitdef);
                Ownership.GetInstance().RegisterBuildingOrder(this, unitdef, aicallback.GetUnitPos(factoryid));
                aicallback.GiveOrder(factoryid, new Command(-unitdef.id));
            }
        }
Пример #8
0
 public void UnitAdded(int deployedunitid, IUnitDef unitdef)
 {
     if (unitdef.name.ToLower() == BuildTable.ArmConstructionVehicle ||
         unitdef.name.ToLower() == "armck" || unitdef.name.ToLower() == "armca" ||
         unitdef.isCommander)
     {
         if (!UnitDefByUnitId.Contains(deployedunitid))
         {
             UnitDefByUnitId.Add(deployedunitid, unitdef);
             logfile.WriteLine("Constructor controller; new constructor: " + unitdef.humanName);
             DoSomething(deployedunitid);
         }
     }
     if (unitdef.isCommander && unitdef.name.ToLower() != BuildTable.ArmCommander)
     {
         aicallback.SendTextMsg("Warning: please make sure the AI is running as ARM", 0);
         aicallback.SendTextMsg("CSAI will not function correctly if not running as ARM", 0);
         logfile.WriteLine("************************************************");
         logfile.WriteLine("************************************************");
         logfile.WriteLine("**** Warning: please make sure the AI is running as ARM ****");
         logfile.WriteLine("**** CSAI will not function correctly if not running as ARM ****");
         logfile.WriteLine("************************************************");
         logfile.WriteLine("************************************************");
     }
 }
Пример #9
0
        public Float3 ClosestBuildSite(IUnitDef thisunitdef, Float3 pos, double searchradius, int mindistance)
        {
            float x = 0; float y = 0; float z = 0;

            ABICInterface.IAICallback_ClosestBuildSite(self, ref x, ref y, ref z, (thisunitdef as UnitDef).self, (float)pos.x, (float)pos.y, (float)pos.z, (float)searchradius, mindistance, 0);
            return(new Float3(x, y, z));
        }
Пример #10
0
 public OwnershipOrder(IBuilder builder, int constructorid, IUnitDef orderedunit, Float3 pos)
 {
     this.builder       = builder;
     this.constructorid = constructorid;
     this.orderedunit   = orderedunit;
     this.pos           = pos;
 }
Пример #11
0
 void csai_UnitFinishedEvent(int deployedunitid, IUnitDef unitdef)
 {
     lock (orders)
     {
         Random random = new Random();
         int    refnum = random.Next(0, 10000);
         List <OwnershipOrder> orderstoremove = new List <OwnershipOrder>();
         logfile.WriteLine(refnum + " orders is null: " + (orders == null).ToString());
         logfile.WriteLine(refnum + " orders type is : " + orders.GetType().ToString());
         logfile.WriteLine(refnum + " orders count is : " + orders.Count.ToString());
         try
         {
             foreach (OwnershipOrder order in orders)
             {
                 if (order.unitdeployedid == deployedunitid)
                 {
                     order.builder.UnitFinished(order, deployedunitid, order.orderedunit);
                     orderstoremove.Add(order);
                 }
             }
             foreach (OwnershipOrder order in orderstoremove)
             {
                 orders.Remove(order);
             }
             ordersbyconstructorid.Remove(deployedunitid);
         }
         catch (Exception e)
         {
             logfile.WriteLine(refnum + " " + e.ToString());
             throw e;
         }
     }
 }
Пример #12
0
        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*");
        }
Пример #13
0
        //int BiggestMexUnit = -1; // cache value to save time later
        public IUnitDef GetBiggestMexUnit()
        {
            //if( BiggestMexUnit != -1 )
            //{
            //  return BiggestMexUnit;
            //}

            logfile.WriteLine("Entering GetBiggestMexUnit()");

            int biggest_mex_id = 0, biggest_area = 0;

            logfile.WriteLine("Scanning unitdef list...");
            IUnitDef biggestmexunit = null;

            foreach (IUnitDef unitdef in availableunittypes)
            {
                if (unitdef.extractsMetal > 0)
                {
                    int thisarea = unitdef.xsize * unitdef.ysize;
                    if (thisarea > biggest_area)
                    {
                        biggest_mex_id = unitdef.id;
                        biggest_area   = thisarea;
                        biggestmexunit = unitdef;
                    }
                }
            }

            logfile.WriteLine("Leaving GetBiggestMexUnit(), it's unittypeid is " + biggest_mex_id);
            return(biggestmexunit);
        }
Пример #14
0
 // mark squares as used
 // and keep record of where this unit was, and how big, in case it is destroyed
 public void UnitCreated(int id, IUnitDef unitdef)
 {
     if (!buildinginfobyid.Contains(id) && !unitdefhelp.IsMobile(unitdef))
     {
         Float3 pos     = aicallback.GetUnitPos(id);
         int    mapposx = (int)(pos.x / 8);
         int    mapposy = (int)(pos.z / 8);
         //int unitsizex = (int)Math.Ceiling( unitdef.xsize / 8.0 );
         //int unitsizey = (int)Math.Ceiling( unitdef.ysize / 8.0 );
         int unitsizex = unitdef.xsize;
         int unitsizey = unitdef.ysize;
         logfile.WriteLine("Buildmap unitcreated " + unitdef.name + " mappos " + mapposx + " " + mapposy + " unitsize " + unitsizex + " " + unitsizey);
         buildinginfobyid.Add(id, new BuildingInfo(mapposx, mapposy, unitsizex, unitsizey));
         for (int x = 0; x < unitsizex; x++)
         {
             for (int y = 0; y < unitsizey; y++)
             {
                 int thisx = mapposx + x - unitdef.xsize / 2;
                 int thisy = mapposy + y - unitdef.ysize / 2;
                 SquareAvailable[thisx, thisy] = false;
                 //if( csai.DebugOn )
                 //{
                 // logfile.WriteLine( "marking " + thisx + " " + thisy + " as used by " + unitdef.name );
                 //  aicallback.DrawUnit( "ARMMINE1", new Float3( thisx * 8, aicallback.GetElevation( thisx * 8, thisy * 8 ), thisy * 8 ), 0.0f, 400, aicallback.GetMyAllyTeam(), true, true);
                 //}
             }
         }
     }
 }
Пример #15
0
        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*" );
        }
Пример #16
0
 public bool IsAirCraft(IUnitDef ud)
 {
     if(ud.type.ToLower() == "fighter")	return true;
     if(ud.type.ToLower() == "bomber")	return true;
     if(ud.canfly&&(ud.movedata == null)) return true;
     return false;
 }
Пример #17
0
 public bool IsMex(IUnitDef ud)
 {
     if(ud.type.ToLower() == "metalextractor"){
         return true;
     }
     return false;
 }
Пример #18
0
        void AddEnemy(int enemyid)
        {
            IUnitDef unitdef = aicallback.GetUnitDef(enemyid);

            if (!EnemyUnitDefByDeployedId.Contains(enemyid))
            {
                EnemyUnitDefByDeployedId.Add(enemyid, unitdef);
                logfile.WriteLine("EnemyController New enemy: " + enemyid);
                if (NewEnemyAddedEvent != null)
                {
                    NewEnemyAddedEvent(enemyid, unitdef);
                }
            }
            if (unitdef != null)
            {
                if (EnemyUnitDefByDeployedId[enemyid] == null)
                {
                    EnemyUnitDefByDeployedId[enemyid] = unitdef;
                    logfile.WriteLine("enemy " + enemyid + " is " + unitdef.humanName);
                }
                if (!unitdefhelp.IsMobile(unitdef))
                {
                    if (!EnemyStaticPosByDeployedId.Contains(enemyid))
                    {
                        EnemyStaticPosByDeployedId.Add(enemyid, aicallback.GetUnitPos(enemyid));
                    }
                }
            }
        }
Пример #19
0
        // Ask what unit they need building
        public IUnitDef WhatUnitDoYouNeed(IFactory factory)
        {
            IUnitDef unitdef = null;

            unitdef = buildtable.UnitDefByName["armrad"] as IUnitDef;
            return(unitdef);
        }
Пример #20
0
        bool BuildConstructionVehicle(int constructorid, IUnitDef constructordef)
        {
            IUnitDef deftobuild = null;

            if (BuildTree.GetInstance().CanBuild(constructordef.name.ToLower(), "armcv"))
            {
                deftobuild = BuildTable.GetInstance().UnitDefByName["armcv"];
            }
            else if (BuildTree.GetInstance().CanBuild(constructordef.name.ToLower(), "armacv"))
            {
                deftobuild = BuildTable.GetInstance().UnitDefByName["armacv"];
            }
            else
            {
                return(false);
            }
            Float3 pos = BuildUnit(constructorid, deftobuild.name.ToLower());

            Ownership.IOrder ownershiporder = Ownership.GetInstance().RegisterBuildingOrder(this,
                                                                                            constructorid,
                                                                                            deftobuild, pos);
            logfile.WriteLine("building: " + deftobuild.name.ToLower());
            //ordertodo.unitsunderconstruction.Add(ownershiporder);
            if (AssistingConstructors.ContainsKey(constructorid))
            {
                AssistingConstructors.Remove(constructorid);
            }
            return(true);
        }
 void MobileFusionController_UnitAddedEvent(int deployedid, IUnitDef unitdef)
 {
     if (unitdef.name.ToLower() == "armmfus")
     {
         mobileunits.Add(deployedid);
     }
 }
Пример #22
0
        void AddUnit(int friendlyunit)
        {
            IUnitDef unitdef = aicallback.GetUnitDef(friendlyunit);

            if (!UnitDefByDeployedId.ContainsKey(friendlyunit))
            {
                logfile.WriteLine("UnitController.AddUnit: unit id " + friendlyunit.ToString() + " " + unitdef.humanName);
                string name = unitdef.name.ToLower();
                UnitDefByDeployedId.Add(friendlyunit, unitdef);
                if (!UnitDefsByName.ContainsKey(name))
                {
                    UnitDefsByName.Add(name, new List <IUnitDef>());
                }
                UnitDefsByName[name].Add(unitdef);

                if (UnitAddedEvent != null)
                {
                    UnitAddedEvent(friendlyunit, unitdef);
                }
                logfile.WriteLine("UnitController.AddUnit finished");
            }
            else
            {
                logfile.WriteLine("UnitController.AddUnit: unit id " + friendlyunit.ToString() + " " + unitdef.humanName + " already exists");
            }
        }
Пример #23
0
        // Ask what unit they need building
        public IUnitDef WhatUnitDoYouNeed(IFactory factory)
        {
            IUnitDef unitdef = null;

            if (factory.Name == "armvp")
            {
                unitdef = buildtable.UnitDefByName["armfav"] as IUnitDef;
            }
            else if (factory.Name == "armlab")
            {
                if (aicallback.GetModName().ToLower().IndexOf("xta") == 0)
                {
                    unitdef = buildtable.UnitDefByName["armpw"] as IUnitDef;
                }
                else
                {
                    unitdef = buildtable.UnitDefByName["armflea"] as IUnitDef;
                }
            }
            else if (factory.Name == "armap")
            {
                unitdef = buildtable.UnitDefByName["armpeep"] as IUnitDef;
            }
            logfile.WriteLine("ScoutController: requesting " + unitdef.humanName);
            return(unitdef);
        }
 void MobileFusionController_UnitAddedEvent(int deployedid, IUnitDef unitdef)
 {
     if (unitdef.name.ToLower() == "armmfus")
     {
         mobileunits.Add(deployedid);
     }
 }
Пример #25
0
 public bool IsMex(IUnitDef ud)
 {
     if (ud.type.ToLower() == "metalextractor")
     {
         return(true);
     }
     return(false);
 }
Пример #26
0
 public bool IsConstructor(IUnitDef unitdef)
 {
     if (unitdef.GetNumBuildOptions() == 0)
     {
         return(false);
     }
     return(unitdef.builder && IsMobile(unitdef));
 }
Пример #27
0
 public bool IsBomber(IUnitDef ud)
 {
     if (IsAirCraft(ud) && (ud.type.ToLower() == "bomber"))
     {
         return(true);
     }
     return(false);
 }
Пример #28
0
 public bool IsFighter(IUnitDef ud)
 {
     if (IsAirCraft(ud) && !ud.hoverAttack)
     {
         return(true);
     }
     return(false);
 }
Пример #29
0
 public bool IsGunship(IUnitDef ud)
 {
     if (IsAirCraft(ud) && ud.hoverAttack)
     {
         return(true);
     }
     return(false);
 }
Пример #30
0
 public bool IsBoat(IUnitDef unitdef)
 {
     if (IsMobile(unitdef) && unitdef.minWaterDepth > 0)
     {
         return(true);
     }
     return(false);
 }
Пример #31
0
 public bool IsBoat( IUnitDef unitdef )
 {
     if( IsMobile( unitdef ) && unitdef.minWaterDepth > 0 )
     {
         return true;
     }
     return false;
 }
Пример #32
0
 public bool IsConstructor(IUnitDef unitdef)
 {
     if (unitdef.buildOptions.GetUpperBound(0) + 1 == 0)
     {
         return(false);
     }
     return(unitdef.builder && IsMobile(unitdef));
 }
Пример #33
0
 bool IsLaserTower(IUnitDef unitdef)
 {
     if (unitdef.name.ToLower() == "armllt" || unitdef.name.ToLower() == "corllt" ||
         unitdef.name.ToLower() == "armfrt" || unitdef.name.ToLower() == "corfrt")
     {
         return(true);
     }
     return(false);
 }
Пример #34
0
 public void RefreshMyMemory(UnitAddedHandler unitadded)
 {
     foreach (DictionaryEntry de in UnitDefByDeployedId)
     {
         int      deployedid = (int)de.Key;
         IUnitDef unitdef    = de.Value as IUnitDef;
         unitadded(deployedid, unitdef);
     }
 }
Пример #35
0
 public void UnitAdded(int id, IUnitDef unitdef)
 {
     if (!LastLosRefreshFrameCountByUnitId.Contains(id))
     {
         LastLosRefreshFrameCountByUnitId.Add(id, aicallback.GetCurrentFrame());
         PosAtLastRefreshByUnitId.Add(id, aicallback.GetUnitPos(id));
         UpdateLosForUnit(id, unitdef);
     }
 }
 // looks at current power usage, and requirements for unit, and decides if we can build it without stalling
 // assumes nothing else suddenly starting at same time...
 // do something more elegant later
 public bool CanBuild( IUnitDef def )
 {
     double excesspowerrequired = ( def.energyCost - aicallback.GetEnergy() ) / def.buildTime;
     double oursurplus = aicallback.GetEnergyIncome() - aicallback.GetEnergyUsage();
        // logfile.WriteLine( "Out income: " + aicallback.GetEnergyIncome() + " usage: " + aicallback.GetEnergyUsage() + " surplus: " + oursurplus );
     bool result =  excesspowerrequired < oursurplus;
     //logfile.WriteLine( "Current energy: " + aicallback.GetEnergy() + " itemenergycost: " + def.energyCost + " buildtime: " + def.buildTime + " Excesspowerrequired: " + excesspowerrequired + " overall: " + result );
     return result;
 }
Пример #37
0
 public UnitDefArrayList( IUnitDef[] array )
 {
     if( array != null )
     {
         foreach( IUnitDef value in array )
         {
             base.Add( value );
         }
     }
 }
 void UnitAddedEvent(int deployedid, IUnitDef unitdef)
 {
     if (!defbyid.ContainsKey(deployedid))
     {
         string name = unitdef.name.ToLower();
         if (unitnames.Contains(name))
         {
             defbyid.Add(deployedid, unitdef);
         }
     }
 }
Пример #39
0
 public bool IsEnergy(IUnitDef ud)
 {
     if(ud.needGeo){
         return false;
     }
     if(ud.energyUpkeep<-1) return true;
     if((ud.windGenerator>0)&&(aicallback.GetMaxWind()>9)) return true;
     if(ud.tidalGenerator>0) return true;
     if(ud.energyMake>5) return true;
     return false;
 }
 void Level1ConstructorList_UnitAddedEvent(int deployedid, IUnitDef unitdef)
 {
     if (!defbyid.ContainsKey(deployedid))
     {
         string name = unitdef.name.ToLower();
         if (constructorunitnames.Contains(name))
         {
             defbyid.Add(deployedid, unitdef);
         }
     }
 }
 void UnitCreatedEvent(int deployedunitid, IUnitDef unitdef)
 {
     IAICallback aicallback = CSAI.GetInstance().aicallback;
     if (aicallback.GetCurrentFrame() <= 1)
     {
         if (unitdef.isCommander)
         {
             startposition = aicallback.GetUnitPos(deployedunitid);
             //aicallback.get
         }
     }
 }
 void UnitAddedEvent(int deployedid, IUnitDef unitdef)
 {
     if (!defbyid.ContainsKey(deployedid))
     {
         string name = unitdef.name.ToLower();
         if (commandernames.Contains(name))
         {
             LogFile.GetInstance().WriteLine("commanderlist unitaddedevent " + deployedid + " " + unitdef.humanName);
             defbyid.Add(deployedid, unitdef);
         }
     }
 }
 // looks at current power usage, and requirements for unit, and decides if we can build it without stalling
 // assumes nothing else suddenly starting at same time...
 // do something more elegant later
 public bool CanBuild( IUnitDef def )
 {
     return aicallback.GetMetal() > def.metalCost;
     /*
     double excessmetalrequired = ( def.metalCost - aicallback.GetMetal() ) / def.buildTime;
     double OurIncome = aicallback.GetMetalIncome() - aicallback.GetMetalUsage();
     logfile.WriteLine( "Metal income: " + aicallback.GetMetalIncome() + " metal usage: " + aicallback.GetMetalUsage() );
     bool result = excessmetalrequired < OurIncome;
     logfile.WriteLine( "Current metal: " + aicallback.GetMetal() + " itemmetalcost: " + def.metalCost + " buildtime: " + def.buildTime + " excessmetalrequired: " + excessmetalrequired + " our income: " + OurIncome + " overall: " + result );
     return result;
     */
 }
Пример #44
0
 void UnitAddedEvent(int deployedid, IUnitDef unitdef)
 {
     LogFile.GetInstance().WriteLine("TankList.UnitAddedEvent " + deployedid + " " + unitdef.humanName);
     if (!defbyid.ContainsKey(deployedid))
     {
         string name = unitdef.name.ToLower();
         if (unitnames.Contains(name))
         {
             LogFile.GetInstance().WriteLine("TankList.UnitAddedEvent " + deployedid + " " + unitdef.humanName + " ACCEPTED");
             defbyid.Add(deployedid, unitdef);
         }
     }
 }
Пример #45
0
 void csai_UnitCreatedEvent(int deployedunitid, IUnitDef unitdef)
 {
     foreach (Order order in orders)
     {
         if (order.orderedunit.id == unitdef.id)
         {
             Float3 createdunitpos = aicallback.GetUnitPos( deployedunitid );
             if (Float3Helper.GetSquaredDistance(createdunitpos, order.pos) < maxdistanceconsideredsame * maxdistanceconsideredsame)
             {
                 order.unitdeployedid = deployedunitid;
                 order.factorycontroller.UnitCreated(order, deployedunitid);
             }
         }
     }
 }
 public void UnitAdded( int id, IUnitDef unitdef )
 {
     if( !PosById.ContainsKey( id ) )
     {
         PosById.Add( id, aicallback.GetUnitPos( id ) );
         if( unitdefhelp.IsMobile( unitdef ) )
         {
             MobileUnitIds.Add( id );
         }
         else
         {
             StaticUnitIds.Add( id );
         }
     }
 }
Пример #47
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);
        }
 // looks at current power usage, and requirements for unit, and decides if we can build it without stalling
 // assumes nothing else suddenly starting at same time...
 // do something more elegant later
 public bool CanBuild( IUnitDef def )
 {
     // if (csai.DebugOn)
       //  {
       //      aicallback.SendTextMsg("metalcontroller canbuild " + def.humanName + " current metal: " + aicallback.GetMetal() + " cost: " + def.metalCost, 0);
       //  }
     if (aicallback.GetMetal() > def.metalCost)
     {
         return true;
     }
     //return aicallback.GetMetal() > def.metalCost;
     double excessmetalrequired = ( def.metalCost - aicallback.GetMetal() * 8 / 10 ) / def.buildTime;
     double OurIncome = aicallback.GetMetalIncome() - aicallback.GetMetalUsage();
     logfile.WriteLine( "Metal income: " + aicallback.GetMetalIncome() + " metal usage: " + aicallback.GetMetalUsage() );
     bool result = ( excessmetalrequired * 4 ) < OurIncome;
     logfile.WriteLine( "Current metal: " + aicallback.GetMetal() + " itemmetalcost: " + def.metalCost + " buildtime: " + def.buildTime + " excessmetalrequired: " + excessmetalrequired + " our income: " + OurIncome + " overall: " + result );
     return result;
 }
Пример #49
0
 public UnitInfo( int deployedid, Float3 pos, IUnitDef unitdef, double squareddistance )
 {
     this.deployedid = deployedid;
     this.pos = pos;
     this.unitdef = unitdef;
     this.squareddistance = squareddistance;
 }
Пример #50
0
 public void UnitAdded( int unitid, IUnitDef unitdef )
 {
     aicallback.AddUnitToGroup( unitid, groupid );
 }
Пример #51
0
 // your request got destroyed; new what-to-build negotations round
 public void YourRequestWasDestroyedDuringBuilding_Sorry( IUnitDef unitwearebuilding )
 {
 }
 public void EnemyAdded( int id, IUnitDef unitdef )
 {
   //  Float3 enemypos = aicallback.GetUnitPos( id );
   //  for( int i = 0; i < 3; i++ )
   //  {
    //     Float3 randomoffset = new Float3( random.Next( -enemysightedsearchradius, enemysightedsearchradius ), 0, random.Next( -enemysightedsearchradius, enemysightedsearchradius ) );
    //     if( csai.DebugOn )
    //     {
     //        aicallback.DrawUnit("ARMARAD", enemypos + randomoffset, 0.0f, 500, aicallback.GetMyAllyTeam(), true, true);
     //    }
      //   PriorityTargets.Enqueue( enemypos + randomoffset );
   //  }
 }
Пример #53
0
 public void UnitAdded( int id, IUnitDef unitdef )
 {
     if( !LastLosRefreshFrameCountByUnitId.Contains( id ) )
     {
         LastLosRefreshFrameCountByUnitId.Add( id, aicallback.GetCurrentFrame() );
         PosAtLastRefreshByUnitId.Add( id, aicallback.GetUnitPos( id ) );
         UpdateLosForUnit( id, unitdef );
     }
 }
Пример #54
0
 void csai_UnitFinishedEvent(int deployedunitid, IUnitDef unitdef)
 {
     List<UnitInCreation> requeststoremove = new List<UnitInCreation>();
     foreach (UnitInCreation unitincreation in unitsincreation)
     {
         if (unitincreation.deployedid == deployedunitid)
         {
             unitincreation.unitrequester.UnitFinished(deployedunitid, unitdef);
             requeststoremove.Add(unitincreation);
         }
     }
     foreach (UnitInCreation unitincreation in requeststoremove)
     {
         unitsincreation.Remove(unitsincreation);
     }
 }
Пример #55
0
 public Request( IUnitDef unitdef, int quantity, double priority )
 {
     this.UnitDef = unitdef;
     this.Quantity = quantity;
     this.Priority = priority;
 }
Пример #56
0
 public UnitInCreation(IUnitRequester requester, IUnitDef unitdef, Float3 pos)
 {
     this.unitrequester = requester;
     this.unitdef = unitdef;
     this.pos = pos;
 }
 bool IsLaserTower(IUnitDef unitdef )
 {
     if( unitdef.name.ToLower() == "armllt" ||  unitdef.name.ToLower() == "corllt" ||
         unitdef.name.ToLower() == "armfrt" ||  unitdef.name.ToLower() == "corfrt" )
     {
         return true;
     }
     return false;
 }
 bool IsPriorityTarget(IUnitDef unitdef )
 {
     string name = unitdef.name.ToLower();
     return prioritytargets.Contains(name);
 }
Пример #59
0
 void UpdateLosForUnit( int unitid, IUnitDef unitdef )
 {
     int thisframecount = aicallback.GetCurrentFrame();
     Float3 pos = friendlyunitpositionobserver.PosById[ unitid ] as Float3;
     int seenmapx = (int)( pos.x / 16 );
     int seenmapy = (int)( pos.z / 16 );
     // int radius = (int)( unitdef.losRadius / 8 / 2 );
     int radius = (int)unitdef.losRadius;
     if( csai.DebugOn )
     {
         //aicallback.SendTextMsg( "Updating los for " + unitid + " " + unitdef.humanName + " los radius " + radius, 0 );
         DrawingUtils.DrawCircle( pos, radius * 16 );
     }
     logfile.WriteLine( "Updating los for " + unitid + " " + unitdef.humanName + " los radius " + radius + " pos " + pos.ToString() );
     // go line by line, determine positive and negative extent of line, mark lostime
     for( int deltay = -radius; deltay <= radius; deltay++ )
     {
         int xextent = (int)Math.Sqrt( radius * radius - deltay * deltay );
         for( int deltax = -xextent; deltax <= xextent; deltax++ )
         {
             int thisx = seenmapx + deltax;
             int thisy = seenmapy + deltay;
             if( thisx >= 0 && thisx < mapwidth / 2 && thisy >= 0 && thisy < mapheight / 2 )
             {
                 LastSeenFrameCount[ thisx, thisy ] = thisframecount;
             }
         }
         // in progress
     }
     LastLosRefreshFrameCountByUnitId[ unitid ] = thisframecount;
     PosAtLastRefreshByUnitId[ unitid ] = pos;
     logfile.WriteLine( "...done" );
 }
 // later on, we'll get the factory to assign ownership to whoever requested it
 // for now we use unitcontroller
 public void UnitAdded( int unitid, IUnitDef unitdef )
 {
     if( unitdef.name.ToLower() == "armfav" || unitdef.name.ToLower() == "armflea" || unitdef.name.ToLower() == "armpeep"  ||
            unitdef.name.ToLower() == "armpw" ) 
     {
         logfile.WriteLine( "ScoutControllerRaider: new scout added " + unitid );
         ScoutUnitDefsById.Add( unitid, unitdef );
         searchcoordinator.ExploreWith(unitid);
         //ExploreWith( unitid );
     }
 }