<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://oldwiki.eq2classic.com/index.php?action=history&amp;feed=atom&amp;title=AI%3ABrainTutorialC</id>
	<title>AI:BrainTutorialC - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://oldwiki.eq2classic.com/index.php?action=history&amp;feed=atom&amp;title=AI%3ABrainTutorialC"/>
	<link rel="alternate" type="text/html" href="https://oldwiki.eq2classic.com/index.php?title=AI:BrainTutorialC&amp;action=history"/>
	<updated>2026-07-11T19:30:23Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.3</generator>
	<entry>
		<id>https://oldwiki.eq2classic.com/index.php?title=AI:BrainTutorialC&amp;diff=4762&amp;oldid=prev</id>
		<title>Jabantiz at 04:09, 30 March 2013</title>
		<link rel="alternate" type="text/html" href="https://oldwiki.eq2classic.com/index.php?title=AI:BrainTutorialC&amp;diff=4762&amp;oldid=prev"/>
		<updated>2013-03-30T04:09:21Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 04:09, 30 March 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l81&quot; &gt;Line 81:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 81:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;		MoveCloser(target);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;		MoveCloser(target);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/pre&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=Using The New Brain=&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Now that we have our brain we can assign it to a NPC.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;pre&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;CombatPetBrain* brain = new CombatPetBrain(npc);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;npc-&amp;gt;SetBrain(brain);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Jabantiz</name></author>
		
	</entry>
	<entry>
		<id>https://oldwiki.eq2classic.com/index.php?title=AI:BrainTutorialC&amp;diff=4761&amp;oldid=prev</id>
		<title>Jabantiz at 03:45, 30 March 2013</title>
		<link rel="alternate" type="text/html" href="https://oldwiki.eq2classic.com/index.php?title=AI:BrainTutorialC&amp;diff=4761&amp;oldid=prev"/>
		<updated>2013-03-30T03:45:52Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 03:45, 30 March 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Creating a new brain in C++ gives you the option of extending the behavior of the default brain or completely override it.&amp;#160; I will use the combat pet brain as an example &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;which extends the functionality of &lt;/del&gt;the default brain.&amp;#160; This will require you to recompile your server.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Creating a new brain in C++ gives you the option of extending the behavior of the default brain or completely override it.&amp;#160; I will use the combat pet brain as an example&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;, it is a brain designed for summoned combat pets or charmed pets.&amp;#160; All this brain does is extend &lt;/ins&gt;the default brain &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;to make the pet follow its owner&lt;/ins&gt;.&amp;#160; This will require you to recompile your server.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Creating The New Brain=&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Creating The New Brain=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Jabantiz</name></author>
		
	</entry>
	<entry>
		<id>https://oldwiki.eq2classic.com/index.php?title=AI:BrainTutorialC&amp;diff=4760&amp;oldid=prev</id>
		<title>Jabantiz: Created page with &quot;Creating a new brain in C++ gives you the option of extending the behavior of the default brain or completely override it.  I will use the combat pet brain as an example which ex...&quot;</title>
		<link rel="alternate" type="text/html" href="https://oldwiki.eq2classic.com/index.php?title=AI:BrainTutorialC&amp;diff=4760&amp;oldid=prev"/>
		<updated>2013-03-30T03:43:03Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Creating a new brain in C++ gives you the option of extending the behavior of the default brain or completely override it.  I will use the combat pet brain as an example which ex...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Creating a new brain in C++ gives you the option of extending the behavior of the default brain or completely override it.  I will use the combat pet brain as an example which extends the functionality of the default brain.  This will require you to recompile your server.&lt;br /&gt;
