Entity.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. #include "Entity.h"
  2. #include <Text.h>
  3. #include "BlockType.h"
  4. #include "Dimension.h"
  5. #include "EntityRemovedUpdate.h"
  6. #include "Game.h"
  7. #include "ItemSkill.h"
  8. #include "NoBlock.h"
  9. ActionTarget::ActionTarget(Vec3<int> blockPos, Direction blockSide)
  10. : blockPos(blockPos),
  11. targetBlockSide(blockSide),
  12. entityId(-1)
  13. {}
  14. ActionTarget::ActionTarget(int entityId)
  15. : entityId(entityId)
  16. {}
  17. bool ActionTarget::isBlock(
  18. Framework::Vec3<int> blockPos, Direction blockSide) const
  19. {
  20. return this->entityId == -1 && this->blockPos == blockPos
  21. && (this->targetBlockSide == targetBlockSide
  22. || blockSide == NO_DIRECTION);
  23. }
  24. bool ActionTarget::isEntity(int entityId) const
  25. {
  26. return this->entityId == entityId;
  27. }
  28. void ActionTarget::useItemSkillOnTarget(
  29. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem)
  30. {
  31. if (entityId >= 0)
  32. {
  33. Entity* target = Game::INSTANCE->zEntity(entityId);
  34. if (target) zItemSkill->use(zActor, zUsedItem, target);
  35. }
  36. else
  37. {
  38. Block* block = Game::INSTANCE->zRealBlockInstance(
  39. blockPos, zActor->getDimensionId());
  40. if (block) zItemSkill->use(zActor, zUsedItem, block);
  41. }
  42. }
  43. void ActionTarget::interactItemSkillOnTarget(
  44. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem)
  45. {
  46. if (zItemSkill)
  47. {
  48. if (entityId >= 0)
  49. {
  50. Entity* target = Game::INSTANCE->zEntity(entityId);
  51. if (target) zItemSkill->interact(zActor, zUsedItem, target);
  52. }
  53. else
  54. {
  55. Block* block = Game::INSTANCE->zRealBlockInstance(
  56. blockPos, zActor->getDimensionId());
  57. if (block) zItemSkill->interact(zActor, zUsedItem, block);
  58. }
  59. }
  60. else
  61. {
  62. if (entityId >= 0)
  63. {
  64. Block* block = Game::INSTANCE->zRealBlockInstance(
  65. blockPos, zActor->getDimensionId());
  66. if (block) block->interact(zUsedItem, zActor);
  67. }
  68. else
  69. {
  70. Block* block = Game::INSTANCE->zRealBlockInstance(
  71. blockPos, zActor->getDimensionId());
  72. if (block) block->interact(zUsedItem, zActor);
  73. }
  74. }
  75. }
  76. void ActionTarget::placeBlock(Entity* zActor, Item* zItem)
  77. {
  78. if (zActor->getStamina() > 0.2f)
  79. {
  80. if (zItem->canBePlacedAt(zActor->getDimensionId(),
  81. blockPos + getDirection(targetBlockSide)))
  82. {
  83. Block* block = zItem->zPlacedBlockType()->createBlockAt(
  84. blockPos + getDirection(targetBlockSide),
  85. zActor->getDimensionId(),
  86. zItem);
  87. if (block)
  88. {
  89. Game::INSTANCE->zDimension(zActor->getDimensionId())
  90. ->placeBlock(block->getPos(), block);
  91. zItem->onPlaced();
  92. zActor->setStamina(zActor->getStamina() - 0.2f);
  93. }
  94. }
  95. }
  96. }
  97. void ActionTarget::toMessage(
  98. const ActionTarget* zTarget, int dimensionId, NetworkMessage* zMsg)
  99. {
  100. if (zTarget)
  101. {
  102. if (zTarget->entityId >= 0)
  103. {
  104. char* message = new char[6];
  105. message[0] = 3;
  106. message[1] = 1;
  107. *(int*)(message + 2) = zTarget->entityId;
  108. zMsg->setMessage(message, 6);
  109. }
  110. else
  111. {
  112. Framework::Text targetUIML = "";
  113. auto block
  114. = Game::INSTANCE->zBlockAt(zTarget->blockPos, dimensionId);
  115. if (block.isA())
  116. {
  117. targetUIML = block.getA()->getTargetUIML();
  118. }
  119. else if (block.isB())
  120. {
  121. targetUIML = StaticRegistry<BlockType>::INSTANCE
  122. .zElement(block.getB())
  123. ->getTargetUIML();
  124. }
  125. char* message = new char[18 + targetUIML.getLength() + 2];
  126. message[0] = 3;
  127. message[1] = 2;
  128. *(int*)(message + 2) = zTarget->blockPos.x;
  129. *(int*)(message + 6) = zTarget->blockPos.y;
  130. *(int*)(message + 10) = zTarget->blockPos.z;
  131. *(int*)(message + 14) = zTarget->targetBlockSide;
  132. short len = (short)targetUIML.getLength();
  133. *(short*)(message + 18) = len;
  134. memcpy(message + 20, targetUIML.getText(), len);
  135. zMsg->setMessage(message, 18 + len + 2);
  136. }
  137. }
  138. else
  139. {
  140. char* message = new char[2];
  141. message[0] = 3;
  142. message[1] = 0;
  143. zMsg->setMessage(message, 2);
  144. }
  145. }
  146. void ActionTarget::save(ActionTarget* zTarget, Framework::StreamWriter* zWriter)
  147. {
  148. if (zTarget)
  149. {
  150. if (zTarget->entityId >= 0)
  151. {
  152. char b = 1;
  153. zWriter->schreibe(&b, 1);
  154. zWriter->schreibe((char*)&zTarget->entityId, 4);
  155. }
  156. else
  157. {
  158. char b = 2;
  159. zWriter->schreibe(&b, 1);
  160. zWriter->schreibe((char*)&zTarget->blockPos.x, 4);
  161. zWriter->schreibe((char*)&zTarget->blockPos.y, 4);
  162. zWriter->schreibe((char*)&zTarget->blockPos.z, 4);
  163. zWriter->schreibe((char*)&zTarget->targetBlockSide, 4);
  164. }
  165. }
  166. else
  167. {
  168. char b = 0;
  169. zWriter->schreibe(&b, 1);
  170. }
  171. }
  172. ActionTarget* ActionTarget::load(Framework::StreamReader* zReader)
  173. {
  174. char b;
  175. zReader->lese(&b, 1);
  176. if (b == 1)
  177. {
  178. int id;
  179. zReader->lese((char*)&id, 4);
  180. return new ActionTarget(id);
  181. }
  182. else if (b == 2)
  183. {
  184. Framework::Vec3<int> pos;
  185. Direction side;
  186. zReader->lese((char*)&pos.x, 4);
  187. zReader->lese((char*)&pos.y, 4);
  188. zReader->lese((char*)&pos.z, 4);
  189. zReader->lese((char*)&side, 4);
  190. return new ActionTarget(pos, side);
  191. }
  192. return 0;
  193. }
  194. Entity::Entity(
  195. int typeId, Framework::Vec3<float> location, int dimensionId, int entityId)
  196. : Inventory(location, dimensionId, true),
  197. chatSecurityLevel(0),
  198. speed(0, 0, 0),
  199. faceDir(1, 0, 0),
  200. target(0),
  201. typeId(typeId),
  202. removed(0),
  203. gravityMultiplier(1.f),
  204. id(entityId),
  205. placeBlockCooldown(0)
  206. {}
  207. void Entity::onDeath()
  208. {
  209. removed = 1;
  210. Game::INSTANCE->requestWorldUpdate(
  211. new EntityRemovedUpdate(id, dimensionId, location));
  212. }
  213. void Entity::useItem(int typeId, Item* zItem, bool left)
  214. {
  215. if (left)
  216. {
  217. if (!zItem || zItem->isUsable())
  218. {
  219. cs.lock();
  220. if (target)
  221. {
  222. ItemSkill* selected = zSkill(typeId);
  223. if (!selected)
  224. {
  225. selected
  226. = StaticRegistry<ItemType>::INSTANCE.zElement(typeId)
  227. ->createDefaultItemSkill();
  228. if (selected) skills.add(selected);
  229. }
  230. if (!selected)
  231. {
  232. selected = zSkill(ItemTypeEnum::PLAYER_HAND);
  233. }
  234. target->useItemSkillOnTarget(this, selected, zItem);
  235. }
  236. cs.unlock();
  237. }
  238. else if (left)
  239. {
  240. useItem(ItemTypeEnum::PLAYER_HAND, 0, left);
  241. }
  242. }
  243. else
  244. {
  245. if (zItem && zItem->isEatable())
  246. { // eat item
  247. zItem->applyFoodEffects(this);
  248. }
  249. else if (zItem && zItem->isPlaceable())
  250. { // place item
  251. if (placeBlockCooldown <= 0)
  252. {
  253. cs.lock();
  254. if (target)
  255. {
  256. target->placeBlock(this, zItem);
  257. placeBlockCooldown = 15;
  258. }
  259. cs.unlock();
  260. }
  261. }
  262. else if (!zItem || zItem->isUsable())
  263. { // use item skill
  264. cs.lock();
  265. if (target)
  266. {
  267. ItemSkill* selected = zSkill(typeId);
  268. if (!selected)
  269. {
  270. selected
  271. = StaticRegistry<ItemType>::INSTANCE.zElement(typeId)
  272. ->createDefaultItemSkill();
  273. if (selected) skills.add(selected);
  274. }
  275. target->interactItemSkillOnTarget(this, selected, zItem);
  276. }
  277. cs.unlock();
  278. }
  279. }
  280. }
  281. void Entity::onTargetChange() {}
  282. void Entity::interact(Item* zItem, Entity* zActor) {}
  283. void Entity::addMovementFrame(MovementFrame& frame)
  284. {
  285. cs.lock();
  286. movements.add(frame);
  287. cs.unlock();
  288. NetworkMessage* message = new NetworkMessage();
  289. message->addressEntity(this);
  290. char* msg = new char[37];
  291. msg[0] = 0;
  292. *(float*)(msg + 1) = frame.direction.x;
  293. *(float*)(msg + 5) = frame.direction.y;
  294. *(float*)(msg + 9) = frame.direction.z;
  295. *(float*)(msg + 13) = frame.targetPosition.x;
  296. *(float*)(msg + 17) = frame.targetPosition.y;
  297. *(float*)(msg + 21) = frame.targetPosition.z;
  298. *(int*)(msg + 25) = frame.movementFlags;
  299. *(double*)(msg + 29) = frame.duration;
  300. message->setMessage(msg, 37);
  301. Game::INSTANCE->broadcastMessage(message);
  302. faceDir = frame.direction;
  303. // TODO implement subscription system to notify only interested clients
  304. }
  305. void Entity::calculateTarget(Framework::Vec3<float> basePos,
  306. Framework::Vec3<float> direction,
  307. const Item* zItem)
  308. {
  309. Vec3<float> headPosition = basePos + faceOffset;
  310. int px = (int)floor(headPosition.x);
  311. int py = (int)floor(headPosition.y);
  312. int pz = (int)floor(headPosition.z);
  313. direction.normalize();
  314. Direction dir = BOTTOM;
  315. while (true)
  316. {
  317. if (getDefaultBlock(Game::INSTANCE->zBlockAt(Vec3<int>{px, py, pz}, dimensionId))
  318. ->isInteractable(zItem))
  319. {
  320. if (!target || !target->isBlock({px, py, pz}, dir))
  321. {
  322. cs.lock();
  323. delete target;
  324. target = new ActionTarget({px, py, pz}, dir);
  325. cs.unlock();
  326. onTargetChange();
  327. }
  328. break;
  329. }
  330. // collision to neighbor of current block
  331. if (direction.x > 0)
  332. {
  333. float xt = ((float)px + 1.f - headPosition.x) / direction.x;
  334. Vec3<float> tmp = headPosition + direction * xt;
  335. if (xt <= targetDistanceLimit && tmp.y >= (float)py
  336. && tmp.y < (float)py + 1.f && tmp.z >= (float)pz
  337. && tmp.z < (float)pz + 1.f)
  338. {
  339. dir = WEST;
  340. px++;
  341. continue;
  342. }
  343. }
  344. if (direction.x < 0)
  345. {
  346. float xt = ((float)px - headPosition.x) / direction.x;
  347. Vec3<float> tmp = headPosition + direction * xt;
  348. if (xt <= targetDistanceLimit && tmp.y >= (float)py
  349. && tmp.y < (float)py + 1.f && tmp.z >= (float)pz
  350. && tmp.z < (float)pz + 1.f)
  351. {
  352. dir = EAST;
  353. px--;
  354. continue;
  355. }
  356. }
  357. if (direction.y > 0)
  358. {
  359. float yt = ((float)py + 1.f - headPosition.y) / direction.y;
  360. Vec3<float> tmp = headPosition + direction * yt;
  361. if (yt <= targetDistanceLimit && tmp.x >= (float)px
  362. && tmp.x < (float)px + 1.f && tmp.z >= (float)pz
  363. && tmp.z < (float)pz + 1.f)
  364. {
  365. dir = NORTH;
  366. py++;
  367. continue;
  368. }
  369. }
  370. if (direction.y < 0)
  371. {
  372. float yt = ((float)py - headPosition.y) / direction.y;
  373. Vec3<float> tmp = headPosition + direction * yt;
  374. if (yt <= targetDistanceLimit && tmp.x >= (float)px
  375. && tmp.x < (float)px + 1.f && tmp.z >= (float)pz
  376. && tmp.z < (float)pz + 1.f)
  377. {
  378. dir = SOUTH;
  379. py--;
  380. continue;
  381. }
  382. }
  383. if (direction.z > 0)
  384. {
  385. float zt = ((float)pz + 1.f - headPosition.z) / direction.z;
  386. Vec3<float> tmp = headPosition + direction * zt;
  387. if (zt <= targetDistanceLimit && tmp.x >= (float)px
  388. && tmp.x < (float)px + 1.f && tmp.y >= (float)py
  389. && tmp.y < (float)py + 1.f)
  390. {
  391. dir = BOTTOM;
  392. pz++;
  393. continue;
  394. }
  395. }
  396. if (direction.z < 0)
  397. {
  398. float zt = ((float)pz - headPosition.z) / direction.z;
  399. Vec3<float> tmp = headPosition + direction * zt;
  400. if (zt <= targetDistanceLimit && tmp.x >= (float)px
  401. && tmp.x < (float)px + 1.f && tmp.y >= (float)py
  402. && tmp.y < (float)py + 1)
  403. {
  404. dir = TOP;
  405. pz--;
  406. continue;
  407. }
  408. }
  409. if (target)
  410. {
  411. cs.lock();
  412. delete target;
  413. target = 0;
  414. cs.unlock();
  415. onTargetChange();
  416. }
  417. break;
  418. }
  419. }
  420. void Entity::removeStatusBarObserver(Entity* zSource, Framework::Text id)
  421. {
  422. cs.lock();
  423. int index = 0;
  424. for (auto observer : statusBarObservers)
  425. {
  426. if (observer.getFirst() == zSource->getId()
  427. && observer.getSecond().istGleich(id))
  428. {
  429. statusBarObservers.remove(index);
  430. break;
  431. }
  432. index++;
  433. }
  434. cs.unlock();
  435. }
  436. void Entity::addStatusBarObserver(Entity* zSource, Framework::Text id)
  437. {
  438. cs.lock();
  439. for (auto observer : statusBarObservers)
  440. {
  441. if (observer.getFirst() == zSource->getId()
  442. && observer.getSecond().istGleich(id))
  443. {
  444. cs.unlock();
  445. return;
  446. }
  447. }
  448. statusBarObservers.add(ImmutablePair<int, Text>(zSource->getId(), id));
  449. cs.unlock();
  450. }
  451. void Entity::notifyStatusBarObservers(NetworkMessage* msg)
  452. {
  453. cs.lock();
  454. int index = 0;
  455. Array<int> toDelete;
  456. for (auto observer : statusBarObservers)
  457. {
  458. Entity* e = Game::INSTANCE->zEntity(observer.getFirst());
  459. if (e)
  460. {
  461. msg->addressGui(observer.getSecond());
  462. Game::INSTANCE->sendMessage(msg->clone(), e);
  463. }
  464. else
  465. toDelete.add(index, 0);
  466. index++;
  467. }
  468. for (int i : toDelete)
  469. statusBarObservers.remove(i);
  470. cs.unlock();
  471. msg->release();
  472. }
  473. ItemSkill* Entity::zSkill(int itemType)
  474. {
  475. ItemSkill* selected = 0;
  476. for (ItemSkill* skill : skills)
  477. {
  478. if (skill->getTypeId() == typeId)
  479. {
  480. return skill;
  481. }
  482. }
  483. return 0;
  484. }
  485. void Entity::prepareTick(const Dimension* zDimension) {}
  486. void Entity::tick(const Dimension* zDimension)
  487. {
  488. if (placeBlockCooldown > 0)
  489. {
  490. placeBlockCooldown--;
  491. }
  492. placeBlockCooldown--;
  493. if (time.isMeasuring())
  494. {
  495. time.messungEnde();
  496. if (movements.getEintragAnzahl() > 0)
  497. {
  498. MovementFrame currentFrame = movements.get(0);
  499. double seconds = time.getSekunden();
  500. while (seconds > 0)
  501. {
  502. if (currentFrame.duration <= 0)
  503. {
  504. cs.lock();
  505. movements.remove(0);
  506. cs.unlock();
  507. if (movements.getEintragAnzahl() > 0)
  508. currentFrame = movements.get(0);
  509. else
  510. break;
  511. }
  512. double t = MIN(currentFrame.duration, seconds);
  513. // TODO: add collision detection to reduce cheating capability
  514. location += (currentFrame.targetPosition - location)
  515. * (float)(t / currentFrame.duration);
  516. currentFrame.duration -= t;
  517. seconds -= t;
  518. if (currentFrame.duration <= 0)
  519. {
  520. location = currentFrame.targetPosition;
  521. }
  522. }
  523. if (currentFrame.duration > 0) movements.set(currentFrame, 0);
  524. if (getStamina() <= getMaxStamina() - 0.0025f)
  525. {
  526. if (getThirst() > 0 && getHunger() > 0)
  527. {
  528. setStamina(getStamina() + 0.0025f);
  529. setHunger(getHunger() - 0.0005f);
  530. setThirst(getThirst() - 0.0015f);
  531. }
  532. }
  533. }
  534. else
  535. {
  536. if (getStamina() <= getMaxStamina() - 0.005f)
  537. {
  538. if (getThirst() > 0 && getHunger() > 0)
  539. {
  540. setStamina(getStamina() + 0.005f);
  541. setHunger(getHunger() - 0.001f);
  542. setThirst(getThirst() - 0.003f);
  543. }
  544. }
  545. }
  546. }
  547. time.messungStart();
  548. }
  549. void Entity::api(Framework::StreamReader* zRequest,
  550. NetworkMessage* zResponse,
  551. Entity* zSource)
  552. {
  553. char type;
  554. zRequest->lese(&type, 1);
  555. switch (type)
  556. {
  557. case 0: // request status bar state
  558. {
  559. char len;
  560. zRequest->lese(&len, 1);
  561. char* guiId = new char[(int)len + 1];
  562. zRequest->lese(guiId, len);
  563. guiId[(int)len] = 0;
  564. zResponse->addressGui(guiId);
  565. addStatusBarObserver(zSource, guiId);
  566. char* msg = new char[33];
  567. msg[0] = 0;
  568. *(float*)(msg + 1) = getMaxHP();
  569. *(float*)(msg + 5) = getCurrentHP();
  570. *(float*)(msg + 9) = getMaxStamina();
  571. *(float*)(msg + 13) = getStamina();
  572. *(float*)(msg + 17) = getMaxHunger();
  573. *(float*)(msg + 21) = getHunger();
  574. *(float*)(msg + 25) = getMaxThirst();
  575. *(float*)(msg + 29) = getThirst();
  576. zResponse->setMessage(msg, 33);
  577. delete[] guiId;
  578. break;
  579. }
  580. case 1: // remove status bar observer
  581. {
  582. char len;
  583. zRequest->lese(&len, 1);
  584. char* guiId = new char[(int)len + 1];
  585. zRequest->lese(guiId, len);
  586. guiId[(int)len] = 0;
  587. removeStatusBarObserver(zSource, guiId);
  588. delete[] guiId;
  589. break;
  590. }
  591. }
  592. }
  593. void Entity::onFall(float collisionSpeed)
  594. {
  595. if (collisionSpeed > 5)
  596. {
  597. // TODO: take damage
  598. }
  599. }
  600. void Entity::setChatSecurityLevel(int level)
  601. {
  602. chatSecurityLevel = level;
  603. }
  604. void Entity::setPosition(Framework::Vec3<float> pos)
  605. {
  606. location = pos;
  607. }
  608. void Entity::setHP(float hp)
  609. {
  610. currentHP = MIN(MAX(hp, 0), maxHP);
  611. NetworkMessage* msg = new NetworkMessage();
  612. char* message = new char[9];
  613. message[0] = 1;
  614. *(float*)(message + 1) = getMaxHP();
  615. *(float*)(message + 5) = getCurrentHP();
  616. msg->setMessage(message, 9);
  617. notifyStatusBarObservers(msg);
  618. }
  619. void Entity::setStamina(float stamina)
  620. {
  621. this->stamina = MIN(MAX(stamina, 0), maxStamina);
  622. NetworkMessage* msg = new NetworkMessage();
  623. char* message = new char[9];
  624. message[0] = 2;
  625. *(float*)(message + 1) = getMaxStamina();
  626. *(float*)(message + 5) = getStamina();
  627. msg->setMessage(message, 9);
  628. notifyStatusBarObservers(msg);
  629. }
  630. void Entity::setHunger(float hunger)
  631. {
  632. this->hunger = MIN(MAX(hunger, 0), maxHunger);
  633. NetworkMessage* msg = new NetworkMessage();
  634. char* message = new char[9];
  635. message[0] = 3;
  636. *(float*)(message + 1) = getMaxHunger();
  637. *(float*)(message + 5) = getHunger();
  638. msg->setMessage(message, 9);
  639. notifyStatusBarObservers(msg);
  640. }
  641. void Entity::setThirst(float thirst)
  642. {
  643. this->thirst = MIN(MAX(thirst, 0), maxThirst);
  644. NetworkMessage* msg = new NetworkMessage();
  645. char* message = new char[9];
  646. message[0] = 4;
  647. *(float*)(message + 1) = getMaxThirst();
  648. *(float*)(message + 5) = getThirst();
  649. msg->setMessage(message, 9);
  650. notifyStatusBarObservers(msg);
  651. }
  652. float Entity::getMaxHP() const
  653. {
  654. return maxHP;
  655. }
  656. float Entity::getCurrentHP() const
  657. {
  658. return currentHP;
  659. }
  660. float Entity::getStamina() const
  661. {
  662. return stamina;
  663. }
  664. float Entity::getMaxStamina() const
  665. {
  666. return maxStamina;
  667. }
  668. float Entity::getHunger() const
  669. {
  670. return hunger;
  671. }
  672. float Entity::getMaxHunger() const
  673. {
  674. return maxHunger;
  675. }
  676. float Entity::getThirst() const
  677. {
  678. return thirst;
  679. }
  680. float Entity::getMaxThirst() const
  681. {
  682. return maxThirst;
  683. }
  684. Framework::Vec3<float> Entity::getSpeed() const
  685. {
  686. return speed;
  687. }
  688. Framework::Vec3<float> Entity::getFaceDir() const
  689. {
  690. return faceDir;
  691. }
  692. Framework::Vec3<float> Entity::getPosition() const
  693. {
  694. return location;
  695. }
  696. float Entity::getGravityMultiplier() const
  697. {
  698. return gravityMultiplier;
  699. }
  700. bool Entity::isRemoved() const
  701. {
  702. return removed;
  703. }
  704. const EntityType* Entity::zType() const
  705. {
  706. return StaticRegistry<EntityType>::INSTANCE.zElement(typeId);
  707. }
  708. const ActionTarget* Entity::zTarget() const
  709. {
  710. return target;
  711. }
  712. int Entity::getId() const
  713. {
  714. return id;
  715. }
  716. bool Entity::hasDefaultModel() const
  717. {
  718. return 1;
  719. }
  720. ModelInfo Entity::getSpecialModel() const
  721. {
  722. return ModelInfo("", "", 0);
  723. }
  724. float Entity::getMaxSpeed() const
  725. {
  726. return maxMovementSpeed;
  727. }
  728. bool Entity::isMoving() const
  729. {
  730. return movements.getEintragAnzahl() > 0;
  731. }
  732. int Entity::getChatSecurityLevel() const
  733. {
  734. return chatSecurityLevel;
  735. }