Ejemplo n.º 1
0
/**
**  Called if a unit can't move. Try to move unit in the way
**
**  @param unit  Pointer to unit what builds the building.
*/
void AiCanNotMove(CUnit &unit)
{
	const Vec2i &goalPos = unit.pathFinderData->input.GetGoalPos();
	const int gw = unit.pathFinderData->input.GetGoalSize().x;
	const int gh = unit.pathFinderData->input.GetGoalSize().y;

	AiPlayer = unit.Player->Ai;
	if (PlaceReachable(unit, goalPos, gw, gh, 0, 255)) {
		// Path probably closed by unit here
		AiMoveUnitInTheWay(unit);
	}
}
Ejemplo n.º 2
0
/**
**  Called if a unit can't move. Try to move unit in the way
**
**  @param unit  Pointer to unit what builds the building.
**
**  @pre         The unit's field flags must have been marked
**               on the map; see MarkUnitFieldFlags.
*/
void AiCanNotMove(CUnit *unit)
{
	// Please do not use UnmarkUnitFieldFlags and MarkUnitFieldFlags
	// around AiCanNotMove calls.
	Assert((Map.Field(unit->X, unit->Y)->Flags & unit->Type->FieldFlags) != 0);

	AiPlayer = unit->Player->Ai;

	if (GameCycle >= AiPlayer->LastCanNotMoveGameCycle + CYCLES_PER_SECOND)
	{
		int gx, gy, gw, gh;
		int minrange, maxrange;

		if (unit->Orders[0]->Goal)
		{
			gw = unit->Orders[0]->Goal->Type->TileWidth;
			gh = unit->Orders[0]->Goal->Type->TileHeight;
			gx = unit->Orders[0]->Goal->X;
			gy = unit->Orders[0]->Goal->Y;
			maxrange = unit->Orders[0]->Range;
			minrange = unit->Orders[0]->MinRange;
		}
		else
		{
			// Take care of non square goals :)
			// If goal is non square, range states a non-existant goal rather
			// than a tile.
			gw = unit->Orders[0]->Width;
			gh = unit->Orders[0]->Height;
			maxrange = unit->Orders[0]->Range;
			minrange = unit->Orders[0]->MinRange;
			gx = unit->Orders[0]->X;
			gy = unit->Orders[0]->Y;
		}

		if (unit->Type->UnitType == UnitTypeFly ||
			PlaceReachable(unit, gx, gy, gw, gh, minrange, maxrange))
		{
			// Path probably closed by unit here
			AiMoveUnitInTheWay(unit);
		}
	}

	AiPlayer->LastCanNotMoveGameCycle = GameCycle;
}