Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#13024) wanted: new script API types
Home

[Freeciv-Dev] (PR#13024) wanted: new script API types

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#13024) wanted: new script API types
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Tue, 10 May 2005 13:32:28 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch:

Adds the Government type to the scripting API.
Adds the following methods:
  * Unit_Type:build_shield_cost()
  * Building_Type:build_shield_cost()

Index: server/scripting/api.pkg
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api.pkg,v
retrieving revision 1.7
diff -u -u -r1.7 api.pkg
--- server/scripting/api.pkg    10 May 2005 16:58:53 -0000      1.7
+++ server/scripting/api.pkg    10 May 2005 20:29:35 -0000
@@ -64,7 +64,7 @@
   const int index @ id;
 };
 
-struct Building_Type {
+struct Government {
   const char *name_orig @ name;
 
   const int index @ id;
@@ -77,9 +77,19 @@
   const int index @ id;
 };
 
+struct Building_Type {
+  const char *name_orig @ name;
+
+  int build_cost;
+
+  const int index @ id;
+};
+
 struct Unit_Type {
   const char *name_orig @ name;
 
+  int build_cost;
+
   const int index @ id;
 };
 
@@ -131,8 +141,17 @@
   return find.terrain(self.terrain_id)
 end
 
--- UnitType methods.
-function UnitType:has_role(role)
+-- Building_Type methods.
+function Building_Type:build_shield_cost()
+  return self.build_cost
+end
+
+-- Unit_Type methods.
+function Unit_Type:build_shield_cost()
+  return self.build_cost
+end
+
+function Unit_Type:has_role(role)
   return methods_unit_type_has_role(self, role)
 end
 $]
@@ -144,26 +163,30 @@
   Unit *api_find_unit @ unit (Player *pplayer, int unit_id);
   Tile *api_find_tile @ tile (int nat_x, int nat_y);
 
-  Building_Type *
-    api_find_building_type_by_name @ building_type (const char *name_orig);
-  Building_Type *
-    api_find_building_type @ building_type (int building_type_id);
-  Nation_Type *
-    api_find_nation_type_by_name @ nation_type (const char *name_orig);
-  Nation_Type *
-    api_find_nation_type @ nation_type (int nation_type_id);
-  Unit_Type *
-    api_find_unit_type_by_name @ unit_type (const char *name_orig);
-  Unit_Type *
-    api_find_unit_type @ unit_type (int unit_type_id);
-  Tech_Type *
-    api_find_tech_type_by_name @ tech_type (const char *name_orig);
-  Tech_Type *
-    api_find_tech_type @ tech_type (int tech_type_id);
-  Terrain *
-    api_find_terrain_by_name @ terrain (const char *name_orig);
-  Terrain *
-    api_find_terrain @ terrain(int terrain_id);
+  Government *api_find_government
+               @ government (int government_id);
+  Government *api_find_government_by_name
+               @ government (const char *name_orig);
+  Nation_Type *api_find_nation_type_by_name
+               @ nation_type (const char *name_orig);
+  Nation_Type *api_find_nation_type
+               @ nation_type (int nation_type_id);
+  Building_Type *api_find_building_type_by_name
+               @ building_type (const char *name_orig);
+  Building_Type *api_find_building_type
+               @ building_type (int building_type_id);
+  Unit_Type *api_find_unit_type_by_name
+               @ unit_type (const char *name_orig);
+  Unit_Type *api_find_unit_type
+               @ unit_type (int unit_type_id);
+  Tech_Type *api_find_tech_type_by_name
+               @ tech_type (const char *name_orig);
+  Tech_Type *api_find_tech_type
+               @ tech_type (int tech_type_id);
+  Terrain *api_find_terrain_by_name
+               @ terrain (const char *name_orig);
+  Terrain *api_find_terrain
+               @ terrain (int terrain_id);
 }
 
 $[
Index: server/scripting/api_find.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_find.c,v
retrieving revision 1.4
diff -u -u -r1.4 api_find.c
--- server/scripting/api_find.c 10 May 2005 16:58:53 -0000      1.4
+++ server/scripting/api_find.c 10 May 2005 20:29:35 -0000
@@ -61,20 +61,19 @@
 }
 
 /**************************************************************************
-  Return the improvement type with the given impr_type_id index.
+  Return the government with the given government_id index.
 **************************************************************************/
-Building_Type *api_find_building_type(int building_type_id)
+Government *api_find_government(int government_id)
 {
-  return get_improvement_type(building_type_id);
+  return get_government(government_id);
 }
 
 /**************************************************************************
-  Return the improvement type with the given name_orig.
+  Return the governmet with the given name_orig.
 **************************************************************************/
