Author: cazfi
Date: Sat Dec 19 06:33:16 2015
New Revision: 31086

URL: http://svn.gna.org/viewcvs/freeciv?rev=31086&view=rev
Log:
Automatically send notifications about techs given by a lua script if script 
does not
do it itself or want to suppress it completely.

See patch #6531

Modified:
    trunk/data/alien/script.lua
    trunk/data/default/default.lua
    trunk/data/multiplayer/script.lua
    trunk/server/scripting/api_server_edit.c
    trunk/server/scripting/api_server_edit.h
    trunk/server/scripting/tolua_server.pkg

Modified: trunk/data/alien/script.lua
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/alien/script.lua?rev=31086&r1=31085&r2=31086&view=diff
==============================================================================
--- trunk/data/alien/script.lua (original)
+++ trunk/data/alien/script.lua Sat Dec 19 06:33:16 2015
@@ -24,7 +24,7 @@
 -- Get a tech from entering a hut.
 function alien_hut_get_tech(unit)
   local owner = unit.owner
-  local tech = owner:give_tech(nil, -1, "hut")
+  local tech = owner:give_tech(nil, -1, false, "hut")
 
   if tech then
     notify.event(owner, unit.tile, E.HUT_TECH,

Modified: trunk/data/default/default.lua
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/default/default.lua?rev=31086&r1=31085&r2=31086&view=diff
==============================================================================
--- trunk/data/default/default.lua      (original)
+++ trunk/data/default/default.lua      Sat Dec 19 06:33:16 2015
@@ -33,7 +33,7 @@
 -- Get a tech from entering a hut.
 function default_hut_get_tech(unit)
   local owner = unit.owner
-  local tech = owner:give_tech(nil, -1, "hut")
+  local tech = owner:give_tech(nil, -1, false, "hut")
 
   if tech then
     notify.event(owner, unit.tile, E.HUT_TECH,

Modified: trunk/data/multiplayer/script.lua
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/multiplayer/script.lua?rev=31086&r1=31085&r2=31086&view=diff
==============================================================================
--- trunk/data/multiplayer/script.lua   (original)
+++ trunk/data/multiplayer/script.lua   Sat Dec 19 06:33:16 2015
@@ -34,8 +34,8 @@
     if player:give_tech(find.tech_type("Theory of Evolution"),
                         0, "researched") then
       -- Give the player two free advances.
-      gained[0] = player:give_tech(nil, 0, "researched")
-      gained[1] = player:give_tech(nil, 0, "researched")
+      gained[0] = player:give_tech(nil, 0, false, "researched")
+      gained[1] = player:give_tech(nil, 0, false, "researched")
 
       -- Notify the player. Include the tech names in a way that makes it
       -- look natural no matter if each tech is announced or not.
@@ -112,7 +112,7 @@
 
     -- Give the player a free advance.
     -- This will give a free advance for each player that shares research.
-    gained = player:give_tech(nil, -1, "researched")
+    gained = player:give_tech(nil, -1, false, "researched")
 
       -- Notify the player. Include the tech names in a way that makes it
       -- look natural no matter if each tech is announced or not.

Modified: trunk/server/scripting/api_server_edit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/api_server_edit.c?rev=31086&r1=31085&r2=31086&view=diff
==============================================================================
--- trunk/server/scripting/api_server_edit.c    (original)
+++ trunk/server/scripting/api_server_edit.c    Sat Dec 19 06:33:16 2015
@@ -19,6 +19,7 @@
 #include "rand.h"
 
 /* common */
+#include "movement.h"
 #include "research.h"
 #include "unittype.h"
 
@@ -32,7 +33,7 @@
 #include "citytools.h"
 #include "console.h" /* enum rfc_status */
 #include "maphand.h"
-#include "movement.h"
+#include "notify.h"
 #include "plrhand.h"
 #include "srv_main.h" /* game_was_started() */
 #include "stdinhand.h"
@@ -272,7 +273,8 @@
   sends script signal "tech_researched" with the given reason
 *****************************************************************************/
 Tech_Type *api_edit_give_technology(lua_State *L, Player *pplayer,
-                                    Tech_Type *ptech, int cost, const char 
*reason)
+                                    Tech_Type *ptech, int cost, bool notify,
+                                    const char *reason)
 {
   struct research *presearch;
   Tech_type_id id;
@@ -316,6 +318,22 @@
     found_new_tech(presearch, id, FALSE, TRUE);
     result = advance_by_number(id);
     script_tech_learned(presearch, pplayer, result, reason);
+
+    if (notify && result != NULL) {
+      const char *adv_name = research_advance_name_translation(presearch, id);
+      char research_name[MAX_LEN_NAME * 2];
+
+      research_pretty_name(presearch, research_name, sizeof(research_name));
+
+      notify_player(pplayer, NULL, E_TECH_GAIN, ftc_server,
+                    Q_("?fromscritp:You acquire %s."), adv_name);
+      notify_research(presearch, pplayer, E_TECH_GAIN, ftc_server,
+                      Q_("?fromscript:%s acquires %s for you."), adv_name);
+      notify_research_embassies(presearch, NULL, E_TECH_EMBASSY, ftc_server,
+                                Q_("?fromscript:%s acquire %s."),
+                                research_name, adv_name);
+    }
+
     return result;
   } else {
     return NULL;

Modified: trunk/server/scripting/api_server_edit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/api_server_edit.h?rev=31086&r1=31085&r2=31086&view=diff
==============================================================================
--- trunk/server/scripting/api_server_edit.h    (original)
+++ trunk/server/scripting/api_server_edit.h    Sat Dec 19 06:33:16 2015
@@ -48,7 +48,7 @@
                                Nation_Type *pnation, const char *ai);
 void api_edit_change_gold(lua_State *L, Player *pplayer, int amount);
 Tech_Type *api_edit_give_technology(lua_State *L, Player *pplayer,
-                                    Tech_Type *ptech, int cost,
+                                    Tech_Type *ptech, int cost, bool notify,
                                     const char *reason);
 bool api_edit_trait_mod_set(lua_State *L, Player *pplayer,
                             const char *trait_name, const int mod);

Modified: trunk/server/scripting/tolua_server.pkg
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/tolua_server.pkg?rev=31086&r1=31085&r2=31086&view=diff
==============================================================================
--- trunk/server/scripting/tolua_server.pkg     (original)
+++ trunk/server/scripting/tolua_server.pkg     Sat Dec 19 06:33:16 2015
@@ -144,7 +144,7 @@
    *    -3          - Apply diplbulbcost */
   Tech_Type *api_edit_give_technology
     @ give_tech (lua_State *L, Player *pplayer, Tech_Type *ptech,
-                 int cost, const char *reason);
+                 int cost, bool notify, const char *reason);
   bool api_edit_trait_mod_set
     @ trait_mod (lua_State *L, Player *pplayer, const char *trait_name,
                  const int mod);
@@ -209,12 +209,12 @@
 
 -- Deprecated; use edit.give_tech()
 function give_technology(player, tech, reason)
-  return edit.give_tech(player, tech, -1, reason)
+  return edit.give_tech(player, tech, -1, false, reason)
 end
 
 -- Deprecated; use edit.give_tech()
 function edit.give_technology(player, tech, reason)
-  return edit.give_tech(player, tech, -1, reason)
+  return edit.give_tech(player, tech, -1, false, reason)
 end
 
 function trait_mod(player, trait, mod)
@@ -253,13 +253,13 @@
   edit.change_gold(self, amount)
 end
 
-function Player:give_tech(tech, cost, reason)
-  return edit.give_tech(self, tech, cost, reason)
+function Player:give_tech(tech, cost, notify, reason)
+  return edit.give_tech(self, tech, cost, notify, reason)
 end
 
 -- Deprecated; use Player:give_tech()
 function Player:give_technology(tech, reason)
-  return edit.give_tech(self, tech, -1, reason)
+  return edit.give_tech(self, tech, -1, false, reason)
 end
 
 function Player:trait_mod(trait, mod)


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

Reply via email to