/** ** Select own air units in a rectangle. ** ** @param corner_topleft, start of selection rectangle ** @param corner_bottomright end of selection rectangle ** ** @return the number of units found. */ int SelectAirUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright) { const Vec2i t0 = Map.MapPixelPosToTilePos(corner_topleft); const Vec2i t1 = Map.MapPixelPosToTilePos(corner_bottomright); const Vec2i range(2, 2); std::vector<CUnit *> table; Select(t0 - range, t1 + range, table); SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table); unsigned int n = 0; for (size_t i = 0; i != table.size(); ++i) { CUnit &unit = *table[i]; if (!CanSelectMultipleUnits(*unit.Player) || !unit.Type->SelectableByRectangle) { continue; } if (unit.IsUnusable()) { // guess SelectUnits doesn't check this continue; } if (unit.Type->UnitType != UnitTypeFly) { continue; } if (unit.TeamSelected) { // Somebody else onteam has this unit continue; } table[n++] = &unit; if (n == MaxSelectable) { break; } } if (n) { ChangeSelectedUnits(&table[0], n); } return n; }
/** ** Add the ground units in the rectangle to the current selection ** ** @param corner_topleft, start of selection rectangle ** @param corner_bottomright end of selection rectangle ** ** @return the number of units found. */ int AddSelectedGroundUnitsInRectangle(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.size(); } // If there is no selected unit yet, do a simple selection. if (Selected.empty()) { return SelectGroundUnitsInRectangle(corner_topleft, corner_bottomright); } const Vec2i t0 = Map.MapPixelPosToTilePos(corner_topleft); const Vec2i t1 = Map.MapPixelPosToTilePos(corner_bottomright); const Vec2i range(2, 2); std::vector<CUnit *> table; Select(t0 - range, t1 + range, table); SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table); unsigned int n = 0; for (size_t i = 0; i < table.size(); ++i) { CUnit &unit = *table[i]; if (!CanSelectMultipleUnits(*unit.Player) || !unit.Type->SelectableByRectangle) { continue; } if (unit.IsUnusable()) { // guess SelectUnits doesn't check this continue; } if (unit.Type->UnitType == UnitTypeFly) { continue; } if (unit.TeamSelected) { // Somebody else onteam has this unit continue; } table[n++] = &unit; if (n == MaxSelectable) { break; } } // Add the units to selected. for (unsigned int i = 0; i < n && Selected.size() < MaxSelectable; ++i) { SelectUnit(*table[i]); } return Selected.size(); }
/** ** 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(); }
/** ** Select own ground units in a rectangle. ** ** @param corner_topleft, start of selection rectangle ** @param corner_bottomright end of selection rectangle ** ** @return the number of units found. */ int SelectGroundUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright) { const Vec2i t0 = Map.MapPixelPosToTilePos(corner_topleft, UI.CurrentMapLayer->ID); const Vec2i t1 = Map.MapPixelPosToTilePos(corner_bottomright, UI.CurrentMapLayer->ID); const Vec2i range(2, 2); std::vector<CUnit *> table; //Wyrmgus start // Select(t0 - range, t1 + range, table); Select(t0 - range, t1 + range, table, UI.CurrentMapLayer->ID); //Wyrmgus end SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table); unsigned int n = 0; for (size_t i = 0; i != table.size(); ++i) { CUnit &unit = *table[i]; if (!CanSelectMultipleUnits(*unit.Player) || !unit.Type->BoolFlag[SELECTABLEBYRECTANGLE_INDEX].value) { continue; } if (unit.IsUnusable()) { // guess SelectUnits doesn't check this continue; } if (unit.Type->UnitType == UnitTypeFly) { continue; } if (unit.TeamSelected) { // Somebody else onteam has this unit continue; } //Wyrmgus start if (unit.Type->BoolFlag[BUILDING_INDEX].value) { //this selection mode is not for buildings continue; } //Wyrmgus end table[n++] = &unit; if (n == MaxSelectable) { break; } } if (n) { ChangeSelectedUnits(&table[0], n); } return n; }
/** ** 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(); }
/** ** Select units in a rectangle. ** Proceed in order in none found: ** @li select local player mobile units ** @li select one local player static unit (random) ** @li select one neutral unit (critter, mine...) ** @li select one enemy unit (random) ** ** @param corner_topleft, start of selection rectangle ** @param corner_bottomright end of selection rectangle ** ** @return the number of units found. */ int SelectUnitsInRectangle(const PixelPos &corner_topleft, const PixelPos &corner_bottomright) { const Vec2i t0 = Map.MapPixelPosToTilePos(corner_topleft); const Vec2i t1 = Map.MapPixelPosToTilePos(corner_bottomright); const Vec2i range(2, 2); std::vector<CUnit *> table; Select(t0 - range, t1 + range, table); SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table); // 1) search for the player units selectable with rectangle if (SelectOrganicUnitsInTable(table)) { const int size = static_cast<int>(table.size()); ChangeSelectedUnits(&table[0], size); return size; } // 2) If no unit found, try a player's unit not selectable by rectangle for (size_t i = 0; i != table.size(); ++i) { CUnit &unit = *table[i]; if (!CanSelectMultipleUnits(*unit.Player)) { continue; } // FIXME: Can we get this? if (!unit.Removed && unit.IsAlive()) { SelectSingleUnit(unit); return 1; } } // 3) If no unit found, try a resource or a neutral critter for (size_t i = 0; i != table.size(); ++i) { CUnit &unit = *table[i]; // Unit visible FIXME: write function UnitSelectable if (!unit.IsVisibleInViewport(*UI.SelectedViewport)) { continue; } const CUnitType &type = *unit.Type; // Buildings are visible but not selectable if (type.Building && !unit.IsVisibleOnMap(*ThisPlayer)) { continue; } if ((type.GivesResource && !unit.Removed)) { // no built resources. SelectSingleUnit(unit); return 1; } } // 4) If no unit found, select an enemy unit (first found) for (size_t i = 0; i != table.size(); ++i) { CUnit &unit = *table[i]; // Unit visible FIXME: write function UnitSelectable if (!unit.IsVisibleInViewport(*UI.SelectedViewport)) { continue; } // Buildings are visible but not selectable if (unit.Type->Building && !unit.IsVisibleOnMap(*ThisPlayer)) { continue; } if (unit.IsAliveOnMap()) { SelectSingleUnit(unit); return 1; } } return 0; }
/** ** Add the air units in the rectangle to the current selection ** ** @param corner_topleft, start of selection rectangle ** @param corner_bottomright end of selection rectangle ** ** @return the number of units found. */ int AddSelectedAirUnitsInRectangle(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.size(); } // If there is no selected unit yet, do a simple selection. //Wyrmgus start // if (Selected.empty()) { if (Selected.empty() || (Selected.size() && Selected[0]->Type->BoolFlag[BUILDING_INDEX].value)) { //Wyrmgus end return SelectAirUnitsInRectangle(corner_topleft, corner_bottomright); } const Vec2i t0 = Map.MapPixelPosToTilePos(corner_topleft, UI.CurrentMapLayer->ID); const Vec2i t1 = Map.MapPixelPosToTilePos(corner_bottomright, UI.CurrentMapLayer->ID); const Vec2i range(2, 2); std::vector<CUnit *> table; //Wyrmgus start // Select(t0 - range, t1 + range, table); Select(t0 - range, t1 + range, table, UI.CurrentMapLayer->ID); //Wyrmgus end SelectSpritesInsideRectangle(corner_topleft, corner_bottomright, table); unsigned int n = 0; for (size_t i = 0; i < table.size(); ++i) { CUnit &unit = *table[i]; if (!CanSelectMultipleUnits(*unit.Player) || !unit.Type->BoolFlag[SELECTABLEBYRECTANGLE_INDEX].value) { continue; } if (unit.IsUnusable()) { // guess SelectUnits doesn't check this continue; } if (unit.Type->UnitType != UnitTypeFly) { continue; } if (unit.TeamSelected) { // Somebody else onteam has this unit continue; } //Wyrmgus start if (unit.Type->BoolFlag[BUILDING_INDEX].value) { //this selection mode is not for buildings continue; } //Wyrmgus end table[n++] = &unit; if (n == MaxSelectable) { break; } } // Add the units to selected. for (unsigned int i = 0; i < n && Selected.size() < MaxSelectable; ++i) { SelectUnit(*table[i]); } return Selected.size(); }