public int[,] gridCostOnWater( Point ori, byte player, bool attack, int radius ) { byte[] pols = returnRelationTypeList( !attack, true, true, false, false, false ); bool onNeutralTerritory = false; if ( game.grid[ ori.X, ori.Y ].territory - 1 != player && game.grid[ ori.X, ori.Y ].territory != 0 && ( game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.ceaseFire || game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.peace || game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.war ) ) onNeutralTerritory = true; int[,] order = new int[ game.width, game.height ]; bool[,] alreadyWorked = new bool[ game.width, game.height ]; for ( int x = 0; x < game.width; x ++ ) for ( int y = 0; y < game.height; y ++ ) order[ x, y ] = -1; order[ ori.X, ori.Y ] = 0; bool mod = true, modInRad = false; int pos = 0; for ( int rad = 0; mod && rad < 3 * game.width; rad ++ ) { mod = false; modInRad = true; while ( modInRad ) { modInRad = false; for ( int x1 = 0; x1 < game.width; x1 ++ ) for ( int y1 = 0; y1 < game.height; y1 ++ ) if ( order[ x1, y1 ] == rad ) { if ( !alreadyWorked[ x1, y1 ] ) { alreadyWorked[ x1, y1 ] = true; structures.Pnt[] inRange = new structures.Pnt[ 8 ]; Point[] sqr = game.radius.returnEmptySquare( x1, y1, 1 ); pos = 0; for ( int k = 0; k < sqr.Length; k ++ ) if ( ori.X == sqr[ k ].X && ori.Y == sqr[ k ].Y ) { inRange[ pos ].X = (int)sqr[ k ].X; inRange[ pos ].Y = (int)sqr[ k ].Y; pos ++; } else if ( Statistics.terrains[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].type ].ew == 0 || ( game.grid[ sqr[ k ].X, sqr[ k ].Y ].city > 0 && ( onNeutralTerritory || game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 == player || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector || ( game.playerList[ player ].foreignRelation[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.war && attack ) ) ) && !caseOccupiedByRelationType( sqr[ k ].X, sqr[ k ].Y, player, pols ) ) { inRange[ pos ].X = (int)sqr[ k ].X; inRange[ pos ].Y = (int)sqr[ k ].Y; pos ++; } for ( int k = pos; k < inRange.Length; k ++ ) inRange[ k ].X = -1; for ( int i = 0; i < inRange.Length; i ++ ) if ( inRange[ i ].X != -1 && ( order[ inRange[ i ].X, inRange[ i ].Y ] == -1 || ( order[ inRange[ i ].X, inRange[ i ].Y ] > rad && order[ inRange[ i ].X, inRange[ i ].Y ] > rad + costBetweenOnWater( new Point( x1, y1 ), new Point( inRange[ i ].X, inRange[ i ].Y ) ) ) ) ) { order[ inRange[ i ].X, inRange[ i ].Y ] = (int)( rad + costBetweenOnWater( new Point( x1, y1 ), new Point( inRange[ i ].X, inRange[ i ].Y ) ) ); mod = true; modInRad = true; } } } else if ( order[ x1, y1 ] > rad ) mod = true; } } return order; }
public System.Drawing.Point[] findWayToOnLand( Point ori, Point dest, byte player, bool attack ) { if ( ori.X == -1 || ori.Y == -1 || dest.X == -1 || dest.Y == -1 ) return new Point[ 1 ] { new Point( -1, -1 ) }; else if ( game.grid[ ori.X, ori.Y ].continent != game.grid[ dest.X, dest.Y ].continent && game.grid[ ori.X, ori.Y ].continent != 0 && game.grid[ dest.X, dest.Y ].continent != 0 ) return new Point[ 1 ] { new Point( -1, -1 ) }; else if ( ori.X == dest.X && ori.Y == dest.Y ) return new Point[ 1 ] { new Point( -2, -2 ) }; else { byte[] pols = returnRelationTypeList( !attack, true, true, false, false, false ); bool onNeutralTerritory = false; if ( game.grid[ ori.X, ori.Y ].territory - 1 != player && game.grid[ ori.X, ori.Y ].territory != 0 && ( game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.ceaseFire || game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.peace || game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.war ) ) onNeutralTerritory = true; uint[,] order = new uint[ game.width, game.height ]; structures.Pnt[,] prevPnt = new structures.Pnt[ game.width, game.height ]; bool[,] alreadyWorked = new bool[ game.width, game.height ]; order[ ori.X, ori.Y ] = 1; bool mod = true, modInRad = false; for ( int rad = 1; mod && rad < 3 * game.width; rad ++ ) { mod = false; modInRad = true; while ( modInRad ) { modInRad = false; for ( int x1 = 0; x1 < game.width; x1 ++ ) for ( int y1 = 0; y1 < game.height; y1 ++ ) if ( order[ x1, y1 ] == rad ) { if ( !alreadyWorked[ x1, y1 ] ) { alreadyWorked[ x1, y1 ] = true; structures.Pnt[] inRange = new structures.Pnt[ 8 ]; Point[] sqr = game.radius.returnEmptySquare( x1, y1, 1 ); int pos = 0; for ( int k = 0; k < sqr.Length; k ++ ) if ( ori.X == sqr[ k ].X && ori.Y == sqr[ k ].Y ) { inRange[ pos ].X = (int)sqr[ k ].X; inRange[ pos ].Y = (int)sqr[ k ].Y; pos ++; } else if ( dest.X == sqr[ k ].X && dest.Y == sqr[ k ].Y ) { inRange[ pos ].X = (int)sqr[ k ].X; inRange[ pos ].Y = (int)sqr[ k ].Y; pos ++; } else if ( game.grid[ sqr[ k ].X, sqr[ k ].Y ].continent == game.grid[ ori.X, ori.Y ].continent && ( game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 == player || game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory == 0 || ( onNeutralTerritory && game.grid[ sqr[ k ].X, sqr[ k ].Y ].city == 0 ) || ( game.playerList[ player ].foreignRelation[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector ) || ( attack && game.playerList[ player ].foreignRelation[ game.grid[ sqr[ k ].X, sqr[ k ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.war ) ) && !caseOccupiedByRelationType( sqr[ k ].X, sqr[ k ].Y, player, pols ) ) { inRange[ pos ].X = (int)sqr[ k ].X; inRange[ pos ].Y = (int)sqr[ k ].Y; pos ++; } for ( int k = pos; k < inRange.Length; k ++ ) inRange[ k ].X = -1; for ( int i = 0; i < inRange.Length; i ++ ) if ( inRange[ i ].X != -1 && ( order[ inRange[ i ].X, inRange[ i ].Y ] == 0 || ( order[ inRange[ i ].X, inRange[ i ].Y ] > rad && order[ inRange[ i ].X, inRange[ i ].Y ] > rad + costBetweenOnLand( new Point( x1, y1 ), new Point( inRange[ i ].X, inRange[ i ].Y ) ) ) ) ) { order[ inRange[ i ].X, inRange[ i ].Y ] = (uint)( rad + costBetweenOnLand( new Point( x1, y1 ), new Point( inRange[ i ].X, inRange[ i ].Y ) ) ); prevPnt[ inRange[ i ].X, inRange[ i ].Y ].X = x1; prevPnt[ inRange[ i ].X, inRange[ i ].Y ].Y = y1; mod = true; modInRad = true; if ( inRange[ i ].X == dest.X && inRange[ i ].Y == dest.Y ) { Point[] way = new Point[ order[ inRange[ i ].X, inRange[ i ].Y ] ]; structures.Pnt[] wayInt = new structures.Pnt[ order[ inRange[ i ].X, inRange[ i ].Y ] ]; way[ 0 ] = dest; wayInt[ 0 ] = inRange[ i ]; for ( int c = 0; c < order[ inRange[ i ].X, inRange[ i ].Y ] - 1; c ++ ) { if ( prevPnt[ wayInt[ c ].X, wayInt[ c ].Y ].X == ori.X && prevPnt[ wayInt[ c ].X, wayInt[ c ].Y ].Y == ori.Y ) { Point[] finalWay = new Point[ c + 1 ]; for ( int f = 0; f < finalWay.Length; f ++ ) finalWay[ f ] = way[ finalWay.Length - f - 1 ]; return finalWay; } wayInt[ c + 1 ] = prevPnt[ wayInt[ c ].X, wayInt[ c ].Y ]; way[ c + 1 ] = new Point( prevPnt[ wayInt[ c ].X, wayInt[ c ].Y ].X, prevPnt[ wayInt[ c ].X, wayInt[ c ].Y ].Y ); } } } } } else if ( order[ x1, y1 ] > rad ) mod = true; } } return new Point[] { new Point( -1, -1 ) }; } }