AnimalAI.cpp 925 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "AnimalAI.h"
  2. #include "Entity.h"
  3. AnimalAI::AnimalAI(Animal* zAnimal)
  4. : ReferenceCounter(),
  5. zAnimal(zAnimal),
  6. ticksToNextAction(0),
  7. viewDistance(0)
  8. {}
  9. void AnimalAI::onTick()
  10. {
  11. ticksToNextAction--;
  12. if (ticksToNextAction <= 0)
  13. {
  14. ticksToNextAction = desideAction();
  15. }
  16. }
  17. void AnimalAI::save(Framework::StreamWriter* zWriter) const {}
  18. void AnimalAI::load(Framework::StreamReader* zReader) {}
  19. void AnimalAI::onEntityEntersView(Entity* zEntity)
  20. {
  21. for (int id : viewableEntities)
  22. {
  23. if (id == zEntity->getId())
  24. {
  25. return;
  26. }
  27. }
  28. viewableEntities.add(zEntity->getId());
  29. }
  30. void AnimalAI::onEntityLeavesView(Entity* zEntity)
  31. {
  32. for (auto iterator = viewableEntities.begin(); iterator; iterator++)
  33. {
  34. if (*iterator == zEntity->getId())
  35. {
  36. iterator.remove();
  37. return;
  38. }
  39. }
  40. }