-Building_Type *api_find_building_type_by_name(const char *name_orig)
+Government *api_find_government_by_name(const char *name_orig)
 {
-  Impr_type_id id = find_improvement_by_name_orig(name_orig);
-  return api_find_building_type(id);
+  return find_government_by_name_orig(name_orig);
 }
 
 /**************************************************************************
@@ -95,6 +94,23 @@
 }
 
 /**************************************************************************
+  Return the improvement type with the given impr_type_id index.
+**************************************************************************/
+Building_Type *api_find_building_type(int building_type_id)
+{
+  return get_improvement_type(building_type_id);
+}
+
+/**************************************************************************
+  Return the improvement type with the given name_orig.
+**************************************************************************/
+Building_Type *api_find_building_type_by_name(const char *name_orig)
+{
+  Impr_type_id id = find_improvement_by_name_orig(name_orig);
+  return api_find_building_type(id);
+}
+
+/**************************************************************************
   Return the unit type with the given unit_type_id index.
 **************************************************************************/
 Unit_Type *api_find_unit_type(int unit_type_id)
Index: server/scripting/api_find.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_find.h,v
retrieving revision 1.4
diff -u -u -r1.4 api_find.h
--- server/scripting/api_find.h 10 May 2005 16:58:53 -0000      1.4
+++ server/scripting/api_find.h 10 May 2005 20:29:35 -0000
@@ -22,10 +22,12 @@
 Unit *api_find_unit(Player *pplayer, int unit_id);
 Tile *api_find_tile(int nat_x, int nat_y);
 
-Building_Type *api_find_building_type(int building_type_id);
-Building_Type *api_find_building_type_by_name(const char *name_orig);
+Government *api_find_government(int government_id);
+Government *api_find_government_by_name(const char *name_orig);
 Nation_Type *api_find_nation_type(int nation_type_id);
 Nation_Type *api_find_nation_type_by_name(const char *name_orig);
+Building_Type *api_find_building_type(int building_type_id);
+Building_Type *api_find_building_type_by_name(const char *name_orig);
 Unit_Type *api_find_unit_type(int unit_type_id);
 Unit_Type *api_find_unit_type_by_name(const char *name_orig);
 Tech_Type *api_find_tech_type(int tech_type_id);
Index: server/scripting/api_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_types.h,v
retrieving revision 1.6
diff -u -u -r1.6 api_types.h
--- server/scripting/api_types.h        10 May 2005 16:58:53 -0000      1.6
+++ server/scripting/api_types.h        10 May 2005 20:29:35 -0000
@@ -18,9 +18,10 @@
 #include "player.h"
 #include "city.h"
 #include "unit.h"
-#include "map.h"
-#include "improvement.h"
+#include "tile.h"
+#include "government.h"
 #include "nation.h"
+#include "improvement.h"
 #include "tech.h"
 #include "unittype.h"
 #include "terrain.h"
@@ -33,8 +34,9 @@
 typedef struct city City;
 typedef struct unit Unit;
 typedef struct tile Tile;
-typedef struct impr_type Building_Type;
+typedef struct government Government;
 typedef struct nation_type Nation_Type;
+typedef struct impr_type Building_Type;
 typedef struct unit_type Unit_Type;
 typedef struct advance Tech_Type;
 typedef struct tile_type Terrain;
Index: server/scripting/script_signal.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/script_signal.c,v
retrieving revision 1.6
diff -u -u -r1.6 script_signal.c
--- server/scripting/script_signal.c    10 May 2005 16:58:53 -0000      1.6
+++ server/scripting/script_signal.c    10 May 2005 20:29:35 -0000
@@ -90,9 +90,17 @@
 static const char *api_type_names[] = {
   NULL, NULL, NULL,
 
-  "Player", "City", "Unit", "Tile",
-
-  "Building_Type", "Nation_Type", "Unit_Type", "Tech_Type", "Terrain"
+  "Player",
+  "City",
+  "Unit",
+  "Tile",
+
+  "Government",
+  "Building_Type",
+  "Nation_Type",
+  "Unit_Type",
+  "Tech_Type",
+  "Terrain"
 };
 
 /**************************************************************************
Index: server/scripting/script_signal.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/script_signal.h,v
retrieving revision 1.4
diff -u -u -r1.4 script_signal.h
--- server/scripting/script_signal.h    10 May 2005 16:58:53 -0000      1.4
+++ server/scripting/script_signal.h    10 May 2005 20:29:35 -0000
@@ -26,6 +26,7 @@
   API_TYPE_UNIT,
   API_TYPE_TILE,
 
+  API_TYPE_GOVERNMENT,
   API_TYPE_BUILDING_TYPE,
   API_TYPE_NATION_TYPE,
   API_TYPE_UNIT_TYPE,

[Prev in Thread] Current Thread [Next in Thread]