Exemplo n.º 1
0
        void GenerateBoatAccessibleMap()
        {
            logfile.WriteLine("GenerateBoatAccessibleMap");
            boatmap = new bool[mapwidth / 2, mapheight / 2];
            for (int y = 0; y < mapheight / 2; y++)
            {
                for (int x = 0; x < mapwidth / 2; x++)
                {
                    boatmap[x, y] = true;
                }
            }

            ArrayIndexer arrayindexer = new ArrayIndexer(mapwidth, mapheight);

            for (int y = 0; y < mapheight; y++)
            {
                for (int x = 0; x < mapwidth; x++)
                {
                    if (heightmap[arrayindexer.GetIndex(x, y)] > 0)
                    {
                        boatmap[x / 2, y / 2] = false;
                    }
                }
            }
        }
Exemplo n.º 2
0
 public override IExpression Visit(ArrayIndexer arrayIndexer)
 {
     arrayIndexer.Indices       = this.Visit(arrayIndexer.Indices);
     arrayIndexer.IndexedObject = this.Visit(arrayIndexer.IndexedObject);
     arrayIndexer.Type          = this.Visit(arrayIndexer.Type);
     return(arrayIndexer);
 }
Exemplo n.º 3
0
        public void DumpCentreHeights(string cmd, string[] cmdsplit, int player)
        {
            logfile.WriteLine("calling GetCentreHeightMap...");
            double[] thismap = aicallback.GetCentreHeightMap();
            logfile.WriteLine("...done");
            int width  = aicallback.GetMapWidth();
            int height = aicallback.GetMapHeight();

            logfile.WriteLine("CentreHeightmap width: " + width + " losheight: " + height);
            ArrayIndexer arrayindexer = new ArrayIndexer(width, height);

            for (int y = 0; y < height; y += 64)
            {
                string line = "";
                for (int x = 0; x < width; x += 64)
                {
                    if (thismap[arrayindexer.GetIndex(x, y)] > 0)
                    {
                        // aicallback.DrawUnit( "ARMRAD", new Float3( x * 64, 0, y * 64 ), 0.0f, 100, aicallback.GetMyAllyTeam(), true, true);
                        line += "*";
                    }
                    else
                    {
                        line += "-";
                    }
                }
                logfile.WriteLine(line);
            }
            aicallback.SendTextMsg("Height dumped to logfile", 0);
        }
Exemplo n.º 4
0
 public void DumpCentreHeights( string cmd, string[]cmdsplit, int player )
 {
     logfile.WriteLine( "calling GetCentreHeightMap..." );
     double[] thismap = aicallback.GetCentreHeightMap();
     logfile.WriteLine( "...done" );
     int width = aicallback.GetMapWidth();
     int height = aicallback.GetMapHeight();
     logfile.WriteLine( "CentreHeightmap width: " + width + " losheight: " + height );
     ArrayIndexer arrayindexer = new ArrayIndexer( width, height );
     for( int y = 0; y < height; y+= 64 )
     {
         string line = "";
         for( int x = 0; x < width; x+= 64 )
         {
             if( thismap[ arrayindexer.GetIndex( x, y ) ] > 0 )
             {
                // aicallback.DrawUnit( "ARMRAD", new Float3( x * 64, 0, y * 64 ), 0.0f, 100, aicallback.GetMyAllyTeam(), true, true);
                 line += "*";
             }
             else
             {
                 line += "-";
             }
         }
         logfile.WriteLine( line );
     }
     aicallback.SendTextMsg("Height dumped to logfile", 0 );
 }
Exemplo n.º 5
0
        public void DumpRadar(string cmd, string[] cmdsplit, int player)
        {
            logfile.WriteLine("calling GetRadarMap...");
            bool[] LosMap = aicallback.GetRadarMap();
            logfile.WriteLine("...done");
            int loswidth  = aicallback.GetMapWidth() / 8;
            int losheight = aicallback.GetMapHeight() / 8;

            logfile.WriteLine("losmap width: " + loswidth + " losheight: " + losheight);
            ArrayIndexer arrayindexer = new ArrayIndexer(loswidth, losheight);

            for (int y = 0; y < losheight; y++)
            {
                string line = "";
                for (int x = 0; x < loswidth; x++)
                {
                    if (LosMap[arrayindexer.GetIndex(x, y)])
                    {
                        aicallback.DrawUnit("ARMRAD", new Float3(x * 64, 0, y * 64), 0.0f, 100, aicallback.GetMyAllyTeam(), true, true);
                        line += "*";
                    }
                    else
                    {
                        line += "-";
                    }
                }
                logfile.WriteLine(line);
            }
            aicallback.SendTextMsg("radar dumped to logfile", 0);
        }