&lt;br /&gt;
=Creating The New Brain=&lt;br /&gt;
The first thing we need to do is create the new brain class and have it inherit from the default brain class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class CombatPetBrain : public Brain {&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every brain needs a constructor, destructor, and think function.  The constructor must take a parameter of type NPC*, this parameter tells the brain what NPC we are controlling in the game.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class CombatPetBrain : public Brain {&lt;br /&gt;
	CombatPetBrain(NPC* body);&lt;br /&gt;
	~CombatPetBrain();&lt;br /&gt;
	void Think();&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That is the minimum needed to create a new brain, you can add whatever else you want to the class but those 3 functions must be there.  For this brain that is all we need.&lt;br /&gt;
&lt;br /&gt;
=Programing The New Brain=&lt;br /&gt;
No matter if you are just extending the default brain or making a completely new one you must call the default brain's constructor to set up some essential variables, mainly the timers and the NPC this brain will control.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CombatPetBrain::CombatPetBrain(NPC* body) : Brain(body) {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Notice the &amp;quot;: Brain(body)&amp;quot; after the parameters for our constructor, this will take the parameter we passed to our constructor, body, and pass it to the default constructor to set up the essential stuff.  For this brain we have nothing special to add to the constructor or destructor so both will be left blank.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CombatPetBrain::~CombatPetBrain() {&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we get to the Think() function.  This will decide what the NPC should do and is called every 1/4 sec by default.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void CombatPetBrain::Think() {&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All we want to do for this brain is extend the functionality of the default brain so this NPC follows its owner around so first thing we need to do is have the default code run.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void CombatPetBrain::Think() {&lt;br /&gt;
	// We are extending the base brain so make sure to call the parent Think() function.&lt;br /&gt;
	// If we want to override then we could remove Brain::Think()&lt;br /&gt;
	Brain::Think();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to completely override the default behavior then you would just leave Brain::Think() out.  Now we add the code to make the NPC follow its owner.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void CombatPetBrain::Think() {&lt;br /&gt;
	// We are extending the base brain so make sure to call the parent Think() function.&lt;br /&gt;
	// If we want to override then we could remove Brain::Think()&lt;br /&gt;
	Brain::Think();&lt;br /&gt;
&lt;br /&gt;
	// All this Brain does is make the pet follow its owner, the combat comes from the default brain&lt;br /&gt;
&lt;br /&gt;
	if (GetBody()-&amp;gt;EngagedInCombat() || !GetBody()-&amp;gt;IsPet() || GetBody()-&amp;gt;IsMezzedOrStunned())&lt;br /&gt;
		return;&lt;br /&gt;
	&lt;br /&gt;
	LogWrite(NPC_AI__DEBUG, 7, &amp;quot;NPC_AI&amp;quot;, &amp;quot;Pet AI code called for %s&amp;quot;, GetBody()-&amp;gt;GetName());&lt;br /&gt;
&lt;br /&gt;
	// If owner is a player and player has stay set then return out&lt;br /&gt;
	if (GetBody()-&amp;gt;GetOwner()-&amp;gt;IsPlayer() &amp;amp;&amp;amp; ((Player*)GetBody()-&amp;gt;GetOwner())-&amp;gt;GetInfoStruct()-&amp;gt;pet_movement == 1)&lt;br /&gt;
		return;&lt;br /&gt;
&lt;br /&gt;
	// Set target to owner&lt;br /&gt;
	Entity* target = GetBody()-&amp;gt;GetOwner();&lt;br /&gt;
	GetBody()-&amp;gt;SetTarget(target);&lt;br /&gt;
&lt;br /&gt;
	// Get distance from the owner&lt;br /&gt;
	float distance = GetBody()-&amp;gt;GetDistance(target);&lt;br /&gt;
	distance -= target-&amp;gt;appearance.pos.collision_radius / 10;&lt;br /&gt;
	distance -= GetBody()-&amp;gt;appearance.pos.collision_radius / 10;&lt;br /&gt;
&lt;br /&gt;
	// If out of melee range then move closer&lt;br /&gt;
	if (distance &amp;gt; MAX_COMBAT_RANGE)&lt;br /&gt;
		MoveCloser(target);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jabantiz</name></author>
		
	</entry>
</feed>