/TGame/TServerMS/Entity/EntityManagerScene.cpp

http://awoe.googlecode.com/ · C++ · 75 lines · 57 code · 14 blank · 4 comment · 10 complexity · 8a0d02a05df0ebe16e408d99d6902e87 MD5 · raw file

  1. #include "stdafx.h"
  2. #include "EntityManagerScene.h"
  3. #include "Entity/EntityDefinition.h"
  4. #include "Entity/EntityVisitorCombat.h"
  5. EntityManagerCombat::EntityManagerCombat()
  6. :m_nIDGenerator(0)
  7. {
  8. }
  9. EntityManagerCombat::~EntityManagerCombat()
  10. {
  11. }
  12. bool
  13. EntityManagerCombat::addEntity(int nID, IEntity* e)
  14. {
  15. if (e->getType()==Entity::ett_Player)
  16. {
  17. //
  18. // note that player is not a combat entity
  19. // only its sub roles will be added into entity manager for combat
  20. //
  21. IEntityManager* pSubRoles = e->getEntityMgr();
  22. if (pSubRoles)
  23. {
  24. EntityVisitorCombatRole visitor(*this);
  25. pSubRoles->forEach(visitor);
  26. }
  27. return true;
  28. }
  29. else
  30. {
  31. if (nID == 0)
  32. {
  33. do
  34. {
  35. nID = ++m_nIDGenerator;
  36. }
  37. while(nID==0 || NULL!=getEntity(nID));
  38. }
  39. return __super::addEntity(nID, e);
  40. }
  41. }
  42. EntityManagerCity::EntityManagerCity()
  43. :m_nIDGenerator(0)
  44. {
  45. }
  46. EntityManagerCity::~EntityManagerCity()
  47. {
  48. }
  49. bool
  50. EntityManagerCity::addEntity(int nID, IEntity* e)
  51. {
  52. if (nID == 0)
  53. {
  54. do
  55. {
  56. nID = ++m_nIDGenerator;
  57. }
  58. while(nID==0 || NULL!=getEntity(nID));
  59. }
  60. return __super::addEntity(nID, e);
  61. }