Entity.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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. }
  239. else
  240. {
  241. if (zItem && zItem->isEatable())
  242. { // eat item
  243. zItem->applyFoodEffects(this);
  244. }
  245. else if (zItem && zItem->isPlaceable())
  246. { // place item
  247. if (placeBlockCooldown <= 0)
  248. {
  249. cs.lock();
  250. if (target)
  251. {
  252. target->placeBlock(this, zItem);
  253. placeBlockCooldown = 15;
  254. }
  255. cs.unlock();
  256. }
  257. }
  258. else if (!zItem || zItem->isUsable())
  259. { // use item skill
  260. cs.lock();
  261. if (target)
  262. {
  263. ItemSkill* selected = zSkill(typeId);
  264. if (!selected)
  265. {
  266. selected
  267. = StaticRegistry<ItemType>::INSTANCE.zElement(typeId)
  268. ->createDefaultItemSkill();
  269. if (selected) skills.add(selected);
  270. }
  271. target->interactItemSkillOnTarget(this, selected, zItem);
  272. }
  273. cs.unlock();
  274. }
  275. }
  276. }
  277. void Entity::onTargetChange() {}
  278. void Entity::interact(Item* zItem, Entity* zActor) {}
  279. void Entity::addMovementFrame(MovementFrame& frame)
  280. {
  281. cs.lock();
  282. movements.add(frame);
  283. cs.unlock();
  284. NetworkMessage* message = new NetworkMessage();
  285. message->addressEntity(this);
  286. char* msg = new char[37];
  287. msg[0] = 0;
  288. *(float*)(msg + 1) = frame.direction.x;
  289. *(float*)(msg + 5) = frame.direction.y;
  290. *(float*)(msg + 9) = frame.direction.z;
  291. *(float*)(msg + 13) = frame.targetPosition.x;
  292. *(float*)(msg + 17) = frame.targetPosition.y;
  293. *(float*)(msg + 21) = frame.targetPosition.z;
  294. *(int*)(msg + 25) = frame.movementFlags;
  295. *(double*)(msg + 29) = frame.duration;
  296. message->setMessage(msg, 37);
  297. Game::INSTANCE->broadcastMessage(message);
  298. faceDir = frame.direction;
  299. // TODO implement subscription system to notify only interested clients
  300. }
  301. void Entity::calculateTarget(Framework::Vec3<float> basePos,
  302. Framework::Vec3<float> direction,
  303. const Item* zItem)
  304. {
  305. Vec3<float> headPosition = basePos + faceOffset;
  306. int px = (int)floor(headPosition.x);
  307. int py = (int)floor(headPosition.y);
  308. int pz = (int)floor(headPosition.z);
  309. direction.normalize();
  310. Direction dir = BOTTOM;
  311. while (true)
  312. {
  313. if (getDefaultBlock(Game::INSTANCE->zBlockAt(Vec3<int>{px, py, pz}, dimensionId))
  314. ->isInteractable(zItem))
  315. {
  316. if (!target || !target->isBlock({px, py, pz}, dir))
  317. {
  318. cs.lock();
  319. delete target;
  320. target = new ActionTarget({px, py, pz}, dir);
  321. cs.unlock();
  322. onTargetChange();
  323. }
  324. break;
  325. }
  326. // collision to neighbor of current block
  327. if (direction.x > 0)
  328. {
  329. float xt = ((float)px + 1.f - headPosition.x) / direction.x;
  330. Vec3<float> tmp = headPosition + direction * xt;
  331. if (xt <= targetDistanceLimit && tmp.y >= (float)py
  332. && tmp.y < (float)py + 1.f && tmp.z >= (float)pz
  333. && tmp.z < (float)pz + 1.f)
  334. {
  335. dir = WEST;
  336. px++;
  337. continue;
  338. }
  339. }
  340. if (direction.x < 0)
  341. {
  342. float xt = ((float)px - headPosition.x) / direction.x;
  343. Vec3<float> tmp = headPosition + direction * xt;
  344. if (xt <= targetDistanceLimit && tmp.y >= (float)py
  345. && tmp.y < (float)py + 1.f && tmp.z >= (float)pz
  346. && tmp.z < (float)pz + 1.f)
  347. {
  348. dir = EAST;
  349. px--;
  350. continue;
  351. }
  352. }
  353. if (direction.y > 0)
  354. {
  355. float yt = ((float)py + 1.f - headPosition.y) / direction.y;
  356. Vec3<float> tmp = headPosition + direction * yt;
  357. if (yt <= targetDistanceLimit && tmp.x >= (float)px
  358. && tmp.x < (float)px + 1.f && tmp.z >= (float)pz
  359. && tmp.z < (float)pz + 1.f)
  360. {
  361. dir = NORTH;
  362. py++;
  363. continue;
  364. }
  365. }
  366. if (direction.y < 0)
  367. {
  368. float yt = ((float)py - headPosition.y) / direction.y;
  369. Vec3<float> tmp = headPosition + direction * yt;
  370. if (yt <= targetDistanceLimit && tmp.x >= (float)px
  371. && tmp.x < (float)px + 1.f && tmp.z >= (float)pz
  372. && tmp.z < (float)pz + 1.f)
  373. {
  374. dir = SOUTH;
  375. py--;
  376. continue;
  377. }
  378. }
  379. if (direction.z > 0)
  380. {
  381. float zt = ((float)pz + 1.f - headPosition.z) / direction.z;
  382. Vec3<float> tmp = headPosition + direction * zt;
  383. if (zt <= targetDistanceLimit && tmp.x >= (float)px
  384. && tmp.x < (float)px + 1.f && tmp.y >= (float)py
  385. && tmp.y < (float)py + 1.f)
  386. {
  387. dir = BOTTOM;
  388. pz++;
  389. continue;
  390. }
  391. }
  392. if (direction.z < 0)
  393. {
  394. float zt = ((float)pz - headPosition.z) / direction.z;
  395. Vec3<float> tmp = headPosition + direction * zt;
  396. if (zt <= targetDistanceLimit && tmp.x >= (float)px
  397. && tmp.x < (float)px + 1.f && tmp.y >= (float)py
  398. && tmp.y < (float)py + 1)
  399. {
  400. dir = TOP;
  401. pz--;
  402. continue;
  403. }
  404. }
  405. if (target)
  406. {
  407. cs.lock();
  408. delete target;
  409. target = 0;
  410. cs.unlock();
  411. onTargetChange();
  412. }
  413. break;
  414. }
  415. }
  416. void Entity::removeStatusBarObserver(Entity* zSource, Framework::Text id)
  417. {
  418. cs.lock();
  419. int index = 0;
  420. for (auto observer : statusBarObservers)
  421. {
  422. if (observer.getFirst() == zSource->getId()
  423. && observer.getSecond().istGleich(id))
  424. {
  425. statusBarObservers.remove(index);
  426. break;
  427. }
  428. index++;
  429. }
  430. cs.unlock();
  431. }
  432. void Entity::addStatusBarObserver(Entity* zSource, Framework::Text id)
  433. {
  434. cs.lock();
  435. for (auto observer : statusBarObservers)
  436. {
  437. if (observer.getFirst() == zSource->getId()
  438. && observer.getSecond().istGleich(id))
  439. {
  440. cs.unlock();
  441. return;
  442. }
  443. }
  444. statusBarObservers.add(ImmutablePair<int, Text>(zSource->getId(), id));
  445. cs.unlock();
  446. }
  447. void Entity::notifyStatusBarObservers(NetworkMessage* msg)
  448. {
  449. cs.lock();
  450. int index = 0;
  451. Array<int> toDelete;
  452. for (auto observer : statusBarObservers)
  453. {
  454. Entity* e = Game::INSTANCE->zEntity(observer.getFirst());
  455. if (e)
  456. {
  457. msg->addressGui(observer.getSecond());
  458. Game::INSTANCE->sendMessage(msg->clone(), e);
  459. }
  460. else
  461. toDelete.add(index, 0);
  462. index++;
  463. }
  464. for (int i : toDelete)
  465. statusBarObservers.remove(i);
  466. cs.unlock();
  467. msg->release();
  468. }
  469. ItemSkill* Entity::zSkill(int itemType)
  470. {
  471. ItemSkill* selected = 0;
  472. for (ItemSkill* skill : skills)
  473. {
  474. if (skill->getTypeId() == typeId)
  475. {
  476. return skill;
  477. }
  478. }
  479. return 0;
  480. }
  481. void Entity::prepareTick(const Dimension* zDimension) {}
  482. void Entity::tick(const Dimension* zDimension)
  483. {
  484. if (placeBlockCooldown > 0)
  485. {
  486. placeBlockCooldown--;
  487. }
  488. placeBlockCooldown--;
  489. if (time.isMeasuring())
  490. {
  491. time.messungEnde();
  492. if (movements.getEintragAnzahl() > 0)
  493. {
  494. MovementFrame currentFrame = movements.get(0);
  495. double seconds = time.getSekunden();
  496. while (seconds > 0)
  497. {
  498. if (currentFrame.duration <= 0)
  499. {
  500. cs.lock();
  501. movements.remove(0);
  502. cs.unlock();
  503. if (movements.getEintragAnzahl() > 0)
  504. currentFrame = movements.get(0);
  505. else
  506. break;
  507. }
  508. double t = MIN(currentFrame.duration, seconds);
  509. // TODO: add collision detection to reduce cheating capability
  510. location += (currentFrame.targetPosition - location)
  511. * (float)(t / currentFrame.duration);
  512. currentFrame.duration -= t;
  513. seconds -= t;
  514. if (currentFrame.duration <= 0)
  515. {
  516. location = currentFrame.targetPosition;
  517. }
  518. }
  519. if (currentFrame.duration > 0) movements.set(currentFrame, 0);
  520. if (getStamina() <= getMaxStamina() - 0.0025f)
  521. {
  522. if (getThirst() > 0 && getHunger() > 0)
  523. {
  524. setStamina(getStamina() + 0.0025f);
  525. setHunger(getHunger() - 0.0005f);
  526. setThirst(getThirst() - 0.0015f);
  527. }
  528. }
  529. }
  530. else
  531. {
  532. if (getStamina() <= getMaxStamina() - 0.005f)
  533. {
  534. if (getThirst() > 0 && getHunger() > 0)
  535. {
  536. setStamina(getStamina() + 0.005f);
  537. setHunger(getHunger() - 0.001f);
  538. setThirst(getThirst() - 0.003f);
  539. }
  540. }
  541. }
  542. }
  543. time.messungStart();
  544. }
  545. void Entity::api(Framework::StreamReader* zRequest,
  546. NetworkMessage* zResponse,
  547. Entity* zSource)
  548. {
  549. char type;
  550. zRequest->lese(&type, 1);
  551. switch (type)
  552. {
  553. case 0: // request status bar state
  554. {
  555. char len;
  556. zRequest->lese(&len, 1);
  557. char* guiId = new char[(int)len + 1];
  558. zRequest->lese(guiId, len);
  559. guiId[(int)len] = 0;
  560. zResponse->addressGui(guiId);
  561. addStatusBarObserver(zSource, guiId);
  562. char* msg = new char[33];
  563. msg[0] = 0;
  564. *(float*)(msg + 1) = getMaxHP();
  565. *(float*)(msg + 5) = getCurrentHP();
  566. *(float*)(msg + 9) = getMaxStamina();
  567. *(float*)(msg + 13) = getStamina();
  568. *(float*)(msg + 17) = getMaxHunger();
  569. *(float*)(msg + 21) = getHunger();
  570. *(float*)(msg + 25) = getMaxThirst();
  571. *(float*)(msg + 29) = getThirst();
  572. zResponse->setMessage(msg, 33);
  573. delete[] guiId;
  574. break;
  575. }
  576. case 1: // remove status bar observer
  577. {
  578. char len;
  579. zRequest->lese(&len, 1);
  580. char* guiId = new char[(int)len + 1];
  581. zRequest->lese(guiId, len);
  582. guiId[(int)len] = 0;
  583. removeStatusBarObserver(zSource, guiId);
  584. delete[] guiId;
  585. break;
  586. }
  587. }
  588. }
  589. void Entity::onFall(float collisionSpeed)
  590. {
  591. if (collisionSpeed > 5)
  592. {
  593. // TODO: take damage
  594. }
  595. }
  596. void Entity::setChatSecurityLevel(int level)
  597. {
  598. chatSecurityLevel = level;
  599. }
  600. void Entity::setPosition(Framework::Vec3<float> pos)
  601. {
  602. location = pos;
  603. }
  604. void Entity::setHP(float hp)
  605. {
  606. currentHP = MIN(MAX(hp, 0), maxHP);
  607. NetworkMessage* msg = new NetworkMessage();
  608. char* message = new char[9];
  609. message[0] = 1;
  610. *(float*)(message + 1) = getMaxHP();
  611. *(float*)(message + 5) = getCurrentHP();
  612. msg->setMessage(message, 9);
  613. notifyStatusBarObservers(msg);
  614. }
  615. void Entity::setStamina(float stamina)
  616. {
  617. this->stamina = MIN(MAX(stamina, 0), maxStamina);
  618. NetworkMessage* msg = new NetworkMessage();
  619. char* message = new char[9];
  620. message[0] = 2;
  621. *(float*)(message + 1) = getMaxStamina();
  622. *(float*)(message + 5) = getStamina();
  623. msg->setMessage(message, 9);
  624. notifyStatusBarObservers(msg);
  625. }
  626. void Entity::setHunger(float hunger)
  627. {
  628. this->hunger = MIN(MAX(hunger, 0), maxHunger);
  629. NetworkMessage* msg = new NetworkMessage();
  630. char* message = new char[9];
  631. message[0] = 3;
  632. *(float*)(message + 1) = getMaxHunger();
  633. *(float*)(message + 5) = getHunger();
  634. msg->setMessage(message, 9);
  635. notifyStatusBarObservers(msg);
  636. }
  637. void Entity::setThirst(float thirst)
  638. {
  639. this->thirst = MIN(MAX(thirst, 0), maxThirst);
  640. NetworkMessage* msg = new NetworkMessage();
  641. char* message = new char[9];
  642. message[0] = 4;
  643. *(float*)(message + 1) = getMaxThirst();
  644. *(float*)(message + 5) = getThirst();
  645. msg->setMessage(message, 9);
  646. notifyStatusBarObservers(msg);
  647. }
  648. float Entity::getMaxHP() const
  649. {
  650. return maxHP;
  651. }
  652. float Entity::getCurrentHP() const
  653. {
  654. return currentHP;
  655. }
  656. float Entity::getStamina() const
  657. {
  658. return stamina;
  659. }
  660. float Entity::getMaxStamina() const
  661. {
  662. return maxStamina;
  663. }
  664. float Entity::getHunger() const
  665. {
  666. return hunger;
  667. }
  668. float Entity::getMaxHunger() const
  669. {
  670. return maxHunger;
  671. }
  672. float Entity::getThirst() const
  673. {
  674. return thirst;
  675. }
  676. float Entity::getMaxThirst() const
  677. {
  678. return maxThirst;
  679. }
  680. Framework::Vec3<float> Entity::getSpeed() const
  681. {
  682. return speed;
  683. }
  684. Framework::Vec3<float> Entity::getFaceDir() const
  685. {
  686. return faceDir;
  687. }
  688. Framework::Vec3<float> Entity::getPosition() const
  689. {
  690. return location;
  691. }
  692. float Entity::getGravityMultiplier() const
  693. {
  694. return gravityMultiplier;
  695. }
  696. bool Entity::isRemoved() const
  697. {
  698. return removed;
  699. }
  700. const EntityType* Entity::zType() const
  701. {
  702. return StaticRegistry<EntityType>::INSTANCE.zElement(typeId);
  703. }
  704. const ActionTarget* Entity::zTarget() const
  705. {
  706. return target;
  707. }
  708. int Entity::getId() const
  709. {
  710. return id;
  711. }
  712. bool Entity::hasDefaultModel() const
  713. {
  714. return 1;
  715. }
  716. ModelInfo Entity::getSpecialModel() const
  717. {
  718. return ModelInfo("", "", 0);
  719. }
  720. float Entity::getMaxSpeed() const
  721. {
  722. return maxMovementSpeed;
  723. }
  724. bool Entity::isMoving() const
  725. {
  726. return movements.getEintragAnzahl() > 0;
  727. }
  728. int Entity::getChatSecurityLevel() const
  729. {
  730. return chatSecurityLevel;
  731. }