Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2003:
[Freeciv-Dev] (PR#4213) New pact: Union v2
Home

[Freeciv-Dev] (PR#4213) New pact: Union v2

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ue80@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#4213) New pact: Union v2
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sat, 14 Jun 2003 05:13:27 -0700
Reply-to: rt@xxxxxxxxxxxxxx

> This patch implements a new pact called 'Union' which is exactly like
> 'Alliance', except you share your research with your Union partners as
> described in PR#3672. It also adds exact description of tech points to
> science dialog, implementing PR#3376.
>
> Breaking a 'Union' does not result in reputation penalty. Changing your
> research goal changes this for all Union partners as well, and the same
> goes for currently researching tech as well.

CHANGES:
 - broader and more unified client support
 - added support for Xaw, and partial support for SDL (diplo status only)
 - removed averaging of tech costs in tech.c (too expensive)
 - fixed case where eg Union(A,B) and Union(B,C),
   and A switches tech or goal to Z and C doesn't receive
   change request.

I consider this patch now commit-worthy. Please test.

On to some more subtle points:

A player gives research points from his cities to all players he is in
Union with. Therefore, if Union(A,B) and Union(B,C), then B will receives
research points from three players including himself, while A and C will
receive "only" from two. When playing with standard research costs and at
least one player is connected to every other Union member, this has no
actual impact on total research speed, and works just as if also
Union(A,C) except A and C do not see the total research going on.

Note that due to the above and non-default tech_cost_styles, players can
still research at different speeds. But this is only a problem if the
Union is badly organized.

If you play with tech leakage==1, and you decide that one player should
lead the research, it is optimal that the player with the most embassies
leads.

  - Per

Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.118
diff -u -r1.118 climisc.c
--- client/climisc.c    17 Apr 2003 20:06:35 -0000      1.118
+++ client/climisc.c    14 Jun 2003 12:12:37 -0000
@@ -281,12 +281,18 @@
   case CLAUSE_ALLIANCE:
     my_snprintf(buf, bufsiz, _("The parties create an alliance"));
     break;
+  case CLAUSE_UNION:
+    my_snprintf(buf, bufsiz, _("The parties create a union"));
+    break;
   case CLAUSE_VISION:
     my_snprintf(buf, bufsiz, _("The %s gives shared vision"),
                get_nation_name_plural(pclause->from->nation));
     break;
   default:
-    if (bufsiz > 0) *buf = '\0';
+    assert(FALSE);
+    if (bufsiz > 0) {
+      *buf = '\0';
+    }
     break;
   }
 }
@@ -1177,4 +1183,37 @@
                name, value, game.player_ptr->economic.gold);
     append_output_window(buf);
   }
+}
+
+/**************************************************************************
+  Returns the text to display in the science dialog.
+**************************************************************************/
+const char *science_dialog_text()
+{
+  int turns_to_advance;
+  static char text[512];
+
+  turns_to_advance = tech_turns_to_advance(game.player_ptr);
+  if (turns_to_advance == FC_INFINITY) {
+    my_snprintf(text, sizeof(text), _("Progress: no research"));
+  } else if (game.player_ptr->research.bulbs_last_turn
+             == game.player_ptr->research.bulbs_last_turn_techpool) {
+    /* Simple version, no techpool */
+    my_snprintf(text, sizeof(text),
+                PL_("Progress: %d turn/advance (%d pts/turn)",
+                    "Progress: %d turns/advance (%d pts/turn)",
+                    turns_to_advance),
+                turns_to_advance, game.player_ptr->research.bulbs_last_turn);
+  } else {
+    /* Techpool version */
+    my_snprintf(text, sizeof(text),
+                PL_("Progress: %d turn/advance (%d pts/turn, "
+                    "%d pts/turn techpool)",
+                    "Progress: %d turns/advance (%d pts/turn, "
+                    "%d pts/turn techpool)",
+                    turns_to_advance),
+                turns_to_advance, game.player_ptr->research.bulbs_last_turn,
+                game.player_ptr->research.bulbs_last_turn_techpool);
+  }
+  return text;
 }
Index: client/climisc.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.h,v
retrieving revision 1.44
diff -u -r1.44 climisc.h
--- client/climisc.h    15 Feb 2003 20:26:17 -0000      1.44
+++ client/climisc.h    14 Jun 2003 12:12:37 -0000
@@ -121,6 +121,7 @@
                            char *buf, size_t bufsz);
 
 const char *unit_description(struct unit *punit);
+const char *science_dialog_text(void);
 
 void cityrep_buy(struct city *pcity);
 
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.306
diff -u -r1.306 packhand.c
--- client/packhand.c   8 May 2003 03:06:58 -0000       1.306
+++ client/packhand.c   14 Jun 2003 12:12:37 -0000
@@ -1318,10 +1318,12 @@
                || pplayer->ai.tech_goal != pinfo->tech_goal);
   pplayer->research.bulbs_researched = pinfo->bulbs_researched;
   pplayer->research.techs_researched = pinfo->techs_researched;
