*implemented 'empty' VehicleAI

NOTE: VehicleAI::UpdateAI runs even while the vehicle is mounted!

--HG--
branch : trunk
This commit is contained in:
Rat
2010-04-29 21:22:25 +02:00
parent 946ded4619
commit 757fbfba83
6 changed files with 59 additions and 10 deletions

View File

@@ -59,6 +59,11 @@ int AOEAI::Permissible(const Creature * /*creature*/)
return PERMIT_BASE_NO;
}
int VehicleAI::Permissible(const Creature * /*creature*/)
{
return PERMIT_BASE_NO;
}
void CombatAI::InitializeAI()
{
for (uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
@@ -281,3 +286,22 @@ void AOEAI::UpdateAI(const uint32 /*diff*/)
if (!me->HasAura(me->m_spells[0]))
me->CastSpell(me, me->m_spells[0],false);
}
//////////////
//VehicleAI
//////////////
//NOTE: VehicleAI::UpdateAI runs even while the vehicle is mounted
void VehicleAI::UpdateAI(const uint32 diff)
{
}
void VehicleAI::Reset()
{
m_vehicle->Reset();
}
void VehicleAI::OnCharmed(bool apply)
{
m_IsVehicleInUse = apply;
}

View File

@@ -100,5 +100,22 @@ struct AOEAI : public CreatureAI
static int Permissible(const Creature *);
};
#define VEHICLE_RESET_TIME 5000
struct VehicleAI : public CreatureAI
{
public:
explicit VehicleAI(Creature *c) : CreatureAI(c), m_vehicle(c->GetVehicleKit()), m_IsVehicleInUse(false) {}
void UpdateAI(const uint32 diff);
static int Permissible(const Creature *);
void Reset();
void MoveInLineOfSight(Unit *) {}
void AttackStart(Unit *) {}
void OnCharmed(bool apply);
private:
Vehicle* m_vehicle;
bool m_IsVehicleInUse;
};
#endif

View File

@@ -50,6 +50,7 @@ namespace AIRegistry
(new CreatureAIFactory<TurretAI>("TurretAI"))->RegisterSelf();
(new CreatureAIFactory<CreatureEventAI>("EventAI"))->RegisterSelf();
(new CreatureAIFactory<AOEAI>("AOEAI"))->RegisterSelf();
(new CreatureAIFactory<VehicleAI>("VehicleAI"))->RegisterSelf();
(new MovementGeneratorFactory<RandomMovementGenerator<Creature> >(RANDOM_MOTION_TYPE))->RegisterSelf();
(new MovementGeneratorFactory<WaypointMovementGenerator<Creature> >(WAYPOINT_MOTION_TYPE))->RegisterSelf();

View File

@@ -54,9 +54,11 @@ namespace FactorySelector
// select by NPC flags
if (!ai_factory)
{
if (creature->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN) && ((Guardian*)creature)->GetOwner()->GetTypeId() == TYPEID_PLAYER)
if (creature->IsVehicle())
ai_factory = ai_registry.GetRegistryItem("VehicleAI");
else if (creature->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN) && ((Guardian*)creature)->GetOwner()->GetTypeId() == TYPEID_PLAYER)
ai_factory = ai_registry.GetRegistryItem("PetAI");
else if (creature->IsVehicle() || creature->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK))
else if (creature->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK))
ai_factory = ai_registry.GetRegistryItem("NullCreatureAI");
else if (creature->isGuard())
ai_factory = ai_registry.GetRegistryItem("GuardAI");

View File

@@ -15167,17 +15167,21 @@ void Unit::RemoveCharmedBy(Unit *charmer)
if (GetTypeId() == TYPEID_UNIT)
{
this->ToCreature()->AI()->OnCharmed(false);
this->ToCreature()->AIM_Initialize();
if (this->ToCreature()->AI() && charmer && charmer->isAlive())
this->ToCreature()->AI()->AttackStart(charmer);
/*if (isAlive() && this->ToCreature()->IsAIEnabled)
if (type != CHARM_TYPE_VEHICLE)//Vehicles' AI is never modified
{
if (charmer && !IsFriendlyTo(charmer))
this->ToCreature()->AIM_Initialize();
if (this->ToCreature()->AI() && charmer && charmer->isAlive())
this->ToCreature()->AI()->AttackStart(charmer);
else
this->ToCreature()->AI()->EnterEvadeMode();
}*/
/*if (isAlive() && this->ToCreature()->IsAIEnabled)
{
if (charmer && !IsFriendlyTo(charmer))
this->ToCreature()->AI()->AttackStart(charmer);
else
this->ToCreature()->AI()->EnterEvadeMode();
}*/
}
}
else
this->ToPlayer()->SetClientControl(this, 1);

View File

@@ -74,6 +74,7 @@ class Vehicle
void RelocatePassengers(float x, float y, float z, float ang);
void RemoveAllPassengers();
void Dismiss();
bool IsVehicleInUse() { return m_Seats.begin() != m_Seats.end(); }
SeatMap m_Seats;