_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

selection.cpp File Reference
#include "stratagus.h"
#include "commands.h"
#include "interface.h"
#include "iolib.h"
#include "map.h"
#include "network.h"
#include "player.h"
#include "ui.h"
#include "unittype.h"
#include "unit.h"
#include "unit_find.h"
#include "unit_manager.h"

selection.cpp - The units' selection.

unsigned int MaxSelectable
 
std::vector< CUnit * > Selected
 Maximum number of selected units. More...
 
static std::vector< CUnit * > TeamSelected [PlayerMax]
 All selected units. More...
 
static std::vector< CUnit * > _Selected
 teams currently selected units More...
 
static std::vector< CUnit * > _TeamSelected [PlayerMax]
 save of Selected More...
 
static unsigned GroupId
 save of TeamSelected More...
 
bool IsOnlySelected (const CUnit &unit)
 Unique group # for automatic groups. More...
 
void SaveSelection ()
 Save selection to restore after. More...
 
void RestoreSelection ()
 Restore selection. More...
 
void UnSelectAll ()
 Clear current selection. More...
 
static void HandleSuicideClick (CUnit &unit)
 
static void ChangeSelectedUnits (CUnit **units, unsigned int count)
 
void ChangeTeamSelectedUnits (CPlayer &player, const std::vector< CUnit * > &units)
 Changed TeamUnit Selection. More...
 
int SelectUnit (CUnit &unit)
 Add a unit to selection. More...
 
void SelectSingleUnit (CUnit &unit)
 Select one unit as selection. More...
 
void UnSelectUnit (CUnit &unit)
 Remove a unit from selection. More...
 
int ToggleSelectUnit (CUnit &unit)
 Add a unit to selected if not already selected, remove it otherwise. More...
 
int SelectUnitsByType (CUnit &base)
 Select units from the same type (if selectable by rectangle) More...
 
int ToggleUnitsByType (CUnit &base)
 Toggle units from the same type (if selectable by rectangle) More...
 
int SelectGroup (int group_number, GroupSelectionMode mode)
 Select the units belonging to a particular group. More...
 
int AddGroupFromUnitToSelection (CUnit &unit)
 Add the units from the same group as the one in parameter. More...
 
int SelectGroupFromUnit (CUnit &unit)
 Select the units from the same group as the one in parameter. More...
 
static bool SelectOrganicUnitsInTable (std::vector< CUnit * > &table, bool added_table)
 
static void SelectSpritesInsideRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright, std::vector< CUnit * > &table)
 
int SelectUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select the units in the selection rectangle. More...
 
int AddSelectedUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add the units in the selection rectangle to the current selection. More...
 
int SelectGroundUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select ground units in the selection rectangle. More...
 
int SelectAirUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Select flying units in the selection rectangle. More...
 
int AddSelectedGroundUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add ground units in the selection rectangle to the current selection. More...
 
int AddSelectedAirUnitsInRectangle (const PixelPos &corner_topleft, const PixelPos &corner_bottomright)
 Add flying units in the selection rectangle to the current selection. More...
 
void SaveSelections (CFile &file)
 Save current selection state. More...
 
void CleanSelections ()
 Clean up selections. More...
 
static int CclSetGroupId (lua_State *l)
 
static int CclSelection (lua_State *l)
 
void SelectionCclRegister ()
 Register CCL selection features. More...
 

Function Documentation

◆ AddGroupFromUnitToSelection()

int AddGroupFromUnitToSelection ( CUnit unit)

Add the units from the same group as the one in parameter.

Add units from group of a particular unit to selection.

Parameters
unitunit belonging to the group to be selected.
Returns
0 if the unit doesn't belong to a group, or the number of units in the group.

◆ AddSelectedAirUnitsInRectangle()

int AddSelectedAirUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Add flying units in the selection rectangle to the current selection.

Add the air units in the rectangle to the current selection

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ AddSelectedGroundUnitsInRectangle()

int AddSelectedGroundUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Add ground units in the selection rectangle to the current selection.

Add the ground units in the rectangle to the current selection

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ AddSelectedUnitsInRectangle()

int AddSelectedUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Add the units in the selection rectangle to the current selection.

Add the units in the rectangle to the current selection

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the total number of units selected.

◆ CclSelection()

static int CclSelection ( lua_State *  l)
static

Define the current selection.

Parameters
lLua state.

◆ CclSetGroupId()

static int CclSetGroupId ( lua_State *  l)
static

Set the current group id. (Needed for load/save)

Parameters
lLua state.

◆ ChangeSelectedUnits()

static void ChangeSelectedUnits ( CUnit **  units,
unsigned int  count 
)
static

Replace a group of selected units by an other group of units.

Parameters
unitsArray of units to be selected.
countNumber of units in array to be selected.

◆ ChangeTeamSelectedUnits()

void ChangeTeamSelectedUnits ( CPlayer player,
const std::vector< CUnit * > &  units 
)

Changed TeamUnit Selection.

Change A Unit Selection from my Team

Parameters
playerThe Player who is selecting the units
unitsThe Units to add/remove

◆ CleanSelections()

void CleanSelections ( )

Clean up selections.

Clean up the selection module.

◆ HandleSuicideClick()

static void HandleSuicideClick ( CUnit unit)
static

Handle a suicide unit click

Parameters
unitsuicide unit.
Todo:
remove static (bug with save/load...)

◆ IsOnlySelected()

bool IsOnlySelected ( const CUnit unit)

