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

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

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#4213) New pact: Union
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sun, 11 May 2003 13:53:40 -0700
Reply-to: rt@xxxxxxxxxxxxxx

(This was part of the previously posted megapatch to improve diplomacy.)

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.

Clients updated: gtk1, gtk2, win32. Only the first tested. I plan on doing
the other clients in the next version of the patch - first some feedback
(hopefully).

Another idea that might be added to Union is a shared treasury.

  - 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    11 May 2003 20:47:39 -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), _("Research speed: 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_("Research speed: %d turn/advance (%d pts/turn)",
+                    "Research speed: %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_("Research speed: %d turn/advance (%d pts/turn, "
+                    "%d pts/turn techpool)",
+                    "Research speed: %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    11 May 2003 20:47:39 -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   11 May 2003 20:47:39 -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   11 May 2003 20:47:39 -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     11 May 2003 20:47:39 -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   11 May 2003 20:47:39 -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.10
diff -u -r1.10 diplodlg.c
--- client/gui-gtk-2.0/diplodlg.c       17 Apr 2003 21:18:08 -0000      1.10
+++ client/gui-gtk-2.0/diplodlg.c       11 May 2003 20:47:40 -0000
@@ -86,6 +86,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);
@@ -341,6 +342,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);
@@ -758,6 +764,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.24
diff -u -r1.24 plrdlg.c
--- client/gui-gtk-2.0/plrdlg.c 30 Apr 2003 21:14:34 -0000      1.24
+++ client/gui-gtk-2.0/plrdlg.c 11 May 2003 20:47:40 -0000
@@ -463,6 +463,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.28
diff -u -r1.28 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       17 Apr 2003 21:18:08 -0000      1.28
+++ client/gui-gtk-2.0/repodlgs.c       11 May 2003 20:47:41 -0000
@@ -32,6 +32,7 @@
 
 #include "cityrep.h"
 #include "civclient.h"
+#include "climisc.h"
 #include "clinet.h"
 #include "dialogs.h"
 #include "gui_main.h"
@@ -360,27 +361,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, science_dialog_text());
 
   for (i=0; i<4; i++) {
     gtk_list_store_clear(science_model[i]);
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 11 May 2003 20:47:41 -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: common/diptreaty.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.h,v
retrieving revision 1.10
diff -u -r1.10 diptreaty.h
--- common/diptreaty.h  17 Apr 2003 20:06:36 -0000      1.10
+++ common/diptreaty.h  11 May 2003 20:47:41 -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_VISION, CLAUSE_UNION };
 
 #define is_pact_clause(x) \
-  ((x == CLAUSE_CEASEFIRE) || (x == CLAUSE_PEACE) || (x == CLAUSE_ALLIANCE))
+  ((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    11 May 2003 20:47:41 -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    11 May 2003 20:47:41 -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.117
diff -u -r1.117 player.c
--- common/player.c     18 Apr 2003 10:08:53 -0000      1.117
+++ common/player.c     11 May 2003 20:47:41 -0000
@@ -99,6 +99,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);
 
@@ -501,7 +503,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) {
@@ -549,7 +552,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.98
diff -u -r1.98 player.h
--- common/player.h     17 Apr 2003 20:06:36 -0000      1.98
+++ common/player.h     11 May 2003 20:47:43 -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
@@ -151,6 +153,7 @@
   DS_PEACE,
   DS_ALLIANCE,
   DS_NO_CONTACT,
+  DS_UNION,
   DS_LAST      /* leave this last */
 };
 
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.61
diff -u -r1.61 tech.c
--- common/tech.c       7 Apr 2003 17:10:44 -0000       1.61
+++ common/tech.c       11 May 2003 20:47:43 -0000
@@ -359,7 +359,8 @@
  3 - Technology cost is reduced depending on the number of normal
      players (human and AI) which already know the tech.
 **************************************************************************/
-int base_total_bulbs_required(struct player *pplayer, Tech_Type_id tech)
+static int player_base_total_bulbs_required(struct player *pplayer, 
+                                            Tech_Type_id tech)
 {
   int cost, tech_cost_style = game.rgame.tech_cost_style;
 
@@ -464,6 +465,26 @@
   }
 
   return cost;
