コード例 #1
0
        // ported from Spring's ReadMap.cpp by Hugh Perkins
        public double[,] GetSlopeMap()
        {
            int mapwidth  = aicallback.GetMapWidth();
            int mapheight = aicallback.GetMapHeight();

            int slopemapwidth  = mapwidth / 2;
            int slopemapheight = mapheight / 2;

            int squaresize = MovementMaps.SQUARE_SIZE; // jsut to save typing...

            logfile.WriteLine("Getting heightmap, this could take a while... ");

            double[,] HeightMap = new double[mapwidth + 1, mapheight + 1];

            //double[]heightmap = aicallback.GetHeightMap();  // cant use heightmap, it is centre heightmap, we need cornermap


            for (int x = 0; x < mapwidth + 1; x++)
            {
                for (int y = 0; y < mapheight + 1; y++)
                {
                    HeightMap[x, y] = aicallback.GetElevation(x * squaresize, y * squaresize);
                }
            }

            // ArrayIndexer heightmapindexer = new ArrayIndexer( mapwidth + 1, mapheight + 1 );
            logfile.WriteLine("calculating slopes...");
            logfile.WriteLine("mapwidth: " + slopemapwidth + " " + slopemapheight);

            double[,] SlopeMap = new double[slopemapwidth, slopemapheight];
            for (int y = 2; y < mapheight - 2; y += 2)
            {
                for (int x = 2; x < mapwidth - 2; x += 2)
                {
                    AdvancedFloat3 e1 = new AdvancedFloat3(-squaresize * 4, HeightMap[x - 1, y - 1] - HeightMap[x + 3, y - 1], 0);
                    AdvancedFloat3 e2 = new AdvancedFloat3(0, HeightMap[x - 1, y - 1] - HeightMap[x - 1, y + 3], -squaresize * 4);

                    AdvancedFloat3 n = e2.Cross(e1);

                    n.Normalize();

                    e1 = new AdvancedFloat3(squaresize * 4, HeightMap[x + 3, y + 3] - HeightMap[x - 1, y + 3], 0);
                    e2 = new AdvancedFloat3(0, HeightMap[x + 3, y + 3] - HeightMap[x + 3, y - 1], squaresize * 4);

                    AdvancedFloat3 n2 = e2.Cross(e1);
                    n2.Normalize();

                    SlopeMap[x / 2, y / 2] = 1 - (n.y + n2.y) * 0.5;
                }
            }
            logfile.WriteLine("... slopes calculated");
            return(SlopeMap);
        }
コード例 #2
0
        // ported from Spring's ReadMap.cpp by Hugh Perkins
        public double[,]GetSlopeMap()
        {
            int mapwidth = aicallback.GetMapWidth();
            int mapheight = aicallback.GetMapHeight();
            
            int slopemapwidth = mapwidth / 2;
            int slopemapheight = mapheight / 2;
            
            int squaresize = MovementMaps.SQUARE_SIZE; // jsut to save typing...
            
            logfile.WriteLine( "Getting heightmap, this could take a while... " );
            
            double[,]HeightMap = new double[ mapwidth + 1, mapheight + 1 ];
            
            //double[]heightmap = aicallback.GetHeightMap();  // cant use heightmap, it is centre heightmap, we need cornermap


            for( int x = 0; x < mapwidth + 1; x++ )
            {
                for( int y = 0; y < mapheight + 1; y++ )
                {
                    HeightMap[ x, y ] = aicallback.GetElevation( x * squaresize, y * squaresize );
                }
            }

            // ArrayIndexer heightmapindexer = new ArrayIndexer( mapwidth + 1, mapheight + 1 );
            logfile.WriteLine("calculating slopes..." );
            logfile.WriteLine("mapwidth: " + slopemapwidth + " " + slopemapheight);
                        
            double[,]SlopeMap = new double[ slopemapwidth, slopemapheight ];
            for(int y = 2; y < mapheight - 2; y+= 2)
            {
                for(int x = 2; x < mapwidth - 2; x+= 2)
                {
                    AdvancedFloat3 e1 = new AdvancedFloat3( -squaresize*4, HeightMap[ x - 1, y - 1 ] - HeightMap[ x + 3, y - 1 ] , 0 );
                    AdvancedFloat3 e2 = new AdvancedFloat3( 0, HeightMap[ x - 1, y - 1 ] - HeightMap[ x - 1, y + 3 ], -squaresize * 4 );
        
                    AdvancedFloat3 n=e2.Cross( e1 );
        
                    n.Normalize();

                    e1 = new AdvancedFloat3( squaresize * 4, HeightMap[ x + 3, y + 3 ] - HeightMap[ x - 1, y + 3 ], 0 );
                    e2 = new AdvancedFloat3( 0, HeightMap[ x + 3, y + 3 ] - HeightMap[ x + 3, y - 1 ], squaresize * 4 );
        
                    AdvancedFloat3 n2 = e2.Cross(e1);
                    n2.Normalize();

                    SlopeMap[ x / 2, y / 2 ]= 1 - ( n.y + n2.y ) * 0.5;
                }
            }
            logfile.WriteLine("... slopes calculated" );
            return SlopeMap;
        }