Unique group # for automatic groups.

Check if unit is the currently only selected.

◆ RestoreSelection()

void RestoreSelection ( )

Restore selection.

Restore selection.

◆ SaveSelection()

void SaveSelection ( )

Save selection to restore after.

Save selection to restore after.

◆ SaveSelections()

void SaveSelections ( CFile file)

Save current selection state.

Save current selection state.

Parameters
fileOutput file.

◆ SelectAirUnitsInRectangle()

int SelectAirUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Select flying units in the selection rectangle.

Select own air units in a rectangle.

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ SelectGroundUnitsInRectangle()

int SelectGroundUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Select ground units in the selection rectangle.

Select own ground units in a rectangle.

Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ SelectGroup()

int SelectGroup ( int  group_number,
GroupSelectionMode  mode 
)

Select the units belonging to a particular group.

Change selected units to units from group group_number Doesn't change the selection if the group has no unit.

Parameters
group_numbernumber of the group to be selected.
Returns
number of units in the group.

◆ SelectGroupFromUnit()

int SelectGroupFromUnit ( CUnit unit)

Select the units from the same group as the one in parameter.

Select units from group of a particular unit. Doesn't change the selection if the group has no unit, or the unit doesn't belong to any group.

Parameters
unitunit belonging to the group to be selected.
Returns
0 if the unit doesn't belong to a group, or the number of units in the group.

◆ SelectionCclRegister()

void SelectionCclRegister ( )

Register CCL selection features.

Register CCL features for selections.

◆ SelectOrganicUnitsInTable()

static bool SelectOrganicUnitsInTable ( std::vector< CUnit * > &  table,
bool  added_table 
)
static

Select the units selectable by rectangle in a local table. Act like a filter: The source table is modified. Return the original table if no unit is found.

Parameters
tableInput/Output table of units.

return true if at least a unit is found;

◆ SelectSingleUnit()

void SelectSingleUnit ( CUnit unit)

Select one unit as selection.

Select a single unit, unselecting the previous ones

Parameters
unitPointer to unit to be selected.

◆ SelectSpritesInsideRectangle()

static void SelectSpritesInsideRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright,
std::vector< CUnit * > &  table 
)
static

Selects units from the table whose sprite is at least partially covered by the rectangle. The rectangle is determined by coordinates of its upper left and lower right corner expressed in screen map coordinate system.

Parameters
corner_topleftcoord of upper left corner of the rectangle
corner_bottomrightcoord of lower right corner of the rectangle
tabletable of units
Returns
number of units found

◆ SelectUnit()

int SelectUnit ( CUnit unit)

Add a unit to selection.

Add a unit to the other selected units.

Parameters
unitPointer to unit to add.
Returns
true if added to selection, false otherwise (if Selected.size() == MaxSelectable or unit is already selected or unselectable)

◆ SelectUnitsByType()

int SelectUnitsByType ( CUnit base)

Select units from the same type (if selectable by rectangle)

Select units from a particular type and belonging to the local player.

The base is included in the selection and defines the type of the other units to be selected.

Parameters
baseSelect all units of same type.
Returns
Number of units found, 0 means selection unchanged

FIXME: 0 can't happen. Maybe when scripting will use it?

FIXME: should always select the nearest 9 units to the base!

◆ SelectUnitsInRectangle()

int SelectUnitsInRectangle ( const PixelPos corner_topleft,
const PixelPos corner_bottomright 
)

Select the units in the selection rectangle.

Select units in a rectangle. Proceed in order in none found:

  • select local player mobile units
  • select one local player static unit (random)
  • select one neutral unit (critter, mine...)
  • select one enemy unit (random)
Parameters
corner_topleft,startof selection rectangle
corner_bottomrightend of selection rectangle
Returns
the number of units found.

◆ ToggleSelectUnit()

int ToggleSelectUnit ( CUnit unit)

Add a unit to selected if not already selected, remove it otherwise.

Toggle the selection of a unit in a group of selected units

Parameters
unitPointer to unit to be toggled.
Returns
0 if unselected, 1 otherwise Toggle the selection of a unit in a group of selected units
Parameters
unitPointer to unit to be toggled.
Returns
0 if unselected, 1 otherwise

◆ ToggleUnitsByType()

int ToggleUnitsByType ( CUnit base)

Toggle units from the same type (if selectable by rectangle)

Toggle units from a particular type and belonging to the local player.

The base is included in the selection and defines the type of the other units to be selected.

Parameters
baseToggle all units of same type.
Returns
Number of units found, 0 means selection unchanged

FIXME: toggle not written FIXME: should always select the nearest 9 units to the base!

◆ UnSelectAll()

void UnSelectAll ( )

Clear current selection.

Unselect all the units in the current selection

◆ UnSelectUnit()

void UnSelectUnit ( CUnit unit)

Remove a unit from selection.

Unselect unit

Parameters
unitPointer to unit to be unselected.

Variable Documentation

◆ _Selected

std::vector<CUnit *> _Selected
static

teams currently selected units

◆ _TeamSelected

std::vector<CUnit *> _TeamSelected[PlayerMax]
static

save of Selected

◆ GroupId

unsigned GroupId
static

save of TeamSelected

◆ MaxSelectable

unsigned int MaxSelectable

◆ Selected

std::vector<CUnit *> Selected

Maximum number of selected units.

How many units could be selected.

◆ TeamSelected

std::vector<CUnit *> TeamSelected[PlayerMax]
static

All selected units.

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.