1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "AnimalAI.h"
- #include "Entity.h"
- AnimalAI::AnimalAI(Animal* zAnimal)
- : ReferenceCounter(),
- zAnimal(zAnimal),
- ticksToNextAction(0),
- viewDistance(0)
- {}
- void AnimalAI::onTick()
- {
- ticksToNextAction--;
- if (ticksToNextAction <= 0)
- {
- ticksToNextAction = desideAction();
- }
- }
- void AnimalAI::save(Framework::StreamWriter* zWriter) const {}
- void AnimalAI::load(Framework::StreamReader* zReader) {}
- void AnimalAI::onEntityEntersView(Entity* zEntity)
- {
- for (int id : viewableEntities)
- {
- if (id == zEntity->getId())
- {
- return;
- }
- }
- viewableEntities.add(zEntity->getId());
- }
- void AnimalAI::onEntityLeavesView(Entity* zEntity)
- {
- for (auto iterator = viewableEntities.begin(); iterator; iterator++)
- {
- if (*iterator == zEntity->getId())
- {
- iterator.remove();
- return;
- }
- }
- }
|