-  pplayer->research.researching=pinfo->researching;
-  pplayer->future_tech=pinfo->future_tech;
-  pplayer->ai.tech_goal=pinfo->tech_goal;
-  
+  pplayer->research.researching = pinfo->researching;
+  pplayer->future_tech = pinfo->future_tech;
+  pplayer->ai.tech_goal = pinfo->tech_goal;
+  pplayer->research.bulbs_last_turn = pinfo->bulbs_last_turn;
+  pplayer->research.bulbs_last_turn_techpool = pinfo->bulbs_last_turn_techpool;
+
   if (can_client_change_view() && pplayer == game.player_ptr) {
     if (poptechup) {
       if (!game.player_ptr->ai.control || ai_popup_windows) {
Index: client/gui-gtk/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/diplodlg.c,v
retrieving revision 1.39
diff -u -r1.39 diplodlg.c
--- client/gui-gtk/diplodlg.c   4 Apr 2003 15:47:46 -0000       1.39
+++ client/gui-gtk/diplodlg.c   14 Jun 2003 12:12:37 -0000
@@ -114,6 +114,7 @@
 static void diplomacy_dialog_ceasefire_callback(GtkWidget *w, gpointer data);
 static void diplomacy_dialog_peace_callback(GtkWidget *w, gpointer data);
 static void diplomacy_dialog_alliance_callback(GtkWidget *w, gpointer data);
+static void diplomacy_dialog_union_callback(GtkWidget *w, gpointer data);
 static void diplomacy_dialog_vision_callback(GtkWidget *w, gpointer data);
 static void close_diplomacy_dialog(struct Diplomacy_dialog *pdialog);
 static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog);
@@ -473,6 +474,11 @@
   gtk_signal_connect(GTK_OBJECT(item),"activate",
        GTK_SIGNAL_FUNC(diplomacy_dialog_alliance_callback),(gpointer)pdialog);
 
+  item = gtk_menu_item_new_with_label(Q_("?diplomatic_state:Union"));
+  gtk_menu_append(GTK_MENU(pdialog->dip_pact_menu), item);
+  gtk_signal_connect(GTK_OBJECT(item), "activate",
+       GTK_SIGNAL_FUNC(diplomacy_dialog_union_callback), (gpointer)pdialog);
+
   gtk_widget_show_all(pdialog->dip_pact_menu);
 
   button=gtk_button_new_with_label(_("Pacts"));
@@ -777,6 +783,14 @@
 static void diplomacy_dialog_alliance_callback(GtkWidget *w, gpointer data)
 {
   diplomacy_dialog_add_pact_clause(w, data, CLAUSE_ALLIANCE);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void diplomacy_dialog_union_callback(GtkWidget *w, gpointer data)
+{
+  diplomacy_dialog_add_pact_clause(w, data, CLAUSE_UNION);
 }
 
 /****************************************************************
Index: client/gui-gtk/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/plrdlg.c,v
retrieving revision 1.48
diff -u -r1.48 plrdlg.c
--- client/gui-gtk/plrdlg.c     5 May 2003 12:11:12 -0000       1.48
+++ client/gui-gtk/plrdlg.c     14 Jun 2003 12:12:37 -0000
@@ -450,6 +450,7 @@
        state_col = colors_standard[COLOR_STD_RED];
        break;
       case DS_ALLIANCE:
+      case DS_UNION:
        state_col = colors_standard[COLOR_STD_GROUND];
        break;
       default:
Index: client/gui-gtk/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/repodlgs.c,v
retrieving revision 1.70
diff -u -r1.70 repodlgs.c
--- client/gui-gtk/repodlgs.c   4 Apr 2003 15:47:47 -0000       1.70
+++ client/gui-gtk/repodlgs.c   14 Jun 2003 12:12:37 -0000
@@ -31,6 +31,7 @@
 #include "support.h"
 
 #include "civclient.h"
+#include "climisc.h"
 #include "clinet.h"
 #include "repodlgs_common.h"
 
@@ -364,22 +365,13 @@
   GtkWidget *item;
   GList *sorting_list = NULL;
   gfloat pct;
-  int turns_to_advance;
   int steps;
 
-  if(is_report_dialogs_frozen()) return;
-
-  turns_to_advance = tech_turns_to_advance(game.player_ptr);
-  if (turns_to_advance == FC_INFINITY) {
-    my_snprintf(text, sizeof(text), _("Research speed: no research"));
-  } else {
-    my_snprintf(text, sizeof(text),
-               PL_("Research speed: %d turn/advance",
-                   "Research speed: %d turns/advance", turns_to_advance),
-               turns_to_advance);
+  if (is_report_dialogs_frozen()) {
+    return;
   }
 
-  gtk_set_label(science_label, text);
+  gtk_set_label(science_label, science_dialog_text());
 
   for (i=0; i<4; i++) {
     gtk_clist_freeze(GTK_CLIST(science_list[i]));
Index: client/gui-gtk-2.0/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/diplodlg.c,v
retrieving revision 1.11
diff -u -r1.11 diplodlg.c
--- client/gui-gtk-2.0/diplodlg.c       18 May 2003 16:19:29 -0000      1.11
+++ client/gui-gtk-2.0/diplodlg.c       14 Jun 2003 12:12:37 -0000
@@ -87,6 +87,7 @@
 static void diplomacy_dialog_ceasefire_callback(GtkWidget *w, gpointer data);
 static void diplomacy_dialog_peace_callback(GtkWidget *w, gpointer data);
 static void diplomacy_dialog_alliance_callback(GtkWidget *w, gpointer data);
+static void diplomacy_dialog_union_callback(GtkWidget *w, gpointer data);
 static void diplomacy_dialog_vision_callback(GtkWidget *w, gpointer data);
 static void close_diplomacy_dialog(struct Diplomacy_dialog *pdialog);
 static void update_diplomacy_dialog(struct Diplomacy_dialog *pdialog);
@@ -342,6 +343,11 @@
     g_signal_connect(item, "activate",
                     G_CALLBACK(diplomacy_dialog_alliance_callback), pdialog);
 
+    item = gtk_menu_item_new_with_mnemonic(Q_("?diplomatic_state:Union"));
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+    g_signal_connect(item, "activate",
+                    G_CALLBACK(diplomacy_dialog_union_callback), pdialog);
+
     item = gtk_menu_item_new_with_mnemonic(_("_Pacts"));
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
     gtk_menu_shell_append(GTK_MENU_SHELL(parent), item);
@@ -763,6 +769,14 @@
 static void diplomacy_dialog_alliance_callback(GtkWidget *w, gpointer data)
 {
   diplomacy_dialog_add_pact_clause(w, data, CLAUSE_ALLIANCE);
+}
+
+/****************************************************************
+  ...
+*****************************************************************/
+static void diplomacy_dialog_union_callback(GtkWidget *w, gpointer data)
+{
+  diplomacy_dialog_add_pact_clause(w, data, CLAUSE_UNION);
 }
 
 /****************************************************************
Index: client/gui-gtk-2.0/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/plrdlg.c,v
retrieving revision 1.27
diff -u -r1.27 plrdlg.c
--- client/gui-gtk-2.0/plrdlg.c 18 May 2003 16:19:29 -0000      1.27
+++ client/gui-gtk-2.0/plrdlg.c 14 Jun 2003 12:12:37 -0000
@@ -474,6 +474,7 @@
      state_col = colors_standard[COLOR_STD_RED];
      break;
    case DS_ALLIANCE:
+   case DS_UNION:
      state_col = colors_standard[COLOR_STD_GROUND];
      break;
    default:
Index: client/gui-gtk-2.0/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/repodlgs.c,v
retrieving revision 1.31
diff -u -r1.31 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       18 May 2003 16:19:29 -0000      1.31
+++ client/gui-gtk-2.0/repodlgs.c       14 Jun 2003 12:12:37 -0000
@@ -32,6 +32,7 @@
 
 #include "cityrep.h"
 #include "civclient.h"
+#include "climisc.h"
 #include "clinet.h"
 #include "dialogs.h"
 #include "gui_main.h"
@@ -364,27 +365,18 @@
 void science_dialog_update(void)
 {
   if(science_dialog_shell) {
-  char text[512];
   int i, j, hist;
+  char text[512];
   GtkWidget *item;
   GList *sorting_list = NULL;
   gdouble pct;
-  int turns_to_advance;
   int steps;
 
-  if(is_report_dialogs_frozen()) return;
-
-  turns_to_advance = tech_turns_to_advance(game.player_ptr);
-  if (turns_to_advance == FC_INFINITY) {
-    my_snprintf(text, sizeof(text), _("Research speed: no research"));
-  } else {
-    my_snprintf(text, sizeof(text),
-               PL_("Research speed: %d turn/advance",
-                   "Research speed: %d turns/advance", turns_to_advance),
-               turns_to_advance);
+  if (is_report_dialogs_frozen()) {
+    return;
   }
 
-  gtk_set_label(science_label, text);
+  gtk_set_label(science_label, (char *)science_dialog_text());
 
   for (i=0; i<4; i++) {
     gtk_list_store_clear(science_model[i]);
Index: client/gui-sdl/diplodlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/diplodlg.c,v
retrieving revision 1.5
diff -u -r1.5 diplodlg.c
--- client/gui-sdl/diplodlg.c   5 Jun 2003 23:10:45 -0000       1.5
+++ client/gui-sdl/diplodlg.c   14 Jun 2003 12:12:38 -0000
@@ -22,7 +22,6 @@
 #include <SDL/SDL.h>
 
 #include "fcintl.h"
-#include "log.h"
 #include "game.h"
 #include "genlist.h"
 #include "government.h"
Index: client/gui-sdl/inteldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/inteldlg.c,v
retrieving revision 1.5
diff -u -r1.5 inteldlg.c
--- client/gui-sdl/inteldlg.c   5 Jun 2003 23:10:46 -0000       1.5
+++ client/gui-sdl/inteldlg.c   14 Jun 2003 12:12:38 -0000
@@ -22,7 +22,6 @@
 #include <SDL/SDL.h>
 
 #include "fcintl.h"
-#include "log.h"
 #include "game.h"
 #include "government.h"
 #include "packets.h"
Index: client/gui-sdl/plrdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/plrdlg.c,v
retrieving revision 1.4
diff -u -r1.4 plrdlg.c
--- client/gui-sdl/plrdlg.c     5 Jun 2003 23:10:46 -0000       1.4
+++ client/gui-sdl/plrdlg.c     14 Jun 2003 12:12:38 -0000
@@ -24,7 +24,6 @@
 #include <SDL/SDL.h>
 
 #include "fcintl.h"
-#include "log.h"
 #include "game.h"
 #include "packets.h"
 #include "nation.h"
@@ -188,6 +187,10 @@
              putline(pPlayer1->dst, x0, y0, x1, y1,
                        get_game_color(COLOR_STD_CITY_GOLD, pPlayer1->dst));
             break;
+           case DS_UNION:
+             putline(pPlayer1->dst, x0, y0, x1, y1,
+                       get_game_color(COLOR_STD_CITY_GOLD, pPlayer1->dst));
+            break;
            case DS_NEUTRAL:
              putline(pPlayer1->dst, x0, y0, x1, y1, 0xFF000000);
            break;
@@ -339,6 +342,9 @@
        case DS_ALLIANCE:
          pStr->forecol = *(get_game_colorRGB(COLOR_STD_GROUND));
        break;
+       case DS_UNION:
+         pStr->forecol = *(get_game_colorRGB(COLOR_STD_GROUND));
+       break;
        case DS_NEUTRAL:
          pStr->forecol = *(get_game_colorRGB(COLOR_STD_BLACK));
        break;
@@ -546,6 +552,10 @@
          set_wstate(pBuf, FC_WS_NORMAL);
         break;
        case DS_ALLIANCE:
+         pBuf->string16->forecol = *(get_game_colorRGB(COLOR_STD_CITY_GOLD));
+         set_wstate(pBuf, FC_WS_NORMAL);
+        break;
+       case DS_UNION:
          pBuf->string16->forecol = *(get_game_colorRGB(COLOR_STD_CITY_GOLD));
          set_wstate(pBuf, FC_WS_NORMAL);
         break;
Index: client/gui-win32/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/repodlgs.c,v
retrieving revision 1.27
diff -u -r1.27 repodlgs.c
--- client/gui-win32/repodlgs.c 4 Apr 2003 15:47:48 -0000       1.27
+++ client/gui-win32/repodlgs.c 14 Jun 2003 12:12:38 -0000
@@ -33,6 +33,7 @@
  
 #include "cityrep.h"
 #include "civclient.h"
+#include "climisc.h"
 #include "dialogs.h"
 #include "gui_stuff.h"
 #include "gui_main.h"
@@ -97,15 +98,7 @@
   if (!science_dlg) return;            
   report_title=get_report_title(_("Science"));
   sz_strlcpy(text, report_title);
-  turns_to_advance = tech_turns_to_advance(game.player_ptr);
-  if (turns_to_advance == FC_INFINITY) {
-    my_snprintf(rate, sizeof(rate), _("\n(no research)"));
-  } else {
-    my_snprintf(rate, sizeof(rate),
-               PL_("\n(%d turn/advance)", "\n(%d turns/advance)",
-                   turns_to_advance), turns_to_advance);
-  }
-  sz_strlcat(text, rate);
+  sz_strlcat(text, science_dialog_text());
   SetWindowText(GetDlgItem(science_dlg,ID_SCIENCE_TOP),text);
   ListBox_ResetContent(GetDlgItem(science_dlg,ID_SCIENCE_LIST));
   for (i=A_FIRST;i<game.num_tech_types;i++)
Index: client/gui-xaw/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/repodlgs.c,v
retrieving revision 1.49
diff -u -r1.49 repodlgs.c
--- client/gui-xaw/repodlgs.c   4 Apr 2003 15:47:48 -0000       1.49
+++ client/gui-xaw/repodlgs.c   14 Jun 2003 12:12:38 -0000
@@ -41,6 +41,7 @@
 #include "support.h"
 
 #include "cityrep.h"
+#include "climisc.h"
 #include "clinet.h"
 #include "dialogs.h"
 #include "gui_main.h"
@@ -144,11 +145,11 @@
 /****************************************************************
 ...
 ****************************************************************/
-static char *get_report_title_plus(char *report_name, char *additional)
+static char *get_report_title_plus(char *report_name, const char *additional)
 {
   char buf[512];
   
-  my_snprintf(buf, sizeof(buf), _("%s\n%s of the %s\n%s %s: %s%s"),
+  my_snprintf(buf, sizeof(buf), _("%s\n%s of the %s\n%s %s: %s\n%s"),
              report_name,
              get_government_name(game.player_ptr->government),
              get_nation_name_plural(game.player_ptr->nation),
@@ -240,7 +241,6 @@
   tech_list_names_ptrs[j]=0;
   qsort(tech_list_names_ptrs, j, sizeof(char *), compare_strings_ptrs);
   num_list = j;
-  /* printf("science list num: %d\n", num_list); */
   
   science_dialog_shell =
     I_T(XtVaCreatePopupShell("sciencepopup", 
@@ -482,19 +482,9 @@
     static char *tech_list_names_ptrs[A_LAST+1];
     int j, flag;
     size_t i;
-    char rate_text[128];
     char *report_title;
-    int turns_to_advance;
     
-    turns_to_advance = tech_turns_to_advance(game.player_ptr);
-    if (turns_to_advance == FC_INFINITY) {
-      my_snprintf(rate_text, sizeof(rate_text), _("\n(no research)"));
-    } else {
-      my_snprintf(rate_text, sizeof(rate_text),
-                 PL_("\n(%d turn/advance)", "\n(%d turns/advance)",
-                     turns_to_advance), turns_to_advance);
-    }
-    report_title=get_report_title_plus(_("Science"), rate_text);
+    report_title = get_report_title_plus(_("Science"), science_dialog_text());
     xaw_set_label(science_label, report_title);
     free(report_title);
 
Index: common/connection.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/connection.h,v
retrieving revision 1.30
diff -u -r1.30 connection.h
--- common/connection.h 28 May 2003 21:11:38 -0000      1.30
+++ common/connection.h 14 Jun 2003 12:12:38 -0000
@@ -15,9 +15,6 @@
 
 #include <time.h>      /* time_t */
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
Index: common/diptreaty.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.h,v
retrieving revision 1.12
diff -u -r1.12 diptreaty.h
--- common/diptreaty.h  31 May 2003 16:22:15 -0000      1.12
+++ common/diptreaty.h  14 Jun 2003 12:12:38 -0000
@@ -18,10 +18,11 @@
 enum clause_type { CLAUSE_ADVANCE, CLAUSE_GOLD, CLAUSE_MAP,
                   CLAUSE_SEAMAP, CLAUSE_CITY, 
                   CLAUSE_CEASEFIRE, CLAUSE_PEACE, CLAUSE_ALLIANCE,
-                  CLAUSE_VISION, CLAUSE_LAST };
+                  CLAUSE_VISION, CLAUSE_UNION, CLAUSE_LAST };
 
-#define is_pact_clause(x) \
-  ((x == CLAUSE_CEASEFIRE) || (x == CLAUSE_PEACE) || (x == CLAUSE_ALLIANCE))
+#define is_pact_clause(x)                                                   \
+  ((x == CLAUSE_CEASEFIRE) || (x == CLAUSE_PEACE) || (x == CLAUSE_ALLIANCE) \
+   || (x == CLAUSE_UNION))
 
 /* For when we need to iterate over treaties */
 struct Clause;
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.247
diff -u -r1.247 packets.c
--- common/packets.c    8 May 2003 03:06:58 -0000       1.247
+++ common/packets.c    14 Jun 2003 12:12:38 -0000
@@ -889,6 +889,8 @@
 
   dio_put_uint32(&dout, pinfo->bulbs_researched);
   dio_put_uint32(&dout, pinfo->techs_researched);
+  dio_put_uint32(&dout, pinfo->bulbs_last_turn);
+  dio_put_uint32(&dout, pinfo->bulbs_last_turn_techpool);
   dio_put_uint8(&dout, pinfo->researching);
 
   dio_put_bit_string(&dout, (char *) pinfo->inventions);
@@ -947,6 +949,8 @@
 
   dio_get_uint32(&din, &pinfo->bulbs_researched);
   dio_get_uint32(&din, &pinfo->techs_researched);
+  dio_get_uint32(&din, &pinfo->bulbs_last_turn);
+  dio_get_uint32(&din, &pinfo->bulbs_last_turn_techpool);
   dio_get_uint8(&din, &pinfo->researching);
   dio_get_bit_string(&din, (char *) pinfo->inventions,
                     sizeof(pinfo->inventions));
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.146
diff -u -r1.146 packets.h
--- common/packets.h    8 May 2003 03:06:58 -0000       1.146
+++ common/packets.h    14 Jun 2003 12:12:38 -0000
@@ -471,6 +471,8 @@
   int gold, tax, science, luxury;
   int bulbs_researched;
   int techs_researched;
+  int bulbs_last_turn;
+  int bulbs_last_turn_techpool;
   int researching;
   int future_tech;
   int tech_goal;
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.119
diff -u -r1.119 player.c
--- common/player.c     5 Jun 2003 23:10:46 -0000       1.119
+++ common/player.c     14 Jun 2003 12:12:38 -0000
@@ -122,6 +122,8 @@
   plr->economic.science=PLAYER_DEFAULT_SCIENCE_RATE;
   plr->economic.luxury=PLAYER_DEFAULT_LUXURY_RATE;
   plr->research.changed_from = -1;
+  plr->research.bulbs_last_turn = 0;
+  plr->research.bulbs_last_turn_techpool = 0;
   player_limit_to_government_rates(plr);
   spaceship_init(&plr->spaceship);
 
@@ -528,7 +530,8 @@
     N_("?diplomatic_state:Cease-fire"),
     N_("?diplomatic_state:Peace"),
     N_("?diplomatic_state:Alliance"),
-    N_("?diplomatic_state:Never met")
+    N_("?diplomatic_state:Never met"),
+    N_("?diplomatic_state:Union")
   };
 
   if (type < DS_LAST) {
@@ -576,7 +579,7 @@
   if (is_barbarian(pplayer) || is_barbarian(pplayer2)) {
     return FALSE;
   }
-  return (ds == DS_ALLIANCE);
+  return (ds == DS_ALLIANCE || ds == DS_UNION);
 }
 
 /***************************************************************
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.100
diff -u -r1.100 player.h
--- common/player.h     31 May 2003 16:22:15 -0000      1.100
+++ common/player.h     14 Jun 2003 12:12:38 -0000
@@ -66,6 +66,8 @@
 struct player_research {
   int bulbs_researched;   /* # bulbs reseached for the current tech */    
   int techs_researched;   /* # techs the player has researched/acquired */
+  int bulbs_last_turn;
+  int bulbs_last_turn_techpool;
   /* 
    * Invention being researched in. Valid values for researching are:
    *  - any existing tech but not A_NONE or
@@ -153,6 +155,7 @@
   DS_PEACE,
   DS_ALLIANCE,
   DS_NO_CONTACT,
+  DS_UNION,
   DS_LAST      /* leave this last */
 };
 
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.214
diff -u -r1.214 cityturn.c
--- server/cityturn.c   31 May 2003 12:45:23 -0000      1.214
+++ server/cityturn.c   14 Jun 2003 12:12:38 -0000
@@ -994,11 +994,13 @@
 
       do_free_cost(pplayer);
       first = pplayer->research.researching;
-      found_new_tech(pplayer, pplayer->research.researching, TRUE, TRUE);
+      found_new_tech(pplayer, pplayer->research.researching, TRUE, TRUE,
+                     A_NONE);
 
       do_free_cost(pplayer);
       second = pplayer->research.researching;
-      found_new_tech(pplayer, pplayer->research.researching, TRUE, TRUE);
+      found_new_tech(pplayer, pplayer->research.researching, TRUE, TRUE,
+                     A_NONE);
 
       (void) mystrlcpy(buffer, get_tech_name(pplayer, first),
                       sizeof(buffer));
Index: server/diplhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v
retrieving revision 1.70
diff -u -r1.70 diplhand.c
--- server/diplhand.c   31 May 2003 16:22:15 -0000      1.70
+++ server/diplhand.c   14 Jun 2003 12:12:38 -0000
@@ -342,7 +342,7 @@
 
        do_dipl_cost(pdest);
 
-       found_new_tech(pdest, pclause->value, FALSE, TRUE);
+       found_new_tech(pdest, pclause->value, FALSE, TRUE, A_NONE);
        break;
       case CLAUSE_GOLD:
        notify_player(pdest, _("Game: You get %d gold."), pclause->value);
@@ -419,6 +419,47 @@
        check_city_workers(plr0);
        check_city_workers(plr1);
        break;
+      case CLAUSE_UNION:
+        notify_player_ex(pgiver, -1, -1, E_TREATY_ALLIANCE,
+                         _("Game: You agree on a union with %s."),
+                         pdest->name);
+        notify_player_ex(pdest, -1, -1, E_TREATY_ALLIANCE,
+                         _("Game: You agree on a union with %s."),
+                         pgiver->name);
+        /* We must share and average research */
+        {
+          int average = (plr0->research.bulbs_researched
+                         + plr1->research.bulbs_researched) / 2;
+          int average2 = (plr0->research.bulbs_researched_before
+                          + plr1->research.bulbs_researched_before) / 2;
+          int tech;
+ 
+          for (tech = 0; tech < A_LAST; tech++) {
+            if (!tech_exists(tech)) {
+              continue;
+            }
+            if (get_invention(plr0, tech) != TECH_KNOWN
+                && get_invention(plr1, tech) == TECH_KNOWN) {
+              found_new_tech(plr0, tech, FALSE, TRUE, A_NONE);
+            }
+            if (get_invention(plr1, tech) != TECH_KNOWN
+                && get_invention(plr0, tech) == TECH_KNOWN) {
+              found_new_tech(plr1, tech, FALSE, TRUE, A_NONE);
+            }
+          }
+          plr0->research.bulbs_researched = average;
+          plr1->research.bulbs_researched = average;
+          plr1->research.researching = plr0->research.researching;
+          plr1->research.changed_from = plr0->research.changed_from;
+          plr0->research.bulbs_researched_before = average2;
+          plr1->research.bulbs_researched_before = average2;
+          plr1->ai.tech_goal = plr0->ai.tech_goal;
+        }
+        pgiver->diplstates[pdest->player_no].type = DS_UNION;
+        pdest->diplstates[pgiver->player_no].type = DS_UNION;
+        check_city_workers(plr0);
+        check_city_workers(plr1);
+        break;
       case CLAUSE_VISION:
        give_shared_vision(pgiver, pdest);
        notify_player_ex(pgiver, -1, -1, E_TREATY_SHARED_VISION,
Index: server/diplomats.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v
retrieving revision 1.37
diff -u -r1.37 diplomats.c
--- server/diplomats.c  30 Apr 2003 21:14:35 -0000      1.37
+++ server/diplomats.c  14 Jun 2003 12:12:39 -0000
@@ -648,7 +648,7 @@
 
     /* Do it. */
     do_conquer_cost (pplayer);
-    found_new_tech (pplayer, target, FALSE, TRUE);
+    found_new_tech (pplayer, target, FALSE, TRUE, A_NONE);
     /* Report it. */
     notify_player_ex(pplayer, pcity->x, pcity->y, E_MY_DIPLOMAT_THEFT,
                     _("Game: Your %s stole %s from %s."),
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.276
diff -u -r1.276 plrhand.c
--- server/plrhand.c    4 Jun 2003 19:32:22 -0000       1.276
+++ server/plrhand.c    14 Jun 2003 12:12:39 -0000
@@ -144,7 +144,7 @@
                           advances[i].name);
 
          do_free_cost(pplayer);
-         found_new_tech(pplayer, i, FALSE, FALSE);
+         found_new_tech(pplayer, i, FALSE, FALSE, A_NONE);
          break;
        }
       }
@@ -201,12 +201,13 @@
 }
 
 /**************************************************************************
-Player has a new technology (from somewhere)
-was_discovery is passed on to upgrade_city_rails
-Logging & notification is not done here as it depends on how the tech came.
+  Player has a new technology (from somewhere). was_discovery is passed 
+  on to upgrade_city_rails. Logging & notification is not done here as 
+  it depends on how the tech came. If next_tech is other than A_NONE, this 
+  is the next tech to research.
 **************************************************************************/
 void found_new_tech(struct player *plr, int tech_found, bool was_discovery,
-                   bool saving_bulbs)
+                   bool saving_bulbs, int next_tech)
 {
   int i;
   bool bonus_tech_hack = FALSE;
@@ -276,7 +277,7 @@
     plr->ai.tech_goal = A_UNSET;
   }
 
-  if (tech_found==plr->research.researching) {
+  if (tech_found == plr->research.researching && next_tech == A_NONE) {
     /* need to pick new tech to research */
 
     int saved_bulbs = plr->research.bulbs_researched;
@@ -313,6 +314,12 @@
     if (saving_bulbs) {
       plr->research.bulbs_researched = saved_bulbs;
     }
+  } else if (tech_found == plr->research.researching && next_tech > A_NONE) {
+    /* Next target already determined. We always save bulbs. */
+    plr->research.researching = next_tech;
+    if (plr->research.bulbs_researched > 0) {
+      plr->research.bulbs_researched = 0;
+    }
   }
 
   if (bonus_tech_hack) {
@@ -366,6 +373,26 @@
       } players_iterate_end;
     }
   }
+
+  /* Update Union */
+  if (next_tech > A_NONE) {
+    /* Avoid unnecessary recursion. */
+    return;
+  }
+  players_iterate(aplayer) {
+    if (plr != aplayer
+        && plr->diplstates[aplayer->player_no].type == DS_UNION
+        && aplayer->is_alive
+        && get_invention(aplayer, tech_found) != TECH_KNOWN) {
+      notify_player_ex(aplayer, -1, -1, E_TECH_LEARNED,
+                       _("Game: Learned %s in cooperation with %s."
+                         "Scientists choose to research %s."),
+                       advances[tech_found].name, plr->name,
+                       get_tech_name(plr, plr->research.researching));
+      found_new_tech(aplayer, tech_found, was_discovery, saving_bulbs,
+                     plr->research.researching);
+    }
+  } players_iterate_end;
 }
 
 /**************************************************************************
@@ -405,7 +432,7 @@
   }
 
   /* do all the updates needed after finding new tech */
