IsSelected renamed to IsOnlySelect. Perpared new group functions.

This commit is contained in:
johns 2001-04-19 22:18:30 +00:00
parent 601fae0a6a
commit 3f09b137eb
16 changed files with 219 additions and 90 deletions

View file

@ -150,9 +150,10 @@ local void EnterTransporter(Unit* unit)
for( i=0; i<sizeof(unit->OnBoard)/sizeof(*unit->OnBoard); ++i ) {
if( transporter->OnBoard[i]==NoUnitP ) {
transporter->OnBoard[i]=unit;
// FIXME: reference counts?
transporter->Value++;
RemoveUnit(unit);
if( IsSelected(transporter) ) {
if( IsOnlySelected(transporter) ) {
UpdateButtonPanel();
MustRedraw|=RedrawPanels;
}

View file

@ -79,7 +79,7 @@ global void HandleActionBuild(Unit* unit)
unit->Orders[0].Action=UnitActionStill;
unit->SubAction=0;
if( IsSelected(unit) ) { // update display for new action
if( unit->Selected ) { // update display for new action
UpdateButtonPanel();
}
@ -125,7 +125,7 @@ global void HandleActionBuild(Unit* unit)
unit->Orders[0].Action=UnitActionStill;
unit->SubAction=0;
if( IsSelected(unit) ) { // update display for new action
if( unit->Selected ) { // update display for new action
UpdateButtonPanel();
}
@ -292,7 +292,7 @@ global void HandleActionBuilded(Unit* unit)
UpdateForNewUnit(unit,0);
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
UpdateButtonPanel();
MustRedraw|=RedrawPanels;
} else if( unit->Player==ThisPlayer ) {
@ -319,7 +319,7 @@ global void HandleActionBuilded(Unit* unit)
}
unit->Wait=5;
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
MustRedraw|=RedrawInfoPanel;
}
}

View file

@ -66,7 +66,7 @@ global void HandleActionFollow(Unit* unit)
unit->Wait=1;
unit->SubAction=0;
unit->Orders[0].Action=UnitActionStill;
if( IsSelected(unit) ) { // update display for new action
if( IsOnlySelected(unit) ) { // update display for new action
UpdateButtonPanel();
}
return;
@ -101,7 +101,7 @@ global void HandleActionFollow(Unit* unit)
unit->Wait=1;
unit->SubAction=0;
unit->Orders[0].Action=UnitActionStill;
if( IsSelected(unit) ) { // update display for new action
if( IsOnlySelected(unit) ) { // update display for new action
UpdateButtonPanel();
}
return;

View file

@ -263,7 +263,7 @@ global void HandleActionMove(Unit* unit)
unit->Orders[0].Goal=NoUnitP;
}
unit->Orders[0].Action=UnitActionStill;
if( IsSelected(unit) ) { // update display for new action
if( unit->Selected ) { // update display for new action
UpdateButtonPanel();
}
return;

View file

@ -121,7 +121,7 @@ local void RepairUnit(Unit* unit,Unit* goal)
if ( CheckUnitToBeDrawn(goal) ) {
MustRedraw|=RedrawMinimap;
}
if( IsSelected(goal) ) { // Update panel if unit is selected
if( IsOnlySelected(goal) ) { // Update panel if unit is selected
MustRedraw|=RedrawInfoPanel;
}
}

View file

@ -80,7 +80,7 @@ global void HandleActionResearch(Unit* unit)
return;
}
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
MustRedraw|=RedrawInfoPanel;
}

View file

@ -185,7 +185,7 @@ local int WaitInResource(Unit* unit,const Resource* resource)
//
source=resource->ResourceOnMap(unit->X,unit->Y);
IfDebug(
DebugLevel3Fn("Found %d,%d=%Zd\n",unit->X,unit->Y
DebugLevel2Fn("Found %d,%d=%Zd\n",unit->X,unit->Y
,UnitNumber(source));
if( !source ) {
DebugLevel0Fn("No unit? (%d,%d)\n",unit->X,unit->Y);
@ -202,7 +202,7 @@ local int WaitInResource(Unit* unit,const Resource* resource)
source->Frame=0;
CheckUnitToBeDrawn(source);
}
if( IsSelected(source) ) {
if( IsOnlySelected(source) ) {
MustRedraw|=RedrawInfoPanel;
}
@ -210,9 +210,7 @@ local int WaitInResource(Unit* unit,const Resource* resource)
// End of resource: destroy the resource.
//
if( source->Value<DEFAULT_INCOMES[resource->Cost] ) {
unit->Removed=0; // BUG ALERT: Unit not dropped out!
DropOutAll(source);
unit->Removed=1;
DestroyUnit(source);
source=NULL;
}
@ -237,8 +235,6 @@ local int WaitInResource(Unit* unit,const Resource* resource)
if( source ) {
DropOutOnSide(unit,LookingW
,source->Type->TileWidth,source->Type->TileHeight);
} else {
DropOutOnSide(unit,LookingW,1,1);
}
unit->Orders[0].Action=UnitActionStill;
unit->SubAction=0;
@ -248,9 +244,6 @@ local int WaitInResource(Unit* unit,const Resource* resource)
DropOutNearest(unit,depot->X+depot->Type->TileWidth/2
,depot->Y+depot->Type->TileHeight/2
,source->Type->TileWidth,source->Type->TileHeight);
} else {
DropOutNearest(unit,depot->X+depot->Type->TileWidth/2
,depot->Y+depot->Type->TileHeight/2,1,1);
}
unit->Orders[0].Goal=depot;
RefsDebugCheck( !depot->Refs );
@ -258,11 +251,12 @@ local int WaitInResource(Unit* unit,const Resource* resource)
unit->Orders[0].RangeX=unit->Orders[0].RangeY=1;
unit->Orders[0].X=unit->Orders[0].Y=-1;
unit->Orders[0].Action=resource->Action;
unit->SubAction=64;
NewResetPath(unit);
}
CheckUnitToBeDrawn(unit);
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
UpdateButtonPanel();
MustRedraw|=RedrawButtonPanel;
}

View file

@ -113,20 +113,29 @@ global void HandleActionTrain(Unit* unit)
unit->SubAction=0;
}
if( unit->NewOrder.Goal ) {
if( unit->NewOrder.Goal->Destroyed ) {
DebugLevel0Fn("Destroyed unit in train unit\n");
RefsDebugCheck( !unit->NewOrder.Goal->Refs );
if( !--unit->NewOrder.Goal->Refs ) {
ReleaseUnit(unit->NewOrder.Goal);
}
unit->NewOrder.Goal=NoUnitP;
unit->NewOrder.Action=UnitActionStill;
}
}
nunit->Orders[0]=unit->NewOrder;
//
// FIXME: Pending command uses any references?
//
if( nunit->Orders[0].Goal ) {
if( nunit->Orders[0].Goal->Destroyed ) {
DebugLevel0Fn("FIXME: you have found a bug, please fix it.\n");
}
RefsDebugCheck( !nunit->Orders[0].Goal->Refs );
nunit->Orders[0].Goal->Refs++;
}
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
UpdateButtonPanel();
MustRedraw|=RedrawPanels;
}
@ -134,7 +143,7 @@ global void HandleActionTrain(Unit* unit)
return;
}
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
MustRedraw|=RedrawInfoPanel;
}

