Clone of UAS2 @ https://github.com/drudgedance/uas2

Object.cpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file Objects.cpp
  19. * Implements general functionality for all objects.
  20. * All object types inherit from this class.
  21. */
  22. #include "Client.h"
  23. #include "DatFile.h"
  24. #include "Object.h"
  25. #include "WorldManager.h"
  26. #include <algorithm>
  27. void cObject::SetLocation( double dNS, double dEW )
  28. {
  29. DWORD dwNewLandBlock;
  30. m_Location.m_flX = ( dEW * 10.0f + 1020.0f ) * 24.0f;
  31. m_Location.m_flY = ( dNS * 10.0f - 1020.0f ) * 24.0f;
  32. m_Location.m_flZ = 500.0f;
  33. dwNewLandBlock = ( (BYTE) ((((DWORD)m_Location.m_flX % 192) / 24.0f) * 8.0f) +
  34. ( ((DWORD)m_Location.m_flY % 192) / 24) ) |
  35. ( (0x00) << 8) |
  36. ( (BYTE) (m_Location.m_flY / 192.0f) << 16) |
  37. ( (BYTE) (m_Location.m_flX / 192.0f) << 24);
  38. dwNewLandBlock -= 0x00010000;
  39. m_Location.m_flX = (float)((int) m_Location.m_flX % 192);
  40. m_Location.m_flY = (float)((int) m_Location.m_flY % 192);
  41. m_Location.m_dwLandBlock = dwNewLandBlock;
  42. }
  43. void cObject::ReSpawn( cObject *pcObject )
  44. {
  45. }
  46. cMessage cObject::Animation( WORD wAnim, float flPlaySpeed )
  47. {
  48. cMessage cAnim;
  49. WORD wAnimPart2;
  50. static BYTE Canimation[] = {
  51. 0x4C, 0xF7, 0x00, 0x00, 0x56, 0x1F, 0x05, 0x50, 0x3C, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
  52. 0x00, 0x00, 0x3D, 0x00, 0x80, 0xF0, 0xD0, 0x03, 0x7C, 0x00, 0x01, 0x00, 0xCA, 0x3F, 0x00, 0x00,//0x00, 0x00, 0x80, 0x3F,
  53. };
  54. ++m_wCurAnim;
  55. CopyMemory( &Canimation[04], &m_dwGUID, 4 );
  56. CopyMemory( &Canimation[8], &m_wNumLogins, 2 );
  57. CopyMemory( &Canimation[10], &m_wCurAnim, 2 );
  58. CopyMemory( &Canimation[12], &++m_wMeleeSequence, 2 );
  59. CopyMemory( &Canimation[24], &wAnim, 2 );
  60. CopyMemory( &Canimation[28], &flPlaySpeed, 4 );
  61. wAnimPart2 = m_wCurAnim - 6;
  62. CopyMemory( &Canimation[26], &wAnimPart2, 2 );
  63. cAnim.CannedData( Canimation, sizeof( Canimation ) );
  64. return cAnim;
  65. }
  66. cMessage cObject::Animation( WORD wAnim, float flPlaySpeed, BYTE bActivity )
  67. {
  68. cMessage cAnim;
  69. WORD wAnimPart2;
  70. static BYTE Canimation[] = {
  71. 0x4C, 0xF7, 0x00, 0x00, 0x56, 0x1F, 0x05, 0x50, 0x3C, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
  72. 0x00, 0x00, 0x3D, 0x00, 0x80, 0xF0, 0xD0, 0x03, 0x7C, 0x00, 0x01, 0x00, 0xCA, 0x3F, 0x00, 0x00,//0x00, 0x00, 0x80, 0x3F,
  73. };
  74. ++m_wCurAnim;
  75. CopyMemory( &Canimation[04], &m_dwGUID, 4 );
  76. CopyMemory( &Canimation[8], &m_wNumLogins, 2 );
  77. CopyMemory( &Canimation[10], &m_wCurAnim, 2 );
  78. CopyMemory( &Canimation[12], &++m_wMeleeSequence, 2 );
  79. CopyMemory( &Canimation[24], &wAnim, 2 );
  80. CopyMemory( &Canimation[28], &flPlaySpeed, 4 );
  81. wAnimPart2 = m_wCurAnim - 6;
  82. CopyMemory( &Canimation[26], &wAnimPart2, 2 );
  83. cAnim.CannedData( Canimation, sizeof( Canimation ) );
  84. return cAnim;
  85. }
  86. void cObject::Attack(cClient *pcAttacker, float flDamageSlider, DWORD F7B0Sequence )
  87. {
  88. }
  89. void cObject::SpellAttack(cClient *pcAttacker, cObject *pcWarSpell, DWORD F7B0Sequence )
  90. {
  91. }
  92. cMessage cObject::RemoveObj( DWORD dwGUID )
  93. {
  94. cMessage cmRemove;
  95. cmRemove << 0xF747L << dwGUID << 0x0L ;
  96. return cmRemove;
  97. }
  98. cMessage cObject::AdjustBar( DWORD dwGUID, DWORD F7B0Sequence )
  99. {
  100. cMessage cmHealth;
  101. cmHealth << 0xF7B0L << dwGUID << F7B0Sequence << 0x01C0L << m_dwGUID << 1.0f;
  102. return cmHealth;
  103. }
  104. cMessage cObject::LocationPacket( )
  105. {
  106. WORD wInvSeq = (WORD(m_bInventorySequence) * 5) - 1;
  107. cMessage cmPacket;
  108. cmPacket << 0xF748L << m_dwGUID << 0x34L << m_Location.m_dwLandBlock << m_Location.m_flX << m_Location.m_flY
  109. << m_Location.m_flZ << m_Location.m_flA << m_Location.m_flB << m_wNumLogins << WORD( wInvSeq ) << WORD( ++m_wPositionSequence ) << WORD( 0 );
  110. return cmPacket;
  111. }
  112. cMessage cObject::CombatAnimation( DWORD dwTarget, WORD wAttackAnim )
  113. {
  114. cMessage cmRet;
  115. unsigned char Canimation [] = {
  116. 0x4C, 0xF7, 0x00, 0x00,
  117. 0xE6, 0xD2, 0x09, 0x50, // object
  118. 0x3C, 0x00, 0x18, 0x00, // numLogins, sequence
  119. 0x03, 0x00, 0x00, 0x00, // numAnims, activity
  120. 0x00, 0x01, 0x00, 0x00, // Anim type, type flag
  121. 0xC1, 0x80, 0x99, 0xB1,
  122. 0x63, 0x00, 0x00, 0x00,
  123. 0x60, 0x00, 0x60, 0x00,
  124. 0x01, 0x00, 0xE4, 0x38,
  125. 0x8E, 0x3F, 0x00, 0x00,
  126. 0x20, 0x8B, 0x99, 0xB1, // dwTarget
  127. };
  128. CopyMemory(&Canimation[4],&m_dwGUID,4);
  129. CopyMemory( &Canimation[8], &m_wNumLogins, 2 );
  130. m_wCurAnim++;
  131. CopyMemory(&Canimation[10],&m_wCurAnim,2);
  132. m_wMeleeSequence++;
  133. CopyMemory(&Canimation[12],&m_wMeleeSequence,2);
  134. CopyMemory(&Canimation[0x28],&dwTarget,4);
  135. CopyMemory(&Canimation[0x20],&m_wCurAnim,2);
  136. CopyMemory(&Canimation[24],&wAttackAnim,2);
  137. cmRet.pasteData(Canimation,sizeof(Canimation));
  138. return cmRet;
  139. }
  140. cMessage cObject::ChangeCombatMode( bool fMode)
  141. {
  142. cMessage cmReturn;
  143. cmReturn << 0xFF00;
  144. return cmReturn;
  145. }
  146. /**
  147. * Handles the message sent for the creation of an object in the world.
  148. *
  149. * This function is called whenever an object should be created in the world for a client.
  150. * @return cMessage - Returns a Create Object (0x0000F745) server message.
  151. */
  152. cMessage cAbiotic::CreatePacket( )
  153. {
  154. cMessage cmCreate;
  155. cmCreate << 0xF745L << m_dwGUID << BYTE( 0x11 ) << BYTE( 0 ) << BYTE( 0 ) << BYTE( 0 );
  156. DWORD dwFlags = 0x00001881;
  157. if ( !m_fIsOwned )
  158. dwFlags |= 0x8000;
  159. cmCreate << dwFlags;
  160. if( m_fIsSolid )
  161. cmCreate << DWORD( 0x00000008 );
  162. else
  163. cmCreate << DWORD( 0x00010044 );
  164. if ( !m_fIsOwned )
  165. cmCreate.CannedData( (BYTE *)&m_Location, sizeof( cLocation ) );
  166. cmCreate << 0x20000014L << 0x3400002BL;
  167. DWORD dwModel = 0x02000000L + m_dwModel;
  168. cmCreate << dwModel << m_flScale;
  169. // SeaGreens
  170. WORD wUnkFlag2 = 0x1;
  171. WORD wUnkFlag3 = 0x1;
  172. WORD wUnkFlag4 = 0;
  173. WORD wUnkFlag6 = 0;
  174. WORD wUnkFlag7 = 0;
  175. WORD wUnkFlag8 = 0;
  176. WORD wUnkFlag10 = 0;
  177. cmCreate << m_wPositionSequence
  178. << wUnkFlag2
  179. << wUnkFlag3
  180. << wUnkFlag4
  181. << m_wNumPortals
  182. << wUnkFlag6
  183. << wUnkFlag7
  184. << wUnkFlag8
  185. << m_wNumLogins
  186. << wUnkFlag10;
  187. DWORD dwFlags2 = 0x00000218;
  188. if ( m_fIsOwned )
  189. dwFlags2 |= 0x4000;
  190. cmCreate << dwFlags2 << m_strName.c_str( ) << WORD( 0x013A ) << WORD( m_wIcon );
  191. DWORD dwObjectFlags1 = 0x01;
  192. cmCreate << dwObjectFlags1;
  193. DWORD dwObjectFlags2 = 0x00;
  194. if ( m_fSelectable ) dwObjectFlags2 |= 0x10;
  195. else dwObjectFlags2 |= 0x80;
  196. if ( !m_fEquippable ) dwObjectFlags2 |= 0x04; // Uncommented Blackstaff 04/13/02
  197. else dwObjectFlags2 |= 0x00;
  198. //dwObjectFlags2 |= 0x10000 | 0x20000 | 0x40000;
  199. cmCreate << dwObjectFlags2 << m_dwValue << m_dwValue;// << 0x00100000 << 0x00100000 << 0x00100000;
  200. BYTE bEquipType = 0x01;
  201. cmCreate << bEquipType;
  202. if ( m_fIsOwned )
  203. cmCreate << m_dwContainer;
  204. return cmCreate;
  205. }
  206. /**
  207. * Handles the assessment of objects.
  208. *
  209. * This function is called whenever an objects is assessed by a client.
  210. * Returns a Game Event (0x0000F7B0) server message of type Identify Object (0x000000C9).
  211. */
  212. void cAbiotic::Assess( cClient *pcAssesser )
  213. {
  214. cMessage cmAssess;
  215. cmAssess << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID() << ++pcAssesser->m_dwF7B0Sequence << 0xC9L;
  216. cmAssess << m_dwGUID << 0x00000800L << 1L << 1L << m_dwValue << m_dwWeight;
  217. pcAssesser->AddPacket( WORLD_SERVER, cmAssess, 4 );
  218. cMessage cmActionComplete;
  219. cmActionComplete << 0xF7B0L << pcAssesser->m_pcAvatar->GetGUID( ) << ++pcAssesser->m_dwF7B0Sequence << 0x01C7L << 0L << 0L;
  220. pcAssesser->AddPacket(WORLD_SERVER,cmActionComplete,4);
  221. }
  222. DWORD cObject::CalculateDamage(int strength, float flPower, float flResistance )
  223. {
  224. srand( timeGetTime( ) );
  225. int iRand = rand( );
  226. iRand = (iRand > 6400) ? iRand % 6400 : iRand;
  227. iRand = (iRand < 1600) ? 1600 + iRand : iRand;
  228. double dLuckFactor = 3200.0f / (double)iRand;
  229. // MaxDamage = (Strength * 0.2 * (flPower + 1.15)) / (flResistance + 5.0)
  230. double dMaxDamage = (double)((strength * 0.2f) * ((flPower + .25f) * 4)) / (double)(flResistance + 7.5f);
  231. return dMaxDamage * dLuckFactor + (rand( ) % 2);
  232. }
  233. cMessage cObject::TurnToTarget( float flHeading, DWORD dwTargetGUID )
  234. {
  235. cMessage cmTurnToTarget;
  236. cmTurnToTarget << 0xF74CL
  237. << m_dwGUID
  238. << m_wNumLogins
  239. << ++m_wCurAnim
  240. << ++m_wMeleeSequence
  241. << WORD(0x0000)
  242. << BYTE(0x08)
  243. << BYTE(0x00)
  244. << WORD(0x003D)
  245. << dwTargetGUID
  246. << flHeading
  247. << 0x1139EE0F
  248. << 1.0f
  249. << 0x00000000;
  250. return cmTurnToTarget;
  251. }
  252. float cObject::GetRange( DWORD dwTargetLandblock, float flTarX, float flTarY, float flTarZ )
  253. {
  254. float nsCoord,ewCoord;
  255. float nsTarCoord,ewTarCoord;
  256. float flRange;
  257. lb LocLB, TarLB;
  258. CopyMemory( &LocLB,&m_Location.m_dwLandBlock , 4 );
  259. CopyMemory( &TarLB,&dwTargetLandblock , 4 );
  260. nsCoord = ( ( ( ( LocLB.bLo + 1 ) * 8 ) + ( m_Location.m_flY / 24 ) ) - 1027.5 )/10;
  261. ewCoord = ( ( ( ( LocLB.bHi + 1 ) * 8 ) + ( m_Location.m_flX / 24 ) ) - 1027.5 )/10;
  262. nsTarCoord = ( ( ( ( TarLB.bLo + 1 ) * 8 ) + ( flTarY / 24 ) ) - 1027.5 )/10;
  263. ewTarCoord = ( ( ( ( TarLB.bHi + 1 ) * 8 ) + ( flTarX / 24 ) ) - 1027.5 )/10;
  264. flRange = sqrt(pow(nsTarCoord - nsCoord,2) + pow(ewTarCoord - ewCoord,2))*10;
  265. return flRange;
  266. }
  267. float cObject::GetHeadingTarget( DWORD dwTargetLandblock, float flTarX, float flTarY, float flTarZ )
  268. {
  269. float nsCoord,ewCoord;
  270. float nsTarCoord,ewTarCoord;
  271. float flHeading;
  272. float intRange;
  273. lb LocLB, TarLB;
  274. flHeading = 0.0f;
  275. CopyMemory( &LocLB,&m_Location.m_dwLandBlock , 4 );
  276. CopyMemory( &TarLB,&dwTargetLandblock , 4 );
  277. /*
  278. nsCoord = ( ( ( ( LocLB.bLo + 1 ) * 8 ) + ( flY / 24 ) ) - 1027.5 )/10;
  279. ewCoord = ( ( ( ( LocLB.bHi + 1 ) * 8 ) + ( flX / 24 ) ) - 1027.5 )/10;
  280. nsTarCoord = ( ( ( ( TarLB.bLo + 1 ) * 8 ) + ( flTarY / 24 ) ) - 1027.5 )/10;
  281. ewTarCoord = ( ( ( ( TarLB.bHi + 1 ) * 8 ) + ( flTarX / 24 ) ) - 1027.5 )/10;
  282. */
  283. nsCoord = (((((m_Location.m_dwLandBlock & 0x00FF0000) / 0x0010000) & 0xFF) + 1) * 8) + static_cast<float>(m_Location.m_flY / 24) - 1027.5;
  284. ewCoord = (((((m_Location.m_dwLandBlock & 0xFF000000) / 0x1000000) & 0xFF) + 1) * 8) + static_cast<float>(m_Location.m_flX / 24) - 1027.5;
  285. nsTarCoord = (((((dwTargetLandblock & 0x00FF0000) / 0x0010000) & 0xFF) + 1) * 8) + static_cast<float>(flTarY / 24) - 1027.5;
  286. ewTarCoord = (((((dwTargetLandblock & 0xFF000000) / 0x1000000) & 0xFF) + 1) * 8) + static_cast<float>(flTarX / 24) - 1027.5;
  287. intRange = sqrt(pow(nsTarCoord - nsCoord,2) + pow(ewTarCoord - ewCoord,2));
  288. if(intRange > 0)
  289. {
  290. if(nsTarCoord - nsCoord < 0 )
  291. {
  292. flHeading = acos((ewTarCoord - ewCoord) / intRange) * 57.2957796;
  293. }
  294. else
  295. {
  296. flHeading = acos(-(ewTarCoord - ewCoord) / intRange) * 57.2957796 + 180;
  297. }
  298. }
  299. return flHeading + 90;
  300. }
  301. cMessage cObject::MoveToTarget( cClient *pcWho )
  302. {
  303. // pcWho is the target client
  304. cMessage cmMoveToTarget;
  305. float flHeadingTarget;
  306. DWORD dwFlags;
  307. dwFlags = 0x1279EFF0;
  308. flHeadingTarget = GetHeadingTarget( pcWho->m_pcAvatar->m_Location.m_dwLandBlock,pcWho->m_pcAvatar->m_Location.m_flX,pcWho->m_pcAvatar->m_Location.m_flY,pcWho->m_pcAvatar->m_Location.m_flZ);
  309. // Positional Info only
  310. cmMoveToTarget << 0xF74CL // dword 1
  311. << m_dwGUID // dword 2
  312. << m_wNumLogins // word
  313. << ++m_wCurAnim // + word = dword 3
  314. << ++m_wMeleeSequence // word
  315. << WORD(0x0000) // + word = dword 4
  316. << BYTE(0x06) // byte
  317. << BYTE(0x00) // +byte
  318. << WORD(0x003E); // +word = dword 5
  319. // Who/Where we are Moving to
  320. cmMoveToTarget << pcWho->m_pcAvatar->GetGUID( ) // dword 6
  321. << m_Location.m_dwLandBlock//pcWho->m_pcAvatar->m_Location.m_dwLandBlock // dword 7
  322. << m_Location.m_flX//pcWho->m_pcAvatar->m_Location.m_flX // dword 8
  323. << m_Location.m_flY//pcWho->m_pcAvatar->m_Location.m_flY // dword 9
  324. << m_Location.m_flZ//pcWho->m_pcAvatar->m_Location.m_flZ // dword 10
  325. << dwFlags // dword 11 - does not change
  326. << flHeadingTarget // dowrd 12
  327. << 0.1f // dword 13 - does not change //pcWho->m_pcAvatar->m_Location.m_flC
  328. << 15.0f // dword 14 - Run speed value
  329. << 1.5f // dword 15
  330. << 15.0f // dword 16
  331. << 0x0L // dword 17
  332. << 1.8201754f; // dword 18
  333. //SetLocation(&pcWho->m_pcAvatar->m_Location);
  334. return cmMoveToTarget;
  335. }
  336. //////////////////////
  337. cMessage cObject::MoveTarget( cClient *pcWho )
  338. {
  339. // pcWho is the target client
  340. cMessage cmMoveToTarget;
  341. float flHeadingTarget;
  342. DWORD dwFlags;
  343. dwFlags = 0x1279EFF0;
  344. flHeadingTarget = GetHeadingTarget( pcWho->m_pcAvatar->m_Location.m_dwLandBlock,pcWho->m_pcAvatar->m_Location.m_flX,pcWho->m_pcAvatar->m_Location.m_flY,pcWho->m_pcAvatar->m_Location.m_flZ);
  345. cmMoveToTarget << 0xF74CL
  346. << m_dwGUID
  347. << m_wNumLogins
  348. << ++m_wCurAnim
  349. << ++m_wMeleeSequence
  350. << WORD(0x0000)
  351. << BYTE(0x06)
  352. << BYTE(0x00)
  353. << WORD(0x003E);
  354. cmMoveToTarget << pcWho->m_pcAvatar->GetGUID( )
  355. << pcWho->m_pcAvatar->m_Location.m_dwLandBlock
  356. << pcWho->m_pcAvatar->m_Location.m_flX
  357. << pcWho->m_pcAvatar->m_Location.m_flY
  358. << pcWho->m_pcAvatar->m_Location.m_flZ
  359. << dwFlags
  360. << 0.0f
  361. << 0.1f
  362. << 75.0f
  363. << 1.0f
  364. << 15.0f
  365. << flHeadingTarget
  366. << 1.8201754f;
  367. SetLocation(&pcWho->m_pcAvatar->m_Location);
  368. return cmMoveToTarget;
  369. }
  370. ////////////////////////////////////////////
  371. // Never Use this function
  372. ////////////////////////////////////////////
  373. cMessage cObject::ReturnToSpawn( )
  374. {
  375. cMessage cmReturnToSpawn;
  376. float flHeadingTarget = 0.0f;
  377. DWORD dwFlags;
  378. float flDistance = 1.0f;
  379. cLocation tempLoc;
  380. dwFlags = 0x1291EE0F;
  381. flHeadingTarget = GetHeadingTarget( m_SpawnLoc.m_dwLandBlock,m_SpawnLoc.m_flX,m_SpawnLoc.m_flY,m_SpawnLoc.m_flZ);
  382. flDistance = GetRange( m_SpawnLoc.m_dwLandBlock, m_SpawnLoc.m_flX, m_SpawnLoc.m_flY, m_SpawnLoc.m_flZ );
  383. tempLoc = EstimateLoc(flHeadingTarget,10,flDistance,2.0f);
  384. cmReturnToSpawn << 0xF74CL
  385. << m_dwGUID
  386. << m_wNumLogins
  387. << ++m_wCurAnim
  388. << ++m_wMeleeSequence
  389. << WORD(0x0000)
  390. << BYTE(0x07)
  391. << BYTE(0x00)
  392. << WORD(0x003D);
  393. // Animation Type 0x07
  394. cmReturnToSpawn << tempLoc.m_dwLandBlock
  395. << tempLoc.m_flX
  396. << tempLoc.m_flY
  397. << tempLoc.m_flZ
  398. << dwFlags
  399. << 0.0f//flHeadingTarget
  400. << 1.0f
  401. << DWORD(0x7F7FFFFF)
  402. << 1.0f
  403. << 5.0f
  404. << flHeadingTarget
  405. << 1.6346154f;
  406. return cmReturnToSpawn;
  407. }
  408. ///////////////////////////////////////////////////////////////////////////
  409. // CoordLoc - Converts NS/EW map coordinates into Landblock Data form
  410. //
  411. //
  412. ///////////////////////////////////////////////////////////////////////////
  413. cLocation cObject::CoordLoc( float dNS, float dEW )
  414. {
  415. cLocation Loc;
  416. char tmpLB[5];
  417. struct{
  418. BYTE bHi;
  419. BYTE bLo;
  420. BYTE bOO;
  421. BYTE bLow;
  422. } lb;
  423. Loc.m_flX = ((dEW * 10.0f) + 1027.5f ) * 24.0f;
  424. Loc.m_flY = ((dNS * 10.0f) + 1027.5f ) * 24.0f;
  425. Loc.m_flZ = 0.0f;//500.0f;
  426. Loc.m_flX = ( float )( ( DWORD ) Loc.m_flX % 192);
  427. Loc.m_flY = ( float )( ( DWORD ) Loc.m_flY % 192);
  428. sprintf(tmpLB," \r\n");
  429. lb.bHi = ((((dEW*10)+1027.5)-(Loc.m_flX/24))/8);
  430. lb.bLo = ((((dNS*10)+1027.5)-(Loc.m_flY/24))/8)-1;
  431. lb.bOO = 0x00; // Indicates on Surface map 0x01 indicates in Dungeon
  432. lb.bLow = ((Loc.m_flX/24)*8) + (Loc.m_flY/24);
  433. CopyMemory( &tmpLB[3], &lb.bHi, 1 );
  434. CopyMemory( &tmpLB[2], &lb.bLo, 1 );
  435. CopyMemory( &tmpLB[1], &lb.bOO, 1 );
  436. CopyMemory( &tmpLB[0], &lb.bLow, 1 );
  437. CopyMemory( &Loc.m_dwLandBlock, &tmpLB, 4 );
  438. return Loc;
  439. }
  440. cLocation cObject::EstimateLoc( float flHeading, float flSpeed, float flDistToTarget, float flTime )
  441. {
  442. cLocation Loc;
  443. lb LocLB,NewLB;
  444. float flEndX = 1.0f;
  445. float flEndY = 1.0f;
  446. float flRadHeading = 0.0f;
  447. float flDistance = 1.0f;
  448. float dNS, dEW;
  449. if(flSpeed < 10.0f)
  450. {
  451. flSpeed = 10.0f;
  452. }
  453. flDistance = (flSpeed*flTime);
  454. if( flDistToTarget < 0.5f)
  455. {
  456. flDistance = flDistToTarget/4;
  457. }
  458. flRadHeading = ((flHeading * 3.14159265359)/180);
  459. CopyMemory( &LocLB,&m_Location.m_dwLandBlock , 4 );
  460. //dNS2 = ( ( ( ( LocLB.bLo + 1 ) * 8 ) + ( flY / 24 ) ) - 1027.5 )/10;
  461. //dEW2 = ( ( ( ( LocLB.bHi + 1 ) * 8 ) + ( flX / 24 ) ) - 1027.5 )/10;
  462. flEndX = (float)(flDistance * sin(flRadHeading));
  463. flEndY = (float)(flDistance * cos(flRadHeading));
  464. dNS = (float)(m_Location.m_flY + flEndY);
  465. dEW = (float)(m_Location.m_flX + flEndX);
  466. // set Landblock HI (EW movement)
  467. if(dNS > 193)
  468. {
  469. NewLB.bLo = LocLB.bLo + 1;
  470. dNS = dNS - 193;
  471. }
  472. else if (dNS < 0)
  473. {
  474. NewLB.bLo = LocLB.bLo - 1;
  475. dNS = dNS + 193;
  476. }
  477. else
  478. {
  479. NewLB.bLo = LocLB.bLo;
  480. }
  481. // Set Landblock LO (NS movement)
  482. if(dEW > 193)
  483. {
  484. NewLB.bHi = LocLB.bHi + 1;
  485. dEW = dEW - 193;
  486. }
  487. else if(dEW < 0)
  488. {
  489. NewLB.bHi = LocLB.bHi - 1;
  490. dEW = dEW + 193;
  491. }
  492. else
  493. {
  494. NewLB.bHi = LocLB.bHi;
  495. }
  496. Loc.m_flX = dEW;
  497. Loc.m_flY = dNS;
  498. Loc.m_flZ = 0.0f;
  499. NewLB.bOO = 0x00; // Indicates on Surface map 0x01 indicates in Dungeon
  500. NewLB.bLow = ((dEW/24)*8) + (dNS/24);
  501. CopyMemory( &Loc.m_dwLandBlock,&NewLB , 4 );
  502. return Loc;
  503. }
  504. cMessage cObject::SetPosition()
  505. {
  506. cMessage cmSetPosition;
  507. DWORD dwFlags = 0x34L;
  508. cmSetPosition << 0xF748L
  509. << m_dwGUID
  510. << 0x34L;
  511. cmSetPosition << m_Location.m_dwLandBlock
  512. << m_Location.m_flX
  513. << m_Location.m_flY
  514. << m_Location.m_flZ
  515. << m_Location.m_flA
  516. << m_Location.m_flB
  517. << m_Location.m_flC
  518. << m_Location.m_flW;
  519. return cmSetPosition;
  520. }