Updated Jasperre's AI

Updated Jasperre's AI to 1.4, fixed a few other coding bugs & fully compiled module.
This commit is contained in:
Jaysyn904
2021-08-30 17:31:44 -04:00
parent 2e0b5b615b
commit 1c1c90e986
404 changed files with 11239 additions and 7881 deletions

View File

@@ -1,6 +1,6 @@
/************************ [On Percieve] ****************************************
Filename: j_ai_onpercieve or nw_c2_default2
************************* [On Percieve] ****************************************
/*/////////////////////// [On Percieve] ////////////////////////////////////////
Filename: J_AI_OnPercieve or nw_c2_default2
///////////////////////// [On Percieve] ////////////////////////////////////////
If the target is an enemy, attack
Will determine combat round on that person, is an enemy, basically.
Includes shouting for a big radius - if the spawn in condition is set to this.
@@ -8,37 +8,43 @@
NOTE: Debug strings in this file will be uncommented for speed by default.
- It is one of the most intensive scripts as it runs so often.
- Attempted to optimise as much as possible.
************************* [History] ********************************************
///////////////////////// [History] ////////////////////////////////////////////
1.3 - We include j_inc_other_ai to initiate combat (or go into combat again)
- j_inc_other_ai holds all other needed functions/integers ETC.
- Turn off hide things.
- Added "Only attack if attacked"
- Removed special conversation things. Almost no one uses them, and the taunt system is easier.
- Should now search around if they move to a dead body, and only once they get there.
************************* [Workings] *******************************************
1.4 - TO DO:
1. Perception needs checking - attacking outside perception ranges!
2. Vanishing targets, etc. test, improve.
3. Problems with dispelling invisibility. Maybe either do change the line to create placable, or, of course, cast at location (dispells cannot be metamagiked or whatever) Source
4. No Effect Type Ethereal. Source
///////////////////////// [Workings] ///////////////////////////////////////////
It fires:
- When a creature enters it perception range (Set in creature properties) and
is seen or heard.
* Tests show (and in general) it fires HEARD first, then immediantly SEEN if,
of course, they are visible. Odd really, but true.
- When a creature uses invisiblity/leaves the area in the creatures perception
range
- When a creature appears suddenly, already in the perception range (not
the other way round, normally)
- When a creature moves out of the creatures perception range, and therefore
becomes unseen.
************************* [Arguments] ******************************************
///////////////////////// [Arguments] //////////////////////////////////////////
Arguments: GetLastPerceived, GetLastPerceptionSeen, GetLastPerceptionHeard,
GetLastPerceptionVanished, GetLastPerceptionInaudible.
************************* [On Percieve] ***************************************/
///////////////////////// [On Percieve] //////////////////////////////////////*/
#include "j_inc_other_ai"
#include "J_INC_OTHER_AI"
void main()
{
// Percieve pre event.
if(FireUserEvent(AI_FLAG_UDE_PERCIEVE_PRE_EVENT, EVENT_PERCIEVE_PRE_EVENT))
// We may exit if it fires
if(ExitFromUDE(EVENT_PERCIEVE_PRE_EVENT)) return;
// Pre-percieve-event. Returns TRUE if we interrupt this script call.
if(FirePreUserEvent(AI_FLAG_UDE_PERCIEVE_PRE_EVENT, EVENT_PERCIEVE_PRE_EVENT)) return;
// AI status check. Is the AI on?
if(GetAIOff()) return;
@@ -47,8 +53,21 @@ void main()
// - We declare OUTSIDE if's JUST IN CASE!
object oPerceived = GetLastPerceived();
object oAttackTarget = GetAttackTarget();
// 1.4: Very rarely is our attack target valid, so we will set it to
// what we would have melee attacked when DCR was called.
if(GetIgnoreNoFriend(oAttackTarget) || oAttackTarget == OBJECT_SELF)
{
oAttackTarget = GetAIObject(AI_LAST_MELEE_TARGET);
}
int bSeen = GetLastPerceptionSeen();
int bHeard = GetLastPerceptionHeard();
int bVanished = GetLastPerceptionVanished();
int bInaudiable = GetLastPerceptionInaudible();
// Debug
DebugActionSpeak("*** PER ***: " + GetName(oPerceived) + "| SEEN: " + IntToString(bSeen) +
"| HEARD: " + IntToString(bHeard) + "| VANISHED: " + IntToString(bVanished) +
"| INAUDIABLE: " + IntToString(bInaudiable));
// Need to be valid and not ignorable.
if(GetIsObjectValid(oPerceived) &&
@@ -58,31 +77,35 @@ void main()
// First, easy enemy checks.
if(GetIsEnemy(oPerceived) && !GetFactionEqual(oPerceived))
{
DebugActionSpeak("*** PER *** ENEMY");
// Turn of hiding, a timer to activate Hiding in the main file. This is
// done in each of the events, with the opposition checking seen/heard.
TurnOffHiding(oPerceived);
// Well, are we both inaudible and vanished?
// * the GetLastPerception should only say what specific event has fired!
if(GetLastPerceptionInaudible() || GetLastPerceptionVanished())
if(bVanished || bInaudiable)
{
DebugActionSpeak("*** PER *** VANISHED OR INAUDIBLE");
// If they just became invisible because of the spell
// invisiblity, or improved invisiblity...we set a local object.
// - Beta: Added in ethereal as well.
if(GetHasEffect(EFFECT_TYPE_INVISIBILITY, oPerceived) ||
GetHasEffect(EFFECT_TYPE_ETHEREAL, oPerceived) ||
GetHasEffect(EFFECT_TYPE_SANCTUARY, oPerceived) ||
GetStealthMode(oPerceived) == STEALTH_MODE_ACTIVATED)
{
// Set object, AND the location they went invisible!
SetAIObject(AI_LAST_TO_GO_INVISIBLE, oPerceived);
// We also set thier location for AOE dispelling - same name
SetLocalLocation(OBJECT_SELF, AI_LAST_TO_GO_INVISIBLE, GetLocation(oPerceived));
SetAILocation(AI_LAST_TO_GO_INVISIBLE, GetLocation(oPerceived));
}
// If they were our target, follow! >:-D
// - Optional, on spawn option, for following through areas.
if(oAttackTarget == oPerceived)
{
DebugActionSpeak("*** PER *** VANISHED OR INAUDIBLE AND IS CURRENT TARGET");
// This means they have exited the area! follow!
if(GetArea(oPerceived) != GetArea(OBJECT_SELF))
{
@@ -94,7 +117,10 @@ void main()
}
// - Added check for not casting a spell. If we are, we finnish
// (EG: AOE spell) and automatically carry on.
else if(GetCurrentAction() != ACTION_CASTSPELL)
// 1.4: If we are using a targetted spell, we do cancle our
// spellcasting if it is them.
else if(GetCurrentAction() != ACTION_CASTSPELL ||
GetAttackTarget() == oPerceived)
{
ClearAllActions();
// 52: "[Perception] Enemy Vanished (Same area) Retargeting/Searching [Percieved] " + GetName(oPerceived)
@@ -111,76 +137,79 @@ void main()
if(bSeen && GetCurrentAction() != ACTION_CASTSPELL &&
(oAttackTarget == oPerceived || !GetObjectSeen(oAttackTarget)))
{
AISpeakString(I_WAS_ATTACKED);
// 53: "[Perception] Enemy seen, and was old enemy/cannot see current. Re-evaluating (no spell) [Percieved] " + GetName(oPerceived)
DebugActionSpeakByInt(53, oPerceived);
DetermineCombatRound(oPerceived);
// Shout to allies to attack oPerceived
AISpeakString(AI_SHOUT_I_WAS_ATTACKED);
}
// Else We check if we are already attacking.
else if(!CannotPerformCombatRound() &&
!GetSpawnInCondition(AI_FLAG_OTHER_ONLY_ATTACK_IF_ATTACKED, AI_OTHER_MASTER))
{
// Special shout, d1000 though!
SpeakArrayString(AI_TALK_ON_PERCIEVE_ENEMY, TRUE);
// * Don't speak when dead. 1.4 change (an obvious one to make)
if(CanSpeak())
{
// Special shout, d1000 though!
SpeakArrayString(AI_TALK_ON_PERCIEVE_ENEMY, TRUE);
}
// Stop stuff because of facing point - New enemy
HideOrClear();
// Face the person (this helps stops sneak attacks if we then
// cast something on ourselves, ETC).
SetFacingPoint(GetPosition(oPerceived));
// Get all allies in 60M to come to thier aid. Talkvolume silent
// shout does not seem to work well.
// - void function. Checks for the spawn int. in it.
// - Turns it off in it too
// - Turns it off in it too (5 minutes - 1.4)
// - Variable range On Spawn
ShoutBossShout(oPerceived);
// Warn others
AISpeakString(I_WAS_ATTACKED);
// 54: "[Perception] Enemy Seen. Not in combat, attacking. [Percieved] " + GetName(oPerceived)
DebugActionSpeakByInt(54, oPerceived);
// Note: added ActionDoCommand, so that SetFacingPoint is not
// interrupted.
ActionDoCommand(DetermineCombatRound(oPerceived));
// 1.4 change: SetFacingPoint(GetPosition(oPerceived));
// Is now part of DetermineCombatRound().
// * This means other events will work similarily.
DetermineCombatRound(oPerceived);
// Warn others
AISpeakString(AI_SHOUT_I_WAS_ATTACKED);
}
}
}
// Else, they are an equal faction, or not an enemy (or both)
else
{
// If they are dead, say we saw something on waypoints, we charge in
// to investigate.
// If they are dead, or fighting, eg: we saw something on
// waypoints, we charge in to investigate.
// * Higher intelligence will buff somewhat as well!
if(GetIsDead(oPerceived) && (bSeen || bHeard))
if((GetIsDead(oPerceived) || GetIsInCombat(oPerceived)) &&
(bSeen || bHeard))
{
// Warn others
AISpeakString(I_WAS_ATTACKED);
if(GetIsDead(oPerceived))
{
// 55: "[Perception] Percieved Dead Friend! Moving into investigate [Percieved] " + GetName(oPerceived)
DebugActionSpeakByInt(55, oPerceived);
}
else
{
// 56: "[Perception] Percieved Alive Fighting Friend! Moving to and attacking. [Percieved] " + GetName(oPerceived)
DebugActionSpeakByInt(56, oPerceived);
}
// Check if we can attack
if(!CannotPerformCombatRound())
{
// Hide or clear actions
HideOrClear();
// 55: "[Perception] Percieved Dead Friend! Moving and Searching [Percieved] " + GetName(oPerceived)
DebugActionSpeakByInt(55, oPerceived);
ActionMoveToLocation(GetLocation(oPerceived), TRUE);
ActionDoCommand(DetermineCombatRound());
// If we were called to arms, react
CallToArmsResponse(oPerceived);
}
}
else if(GetIsInCombat(oPerceived) && (bSeen || bHeard))
{
// Warn others
AISpeakString(I_WAS_ATTACKED);
// Only if we can attack.
if(!CannotPerformCombatRound())
else
{
// Hide or clear actions
HideOrClear();
// 56: "[Perception] Percieved Alive Fighting Friend! Moving to and attacking. [Percieved] " + GetName(oPerceived)
DebugActionSpeakByInt(56, oPerceived);
ActionMoveToLocation(GetLocation(oPerceived), TRUE);
ActionDoCommand(DetermineCombatRound());
// Warn others even if we don't, or cannot, attack
AISpeakString(AI_SHOUT_CALL_TO_ARMS);
}
}
}