View file

@ -115,7 +115,7 @@ local void LeaveTransporter(Unit* unit)
}
}
}
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
UpdateButtonPanel();
MustRedraw|=RedrawPanels;
}

View file

@ -83,7 +83,7 @@ global void HandleActionUpgradeTo(Unit* unit)
//
// Update possible changed buttons.
//
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
UpdateButtonPanel();
MustRedraw|=RedrawPanels;
} else if( player==ThisPlayer ) {
@ -94,7 +94,7 @@ global void HandleActionUpgradeTo(Unit* unit)
return;
}
if( IsSelected(unit) ) {
if( IsOnlySelected(unit) ) {
MustRedraw|=RedrawInfoPanel;
}

View file

@ -297,7 +297,7 @@ local void HandleUnitAction(Unit* unit)
unit->SubAction=unit->State=0;
unit->Wait=1;
if( IsSelected(unit) ) { // update display for new action
if( IsOnlySelected(unit) ) {// update display for new action
UpdateButtonPanel();
MustRedraw|=RedrawInfoPanel;
}

View file

@ -184,6 +184,14 @@
**
** Unit::GroupId
**
** Number of the group to that the unit belongs. This is the main
** group showed on map, an unit can belong to many groups.
**
** Unit::LastGroup
**
** Automatic group number, to reselect the same units. When the
** user selects more than one unit all units is given the next
** same number. (Used for ALT-CLICK)
**
** Unit::Value
**
@ -433,6 +441,7 @@ struct _unit_ {
unsigned UnholyArmor; /// ticks unholy armor
unsigned GroupId; /// unit belongs to this group id
unsigned LastGroup; /// unit belongs to this last group
unsigned Value; /// value used for much
@ -792,9 +801,7 @@ extern void RemoveUnitFromGroup(Unit *unit);
// in selection.c
/// Check if unit is the currently only selected
// FIXME: lokh: Is it necessary to check if NumSelected==1?
// Maybe we can add a #define IsOnlySelected(unit)?
#define IsSelected(unit) (NumSelected==1 && Selected[0]==(unit))
#define IsOnlySelected(unit) (NumSelected==1 && Selected[0]==(unit))
/// Clear current selection
extern void UnSelectAll(void);

View file

@ -39,11 +39,12 @@
-- Variables
----------------------------------------------------------------------------*/
// FIXME?: wanted to use 'SelectionGroup' but it is already used
// in the unitsound.c file...
typedef struct _group_ {
Unit *units[NUM_UNITS_PER_GROUP];
int num_units;
/**
** Defines a group of units.
*/
typedef struct _unit_group_ {
Unit *units[NUM_UNITS_PER_GROUP]; /// Units in the group
int num_units; /// How many units in the group
} UnitGroup; /// group of units
global UnitGroup Groups[NUM_GROUPS]; /// Number of groups predefined

View file

@ -53,12 +53,13 @@ global Unit* Selected[MaxSelectable] = {
*/
global void UnSelectAll(void)
{
Unit *u;
Unit *unit;
while( NumSelected ) {
u=Selected[--NumSelected];
unit=Selected[--NumSelected];
Selected[NumSelected]=NoUnitP; // FIXME: only needed for old code
u->Selected=0;
CheckUnitToBeDrawn(u);
unit->Selected=0;
CheckUnitToBeDrawn(unit);
}
}

View file

@ -25,7 +25,8 @@
#include "freecraft.h"
#include "video.h"
#include "sound_id.h"
#include "unitsound.h"
#include "sound.h"
#include "sound_server.h"
#include "unittype.h"
#include "player.h"
#include "unit.h"
@ -80,6 +81,124 @@ local void ShowInput(void)
SetStatusLine(input);
}
/**
** Begin input.
*/
local void BeginInput(void)
{
KeyState=KeyStateInput;
Input[0]='\0';
InputIndex=0;
ShowInput();
}
//-----------------------------------------------------------------------------
// User interface group commands
//-----------------------------------------------------------------------------
// Johns: I make small functions to allow later new keyboard bindings.
/**
** Unselect all currently selected units.
*/
local void UiUnselectAll(void)
{
UnSelectAll();
UpdateButtonPanel();
}
/**
** Select group. If already selected center on the group.
**
** @param group Group number to select.
*/
local void UiSelectGroup(unsigned group)
{
SelectGroup(group);
UpdateButtonPanel();
MustRedraw|=RedrawCursor|RedrawMap|RedrawPanels;
}
/**
** Add group to current selection.
**
** @param group Group number to add.
*/
local void UiAddGroupToSelection(unsigned group)
{
SelectGroup(group);
UpdateButtonPanel();
MustRedraw|=RedrawCursor|RedrawMap|RedrawPanels;
}
/**
** Define a group. The current selected units become a new group.
**
** @param group Group number to create.
*/
local void UiDefineGroup(unsigned group)
{
SetGroup(Selected,NumSelected,group);
}
/**
** Add to group. The current selected units are added to the group.
**
** @param group Group number to be expanded.
*/
local void UiAddToGroup(unsigned group)
{
}
/**
** Define an alternate group. The current selected units become a new
** group. But remains in the old group.
**
** @param group Group number to create.
*/
local void UiDefineAlternateGroup(unsigned group)
{
SetGroup(Selected,NumSelected,group);
}
/**
** Add to alternate group. The current selected units are added to the
** group. But remains in the old group.
**
** @param group Group number to be expanded.
*/
local void UiAddToAlternateGroup(unsigned group)
{
}
/**
** Toggle sound on / off.
*/
local void UiToggleSound(void)
{
if( SoundFildes != -1 ) {
SoundOff^=1;
}
if( SoundOff ) {
SetMessage("Sound is off.");
} else {
SetMessage("Sound is off.");
}
}
/**
** Toggle pause on / off.
*/
local void UiTogglePause(void)
{
GamePaused^=1;
if(GamePaused) {
SetStatusLine("Game Paused");
} else {
SetStatusLine("Game Resumed");
}
}
/**
** Handle keys in command mode.
**
@ -90,45 +209,35 @@ local int CommandKey(int key)
{
switch( key ) {
case '\r': // Return enters chat/input mode.
KeyState=KeyStateInput;
Input[0]='\0';
InputIndex=0;
ShowInput();
BeginInput();
return 1;
case '^': // Unselect everything
UnSelectAll();
UpdateButtonPanel();
UiUnselectAll();
break;
case '0': // Group selection
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '0': case '1': case '2': // Group selection
case '3': case '4': case '5':
case '6': case '7': case '8':
case '9':
if( KeyModifiers&ModifierShift ) {
DebugLevel0("FIXME: not written\n");
if( KeyModifiers&ModifierAlt ) {
UiAddToAlternateGroup(key-'0');
} else if( KeyModifiers&ModifierControl ) {
UiAddToGroup(key-'0');
} else {
UiAddGroupToSelection(key-'0');
}
} else {
if( KeyModifiers&ModifierAlt ) {
UiDefineAlternateGroup(key-'0');
} else if( KeyModifiers&ModifierControl ) {
UiDefineGroup(key-'0');
} else {
UiSelectGroup(key-'0');
}
}
if( KeyModifiers&ModifierAlt ) {
DebugLevel0("FIXME: not written\n");
}
if( KeyModifiers&ModifierHyper ) {
DebugLevel0("FIXME: not written\n");
}
if( KeyModifiers&ModifierControl ) {
// dirty atoi version :)
SetGroup(Selected,NumSelected,key-48);
// FIXME: center on group??
} else {
SelectGroup(key-48);
}
// FIXME: this should be moved into the select/group functions.
UpdateButtonPanel();
MustRedraw|=RedrawCursor|RedrawMap|RedrawPanels;
break;
#if 0
IfDebug(
case '0':
@ -149,19 +258,14 @@ local int CommandKey(int key)
);
#endif
case 'p'&0x1F:
case 'p': // If pause-key didn't work
case 'P':
case 'P': // CTRL-P, ALT-P Toggle pause
if( !(KeyModifiers&(ModifierAlt|ModifierControl)) ) {
break;
}
case KeyCodePause:
if(GamePaused) {
GamePaused=0;
SetStatusLine("Game Resumed");
} else {
GamePaused=1;
SetStatusLine("Game Paused");
}
UiTogglePause();
break;
case KeyCodeF1:
@ -206,6 +310,10 @@ local int CommandKey(int key)
SetStatusLine("Slower");
break;
case 's'&0x1F: // Ctrl + S - Turn sound on / off
UiToggleSound();
break;
case 's': // ALT s F11 save game menu
case 'S':
if( !(KeyModifiers&ModifierAlt) ) {
@ -222,6 +330,7 @@ local int CommandKey(int key)
}
break;
case 'g'&0x1F:
case 'g':
case 'G': // ALT+G, CTRL+G grab mouse pointer
if( !(KeyModifiers&(ModifierAlt|ModifierControl)) ) {
@ -231,6 +340,7 @@ local int CommandKey(int key)
ToggleGrabMouse();
break;
case 'f'&0x1F:
case 'f':
case 'F': // toggle fullscreen
if( !(KeyModifiers&(ModifierAlt|ModifierControl)) ) {
@ -260,6 +370,7 @@ local int CommandKey(int key)
MustRedraw|=RedrawMinimap;
break;
case 'x'&0x1F:
case 'x':
case 'X': // ALT+X, CTRL+X: Exit game
if( !(KeyModifiers&(ModifierAlt|ModifierControl)) ) {
@ -267,6 +378,7 @@ local int CommandKey(int key)
}
Exit(0);
case 'q'&0x1F:
case 'q':
case 'Q': // ALT+Q, CTRL+Q: Quit level
if( !(KeyModifiers&(ModifierAlt|ModifierControl)) ) {

View file

@ -511,23 +511,27 @@ global void UIHandleMouseMove(int x,int y)
int xo = MapX, yo = MapY;
if ( TheUI.ReverseMouseMove ) {
if (x < CursorStartX)
if (x < CursorStartX) {
xo++;
else if (x > CursorStartX)
} else if (x > CursorStartX) {
xo--;
if (y < CursorStartY)
}
if (y < CursorStartY) {
yo++;
else if (y > CursorStartY)
} else if (y > CursorStartY) {
yo--;
}
} else {
if (x < CursorStartX)
if (x < CursorStartX) {
xo--;
else if (x > CursorStartX)
} else if (x > CursorStartX) {
xo++;
if (y < CursorStartY)
}
if (y < CursorStartY) {
yo--;
else if (y > CursorStartY)
} else if (y > CursorStartY) {
yo++;
}
}
TheUI.WarpX = CursorStartX;
TheUI.WarpY = CursorStartY;