Clone of Akilla's ac2d @ https://github.com/deregtd/AC2D

cWObject.cpp 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. #include "stdafx.h"
  2. #include "cWObject.h"
  3. #include <math.h>
  4. cWObject::cWObject()
  5. {
  6. //init all values to zero...
  7. GUID = 0;
  8. wielder = 0;
  9. m_wStance = 0x003D;
  10. location.xOffset = 0;
  11. location.yOffset = 0;
  12. location.zOffset = 0;
  13. location.wHeading = 0;
  14. location.aHeading = 0;
  15. location.bHeading = 0;
  16. location.cHeading = 0;
  17. location.landblock = 0;
  18. objectName = "";
  19. animCount = 0;
  20. unknown5 = 0;
  21. category = 0;
  22. m_fScale = 1.0f;
  23. moveCount = 0;
  24. m_bMoving = false;
  25. Velocity = cPoint3D(0,0,0);
  26. fVelocityTurn = 0;
  27. fVelocityStrafe = 0;
  28. fVelocityFB = 0;
  29. CalcPosition = cPoint3D(0,0,0);
  30. //m_fHeading = 0;
  31. m_bModelUpdate = false;
  32. m_mgModel = 0;
  33. }
  34. cWObject::~cWObject()
  35. {
  36. delete m_mgModel;
  37. }
  38. int cWObject::Draw()
  39. {
  40. if (m_mgModel)
  41. return m_mgModel->Draw();
  42. else
  43. return 0;
  44. }
  45. void cWObject::SetMoveVelocities(float fFB, float fStrafe, float fTurn)
  46. {
  47. fVelocityFB = fFB;
  48. fVelocityStrafe = fStrafe;
  49. fVelocityTurn = fTurn;
  50. m_bMoving = ((fFB != 0) || (fStrafe != 0) || (fTurn != 0));
  51. }
  52. void cWObject::UpdatePosition(float fTimeDiff)
  53. {
  54. Lock();
  55. if (m_bMoving)
  56. {
  57. CalcPosition += Velocity*fTimeDiff;
  58. //Turning...
  59. float fCurHeading = GetHeading();
  60. fCurHeading -= (float) (fVelocityTurn*(M_PI/2)*fTimeDiff);
  61. if (fCurHeading > 2*M_PI)
  62. fCurHeading -= (float) (2*M_PI);
  63. if (fCurHeading < 0)
  64. fCurHeading += (float) (2*M_PI);
  65. LoadLocationHeading(fCurHeading);
  66. //Forwards/Backwards
  67. cPoint3D tpstrafe(0,1,0);
  68. tpstrafe.RotateAround(cPoint3D(0,0,0), cPoint3D(0,0,fCurHeading));
  69. CalcPosition += tpstrafe*(fVelocityFB*fTimeDiff/240.0f);
  70. //Strafing
  71. tpstrafe.RotateAround(cPoint3D(0,0,0), cPoint3D(0,0,(float) -M_PI/2));
  72. CalcPosition += tpstrafe*(fVelocityStrafe*fTimeDiff/240.0f);
  73. CalcHeading();
  74. }
  75. if (m_bModelUpdate)
  76. {
  77. bool FirstSet = false;
  78. if (!m_mgModel)
  79. {
  80. FirstSet = true;
  81. m_mgModel = new cModelGroup();
  82. }
  83. m_mgModel->ReadModel(modelNumber, &palettes, &textures, &models);
  84. m_mgModel->SetScale((1/240.0f) * m_fScale);
  85. if (FirstSet)
  86. {
  87. if (m_mAnims.find(0x003D0003) != m_mAnims.end())
  88. {
  89. stAnimSet asTemp = m_mAnims[0x003D0003]; //idle anim?
  90. m_mgModel->SetDefaultAnim(asTemp.vAnims[0].dwAnim);
  91. }
  92. }
  93. m_bModelUpdate = false;
  94. }
  95. m_mgModel->SetTranslation(CalcPosition);
  96. m_mgModel->SetRotation(location.wHeading, location.aHeading, location.bHeading, location.cHeading);
  97. m_mgModel->UpdateAnim(fTimeDiff);
  98. Unlock();
  99. }
  100. void cWObject::PlayAnimation(WORD wAnim, WORD wStance, float fPlaySpeed, bool bSetDefault)
  101. {
  102. //fix this to cache...
  103. if (!m_mgModel)
  104. return;
  105. if (m_mAnims.find(((DWORD) wStance << 16) | wAnim) != m_mAnims.end())
  106. {
  107. stAnimSet *asTemp = &m_mAnims[((DWORD) wStance << 16) | wAnim];
  108. stAnimInfo aiTemp = asTemp->vAnims[0];
  109. if (bSetDefault)
  110. m_mgModel->SetDefaultAnim(aiTemp.dwAnim);
  111. m_mgModel->PlayAnimation(aiTemp.dwAnim, aiTemp.dwStartFrame, aiTemp.dwEndFrame, aiTemp.fPlaySpeed * fPlaySpeed);
  112. }
  113. }
  114. void cWObject::ParseF74C(cMessage * Message)
  115. {
  116. Lock();
  117. numLogins = Message->ReadWORD();
  118. WORD sequence = Message->ReadWORD();
  119. animCount = Message->ReadWORD();
  120. WORD activity = Message->ReadWORD();
  121. BYTE animation_type = Message->ReadByte();
  122. BYTE type_flags = Message->ReadByte();
  123. WORD wStance = Message->ReadWORD();
  124. // if (m_wStance != wStance)
  125. // f74csequence++;
  126. m_wStance = wStance;
  127. switch (animation_type)
  128. {
  129. case 0x00:
  130. {
  131. //general animation
  132. DWORD flags = Message->ReadDWORD();
  133. WORD wAnimToPlay = 3;
  134. bool bSetDefault = true;
  135. float fSpeed = 1.0f;
  136. m_bMoving = false;
  137. if (flags & 0x1)
  138. {
  139. WORD stance2 = Message->ReadWORD();
  140. if (m_wStance != stance2)
  141. int a = 4;
  142. }
  143. if (flags & 0x2)
  144. {
  145. //hold animation until stopped
  146. //holding out hand does this
  147. wAnimToPlay = Message->ReadWORD();
  148. }
  149. if (flags & 0x8)
  150. {
  151. //strafing
  152. wAnimToPlay = Message->ReadWORD();
  153. m_bMoving = true;
  154. }
  155. else
  156. fVelocityStrafe = 0;
  157. if (flags & 0x20)
  158. {
  159. //turning...
  160. wAnimToPlay = Message->ReadWORD();
  161. m_bMoving = true;
  162. }
  163. else
  164. fVelocityTurn = 0;
  165. if (flags & 0x4)
  166. {
  167. //movement speed (forward/backwards)
  168. fVelocityFB = Message->ReadFloat();
  169. fSpeed = fabs(fVelocityFB);
  170. fVelocityFB *= 3;
  171. m_bMoving = true;
  172. }
  173. else
  174. fVelocityFB = 0;
  175. if (flags & 0x10)
  176. {
  177. //strafe speed
  178. fVelocityStrafe = Message->ReadFloat();
  179. fSpeed = fabs(fVelocityStrafe);
  180. m_bMoving = true;
  181. }
  182. if (flags & 0x40)
  183. {
  184. //turn speed
  185. fVelocityTurn = Message->ReadFloat();
  186. fSpeed = fabs(fVelocityTurn);
  187. m_bMoving = true;
  188. }
  189. if (flags & 0x80)
  190. {
  191. //anim sequence
  192. wAnimToPlay = Message->ReadWORD();
  193. WORD sequence = Message->ReadWORD();
  194. fSpeed = Message->ReadFloat();
  195. bSetDefault = false;
  196. }
  197. if (!m_bMoving)
  198. {
  199. // fVelocityStrafe = 0;
  200. // fVelocityTurn = 0;
  201. // fVelocityFB = 0;
  202. }
  203. PlayAnimation(wAnimToPlay, m_wStance, fSpeed, bSetDefault);
  204. break;
  205. }
  206. case 0x06:
  207. {
  208. //move to object
  209. DWORD object = Message->ReadDWORD();
  210. stLocation tpLoc;
  211. memcpy(&tpLoc, Message->ReadGroup(sizeof(tpLoc)), sizeof(tpLoc));
  212. float animation_speed = Message->ReadFloat();
  213. float float_4 = Message->ReadFloat();
  214. float heading = Message->ReadFloat();
  215. DWORD unknown_value = Message->ReadDWORD();
  216. cPoint3D GoTo;
  217. GoTo.CalcFromLocation(&tpLoc);
  218. Velocity = (GoTo - CalcPosition);
  219. Velocity.Normalize();
  220. Velocity *= animation_speed/240;
  221. m_bMoving = true;
  222. break;
  223. }
  224. case 0x07:
  225. {
  226. stLocation tpLoc;
  227. memcpy(&tpLoc, Message->ReadGroup(sizeof(tpLoc)), sizeof(tpLoc));
  228. float animation_speed = Message->ReadFloat();
  229. float float_4 = Message->ReadFloat();
  230. float heading = Message->ReadFloat();
  231. DWORD unknown_value = Message->ReadDWORD();
  232. cPoint3D GoTo;
  233. GoTo.CalcFromLocation(&tpLoc);
  234. Velocity = (GoTo - CalcPosition);
  235. Velocity.Normalize();
  236. Velocity *= animation_speed/240;
  237. m_bMoving = true;
  238. break;
  239. }
  240. case 0x08:
  241. {
  242. int a = 4;
  243. break;
  244. }
  245. case 0x09:
  246. {
  247. int a = 4;
  248. break;
  249. }
  250. default:
  251. {
  252. int a = 4;
  253. break;
  254. }
  255. };
  256. //TODO: more stuff after this... check protocol and figure it all out...
  257. Message->ReadAlign();
  258. Unlock();
  259. }
  260. void cWObject::ParseF625(cMessage * Message)
  261. {
  262. Lock();
  263. Message->ReadByte(); //eleven
  264. int paletteCount = Message->ReadByte();
  265. int textureCount = Message->ReadByte();
  266. int modelCount = Message->ReadByte();
  267. palettes.clear();
  268. textures.clear();
  269. models.clear();
  270. if (paletteCount)
  271. {
  272. DWORD palflags = Message->ReadPackedDWORD();
  273. for (int i=0;i<paletteCount;i++)
  274. {
  275. stPaletteSwap tpPal;
  276. tpPal.newPalette = Message->ReadPackedDWORD();
  277. tpPal.offset = Message->ReadByte();
  278. tpPal.length = Message->ReadByte();
  279. palettes.push_back(tpPal);
  280. }
  281. }
  282. for (int i=0;i<textureCount;i++)
  283. {
  284. stTextureSwap tpTex;
  285. tpTex.modelIndex = Message->ReadByte();
  286. tpTex.oldTexture = Message->ReadPackedDWORD();
  287. tpTex.newTexture = Message->ReadPackedDWORD();
  288. textures.push_back(tpTex);
  289. }
  290. for (int i=0;i<modelCount;i++)
  291. {
  292. stModelSwap tpMod;
  293. tpMod.modelIndex = Message->ReadByte();
  294. tpMod.newModel = Message->ReadPackedDWORD();
  295. models.push_back(tpMod);
  296. }
  297. Message->ReadAlign();
  298. m_bModelUpdate = true;
  299. Unlock();
  300. }
  301. void cWObject::ParseF745(cMessage * Message)
  302. {
  303. Lock();
  304. GUID = Message->ReadDWORD();
  305. //mmm, code reuse
  306. ParseF625(Message);
  307. DWORD flags = Message->ReadDWORD();
  308. portalMode = Message->ReadWORD();
  309. unknown_1 = Message->ReadWORD();
  310. //flags mask..
  311. if (flags & 0x00010000)
  312. {
  313. DWORD unknownCount = Message->ReadDWORD();
  314. for (int i=0;i<(int) unknownCount;i++)
  315. {
  316. BYTE unknownByte = Message->ReadByte();
  317. }
  318. DWORD unknownDword = Message->ReadDWORD();
  319. }
  320. if (flags & 0x00020000)
  321. {
  322. DWORD unknown = Message->ReadDWORD();
  323. }
  324. if (flags & 0x00008000)
  325. {
  326. memcpy(&location, Message->ReadGroup(sizeof(stLocation)), sizeof(stLocation));
  327. }
  328. if (flags & 0x00000002)
  329. {
  330. animConfig = Message->ReadDWORD();
  331. //parse animset!
  332. LoadAnimset();
  333. }
  334. if (flags & 0x00000800)
  335. {
  336. soundset = Message->ReadDWORD();
  337. }
  338. if (flags & 0x00001000)
  339. {
  340. unknown_blue = Message->ReadDWORD();
  341. }
  342. if (flags & 0x00000001)
  343. {
  344. modelNumber = Message->ReadDWORD();
  345. }
  346. if (flags & 0x00000020)
  347. {
  348. wielder = Message->ReadDWORD();
  349. wieldingSlot = Message->ReadDWORD();
  350. }
  351. if (flags & 0x00000040)
  352. {
  353. int equipCount = Message->ReadDWORD();
  354. for (int i=0;i<equipCount;i++)
  355. {
  356. stEquipped tpEquip;
  357. tpEquip.equipID = Message->ReadDWORD();
  358. tpEquip.equipSlot = Message->ReadDWORD();
  359. equipped.push_back(tpEquip);
  360. }
  361. }
  362. if (flags & 0x00000080)
  363. {
  364. m_fScale = Message->ReadFloat();
  365. }
  366. if (flags & 0x00000100)
  367. {
  368. unknown_darkbrown = Message->ReadDWORD();
  369. }
  370. if (flags & 0x00000200)
  371. {
  372. unknown_brightpurple = Message->ReadDWORD();
  373. }
  374. if (flags & 0x00040000)
  375. {
  376. unknown_lightgrey = Message->ReadFloat();
  377. }
  378. if (flags & 0x00000004)
  379. {
  380. unknown_trio1_1 = Message->ReadFloat();
  381. unknown_trio1_2 = Message->ReadFloat();
  382. unknown_trio1_3 = Message->ReadFloat();
  383. }
  384. if (flags & 0x00000008)
  385. {
  386. unknown_trio2_1 = Message->ReadFloat();
  387. unknown_trio2_2 = Message->ReadFloat();
  388. unknown_trio2_3 = Message->ReadFloat();
  389. }
  390. if (flags & 0x00000010)
  391. {
  392. unknown_trio3_1 = Message->ReadFloat();
  393. unknown_trio3_2 = Message->ReadFloat();
  394. unknown_trio3_3 = Message->ReadFloat();
  395. }
  396. if (flags & 0x00002000)
  397. {
  398. unknown_medgrey = Message->ReadDWORD();
  399. }
  400. if (flags & 0x00004000)
  401. {
  402. unknown_bluegrey = Message->ReadFloat();
  403. }
  404. //end of flags section
  405. //balh?
  406. if ((flags & 0x4004) == 0x4004)
  407. {
  408. Velocity = cPoint3D(unknown_trio1_1, unknown_trio1_2, unknown_trio1_3);
  409. Velocity *= 1.0f/240;
  410. // Velocity *= unknown_bluegrey/240; //unknown_bluegrey's connection hasn't been explored yet
  411. m_bMoving = true;
  412. }
  413. //blah!
  414. //one of these might not exist...
  415. numMovements = Message->ReadWORD();
  416. numAnimInteract = Message->ReadWORD();
  417. numBubbleMode = Message->ReadWORD();
  418. numJumps = Message->ReadWORD();
  419. numPortals = Message->ReadWORD();
  420. animCount = Message->ReadWORD();
  421. numOverride = Message->ReadWORD();
  422. unknown_seagreen8 = Message->ReadWORD();
  423. numLogins = Message->ReadWORD();
  424. // unknown_seagreen10 = Message->ReadWORD();
  425. Message->ReadAlign();
  426. //Game data
  427. DWORD flags1 = Message->ReadDWORD();
  428. char *tpString = Message->ReadString();
  429. objectName = tpString;
  430. delete []tpString;
  431. model = Message->ReadPackedDWORD();
  432. icon = Message->ReadPackedDWORD();
  433. category = Message->ReadDWORD();
  434. behavior = Message->ReadDWORD();
  435. Message->ReadAlign();
  436. DWORD flags2 = 0;
  437. if (behavior & 0x04000000)
  438. flags2 = Message->ReadDWORD();
  439. //flags1 masks...
  440. if (flags1 & 0x00000001)
  441. {
  442. namePlural = Message->ReadString();
  443. }
  444. if (flags1 & 0x00000002)
  445. {
  446. itemSlots = Message->ReadByte();
  447. }
  448. if (flags1 & 0x00000004)
  449. {
  450. packSlots = Message->ReadByte();
  451. }
  452. if (flags1 & 0x00000100)
  453. {
  454. ammunition = Message->ReadWORD();
  455. }
  456. if (flags1 & 0x00000008)
  457. {
  458. value = Message->ReadDWORD();
  459. }
  460. if (flags1 & 0x00000010)
  461. {
  462. unknown_v2 = Message->ReadDWORD();
  463. }
  464. if (flags1 & 0x00000020)
  465. {
  466. approachDistance = Message->ReadFloat();
  467. }
  468. if (flags1 & 0x00080000)
  469. {
  470. usableOn = Message->ReadDWORD();
  471. }
  472. if (flags1 & 0x00000080)
  473. {
  474. iconHighlight = Message->ReadDWORD();
  475. }
  476. if (flags1 & 0x00000200)
  477. {
  478. wieldType = Message->ReadByte();
  479. }
  480. if (flags1 & 0x00000400)
  481. {
  482. usesLeft = Message->ReadWORD();
  483. }
  484. if (flags1 & 0x00000800)
  485. {
  486. totalUses = Message->ReadWORD();
  487. }
  488. if (flags1 & 0x00001000)
  489. {
  490. stackCount = Message->ReadWORD();
  491. }
  492. if (flags1 & 0x00002000)
  493. {
  494. stackMax = Message->ReadWORD();
  495. }
  496. if (flags1 & 0x00004000)
  497. {
  498. container = Message->ReadDWORD();
  499. }
  500. if (flags1 & 0x00008000)
  501. {
  502. owner = Message->ReadDWORD();
  503. }
  504. if (flags1 & 0x00010000)
  505. {
  506. coverage1 = Message->ReadDWORD();
  507. }
  508. if (flags1 & 0x00020000)
  509. {
  510. coverage2 = Message->ReadDWORD();
  511. }
  512. if (flags1 & 0x00040000)
  513. {
  514. coverage3 = Message->ReadDWORD();
  515. }
  516. if (flags1 & 0x00100000)
  517. {
  518. unknown5 = Message->ReadByte();
  519. }
  520. if (flags1 & 0x00800000)
  521. {
  522. unknown_v6 = Message->ReadByte();
  523. }
  524. if (flags1 & 0x08000000)
  525. {
  526. unknown800000 = Message->ReadWORD();
  527. }
  528. if (flags1 & 0x01000000)
  529. {
  530. workmanship = Message->ReadFloat();
  531. }
  532. if (flags1 & 0x00200000)
  533. {
  534. burden = Message->ReadWORD();
  535. }
  536. if (flags1 & 0x00400000)
  537. {
  538. associatedSpell = Message->ReadWORD();
  539. }
  540. if (flags1 & 0x02000000)
  541. {
  542. houseOwnerID = Message->ReadDWORD();
  543. }
  544. if (flags1 & 0x04000000)
  545. {
  546. dwellingaccess = Message->ReadDWORD();
  547. }
  548. if (flags1 & 0x20000000)
  549. {
  550. hookTypeUnknown = Message->ReadWORD();
  551. hookType = Message->ReadWORD();
  552. }
  553. if (flags1 & 0x00000040)
  554. {
  555. monarch = Message->ReadDWORD();
  556. }
  557. if (flags1 & 0x10000000)
  558. {
  559. hookableOn = Message->ReadWORD();
  560. }
  561. if (flags1 & 0x40000000)
  562. {
  563. iconOverlay = Message->ReadPackedDWORD();
  564. }
  565. if (behavior & 0x04000000)
  566. {
  567. // if (flags2 & 0x00000001) //yes this should be flags2
  568. // {
  569. iconUnderlay = Message->ReadPackedDWORD();
  570. // }
  571. }
  572. if (flags1 & 0x80000000)
  573. {
  574. material = Message->ReadDWORD();
  575. }
  576. //end flags1
  577. //now precalc shit
  578. CalcPosition.CalcFromLocation(&location);
  579. CalcHeading();
  580. Unlock();
  581. }
  582. void cWObject::ParseF748(cMessage * Message)
  583. {
  584. Lock();
  585. DWORD flags = Message->ReadDWORD();
  586. location.landblock = Message->ReadDWORD();
  587. location.xOffset = Message->ReadFloat();
  588. location.yOffset = Message->ReadFloat();
  589. location.zOffset = Message->ReadFloat();
  590. if (~flags & 0x08) location.wHeading = Message->ReadFloat();
  591. if (~flags & 0x10) location.aHeading = Message->ReadFloat();// else location.aHeading = 0;
  592. if (~flags & 0x20) location.bHeading = Message->ReadFloat();// else location.bHeading = 0;
  593. if (~flags & 0x40) location.cHeading = Message->ReadFloat();
  594. if (flags & 0x01)
  595. {
  596. //velocity
  597. float tx = Message->ReadFloat();
  598. float ty = Message->ReadFloat();
  599. float tz = Message->ReadFloat();
  600. Velocity = cPoint3D(tx, ty, tz);
  601. }
  602. if (flags & 0x02)
  603. {
  604. DWORD unknown = Message->ReadDWORD();
  605. }
  606. if (flags & 0x04)
  607. {
  608. numLogins = Message->ReadWORD();
  609. moveCount = Message->ReadWORD();
  610. numPortals = Message->ReadWORD();
  611. numOverride = Message->ReadWORD();
  612. }
  613. CalcPosition.CalcFromLocation(&location);
  614. CalcHeading();
  615. Unlock();
  616. }
  617. void cWObject::AdjustStack(DWORD Count, DWORD Value)
  618. {
  619. //hmmmm, make sure this is right at some point
  620. Lock();
  621. stackCount = (WORD) Count;
  622. value = Value;
  623. Unlock();
  624. }
  625. void cWObject::Set229(DWORD Type, DWORD Value)
  626. {
  627. Lock();
  628. switch (Type)
  629. {
  630. case 0x0A:
  631. {
  632. //set coverage
  633. coverage2 = Value;
  634. break;
  635. }
  636. case 0x5C:
  637. {
  638. //uses remaining
  639. usesLeft = (WORD) Value;
  640. break;
  641. }
  642. case 0xC1:
  643. {
  644. //keys on keyring
  645. usesLeft = (WORD) Value;//same variable?
  646. break;
  647. }
  648. };
  649. Unlock();
  650. }
  651. void cWObject::Set22D(DWORD Type, DWORD Value)
  652. {
  653. Lock();
  654. switch (Type)
  655. {
  656. case 0x02:
  657. {
  658. //set as container
  659. wielder = 0;
  660. container = Value;
  661. break;
  662. }
  663. case 0x03:
  664. {
  665. //set as wielder
  666. wielder = Value;
  667. container = 0;
  668. break;
  669. }
  670. };
  671. Unlock();
  672. }
  673. DWORD cWObject::GetGUID()
  674. {
  675. return GUID;
  676. }
  677. DWORD cWObject::GetWielder()
  678. {
  679. return wielder;
  680. }
  681. cPoint3D cWObject::GetPosition()
  682. {
  683. return CalcPosition;
  684. }
  685. float cWObject::GetHeading()
  686. {
  687. return m_fHeading;
  688. }
  689. DWORD cWObject::GetObjectFlags2()
  690. {
  691. return category;
  692. }
  693. DWORD cWObject::GetRadarOverride()
  694. {
  695. return unknown5;
  696. }
  697. void cWObject::CalcHeading()
  698. {
  699. //trimmed way down quat->euler algo
  700. double matrix[3][3];
  701. double sy;
  702. double cz,sz;
  703. // CONVERT QUATERNION TO MATRIX - I DON'T REALLY NEED ALL OF IT
  704. matrix[0][0] = 1.0f - (2.0f * location.bHeading * location.bHeading) - (2.0f * location.cHeading * location.cHeading);
  705. // matrix[0][1] = (2.0f * location.aHeading * location.bHeading) - (2.0f * location.wHeading * location.cHeading);
  706. // matrix[0][2] = (2.0f * location.aHeading * location.cHeading) + (2.0f * location.wHeading * location.bHeading);
  707. matrix[1][0] = (2.0f * location.aHeading * location.bHeading) + (2.0f * location.wHeading * location.cHeading);
  708. // matrix[1][1] = 1.0f - (2.0f * location.aHeading * location.aHeading) - (2.0f * location.cHeading * location.cHeading);
  709. // matrix[1][2] = (2.0f * location.bHeading * location.cHeading) - (2.0f * location.wHeading * location.aHeading);
  710. matrix[2][0] = (2.0f * location.aHeading * location.cHeading) - (2.0f * location.wHeading * location.bHeading);
  711. // matrix[2][1] = (2.0f * location.bHeading * location.cHeading) + (2.0f * location.wHeading * location.aHeading);
  712. // matrix[2][2] = 1.0f - (2.0f * location.aHeading * location.aHeading) - (2.0f * location.bHeading * location.bHeading);
  713. sy = -matrix[2][0];
  714. if ((sy != 1.0f) && (sy != -1.0f))
  715. {
  716. double cy = sqrt(1 - (sy * sy));
  717. cz = matrix[0][0] / cy;
  718. sz = matrix[1][0] / cy;
  719. m_fHeading = (float)atan2(sz,cz);
  720. }
  721. else
  722. {
  723. cz = 1.0f;
  724. sz = 0.0f;
  725. m_fHeading = (float)atan2(sz,cz);
  726. }
  727. }
  728. void cWObject::LoadLocationHeading(float fZ)
  729. {
  730. //only
  731. float c2 = cos(fZ/2);
  732. float s2 = sin(fZ/2);
  733. // w = c1 c2 c3 - s1 s2 s3
  734. // x = s1 s2 c3 +c1 c2 s3
  735. // y = s1 c2 c3 + c1 s2 s3
  736. // z = c1 s2 c3 - s1 c2 s3
  737. location.wHeading = c2;
  738. location.aHeading = 0;
  739. location.bHeading = 0;
  740. location.cHeading = s2;
  741. }
  742. std::string cWObject::GetName()
  743. {
  744. return objectName;
  745. }
  746. DWORD cWObject::GetLandblock()
  747. {
  748. return location.landblock;
  749. }
  750. stLocation * cWObject::GetLocation()
  751. {
  752. return &location;
  753. }
  754. stMoveInfo cWObject::GetMoveInfo()
  755. {
  756. stMoveInfo miTemp;
  757. miTemp.moveCount = moveCount;
  758. miTemp.numLogins = numLogins;
  759. miTemp.numOverride = numOverride;
  760. miTemp.numPortals = numPortals;
  761. return miTemp;
  762. }
  763. void cWObject::SetVelocity(cPoint3D NewVelocity)
  764. {
  765. Velocity = NewVelocity;
  766. }
  767. void cWObject::LoadAnimset()
  768. {
  769. cPortalFile *pf = m_Portal->OpenEntry(animConfig);
  770. if (!pf)
  771. return;
  772. cByteStream BS(pf->data, pf->length);
  773. BS.ReadBegin();
  774. //portal ID
  775. DWORD dwID = BS.ReadDWORD();
  776. //something that tends to always be 0x8000003D
  777. DWORD dwUnknown = BS.ReadDWORD();
  778. //first vector, pairs together different 0x800000**'s to 0x41000003?
  779. DWORD vec1count = BS.ReadDWORD();
  780. for (DWORD i=0; i<vec1count; i++)
  781. {
  782. DWORD unk1 = BS.ReadDWORD();
  783. DWORD unk2 = BS.ReadDWORD();
  784. }
  785. FILE *out = NULL;
  786. //FILE *out=fopen("aset.txt","wt");
  787. DWORD vec2count = BS.ReadDWORD();
  788. for (DWORD i=0; i<vec2count; i++)
  789. {
  790. //0x003D0141 ?? obj[0];
  791. stAnimSet asTemp;
  792. asTemp.dwID = BS.ReadDWORD();
  793. asTemp.dwFlags = BS.ReadDWORD();
  794. stAnimInfo aiTemp;
  795. aiTemp.dwAnim = BS.ReadDWORD(); //0x0300****
  796. aiTemp.dwStartFrame = BS.ReadDWORD(); //0x00000000
  797. aiTemp.dwEndFrame = BS.ReadDWORD(); //0xFFFFFFFF
  798. aiTemp.fPlaySpeed = BS.ReadFloat();
  799. if (out != NULL) {
  800. fprintf(out, "%08X (%08X): %08X\n", asTemp.dwID, asTemp.dwFlags, aiTemp.dwAnim);
  801. }
  802. if (aiTemp.fPlaySpeed == 0)
  803. aiTemp.fPlaySpeed = 30.0f;
  804. asTemp.vAnims.push_back(aiTemp);
  805. m_mAnims[asTemp.dwID] = asTemp;
  806. if (asTemp.dwFlags & 0x20000) {
  807. //3 floats? are here
  808. BS.ReadFloat();
  809. BS.ReadFloat();
  810. BS.ReadFloat();
  811. }
  812. }
  813. DWORD vec3count = BS.ReadDWORD();
  814. for (DWORD i=0; i<vec3count; i++)
  815. {
  816. //first word(low) is weird (0x0D, 0x0F, etc.)
  817. //second word(high) is animation stance?
  818. WORD stance = (WORD)(BS.ReadDWORD() >> 16);
  819. //probably not flags, probably 2 WORDS (high is usually 2, sometimes 1)
  820. DWORD flags = BS.ReadDWORD();
  821. //last 3 are floats? could be dependent on flags, who knows..
  822. BS.ReadFloat();
  823. BS.ReadFloat();
  824. BS.ReadFloat();
  825. }
  826. DWORD vec4count = BS.ReadDWORD();
  827. for (DWORD i=0; i<vec4count; i++)
  828. {
  829. //0x003D0141 ?? obj[0]
  830. WORD wUnk = BS.ReadWORD();
  831. WORD wStance = BS.ReadWORD();
  832. if (out != NULL) {
  833. fprintf(out, "%04X (%04X): \n", wStance, wUnk);
  834. }
  835. DWORD vec5count = BS.ReadDWORD();
  836. for (DWORD h=0; h<vec5count; h++)
  837. {
  838. stAnimSet asTemp;
  839. asTemp.dwID = BS.ReadWORD();
  840. asTemp.dwFlags = BS.ReadWORD();
  841. if (out != NULL) {
  842. fprintf(out, " %04X (%04X):: ", asTemp.dwID, asTemp.dwFlags);
  843. }
  844. DWORD vec6count = BS.ReadDWORD();
  845. for (DWORD vec6it = 0; vec6it < vec6count; vec6it++)
  846. {
  847. stAnimInfo aiTemp;
  848. aiTemp.dwAnim = BS.ReadDWORD(); //0x0300****
  849. aiTemp.dwStartFrame = BS.ReadDWORD(); //0x00000000
  850. aiTemp.dwEndFrame = BS.ReadDWORD(); //0xFFFFFFFF
  851. aiTemp.fPlaySpeed = BS.ReadFloat();
  852. if (out != NULL)
  853. {
  854. fprintf(out, "%08X ", aiTemp.dwAnim);
  855. }
  856. //?
  857. if (aiTemp.fPlaySpeed == 0)
  858. aiTemp.fPlaySpeed = 30.0f;
  859. asTemp.vAnims.push_back(aiTemp);
  860. }
  861. if (out != NULL) {
  862. fprintf(out, "\n");
  863. }
  864. //uhh, ick...
  865. if ((wUnk == 0) || (wUnk == 3))
  866. asTemp.dwID |= ((DWORD) wStance << 16);
  867. else
  868. asTemp.dwID |= ((DWORD) wUnk << 16);
  869. m_mAnims[asTemp.dwID] = asTemp;
  870. }
  871. }
  872. if (out != NULL) {
  873. fclose(out);
  874. }
  875. }
  876. WORD cWObject::GetStance()
  877. {
  878. return m_wStance;
  879. }