Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
dp88_customAI.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#pragma once
13
14#include "LoopedAnimationController.h"
15#include "ObserverImpClass.h"
16#include "ReferencerClass.h"
17
18class ActionParamsStruct;
19
20class Pathfind_Help_Implementer
21{
22public:
23 virtual ~Pathfind_Help_Implementer() {};
24 virtual bool Should_Ignore_Blocked_Checking(GameObject *obj) = 0;
25 virtual void Prepare_Getting_Around(GameObject *obj) = 0;
26 virtual void Stop_Getting_Around(GameObject *obj) = 0;
27 virtual void On_Unable_To_Get_Unstuck(GameObject *obj) = 0;
28 // Modify action params during getting unstuck to include target shooting, if any exist
29 virtual ActionParamsStruct Get_Param_Attack_Modifications(ActionParamsStruct params) = 0;
30};
31
32// Forward declaration
33class VehicleGameObj;
36
37/*------------------------
38Base class for custom AI's
39--------------------------*/
40
41
58class dp88_customAI : public ScriptImpClass
59{
60public:
61
62 /* -----
63 Constructor / Destructor (cleanup debug file if applicable
64 ----- */
65
66 dp88_customAI() { debugFile = NULL; };
67 ~dp88_customAI() { if ( debugFile != NULL ) { fclose(debugFile); } };
68
69
70
71
72 /* -----
73 Variables
74 ----- */
75
76 // Priority and weapon choice for each target type
77 float priority_infantry; bool primary_infantry;
78 float priority_lightVehicle; bool primary_lightVehicle;
79 float priority_heavyVehicle; bool primary_heavyVehicle;
80 float priority_VTOL; bool primary_VTOL;
81 float priority_building; bool primary_building;
82
83 // Priority modifiers
84 float modifier_distance, modifier_target_damage, modifier_target_value;
85
86 // Attack ranges
87 int primary_minRange, primary_maxRange;
88 int secondary_minRange, secondary_maxRange;
89
90 // Current target state
91 //int targetID;
92 ReferencerClass m_target;
93 bool hasTarget;
94 int targetLastSeen;
95 float targetPriority;
96 bool m_bTargetPrimaryFire;
97
98 // Brain speed
99 float thinkTime;
100
101 // Other settings
102 bool m_bAiEnabled;
103 bool m_bCanDetectStealth;
104
105 // Debug state
106 bool debug;
107 FILE* debugFile;
108
109 // Target types
110 enum TargetType {
111 SOLDIER = 0,
112 LIGHT_VEHICLE,
113 HEAVY_VEHICLE,
114 FLYING,
115 BUILDING,
116 REPAIRABLE,
117 UNKNOWN
118 };
119
120
121
122 /* -----
123 Events
124 ----- */
125
126 virtual void Created( GameObject *obj );
127 virtual void Timer_Expired(GameObject *obj, int number);
128 virtual void Custom ( GameObject* pObj, int message, int param, GameObject* pSender );
129 virtual void Action_Complete( GameObject *obj, int action_id, ActionCompleteReason complete_reason );
130 //virtual void Enemy_Seen ( GameObject *obj, GameObject *enemy );
131 //virtual void Timer_Expired( GameObject *obj, int number );
132
133
134
135
136 /* ----
137 Functions
138 ----- */
139
140 virtual void Init( GameObject *obj );
141 virtual void loadSettings( GameObject *obj, bool loadSecondaryFireSettings, bool loadBuildingTargetSettings );
142
143 virtual void AIStateChanged( GameObject* pObj, bool bEnabled );
144
149 virtual void ResetAllActions(GameObject* obj);
150
151 static float getDistance ( GameObject *obj1, GameObject *obj2 );
152 virtual float getBasePriority(GameObject *target );
153 virtual float getPriority( GameObject *obj, GameObject *target );
154 virtual float getPriority( GameObject *obj, int target_id );
155 bool getPrimary ( GameObject *target );
156
157 /* Utility functions for both priority calculations and AI scripts to utilise */
158 virtual bool IsVehicleEmpty( VehicleGameObj* vobj );
159 virtual bool IsVehicleAIEnabled( VehicleGameObj* vobj );
160
161 // "Global" decider about what a unit type is
162 static TargetType GetTargetType(GameObject* obj);
163};
164
165// -------------------------------------------------------------------------------------------------
166
175class dp88_AI_heavyVehicleMarker : public ScriptImpClass
176{
177 void Created(GameObject* obj);
178};
179
180// -------------------------------------------------------------------------------------------------
181
189class dp88_AI_Marker_Building : public ScriptImpClass {};
190
191// -------------------------------------------------------------------------------------------------
192
201class dp88_AI_Marker_HeavyVehicle : public ScriptImpClass {};
202
203// -------------------------------------------------------------------------------------------------
204
212class dp88_AI_Marker_Repairable : public ScriptImpClass
213{
214public:
215 void Created(GameObject* obj);
216 float Get_Distance_From_Pathfind();
217protected:
218 float pathfindDistance;
219};
220
221// -------------------------------------------------------------------------------------------------
222
231{
232public:
233 // Game Events
234 void Created(GameObject *obj);
235 void Detach(GameObject *obj);
236 void Timer_Expired(GameObject *obj, int number);
237 void Action_Complete(GameObject *obj, int action_id, ActionCompleteReason reason);
238
239 // Custom AI initialisation script overloads
240 virtual void Init(GameObject *obj);
241 virtual void loadSettings(GameObject *obj, bool loadSecondaryFireSettings, bool loadBuildingTargetSettings);
242
243 virtual void Force_Clear_Current_Objective();
244 dp88_AI_Objective* Get_Current_Objective() { return m_pCurrentObjective; }
245
246 // used in combination with Force_Clear_Current_Objective() to invalidate references to objectives when they are deleted (prevents use-after-free bugs)
247 static DynamicVectorClass<dp88_AI_Unit*> ListOfAIUnits;
248
249protected:
250 static const int ACTION_ID_MOVE_TO_OBJECTIVE = 7850001;
251 static const int ACTION_ID_ATTACK_TARGET = 7850002;
252
253 // Action reset handler
254 void ResetAllActions(GameObject* obj);
255
256 // Go to the location of the current objective
257 virtual void GoToObjective(GameObject *obj, float speed = 1.0f);
258
259 // Attack the specified target
260 virtual void AttackTarget(GameObject *obj, GameObject *target);
261
270 virtual bool ShouldPursueTarget(GameObject *obj, GameObject *target);
271
275 virtual int GetPreferredAttackRange(GameObject* obj, GameObject *target) = 0;
276
280 virtual bool IsValidTarget(GameObject* obj, GameObject *target) = 0;
281
285 virtual dp88_AI_Objective* ChooseNewObjective(GameObject* obj) = 0;
286
287 // -----------------------------------------------------------------------------------------------
288 // Member variables
289
292
295
296 // Current objective
297 dp88_AI_Objective* m_pCurrentObjective;
298};
299
300// -------------------------------------------------------------------------------------------------
301
310{
311public:
312 // Game Events
313 void Created(GameObject *obj);
314 void Enemy_Seen(GameObject *obj, GameObject *enemy);
315
316 // Custom AI initialisation script overloads
317 virtual void Init(GameObject *obj);
318 virtual void loadSettings(GameObject *obj, bool loadSecondaryFireSettings, bool loadBuildingTargetSettings);
319
320protected:
321
325 virtual int GetPreferredAttackRange(GameObject* obj, GameObject *target);
326
330 virtual bool IsValidTarget(GameObject* obj, GameObject *target);
331
335 virtual dp88_AI_Objective* ChooseNewObjective(GameObject* obj);
336
339 int m_primary_prefRange, m_secondary_prefRange;
340 int retreatDamageAmount;
342};
343
344// -------------------------------------------------------------------------------------------------
345
417{
418public:
419 // Events
420 virtual void Enemy_Seen ( GameObject *obj, GameObject *enemy );
421 virtual void Timer_Expired( GameObject *obj, int number );
422 virtual void Damaged(GameObject *obj, GameObject *damager, float amount);
423
424 // Custom AI initialisation script overrides
425 virtual void Init( GameObject *obj );
426 virtual void loadSettings( GameObject *obj, bool loadSecondaryFireSettings, bool loadBuildingTargetSettings );
427
428 // Custom AI event overrides
429 virtual void AIStateChanged( GameObject* pObj, bool bEnabled );
430
431protected:
432 bool requiresPower, splashInfantry;
433
434 // These can be overloaded from their default functionality as required, allowing the default
435 // enemy seen procedure to be reused even when the behaviour of these checks has been altered
436 virtual bool checkTeam ( GameObject* obj, GameObject* target );
437 virtual bool checkRange ( GameObject* obj, GameObject* target, bool primary );
438 virtual bool checkPowerState( GameObject* obj );
439
440
441
442
443 /* These functions are used to initiate and control the AI actions and can be overloaded from
444 their defaults if required to provide custom functionality, such as delaying an attack whilst
445 waiting for a chargeup / popup animation to occur. */
446
447 // These is called when a valid target has been identified and selected as the highest priority
448 // target, the turret should begin attacking in this function. Note that this may be called
449 // while another attack is already in progress, either normal or splash.
450 virtual void attackTarget ( GameObject* obj, GameObject* target, bool primary );
451
452 // This is called instead of attackTarget when we are set to splash infantry instead of shooting
453 // at them directly. Whilst we are attacking an infantry unit with splash this will be called
454 // regularly on a timer to update the location of the target. Note that this may be called
455 // while another attack is already in progress, either normal or splash.
456 virtual void attackLocation ( GameObject* obj, Vector3 location, bool primary );
457
458 // This is called when the target is no longer valid and the turret should stop attacking, this
459 // is called to stop both attackTarget and splashLocation attacks.
460 virtual void stopAttacking ( GameObject* obj );
461};
462
463// -------------------------------------------------------------------------------------------------
464
548{
549public:
550 // Game events
551 virtual void Created ( GameObject* pSelf );
552 virtual void Timer_Expired ( GameObject* pSelf, int number );
553 virtual void Custom ( GameObject* pSelf, int type, int param, GameObject* pSender );
554 virtual void Animation_Complete ( GameObject* pSelf, const char* animation_name );
555 virtual void Destroyed( GameObject* pSelf );
556
557
558protected:
559 static const unsigned char STATE_UNDEPLOYED = 0x00;
560 static const unsigned char STATE_DEPLOYING = 0x01;
561 static const unsigned char STATE_DEPLOYED = 0x02;
562 static const unsigned char STATE_UNDEPLOYING = 0x03;
563
565 unsigned char m_deploymentState;
566
569
572
573
575 virtual void attackTarget ( GameObject* pSelf, GameObject* pTarget, bool primary );
576
578 virtual void attackLocation ( GameObject* pSelf, Vector3 location, bool primary );
579
580
583 virtual void Deploy ( GameObject* pSelf );
584
587 virtual void Undeploy ( GameObject* pSelf );
588};
589
590// -------------------------------------------------------------------------------------------------
591
600class dp88_AI_PopupTurret_Spotter : public ScriptImpClass
601{
602 void Enemy_Seen ( GameObject* pSelf, GameObject* pEnemy );
603};
604
605// -------------------------------------------------------------------------------------------------
606
715{
716public:
717 // Game events
718 virtual void Timer_Expired ( GameObject* pSelf, int number );
719 virtual void Animation_Complete ( GameObject* pSelf, const char* animation_name );
720 virtual void Destroyed( GameObject* pSelf );
721
722 // Custom AI initialisation script overloads
723 virtual void Init( GameObject* pSelf );
724 virtual void loadSettings( GameObject* pSelf, bool loadSecondaryFireSettings, bool loadBuildingTargetSettings );
725
726
727protected:
728 unsigned int m_myObjId;
729
732
735
740
743
746
749
752
753
756 virtual void attackTarget ( GameObject* pSelf, GameObject* pTarget, bool primary );
757
760 virtual void attackLocation ( GameObject* pSelf, Vector3 location, bool primary );
761
762
764 virtual void StartCharging ( GameObject* pSelf );
765
767 virtual void StartDischarging ( GameObject* pSelf );
768
769
773 virtual GameObject* GetAnimationObject ( GameObject* pSelf );
774
776 virtual void ApplyIdleAnimation ( GameObject* pSelf );
777};
778
786{
787public:
789
790 // Game events
791 virtual void Animation_Complete(GameObject* pSelf, const char* animation_name);
792
793private:
794 dp88_AI_ChargedTurret* m_pParent;
795};
796
797// -------------------------------------------------------------------------------------------------
798
826class dp88_AI_Objective : public ScriptImpClass
827{
828public:
829 void Created ( GameObject* obj );
830 void Detach ( GameObject* obj );
831
832 GameObject* GetGameObject();
833
834 unsigned int GetType() { return m_type; }
835 int GetTeam() { return m_team; }
836 int GetRange() { return m_range; }
837 const char* GetDebugTag() { return m_debugTag; }
838
840 float GetPriority(GameObject* obj, float distance_modifier);
841
846 static dp88_AI_Objective* GetBestObjective ( GameObject* obj, unsigned int objective_type, float distance_modifier, DynamicVectorClass<int> ignoredObjectives );
847
851 static int CountObjectives( int team, unsigned int objective_type );
852
856 static int CountUnitObjectives( int team, unsigned int objective_type, GameObject* obj, float distance_modifier );
857
859 static bool IsValidObjective ( dp88_AI_Objective* pObjective );
860
863 const static unsigned int TYPE_OFFENSIVE = 1;
864 const static unsigned int TYPE_DEFENSIVE = 2;
865 const static unsigned int TYPE_ENGINEERING = 3;
868protected:
871 const static unsigned char UNITTYPE_SOLDIER = 0;
872 const static unsigned char UNITTYPE_LVEHICLE = 1;
873 const static unsigned char UNITTYPE_HVEHICLE = 2;
874 const static unsigned char UNITTYPE_AIRCRAFT = 3;
875 const static unsigned char UNITTYPE_MAX = UNITTYPE_AIRCRAFT;
876 const static unsigned char UNITTYPE_UNKNOWN = UCHAR_MAX;
880 unsigned char GetUnitType(GameObject* obj);
881
882 //int m_objID;;
883
886 unsigned int m_type;
887 int m_priority[UNITTYPE_MAX + 1];
888 int m_range;
889 int m_team;
890 const char* m_debugTag;
893 static DynamicVectorClass<dp88_AI_Objective *> Objectives;
894};
Controller for looped animations using a subset of frames.
Definition LoopedAnimationController.h:31
GameObject Observer Base Class.
Definition ObserverImpClass.h:24
Chargeup Animation Observer.
Definition dp88_customAI.h:786
Charged Turret AI.
Definition dp88_customAI.h:715
virtual void attackTarget(GameObject *pSelf, GameObject *pTarget, bool primary)
Definition dp88_customAI.cpp:1367
LoopedAnimationController * m_pLoopedAnimCtrl
Definition dp88_customAI.h:748
unsigned int m_myObjId
My own GameObject ID, used by the observer callbacks.
Definition dp88_customAI.h:728
virtual void attackLocation(GameObject *pSelf, Vector3 location, bool primary)
Definition dp88_customAI.cpp:1379
virtual GameObject * GetAnimationObject(GameObject *pSelf)
Definition dp88_customAI.cpp:1452
bool m_bIsPreReloading
Definition dp88_customAI.h:739
bool m_bPowerState
Definition dp88_customAI.h:745
virtual void StartDischarging(GameObject *pSelf)
Definition dp88_customAI.cpp:1419
int m_chargeAnimObjId
Definition dp88_customAI.h:742
virtual void ApplyIdleAnimation(GameObject *pSelf)
Definition dp88_customAI.cpp:1461
bool m_bIsCharging
Definition dp88_customAI.h:731
dp88_AI_ChargedTurret_AnimationObserver * m_pAnimationObserver
Definition dp88_customAI.h:751
bool m_bIsDischarging
Definition dp88_customAI.h:734
virtual void StartCharging(GameObject *pSelf)
Definition dp88_customAI.cpp:1391
danpaul88's Custom AI Building Marker
Definition dp88_customAI.h:189
danpaul88's Custom AI Heavy Vehicle Marker
Definition dp88_customAI.h:201
danpaul88's Custom AI Repair Target Marker
Definition dp88_customAI.h:213
AI Objective.
Definition dp88_customAI.h:827
static dp88_AI_Objective * GetBestObjective(GameObject *obj, unsigned int objective_type, float distance_modifier, DynamicVectorClass< int > ignoredObjectives)
Definition dp88_customAI.cpp:1631
float GetPriority(GameObject *obj, float distance_modifier)
Definition dp88_customAI.cpp:1613
static int CountObjectives(int team, unsigned int objective_type)
Definition dp88_customAI.cpp:1659
static bool IsValidObjective(dp88_AI_Objective *pObjective)
Definition dp88_customAI.cpp:1693
static int CountUnitObjectives(int team, unsigned int objective_type, GameObject *obj, float distance_modifier)
Definition dp88_customAI.cpp:1676
unsigned char GetUnitType(GameObject *obj)
Definition dp88_customAI.cpp:1593
Popup Turret Spotter.
Definition dp88_customAI.h:601
Popup Turret AI.
Definition dp88_customAI.h:548
unsigned char m_deploymentState
Definition dp88_customAI.h:565
virtual void Undeploy(GameObject *pSelf)
Definition dp88_customAI.cpp:1163
time_t m_undeployTime
Definition dp88_customAI.h:568
int m_spotterId
Definition dp88_customAI.h:571
virtual void attackTarget(GameObject *pSelf, GameObject *pTarget, bool primary)
Definition dp88_customAI.cpp:1128
virtual void Deploy(GameObject *pSelf)
Definition dp88_customAI.cpp:1148
virtual void attackLocation(GameObject *pSelf, Vector3 location, bool primary)
Definition dp88_customAI.cpp:1138
Offensive Tank AI.
Definition dp88_customAI.h:310
virtual int GetPreferredAttackRange(GameObject *obj, GameObject *target)
Definition dp88_customAI.cpp:692
virtual dp88_AI_Objective * ChooseNewObjective(GameObject *obj)
Definition dp88_customAI.cpp:715
virtual bool IsValidTarget(GameObject *obj, GameObject *target)
Definition dp88_customAI.cpp:699
Turret AI.
Definition dp88_customAI.h:417
Unit AI Base Class.
Definition dp88_customAI.h:231
virtual dp88_AI_Objective * ChooseNewObjective(GameObject *obj)=0
bool m_bMovingToObjective
Definition dp88_customAI.h:291
void ResetAllActions(GameObject *obj)
Definition dp88_customAI.cpp:508
virtual int GetPreferredAttackRange(GameObject *obj, GameObject *target)=0
virtual bool IsValidTarget(GameObject *obj, GameObject *target)=0
virtual bool ShouldPursueTarget(GameObject *obj, GameObject *target)
Definition dp88_customAI.cpp:610
bool m_bMovingToTarget
Definition dp88_customAI.h:294
danpaul88's Custom AI Heavy Vehicle Marker
Definition dp88_customAI.h:176
danpaul88's Custom AI Core
Definition dp88_customAI.h:59
virtual void ResetAllActions(GameObject *obj)
Definition dp88_customAI.cpp:85