Ejemplo n.º 1
0
/**
**  Change selected units to units from group group_number
**  Doesn't change the selection if the group has no unit.
**
**  @param group_number  number of the group to be selected.
**
**  @return              number of units in the group.
*/
int SelectGroup(int group_number, GroupSelectionMode mode)
{
	int nunits = GetNumberUnitsOfGroup(group_number, SELECT_ALL);
	if (nunits) {
		if (mode == SELECT_ALL || !IsGroupTainted(group_number)) {
			ChangeSelectedUnits(GetUnitsOfGroup(group_number), nunits);
			return NumSelected;
		} else {
			std::vector<CUnit *> table;
			CUnit **group = GetUnitsOfGroup(group_number);

			for (int i = 0; i < nunits; ++i) {
				const CUnitType *type = group[i]->Type;
				if (type && type->CanSelect(mode)) {
					table.push_back(group[i]);
				}
			}
			if (table.empty() == false) {
				ChangeSelectedUnits(&table[0], static_cast<int>(table.size()));
				return NumSelected;
			}
		}
	}
	return 0;
}
Ejemplo n.º 2
0
/**
**  Change selected units to units from group group_number
**  Doesn't change the selection if the group has no unit.
**
**  @param group_number  number of the group to be selected.
**
**  @return              number of units in the group.
*/
int SelectGroup(int group_number, GroupSelectionMode mode)
{
	const std::vector<CUnit *> &units = GetUnitsOfGroup(group_number);

	if (units.empty()) {
		return 0;
	}
	if (mode == SELECT_ALL || !IsGroupTainted(group_number)) {
		ChangeSelectedUnits(const_cast<CUnit **>(&units[0]), units.size());
		return Selected.size();
	}
	std::vector<CUnit *> table;

	for (size_t i = 0; i != units.size(); ++i) {
		const CUnitType *type = units[i]->Type;
		if (type && type->CanSelect(mode)) {
			table.push_back(units[i]);
		}
	}
	if (table.empty() == false) {
		ChangeSelectedUnits(&table[0], table.size());
		return Selected.size();
	}
	return 0;
}
Ejemplo n.º 3
0
/**
**  Add group to current selection.
**
**  @param group  Group number to add.
*/
static void UiAddGroupToSelection(unsigned group)
{
	CUnit **units;
	int n;

	if (!(n = GetNumberUnitsOfGroup(group, SELECT_ALL))) {
		return;
	}

	//
	//  Don't allow to mix units and buildings
	//
	if (NumSelected && Selected[0]->Type->Building) {
		return;
	}

	units = GetUnitsOfGroup(group);

	while (n--) {
		if (!(units[n]->Removed || units[n]->Type->Building)) {
			SelectUnit(*units[n]);
		}
	}

	SelectionChanged();
}
Ejemplo n.º 4
0
/**
**  Center on group.
**
**  @param group  Group number to center on.
**
**  @todo Improve this function, try to show all selected units
**        or the most possible units.
*/
static void UiCenterOnGroup(unsigned group, GroupSelectionMode mode = SELECTABLE_BY_RECTANGLE_ONLY)
{
	int n = GetNumberUnitsOfGroup(group, SELECT_ALL);

	if (n--) {
		CUnit **units = GetUnitsOfGroup(group);
		PixelPos pos(-1, -1);

		// FIXME: what should we do with the removed units? ignore?
		if (units[n]->Type && units[n]->Type->CanSelect(mode)) {
			pos = units[n]->GetMapPixelPosCenter();
		}
		while (n--) {
			if (units[n]->Type && units[n]->Type->CanSelect(mode)) {
				if (pos.x != -1) {
					pos += (units[n]->GetMapPixelPosCenter() - pos) / 2;
				} else {
					pos = units[n]->GetMapPixelPosCenter();
				}
			}
		}
		if (pos.x != -1) {
			UI.SelectedViewport->Center(pos);
		}
	}
}
Ejemplo n.º 5
0
/**
**  Center on group.
**
**  @param group  Group number to center on.
**
**  @todo Improve this function, try to show all selected units
**        or the most possible units.
*/
static void UiCenterOnGroup(unsigned group, GroupSelectionMode mode = SELECTABLE_BY_RECTANGLE_ONLY)
{
	const std::vector<CUnit *> &units = GetUnitsOfGroup(group);
	PixelPos pos(-1, -1);

	// FIXME: what should we do with the removed units? ignore?
	for (size_t i = 0; i != units.size(); ++i) {
		if (units[i]->Type && units[i]->Type->CanSelect(mode)) {
			if (pos.x != -1) {
				pos += (units[i]->GetMapPixelPosCenter() - pos) / 2;
			} else {
				pos = units[i]->GetMapPixelPosCenter();
			}
		}
	}
	if (pos.x != -1) {
		UI.SelectedViewport->Center(pos);
	}
}
Ejemplo n.º 6
0
/**
**  Add group to current selection.
**
**  @param group  Group number to add.
*/
static void UiAddGroupToSelection(unsigned group)
{
	const std::vector<CUnit *> &units = GetUnitsOfGroup(group);

	if (units.empty()) {
		return;
	}

	//  Don't allow to mix units and buildings
	if (!Selected.empty() && Selected[0]->Type->Building) {
		return;
	}

	for (size_t i = 0; i != units.size(); ++i) {
		if (!(units[i]->Removed || units[i]->Type->Building)) {
			SelectUnit(*units[i]);
		}
	}
	SelectionChanged();
}