Exemplo n.º 1
0
        bool DoReclaim(int constructorid)
        {
            if (totalticks == 0) // check ticks first, beacuse metal shows as zero at start
            {
                return(false);
            }
            IUnitDef     unitdef      = UnitDefByUnitId[constructorid] as IUnitDef;
            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.DebugOn)
                {
                    aicallback.DrawUnit("ARMMEX", reclaimpos, 0.0f, 200, aicallback.GetMyAllyTeam(), true, true);
                }
                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(reclaimfound);
        }
        public void  VoiceCommandMoveCommander(string chatstring, string[] splitchatstring, int player)
        {
            int targetteam = Convert.ToInt32(splitchatstring[2]);

            if (targetteam == csai.Team)
            {
                double x = Convert.ToDouble(splitchatstring[3]);
                double z = Convert.ToDouble(splitchatstring[4]);
                double y = aicallback.GetElevation(x, z);
                aicallback.SendTextMsg("moving commander to " + x + "," + y + "," + z, 0);
                logfile.WriteLine("moving commander to " + x + "," + y + "," + z);
                aicallback.GiveOrder(commanderid, new Command(Command.CMD_MOVE, new double[] { x, y, z }));
            }
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
        void ExploreWith(int unitid)
        {
            Float3 destination = new Float3();

            if (PriorityTargets.Count > 0)
            {
                destination = PriorityTargets.Dequeue() as Float3;
                logfile.WriteLine("dequeued next destination: " + destination.ToString());
            }
            else
            {
                destination.x = random.Next(0, aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE);
                destination.z = random.Next(0, aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE);
                destination.y = aicallback.GetElevation(destination.x, destination.y);
                logfile.WriteLine("mapwidth: " + aicallback.GetMapWidth() + " squaresize: " + MovementMaps.SQUARE_SIZE);
                logfile.WriteLine("ScoutController sending scout " + unitid + " to " + destination.ToString());
            }
            aicallback.GiveOrder(unitid, new Command(Command.CMD_MOVE, destination.ToDoubleArray()));
        }
Exemplo n.º 5
0
 // kills all except commander, allows testing expansion from nothing, without having to relaod spring.exe
 void VoiceCommandKillAllFriendly(string cmd, string[] splitcmd, int player)
 {
     foreach (DictionaryEntry de in UnitDefByDeployedId)
     {
         int      id      = (int)de.Key;
         IUnitDef unitdef = de.Value as IUnitDef;
         if (!unitdef.isCommander)
         {
             aicallback.GiveOrder(id, new Command(Command.CMD_SELFD));
         }
     }
 }
Exemplo n.º 6
0
        public void UnitCreated(int unit)
        {
            aicallback.SendTextMsg("Unit created: " + unit, 0);

            IUnitDef unitdef = aicallback.GetUnitDef(unit);

            aicallback.SendTextMsg("Unit created: " + unitdef.name, 0);

            IMoveData movedata = unitdef.movedata;

            if (movedata != null)
            {
                aicallback.SendTextMsg("Max Slope: " + movedata.maxSlope, 0);
            }

            if (unitdef.isCommander)
            {
                int    numbuildoptions    = unitdef.GetNumBuildOptions();
                string buildoptionsstring = "Build options: ";
                for (int i = 0; i < numbuildoptions; i++)
                {
                    buildoptionsstring += unitdef.GetBuildOption(i);
                }
                aicallback.SendTextMsg(buildoptionsstring, 0);

                Float3 commanderpos = aicallback.GetUnitPos(unit);
                aicallback.SendTextMsg("Commanderpos: " + commanderpos.ToString(), 0);

                int numunitdefs = aicallback.GetNumUnitDefs();
                aicallback.SendTextMsg("Num unit defs: " + numunitdefs, 0);

                for (int i = 1; i <= numunitdefs; i++)
                {
                    IUnitDef thisunitdef = aicallback.GetUnitDefByTypeId(i);
                    if (thisunitdef.name == "ARMSOLAR")
                    {
                        aicallback.SendTextMsg("Found solar collector def: " + thisunitdef.id, 0);

                        Float3 nearestbuildpos = aicallback.ClosestBuildSite(thisunitdef, commanderpos, 1400, 2);
                        aicallback.SendTextMsg("Closest build site: " + nearestbuildpos.ToString(), 0);

                        aicallback.DrawUnit("ARMSOLAR", nearestbuildpos, 0,
                                            200, aicallback.GetMyAllyTeam(), true, true);

                        aicallback.GiveOrder(unit, new Command(-thisunitdef.id, nearestbuildpos.ToDoubleArray()));
                    }
                }
            }
        }
Exemplo n.º 7
0
        void ExploreWith(int unitid)
        {
            bool         destinationfound = false;
            Float3       currentpos       = aicallback.GetUnitPos(unitid);
            MovementMaps movementmaps     = MovementMaps.GetInstance();
            IUnitDef     unitdef          = UnitDefListByDeployedId[unitid] as IUnitDef;
            int          currentarea      = movementmaps.GetArea(unitdef, currentpos);
            LosMap       losmap           = LosMap.GetInstance();

            if (csai.DebugOn)
            {
                logfile.WriteLine("explorewith unit " + unitid + " " + unitdef.humanName + " area: " + currentarea);
            }

            /*
             * int numtriesleft = 30; // just try a few times then give up
             * // maybe there is a better way to do this?
             * while( !destinationfound )
             * {
             *  Float3 destination = GetRandomDestination();
             * // logfile.WriteLine( "SpreadSearchWithSearchGrid attempt " + destination.ToString() );
             *  int mapx = (int)( destination.x / 16 );
             *  int mapy = (int)( destination.z / 16 );
             *  if( ( movementmaps.GetArea( unitdef, destination ) == currentarea &&
             *      losmap.LastSeenFrameCount[ mapx, mapy ] < recentmeansnumframes || numtriesleft <= 0 ) )
             *  {
             *      logfile.WriteLine( "Looks good. Go. " + numtriesleft + " retriesleft" );
             *      if( csai.DebugOn )
             *      {
             *          aicallback.CreateLineFigure( currentpos, destination,10,true,400,0);
             *          aicallback.DrawUnit( "ARMFAV", destination, 0.0f, 400, aicallback.GetMyAllyTeam(), true, true);
             *      }
             *      aicallback.GiveOrder( unitid, new Command( Command.CMD_MOVE, destination.ToDoubleArray() ) );
             *      return;
             *  }
             *  numtriesleft--;
             * }
             */
            // find nearest, area that hasnt had los recently
            //int maxradius = Math.Max( aicallback.GetMapWidth(), aicallback.GetMapHeight() ) / 2;
            //for( int radius =
            Float3 nextpoint = LosMap.GetInstance().GetNearestUnseen(currentpos, unitdef, 6000);

            if (nextpoint == null)
            {
                nextpoint = GetRandomDestination();
            }
            aicallback.GiveOrder(unitid, new Command(Command.CMD_MOVE, nextpoint.ToDoubleArray()));
        }
Exemplo n.º 8
0
 void GiveOrder(OOPCommand command)
 {
     UnitCommandCache.GetInstance().RegisterCommand(command.UnitToReceiveOrder, command);
     logfile.WriteLine("GiveOrder " + command.ToString());
     lock (recentcommands)
     {
         TimeSpan gametime = TimeHelper.GetGameTime();
         recentcommands.Add(new CommandInfo(gametime, command));
         allcommands.Add(new CommandInfo(gametime, command));
     }
     if (aicallback.GiveOrder(command.UnitToReceiveOrder, command.ToSpringCommand()) == -1)
     {
         throw new Exception("GiveOrder failed");
     }
 }
 void MoveTo(Float3 pos)
 {
     // check whether we really need to do anything or if order is roughly same as last one
     if (csai.DebugOn)
     {
         aicallback.DrawUnit("ARMSOLAR", pos, 0.0f, 50, aicallback.GetMyAllyTeam(), true, true);
     }
     if (restartedfrompause || Float3Helper.GetSquaredDistance(pos, lasttargetpos) > (movetothreshold * movetothreshold))
     {
         foreach (DictionaryEntry de in UnitDefListByDeployedId)
         {
             int      deployedid = (int)de.Key;
             IUnitDef unitdef    = de.Value as IUnitDef;
             aicallback.GiveOrder(deployedid, new Command(Command.CMD_MOVE, pos.ToDoubleArray()));
         }
         restartedfrompause = false;
         lasttargetpos      = pos;
     }
 }
Exemplo n.º 10
0
        void ExploreWith(int unitid)
        {
            Float3 destination = GetRandomDestination();

            aicallback.GiveOrder(unitid, new Command(Command.CMD_MOVE, destination.ToDoubleArray()));
        }
Exemplo n.º 11
0
 void SetGuard(int unitid)
 {
     aicallback.GiveOrder(unitid, new Command(Command.CMD_GUARD, new double[] { targetid }));
 }
Exemplo n.º 12
0
 void Move(int unitid)
 {
     aicallback.GiveOrder(unitid, new Command(Command.CMD_MOVE, targetpos.ToDoubleArray()));
 }