File: IGlobalAI.h

package info (click to toggle)
spring 104.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,512 kB
  • sloc: cpp: 391,093; ansic: 79,943; python: 12,356; java: 12,201; awk: 5,889; sh: 1,826; xml: 655; makefile: 486; perl: 405; php: 211; objc: 194; sed: 2
file content (132 lines) | stat: -rw-r--r-- 3,881 bytes parent folder | download | duplicates (5)
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef I_GLOBAL_AI_H
#define I_GLOBAL_AI_H

#include <cstdlib>
#include <cstring>

#include "aibase.h"
#include "Sim/Units/CommandAI/Command.h"
#include "System/float3.h"

#define GLOBAL_AI_INTERFACE_VERSION (19 + AI_INTERFACE_GENERATED_VERSION)

#define AI_EVENT_UNITGIVEN       1 // ChangeTeamEvent
#define AI_EVENT_UNITCAPTURED    2 // ChangeTeamEvent
#define AI_EVENT_WEAPON_FIRED    3 // WeaponFireEvent
#define AI_EVENT_PLAYER_COMMAND  4 // PlayerCommandEvent
#define AI_EVENT_SEISMIC_PING    5 // SeismicPingEvent


namespace springLegacyAI {

class IGlobalAICallback;
struct WeaponDef;

class IGlobalAI
{
public:
	struct ChangeTeamEvent {
		int unit, newteam, oldteam;
	};
	struct WeaponFireEvent {
		int unit;
		const WeaponDef* def;
	};
	struct PlayerCommandEvent {
		std::vector<int> units;
		Command command;
		int player;
	};
	struct SeismicPingEvent {
		float3 pos;
		float strength;
	};

	/// Called only once, right after the constructor was called
	virtual void InitAI(IGlobalAICallback* callback, int team) = 0;
	/// Called only once, right before the destructor is called
	virtual void ReleaseAI() {}

	/// called when a new unit is created on ai team
	virtual void UnitCreated(int unit, int builder) = 0;
	/// called when an unit has finished building
	virtual void UnitFinished(int unit) = 0;
	/// called when a unit is destroyed
	virtual void UnitDestroyed(int unit, int attacker) = 0;

	/// called when a new enemy unit is created
	virtual void EnemyCreated(int enemy) {}
	/// called when a new enemy unit has finished building
	virtual void EnemyFinished(int enemy) {}

	virtual void EnemyEnterLOS(int enemy) = 0;
	virtual void EnemyLeaveLOS(int enemy) = 0;

	/**
	 * called when an enemy enter radar coverage
	 * (los always count as radar coverage to)
	 */
	virtual void EnemyEnterRadar(int enemy) = 0;
	/**
	 * called when an enemy leave radar coverage
	 * (los always count as radar coverage to)
	 */
	virtual void EnemyLeaveRadar(int enemy) = 0;

	/// called when an enemy inside los or radar is damaged
	virtual void EnemyDamaged(int damaged, int attacker, float damage, float3 dir) = 0;
	/**
	 * will be called if an enemy inside los or radar dies
	 * (note that leave los etc will not be called then)
	 */
	virtual void EnemyDestroyed(int enemy, int attacker) = 0;

	/// called when a unit go idle and is not assigned to any group
	virtual void UnitIdle(int unit) = 0;


	/**
	 * @deprecated
	 * @see #RecvChatMessage
	 */
	virtual void GotChatMsg(const char* message, int player) {}


	/// called when a player sends a chat message
	virtual void RecvChatMessage(const char* message, int player) { GotChatMsg(message, player); }

	/// called when a Lua widget or unsynced gadget sends a message to this AI
	/// do not use outData, it is always NULL for interface-technical reasons
	virtual void RecvLuaMessage(const char* inData, const char** outData) { /* *outData = inData; */ }


	/// called when one of your units are damaged
	virtual void UnitDamaged(int damaged, int attacker, float damage, float3 dir) = 0;
	/// called when a ground unit failed to reach it's destination
	virtual void UnitMoveFailed(int unit) = 0;

	/// general messaging function to be used for future API extensions.
	virtual int HandleEvent(int msg, const void *data) = 0;

	/// called every frame
	virtual void Update() = 0;

	/// load ai from file
	virtual void Load(IGlobalAICallback* callback, std::istream* s) {}
	/// save ai to file
	virtual void Save(std::ostream* s) {}

	// use virtual instead of pure virtual,
	// because pure virtual is not well supported
	// among different OSs and compilers,
	// and pure virtual has no advantage
	// if we have other pure virtual functions
	// in the class
	virtual ~IGlobalAI() {}
};

} // namespace springLegacyAI

#endif // I_GLOBAL_AI_H