Exemplo n.º 6
0
        public override List <IProperty> GetProperties()
        {
            List <IProperty> l        = base.GetProperties();
            ArrayIndexer     property = new ArrayIndexer(elementType, this.BaseType.GetUnderlyingClass());
            IReturnType      int32    = pc.SystemTypes.Int32;

            for (int i = 0; i < dimensions; ++i)
            {
                property.Parameters.Add(new DefaultParameter("index", int32, DomRegion.Empty));
            }
            l.Add(property);
            return(l);
        }
        /// <summary>
        /// Constructs the indexed array given a 1-dimensional array and the n-dimensional bounds.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="bounds"></param>
        public IndexableArray(T[] array, params int[] bounds)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }
            if (bounds.Aggregate(1, (x, y) => x * y) != array.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(bounds), "There array length does not match the bounds");
            }

            Array    = array;
            _indexer = new ArrayIndexer(bounds);
        }
        /// <summary>
        /// Restores target from source. Can be used for read-only properties when source object is already fully serialized.
        /// </summary>
        private static void CopyContent(object source, object target)
        {
            Debug.Assert(target != null && source != null && target.GetType() == source.GetType(), $"Same types are expected in {nameof(CopyContent)}.");

            // 1.) Array
            if (target is Array targetArray && source is Array sourceArray)
            {
                int[] lengths     = new int[sourceArray.Rank];
                int[] lowerBounds = new int[sourceArray.Rank];
                for (int i = 0; i < sourceArray.Rank; i++)
                {
                    lengths[i]     = sourceArray.GetLength(i);
                    lowerBounds[i] = sourceArray.GetLowerBound(i);
                }

                CheckArray(targetArray, lengths, lowerBounds, true);
                if (targetArray.GetType().GetElementType()?.IsPrimitive == true)
                {
                    Buffer.BlockCopy(sourceArray, 0, targetArray, 0, Buffer.ByteLength(sourceArray));
                }
                else if (lengths.Length == 1)
                {
                    Array.Copy(sourceArray, targetArray, sourceArray.Length);
                }
                else
                {
                    var indices = new ArrayIndexer(lengths, lowerBounds);
                    while (indices.MoveNext())
                    {
                        targetArray.SetValue(sourceArray.GetValue(indices.Current), indices.Current);
                    }
                }

                return;
            }

            // 2.) non-array: every fields (here we don't know how was the instance serialized but we have a deserialized source)
            SerializationHelper.CopyFields(source, target);
        }