-  found_new_tech(plr, plr->research.researching, TRUE, FALSE);
+  found_new_tech(plr, plr->research.researching, TRUE, FALSE, A_NONE);
 }
 
 /**************************************************************************
@@ -415,7 +442,18 @@
 {
   int excessive_bulbs;
 
-  plr->research.bulbs_researched += bulbs;
+  players_iterate(pplayer) {
+    if (pplayer == plr) {
+      pplayer->research.bulbs_researched += bulbs;
+      pplayer->research.bulbs_last_turn += bulbs;
+      pplayer->research.bulbs_last_turn_techpool += bulbs;
+    } else if (pplayer->diplstates[plr->player_no].type == DS_UNION
+               && pplayer->is_alive) {
+      /* Share with union partner(s). We'll get in return later. */
+      pplayer->research.bulbs_researched += bulbs;
+      pplayer->research.bulbs_last_turn_techpool += bulbs;
+    }
+  } players_iterate_end;
   
   excessive_bulbs =
       (plr->research.bulbs_researched - total_bulbs_required(plr));
@@ -458,7 +496,6 @@
   return FALSE;
 }
 
-
 /**************************************************************************
 ...
 **************************************************************************/
@@ -631,7 +668,7 @@
                   get_nation_name_plural(target->nation));
 
   do_conquer_cost(pplayer);
