[Freeciv-Dev] (PR#39451) Add signal emit to scripting api

2007-07-17 Thread Ulrik Sverdrup

URL: 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


Re: [Freeciv-Dev] (PR#39451) Add signal emit to scripting api

2007-07-14 Thread William Allen Simpson

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39451 

Ulrik Sverdrup wrote:
 As a third option, we could make more abstract functions for giving
 techs etc so that it would not be necessary to initiate signals in the
 code; really if a tech is given in a scenario script, the side effects
 (signals etc) should be so fundamental that we shouldn't need to send
 the signals manually.
 
That sounds better to me.  KISS.

Remember, the lua code cannot do anything that requires understanding of
the underlying structure, nor anything random (choosing), as that would
break fundamental assumptions of the network, ruleset, and savegame code.



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


Re: [Freeciv-Dev] (PR#39451) Add signal emit to scripting api

2007-07-14 Thread Ulrik Sverdrup

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39451 

 That sounds better to me.  KISS.

 Remember, the lua code cannot do anything that requires understanding of
 the underlying structure, nor anything random (choosing), as that would
 break fundamental assumptions of the network, ruleset, and savegame code.

Good catch: The hut code that per has been working on (and now I),
uses api_utilities_random in server/scripting/api_utilities.c . That
is a random outcome on the server, and should be reproducible since it
uses myrand. Is this not safe in the long run?



___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#39451) Add signal emit to scripting api

2007-07-10 Thread Ulrik Sverdrup

URL: http://bugs.freeciv.org/Ticket/Display.html?id=39451 

Allow signals to be emitted from Lua scripts.

Add a wrapper for script_signal_emit to the signal module.

___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev