Пример #1
0
/**
**  Add the units in the rectangle to the current selection
**
**  @param corner_topleft,  start of selection rectangle
**  @param corner_bottomright end of selection rectangle
**
**  @return    the _total_ number of units selected.
*/
int AddSelectedUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
{
	// Check if the original selected unit (if it's alone) is ours,
	// and can be selectable by rectangle.
	// In this case, do nothing.
	if (Selected.size() == 1
		&& (!CanSelectMultipleUnits(*Selected[0]->Player)
			|| !Selected[0]->Type->BoolFlag[SELECTABLEBYRECTANGLE_INDEX].value)) {
		return Selected.empty();
	}
	// If there is no selected unit yet, do a simple selection.
	if (Selected.empty()) {
		return SelectUnitsInRectangle(corner_topleft, corner_bottomright);
	}
	const Vec2i tilePos0 = Map.MapPixelPosToTilePos(corner_topleft, UI.CurrentMapLayer->ID);
	const Vec2i tilePos1 = Map.MapPixelPosToTilePos(corner_bottomright, UI.CurrentMapLayer->ID);
	const Vec2i range(2, 2);
	std::vector<CUnit *> table;

	//Wyrmgus start
//	Select(tilePos0 - range, tilePos1 + range, table);
	Select(tilePos0 - range, tilePos1 + range, table, UI.CurrentMapLayer->ID);
	//Wyrmgus end
	SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table);
	// If no unit in rectangle area... do nothing
	if (table.empty()) {
		return Selected.size();
	}

	// Now we should only have mobile (organic) units belonging to us,
	// so if there's no such units in the rectangle, do nothing.
	//Wyrmgus start
//	if (SelectOrganicUnitsInTable(table) == false) {
	if (SelectOrganicUnitsInTable(table, true) == false) {
	//Wyrmgus end
		return Selected.size();
	}

	for (size_t i = 0; i < table.size() && Selected.size() < MaxSelectable; ++i) {
		//Wyrmgus start
		if (Selected.size() && !UnitCanBeSelectedWith(*Selected[0], *table[i])) {
			continue;
		}
		//Wyrmgus end
		SelectUnit(*table[i]);
	}
	return Selected.size();
}
Пример #2
0
/**
**  Add the units in the rectangle to the current selection
**
**  @param corner_topleft,  start of selection rectangle
**  @param corner_bottomright end of selection rectangle
**
**  @return    the _total_ number of units selected.
*/
int AddSelectedUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
{
	// Check if the original selected unit (if it's alone) is ours,
	// and can be selectable by rectangle.
	// In this case, do nothing.
	if (Selected.size() == 1
		&& (!CanSelectMultipleUnits(*Selected[0]->Player)
			|| !Selected[0]->Type->SelectableByRectangle)) {
		return Selected.empty();
	}
	// If there is no selected unit yet, do a simple selection.
	if (Selected.empty()) {
		return SelectUnitsInRectangle(corner_topleft, corner_bottomright);
	}
	const Vec2i tilePos0 = Map.MapPixelPosToTilePos(corner_topleft);
	const Vec2i tilePos1 = Map.MapPixelPosToTilePos(corner_bottomright);
	const Vec2i range(2, 2);
	std::vector<CUnit *> table;

	Select(tilePos0 - range, tilePos1 + range, table);
	SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table);
	// If no unit in rectangle area... do nothing
	if (table.empty()) {
		return Selected.size();
	}

	// Now we should only have mobile (organic) units belonging to us,
	// so if there's no such units in the rectangle, do nothing.
	if (SelectOrganicUnitsInTable(table) == false) {
		return Selected.size();
	}

	for (size_t i = 0; i < table.size() && Selected.size() < MaxSelectable; ++i) {
		SelectUnit(*table[i]);
	}
	return Selected.size();
}