Exemplo n.º 9
0
        // algorithm more or less by krogothe
        // ported from Submarine's original C++ version
        public void SearchMetalSpots()
        {	
            logfile.WriteLine( "SearchMetalSpots() >>>");
            
            isMetalMap = false;
        
            ArrayList metalspotsal = new ArrayList();
            
            int mapheight = aicallback.GetMapHeight() / 2; //metal map has 1/2 resolution of normal map
            int mapwidth = aicallback.GetMapWidth() / 2;
            double mapmaxmetal = aicallback.GetMaxMetal();
            int totalcells = mapheight * mapwidth;
            
            logfile.WriteLine( "mapwidth: " + mapwidth + " mapheight " + mapheight + " maxmetal:" + mapmaxmetal );
            
            byte[] metalmap = aicallback.GetMetalMap(); // original metal map
            int[,] metalremaining = new int[ mapwidth, mapheight ];  // actual metal available at that point. we remove metal from this as we add spots to MetalSpots
            int[,] SpotAvailableMetal = new int [ mapwidth, mapheight ]; // amount of metal an extractor on this spot could make
            int[,] NormalizedSpotAvailableMetal = new int [ mapwidth, mapheight ]; // SpotAvailableMetal, normalized to 0-255 range
        
            int totalmetal = 0;
            ArrayIndexer arrayindexer = new ArrayIndexer( mapwidth, mapheight );
            //Load up the metal Values in each pixel
            logfile.WriteLine( "width: " + mapwidth + " height: " + mapheight );
            for (int y = 0; y < mapheight; y++)
            {
                //string logline = "";
                for( int x = 0; x < mapwidth; x++ )
                {
                    metalremaining[ x, y ] = (int)metalmap[ arrayindexer.GetIndex( x, y ) ];
                    totalmetal += metalremaining[ x, y ];		// Count the total metal so you can work out an average of the whole map
                    //logline += metalremaining[ x, y ].ToString() + " ";
                  //  logline += metalremaining[ x, y ] + " ";
                }
               // logfile.WriteLine( logline );
            }
            logfile.WriteLine ("*******************************************");
        
            double averagemetal = ((double)totalmetal) / ((double)totalcells);  //do the average
           // int maxmetal = 0;

            int ExtractorRadius = (int)( aicallback.GetExtractorRadius() / 16.0 );
            int DoubleExtractorRadius = ExtractorRadius * 2;
            int SquareExtractorRadius = ExtractorRadius * ExtractorRadius; //used to speed up loops so no recalculation needed
            int FourSquareExtractorRadius = 4 * SquareExtractorRadius; // same as above 
            double CellsInRadius = Math.PI * ExtractorRadius * ExtractorRadius;
            
            int maxmetalspotamount = 0;
            logfile.WriteLine( "Calculating available metal for each spot..." );
            SpotAvailableMetal = CalculateAvailableMetalForEachSpot( metalremaining, ExtractorRadius, out maxmetalspotamount );
            
            logfile.WriteLine( "Normalizing..." );
            // normalize the metal so any map will have values 0-255, no matter how much metal it has
            int[,] NormalizedMetalRemaining = new int[ mapwidth, mapheight ];
            for (int y = 0; y < mapheight; y++)
            {
                for (int x = 0; x < mapwidth; x++)
                {
                    NormalizedSpotAvailableMetal[ x, y ] = ( SpotAvailableMetal[ x, y ] * 255 ) / maxmetalspotamount;
                }
            }
            
            logfile.WriteLine( "maxmetalspotamount: " + maxmetalspotamount );
            
            bool Stopme = false;
            int SpotsFound = 0;
            //logfile.WriteLine( BuildTable.GetInstance().GetBiggestMexUnit().ToString() );
           // IUnitDef biggestmex = BuildTable.GetInstance().GetBiggestMexUnit();
           // logfile.WriteLine( "biggestmex is " + biggestmex.name + " " + biggestmex.humanName );
            for (int spotindex = 0; spotindex < MaxSpots && !Stopme; spotindex++)
            {	                
                logfile.WriteLine( "spotindex: " + spotindex );
                int bestspotx = 0, bestspoty = 0;
                int actualmetalatbestspot = 0; // use to try to put extractors over spot itself
                //finds the best spot on the map and gets its coords
                int BestNormalizedAvailableSpotAmount = 0;
                for (int y = 0; y < mapheight; y++)
                {
                    for (int x = 0; x < mapwidth; x++)
                    {
                        if( NormalizedSpotAvailableMetal[ x, y ] > BestNormalizedAvailableSpotAmount ||
                            ( NormalizedSpotAvailableMetal[ x, y ] == BestNormalizedAvailableSpotAmount && 
                            metalremaining[ x, y ] > actualmetalatbestspot ) )
                        {
                            BestNormalizedAvailableSpotAmount = NormalizedSpotAvailableMetal[ x, y ];
                            bestspotx = x;
                            bestspoty = y;
                            actualmetalatbestspot = metalremaining[ x, y ];
                        }
                    }
                }		
                logfile.WriteLine( "BestNormalizedAvailableSpotAmount: " + BestNormalizedAvailableSpotAmount );                
                if( BestNormalizedAvailableSpotAmount < MinMetalForSpot )
                {
                    Stopme = true; // if the spots get too crappy it will stop running the loops to speed it all up
                    logfile.WriteLine( "Remaining spots too small; stopping search" );
                }
        
                if( !Stopme )
                {
                    Float3 pos = new Float3();
                    pos.x = bestspotx * 2 * MovementMaps.SQUARE_SIZE;
                    pos.z = bestspoty * 2 * MovementMaps.SQUARE_SIZE;
                    pos.y = aicallback.GetElevation( pos.x, pos.z );
                    
                    //pos = Map.PosToFinalBuildPos( pos, biggestmex );
                
                    logfile.WriteLine( "Metal spot: " + pos + " " + BestNormalizedAvailableSpotAmount );
                    MetalSpot thismetalspot = new MetalSpot( (int)( ( BestNormalizedAvailableSpotAmount  * mapmaxmetal * maxmetalspotamount ) / 255 ), pos );
                    
                //    if (aicallback.CanBuildAt(biggestmex, pos) )
                  //  {
                       // pos = Map.PosToBuildMapPos( pos, biggestmex );
                       // logfile.WriteLine( "Metal spot: " + pos + " " + BestNormalizedAvailableSpotAmount );
                        
                   //     if(pos.z >= 2 && pos.x >= 2 && pos.x < mapwidth -2 && pos.z < mapheight -2)
                  //      {
                          //  if(CanBuildAt(pos.x, pos.z, biggestmex.xsize, biggestmex.ysize))
                           // {
                                metalspotsal.Add( thismetalspot );			
                                SpotsFound++;
        
                                //if(pos.y >= 0)
                                //{
                                   // SetBuildMap(pos.x-2, pos.z-2, biggestmex.xsize+4, biggestmex.ysize+4, 1);
                                //}
                                //else
                                //{
                                    //SetBuildMap(pos.x-2, pos.z-2, biggestmex.xsize+4, biggestmex.ysize+4, 5);
                                //}
                          //  }
                     //   }
                 //   }
                        
                    for (int myx = bestspotx - (int)ExtractorRadius; myx < bestspotx + (int)ExtractorRadius; myx++)
                    {
                        if (myx >= 0 && myx < mapwidth )
                        {
                            for (int myy = bestspoty - (int)ExtractorRadius; myy < bestspoty + (int)ExtractorRadius; myy++)
                            {
                                if ( myy >= 0 && myy < mapheight &&
                                    ( ( bestspotx - myx ) * ( bestspotx - myx ) + ( bestspoty - myy ) * ( bestspoty - myy ) ) <= (int)SquareExtractorRadius )
                                {
                                    metalremaining[ myx, myy ] = 0; //wipes the metal around the spot so its not counted twice
                                    NormalizedSpotAvailableMetal[ myx, myy ] = 0;
                                }
                            }
                        }
                    }
        
                    // Redo the whole averaging process around the picked spot so other spots can be found around it
                    for (int y = bestspoty - (int)DoubleExtractorRadius; y < bestspoty + (int)DoubleExtractorRadius; y++)
                    {
                        if(y >=0 && y < mapheight)
                        {
                            for (int x = bestspotx - (int)DoubleExtractorRadius; x < bestspotx + (int)DoubleExtractorRadius; x++)
                            {
                                //funcion below is optimized so it will only update spots between r and 2r, greatly speeding it up
                                if((bestspotx - x)*(bestspotx - x) + (bestspoty - y)*(bestspoty - y) <= (int)FourSquareExtractorRadius && 
                                    x >=0 && x < mapwidth && 
                                    NormalizedSpotAvailableMetal[ x, y ] > 0 )
                                {
                                    totalmetal = 0;
                                    for (int myx = x - (int)ExtractorRadius; myx < x + (int)ExtractorRadius; myx++)
                                    {
                                        if (myx >= 0 && myx < mapwidth )
                                        {
                                            for (int myy = y - (int)ExtractorRadius; myy < y + (int)ExtractorRadius; myy++)
                                            { 
                                                if (myy >= 0 && myy < mapheight && 
                                                    ((x - myx)*(x - myx) + (y - myy)*(y - myy)) <= (int)SquareExtractorRadius )
                                                {
                                                    totalmetal += metalremaining[ myx, myy ]; //recalculate nearby spots to account for deleted metal from chosen spot
                                                }
                                            }
                                        }
                                    }
                                    NormalizedSpotAvailableMetal[ x, y ] = totalmetal * 255 / maxmetalspotamount; //set that spots metal amount 
                                }
                            }
                        }
                    }
                }
            }
        
            if(SpotsFound > 500)
            {
                isMetalMap = true;
                metalspotsal.Clear();
                logfile.WriteLine( "Map is considered to be a metal map" );
            }
            else
            {
                isMetalMap = false;
        
                // debug
                //for(list<AAIMetalSpot>::iterator spot = metal_spots.begin(); spot != metal_spots.end(); spot++)
            }
            
            MetalSpots = ( MetalSpot[] )metalspotsal.ToArray( typeof( MetalSpot ) );
            
            SaveCache();
            logfile.WriteLine( "SearchMetalSpots() <<<");
        }
