public static structures.pntWithDist[] costList(byte player, int range, Point ori) { structures.Pnt[] tempPntList = new xycv_ppc.structures.Pnt[Form1.game.width * Form1.game.height]; int tot = 0; byte[] pols = Form1.game.radius.relationTypeListNonAllies; int oriInd = 0; for (int x = 0; x < Form1.game.width; x++) { for (int y = 0; y < Form1.game.width; y++) { if (x == ori.X && y == ori.Y) { oriInd = tot; tempPntList[tot].X = x; tempPntList[tot].Y = y; tot++; } else if ( Form1.game.playerList[player].discovered[x, y] && ( Form1.game.grid[x, y].territory > 0 && ( Form1.game.grid[x, y].territory - 1 == player || Form1.game.playerList[player].foreignRelation[Form1.game.grid[x, y].territory - 1].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[player].foreignRelation[Form1.game.grid[x, y].territory - 1].politic == (byte)Form1.relationPolType.Protected || Form1.game.playerList[player].foreignRelation[Form1.game.grid[x, y].territory - 1].politic == (byte)Form1.relationPolType.Protector ) && ( Form1.game.grid[x, y].militaryImprovement == (byte)enums.militaryImprovement.airport || Form1.game.grid[x, y].city > 0 ) && !Form1.game.radius.caseOccupiedByRelationType(x, y, player, pols) ) ) { tempPntList[tot].X = x; tempPntList[tot].Y = y; tot++; } } } structures.Pnt[] pnts = new xycv_ppc.structures.Pnt[tot]; int[] prevPnt = new int[tot]; int[] order = new int[tot]; for (int i = 0; i < tot; i++) { pnts[i] = tempPntList[i]; order[i] = -1; } order[oriInd] = 0; bool mod = true; for (int rad = 1; mod; rad++) { mod = false; for (int i = 0; i < tot; i++) { if (order[i] == rad - 1) // used { for (int j = 0; j < tot; j++) { if ( i != j && order[j] == -1 && range >= Form1.game.radius.getDistWith(new Point(pnts[i].X, pnts[i].Y), new Point(pnts[j].X, pnts[j].Y)) ) // different, unused & in range { order[j] = rad; prevPnt[j] = i; mod = true; } } } } } bool[] valid = new bool[tot]; int tot1 = 0; for (int i = 0; i < tot; i++) { if (order[i] != -1) { valid[i] = true; tot1++; } } structures.pntWithDist[] costs = new xycv_ppc.structures.pntWithDist[tot1]; int pos = 0; for (int i = 0; i < tot; i++) { if (valid[i]) { costs[pos].dist = order[i]; costs[pos].X = pnts[i].X; costs[pos].Y = pnts[i].Y; pos++; } } return(costs); }
public static structures.pntWithDist[] costList( byte player, int range, Point ori ) { structures.Pnt[] tempPntList = new xycv_ppc.structures.Pnt[ Form1.game.width * Form1.game.height ]; int tot = 0; byte[] pols = Form1.game.radius.relationTypeListNonAllies; int oriInd = 0; for ( int x = 0; x < Form1.game.width; x ++ ) for ( int y = 0; y < Form1.game.width; y ++ ) if ( x == ori.X && y == ori.Y ) { oriInd = tot; tempPntList[ tot ].X = x; tempPntList[ tot ].Y = y; tot ++; } else if ( Form1.game.playerList[ player ].discovered[ x, y ] && ( Form1.game.grid[ x, y ].territory > 0 && ( Form1.game.grid[ x, y ].territory - 1 == player || Form1.game.playerList[ player ].foreignRelation[ Form1.game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[ player ].foreignRelation[ Form1.game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected || Form1.game.playerList[ player ].foreignRelation[ Form1.game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector ) && ( Form1.game.grid[ x, y ].militaryImprovement == (byte)enums.militaryImprovement.airport || Form1.game.grid[ x, y ].city > 0 ) && !Form1.game.radius.caseOccupiedByRelationType( x, y, player, pols ) ) ) { tempPntList[ tot ].X = x; tempPntList[ tot ].Y = y; tot ++; } structures.Pnt[] pnts = new xycv_ppc.structures.Pnt[ tot ]; int[] prevPnt = new int[ tot ]; int[] order = new int[ tot ]; for ( int i = 0; i < tot; i ++ ) { pnts[ i ] = tempPntList[ i ]; order[ i ] = -1; } order[ oriInd ] = 0; bool mod = true; for ( int rad = 1; mod; rad ++ ) { mod = false; for ( int i = 0; i < tot; i ++ ) if ( order[ i ] == rad - 1 ) // used for( int j = 0; j < tot; j ++ ) if ( i != j && order[ j ] == -1 && range >= Form1.game.radius.getDistWith( new Point( pnts[ i ].X, pnts[ i ].Y ), new Point( pnts[ j ].X, pnts[ j ].Y ) ) ) // different, unused & in range { order[ j ] = rad; prevPnt[ j ] = i; mod = true; } } bool[] valid = new bool[ tot ]; int tot1 = 0; for ( int i = 0; i < tot; i ++ ) if ( order[ i ] != -1 ) { valid[ i ] = true; tot1 ++; } structures.pntWithDist[] costs = new xycv_ppc.structures.pntWithDist[ tot1 ]; int pos = 0; for ( int i = 0; i < tot; i ++ ) if ( valid[ i ] ) { costs[ pos ].dist = order[ i ]; costs[ pos ].X = pnts[ i ].X; costs[ pos ].Y = pnts[ i ].Y; pos ++; } return costs; }
public structures.pntWithDist[] findNearestCaseTo( int xo, int yo, int xDest, int yDest, byte terrain, byte player, bool tet, bool attacking ) { Point dest = new Point( xDest, yDest ); Point[] sqr = returnEmptySquare( xo, yo, 1 ); bool[] valid = new bool[ sqr.Length ]; int[] dist = new int[ sqr.Length ]; byte[] order = new byte[ sqr.Length ]; for ( int j = 0; j < sqr.Length; j ++ ) { if ( sqr[ j ].X == xDest && sqr[ j ].Y == yDest ) { structures.pntWithDist[] pwd = new xycv_ppc.structures.pntWithDist[ 1 ]; pwd[ 0 ].X = sqr[ j ].X; pwd[ 0 ].Y = sqr[ j ].Y; pwd[ 0 ].dist = 0; return pwd; } if ( ( Statistics.terrains[ game.grid[ sqr[ j ].X, sqr[ j ].Y ].type ].ew == terrain || ( game.grid[ sqr[ j ].X, sqr[ j ].Y ].city > 0 && ( game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 == player || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector ) ) || game.grid[ sqr[ j ].X, sqr[ j ].Y ].river ) && ( game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 == player || game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory == 0 || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected || game.playerList[ player ].foreignRelation[ game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector || ( game.playerList[ player ].foreignRelation[ game.grid[ sqr[ j ].X, sqr[ j ].Y ].territory - 1 ].politic == (byte)Form1.relationPolType.war && tet ) || ( game.grid[ xo, yo ].territory - 1 != player && ( game.grid[ sqr[ j ].X, sqr[ j ].Y ].city == 0 || attacking ) ) ) ) { // valid case if ( !game.radius.caseOccupiedByRelationType( sqr[ j ].X, sqr[ j ].Y, player, true, true, true, false, false, false ) || ( attacking && !game.radius.caseOccupiedByRelationType( sqr[ j ].X, sqr[ j ].Y, player, false, true, true, false, false, false ) ) ) { valid[ j ] = true; dist[ j ] = getDistWith( sqr[ j ], dest ); } } else { // invalid case } } byte validCases = 0; for ( int j = 0; j < sqr.Length; j ++ ) if ( valid[ j ] ) validCases ++; structures.pntWithDist[] retour = new structures.pntWithDist[ validCases ]; for ( int j = 0, k = 0; j < sqr.Length; j ++ ) if ( valid[ j ] ) { retour[ k ].X = sqr[ j ].X; retour[ k ].Y = sqr[ j ].Y; retour[ k ].dist = dist[ j ]; k ++; } bool mod = true; structures.pntWithDist buffer; while ( mod ) { mod = false; for ( int j = 1; j < retour.Length; j ++ ) if ( retour[ j ].dist < retour[ j - 1 ].dist ) { buffer = retour[ j ]; retour[ j ] = retour[ j - 1 ]; retour[ j - 1 ] = buffer; mod = true; } } return retour; }