Stuck: Pet->Ai() Now Returns A Creatureai Instead Of Petai...

Hmm, so I seem to be stuck. Using rev: 98687770ffb3, I can’t seem to get direct access to the PetAI() anymore. Take this code for example that I’m adding to Unit::DealDamage():


if (victim->GetTypeId() == TYPEID_PLAYER)

{

	 Pet* pet = victim->ToPlayer()->GetPet();


	 if (pet)

		  pet->AI()->OwnerDamagedBy(this); // Doesn't exist, AI is returning a CreatureAI now?

}

The pet->AI() in the past used to give direct access to PetAI but now it returns CreatureAI. Since OwnerDamagedBy() has no relavance to non-pet entities it didn’t make sense to make it virtual in CreatureAI so I declared it public in PetAI.

I tried casting to a PetAI but that made Visual Studio very unhappy. How do I get direct access to the PetAI?

Note: I’m currently working on a patch for the PetAI to improve target selection and overall functionality. For now I’ve made it virtual but it seems silly to do that.

PetAI comes from CreatureAI, you should be able to cast it without problems

Yeah, that’s what I thought but these all return a CreatureAI which doesn’t include my added functions.

pet->AI()

pet->GetAI()

((PetAI*)pet->AI())

((PetAI*)pet->GetAI())

((PetAI&)pet->AI())

((PetAI&)pet->GetAI())

PetAI(pet->ToCreature())

((PetAI*)(pet->AI()))-> this should work, althought its the same as ((PetAI*)pet->GetAI()), whats the error it shows?

Well, I tried getting the pet AI in SpellHandler from _player:


Pet* playerPet = _player->GetPet();


if (playerPet)

{

	 ((PetAI*)playerPet->AI())->MyFunction();

}

but intellisense says the expression could not be resolved and when I try to compile it says MyFunction isn’t a member.

tried static_casting it?

No but I moved it into Spell.cpp instead and it doesn’t work because PetAI is undeclared. I didn’t want to include PetAI so I just made the functions virtual in CreatureAI.

I’m still curious what’s happened though. Any way to get direct access to the PetAI? It seems unnecessary to add a bunch of calls to the stack when you should be able to dereference the CreatureAI into a PetAI.