Пример #1
0
/**
**  Find a free position close to x, y
**
**  @param x     Original x search position
**  @param y     Original y search position
**  @param resx  Unload x position.
**  @param resy  Unload y position.
**  @param mask  Movement mask for the unit to be droped.
**
**  @return      True if a position was found, False otherwise.
**  @note        resx and resy are undefined if a position is not found.
**
**  @bug         FIXME: Place unit only on fields reachable from the transporter
**  @bug         FIXME: This function fails for units larger than 1x1.
*/
static int FindUnloadPosition(int x, int y, int *resx, int *resy, int mask)
{
	int i;
	int n;
	int addx;
	int addy;

	addx = addy = 1;
	--x;
	for (n = 0; n < 2; ++n) {
		// Nobody: There was some code here to check for unloading units that can
		// only go on even tiles. It's useless, since we can only unload land units.
		for (i = addy; i--; ++y) {
			if (CheckedCanMoveToMask(x, y, mask)) {
				*resx = x;
				*resy = y;
				return 1;
			}
		}
		++addx;
		for (i = addx; i--; ++x) {
			if (CheckedCanMoveToMask(x, y, mask)) {
				*resx = x;
				*resy = y;
				return 1;
			}
		}
		++addy;
		for (i = addy; i--; --y) {
			if (CheckedCanMoveToMask(x, y, mask)) {
				*resx = x;
				*resy = y;
				return 1;
			}
		}
		++addx;
		for (i = addx; i--; --x) {
			if (CheckedCanMoveToMask(x, y, mask)) {
				*resx = x;
				*resy = y;
				return 1;
			}
		}
		++addy;
	}
	return 0;
}
Пример #2
0
/**
**	Reappear unit on map.
**
**	@param unit	Unit to drop out.
**	@param addx	Tile size in x.
**	@param addy	Tile size in y.
**
**	@return		True if unit can be unloaded.
**
**	@bug FIXME: Place unit only on fields reachable from the transporter
*/
global int UnloadUnit(Unit* unit,int addx,int addy)
{
    int x;
    int y;
    int i;
    int mask;
    int n;

    DebugCheck( !unit->Removed );

    x=unit->X;
    y=unit->Y;
    mask=UnitMovementMask(unit);

    --x;
    // FIXME: don't search outside of the map
    for( n=0; n<2; ++n ) {
	for( i=addy; i--; y++ ) {
#ifdef NEW_SHIPS
	    if( unit->Type->UnitType!=UnitTypeLand && ((x&1) || (y&1)) ) {
		continue;
	    }
#endif
	    if( CheckedCanMoveToMask(x,y,mask) ) {
		goto found;
	    }
	}
	++addx;
	for( i=addx; i--; x++ ) {
#ifdef NEW_SHIPS
	    if( unit->Type->UnitType!=UnitTypeLand && ((x&1) || (y&1)) ) {
		continue;
	    }
#endif
	    if( CheckedCanMoveToMask(x,y,mask) ) {
		goto found;
	    }
	}
	++addy;
	for( i=addy; i--; y-- ) {
#ifdef NEW_SHIPS
	    if( unit->Type->UnitType!=UnitTypeLand && ((x&1) || (y&1)) ) {
		continue;
	    }
#endif
	    if( CheckedCanMoveToMask(x,y,mask) ) {
		goto found;
	    }
	}
	++addx;
	for( i=addx; i--; x-- ) {
#ifdef NEW_SHIPS
	    if( unit->Type->UnitType!=UnitTypeLand && ((x&1) || (y&1)) ) {
		continue;
	    }
#endif
	    if( CheckedCanMoveToMask(x,y,mask) ) {
		goto found;
	    }
	}
	++addy;
    }
    return 0;

found:
    unit->X=x;
    unit->Y=y;

    unit->Wait=1;		// should be correct unit has still action

    PlaceUnit(unit,x,y);

    return 1;
}