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

src/stratagus/selection.cpp File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include "unittype.h"
#include "player.h"
#include "unit.h"
#include "unit_manager.h"
#include "interface.h"
#include "map.h"
#include "tileset.h"
#include "ui.h"
#include "commands.h"
#include "network.h"
#include "iolib.h"
#include "script.h"

selection.cpp - The units' selection.

int NumSelected
 teams currently selected units
int TeamNumSelected [PlayerMax]
 Number of selected units.
int MaxSelectable
 How many units selected.
CUnit ** Selected
 Maximum number of selected units.
CUnit ** TeamSelected [PlayerMax]
 All selected units.
static int _NumSelected
 teams currently selected units
static int _TeamNumSelected [PlayerMax]
 save of NumSelected
static CUnit ** _Selected
 save of TeamNumSelected
static CUnit ** _TeamSelected [PlayerMax]
 save of Selected
static unsigned GroupId
 save of TeamSelected
void SaveSelection ()
 Unique group # for automatic groups.
void RestoreSelection ()
 Restore selection.
void UnSelectAll ()
 Clear current selection.
static void HandleSuicideClick (CUnit &unit)
void ChangeSelectedUnits (CUnit **units, int count)
 Select group as selection.
void ChangeTeamSelectedUnits (CPlayer &player, CUnit **units, int adjust, int count)
 Changed TeamUnit Selection.
int SelectUnit (CUnit &unit)
 Add a unit to selection.
void SelectSingleUnit (CUnit &unit)
 Select one unit as selection.
void UnSelectUnit (CUnit &unit)
 Remove a unit from selection.
int ToggleSelectUnit (CUnit &unit)
 Add a unit to selected if not already selected, remove it otherwise.
int SelectUnitsByType (CUnit &base)
 Select units from the same type (if selectable by rectangle).
int ToggleUnitsByType (CUnit &base)
 Toggle units from the same type (if selectable by rectangle).
int SelectGroup (int group_number, GroupSelectionMode mode)
 Select the units belonging to a particular group.
int AddGroupFromUnitToSelection (CUnit &unit)
 Add the units from the same group as the one in parameter.
int SelectGroupFromUnit (CUnit &unit)
 Select the units from the same group as the one in parameter.
static int SelectOrganicUnitsInTable (CUnit **table, int num_units)
static int SelectSpritesInsideRectangle (int sx0, int sy0, int sx1, int sy1, CUnit **table, int num_units)
static int DoSelectUnitsInRectangle (int sx0, int sy0, int sx1, int sy1, CUnit **table, int num_units=UnitMax)
int SelectUnitsInRectangle (int sx0, int sy0, int sx1, int sy1)
 Select the units in the selection rectangle.
int AddSelectedUnitsInRectangle (int x0, int y0, int x1, int y1)
 Add the units in the selection rectangle to the current selection.
static int DoSelectGroundUnitsInRectangle (int sx0, int sy0, int sx1, int sy1, CUnit **table, int num_units=UnitMax)
int SelectGroundUnitsInRectangle (int sx0, int sy0, int sx1, int sy1)
 Select ground units in the selection rectangle.
int DoSelectAirUnitsInRectangle (int sx0, int sy0, int sx1, int sy1, CUnit **table)
int SelectAirUnitsInRectangle (int sx0, int sy0, int sx1, int sy1)
 Select flying units in the selection rectangle.
int AddSelectedGroundUnitsInRectangle (int sx0, int sy0, int sx1, int sy1)
 Add ground units in the selection rectangle to the current selection.
int AddSelectedAirUnitsInRectangle (int sx0, int sy0, int sx1, int sy1)
 Add flying units in the selection rectangle to the current selection.
void InitSelections ()
 Init selections.
void SaveSelections (CFile *file)
 Save current selection state.
void CleanSelections ()
 Clean up selections.
static int CclSetGroupId (lua_State *l)
static int CclSelection (lua_State *l)
void SelectionCclRegister ()
 Register CCL selection features.

Function Documentation

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:
unit unit 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.

int AddSelectedAirUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

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

Add the air units in the rectangle to the current selection

Parameters:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
Returns:
the number of units found.

int AddSelectedGroundUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

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

Add the ground units in the rectangle to the current selection

Parameters:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
Returns:
the number of units found.

int AddSelectedUnitsInRectangle ( int  x0,
int  y0,
int  x1,
int  y1 
)

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

Add the units in the rectangle to the current selection

Parameters:
x0 X start of selection rectangle in tile coordinates
y0 Y start of selection rectangle in tile coordinates
x1 X start of selection rectangle in tile coordinates
y1 Y start of selection rectangle in tile coordinates
Returns:
the _total_ number of units selected.

