-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate_interfaces.py
164 lines (125 loc) · 4.9 KB
/
generate_interfaces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
bwapi_modules = [
"AIModule",
# "Bitmap",
"Bullet",
"BulletType",
"Client",
"Color",
"Constants",
"CoordinateType",
"DamageType",
"Error",
"Event",
"EventType",
"ExplosionType",
"Flag",
"Force",
"Game",
"GameType",
"Input",
"Latency",
"Order",
"Player",
"PlayerType",
"Position",
"Race",
"TechType",
"TilePosition",
"Unit",
"UnitCommand",
"UnitCommandType",
"UnitSizeType",
"UnitType",
"UpgradeType",
"WeaponType",
]
bwta_modules = [
"BaseLocation",
"Chokepoint",
"Polygon",
"RectangleArray",
"Region",
]
bwapi_collision_names = set(['None', 'Normal', 'Unknown', 'Irradiate', 'Corrosive_Acid', 'Lockdown', 'Invalid', 'Stasis_Field', 'Optical_Flare', 'Mind_Control', 'Nuclear_Strike', 'Independent', 'Neutral', 'Spider_Mines', 'Yamato_Gun', 'Restoration', 'Plague', 'EMP_Shockwave', 'Parasite', 'Maelstrom', 'Spawn_Broodlings', 'Feedback', 'Dark_Swarm', 'Consume', 'Ensnare', 'Psionic_Storm', 'Disruption_Web', 'Melee', 'Attack_Move', 'Attack_Unit', 'Build', 'Build_Addon', 'Train', 'Morph', 'Research', 'Upgrade', 'Set_Rally_Position', 'Set_Rally_Unit', 'Move', 'Patrol', 'Hold_Position', 'Stop', 'Follow', 'Gather', 'Return_Cargo', 'Repair', 'Burrow', 'Unburrow', 'Cloak', 'Decloak', 'Siege', 'Unsiege', 'Lift', 'Land', 'Load', 'Unload', 'Unload_All', 'Unload_All_Position', 'Right_Click_Position', 'Right_Click_Unit', 'Halt_Construction', 'Cancel_Construction', 'Cancel_Addon', 'Cancel_Train', 'Cancel_Train_Slot', 'Cancel_Morph', 'Cancel_Research', 'Cancel_Upgrade', 'Use_Tech', 'Use_Tech_Position', 'Use_Tech_Unit', 'Gemini_Missiles', 'Burst_Lasers', 'Longbolt_Missile', 'Acid_Spore', 'Glave_Wurm', 'Seeker_Spores', 'Phase_Disruptor', 'Pulse_Cannon', 'Neutron_Flare', 'Halo_Rockets', 'Subterranean_Spines', 'Fragmentation_Grenade', 'Player', 'RescuePassive', 'PlayerLeft', 'Burrowing'])
def get_templates():
wrapper_modules = {'BWAPI': ["Player", "Unit", "Force"], 'BWTA': ["Region", "Chokepoint", "BaseLocation"]}
wrapper_ptrnext_modules = {'BWAPI': ["Position", "TilePosition", "UnitType"]}
templates = []
for wrapper_type in ('Set', 'List'):
for (namespace, modules) in wrapper_modules.items():
templates += ["%%template (%(module)s%(wrapper_type)s) %(wrapper_type)sWrapper<%(namespace)s::%(module)s*>;"%locals() for module in modules]
for (namespace, modules) in wrapper_ptrnext_modules.items():
templates += ["%%template (%(module)s%(wrapper_type)s) %(wrapper_type)sWrapper_PtrNext<%(namespace)s::%(module)s>;"%locals() for module in modules]
return '\n'.join(templates)
templates = get_templates()
f = open('pybw.i','w')
f.write("""
%module pybw_swig
%include "std_string.i"
%include "std_vector.i"
//%include "std_pair.i"
//%include "std_map.i"
//%include "std_set.i"
%include "std_wrappers.i"
""" + templates + """
%include "bwapi.i"
%include "bwta.i"
%{
#include "helper.h"
#include "heatmap.h"
using namespace BWTA;
%}
%include "helper.h"
%include "heatmap.h"
%{
// Define our own init function, with a simple declaration.
// Declare SWIG_init because it's not declared yet.
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT
#if PY_VERSION_HEX >= 0x03000000
PyObject*
#else
void
#endif
SWIG_init(void);
void python_wrap_init()
{
SWIG_init();
}
// Used for event-dispatcher callbacks
PyObject* _getSwigUnit(BWAPI::Unit* unit)
{
return SWIG_NewPointerObj(SWIG_as_voidptr(unit), SWIGTYPE_p_BWAPI__Unit, 0 );
}
PyObject* _getSwigPlayer(BWAPI::Player* player)
{
return SWIG_NewPointerObj(SWIG_as_voidptr(player), SWIGTYPE_p_BWAPI__Player, 0 );
}
PyObject* _getSwigPosition(BWAPI::Position* position)
{
return SWIG_NewPointerObj(SWIG_as_voidptr(position), SWIGTYPE_p_BWAPI__Position, 0 );
}
%}
""")
f.write( "\n//renames\n" )
for m in bwapi_modules:
f.write("%%ignore BWAPI::%(name)ss::init;\n" % dict(name=m) )
for cn in bwapi_collision_names:
f.write("%%rename(%(name)ss_%(collname)s) BWAPI::%(name)ss::%(collname)s;\n" % dict(name=m, collname=cn))
event_types = ['MatchStart', 'MatchEnd', 'MatchFrame', 'MenuFrame', 'SendText',
'ReceiveText', 'PlayerLeft', 'NukeDetect', 'UnitDiscover', 'UnitEvade', 'UnitShow', 'UnitHide', 'UnitCreate', 'UnitDestroy', 'UnitMorph', 'UnitRenegade', 'SaveGame', 'None']
for et in event_types:
f.write("%%rename(EventTypes_%s) BWAPI::EventType::%s;\n" % (et,et))
f.write( "\n// includes\n%{\n" )
for m in bwapi_modules:
f.write("""\t#include "BWAPI/%s.h"\n"""% ( m ) )
for m in bwta_modules:
f.write("""\t#include "BWTA/%s.h"\n"""% ( m ) )
f.write( "%}\n" )
for m in bwapi_modules:
f.write("""\t%%include "BWAPI/%s.h"\n"""% ( m ) )
for m in bwta_modules:
f.write("""\t%%include "BWTA/%s.h"\n"""% ( m ) )
f.close()