-  found_new_tech(pplayer, i, FALSE, TRUE);
+  found_new_tech(pplayer, i, FALSE, TRUE, A_NONE);
 }
 
 /**************************************************************************
@@ -687,6 +724,16 @@
 {
   choose_tech(pplayer, preq->tech);
   send_player_info(pplayer, pplayer);
+
+  /* Notify Union members */
+  players_iterate(aplayer) {
+    if (pplayer != aplayer
+       && aplayer->research.researching != preq->tech
+       && pplayer->diplstates[aplayer->player_no].type == DS_UNION
+       && aplayer->is_alive) {
+      handle_player_research(aplayer, preq);
+    }
+  } players_iterate_end;
 }
 
 /**************************************************************************
@@ -697,6 +744,16 @@
 {
   choose_tech_goal(pplayer, preq->tech);
   send_player_info(pplayer, pplayer);
+
+  /* Notify Union members */
+  players_iterate(aplayer) {
+    if (pplayer != aplayer
+        && pplayer->diplstates[aplayer->player_no].type == DS_UNION
+        && aplayer->is_alive
+        && aplayer->ai.tech_goal != preq->tech) {
+      handle_player_tech_goal(aplayer, preq);
+    }
+  } players_iterate_end;
 }
 
 /**************************************************************************
@@ -869,6 +926,10 @@
     new_type = DS_PEACE;
     reppenalty = GAME_MAX_REPUTATION/4;
     break;
+  case DS_UNION:
+    new_type = DS_ALLIANCE;
+    reppenalty = 0;
+    break;
   default:
     freelog(LOG_VERBOSE, "non-pact diplstate in handle_player_cancel_pact");
     return;
@@ -1195,6 +1256,8 @@
     packet->luxury          = plr->economic.luxury;
     packet->bulbs_researched= plr->research.bulbs_researched;
     packet->techs_researched= plr->research.techs_researched;
+    packet->bulbs_last_turn = plr->research.bulbs_last_turn;
+    packet->bulbs_last_turn_techpool = plr->research.bulbs_last_turn_techpool;
     packet->researching     = plr->research.researching;
     packet->future_tech     = plr->future_tech;
     if (plr->revolution != 0) {
@@ -1222,6 +1285,8 @@
     packet->luxury          = 0;
     packet->bulbs_researched= 0;
     packet->techs_researched= 0;
+    packet->bulbs_last_turn = 0;
+    packet->bulbs_last_turn_techpool = 0;
     packet->researching     = A_NOINFO;
     packet->future_tech     = 0;
     packet->revolution      = 0;
@@ -1260,7 +1325,8 @@
    * A_NONE. */
   packet->inventions[A_NONE] = plr->research.inventions[A_NONE].state + '0';
 