static int CclSelection ( lua_State *  l  )  [static]

Define the current selection.

Parameters:
l Lua state.

static int CclSetGroupId ( lua_State *  l  )  [static]

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

Parameters:
l Lua state.

void ChangeSelectedUnits ( CUnit **  units,
int  count 
)

Select group as selection.

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

Parameters:
units Array of units to be selected.
count Number of units in array to be selected.

void ChangeTeamSelectedUnits ( CPlayer player,
CUnit **  units,
int  adjust,
int  count 
)

Changed TeamUnit Selection.

Change A Unit Selection from my Team

Parameters:
player The Player who is selecting the units
units The Units to add/remove
adjust 0 = reset, 1 = remove units, 2 = add units
count the number of units to be adjusted

void CleanSelections (  ) 

Clean up selections.

Clean up the selection module.

int DoSelectAirUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1,
CUnit **  table 
)

static int DoSelectGroundUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1,
CUnit **  table,
int  num_units = UnitMax 
) [static]

static int DoSelectUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1,
CUnit **  table,
int  num_units = UnitMax 
) [static]

static void HandleSuicideClick ( CUnit unit  )  [static]

Handle a suicide unit click

Parameters:
unit suicide unit.

void InitSelections (  ) 

Init selections.

Initialize the selection module.

void RestoreSelection (  ) 

Restore selection.

Restore selection.

void SaveSelection (  ) 

Unique group # for automatic groups.

Save selection to restore after.

Save selection to restore after.

void SaveSelections ( CFile file  ) 

Save current selection state.

Save current selection state.

Parameters:
file Output file.

int SelectAirUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

Select flying units in the selection rectangle.

Select own air units in a rectangle.

Parameters:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
Returns:
the number of units found.

int SelectGroundUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

Select ground units in the selection rectangle.

Select own ground units in a rectangle.

Parameters:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
Returns:
the number of units found.

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_number number of the group to be selected.
Returns:
number of units in the group.

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:
unit unit 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.

void SelectionCclRegister (  ) 

Register CCL selection features.

Register CCL features for selections.

static int SelectOrganicUnitsInTable ( CUnit **  table,
int  num_units 
) [static]

Select the units selecteable 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:
table Input/Output table of units.
num_units Number of units in input table.
Returns:
the number of units found.

void SelectSingleUnit ( CUnit unit  ) 

Select one unit as selection.

Select a single unit, unselecting the previous ones

Parameters:
unit Pointer to unit to be selected.

static int SelectSpritesInsideRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1,
CUnit **  table,
int  num_units 
) [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:
sx0 x-coord of upper left corner of the rectangle
sy0 y-coord of upper left corner of the rectangle
sx1 x-coord of lower right corner of the rectangle
sy1 y-coord of lower right corner of the rectangle
table table of units
num_units number of units in table
Returns:
number of units found

int SelectUnit ( CUnit unit  ) 

Add a unit to selection.

Add a unit to the other selected units.

Parameters:
unit Pointer to unit to add.
Returns:
true if added to selection, false otherwise (if NumSelected == MaxSelectable or unit is already selected or unselectable)

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:
base Select 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!

int SelectUnitsInRectangle ( int  sx0,
int  sy0,
int  sx1,
int  sy1 
)

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:
sx0 X start of selection rectangle in tile coordinates
sy0 Y start of selection rectangle in tile coordinates
sx1 X start of selection rectangle in tile coordinates
sy1 Y start of selection rectangle in tile coordinates
Returns:
the number of units found.

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:
unit Pointer to unit to be toggled.
Returns:
0 if unselected, 1 otherwise

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:
base Toggle 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!

void UnSelectAll (  ) 

Clear current selection.

Unselect all the units in the current selection

void UnSelectUnit ( CUnit unit  ) 

Remove a unit from selection.

Unselect unit

Parameters:
unit Pointer to unit to be unselected.


Variable Documentation

int _NumSelected [static]

teams currently selected units

CUnit** _Selected [static]

save of TeamNumSelected

int _TeamNumSelected[PlayerMax] [static]

save of NumSelected

CUnit** _TeamSelected[PlayerMax] [static]

save of Selected

unsigned GroupId [static]

save of TeamSelected

How many units selected.

teams currently selected units

Maximum number of selected units.

How many units could be selected.

int TeamNumSelected[PlayerMax]

Number of selected units.

how many units selected

CUnit** TeamSelected[PlayerMax]

All selected units.

currently selected units

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