Exemplo n.º 10
0
        public bool Serialize(Type _Type, object _Object, out byte[] _Bytes)
        {
            if (!_Type.IsArray)
            {
                _Bytes = null;
                return(false);
            }

            ByteWriter var_Writer = new ByteWriter();

            if (_Object == null)
            {
                var_Writer.Write((bool)true);
                _Bytes = var_Writer.ToArray();
                return(true);
            }
            else
            {
                var_Writer.Write((bool)false);
            }

            //

            Array var_Array = _Object as Array;

            Type var_ElementType = _Type.GetElementType();

            //Write dimensions!
            var_Writer.Write((int)var_Array.Rank);
            //Go through each dimension and write the length!
            int[] var_ArrayLength = new int[var_Array.Rank];
            for (int d = 0; d < var_Array.Rank; d++)
            {
                var_ArrayLength[d] = (int)var_Array.GetLength(d);
                var_Writer.Write((int)var_Array.GetLength(d));
            }
            //Go through each dimension and write the lowerbound!
            int[] var_ArrayLowerBound = new int[var_Array.Rank];
            for (int d = 0; d < var_Array.Rank; d++)
            {
                var_ArrayLowerBound[d] = (int)var_Array.GetLowerBound(d);
                var_Writer.Write((int)var_Array.GetLowerBound(d));
            }

            ArrayIndexer arrayIndexer = new ArrayIndexer(var_ArrayLength, var_ArrayLowerBound);

            if (PrimitiveTypeMatcher.TypeDictionary.ContainsKey(var_ElementType))
            {
                while (arrayIndexer.MoveNext())
                {
                    var_Writer.Write(var_ElementType, var_Array.GetValue(arrayIndexer.Current));
                }
            }
            else
            {
                while (arrayIndexer.MoveNext())
                {
                    byte[] var_Bytes = Serializer.Internal_Serialize(var_ElementType, var_Array.GetValue(arrayIndexer.Current));
                    var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
                }
            }

            _Bytes = var_Writer.ToArray();
            return(true);
        }
