-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPythonScripting.h
More file actions
76 lines (61 loc) · 1.74 KB
/
PythonScripting.h
File metadata and controls
76 lines (61 loc) · 1.74 KB
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
#pragma once
#if defined(_DEBUG)
// fix some _DEBUG mismatches
# include <cstdio>
# undef _DEBUG
# include "Python.h"
# define _DEBUG
#else
# include "Python.h"
#endif
#include <map>
#include <boost/python.hpp>
namespace bp = boost::python;
class BaczekKPAI;
class PythonScripting
{
protected:
boost::python::object init;
int teamId;
typedef std::map<int, BaczekKPAI*> ai_map_t;
static ai_map_t ai_map;
public:
PythonScripting(int teamId, std::string datadir);
~PythonScripting();
static void RegisterAI(int teamId, BaczekKPAI *);
static void UnregisterAI(int teamId);
static BaczekKPAI* GetAIForTeam(int teamId);
void GameFrame(int framenum);
void DumpStatus(int framenum, const std::vector<float3>& geos,
const std::vector<float3>& friendlies,
const std::vector<float3>& enemies);
int GetBuilderRetreatTimeout(int frameNum);
int GetWantedConstructors(int geospots, int mapwidth, int mapheight);
int GetBuildSpotPriority(float distance, int influence, int mapwidth, int mapheight, int def);
template<typename T> T extract_default(bp::object obj, T def)
{
try {
return bp::extract<T>(obj);
} catch (bp::error_already_set&) {
PyErr_Print();
return def;
}
}
template<typename T1, typename T2, typename Ret> Ret extract_default(bp::object obj, Ret def)
{
try {
return Ret(bp::extract<T1>(obj));
} catch (bp::error_already_set&) {
PyErr_Print();
}
try {
return Ret(bp::extract<T2>(obj));
} catch (bp::error_already_set&) {
PyErr_Print();
return def;
}
}
int GetIntValue(const char* name, int def);
float GetFloatValue(const char* name, float def);
std::string GetStringValue(const char* name, const std::string& def);
};