+}
+
+/**************************************************************************
+  Return cost of technology. For Union pacts we average the result over
+  all Union members.
+**************************************************************************/
+int base_total_bulbs_required(struct player *pplayer, Tech_Type_id tech)
+{
+ int s = 0, n = 0;
+
+ players_iterate(aplayer) {
+  if (pplayer == aplayer
+      || (pplayer->diplstates[aplayer->player_no].type == DS_UNION
+          && aplayer->is_alive)) {
+    n++;
+    s += player_base_total_bulbs_required(aplayer, tech);
+  }
+ } players_iterate_end;
+
+ return s / n;
 }
 
 /**************************************************************************
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.211
diff -u -r1.211 cityturn.c
--- server/cityturn.c   6 May 2003 05:18:49 -0000       1.211
+++ server/cityturn.c   11 May 2003 20:47:44 -0000
@@ -988,11 +988,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.69
diff -u -r1.69 diplhand.c
--- server/diplhand.c   30 Apr 2003 21:14:35 -0000      1.69
+++ server/diplhand.c   11 May 2003 20:47:44 -0000
@@ -311,7 +311,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);
@@ -388,6 +388,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  11 May 2003 20:47:44 -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.271
diff -u -r1.271 plrhand.c
--- server/plrhand.c    10 May 2003 19:20:16 -0000      1.271
+++ server/plrhand.c    11 May 2003 20:47:44 -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);
 }
 
 /**************************************************************************
@@ -685,8 +722,14 @@
 void handle_player_research(struct player *pplayer,
                            struct packet_player_request *preq)
 {
-  choose_tech(pplayer, preq->tech);
-  send_player_info(pplayer, pplayer);
+  players_iterate(aplayer) {
+   if (pplayer == aplayer
+       || (pplayer->diplstates[aplayer->player_no].type == DS_UNION
+           && aplayer->is_alive)) {
+      choose_tech(aplayer, preq->tech);
+      send_player_info(aplayer, aplayer);
+    }
+  } players_iterate_end;
 }
 
 /**************************************************************************
@@ -695,8 +738,14 @@
 void handle_player_tech_goal(struct player *pplayer,
                            struct packet_player_request *preq)
 {
-  choose_tech_goal(pplayer, preq->tech);
-  send_player_info(pplayer, pplayer);
+ players_iterate(aplayer) {
+   if (pplayer == aplayer
+       || (pplayer->diplstates[aplayer->player_no].type == DS_UNION
+           && aplayer->is_alive)) {
+     choose_tech_goal(aplayer, preq->tech);
+     send_player_info(aplayer, aplayer);
+    }
+  } players_iterate_end;
 }
 
 /**************************************************************************
@@ -861,6 +910,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;
@@ -1182,6 +1235,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) {
@@ -1205,7 +1260,9 @@
     packet->luxury          = 0;
     packet->bulbs_researched= 0;
     packet->techs_researched= 0;
-    packet->researching     = A_UNSET;
+    packet->bulbs_last_turn = 0;
+    packet->bulbs_last_turn_techpool = 0;
+    packet->researching     = A_NONE;
     packet->future_tech     = 0;
     packet->revolution      = 0;
 
@@ -1238,7 +1295,8 @@
     }
   }
 
-  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;
@@ -1345,6 +1403,8 @@
       || is_barbarian(pplayer1) || is_barbarian(pplayer2)) {
     return;
   }
+  pplayer1->diplstates[player2].contact_turns_left = game.contactturns;
+  pplayer2->diplstates[player1].contact_turns_left = game.contactturns;
 
   /* FIXME: Always declaring war for the AI is a kludge until AI
      diplomacy is implemented. */
@@ -1367,8 +1427,6 @@
       || player_has_embassy(pplayer2, pplayer1)) {
     return; /* Avoid sending too much info over the network */
   }
-  pplayer1->diplstates[player2].contact_turns_left = game.contactturns;
-  pplayer2->diplstates[player1].contact_turns_left = game.contactturns;
   send_player_info(pplayer1, pplayer1);
   send_player_info(pplayer2, pplayer2);
 }
@@ -1532,7 +1590,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    11 May 2003 20:47:44 -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.116
diff -u -r1.116 savegame.c
--- server/savegame.c   22 Apr 2003 20:50:56 -0000      1.116
+++ server/savegame.c   11 May 2003 20:47:45 -0000
@@ -662,6 +662,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.126
diff -u -r1.126 srv_main.c
--- server/srv_main.c   5 May 2003 12:11:13 -0000       1.126
+++ server/srv_main.c   11 May 2003 20:47:45 -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.223
diff -u -r1.223 unittools.c
--- server/unittools.c  10 May 2003 18:11:25 -0000      1.223
+++ server/unittools.c  11 May 2003 20:47:45 -0000
@@ -2231,7 +2231,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]