コード例 #3
0
        void Attack(UnitInfo[] closestunits)
        {
            //logfile.WriteLine( "AttackPackCoordinator attacking" );
            //if( debugon )
            // {
            //      aicallback.SendTextMsg( "AttackPackCoordinator attacking", 0 );
            // }

            // get vector from head unit to target
            // pick point a bit behind target, backwards along vector
            AdvancedFloat3 vectortargettohead = new AdvancedFloat3(targetpos - closestunits[0].pos);

            vectortargettohead.Normalize();
            //vectortargettohead = vectortargettohead * AttackDistance;
            MoveTo(targetpos + vectortargettohead * AttackDistance);
        }
コード例 #4
0
ファイル: SlopeMap.cs プロジェクト: achoum/spring
        // ported from Spring's ReadMap.cpp by Hugh Perkins
        public double[, ]GetSlopeMap()
        {
            int mapwidth = aicallback.GetMapWidth();
            int mapheight = aicallback.GetMapHeight();

            int slopemapwidth = mapwidth / 2;
            int slopemapheight = mapheight / 2;

            int squaresize = MovementMaps.SQUARE_SIZE; // jsut to save typing...

            double[,] heightmap = HeightMap.GetInstance().GetHeightMap();
            logfile.WriteLine( "Getting heightmap, this could take a while... " );

            // ArrayIndexer heightmapindexer = new ArrayIndexer( mapwidth + 1, mapheight + 1 );
            logfile.WriteLine("calculating slopes..." );
            logfile.WriteLine("mapwidth: " + slopemapwidth + " " + slopemapheight);

            double[,]SlopeMap = new double[ slopemapwidth, slopemapheight ];
            for(int y = 2; y < mapheight - 2; y+= 2)
            {
                for(int x = 2; x < mapwidth - 2; x+= 2)
                {
                    AdvancedFloat3 e1 = new AdvancedFloat3(-squaresize * 4, heightmap[x - 1, y - 1] - heightmap[x + 3, y - 1], 0);
                    AdvancedFloat3 e2 = new AdvancedFloat3(0, heightmap[x - 1, y - 1] - heightmap[x - 1, y + 3], -squaresize * 4);

                    AdvancedFloat3 n=e2.Cross( e1 );

                    n.Normalize();

                    e1 = new AdvancedFloat3(squaresize * 4, heightmap[x + 3, y + 3] - heightmap[x - 1, y + 3], 0);
                    e2 = new AdvancedFloat3(0, heightmap[x + 3, y + 3] - heightmap[x + 3, y - 1], squaresize * 4);

                    AdvancedFloat3 n2 = e2.Cross(e1);
                    n2.Normalize();

                    SlopeMap[ x / 2, y / 2 ]= 1 - ( n.y + n2.y ) * 0.5;
                }
            }
            logfile.WriteLine("... slopes calculated" );
            return SlopeMap;
        }
コード例 #5
0
 // ported from Spring's float3.h
 public AdvancedFloat3 Cross(AdvancedFloat3 f)
 {
     return(new AdvancedFloat3(y * f.z - z * f.y,
                               z * f.x - x * f.z,
                               x * f.y - y * f.x));
 }
コード例 #6
0
ファイル: AdvancedFloat3.cs プロジェクト: achoum/spring
 // ported from Spring's float3.h
 public AdvancedFloat3 Cross( AdvancedFloat3 f )
 {
     return new AdvancedFloat3( y*f.z - z*f.y,
                                              z*f.x - x*f.z,
                                              x*f.y - y*f.x  );
 }
コード例 #7
0
        void Attack(UnitInfo[] closestunits)
        {
            //logfile.WriteLine( "AttackPackCoordinator attacking" );
            //if( debugon )
               // {
              //      aicallback.SendTextMsg( "AttackPackCoordinator attacking", 0 );
               // }

            // get vector from head unit to target
            // pick point a bit behind target, backwards along vector
            AdvancedFloat3 vectortargettohead = new AdvancedFloat3( targetpos - closestunits[0].pos );
            vectortargettohead.Normalize();
            //vectortargettohead = vectortargettohead * AttackDistance;
            MoveTo(targetpos + vectortargettohead * AttackDistance);
        }