-  if (info_level >= INFO_FULL) {
+  if (info_level >= INFO_FULL
+      || plr->diplstates[receiver->player_no].type == DS_UNION) {
     packet->tech_goal       = plr->ai.tech_goal;
   } else {
     packet->tech_goal       = A_UNSET;
@@ -1368,6 +1434,8 @@
       || is_barbarian(pplayer1) || is_barbarian(pplayer2)) {
     return;
   }
+  pplayer1->diplstates[player2].contact_turns_left = game.contactturns;
+  pplayer2->diplstates[player1].contact_turns_left = game.contactturns;
 
   pplayer1->diplstates[player2].contact_turns_left = game.contactturns;
   pplayer2->diplstates[player1].contact_turns_left = game.contactturns;
@@ -1560,7 +1628,9 @@
   cplayer->research.bulbs_researched = 0;
   cplayer->research.techs_researched = pplayer->research.techs_researched;
   cplayer->research.researching = pplayer->research.researching;
-  
+  cplayer->research.bulbs_last_turn = 0;
+  cplayer->research.bulbs_last_turn_techpool = 0;
+ 
   for(i = 0; i<game.num_tech_types ; i++)
     cplayer->research.inventions[i] = pplayer->research.inventions[i];
   cplayer->turn_done = TRUE; /* Have other things to think about - paralysis*/
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.54
diff -u -r1.54 plrhand.h
--- server/plrhand.h    30 Apr 2003 21:14:35 -0000      1.54
+++ server/plrhand.h    14 Jun 2003 12:12:39 -0000
@@ -68,8 +68,8 @@
 void handle_player_attribute_chunk(struct player *pplayer,
                                   struct packet_attribute_chunk *chunk);
 void handle_player_attribute_block(struct player *pplayer);
-void found_new_tech(struct player *plr, int tech_found, bool was_discovery, 
-                   bool saving_bulbs);
+void found_new_tech(struct player *plr, int tech_found, bool was_discovery,
+                    bool saving_bulbs, int next_tech);
 void found_new_future_tech(struct player *pplayer);
 void update_tech(struct player *plr, int bulbs);
 void init_tech(struct player *plr, int tech);
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.118
diff -u -r1.118 savegame.c
--- server/savegame.c   31 May 2003 16:22:15 -0000      1.118
+++ server/savegame.c   14 Jun 2003 12:12:39 -0000
@@ -669,6 +669,8 @@
                                             "player%d.researchpoints", plrno);
   plr->research.researching=secfile_lookup_int(file, 
                                             "player%d.researching", plrno);