Exemplo n.º 11
0
        public bool DeSerialize(Type _Type, byte[] _Bytes, out object _Object)
        {
            if (!_Type.IsArray)
            {
                _Object = null;
                return(false);
            }

            ByteReader var_Reader = new ByteReader(_Bytes);

            bool var_IsNull = var_Reader.ReadBoolean();

            if (var_IsNull)
            {
                _Object = null;
                return(true);
            }

            //

            Type var_ElementType = _Type.GetElementType();

            //Read dimensions
            int var_Dimensions = var_Reader.ReadInt32();

            //Go through each dimension and read the length!
            int[] var_ArrayLength = new int[var_Dimensions];
            for (int d = 0; d < var_Dimensions; d++)
            {
                var_ArrayLength[d] = var_Reader.ReadInt32();
            }

            //Go through each dimension and read the lowerbound!
            int[] var_ArrayLowerBound = new int[var_Dimensions];
            for (int d = 0; d < var_Dimensions; d++)
            {
                var_ArrayLowerBound[d] = var_Reader.ReadInt32();
            }

            var var_Array = Array.CreateInstance(var_ElementType, var_ArrayLength);

            ArrayIndexer arrayIndexer = new ArrayIndexer(var_ArrayLength, var_ArrayLowerBound);

            if (PrimitiveTypeMatcher.TypeDictionary.ContainsKey(var_ElementType))
            {
                while (arrayIndexer.MoveNext())
                {
                    var_Array.SetValue(var_Reader.Read(var_ElementType), arrayIndexer.Current);
                }
            }
            else
            {
                while (arrayIndexer.MoveNext())
                {
                    byte[] var_Bytes = var_Reader.ReadBytesAndSize();
                    Object var_Item  = Serializer.DeSerialize(_Type.GetElementType(), var_Bytes);
                    var_Array.SetValue(var_Item, arrayIndexer.Current);
                }
            }

            _Object = var_Array;
            return(true);
        }
