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

[Freeciv-Dev] (PR#13037) [PATCH] new API functions wanted

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#13037) [PATCH] new API functions wanted
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Tue, 10 May 2005 17:52:25 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch should add all of these.

Index: server/scripting/api.pkg
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api.pkg,v
retrieving revision 1.8
diff -u -u -r1.8 api.pkg
--- server/scripting/api.pkg    10 May 2005 20:33:08 -0000      1.8
+++ server/scripting/api.pkg    11 May 2005 00:51:25 -0000
@@ -105,8 +105,25 @@
 
 
 /* Class methods. */
+int api_methods_player_num_cities
+       @ methods_player_num_cities (Player *pplayer);
+int api_methods_player_num_units
+       @ methods_player_num_units (Player *pplayer);
+
+bool api_methods_unit_type_has_flag
+       @ methods_unit_type_has_flag (Unit_Type *punit_type, const char *flag);
 bool api_methods_unit_type_has_role
-       @ methods_unit_type_has_role(Unit_Type *punit_type, const char *role);
+       @ methods_unit_type_has_role (Unit_Type *punit_type, const char *role);
+
+bool api_methods_building_type_is_wonder
+       @ methods_building_type_is_wonder (Building_Type *pbuilding);
+bool api_methods_building_type_is_great_wonder
+       @ methods_building_type_is_great_wonder (Building_Type *pbuilding);
+bool api_methods_building_type_is_small_wonder
+       @ methods_building_type_is_small_wonder (Building_Type *pbuilding);
+bool api_methods_building_type_is_improvement
+       @ methods_building_type_is_improvement (Building_Type *pbuilding);
+
 
 $[
 -- Player methods.
@@ -118,6 +135,14 @@
   return find.nation(self.nation_id)
 end
 
+function Player:num_cities()
+  return methods_player_num_cities(self)
+end
+
+function Player:num_units()
+  return methods_player_num_units(self)
+end
+
 -- City methods.
 function City:owner()
   return find.player(self.owner_id)
@@ -146,11 +171,31 @@
   return self.build_cost
 end
 
+function Building_Type:is_wonder()
+  return methods_building_type_is_wonder(self)
+end
+
+function Building_Type:is_great_wonder()
+  return methods_building_type_is_great_wonder(self)
+end
+
+function Building_Type:is_small_wonder()
+  return methods_building_type_is_small_wonder(self)
+end
+
+function Building_Type:is_improvement()
+  return methods_building_type_is_improvement(self)
+end
+
 -- Unit_Type methods.
 function Unit_Type:build_shield_cost()
   return self.build_cost
 end
 
+function Unit_Type:has_flag(flag)
+  return methods_unit_type_has_flag(self, flag)
+end
+
 function Unit_Type:has_role(role)
   return methods_unit_type_has_role(self, role)
 end
Index: server/scripting/api_methods.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_methods.c,v
retrieving revision 1.1
diff -u -u -r1.1 api_methods.c
--- server/scripting/api_methods.c      10 May 2005 16:58:53 -0000      1.1
+++ server/scripting/api_methods.c      11 May 2005 00:51:25 -0000
@@ -18,6 +18,40 @@
 #include "api_methods.h"
 #include "script.h"
 
+/**************************************************************************
+  Return the number of cities pplayer has.
+**************************************************************************/
+int api_methods_player_num_cities(Player *pplayer)
+{
+  return city_list_size(pplayer->cities);
+}
+
+/**************************************************************************
+  Return the number of units pplayer has.
+**************************************************************************/
+int api_methods_player_num_units(Player *pplayer)
+{
+  return unit_list_size(pplayer->units);
+}
+
+/**************************************************************************
+  Return TRUE if punit_type has flag.
+**************************************************************************/
+bool api_methods_unit_type_has_flag(Unit_Type *punit_type, const char *flag)
+{
+  enum unit_flag_id id = unit_flag_from_str(flag);
+
+  if (id != F_LAST) {
+    return unit_type_flag(punit_type->index, id);
+  } else {
+    script_error("Unit flag \"%s\" does not exist", flag);
+    return FALSE;
+  }
+}
+
+/**************************************************************************
+  Return TRUE if punit_type has role.
+**************************************************************************/
 bool api_methods_unit_type_has_role(Unit_Type *punit_type, const char *role)
 {
   enum unit_role_id id = unit_role_from_str(role);
@@ -30,3 +64,36 @@
   }
 }
 
+/**************************************************************************
+  Return TRUE if pbuilding is a wonder.
+**************************************************************************/
+bool api_methods_building_type_is_wonder(Building_Type *pbuilding)
+{
+  return is_wonder(pbuilding->index);
+}
+
+/**************************************************************************
+  Return TRUE if pbuilding is a great wonder.
+**************************************************************************/
+bool api_methods_building_type_is_great_wonder(Building_Type *pbuilding)
+{
+  return is_great_wonder(pbuilding->index);
+}
+
+/**************************************************************************
+  Return TRUE if pbuilding is a small wonder.
+**************************************************************************/
+bool api_methods_building_type_is_small_wonder(Building_Type *pbuilding)
+{
+  return is_small_wonder(pbuilding->index);
+}
+
+/**************************************************************************
+  Return TRUE if pbuilding is a building.
+**************************************************************************/
+bool api_methods_building_type_is_improvement(Building_Type *pbuilding)
+{
+  return is_improvement(pbuilding->index);
+}
+
+
Index: server/scripting/api_methods.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_methods.h,v
retrieving revision 1.1
diff -u -u -r1.1 api_methods.h
--- server/scripting/api_methods.h      10 May 2005 16:58:53 -0000      1.1
+++ server/scripting/api_methods.h      11 May 2005 00:51:25 -0000
@@ -16,7 +16,16 @@
 
 #include "api_types.h"
 
+int api_methods_player_num_cities(Player *pplayer);
+int api_methods_player_num_units(Player *pplayer);
+
+bool api_methods_unit_type_has_flag(Unit_Type *punit_type, const char *flag);
 bool api_methods_unit_type_has_role(Unit_Type *punit_type, const char *role);
 
+bool api_methods_building_type_is_wonder(Building_Type *pbuilding);
+bool api_methods_building_type_is_great_wonder(Building_Type *pbuilding);
+bool api_methods_building_type_is_small_wonder(Building_Type *pbuilding);
+bool api_methods_building_type_is_improvement(Building_Type *pbuilding);
+
 #endif
 

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