1 /*
2 	This file is part of Warzone 2100.
3 	Copyright (C) 1999-2004  Eidos Interactive
4 	Copyright (C) 2005-2020  Warzone 2100 Project
5 
6 	Warzone 2100 is free software; you can redistribute it and/or modify
7 	it under the terms of the GNU General Public License as published by
8 	the Free Software Foundation; either version 2 of the License, or
9 	(at your option) any later version.
10 
11 	Warzone 2100 is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with Warzone 2100; if not, write to the Free Software
18 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 /** @file
21  *  Definitions for the AI system structures
22  */
23 
24 #ifndef __INCLUDED_SRC_AI_H__
25 #define __INCLUDED_SRC_AI_H__
26 
27 struct BASE_OBJECT;
28 struct DROID;
29 
30 #include "weapondef.h"
31 
32 #define ALLIANCE_BROKEN		0			// states of alliance between players
33 #define ALLIANCE_REQUESTED	1
34 #define ALLIANCE_INVITATION	2
35 #define ALLIANCE_FORMED		3
36 #define	ALLIANCE_NULL		4			// for setting values only.
37 
38 enum AllianceType
39 {
40 	NO_ALLIANCES,        // FFA
41 	ALLIANCES,           // Players can make and break alliances during the game.
42 	ALLIANCES_TEAMS,     // Alliances are set before the game.
43 	ALLIANCES_UNSHARED,  // Alliances are set before the game. No shared research.
44 };
45 
46 /// Amount of time to rage at the world when frustrated (10 seconds)
47 #define FRUSTRATED_TIME (1000 * 10)
48 
49 // alliances
50 extern uint8_t alliances[MAX_PLAYER_SLOTS][MAX_PLAYER_SLOTS];
51 extern PlayerMask alliancebits[MAX_PLAYER_SLOTS];
52 extern PlayerMask satuplinkbits;
53 
54 /** Check no alliance has formed. This is a define to make sure we inline it. */
55 #define aiCheckAlliances(_s1, _s2) (alliances[_s1][_s2] == ALLIANCE_FORMED)
56 
57 /* Initialise the AI system */
58 bool aiInitialise();
59 
60 /* Shutdown the AI system */
61 bool aiShutdown();
62 
63 /* Do the AI for a droid */
64 void aiUpdateDroid(DROID *psDroid);
65 
66 // Find the nearest best target for a droid
67 // returns integer representing quality of choice, -1 if failed
68 int aiBestNearestTarget(DROID *psDroid, BASE_OBJECT **ppsObj, int weapon_slot, int extraRange = 0);
69 
70 // Are there a lot of bullets heading towards the structure?
71 bool aiObjectIsProbablyDoomed(BASE_OBJECT *psObject, bool isDirect);
72 
73 // Update the expected damage of the object.
74 void aiObjectAddExpectedDamage(BASE_OBJECT *psObject, SDWORD damage, bool isDirect);
75 
76 /* See if there is a target in range added int weapon_slot*/
77 bool aiChooseTarget(BASE_OBJECT *psObj,
78                     BASE_OBJECT **ppsTarget, int weapon_slot, bool bUpdateTarget, TARGET_ORIGIN *targetOrigin);
79 
80 /** See if there is a target in range for Sensor objects. */
81 bool aiChooseSensorTarget(BASE_OBJECT *psObj, BASE_OBJECT **ppsTarget);
82 
83 /*set of rules which determine whether the weapon associated with the object
84 can fire on the propulsion type of the target*/
85 bool validTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget, int weapon_slot);
86 // Check if any of the weapons can target the target
87 bool checkAnyWeaponsTarget(BASE_OBJECT *psObject, BASE_OBJECT *psTarget);
88 // Check properties of the AllianceType enum.
alliancesFixed(int t)89 static inline bool alliancesFixed(int t)
90 {
91 	return t != ALLIANCES;
92 }
alliancesSharedVision(int t)93 static inline bool alliancesSharedVision(int t)
94 {
95 	return t == ALLIANCES_TEAMS || t == ALLIANCES_UNSHARED;
96 }
alliancesSharedResearch(int t)97 static inline bool alliancesSharedResearch(int t)
98 {
99 	return t == ALLIANCES || t == ALLIANCES_TEAMS;
100 }
alliancesSetTeamsBeforeGame(int t)101 static inline bool alliancesSetTeamsBeforeGame(int t)
102 {
103 	return t == ALLIANCES_TEAMS || t == ALLIANCES_UNSHARED;
104 }
alliancesCanGiveResearchAndRadar(int t)105 static inline bool alliancesCanGiveResearchAndRadar(int t)
106 {
107 	return t == ALLIANCES;
108 }
alliancesCanGiveAnything(int t)109 static inline bool alliancesCanGiveAnything(int t)
110 {
111 	return t != NO_ALLIANCES;
112 }
113 
114 #endif // __INCLUDED_SRC_AI_H__
115