forked from Warzone2100/warzone2100
/
ai.h
114 lines (93 loc) · 3.77 KB
/
ai.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
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
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2019 Warzone 2100 Project
Warzone 2100 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 of the License, or
(at your option) any later version.
Warzone 2100 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.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** @file
* Definitions for the AI system structures
*/
#ifndef __INCLUDED_SRC_AI_H__
#define __INCLUDED_SRC_AI_H__
struct BASE_OBJECT;
struct DROID;
#include "weapondef.h"
#define ALLIANCE_BROKEN 0 // states of alliance between players
#define ALLIANCE_REQUESTED 1
#define ALLIANCE_INVITATION 2
#define ALLIANCE_FORMED 3
#define ALLIANCE_NULL 4 // for setting values only.
enum AllianceType
{
NO_ALLIANCES, // FFA
ALLIANCES, // Players can make and break alliances during the game.
ALLIANCES_TEAMS, // Alliances are set before the game.
ALLIANCES_UNSHARED, // Alliances are set before the game. No shared research.
};
/// Amount of time to rage at the world when frustrated (10 seconds)
#define FRUSTRATED_TIME (1000 * 10)
// alliances
extern uint8_t alliances[MAX_PLAYER_SLOTS][MAX_PLAYER_SLOTS];
extern PlayerMask alliancebits[MAX_PLAYER_SLOTS];
extern PlayerMask satuplinkbits;
/** Check no alliance has formed. This is a define to make sure we inline it. */
#define aiCheckAlliances(_s1, _s2) (alliances[_s1][_s2] == ALLIANCE_FORMED)
/* Initialise the AI system */
bool aiInitialise();
/* Shutdown the AI system */
bool aiShutdown();
/* Do the AI for a droid */
void aiUpdateDroid(DROID *psDroid);
// Find the nearest best target for a droid
// returns integer representing quality of choice, -1 if failed
int aiBestNearestTarget(DROID *psDroid, BASE_OBJECT **ppsObj, int weapon_slot, int extraRange = 0);
// Are there a lot of bullets heading towards the structure?
bool aiObjectIsProbablyDoomed(BASE_OBJECT *psObject, bool isDirect);
// Update the expected damage of the object.
void aiObjectAddExpectedDamage(BASE_OBJECT *psObject, SDWORD damage, bool isDirect);
/* See if there is a target in range added int weapon_slot*/
bool aiChooseTarget(BASE_OBJECT *psObj,
BASE_OBJECT **ppsTarget, int weapon_slot, bool bUpdateTarget, TARGET_ORIGIN *targetOrigin);
/** See if there is a target in range for Sensor objects. */
bool aiChooseSensorTarget(BASE_OBJECT *psObj, BASE_OBJECT **ppsTarget);
/*set of rules which determine whether the weapon associated with the object
can fire on the propulsion type of the target*/
bool validTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget, int weapon_slot);
// Check if any of the weapons can target the target
bool checkAnyWeaponsTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget);
// Check properties of the AllianceType enum.
static inline bool alliancesFixed(int t)
{
return t != ALLIANCES;
}
static inline bool alliancesSharedVision(int t)
{
return t == ALLIANCES_TEAMS || t == ALLIANCES_UNSHARED;
}
static inline bool alliancesSharedResearch(int t)
{
return t == ALLIANCES || t == ALLIANCES_TEAMS;
}
static inline bool alliancesSetTeamsBeforeGame(int t)
{
return t == ALLIANCES_TEAMS || t == ALLIANCES_UNSHARED;
}
static inline bool alliancesCanGiveResearchAndRadar(int t)
{
return t == ALLIANCES;
}
static inline bool alliancesCanGiveAnything(int t)
{
return t != NO_ALLIANCES;
}
#endif // __INCLUDED_SRC_AI_H__