[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: next unit gameplay



Le 18/03/2014 19:51, Jens Granseuer a Ãcrit :

Hi SÃbastien, and welcome to CF.

Thanks for your patch. It looks quite useful. Maybe we can even improve
the behaviour a little more. How about this: If you press the shortcut
and there is a unit under the cursor, check whether it is still active
(ie. can be selected but isn't). If so select this unit, otherwise
select the next one in the list (just the way you do now). It currently
feels a little strange that the cursor moves away from the unit it
hovers over even if it would be perfectly legit to select it.

Does that sound good to you?

Sorry if I'm a little slow to respond, btw. I'm somewhat busy these
days...


Hi,

Tell me if it is satisfying for you.

--
SÃbastien
diff -urNp crimson-0.5.3_orig/src/cf/game.cpp crimson-0.5.3/src/cf/game.cpp
--- crimson-0.5.3_orig/src/cf/game.cpp	2007-06-24 17:30:18.000000000 +0200
+++ crimson-0.5.3/src/cf/game.cpp	2014-03-18 22:12:54.000000000 +0100
@@ -1223,6 +1223,25 @@ void Game::DeselectUnit( bool display /*
 }
 
 ////////////////////////////////////////////////////////////////////////
+// NAME       : Game::checkUnitForSelection
+// DESCRIPTION: Check if the unit match the required for beeing selected
+//              and select it if it does
+// PARAMETERS : u - unit to be selected
+// RETURNS    : TRUE if the unit has been selected
+//              FALSE otherwise.
+////////////////////////////////////////////////////////////////////////
+
+bool Game::checkUnitForSelection( Unit *u ) {
+  if ( (u->Owner() == &mission->GetPlayer()) && u->IsReady() && !u->IsSheltered() ) {
+    // we ignore SHELTERED units because it wouldn't be obvious which
+    // of the units inside the transport was selected
+    SelectUnit( u );
+    return true;
+  }
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////////
 // NAME       : Game::SelectNextUnit
 // DESCRIPTION: Select the current player's next available unit.
 // PARAMETERS : -
@@ -1233,19 +1252,26 @@ void Game::SelectNextUnit( void ) {
   List &units = mission->GetUnits();
   Unit *start, *u;
 
-  if ( unit ) start = unit;
-  else start = static_cast<Unit *>( units.Head() );
+  if ( unit ) {
+      start = unit;
+  } else {
+    // look for any unit under the cursor
+    MapView *mv = mwin->GetMapView();
+    Point cursor = mv->Cursor();
+    Unit *u = mission->GetMap().GetUnit( cursor );
+    if (u) {
+      if ( checkUnitForSelection( u ) ) return;
+      else start = u;
+    } else {
+      start = static_cast<Unit *>( units.Head() );
+    }
+  }
 
   u = static_cast<Unit *>( units.NextNode(start) );
 
   while ( u && (u != start) ) {
 
-    if ( (u->Owner() == &mission->GetPlayer()) && u->IsReady() && !u->IsSheltered() ) {
-      // we ignore SHELTERED units because it wouldn't be obvious which
-      // of the units inside the transport was selected
-      SelectUnit( u );
-      break;
-    }
+    if ( checkUnitForSelection( u ) ) break;
 
     u = static_cast<Unit *>( units.NextNode(u) );
   }
diff -urNp crimson-0.5.3_orig/src/cf/game.h crimson-0.5.3/src/cf/game.h
--- crimson-0.5.3_orig/src/cf/game.h	2007-05-18 17:24:43.000000000 +0200
+++ crimson-0.5.3/src/cf/game.h	2014-03-18 22:07:02.000000000 +0100
@@ -106,6 +106,7 @@ private:
   void ScrollCommand( int key );
   void HandleLMB( const Point &hex );
   void EnterSpecialMode( unsigned char mode );
+  bool checkUnitForSelection( Unit *u);
   void SelectNextUnit( void );
   void RemoveUnit( Unit *u );
   void Undo( void );