Author: sveinung
Date: Tue Apr 21 16:35:45 2015
New Revision: 28834

URL: http://svn.gna.org/viewcvs/freeciv?rev=28834&view=rev
Log:
Sort by state kind when sorting the nations tab by diplomatic state.

Where in the alphabet the name of a diplomatic state appears doesn't say all
that much about it. Sort by how "close" a state is in stead.

Reported anonymously

Patch by Hauke Henningsen <addaleax>

See bug #23420

Modified:
    branches/S2_6/client/plrdlg_common.c

Modified: branches/S2_6/client/plrdlg_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/plrdlg_common.c?rev=28834&r1=28833&r2=28834&view=diff
==============================================================================
--- branches/S2_6/client/plrdlg_common.c        (original)
+++ branches/S2_6/client/plrdlg_common.c        Tue Apr 21 16:35:45 2015
@@ -118,6 +118,54 @@
       return diplstate_type_translated_name(pds->type);
     }
   }
+}
+
+/******************************************************************
+ Return a numerical value suitable for ordering players by
+ their diplomatic status in the players dialog
+ 
+ A lower value stands for more friendly diplomatic status.
+*******************************************************************/
+static int diplstate_value(const struct player *plr)
+{
+  /* these values are scaled so that adding/subtracting
+     the number of turns left makes sense */
+  static const int diplstate_cmp_lookup[DS_LAST] = {
+    [DS_TEAM] = 1 << 16,
+    [DS_ALLIANCE] = 2 << 16,
+    [DS_PEACE] = 3 << 16,
+    [DS_ARMISTICE] = 4 << 16,
+    [DS_CEASEFIRE] = 5 << 16,
+    [DS_WAR] = 6 << 16,
+    [DS_NO_CONTACT] = 7 << 16
+  };
+  
+  const struct player_diplstate *pds;
+  int ds_value;
+  
+  if (NULL == client.conn.playing || plr == client.conn.playing) {
+    /* current global player is as close as players get
+       -> return value smaller than for DS_TEAM */
+    return 0;
+  }
+  
+  pds = player_diplstate_get(client.conn.playing, plr);
+  ds_value = diplstate_cmp_lookup[pds->type];
+  
+  if (pds->type == DS_ARMISTICE || pds->type == DS_CEASEFIRE) {
+    ds_value += pds->turns_left;
+  }
+  
+  return ds_value;
+}
+
+/******************************************************************
+ Compares diplomatic status of two players in players dialog
+*******************************************************************/
+static int cmp_diplstate(const struct player *player1,
+                         const struct player *player2)
+{
+  return diplstate_value(player1) - diplstate_value(player2);
 }
 
 /******************************************************************
@@ -264,7 +312,8 @@
   {TRUE, COL_BOOLEAN, N_("AI"), NULL, col_ai, NULL,  "ai"},
   {TRUE, COL_TEXT, N_("Attitude"), col_love, NULL, cmp_love,  "attitude"},
   {TRUE, COL_TEXT, N_("Embassy"), col_embassy, NULL, NULL,  "embassy"},
-  {TRUE, COL_TEXT, N_("Dipl.State"), col_diplstate, NULL, NULL,  "diplstate"},
+  {TRUE, COL_TEXT, N_("Dipl.State"), col_diplstate, NULL, cmp_diplstate,
+    "diplstate"},
   {TRUE, COL_TEXT, N_("Vision"), col_vision, NULL, NULL,  "vision"},
   {TRUE, COL_TEXT, N_("State"), plrdlg_col_state, NULL, NULL,  "state"},
   {FALSE, COL_TEXT, N_("?Player_dlg:Host"), col_host, NULL, NULL,  "host"},


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to