pmove.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "quakedef.h"
  16. movevars_t movevars;
  17. playermove_t pmove;
  18. int onground;
  19. int waterlevel;
  20. int watertype;
  21. float frametime;
  22. vec3_t forward, right, up;
  23. vec3_t player_mins = {-16, -16, -24};
  24. vec3_t player_maxs = {16, 16, 32};
  25. // #define PM_GRAVITY 800
  26. // #define PM_STOPSPEED 100
  27. // #define PM_MAXSPEED 320
  28. // #define PM_SPECTATORMAXSPEED 500
  29. // #define PM_ACCELERATE 10
  30. // #define PM_AIRACCELERATE 0.7
  31. // #define PM_WATERACCELERATE 10
  32. // #define PM_FRICTION 6
  33. // #define PM_WATERFRICTION 1
  34. void PM_InitBoxHull (void);
  35. void Pmove_Init (void)
  36. {
  37. PM_InitBoxHull ();
  38. }
  39. #define STEPSIZE 18
  40. #define BUTTON_JUMP 2
  41. /*
  42. ==================
  43. PM_ClipVelocity
  44. Slide off of the impacting object
  45. returns the blocked flags (1 = floor, 2 = step / wall)
  46. ==================
  47. */
  48. #define STOP_EPSILON 0.1
  49. int PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
  50. {
  51. float backoff;
  52. float change;
  53. int i, blocked;
  54. blocked = 0;
  55. if (normal[2] > 0)
  56. blocked |= 1; // floor
  57. if (!normal[2])
  58. blocked |= 2; // step
  59. backoff = DotProduct (in, normal) * overbounce;
  60. for (i=0 ; i<3 ; i++)
  61. {
  62. change = normal[i]*backoff;
  63. out[i] = in[i] - change;
  64. if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON)
  65. out[i] = 0;
  66. }
  67. return blocked;
  68. }
  69. /*
  70. ============
  71. PM_FlyMove
  72. The basic solid body movement clip that slides along multiple planes
  73. ============
  74. */
  75. #define MAX_CLIP_PLANES 5
  76. int PM_FlyMove (void)
  77. {
  78. int bumpcount, numbumps;
  79. vec3_t dir;
  80. float d;
  81. int numplanes;
  82. vec3_t planes[MAX_CLIP_PLANES];
  83. vec3_t primal_velocity, original_velocity;
  84. int i, j;
  85. pmtrace_t trace;
  86. vec3_t end;
  87. float time_left;
  88. int blocked;
  89. numbumps = 4;
  90. blocked = 0;
  91. VectorCopy (pmove.velocity, original_velocity);
  92. VectorCopy (pmove.velocity, primal_velocity);
  93. numplanes = 0;
  94. time_left = frametime;
  95. for (bumpcount=0 ; bumpcount<numbumps ; bumpcount++)
  96. {
  97. for (i=0 ; i<3 ; i++)
  98. end[i] = pmove.origin[i] + time_left * pmove.velocity[i];
  99. trace = PM_PlayerMove (pmove.origin, end);
  100. if (trace.startsolid || trace.allsolid)
  101. { // entity is trapped in another solid
  102. VectorCopy (vec3_origin, pmove.velocity);
  103. return 3;
  104. }
  105. if (trace.fraction > 0)
  106. { // actually covered some distance
  107. VectorCopy (trace.endpos, pmove.origin);
  108. numplanes = 0;
  109. }
  110. if (trace.fraction == 1)
  111. break; // moved the entire distance
  112. // save entity for contact
  113. pmove.touchindex[pmove.numtouch] = trace.ent;
  114. pmove.numtouch++;
  115. if (trace.plane.normal[2] > 0.7)
  116. {
  117. blocked |= 1; // floor
  118. }
  119. if (!trace.plane.normal[2])
  120. {
  121. blocked |= 2; // step
  122. }
  123. time_left -= time_left * trace.fraction;
  124. // cliped to another plane
  125. if (numplanes >= MAX_CLIP_PLANES)
  126. { // this shouldn't really happen
  127. VectorCopy (vec3_origin, pmove.velocity);
  128. break;
  129. }
  130. VectorCopy (trace.plane.normal, planes[numplanes]);
  131. numplanes++;
  132. //
  133. // modify original_velocity so it parallels all of the clip planes
  134. //
  135. for (i=0 ; i<numplanes ; i++)
  136. {
  137. PM_ClipVelocity (original_velocity, planes[i], pmove.velocity, 1);
  138. for (j=0 ; j<numplanes ; j++)
  139. if (j != i)
  140. {
  141. if (DotProduct (pmove.velocity, planes[j]) < 0)
  142. break; // not ok
  143. }
  144. if (j == numplanes)
  145. break;
  146. }
  147. if (i != numplanes)
  148. { // go along this plane
  149. }
  150. else
  151. { // go along the crease
  152. if (numplanes != 2)
  153. {
  154. // Con_Printf ("clip velocity, numplanes == %i\n",numplanes);
  155. VectorCopy (vec3_origin, pmove.velocity);
  156. break;
  157. }
  158. CrossProduct (planes[0], planes[1], dir);
  159. d = DotProduct (dir, pmove.velocity);
  160. VectorScale (dir, d, pmove.velocity);
  161. }
  162. //
  163. // if original velocity is against the original velocity, stop dead
  164. // to avoid tiny occilations in sloping corners
  165. //
  166. if (DotProduct (pmove.velocity, primal_velocity) <= 0)
  167. {
  168. VectorCopy (vec3_origin, pmove.velocity);
  169. break;
  170. }
  171. }
  172. if (pmove.waterjumptime)
  173. {
  174. VectorCopy (primal_velocity, pmove.velocity);
  175. }
  176. return blocked;
  177. }
  178. /*
  179. =============
  180. PM_GroundMove
  181. Player is on ground, with no upwards velocity
  182. =============
  183. */
  184. void PM_GroundMove (void)
  185. {
  186. vec3_t start, dest;
  187. pmtrace_t trace;
  188. vec3_t original, originalvel, down, up, downvel;
  189. float downdist, updist;
  190. pmove.velocity[2] = 0;
  191. if (!pmove.velocity[0] && !pmove.velocity[1] && !pmove.velocity[2])
  192. return;
  193. // first try just moving to the destination
  194. dest[0] = pmove.origin[0] + pmove.velocity[0]*frametime;
  195. dest[1] = pmove.origin[1] + pmove.velocity[1]*frametime;
  196. dest[2] = pmove.origin[2];
  197. // first try moving directly to the next spot
  198. VectorCopy (dest, start);
  199. trace = PM_PlayerMove (pmove.origin, dest);
  200. if (trace.fraction == 1)
  201. {
  202. VectorCopy (trace.endpos, pmove.origin);
  203. return;
  204. }
  205. // try sliding forward both on ground and up 16 pixels
  206. // take the move that goes farthest
  207. VectorCopy (pmove.origin, original);
  208. VectorCopy (pmove.velocity, originalvel);
  209. // slide move
  210. PM_FlyMove ();
  211. VectorCopy (pmove.origin, down);
  212. VectorCopy (pmove.velocity, downvel);
  213. VectorCopy (original, pmove.origin);
  214. VectorCopy (originalvel, pmove.velocity);
  215. // move up a stair height
  216. VectorCopy (pmove.origin, dest);
  217. dest[2] += STEPSIZE;
  218. trace = PM_PlayerMove (pmove.origin, dest);
  219. if (!trace.startsolid && !trace.allsolid)
  220. {
  221. VectorCopy (trace.endpos, pmove.origin);
  222. }
  223. // slide move
  224. PM_FlyMove ();
  225. // press down the stepheight
  226. VectorCopy (pmove.origin, dest);
  227. dest[2] -= STEPSIZE;
  228. trace = PM_PlayerMove (pmove.origin, dest);
  229. if ( trace.plane.normal[2] < 0.7)
  230. goto usedown;
  231. if (!trace.startsolid && !trace.allsolid)
  232. {
  233. VectorCopy (trace.endpos, pmove.origin);
  234. }
  235. VectorCopy (pmove.origin, up);
  236. // decide which one went farther
  237. downdist = (down[0] - original[0])*(down[0] - original[0])
  238. + (down[1] - original[1])*(down[1] - original[1]);
  239. updist = (up[0] - original[0])*(up[0] - original[0])
  240. + (up[1] - original[1])*(up[1] - original[1]);
  241. if (downdist > updist)
  242. {
  243. usedown:
  244. VectorCopy (down, pmove.origin);
  245. VectorCopy (downvel, pmove.velocity);
  246. } else // copy z value from slide move
  247. pmove.velocity[2] = downvel[2];
  248. // if at a dead stop, retry the move with nudges to get around lips
  249. }
  250. /*
  251. ==================
  252. PM_Friction
  253. Handles both ground friction and water friction
  254. ==================
  255. */
  256. void PM_Friction (void)
  257. {
  258. float *vel;
  259. float speed, newspeed, control;
  260. float friction;
  261. float drop;
  262. vec3_t start, stop;
  263. pmtrace_t trace;
  264. if (pmove.waterjumptime)
  265. return;
  266. vel = pmove.velocity;
  267. speed = sqrt(vel[0]*vel[0] +vel[1]*vel[1] + vel[2]*vel[2]);
  268. if (speed < 1)
  269. {
  270. vel[0] = 0;
  271. vel[1] = 0;
  272. return;
  273. }
  274. friction = movevars.friction;
  275. // if the leading edge is over a dropoff, increase friction
  276. if (onground != -1) {
  277. start[0] = stop[0] = pmove.origin[0] + vel[0]/speed*16;
  278. start[1] = stop[1] = pmove.origin[1] + vel[1]/speed*16;
  279. start[2] = pmove.origin[2] + player_mins[2];
  280. stop[2] = start[2] - 34;
  281. trace = PM_PlayerMove (start, stop);
  282. if (trace.fraction == 1) {
  283. friction *= 2;
  284. }
  285. }
  286. drop = 0;
  287. if (waterlevel >= 2) // apply water friction
  288. drop += speed*movevars.waterfriction*waterlevel*frametime;
  289. else if (onground != -1) // apply ground friction
  290. {
  291. control = speed < movevars.stopspeed ? movevars.stopspeed : speed;
  292. drop += control*friction*frametime;
  293. }
  294. // scale the velocity
  295. newspeed = speed - drop;
  296. if (newspeed < 0)
  297. newspeed = 0;
  298. newspeed /= speed;
  299. vel[0] = vel[0] * newspeed;
  300. vel[1] = vel[1] * newspeed;
  301. vel[2] = vel[2] * newspeed;
  302. }
  303. /*
  304. ==============
  305. PM_Accelerate
  306. ==============
  307. */
  308. void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel)
  309. {
  310. int i;
  311. float addspeed, accelspeed, currentspeed;
  312. if (pmove.dead)
  313. return;
  314. if (pmove.waterjumptime)
  315. return;
  316. currentspeed = DotProduct (pmove.velocity, wishdir);
  317. addspeed = wishspeed - currentspeed;
  318. if (addspeed <= 0)
  319. return;
  320. accelspeed = accel*frametime*wishspeed;
  321. if (accelspeed > addspeed)
  322. accelspeed = addspeed;
  323. for (i=0 ; i<3 ; i++)
  324. pmove.velocity[i] += accelspeed*wishdir[i];
  325. }
  326. void PM_AirAccelerate (vec3_t wishdir, float wishspeed, float accel)
  327. {
  328. int i;
  329. float addspeed, accelspeed, currentspeed, wishspd = wishspeed;
  330. if (pmove.dead)
  331. return;
  332. if (pmove.waterjumptime)
  333. return;
  334. if (wishspd > 30)
  335. wishspd = 30;
  336. currentspeed = DotProduct (pmove.velocity, wishdir);
  337. addspeed = wishspd - currentspeed;
  338. if (addspeed <= 0)
  339. return;
  340. accelspeed = accel * wishspeed * frametime;
  341. if (accelspeed > addspeed)
  342. accelspeed = addspeed;
  343. for (i=0 ; i<3 ; i++)
  344. pmove.velocity[i] += accelspeed*wishdir[i];
  345. }
  346. /*
  347. ===================
  348. PM_WaterMove
  349. ===================
  350. */
  351. void PM_WaterMove (void)
  352. {
  353. int i;
  354. vec3_t wishvel;
  355. float wishspeed;
  356. vec3_t wishdir;
  357. vec3_t start, dest;
  358. pmtrace_t trace;
  359. //
  360. // user intentions
  361. //
  362. for (i=0 ; i<3 ; i++)
  363. wishvel[i] = forward[i]*pmove.cmd.forwardmove + right[i]*pmove.cmd.sidemove;
  364. if (!pmove.cmd.forwardmove && !pmove.cmd.sidemove && !pmove.cmd.upmove)
  365. wishvel[2] -= 60; // drift towards bottom
  366. else
  367. wishvel[2] += pmove.cmd.upmove;
  368. VectorCopy (wishvel, wishdir);
  369. wishspeed = VectorNormalize(wishdir);
  370. if (wishspeed > movevars.maxspeed)
  371. {
  372. VectorScale (wishvel, movevars.maxspeed/wishspeed, wishvel);
  373. wishspeed = movevars.maxspeed;
  374. }
  375. wishspeed *= 0.7;
  376. //
  377. // water acceleration
  378. //
  379. // if (pmove.waterjumptime)
  380. // Con_Printf ("wm->%f, %f, %f\n", pmove.velocity[0], pmove.velocity[1], pmove.velocity[2]);
  381. PM_Accelerate (wishdir, wishspeed, movevars.wateraccelerate);
  382. // assume it is a stair or a slope, so press down from stepheight above
  383. VectorMA (pmove.origin, frametime, pmove.velocity, dest);
  384. VectorCopy (dest, start);
  385. start[2] += STEPSIZE + 1;
  386. trace = PM_PlayerMove (start, dest);
  387. if (!trace.startsolid && !trace.allsolid) // FIXME: check steep slope?
  388. { // walked up the step
  389. VectorCopy (trace.endpos, pmove.origin);
  390. return;
  391. }
  392. PM_FlyMove ();
  393. // if (pmove.waterjumptime)
  394. // Con_Printf ("<-wm%f, %f, %f\n", pmove.velocity[0], pmove.velocity[1], pmove.velocity[2]);
  395. }
  396. /*
  397. ===================
  398. PM_AirMove
  399. ===================
  400. */
  401. void PM_AirMove (void)
  402. {
  403. int i;
  404. vec3_t wishvel;
  405. float fmove, smove;
  406. vec3_t wishdir;
  407. float wishspeed;
  408. fmove = pmove.cmd.forwardmove;
  409. smove = pmove.cmd.sidemove;
  410. forward[2] = 0;
  411. right[2] = 0;
  412. VectorNormalize (forward);
  413. VectorNormalize (right);
  414. for (i=0 ; i<2 ; i++)
  415. wishvel[i] = forward[i]*fmove + right[i]*smove;
  416. wishvel[2] = 0;
  417. VectorCopy (wishvel, wishdir);
  418. wishspeed = VectorNormalize(wishdir);
  419. //
  420. // clamp to server defined max speed
  421. //
  422. if (wishspeed > movevars.maxspeed)
  423. {
  424. VectorScale (wishvel, movevars.maxspeed/wishspeed, wishvel);
  425. wishspeed = movevars.maxspeed;
  426. }
  427. // if (pmove.waterjumptime)
  428. // Con_Printf ("am->%f, %f, %f\n", pmove.velocity[0], pmove.velocity[1], pmove.velocity[2]);
  429. if ( onground != -1)
  430. {
  431. pmove.velocity[2] = 0;
  432. PM_Accelerate (wishdir, wishspeed, movevars.accelerate);
  433. pmove.velocity[2] -= movevars.entgravity * movevars.gravity * frametime;
  434. PM_GroundMove ();
  435. }
  436. else
  437. { // not on ground, so little effect on velocity
  438. PM_AirAccelerate (wishdir, wishspeed, movevars.accelerate);
  439. // add gravity
  440. pmove.velocity[2] -= movevars.entgravity * movevars.gravity * frametime;
  441. PM_FlyMove ();
  442. }
  443. //Con_Printf("airmove:vec: %4.2f %4.2f %4.2f\n",
  444. // pmove.velocity[0],
  445. // pmove.velocity[1],
  446. // pmove.velocity[2]);
  447. //
  448. // if (pmove.waterjumptime)
  449. // Con_Printf ("<-am%f, %f, %f\n", pmove.velocity[0], pmove.velocity[1], pmove.velocity[2]);
  450. }
  451. /*
  452. =============
  453. PM_CatagorizePosition
  454. =============
  455. */
  456. void PM_CatagorizePosition (void)
  457. {
  458. vec3_t point;
  459. int cont;
  460. pmtrace_t tr;
  461. // if the player hull point one unit down is solid, the player
  462. // is on ground
  463. // see if standing on something solid
  464. point[0] = pmove.origin[0];
  465. point[1] = pmove.origin[1];
  466. point[2] = pmove.origin[2] - 1;
  467. if (pmove.velocity[2] > 180)
  468. {
  469. onground = -1;
  470. }
  471. else
  472. {
  473. tr = PM_PlayerMove (pmove.origin, point);
  474. if ( tr.plane.normal[2] < 0.7)
  475. onground = -1; // too steep
  476. else
  477. onground = tr.ent;
  478. if (onground != -1)
  479. {
  480. pmove.waterjumptime = 0;
  481. if (!tr.startsolid && !tr.allsolid)
  482. VectorCopy (tr.endpos, pmove.origin);
  483. }
  484. // standing on an entity other than the world
  485. if (tr.ent > 0)
  486. {
  487. pmove.touchindex[pmove.numtouch] = tr.ent;
  488. pmove.numtouch++;
  489. }
  490. }
  491. //
  492. // get waterlevel
  493. //
  494. waterlevel = 0;
  495. watertype = CONTENTS_EMPTY;
  496. point[2] = pmove.origin[2] + player_mins[2] + 1;
  497. cont = PM_PointContents (point);
  498. if (cont <= CONTENTS_WATER)
  499. {
  500. watertype = cont;
  501. waterlevel = 1;
  502. point[2] = pmove.origin[2] + (player_mins[2] + player_maxs[2])*0.5;
  503. cont = PM_PointContents (point);
  504. if (cont <= CONTENTS_WATER)
  505. {
  506. waterlevel = 2;
  507. point[2] = pmove.origin[2] + 22;
  508. cont = PM_PointContents (point);
  509. if (cont <= CONTENTS_WATER)
  510. waterlevel = 3;
  511. }
  512. }
  513. }
  514. /*
  515. =============
  516. JumpButton
  517. =============
  518. */
  519. void JumpButton (void)
  520. {
  521. if (pmove.dead)
  522. {
  523. pmove.oldbuttons |= BUTTON_JUMP; // don't jump again until released
  524. return;
  525. }
  526. if (pmove.waterjumptime)
  527. {
  528. pmove.waterjumptime -= frametime;
  529. if (pmove.waterjumptime < 0)
  530. pmove.waterjumptime = 0;
  531. return;
  532. }
  533. if (waterlevel >= 2)
  534. { // swimming, not jumping
  535. onground = -1;
  536. if (watertype == CONTENTS_WATER)
  537. pmove.velocity[2] = 100;
  538. else if (watertype == CONTENTS_SLIME)
  539. pmove.velocity[2] = 80;
  540. else
  541. pmove.velocity[2] = 50;
  542. return;
  543. }
  544. if (onground == -1)
  545. return; // in air, so no effect
  546. if ( pmove.oldbuttons & BUTTON_JUMP )
  547. return; // don't pogo stick
  548. onground = -1;
  549. pmove.velocity[2] += 270;
  550. pmove.oldbuttons |= BUTTON_JUMP; // don't jump again until released
  551. }
  552. /*
  553. =============
  554. CheckWaterJump
  555. =============
  556. */
  557. void CheckWaterJump (void)
  558. {
  559. vec3_t spot;
  560. int cont;
  561. vec3_t flatforward;
  562. if (pmove.waterjumptime)
  563. return;
  564. // ZOID, don't hop out if we just jumped in
  565. if (pmove.velocity[2] < -180)
  566. return; // only hop out if we are moving up
  567. // see if near an edge
  568. flatforward[0] = forward[0];
  569. flatforward[1] = forward[1];
  570. flatforward[2] = 0;
  571. VectorNormalize (flatforward);
  572. VectorMA (pmove.origin, 24, flatforward, spot);
  573. spot[2] += 8;
  574. cont = PM_PointContents (spot);
  575. if (cont != CONTENTS_SOLID)
  576. return;
  577. spot[2] += 24;
  578. cont = PM_PointContents (spot);
  579. if (cont != CONTENTS_EMPTY)
  580. return;
  581. // jump out of water
  582. VectorScale (flatforward, 50, pmove.velocity);
  583. pmove.velocity[2] = 310;
  584. pmove.waterjumptime = 2; // safety net
  585. pmove.oldbuttons |= BUTTON_JUMP; // don't jump again until released
  586. }
  587. /*
  588. =================
  589. NudgePosition
  590. If pmove.origin is in a solid position,
  591. try nudging slightly on all axis to
  592. allow for the cut precision of the net coordinates
  593. =================
  594. */
  595. void NudgePosition (void)
  596. {
  597. vec3_t base;
  598. int x, y, z;
  599. int i;
  600. static int sign[3] = {0, -1, 1};
  601. VectorCopy (pmove.origin, base);
  602. for (i=0 ; i<3 ; i++)
  603. pmove.origin[i] = ((int)(pmove.origin[i]*8)) * 0.125;
  604. // pmove.origin[2] += 0.124;
  605. // if (pmove.dead)
  606. // return; // might be a squished point, so don'y bother
  607. // if (PM_TestPlayerPosition (pmove.origin) )
  608. // return;
  609. for (z=0 ; z<=2 ; z++)
  610. {
  611. for (x=0 ; x<=2 ; x++)
  612. {
  613. for (y=0 ; y<=2 ; y++)
  614. {
  615. pmove.origin[0] = base[0] + (sign[x] * 1.0/8);
  616. pmove.origin[1] = base[1] + (sign[y] * 1.0/8);
  617. pmove.origin[2] = base[2] + (sign[z] * 1.0/8);
  618. if (PM_TestPlayerPosition (pmove.origin))
  619. return;
  620. }
  621. }
  622. }
  623. VectorCopy (base, pmove.origin);
  624. // Con_DPrintf ("NudgePosition: stuck\n");
  625. }
  626. /*
  627. ===============
  628. SpectatorMove
  629. ===============
  630. */
  631. void SpectatorMove (void)
  632. {
  633. float speed, drop, friction, control, newspeed, accel;
  634. float currentspeed, addspeed, accelspeed;
  635. int i;
  636. vec3_t wishvel;
  637. float fmove, smove;
  638. vec3_t wishdir;
  639. float wishspeed;
  640. #ifndef SERVERONLY
  641. extern float server_version; // version of server we connected to
  642. #endif
  643. // friction
  644. speed = Length (pmove.velocity);
  645. if (speed < 1)
  646. {
  647. VectorCopy (vec3_origin, pmove.velocity)
  648. }
  649. else
  650. {
  651. drop = 0;
  652. friction = movevars.friction*1.5; // extra friction
  653. control = speed < movevars.stopspeed ? movevars.stopspeed : speed;
  654. drop += control*friction*frametime;
  655. // scale the velocity
  656. newspeed = speed - drop;
  657. if (newspeed < 0)
  658. newspeed = 0;
  659. newspeed /= speed;
  660. VectorScale (pmove.velocity, newspeed, pmove.velocity);
  661. }
  662. // accelerate
  663. fmove = pmove.cmd.forwardmove;
  664. smove = pmove.cmd.sidemove;
  665. VectorNormalize (forward);
  666. VectorNormalize (right);
  667. for (i=0 ; i<3 ; i++)
  668. wishvel[i] = forward[i]*fmove + right[i]*smove;
  669. wishvel[2] += pmove.cmd.upmove;
  670. VectorCopy (wishvel, wishdir);
  671. wishspeed = VectorNormalize(wishdir);
  672. //
  673. // clamp to server defined max speed
  674. //
  675. if (wishspeed > movevars.spectatormaxspeed)
  676. {
  677. VectorScale (wishvel, movevars.spectatormaxspeed/wishspeed, wishvel);
  678. wishspeed = movevars.spectatormaxspeed;
  679. }
  680. currentspeed = DotProduct(pmove.velocity, wishdir);
  681. addspeed = wishspeed - currentspeed;
  682. if (addspeed <= 0)
  683. return;
  684. accelspeed = movevars.accelerate*frametime*wishspeed;
  685. if (accelspeed > addspeed)
  686. accelspeed = addspeed;
  687. for (i=0 ; i<3 ; i++)
  688. pmove.velocity[i] += accelspeed*wishdir[i];
  689. // move
  690. VectorMA (pmove.origin, frametime, pmove.velocity, pmove.origin);
  691. }
  692. /*
  693. =============
  694. PlayerMove
  695. Returns with origin, angles, and velocity modified in place.
  696. Numtouch and touchindex[] will be set if any of the physents
  697. were contacted during the move.
  698. =============
  699. */
  700. void PlayerMove (void)
  701. {
  702. frametime = pmove.cmd.msec * 0.001;
  703. pmove.numtouch = 0;
  704. AngleVectors (pmove.angles, forward, right, up);
  705. if (pmove.spectator)
  706. {
  707. SpectatorMove ();
  708. return;
  709. }
  710. NudgePosition ();
  711. // take angles directly from command
  712. VectorCopy (pmove.cmd.angles, pmove.angles);
  713. // set onground, watertype, and waterlevel
  714. PM_CatagorizePosition ();
  715. if (waterlevel == 2)
  716. CheckWaterJump ();
  717. if (pmove.velocity[2] < 0)
  718. pmove.waterjumptime = 0;
  719. if (pmove.cmd.buttons & BUTTON_JUMP)
  720. JumpButton ();
  721. else
  722. pmove.oldbuttons &= ~BUTTON_JUMP;
  723. PM_Friction ();
  724. if (waterlevel >= 2)
  725. PM_WaterMove ();
  726. else
  727. PM_AirMove ();
  728. // set onground, watertype, and waterlevel for final spot
  729. PM_CatagorizePosition ();
  730. }