http://bugs.freeciv.org/Ticket/Display.html?id=39451 >
Committed the attached patch to trunk as r13112, posted first three days
ago.
Rationale:
(PR#39451) Add signal emit to scripting api
Make sure the scripting api action give_technology sends a
script signal message for every researched technology.
give_technology now takes a new argument reason that is sent
with the signal, and it should almost always be "hut" for
scripts.
It was decided that script signal emission should not be
exposed to the scripting api.
diff --git a/server/scripting/api.pkg b/server/scripting/api.pkg
index d8a5986..3eee83d 100644
--- a/server/scripting/api.pkg
+++ b/server/scripting/api.pkg
@@ -494,5 +494,6 @@ void api_actions_create_city @ create_city (Player *pplayer, Tile *ptile,
const char *name);
void api_actions_change_gold @ change_gold (Player *pplayer, int amount);
Tech_Type *api_actions_give_technology @ give_technology (Player *pplayer,
- Tech_Type *ptech);
+ Tech_Type *ptech,
+ const char *reason);
diff --git a/server/scripting/api_actions.c b/server/scripting/api_actions.c
index 61600bf..ad93f9c 100644
--- a/server/scripting/api_actions.c
+++ b/server/scripting/api_actions.c
@@ -21,6 +21,7 @@
#include "unittools.h"
#include "api_find.h"
+#include "script_signal.h"
#include "api_actions.h"
@@ -59,10 +60,13 @@ void api_actions_change_gold(Player *pplayer, int amount)
Give pplayer technology ptech. Quietly returns A_NONE (zero) if
player already has this tech; otherwise returns the tech granted.
Use NULL for ptech to grant a random tech.
+ sends script signal "tech_researched" with the given reason
**/
-Tech_Type *api_actions_give_technology(Player *pplayer, Tech_Type *ptech)
+Tech_Type *api_actions_give_technology(Player *pplayer, Tech_Type *ptech,
+ const char *reason)
{
Tech_type_id id;
+ Tech_Type *result;
if (ptech) {
id = ptech->index;
@@ -76,7 +80,11 @@ Tech_Type *api_actions_give_technology(Player *pplayer, Tech_Type *ptech)
if (get_invention(pplayer, id) != TECH_KNOWN) {
do_free_cost(pplayer, id);
found_new_tech(pplayer, id, FALSE, TRUE);
-return api_find_tech_type(id);
+result = api_find_tech_type(id);
+script_signal_emit("tech_researched", 3,
+ API_TYPE_TECH_TYPE, result, API_TYPE_PLAYER, pplayer,
+ API_TYPE_STRING, reason);
+return result;
} else {
return api_find_tech_type(A_NONE);
}
diff --git a/server/scripting/api_actions.h b/server/scripting/api_actions.h
index 135340c..4273ea1 100644
--- a/server/scripting/api_actions.h
+++ b/server/scripting/api_actions.h
@@ -21,7 +21,8 @@ Unit *api_actions_create_unit(Player *pplayer, Tile *ptile, Unit_Type *ptype,
int moves_left);
void api_actions_create_city(Player *pplayer, Tile *ptile, const char *name);
void api_actions_change_gold(Player *pplayer, int amount);
-Tech_Type *api_actions_give_technology(Player *pplayer, Tech_Type *ptech);
+Tech_Type *api_actions_give_technology(Player *pplayer, Tech_Type *ptech,
+ const char *reason);
#endif
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev