Author: jtn
Date: Mon Nov 17 11:34:15 2014
New Revision: 27063

URL: http://svn.gna.org/viewcvs/freeciv?rev=27063&view=rev
Log:
With team_pooled_research, send "tech_researched" signal to player whose
action caused it before other players.

See gna patch #5430.

Modified:
    branches/S2_5/server/diplhand.c
    branches/S2_5/server/scripting/api_server_edit.c
    branches/S2_5/server/techtools.c
    branches/S2_5/server/techtools.h

Modified: branches/S2_5/server/diplhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/diplhand.c?rev=27063&r1=27062&r2=27063&view=diff
==============================================================================
--- branches/S2_5/server/diplhand.c     (original)
+++ branches/S2_5/server/diplhand.c     Mon Nov 17 11:34:15 2014
@@ -432,16 +432,8 @@
                            nation_plural_for_player(pdest),
                            advance_name_for_player(pdest, pclause->value),
                            nation_plural_for_player(pgiver));
-
-          players_iterate(aplayer) {
-            if (player_research_get(pdest) == player_research_get(aplayer)) {
-              script_server_signal_emit("tech_researched", 3,
-                                        API_TYPE_TECH_TYPE,
-                                        advance_by_number(pclause->value),
-                                        API_TYPE_PLAYER, aplayer,
-                                        API_TYPE_STRING, "traded");
-            }
-          } players_iterate_end;
+          script_tech_learned(pdest, advance_by_number(pclause->value),
+                              "traded");
           do_dipl_cost(pdest, pclause->value);
           found_new_tech(pdest, pclause->value, FALSE, TRUE);
         }

Modified: branches/S2_5/server/scripting/api_server_edit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/scripting/api_server_edit.c?rev=27063&r1=27062&r2=27063&view=diff
==============================================================================
--- branches/S2_5/server/scripting/api_server_edit.c    (original)
+++ branches/S2_5/server/scripting/api_server_edit.c    Mon Nov 17 11:34:15 2014
@@ -281,14 +281,7 @@
     do_free_cost(pplayer, id);
     found_new_tech(pplayer, id, FALSE, TRUE);
     result = advance_by_number(id);
-    players_iterate(aplayer) {
-      if (presearch == player_research_get(aplayer)) {
-        script_server_signal_emit("tech_researched", 3,
-                                  API_TYPE_TECH_TYPE, result,
-                                  API_TYPE_PLAYER, aplayer,
-                                  API_TYPE_STRING, reason);
-      }
-    } players_iterate_end;
+    script_tech_learned(pplayer, result, reason);
     return result;
   } else {
     return NULL;

Modified: branches/S2_5/server/techtools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/techtools.c?rev=27063&r1=27062&r2=27063&view=diff
==============================================================================
--- branches/S2_5/server/techtools.c    (original)
+++ branches/S2_5/server/techtools.c    Mon Nov 17 11:34:15 2014
@@ -96,6 +96,31 @@
 }
 
 /****************************************************************************
+  Emit script signal(s) for player/team learning new tech.
+****************************************************************************/
+void script_tech_learned(struct player *plr, struct advance *tech,
+                         const char *reason)
+{
+  /* Emit signal for individual player whose action triggered the
+   * tech first */
+  script_server_signal_emit("tech_researched", 3,
+                            API_TYPE_TECH_TYPE, tech,
+                            API_TYPE_PLAYER, plr,
+                            API_TYPE_STRING, reason);
+
+  /* Emit signal to remaining research teammates, if any */
+  players_iterate(aplayer) {
+    if (aplayer != plr
+        && player_research_get(plr) == player_research_get(aplayer)) {
+      script_server_signal_emit("tech_researched", 3,
+                                API_TYPE_TECH_TYPE, tech,
+                                API_TYPE_PLAYER, aplayer,
+                                API_TYPE_STRING, reason);
+    }
+  } players_iterate_end;
+}
+
+/****************************************************************************
   Player has researched a new technology
 ****************************************************************************/
 static void tech_researched(struct player *plr)
@@ -127,15 +152,7 @@
   /* do all the updates needed after finding new tech */
   found_new_tech(plr, research->researching, TRUE, TRUE);
 
-  players_iterate(aplayer) {
-    if (research == player_research_get(aplayer)) {
-      script_server_signal_emit("tech_researched", 3,
-                                API_TYPE_TECH_TYPE,
-                                advance_by_number(researched_tech),
-                                API_TYPE_PLAYER, aplayer,
-                                API_TYPE_STRING, "researched");
-    }
-  } players_iterate_end;
+  script_tech_learned(plr, advance_by_number(researched_tech), "researched");
 }
 
 /****************************************************************************
@@ -178,17 +195,7 @@
 
          do_free_cost(pplayer, i);
          found_new_tech(pplayer, i, FALSE, TRUE);
-
-          players_iterate(aplayer) {
-            if (player_research_get(pplayer)
-                == player_research_get(aplayer)) {
-              script_server_signal_emit("tech_researched", 3,
-                                        API_TYPE_TECH_TYPE,
-                                        advance_by_number(i),
-                                        API_TYPE_PLAYER, aplayer,
-                                        API_TYPE_STRING, "stolen");
-            }
-          } players_iterate_end;
+          script_tech_learned(pplayer, advance_by_number(i), "stolen");
          break;
        }
       }
@@ -1120,15 +1127,7 @@
     do_conquer_cost(pplayer, stolen_tech);
     found_new_tech(pplayer, stolen_tech, FALSE, TRUE);
 
-    players_iterate(aplayer) {
-      if (player_research_get(pplayer) == player_research_get(aplayer)) {
-        script_server_signal_emit("tech_researched", 3,
-                                  API_TYPE_TECH_TYPE,
-                                  advance_by_number(stolen_tech),
-                                  API_TYPE_PLAYER, aplayer,
-                                  API_TYPE_STRING, "stolen");
-      }
-    } players_iterate_end;
+    script_tech_learned(pplayer, advance_by_number(stolen_tech), "stolen");
 
     return stolen_tech;
   };

Modified: branches/S2_5/server/techtools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/techtools.h?rev=27063&r1=27062&r2=27063&view=diff
==============================================================================
--- branches/S2_5/server/techtools.h    (original)
+++ branches/S2_5/server/techtools.h    Mon Nov 17 11:34:15 2014
@@ -21,6 +21,8 @@
 void do_dipl_cost(struct player *pplayer, Tech_type_id tech);
 
 void do_tech_parasite_effect(struct player *pplayer);
+void script_tech_learned(struct player *plr, struct advance *tech,
+                         const char *reason);
 void found_new_tech(struct player *plr, Tech_type_id tech_found,
                     bool was_discovery, bool saving_bulbs);
 bool update_bulbs(struct player *plr, int bulbs, bool check_tech);


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

Reply via email to