-
Notifications
You must be signed in to change notification settings - Fork 1
/
AIModule.h
76 lines (68 loc) · 2.19 KB
/
AIModule.h
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
#include "Types.h"
#ifdef __cplusplus
extern "C" {
#endif
/// Declare your own module:
///
/// typedef struct MyModule {
/// const AIModule_vtable* vtable_;
/// int my_field;
/// ...
/// };
///
/// Create vtable:
///
/// void onStart(AIModule*) { }
/// static AIModule_vtable my_vtable = { onStart, pointer to functions... };
///
/// Set vtable:
///
/// MyModule module;
/// module.vtable = &my_vtable;
///
/// Wrap your module into a BWAPI::AIModule:
/// /* BWAPI::AIModule* */ void* wrapper_ptr = createAIModuleWrapper(&module);
///
/// createAIModuleWrapper does not own your module
///
/// Now your wrapper_ptr can be passed inside the game on call to newAIModule from dll
/// NOTE Using MS extension you may derive from AIModule
/// In MSVC enabled by default;
/// In gcc: add flag -fms-extensions
///
/// Example:
/// typedef struct MyModule {
/// truct AIModule; // base
/// int my_field;
/// ...
/// } MyModule;
typedef struct AIModule_vtable AIModule_vtable;
typedef struct AIModule {
const AIModule_vtable* vtable;
} AIModule;
struct AIModule_vtable
{
void (*onStart)(AIModule* module);
void (*onEnd)(AIModule* module, bool isWinner);
void (*onFrame)(AIModule* module);
void (*onSendText)(AIModule* module, const char* text);
void (*onReceiveText)(AIModule* module, Player* player, const char* text);
void (*onPlayerLeft)(AIModule* module, Player* player);
void (*onNukeDetect)(AIModule* module, Position target);
void (*onUnitDiscover)(AIModule* module, Unit* unit);
void (*onUnitEvade)(AIModule* module, Unit* unit);
void (*onUnitShow)(AIModule* module, Unit* unit);
void (*onUnitHide)(AIModule* module, Unit* unit);
void (*onUnitCreate)(AIModule* module, Unit* unit);
void (*onUnitDestroy)(AIModule* module, Unit* unit);
void (*onUnitMorph)(AIModule* module, Unit* unit);
void (*onUnitRenegade)(AIModule* module, Unit* unit);
void (*onSaveGame)(AIModule* module, const char* gameName);
void (*onUnitComplete)(AIModule* module, Unit* unit);
};
/* BWAPI::AIModule* */ void* createAIModuleWrapper(AIModule* module);
void destroyAIModuleWrapper(/* BWAPI::AIModule* */ void* module);
#ifdef __cplusplus
} // extern "C"
#endif