PlayerEntity.es 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. /*
  13. * Player entity.
  14. */
  15. 4
  16. %{
  17. #include "StdH.h"
  18. #include <Engine/Entities/InternalClasses.h>
  19. #include <Engine/Base/Stream.h>
  20. #include <Engine/Base/CRC.h>
  21. %}
  22. class export CPlayerEntity : CMovableModelEntity {
  23. name "PlayerEntity";
  24. thumbnail "";
  25. features "AbstractBaseClass";
  26. properties:
  27. 1 FLOAT en_tmPing = 0.0f, // ping value in seconds (determined by derived class and distributed by the engine)
  28. {
  29. CPlayerCharacter en_pcCharacter; // character of the player
  30. CPlacement3D en_plViewpoint; // placement of view point relative to the entity
  31. CPlacement3D en_plLastViewpoint; // last view point (used for lerping)
  32. }
  33. components:
  34. functions:
  35. /* Get name of this player. */
  36. export CTString GetPlayerName(void)
  37. {
  38. return en_pcCharacter.GetNameForPrinting();
  39. }
  40. export const CTString &GetName(void) const
  41. {
  42. return en_pcCharacter.GetName();
  43. }
  44. /* Get index of this player in the game. */
  45. export INDEX GetMyPlayerIndex(void)
  46. {
  47. CEntity *penMe = this;
  48. if (IsPredictor()) {
  49. penMe = GetPredicted();
  50. }
  51. for (INDEX iPlayer=0; iPlayer<GetMaxPlayers(); iPlayer++) {
  52. // if this is ME (this)
  53. if (GetPlayerEntity(iPlayer)==penMe) {
  54. return iPlayer;
  55. }
  56. }
  57. // must find my self
  58. return 15; // if not found, still return a relatively logical value
  59. }
  60. /* Calculate physics for moving. */
  61. export void DoMoving(void) // override from CMovableEntity
  62. {
  63. CMovableModelEntity::DoMoving();
  64. }
  65. /* Copy entity from another entity of same class. */
  66. export void Copy(CEntity &enOther, ULONG ulFlags)
  67. {
  68. CMovableModelEntity::Copy(enOther, ulFlags);
  69. CPlayerEntity *ppenOther = (CPlayerEntity *)(&enOther);
  70. en_pcCharacter = ppenOther->en_pcCharacter;
  71. en_plViewpoint = ppenOther->en_plViewpoint;
  72. en_plLastViewpoint = ppenOther->en_plLastViewpoint;
  73. }
  74. /* Copy entity from another entity of same class. */
  75. /*CPlayerEntity &operator=(CPlayerEntity &enOther)
  76. {
  77. CMovableModelEntity::operator=(enOther);
  78. en_pcCharacter = enOther.en_pcCharacter;
  79. en_plViewpoint = enOther.en_plViewpoint;
  80. return *this;
  81. }*/
  82. /* Read from stream. */
  83. export void Read_t( CTStream *istr) // throw char *
  84. {
  85. CMovableModelEntity::Read_t(istr);
  86. (*istr)>>en_pcCharacter>>en_plViewpoint;
  87. en_plLastViewpoint = en_plViewpoint;
  88. }
  89. /* Write to stream. */
  90. export void Write_t( CTStream *ostr) // throw char *
  91. {
  92. CMovableModelEntity::Write_t(ostr);
  93. (*ostr)<<en_pcCharacter<<en_plViewpoint;
  94. }
  95. // Apply the action packet to the entity movement.
  96. export virtual void ApplyAction(const CPlayerAction &pa, FLOAT tmLatency) {};
  97. // Called when player is disconnected
  98. export virtual void Disconnect(void) {};
  99. // Called when player character is changed
  100. export virtual void CharacterChanged(const CPlayerCharacter &pcNew) { en_pcCharacter = pcNew; };
  101. // provide info for GameAgent enumeration
  102. export virtual void GetGameAgentPlayerInfo( INDEX iPlayer, CTString &strOut) { };
  103. // provide info for MSLegacy enumeration
  104. export virtual void GetMSLegacyPlayerInf( INDEX iPlayer, CTString &strOut) { };
  105. // create a checksum value for sync-check
  106. export void ChecksumForSync(ULONG &ulCRC, INDEX iExtensiveSyncCheck)
  107. {
  108. CMovableModelEntity::ChecksumForSync(ulCRC, iExtensiveSyncCheck);
  109. CRC_AddBlock(ulCRC, en_pcCharacter.pc_aubGUID, sizeof(en_pcCharacter.pc_aubGUID));
  110. CRC_AddBlock(ulCRC, en_pcCharacter.pc_aubAppearance, sizeof(en_pcCharacter.pc_aubAppearance));
  111. }
  112. // dump sync data to text file
  113. export void DumpSync_t(CTStream &strm, INDEX iExtensiveSyncCheck) // throw char *
  114. {
  115. CMovableModelEntity::DumpSync_t(strm, iExtensiveSyncCheck);
  116. strm.FPrintF_t("player: %s\n",
  117. en_pcCharacter.GetName());
  118. strm.FPrintF_t("GUID: ");
  119. {for (INDEX i=0; i<sizeof(en_pcCharacter.pc_aubGUID); i++) {
  120. strm.FPrintF_t("%02X", en_pcCharacter.pc_aubGUID[i]);
  121. }}
  122. strm.FPrintF_t("\n");
  123. strm.FPrintF_t("appearance: ");
  124. {for (INDEX i=0; i<MAX_PLAYERAPPEARANCE; i++) {
  125. strm.FPrintF_t("%02X", en_pcCharacter.pc_aubAppearance[i]);
  126. }}
  127. strm.FPrintF_t("\n");
  128. }
  129. procedures:
  130. // must have at least one procedure per class
  131. Dummy() {};
  132. };