Exemplo n.º 12
0
        // algorithm more or less by krogothe
        // ported from Submarine's original C++ version
        public void SearchMetalSpots()
        {
            logfile.WriteLine("SearchMetalSpots() >>>");

            isMetalMap = false;

            ArrayList metalspotsal = new ArrayList();

            int    mapheight   = aicallback.GetMapHeight() / 2; //metal map has 1/2 resolution of normal map
            int    mapwidth    = aicallback.GetMapWidth() / 2;
            double mapmaxmetal = aicallback.GetMaxMetal();
            int    totalcells  = mapheight * mapwidth;

            logfile.WriteLine("mapwidth: " + mapwidth + " mapheight " + mapheight + " maxmetal:" + mapmaxmetal);

            byte[] metalmap = aicallback.GetMetalMap();                          // original metal map
            int[,] metalremaining               = new int[mapwidth, mapheight];  // actual metal available at that point. we remove metal from this as we add spots to MetalSpots
            int[,] SpotAvailableMetal           = new int [mapwidth, mapheight]; // amount of metal an extractor on this spot could make
            int[,] NormalizedSpotAvailableMetal = new int [mapwidth, mapheight]; // SpotAvailableMetal, normalized to 0-255 range

            int          totalmetal   = 0;
            ArrayIndexer arrayindexer = new ArrayIndexer(mapwidth, mapheight);

            //Load up the metal Values in each pixel
            logfile.WriteLine("width: " + mapwidth + " height: " + mapheight);
            for (int y = 0; y < mapheight; y++)
            {
                //string logline = "";
                for (int x = 0; x < mapwidth; x++)
                {
                    metalremaining[x, y] = (int)metalmap[arrayindexer.GetIndex(x, y)];
                    totalmetal          += metalremaining[x, y];        // Count the total metal so you can work out an average of the whole map
                    //logline += metalremaining[ x, y ].ToString() + " ";
                    //  logline += metalremaining[ x, y ] + " ";
                }
                // logfile.WriteLine( logline );
            }
            logfile.WriteLine("*******************************************");

            double averagemetal = ((double)totalmetal) / ((double)totalcells);  //do the average
            // int maxmetal = 0;

            int    ExtractorRadius           = (int)(aicallback.GetExtractorRadius() / 16.0);
            int    DoubleExtractorRadius     = ExtractorRadius * 2;
            int    SquareExtractorRadius     = ExtractorRadius * ExtractorRadius; //used to speed up loops so no recalculation needed
            int    FourSquareExtractorRadius = 4 * SquareExtractorRadius;         // same as above
            double CellsInRadius             = Math.PI * ExtractorRadius * ExtractorRadius;

            int maxmetalspotamount = 0;

            logfile.WriteLine("Calculating available metal for each spot...");
            SpotAvailableMetal = CalculateAvailableMetalForEachSpot(metalremaining, ExtractorRadius, out maxmetalspotamount);

            logfile.WriteLine("Normalizing...");
            // normalize the metal so any map will have values 0-255, no matter how much metal it has
            int[,] NormalizedMetalRemaining = new int[mapwidth, mapheight];
            for (int y = 0; y < mapheight; y++)
            {
                for (int x = 0; x < mapwidth; x++)
                {
                    NormalizedSpotAvailableMetal[x, y] = (SpotAvailableMetal[x, y] * 255) / maxmetalspotamount;
                }
            }

            logfile.WriteLine("maxmetalspotamount: " + maxmetalspotamount);

            bool Stopme     = false;
            int  SpotsFound = 0;

            //logfile.WriteLine( BuildTable.GetInstance().GetBiggestMexUnit().ToString() );
            // IUnitDef biggestmex = BuildTable.GetInstance().GetBiggestMexUnit();
            // logfile.WriteLine( "biggestmex is " + biggestmex.name + " " + biggestmex.humanName );
            for (int spotindex = 0; spotindex < MaxSpots && !Stopme; spotindex++)
            {
                logfile.WriteLine("spotindex: " + spotindex);
                int bestspotx = 0, bestspoty = 0;
                int actualmetalatbestspot = 0; // use to try to put extractors over spot itself
                //finds the best spot on the map and gets its coords
                int BestNormalizedAvailableSpotAmount = 0;
                for (int y = 0; y < mapheight; y++)
                {
                    for (int x = 0; x < mapwidth; x++)
                    {
                        if (NormalizedSpotAvailableMetal[x, y] > BestNormalizedAvailableSpotAmount ||
                            (NormalizedSpotAvailableMetal[x, y] == BestNormalizedAvailableSpotAmount &&
                             metalremaining[x, y] > actualmetalatbestspot))
                        {
                            BestNormalizedAvailableSpotAmount = NormalizedSpotAvailableMetal[x, y];
                            bestspotx             = x;
                            bestspoty             = y;
                            actualmetalatbestspot = metalremaining[x, y];
                        }
                    }
                }
                logfile.WriteLine("BestNormalizedAvailableSpotAmount: " + BestNormalizedAvailableSpotAmount);
                if (BestNormalizedAvailableSpotAmount < MinMetalForSpot)
                {
                    Stopme = true; // if the spots get too crappy it will stop running the loops to speed it all up
                    logfile.WriteLine("Remaining spots too small; stopping search");
                }

                if (!Stopme)
                {
                    Float3 pos = new Float3();
                    pos.x = bestspotx * 2 * MovementMaps.SQUARE_SIZE;
                    pos.z = bestspoty * 2 * MovementMaps.SQUARE_SIZE;
                    pos.y = aicallback.GetElevation(pos.x, pos.z);

                    //pos = Map.PosToFinalBuildPos( pos, biggestmex );

                    logfile.WriteLine("Metal spot: " + pos + " " + BestNormalizedAvailableSpotAmount);
                    MetalSpot thismetalspot = new MetalSpot((int)((BestNormalizedAvailableSpotAmount * mapmaxmetal * maxmetalspotamount) / 255), pos);

                    //    if (aicallback.CanBuildAt(biggestmex, pos) )
                    //  {
                    // pos = Map.PosToBuildMapPos( pos, biggestmex );
                    // logfile.WriteLine( "Metal spot: " + pos + " " + BestNormalizedAvailableSpotAmount );

                    //     if(pos.z >= 2 && pos.x >= 2 && pos.x < mapwidth -2 && pos.z < mapheight -2)
                    //      {
                    //  if(CanBuildAt(pos.x, pos.z, biggestmex.xsize, biggestmex.ysize))
                    // {
                    metalspotsal.Add(thismetalspot);
                    SpotsFound++;

                    //if(pos.y >= 0)
                    //{
                    // SetBuildMap(pos.x-2, pos.z-2, biggestmex.xsize+4, biggestmex.ysize+4, 1);
                    //}
                    //else
                    //{
                    //SetBuildMap(pos.x-2, pos.z-2, biggestmex.xsize+4, biggestmex.ysize+4, 5);
                    //}
                    //  }
                    //   }
                    //   }

                    for (int myx = bestspotx - (int)ExtractorRadius; myx < bestspotx + (int)ExtractorRadius; myx++)
                    {
                        if (myx >= 0 && myx < mapwidth)
                        {
                            for (int myy = bestspoty - (int)ExtractorRadius; myy < bestspoty + (int)ExtractorRadius; myy++)
                            {
                                if (myy >= 0 && myy < mapheight &&
                                    ((bestspotx - myx) * (bestspotx - myx) + (bestspoty - myy) * (bestspoty - myy)) <= (int)SquareExtractorRadius)
                                {
                                    metalremaining[myx, myy] = 0;   //wipes the metal around the spot so its not counted twice
                                    NormalizedSpotAvailableMetal[myx, myy] = 0;
                                }
                            }
                        }
                    }

                    // Redo the whole averaging process around the picked spot so other spots can be found around it
                    for (int y = bestspoty - (int)DoubleExtractorRadius; y < bestspoty + (int)DoubleExtractorRadius; y++)
                    {
                        if (y >= 0 && y < mapheight)
                        {
                            for (int x = bestspotx - (int)DoubleExtractorRadius; x < bestspotx + (int)DoubleExtractorRadius; x++)
                            {
                                //funcion below is optimized so it will only update spots between r and 2r, greatly speeding it up
                                if ((bestspotx - x) * (bestspotx - x) + (bestspoty - y) * (bestspoty - y) <= (int)FourSquareExtractorRadius &&
                                    x >= 0 && x < mapwidth &&
                                    NormalizedSpotAvailableMetal[x, y] > 0)
                                {
                                    totalmetal = 0;
                                    for (int myx = x - (int)ExtractorRadius; myx < x + (int)ExtractorRadius; myx++)
                                    {
                                        if (myx >= 0 && myx < mapwidth)
                                        {
                                            for (int myy = y - (int)ExtractorRadius; myy < y + (int)ExtractorRadius; myy++)
                                            {
                                                if (myy >= 0 && myy < mapheight &&
                                                    ((x - myx) * (x - myx) + (y - myy) * (y - myy)) <= (int)SquareExtractorRadius)
                                                {
                                                    totalmetal += metalremaining[myx, myy];   //recalculate nearby spots to account for deleted metal from chosen spot
                                                }
                                            }
                                        }
                                    }
                                    NormalizedSpotAvailableMetal[x, y] = totalmetal * 255 / maxmetalspotamount;   //set that spots metal amount
                                }
                            }
                        }
                    }
                }
            }

            if (SpotsFound > 500)
            {
                isMetalMap = true;
                metalspotsal.Clear();
                logfile.WriteLine("Map is considered to be a metal map");
            }
            else
            {
                isMetalMap = false;

                // debug
                //for(list<AAIMetalSpot>::iterator spot = metal_spots.begin(); spot != metal_spots.end(); spot++)
            }

            MetalSpots = ( MetalSpot[] )metalspotsal.ToArray(typeof(MetalSpot));

            SaveCache();
            logfile.WriteLine("SearchMetalSpots() <<<");
        }
