Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2006:
[Freeciv-Dev] (PR#16347) Lua tech API improvement
Home

[Freeciv-Dev] (PR#16347) Lua tech API improvement

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#16347) Lua tech API improvement
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sun, 9 Apr 2006 06:08:48 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=16347 >

This patch changes the return type of the give_technology() to Tech_Type
instead of bool, so that the script can know which random tech was granted
by this function when a random tech was requested.

This also matches the API of the events documentation in the wiki.

  - Per

Index: server/scripting/api_actions.h
===================================================================
--- server/scripting/api_actions.h      (revision 11822)
+++ server/scripting/api_actions.h      (working copy)
@@ -21,7 +21,7 @@
                              int moves_left);
 void api_actions_create_city(Player *pplayer, Tile *ptile, const char *name);
 void api_actions_change_gold(Player *pplayer, int amount);
-bool api_actions_give_technology(Player *pplayer, Tech_Type *ptech);
+Tech_Type *api_actions_give_technology(Player *pplayer, Tech_Type *ptech);
 
 #endif
 
Index: server/scripting/api.pkg
===================================================================
--- server/scripting/api.pkg    (revision 11822)
+++ server/scripting/api.pkg    (working copy)
@@ -411,6 +411,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);
-bool api_actions_give_technology @ give_technology (Player *pplayer,
+Tech_Type *api_actions_give_technology @ give_technology (Player *pplayer,
                                                    Tech_Type *ptech);
 
Index: server/scripting/api_actions.c
===================================================================
--- server/scripting/api_actions.c      (revision 11822)
+++ server/scripting/api_actions.c      (working copy)
@@ -20,6 +20,8 @@
 #include "techtools.h"
 #include "unittools.h"
 
+#include "api_find.h"
+
 #include "api_actions.h"
 
 
@@ -54,9 +56,11 @@
 }
 
 /**************************************************************************
-  Give pplayer technology ptech.
+  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.
 **************************************************************************/
-bool api_actions_give_technology(Player *pplayer, Tech_Type *ptech)
+Tech_Type *api_actions_give_technology(Player *pplayer, Tech_Type *ptech)
 {
   Tech_type_id id;
 
@@ -72,8 +76,8 @@
   if (get_invention(pplayer, id) != TECH_KNOWN) {
     do_free_cost(pplayer, id);
     found_new_tech(pplayer, id, FALSE, TRUE);
-    return TRUE;
+    return api_find_tech_type(id);
   } else {
-    return FALSE;
+    return api_find_tech_type(A_NONE);
   }
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#16347) Lua tech API improvement, Per I. Mathisen <=