EntityType.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "EntityType.h"
  2. #include "Entity.h"
  3. #include "Game.h"
  4. EntityType::EntityType( int id )
  5. : ReferenceCounter(),
  6. id( id )
  7. {
  8. StaticRegistry<EntityType>::INSTANCE.registerT( this, id );
  9. }
  10. void EntityType::loadSuperEntity( Entity* zEntity, Framework::StreamReader* zReader ) const
  11. {
  12. zEntity->loadInventory( zReader );
  13. zReader->lese( (char*)&zEntity->id, 4 );
  14. zReader->lese( (char*)&zEntity->maxHP, 4 );
  15. zReader->lese( (char*)&zEntity->currentHP, 4 );
  16. zReader->lese( (char*)&zEntity->stamina, 4 );
  17. zReader->lese( (char*)&zEntity->maxStamina, 4 );
  18. zReader->lese( (char*)&zEntity->hunger, 4 );
  19. zReader->lese( (char*)&zEntity->maxHunger, 4 );
  20. zReader->lese( (char*)&zEntity->thirst, 4 );
  21. zReader->lese( (char*)&zEntity->maxThirst, 4 );
  22. zReader->lese( (char*)&zEntity->speed.x, 4 );
  23. zReader->lese( (char*)&zEntity->speed.y, 4 );
  24. zReader->lese( (char*)&zEntity->speed.z, 4 );
  25. zReader->lese( (char*)&zEntity->faceDir.x, 4 );
  26. zReader->lese( (char*)&zEntity->faceDir.y, 4 );
  27. zReader->lese( (char*)&zEntity->currentDimensionId, 4 );
  28. zReader->lese( (char*)&zEntity->location.x, 4 );
  29. zReader->lese( (char*)&zEntity->location.y, 4 );
  30. zReader->lese( (char*)&zEntity->location.z, 4 );
  31. if( zEntity->target )
  32. delete zEntity->target;
  33. zEntity->target = ActionTarget::load( zReader );
  34. }
  35. void EntityType::saveSuperEntity( Entity* zEntity, Framework::StreamWriter* zWriter ) const
  36. {
  37. zEntity->saveInventory( zWriter );
  38. zWriter->schreibe( (char*)&zEntity->id, 4 );
  39. zWriter->schreibe( (char*)&zEntity->maxHP, 4 );
  40. zWriter->schreibe( (char*)&zEntity->currentHP, 4 );
  41. zWriter->schreibe( (char*)&zEntity->stamina, 4 );
  42. zWriter->schreibe( (char*)&zEntity->maxStamina, 4 );
  43. zWriter->schreibe( (char*)&zEntity->hunger, 4 );
  44. zWriter->schreibe( (char*)&zEntity->maxHunger, 4 );
  45. zWriter->schreibe( (char*)&zEntity->thirst, 4 );
  46. zWriter->schreibe( (char*)&zEntity->maxThirst, 4 );
  47. zWriter->schreibe( (char*)&zEntity->speed.x, 4 );
  48. zWriter->schreibe( (char*)&zEntity->speed.y, 4 );
  49. zWriter->schreibe( (char*)&zEntity->speed.z, 4 );
  50. zWriter->schreibe( (char*)&zEntity->faceDir.x, 4 );
  51. zWriter->schreibe( (char*)&zEntity->faceDir.y, 4 );
  52. zWriter->schreibe( (char*)&zEntity->currentDimensionId, 4 );
  53. zWriter->schreibe( (char*)&zEntity->location.x, 4 );
  54. zWriter->schreibe( (char*)&zEntity->location.y, 4 );
  55. zWriter->schreibe( (char*)&zEntity->location.z, 4 );
  56. ActionTarget::save( zEntity->target, zWriter );
  57. }
  58. void EntityType::createSuperEntity( Entity* zEntity ) const
  59. {}
  60. Entity* EntityType::loadEntity( Framework::StreamReader* zReader ) const
  61. {
  62. Entity* entity = createEntity( Framework::Vec3<float>( 0, 0, 0 ), 0, 0 );
  63. loadSuperEntity( entity, zReader );
  64. return entity;
  65. }
  66. void EntityType::saveEntity( Entity* zEntity, Framework::StreamWriter* zWriter ) const
  67. {
  68. saveSuperEntity( zEntity, zWriter );
  69. }
  70. Entity* EntityType::createEntityAt( Framework::Vec3<float> position, int dimensionId ) const
  71. {
  72. Entity* entity = createEntity( position, dimensionId, Game::INSTANCE->getNextEntityId() );
  73. createSuperEntity( entity );
  74. return entity;
  75. }
  76. int EntityType::getId() const
  77. {
  78. return id;
  79. }