+  plr->research.bulbs_last_turn = 0;
+  plr->research.bulbs_last_turn_techpool = 0;
   if (plr->research.researching == A_NONE
       || !tech_exists(plr->research.researching)) {
     /* The value of A_FUTURE could change in the future, since it
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.127
diff -u -r1.127 srv_main.c
--- server/srv_main.c   15 May 2003 16:02:00 -0000      1.127
+++ server/srv_main.c   14 Jun 2003 12:12:39 -0000
@@ -488,6 +488,11 @@
     }
   } players_iterate_end;
 
+  players_iterate(pplayer) {
+    pplayer->research.bulbs_last_turn = 0;
+    pplayer->research.bulbs_last_turn_techpool = 0;
+  } players_iterate_end;
+
   /* Refresh cities */
   for(i=0; i<game.nplayers; i++) {
     struct player *pplayer = shuffled_player(i);
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.225
diff -u -r1.225 unittools.c
--- server/unittools.c  4 Jun 2003 20:05:40 -0000       1.225
+++ server/unittools.c  14 Jun 2003 12:12:39 -0000
@@ -2151,7 +2151,7 @@
 
   do_free_cost(pplayer);
   if (!is_future_tech(new_tech)) {
-    found_new_tech(pplayer, new_tech, FALSE, TRUE);
+    found_new_tech(pplayer, new_tech, FALSE, TRUE, A_NONE);
   } else {
     found_new_future_tech(pplayer);
   }

[Prev in Thread] Current Thread [Next in Thread]