[Freeciv-Dev] (PR#13024) wanted: new script API types
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13024 >
The attached patch:
* Renames Impr_Type to Building_Type.
* Adds UnitType:has_role(role) method.
Index: server/scripting/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/Makefile.am,v
retrieving revision 1.3
diff -u -u -r1.3 Makefile.am
--- server/scripting/Makefile.am 5 May 2005 12:35:28 -0000 1.3
+++ server/scripting/Makefile.am 10 May 2005 16:56:40 -0000
@@ -17,6 +17,8 @@
api_gen.h \
api_intl.c \
api_intl.h \
+ api_methods.c \
+ api_methods.h \
api_notify.c \
api_notify.h \
api_utilities.c \
Index: server/scripting/api.pkg
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api.pkg,v
retrieving revision 1.6
diff -u -u -r1.6 api.pkg
--- server/scripting/api.pkg 10 May 2005 02:25:27 -0000 1.6
+++ server/scripting/api.pkg 10 May 2005 16:56:40 -0000
@@ -19,6 +19,7 @@
$#include "api_actions.h"
$#include "api_find.h"
$#include "api_intl.h"
+$#include "api_methods.h"
$#include "api_notify.h"
$#include "api_utilities.h"
$#include "script.h"
@@ -63,7 +64,7 @@
const int index @ id;
};
-struct Impr_Type {
+struct Building_Type {
const char *name_orig @ name;
const int index @ id;
@@ -92,6 +93,11 @@
const char *terrain_name_orig @ name;
};
+
+/* Class methods. */
+bool api_methods_unit_type_has_role
+ @ methods_unit_type_has_role(Unit_Type *punit_type, const char *role);
+
$[
-- Player methods.
function Player:is_human()
@@ -124,6 +130,11 @@
function Tile:terrain()
return find.terrain(self.terrain_id)
end
+
+-- UnitType methods.
+function UnitType:has_role(role)
+ return methods_unit_type_has_role(self, role)
+end
$]
/* Object find module. */
@@ -133,10 +144,10 @@
Unit *api_find_unit @ unit (Player *pplayer, int unit_id);
Tile *api_find_tile @ tile (int nat_x, int nat_y);
- Impr_Type *
- api_find_impr_type_by_name @ impr_type (const char *name_orig);
- Impr_Type *
- api_find_impr_type @ impr_type (int impr_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);
Nation_Type *
api_find_nation_type_by_name @ nation_type (const char *name_orig);
Nation_Type *
Index: server/scripting/api_find.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_find.c,v
retrieving revision 1.3
diff -u -u -r1.3 api_find.c
--- server/scripting/api_find.c 10 May 2005 00:35:15 -0000 1.3
+++ server/scripting/api_find.c 10 May 2005 16:56:40 -0000
@@ -63,18 +63,18 @@
/**************************************************************************
Return the improvement type with the given impr_type_id index.
**************************************************************************/
-Impr_Type *api_find_impr_type(int impr_type_id)
+Building_Type *api_find_building_type(int building_type_id)
{
- return get_improvement_type(impr_type_id);
+ return get_improvement_type(building_type_id);
}
/**************************************************************************
Return the improvement type with the given name_orig.
**************************************************************************/
-Impr_Type *api_find_impr_type_by_name(const char *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_impr_type(id);
+ return api_find_building_type(id);
}
/**************************************************************************
Index: server/scripting/api_find.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_find.h,v
retrieving revision 1.3
diff -u -u -r1.3 api_find.h
--- server/scripting/api_find.h 10 May 2005 00:35:15 -0000 1.3
+++ server/scripting/api_find.h 10 May 2005 16:56:40 -0000
@@ -22,8 +22,8 @@
Unit *api_find_unit(Player *pplayer, int unit_id);
Tile *api_find_tile(int nat_x, int nat_y);
-Impr_Type *api_find_impr_type(int impr_type_id);
-Impr_Type *api_find_impr_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);
Nation_Type *api_find_nation_type(int nation_type_id);
Nation_Type *api_find_nation_type_by_name(const char *name_orig);
Unit_Type *api_find_unit_type(int unit_type_id);
Index: server/scripting/api_methods.c
===================================================================
RCS file: server/scripting/api_methods.c
diff -N server/scripting/api_methods.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ server/scripting/api_methods.c 10 May 2005 16:56:40 -0000
@@ -0,0 +1,32 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Project
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "api_methods.h"
+#include "script.h"
+
+bool api_methods_unit_type_has_role(Unit_Type *punit_type, const char *role)
+{
+ enum unit_role_id id = unit_role_from_str(role);
+
+ if (id != L_LAST) {
+ return unit_has_role(punit_type->index, id);
+ } else {
+ script_error("Unit role \"%s\" does not exist", role);
+ return FALSE;
+ }
+}
+
Index: server/scripting/api_methods.h
===================================================================
RCS file: server/scripting/api_methods.h
diff -N server/scripting/api_methods.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ server/scripting/api_methods.h 10 May 2005 16:56:40 -0000
@@ -0,0 +1,22 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Project
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifndef FC__API_METHODS_H
+#define FC__API_METHODS_H
+
+#include "api_types.h"
+
+bool api_methods_unit_type_has_role(Unit_Type *punit_type, const char *role);
+
+#endif
+
Index: server/scripting/api_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_types.h,v
retrieving revision 1.5
diff -u -u -r1.5 api_types.h
--- server/scripting/api_types.h 10 May 2005 02:09:57 -0000 1.5
+++ server/scripting/api_types.h 10 May 2005 16:56:40 -0000
@@ -33,7 +33,7 @@
typedef struct city City;
typedef struct unit Unit;
typedef struct tile Tile;
-typedef struct impr_type Impr_Type;
+typedef struct impr_type Building_Type;
typedef struct nation_type Nation_Type;
typedef struct unit_type Unit_Type;
typedef struct advance Tech_Type;
Index: server/scripting/script_signal.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/script_signal.c,v
retrieving revision 1.5
diff -u -u -r1.5 script_signal.c
--- server/scripting/script_signal.c 10 May 2005 16:13:47 -0000 1.5
+++ server/scripting/script_signal.c 10 May 2005 16:56:40 -0000
@@ -92,7 +92,7 @@
"Player", "City", "Unit", "Tile",
- "Impr_Type", "Nation_Type", "Unit_Type", "Tech_Type", "Terrain"
+ "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.3
diff -u -u -r1.3 script_signal.h
--- server/scripting/script_signal.h 10 May 2005 16:13:47 -0000 1.3
+++ server/scripting/script_signal.h 10 May 2005 16:56:40 -0000
@@ -26,7 +26,7 @@
API_TYPE_UNIT,
API_TYPE_TILE,
- API_TYPE_IMPR_TYPE,
+ API_TYPE_BUILDING_TYPE,
API_TYPE_NATION_TYPE,
API_TYPE_UNIT_TYPE,
API_TYPE_TECH_TYPE,
|
|