Exemplo n.º 13
0
        void GenerateVehicleAccessibleMap()
        {
            logfile.WriteLine( "GenerateVehicleAccessibleMap" );
            vehiclemap = new bool[ mapwidth / 2, mapheight / 2 ];
            for( int y = 0; y < mapheight / 2; y++ )
            {
                for( int x = 0; x < mapwidth / 2; x++ )
                {
                    vehiclemap[ x , y ] = true;
                }
            }

            ArrayIndexer arrayindexer = new ArrayIndexer( mapwidth, mapheight );
            for( int y = 0; y < mapheight; y++ )
            {
                for( int x = 0; x < mapwidth; x++ )
                {
                    if( slopemap[ x/ 2, y / 2 ] > 0.08 )
                    {
                        vehiclemap[ x /2, y / 2 ] = false;
                    }
                    if( heightmap[ arrayindexer.GetIndex( x, y ) ] < 0 )
                    {
                        vehiclemap[ x /2, y / 2 ] = false;
                    }
                }
            }
        }
Exemplo n.º 14
0
		public override List<IProperty> GetProperties()
		{
			List<IProperty> l = base.GetProperties();
			ArrayIndexer property = new ArrayIndexer(elementType, this.BaseType.GetUnderlyingClass());
			IReturnType int32 = pc.SystemTypes.Int32;
			for (int i = 0; i < dimensions; ++i) {
				property.Parameters.Add(new DefaultParameter("index", int32, DomRegion.Empty));
			}
			l.Add(property);
			return l;
		}
Exemplo n.º 15
0
 public void DumpRadar( string cmd, string[]cmdsplit, int player )
 {
     logfile.WriteLine( "calling GetRadarMap..." );
     bool[] LosMap = aicallback.GetRadarMap();
     logfile.WriteLine( "...done" );
     int loswidth = aicallback.GetMapWidth() / 8;
     int losheight = aicallback.GetMapHeight() / 8;
     logfile.WriteLine( "losmap width: " + loswidth + " losheight: " + losheight );
     ArrayIndexer arrayindexer = new ArrayIndexer( loswidth, losheight );
     for( int y = 0; y < losheight; y++ )
     {
         string line = "";
         for( int x = 0; x < loswidth; x++ )
         {
             if( LosMap[ arrayindexer.GetIndex( x, y ) ] )
             {
                 aicallback.DrawUnit( "ARMRAD", new Float3( x * 64, 0, y * 64 ), 0.0f, 100, aicallback.GetMyAllyTeam(), true, true);
                 line += "*";
             }
             else
             {
                 line += "-";
             }
         }
         logfile.WriteLine( line );
     }
     aicallback.SendTextMsg("radar dumped to logfile", 0 );
 }