<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39450 >
Attached patch v1. Also attached test .sav file, that should work by just loading it with the server, no need to even start the game. Using suggested :rule_name() :translated_name() Sorted everything in the order the types are defined, that is: Government Nation_Type Building_Type Unit_Type Tech_Type Terrain
Index: server/scripting/api_methods.h
===================================================================
--- server/scripting/api_methods.h (revision 13101)
+++ server/scripting/api_methods.h (arbetskopia)
@@ -27,5 +27,19 @@
bool api_methods_building_type_is_small_wonder(Building_Type *pbuilding);
bool api_methods_building_type_is_improvement(Building_Type *pbuilding);
+/* rule name and translated name methods */
+const char *api_methods_government_rule_name(Government *pgovernment);
+const char *api_methods_government_translated_name(Government *pgovernment);
+const char *api_methods_nation_type_rule_name(Nation_Type *pnation);
+const char *api_methods_nation_type_translated_name(Nation_Type *pnation);
+const char *api_methods_building_type_rule_name(Building_Type *pbuilding);
+const char *api_methods_building_type_translated_name(Building_Type
+ *pbuilding);
+const char *api_methods_unit_type_rule_name(Unit_Type *punit_type);
+const char *api_methods_unit_type_translated_name(Unit_Type *punit_type);
+const char *api_methods_tech_type_rule_name(Tech_Type *ptech);
+const char *api_methods_tech_type_translated_name(Tech_Type *ptech);
+const char *api_methods_terrain_rule_name(Terrain *pterrain);
+const char *api_methods_terrain_translated_name(Terrain *pterrain);
#endif
Index: server/scripting/api.pkg
===================================================================
--- server/scripting/api.pkg (revision 13101)
+++ server/scripting/api.pkg (arbetskopia)
@@ -94,16 +94,26 @@
/* Class methods. */
+
+/* Player */
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);
+/* Government */
+const char *api_methods_government_rule_name
+ @ methods_government_rule_name (Government *pgovernment);
+const char *api_methods_government_translated_name
+ @ methods_government_translated_name (Government *pgovernment);
+/* Nation_Type */
+const char *api_methods_nation_type_rule_name
+ @ methods_nation_type_rule_name (Nation_Type *pnation);
+const char *api_methods_nation_type_translated_name
+ @ methods_nation_type_translated_name (Nation_Type *pnation);
+
+/* Building_Type */
bool api_methods_building_type_is_wonder
@ methods_building_type_is_wonder (Building_Type *pbuilding);
bool api_methods_building_type_is_great_wonder
@@ -112,8 +122,33 @@
@ methods_building_type_is_small_wonder (Building_Type *pbuilding);
bool api_methods_building_type_is_improvement
@ methods_building_type_is_improvement (Building_Type *pbuilding);
+const char *api_methods_building_type_rule_name
+ @ methods_building_type_rule_name (Building_Type *pbuilding);
+const char *api_methods_building_type_translated_name
+ @ methods_building_type_translated_name (Building_Type *pbuilding);
+/* Unit_Type */
+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);
+const char *api_methods_unit_type_rule_name
+ @ methods_unit_type_rule_name (Unit_Type *punit_type);
+const char *api_methods_unit_type_translated_name
+ @ methods_unit_type_translated_name (Unit_Type *punit_type);
+/* Tech_Type */
+const char *api_methods_tech_type_rule_name
+ @ methods_tech_type_rule_name (Tech_Type *ptech);
+const char *api_methods_tech_type_translated_name
+ @ methods_tech_type_translated_name (Tech_Type *ptech);
+
+/* Terrain */
+const char *api_methods_terrain_rule_name
+ @ methods_terrain_rule_name (Terrain *pterrain);
+const char *api_methods_terrain_translated_name
+ @ methods_terrain_translated_name (Terrain *pterrain);
+
$[
-- Player methods.
function Player:is_human()
@@ -133,6 +168,24 @@
return find.city(self.owner, self.homecity_id)
end
+-- Government methods
+function Government:rule_name()
+ return methods_government_rule_name(self)
+end
+
+function Government:translated_name()
+ return methods_government_translated_name(self)
+end
+
+-- Nation_Type methods
+function Nation_Type:rule_name()
+ return methods_nation_type_rule_name(self)
+end
+
+function Nation_Type:translated_name()
+ return methods_nation_type_translated_name(self)
+end
+
-- Building_Type methods.
function Building_Type:build_shield_cost()
return self.build_cost
@@ -154,6 +207,14 @@
return methods_building_type_is_improvement(self)
end
+function Building_Type:rule_name()
+ return methods_building_type_rule_name(self)
+end
+
+function Building_Type:translated_name()
+ return methods_building_type_translated_name(self)
+end
+
-- Unit_Type methods.
function Unit_Type:build_shield_cost()
return self.build_cost
@@ -166,6 +227,32 @@
function Unit_Type:has_role(role)
return methods_unit_type_has_role(self, role)
end
+
+function Unit_Type:rule_name()
+ return methods_unit_type_rule_name(self)
+end
+
+function Unit_Type:translated_name()
+ return methods_unit_type_translated_name(self)
+end
+
+-- Tech_Type methods
+function Tech_Type:rule_name()
+ return methods_tech_type_rule_name(self)
+end
+
+function Tech_Type:translated_name()
+ return methods_tech_type_translated_name(self)
+end
+
+-- Terrain methods
+function Terrain:rule_name()
+ return methods_terrain_rule_name(self)
+end
+
+function Terrain:translated_name()
+ return methods_terrain_translated_name(self)
+end
$]
/* Object find module. */
Index: server/scripting/api_methods.c
===================================================================
--- server/scripting/api_methods.c (revision 13101)
+++ server/scripting/api_methods.c (arbetskopia)
@@ -15,7 +15,13 @@
#include <config.h>
#endif
+#include "government.h"
+#include "improvement.h"
+#include "nation.h"
+#include "tech.h"
+#include "terrain.h"
#include "unitlist.h"
+#include "unittype.h"
#include "api_methods.h"
#include "script.h"
@@ -98,4 +104,98 @@
return is_improvement(pbuilding->index);
}
+/**************************************************************************
+ Return rule name for Government
+**************************************************************************/
+const char *api_methods_government_rule_name(Government *pgovernment)
+{
+ return government_rule_name(pgovernment);
+}
+/**************************************************************************
+ Return translated name for Government
+**************************************************************************/
+const char *api_methods_government_translated_name(Government *pgovernment)
+{
+ return government_name_translation(pgovernment);
+}
+
+/**************************************************************************
+ Return rule name for Nation_Type
+**************************************************************************/
+const char *api_methods_nation_type_rule_name(Nation_Type *pnation)
+{
+ return nation_rule_name(pnation);
+}
+
+/**************************************************************************
+ Return translated name for Nation_Type
+**************************************************************************/
+const char *api_methods_nation_type_translated_name(Nation_Type *pnation)
+{
+ return nation_name_translation(pnation);
+}
+
+/**************************************************************************
+ Return rule name for Building_Type
+**************************************************************************/
+const char *api_methods_building_type_rule_name(Building_Type *pbuilding)
+{
+ return improvement_rule_name(pbuilding->index);
+}
+
+/**************************************************************************
+ Return translated name for Building_Type
+**************************************************************************/
+const char *api_methods_building_type_translated_name(Building_Type *pbuilding)
+{
+ return improvement_name_translation(pbuilding->index);
+}
+
+/**************************************************************************
+ Return rule name for Unit_Type
+**************************************************************************/
+const char *api_methods_unit_type_rule_name(Unit_Type *punit_type)
+{
+ return utype_rule_name(punit_type);
+}
+
+/**************************************************************************
+ Return translated name for Unit_Type
+**************************************************************************/
+const char *api_methods_unit_type_translated_name(Unit_Type *punit_type)
+{
+ return utype_name_translation(punit_type);
+}
+
+/**************************************************************************
+ Return rule name for Tech_Type
+**************************************************************************/
+const char *api_methods_tech_type_rule_name(Tech_Type *ptech)
+{
+ return advance_rule_name(ptech->index);
+}
+
+/**************************************************************************
+ Return translated name for Tech_Type
+**************************************************************************/
+const char *api_methods_tech_type_translated_name(Tech_Type *ptech)
+{
+ return advance_name_translation(ptech->index);
+}
+
+/**************************************************************************
+ Return rule name for Terrain
+**************************************************************************/
+const char *api_methods_terrain_rule_name(Terrain *pterrain)
+{
+ return terrain_rule_name(pterrain);
+}
+
+/**************************************************************************
+ Return translated name for Terrain
+**************************************************************************/
+const char *api_methods_terrain_translated_name(Terrain *pterrain)
+{
+ return terrain_name_translation(pterrain);
+}
test-name-api.sav
Description: Binary data
_______________________________________________ Freeciv-dev mailing list [email protected] https://mail.gna.org/listinfo/freeciv-dev
