Hunt2.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719
  1. #define _MAIN_
  2. #include "Hunt.h"
  3. #include "stdio.h"
  4. float rav=0;
  5. float rbv=0;
  6. #ifdef _soft
  7. BOOL PHONG = FALSE;
  8. BOOL GOUR = FALSE;
  9. BOOL ENVMAP = FALSE;
  10. #else
  11. BOOL PHONG = TRUE;
  12. BOOL GOUR = TRUE;
  13. BOOL ENVMAP = TRUE;
  14. #endif
  15. BOOL NeedRVM = TRUE;
  16. float BinocularPower = 2.5;
  17. float wpshy = 0;
  18. float wpshz = 0;
  19. float wpnb = 0;
  20. int wpnlight;
  21. void HideWeapon();
  22. char cheatcode[16] = "DEBUGUP";
  23. int cheati = 0;
  24. void ResetMousePos()
  25. {
  26. SetCursorPos(VideoCX, VideoCY);
  27. }
  28. float CalcFogLevel(Vector3d v)
  29. {
  30. if (!FOGON) return 0;
  31. BOOL vinfog = TRUE;
  32. int cf;
  33. if (!UNDERWATER) {
  34. cf = FogsMap[ ((int)(v.z + CameraZ))>>9 ][ ((int)(v.x + CameraX))>>9 ];
  35. if ((!cf) && CAMERAINFOG) { cf = CameraFogI; vinfog = FALSE; }
  36. } else cf = 127;
  37. if (! (CAMERAINFOG | cf) ) return 0;
  38. TFogEntity *fptr;
  39. fptr = &FogsList[cf];
  40. CurFogColor = fptr->fogRGB;
  41. float d = VectorLength(v);
  42. v.y+=CameraY;
  43. float fla= -(v.y - fptr->YBegin*ctHScale) / ctHScale;
  44. if (!vinfog) if (fla>0) fla=0;
  45. float flb = -(CameraY - fptr->YBegin*ctHScale) / ctHScale;
  46. if (!CAMERAINFOG) if (flb>0) flb=0;
  47. if (fla<0 && flb<0) return 0;
  48. if (fla<0) { d*= flb / (flb-fla); fla = 0; }
  49. if (flb<0) { d*= fla / (fla-flb); flb = 0; }
  50. float fl = (fla + flb);
  51. fl *= (d+(fptr->Transp/2)) / fptr->Transp;
  52. return min(fl, fptr->FLimit);
  53. }
  54. void PreCashGroundModel()
  55. {
  56. SKYDTime = RealTime>>1;
  57. int x,y;
  58. int kx = SKYDTime & 255;
  59. int ky = SKYDTime & 255;
  60. int SKYDT = SKYDTime>>8;
  61. VideoCX16 = VideoCX * 16;
  62. VideoCY16 = VideoCY * 16;
  63. VideoCXf = VideoCX;
  64. VideoCYf = VideoCY;
  65. CameraW16 = CameraW * 16;
  66. CameraH16 = CameraH * 16;
  67. BOOL FogFound = FALSE;
  68. NeedWater = FALSE;
  69. MapMinY = 10241024;
  70. Vector3d rv;
  71. for (y=-(ctViewR+3); y<(ctViewR+3); y++)
  72. for (x=-(ctViewR+3); x<(ctViewR+3); x++) {
  73. int r = max((max(y,-y)), (max(x,-x)));
  74. if ( r>ctViewR1+4 )
  75. if ( (x & 1) + (y & 1) > 0) continue;
  76. int xx = (CCX + x) & 1023;
  77. int yy = (CCY + y) & 1023;
  78. v[0].x = xx*256 - CameraX;
  79. v[0].z = yy*256 - CameraZ;
  80. v[0].y = (float)((int)HMap[yy][xx])*ctHScale - CameraY;
  81. //========= water section ===========//
  82. //if (RunMode)
  83. if ((FMap[yy][xx] & fmWaterA)>0) {
  84. rv = v[0];
  85. rv.y = WaterList[ WMap[yy][xx] ].wlevel*ctHScale - CameraY;
  86. float wdelta = (float)f_sin(-pi/2 + RandomMap[yy & 31][xx & 31]/128+RealTime/200.f);
  87. if ( (FMap[yy][xx] & fmWater) && (r < ctViewR1-4)) {
  88. rv.x+=(float)f_sin(xx+yy + RealTime/200.f) * 16.f;
  89. rv.z+=(float)f_sin(pi/2.f + xx+yy + RealTime/200.f) * 16.f;
  90. }
  91. rv = RotateVector(rv);
  92. VMap2[128+y][128+x].v = rv;
  93. if (fabs(rv.x) > -rv.z + 1524) {
  94. VMap2[128+y][128+x].DFlags = 128;
  95. } else {
  96. NeedWater = TRUE;
  97. VMap2[128+y][128+x].Light = 168-(int)(wdelta*24);
  98. float Alpha;
  99. if (UNDERWATER) {
  100. Alpha = 160 - VectorLength(rv)* 160 / 220 / ctViewR;
  101. if (Alpha<10) Alpha=10;
  102. } else
  103. if (r < ctViewR1+2) {
  104. int wi = WMap[yy][xx];
  105. Alpha = (float)((WaterList[wi].wlevel - HMap[yy][xx])*2+4)*WaterList[wi].transp;
  106. Alpha+=VectorLength(rv) / 256;
  107. Alpha+=wdelta*2;
  108. if (Alpha<0) Alpha=0;
  109. Vector3d va = v[0];
  110. NormVector(va,1.0f); va.y=-va.y;
  111. if (va.y<0) va.y=0;
  112. Alpha*=6.f/(va.y+0.1f);
  113. if (Alpha>255) Alpha=255.f;
  114. } else Alpha = 255.f;
  115. VMap2[128+y][128+x].ALPHA=(int)Alpha;
  116. VMap2[128+y][128+x].Fog = 0;
  117. if (rv.z>-256.0) VMap2[128+y][128+x].DFlags=128; else {
  118. #ifdef _soft
  119. VMap2[128+y][128+x].scrx = VideoCX - (int)(rv.x / rv.z * CameraW);
  120. VMap2[128+y][128+x].scry = VideoCY + (int)(rv.y / rv.z * CameraH);
  121. int DF = 0;
  122. if (VMap2[128+y][128+x].scrx < 0) DF+=1;
  123. if (VMap2[128+y][128+x].scrx > WinEX) DF+=2;
  124. if (VMap2[128+y][128+x].scry < 0) DF+=4;
  125. if (VMap2[128+y][128+x].scry > WinEY) DF+=8;
  126. #endif
  127. #ifdef _3dfx
  128. VMap2[128+y][128+x].scrx = VideoCX16 - (int)(rv.x / rv.z * CameraW16);
  129. VMap2[128+y][128+x].scry = VideoCY16 + (int)(rv.y / rv.z * CameraH16);
  130. int DF = 0;
  131. if (VMap2[128+y][128+x].scrx < 0) DF+=1;
  132. if (VMap2[128+y][128+x].scrx > WinEX*16) DF+=2;
  133. if (VMap2[128+y][128+x].scry < 0) DF+=4;
  134. if (VMap2[128+y][128+x].scry > WinEY*16) DF+=8;
  135. #endif
  136. #ifdef _d3d
  137. VMap2[128+y][128+x].scrx = VideoCXf - (rv.x / rv.z * CameraW);
  138. VMap2[128+y][128+x].scry = VideoCYf + (rv.y / rv.z * CameraH);
  139. int DF = 0;
  140. if (VMap2[128+y][128+x].scrx < 0) DF+=1;
  141. if (VMap2[128+y][128+x].scrx > WinEX) DF+=2;
  142. if (VMap2[128+y][128+x].scry < 0) DF+=4;
  143. if (VMap2[128+y][128+x].scry > WinEY) DF+=8;
  144. #endif
  145. VMap2[128+y][128+x].DFlags = DF;
  146. }
  147. }
  148. }
  149. #ifdef _soft
  150. #else
  151. if (r>ctViewR1-20 && r<ctViewR1+8)
  152. if ( (x & 1) + (y & 1) > 0)
  153. {
  154. float y1;
  155. float zd = (float)sqrt(v[0].x*v[0].x + v[0].z*v[0].z) / 256.f;
  156. float k = (zd - (ctViewR1-8)) / 4.f;
  157. if (k<0) k=0;
  158. if (k>1) k=1;
  159. if ((y & 1)==0) y1 = (float)((int)HMap[yy][xx-1]+HMap[yy][xx+1])*ctHScale/2 - CameraY; else
  160. if ((x & 1)==0) y1 = (float)((int)HMap[yy-1][xx]+HMap[yy+1][xx])*ctHScale/2 - CameraY; else
  161. y1 = (float)((int)HMap[yy-1][xx-1]+HMap[yy+1][xx+1])*ctHScale/2 - CameraY;
  162. v[0].y = ((v[0].y+2) * (1-k) + (y1+8) * k);
  163. }
  164. #endif
  165. if ( (x & 1) + (y & 1) > 0)
  166. if (RunMode) {
  167. float y1;
  168. if ((y & 1)==0) y1 = (float)((int)HMap[yy][xx-1]+HMap[yy][xx+1])*ctHScale/2 - CameraY; else
  169. if ((x & 1)==0) y1 = (float)((int)HMap[yy-1][xx]+HMap[yy+1][xx])*ctHScale/2 - CameraY; else
  170. y1 = (float)((int)HMap[yy-1][xx-1]+HMap[yy+1][xx+1])*ctHScale/2 - CameraY;
  171. v[0].y = y1;
  172. }
  173. rv = RotateVector(v[0]);
  174. if (fabs(rv.x * FOVK) > -rv.z + 1600) {
  175. VMap[128+y][128+x].v = rv;
  176. VMap[128+y][128+x].DFlags = 128;
  177. continue;
  178. }
  179. if (HARD3D)
  180. if ( ((FMap[yy][xx] & fmWater)==0) || UNDERWATER)
  181. VMap[128+y][128+x].Fog = CalcFogLevel(v[0]); else
  182. VMap[128+y][128+x].Fog = 0;
  183. VMap[128+y][128+x].ALPHA = 255;
  184. v[0]=rv;
  185. if (v[0].z<1024)
  186. if (FOGENABLE)
  187. if (FogsMap[yy>>1][xx>>1]) FogFound = TRUE;
  188. VMap[128+y][128+x].v = v[0];
  189. int DF = 0;
  190. int db = 0;
  191. if (v[0].z<256) {
  192. if (Clouds) {
  193. int shmx = (xx + SKYDT) & 127;
  194. int shmy = (yy + SKYDT) & 127;
  195. int db1 = SkyMap[shmy * 128 + shmx ];
  196. int db2 = SkyMap[shmy * 128 + ((shmx+1) & 127) ];
  197. int db3 = SkyMap[((shmy+1) & 127) * 128 + shmx ];
  198. int db4 = SkyMap[((shmy+1) & 127) * 128 + ((shmx+1) & 127) ];
  199. db = (db1 * (256 - kx) + db2 * kx) * (256-ky) +
  200. (db3 * (256 - kx) + db4 * kx) * ky;
  201. db>>=17;
  202. db = db - 40;
  203. if (db<0) db=0;
  204. if (db>48) db=48;
  205. }
  206. int clt = LMap[yy][xx];
  207. clt= max(64, clt-db);
  208. VMap[128+y][128+x].Light = clt;
  209. }
  210. if (v[0].z>-256.0) DF+=128; else {
  211. #ifdef _soft
  212. VMap[128+y][128+x].scrx = VideoCX - (int)(v[0].x / v[0].z * CameraW);
  213. VMap[128+y][128+x].scry = VideoCY + (int)(v[0].y / v[0].z * CameraH);
  214. if (VMap[128+y][128+x].scrx < 0) DF+=1;
  215. if (VMap[128+y][128+x].scrx > WinEX) DF+=2;
  216. if (VMap[128+y][128+x].scry < 0) DF+=4;
  217. if (VMap[128+y][128+x].scry > WinEY) DF+=8;
  218. #endif
  219. #ifdef _3dfx
  220. VMap[128+y][128+x].scrx = VideoCX16 - (int)(v[0].x / v[0].z * CameraW16);
  221. VMap[128+y][128+x].scry = VideoCY16 + (int)(v[0].y / v[0].z * CameraH16);
  222. if (VMap[128+y][128+x].scrx < 0) DF+=1;
  223. if (VMap[128+y][128+x].scrx > WinEX*16) DF+=2;
  224. if (VMap[128+y][128+x].scry < 0) DF+=4;
  225. if (VMap[128+y][128+x].scry > WinEY*16) DF+=8;
  226. #endif
  227. #ifdef _d3d
  228. VMap[128+y][128+x].scrx = VideoCXf - (v[0].x / v[0].z * CameraW);
  229. VMap[128+y][128+x].scry = VideoCYf + (v[0].y / v[0].z * CameraH);
  230. if (VMap[128+y][128+x].scrx < 0) DF+=1;
  231. if (VMap[128+y][128+x].scrx > WinEX) DF+=2;
  232. if (VMap[128+y][128+x].scry < 0) DF+=4;
  233. if (VMap[128+y][128+x].scry > WinEY) DF+=8;
  234. #endif
  235. }
  236. VMap[128+y][128+x].DFlags = DF;
  237. }
  238. FOGON = FogFound || UNDERWATER;
  239. }
  240. void AddShadowCircle(int x, int y, int R, int D)
  241. {
  242. if (UNDERWATER) return;
  243. int cx = x / 256;
  244. int cy = y / 256;
  245. int cr = 1 + R / 256;
  246. for (int yy=-cr; yy<=cr; yy++)
  247. for (int xx=-cr; xx<=cr; xx++) {
  248. int tx = (cx+xx)*256;
  249. int ty = (cy+yy)*256;
  250. int r = (int)sqrt( (tx-x)*(tx-x) + (ty-y)*(ty-y) );
  251. if (r>R) continue;
  252. VMap[cy+yy - CCY + 128][cx+xx - CCX + 128].Light-= D * (R-r) / R;
  253. if (VMap[cy+yy - CCY + 128][cx+xx - CCX + 128].Light < 32)
  254. VMap[cy+yy - CCY + 128][cx+xx - CCX + 128].Light = 32;
  255. }
  256. }
  257. void DrawScene()
  258. {
  259. dFacesCount = 0;
  260. ca = (float)f_cos(CameraAlpha);
  261. sa = (float)f_sin(CameraAlpha);
  262. cb = (float)f_cos(CameraBeta);
  263. sb = (float)f_sin(CameraBeta);
  264. CCX = ((int)CameraX / 512) * 2;
  265. CCY = ((int)CameraZ / 512) * 2;
  266. PreCashGroundModel();
  267. #ifdef _soft
  268. CreateChRenderList();
  269. #endif
  270. RenderSkyPlane();
  271. cb = (float)f_cos(CameraBeta);
  272. sb = (float)f_sin(CameraBeta);
  273. RenderGround();
  274. RenderModelsList();
  275. Render3DHardwarePosts();
  276. if (NeedWater) RenderWater();
  277. RenderElements();
  278. }
  279. void DrawOpticCross( int v)
  280. {
  281. int sx = VideoCX + (int)(rVertex[v].x / (-rVertex[v].z) * CameraW);
  282. int sy = VideoCY - (int)(rVertex[v].y / (-rVertex[v].z) * CameraH);
  283. if ( (fabs(VideoCX - sx) > WinW / 2) ||
  284. (fabs(VideoCY - sy) > WinH / 4) ) return;
  285. Render_Cross(sx, sy);
  286. }
  287. void ScanLifeForms()
  288. {
  289. int li = -1;
  290. float dm = (float)(ctViewR+2)*256;
  291. for (int c=0; c<ChCount; c++) {
  292. TCharacter *cptr = &Characters[c];
  293. if (!cptr->Health) continue;
  294. if (cptr->rpos.z > -512) continue;
  295. float d = (float)sqrt( cptr->rpos.x*cptr->rpos.x + cptr->rpos.y*cptr->rpos.y + cptr->rpos.z*cptr->rpos.z );
  296. if (d > ctViewR*256) continue;
  297. float r = (float)(fabs(cptr->rpos.x) + fabs(cptr->rpos.y)) / d;
  298. if (r > 0.15) continue;
  299. if (d<dm)
  300. if (!TraceLook(cptr->pos.x, cptr->pos.y+220, cptr->pos.z,
  301. CameraX, CameraY, CameraZ) ) {
  302. dm = d;
  303. li = c;
  304. }
  305. }
  306. if (li==-1) return;
  307. Render_LifeInfo(li);
  308. }
  309. void DrawPostObjects()
  310. {
  311. float b;
  312. TWeapon* wptr = &Weapon;
  313. Hardware_ZBuffer(FALSE);
  314. if (DemoPoint.DemoTime) goto SKIPWEAPON;
  315. GlassL = 0;
  316. if (BINMODE) {
  317. RenderNearModel(Binocular, 0, 0, 2*(216-72 * BinocularPower), 192, 0,0);
  318. ScanLifeForms();
  319. MapMode = FALSE;
  320. }
  321. //goto SKIPWIND;
  322. if (BINMODE || OPTICMODE) goto SKIPWIND;
  323. if (!TrophyMode)
  324. if (!KeyboardState[VK_CAPITAL] & 1) {
  325. BOOL lr = LOWRESTX;
  326. LOWRESTX = TRUE;
  327. VideoCX = WinW / 5;
  328. VideoCY = WinH - (WinH * 10 / 23);
  329. VideoCXf= VideoCX;
  330. VideoCYf= VideoCY;
  331. VideoCX16 = VideoCX * 16;
  332. VideoCY16 = VideoCY * 16;
  333. CreateMorphedModel(WindModel.mptr, &WindModel.Animation[0], (int)(Wind.speed*50.f), 1.0);
  334. RenderNearModel(WindModel.mptr, -10, -37, -96, 192, CameraAlpha-Wind.alpha,0);
  335. VideoCX = WinW - (WinW / 5);
  336. VideoCY = WinH - (WinH * 10 / 23);
  337. VideoCXf= VideoCX;
  338. VideoCYf= VideoCY;
  339. VideoCX16 = VideoCX * 16;
  340. VideoCY16 = VideoCY * 16;
  341. RenderNearModel(CompasModel, +8, -38, -96, 192, CameraAlpha,0);
  342. VideoCX = WinW / 2;
  343. VideoCY = WinH / 2;
  344. VideoCXf= VideoCX;
  345. VideoCYf= VideoCY;
  346. VideoCX16 = VideoCX * 16;
  347. VideoCY16 = VideoCY * 16;
  348. LOWRESTX = lr;
  349. }
  350. SKIPWIND:
  351. if (wptr->state == 0) goto SKIPWEAPON;
  352. MapMode = FALSE;
  353. wptr->shakel+= TimeDt / 10000.f;
  354. //wptr->shakel = 0;
  355. if (wptr->shakel > 4.0f) wptr->shakel = 4.0f;
  356. if (wptr->state == 1) {
  357. wptr->FTime+=TimeDt;
  358. if (wptr->FTime >= wptr->chinfo[CurrentWeapon].Animation[0].AniTime) {
  359. wptr->FTime = 0;
  360. wptr->state = 2;
  361. }
  362. }
  363. if (wptr->state == 4) {
  364. wptr->FTime+=TimeDt;
  365. if (wptr->FTime >= wptr->chinfo[CurrentWeapon].Animation[3].AniTime) {
  366. wptr->FTime = 0;
  367. wptr->state = 2;
  368. }
  369. }
  370. if (wptr->state == 2 && wptr->FTime>0) {
  371. wptr->FTime+=TimeDt;
  372. if (wptr->FTime >= wptr->chinfo[CurrentWeapon].Animation[1].AniTime) {
  373. wptr->FTime = 0;
  374. wptr->state = 2;
  375. if (WeapInfo[CurrentWeapon].Reload)
  376. if ( (ShotsLeft[CurrentWeapon] % WeapInfo[CurrentWeapon].Reload) == 0 )
  377. if ( (ShotsLeft[CurrentWeapon]>0) || (AmmoMag[CurrentWeapon]>0) )
  378. {
  379. wptr->state = 4;
  380. wptr->FTime = 1;
  381. AddVoicev(wptr->chinfo[CurrentWeapon].SoundFX[3].length,
  382. wptr->chinfo[CurrentWeapon].SoundFX[3].lpData, 256);
  383. }
  384. if (!ShotsLeft[CurrentWeapon])
  385. if (AmmoMag[CurrentWeapon]) {
  386. AmmoMag[CurrentWeapon]--;
  387. ShotsLeft[CurrentWeapon] = WeapInfo[CurrentWeapon].Shots;
  388. if (wptr->chinfo[CurrentWeapon].Animation[3].AniTime) {
  389. wptr->state = 4;
  390. wptr->FTime = 1;
  391. AddVoicev(wptr->chinfo[CurrentWeapon].SoundFX[3].length,
  392. wptr->chinfo[CurrentWeapon].SoundFX[3].lpData, 256);
  393. }
  394. }
  395. }
  396. }
  397. if (wptr->state == 3) {
  398. wptr->FTime+=TimeDt;
  399. if (wptr->FTime >= wptr->chinfo[CurrentWeapon].Animation[2].AniTime) {
  400. wptr->FTime = 0;
  401. wptr->state = 0;
  402. if (CurrentWeapon != TargetWeapon) {
  403. CurrentWeapon = TargetWeapon;
  404. HideWeapon();
  405. }
  406. goto SKIPWEAPON;
  407. }
  408. }
  409. if (!ShotsLeft[CurrentWeapon]) {
  410. HideWeapon();
  411. for (int w=0; w<10; w++)
  412. if (ShotsLeft[w]) { TargetWeapon=w; break; }
  413. }
  414. CreateMorphedModel(wptr->chinfo[CurrentWeapon].mptr,
  415. &wptr->chinfo[CurrentWeapon].Animation[wptr->state-1], wptr->FTime, 1.0);
  416. b = (float)f_sin((float)RealTime / 300.f) / 100.f;
  417. wpnDAlpha = wptr->shakel * (float)f_sin((float)RealTime / 300.f+pi/2) / 200.f;
  418. wpnDBeta = wptr->shakel * (float)f_sin((float)RealTime / 300.f) / 400.f;
  419. nv.z = 0;
  420. //==================== render weapon ===================//
  421. Vector3d v = Sun3dPos;
  422. Sun3dPos = RotateVector(Sun3dPos);
  423. CalcNormals(wptr->chinfo[CurrentWeapon].mptr, wptr->normals);
  424. if (GOUR)
  425. CalcGouraud(wptr->chinfo[CurrentWeapon].mptr, wptr->normals);
  426. else
  427. for (int c=0; c<1000; c++)
  428. wptr->chinfo[CurrentWeapon].mptr->VLight[0][c] = 0;
  429. if (HARD3D) wpnlight = 96 + GetLandLt(PlayerX, PlayerZ) / 4;
  430. else wpnlight = 200;
  431. RenderNearModel(wptr->chinfo[CurrentWeapon].mptr, 0, wpshy, wpshz, wpnlight,
  432. -wpnDAlpha, -wpnDBeta + wpnb);
  433. #ifdef _soft
  434. #else
  435. if (PHONG) {
  436. CalcPhongMapping(wptr->chinfo[CurrentWeapon].mptr, wptr->normals);
  437. RenderModelClipPhongMap(wptr->chinfo[CurrentWeapon].mptr, 0, wpshy, wpshz, -wpnDAlpha, -wpnDBeta+wpnb);
  438. }
  439. if (ENVMAP) {
  440. CalcEnvMapping(wptr->chinfo[CurrentWeapon].mptr, wptr->normals);
  441. RenderModelClipEnvMap(wptr->chinfo[CurrentWeapon].mptr, 0, wpshy, wpshz, -wpnDAlpha, -wpnDBeta+wpnb);
  442. }
  443. #endif
  444. Sun3dPos = v;
  445. //Render_Cross(VideoCX, VideoCY);
  446. if (OPTICMODE) DrawOpticCross(wptr->chinfo[CurrentWeapon].mptr->VCount-1);
  447. SKIPWEAPON:
  448. if (ChCallTime) {
  449. ChCallTime-=TimeDt;
  450. if (ChCallTime<0) ChCallTime=0;
  451. DrawPicture(WinW - 10 - DinoInfo[ AI_to_CIndex[TargetCall] ].CallIcon.W, 7,
  452. DinoInfo[ AI_to_CIndex[TargetCall] ].CallIcon);
  453. }
  454. Hardware_ZBuffer(TRUE);
  455. if (Weapon.state) {
  456. int y0 = 5;
  457. if (AmmoMag[CurrentWeapon]) {
  458. for (int bl=0; bl<WeapInfo[CurrentWeapon].Shots; bl++)
  459. DrawPicture(6 + bl*Weapon.BulletPic[CurrentWeapon].W, y0, Weapon.BulletPic[CurrentWeapon]);
  460. y0+=Weapon.BulletPic[CurrentWeapon].H+4;
  461. }
  462. for (int bl=0; bl<ShotsLeft[CurrentWeapon]; bl++)
  463. DrawPicture(6 + bl*Weapon.BulletPic[CurrentWeapon].W, y0, Weapon.BulletPic[CurrentWeapon]);
  464. }
  465. if (TrophyMode)
  466. DrawPicture( VideoCX - TrophyExit.W / 2, 2, TrophyExit);
  467. if (EXITMODE)
  468. DrawPicture( (WinW - ExitPic.W) / 2, (WinH - ExitPic.H) / 2, ExitPic);
  469. if (PAUSE)
  470. DrawPicture( (WinW - PausePic.W) / 2, (WinH - PausePic.H) / 2, PausePic);
  471. if (TrophyMode || TrophyTime)
  472. if (TrophyBody!=-1) {
  473. int x0 = WinW - TrophyPic.W - 16;
  474. int y0 = WinH - TrophyPic.H - 12;
  475. if (!TrophyMode)
  476. x0 = VideoCX - TrophyPic.W / 2;
  477. DrawPicture( x0, y0, TrophyPic);
  478. DrawTrophyText(x0, y0);
  479. if (TrophyTime) {
  480. TrophyTime-=TimeDt;
  481. if (TrophyTime<0) {
  482. TrophyTime=0;
  483. TrophyBody = -1;
  484. }
  485. }
  486. }
  487. }
  488. void SwitchMode(LPSTR lps, BOOL& b)
  489. {
  490. b = !b;
  491. char buf[200];
  492. if (b) wsprintf(buf,"%s is ON", lps);
  493. else wsprintf(buf,"%s is OFF", lps);
  494. MessageBeep(0xFFFFFFFF);
  495. AddMessage(buf);
  496. }
  497. void ChangeViewR(int d1, int d2, int d3)
  498. {
  499. char buf[200];
  500. ctViewR +=d1;
  501. ctViewR1+=d2;
  502. ctViewRM+=d3;
  503. if (ctViewR<20) ctViewR = 20;
  504. if (ctViewR>122) ctViewR = 122;
  505. if (ctViewR1 < 12) ctViewR1=12;
  506. if (ctViewR1 > ctViewR-10) ctViewR1=ctViewR-10;
  507. if (ctViewRM < 4) ctViewRM = 4;
  508. if (ctViewRM > 60) ctViewRM = 60;
  509. wsprintf(buf,"ViewR = %d (%d + %d) BMP at %d", ctViewR, ctViewR1, ctViewR-ctViewR1, ctViewRM);
  510. //MessageBeep(0xFFFFFFFF);
  511. AddMessage(buf);
  512. }
  513. void ChangeCall()
  514. {
  515. if (!TargetDino) return;
  516. if (ChCallTime)
  517. for (int t=0; t<32; t++) {
  518. TargetCall++;
  519. if (TargetCall>32) TargetCall=10;
  520. if (TargetDino & (1<<TargetCall)) break;
  521. }
  522. //wsprintf(logt,"Call: %s", DinoInfo[ AI_to_CIndex[TargetCall] ].Name);
  523. //AddMessage(logt);
  524. //CallLockTime+= 1024;
  525. ChCallTime = 2048;
  526. }
  527. void ToggleBinocular()
  528. {
  529. if (Weapon.state) return;
  530. if (UNDERWATER) return;
  531. if (!MyHealth) return;
  532. BINMODE = !BINMODE;
  533. MapMode = FALSE;
  534. }
  535. void ToggleRunMode()
  536. {
  537. RunMode = !RunMode;
  538. if (RunMode) AddMessage("Run mode is ON");
  539. else AddMessage("Run mode is OFF");
  540. }
  541. void ToggleCrouchMode()
  542. {
  543. CrouchMode = !CrouchMode;
  544. if (CrouchMode) AddMessage("Crouch mode is ON");
  545. else AddMessage("Crouch mode is OFF");
  546. }
  547. void ToggleMapMode()
  548. {
  549. if (!MyHealth) return;
  550. if (BINMODE) return;
  551. if (Weapon.state) return;
  552. MapMode = !MapMode;
  553. }
  554. void ShowShifts()
  555. {
  556. sprintf(logt, "Y=%3.4f Z=%3.4f A=%3.4f", wpshy/2, wpshz/2, wpnb*180/3.1415);
  557. AddMessage(logt);
  558. }
  559. LONG APIENTRY MainWndProc( HWND hWnd, UINT message, UINT wParam, LONG lParam)
  560. {
  561. BOOL A = (GetActiveWindow() == hWnd);
  562. if (A!=blActive) {
  563. blActive = A;
  564. if (blActive) SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS);
  565. else SetPriorityClass( GetCurrentProcess(), IDLE_PRIORITY_CLASS);
  566. if (!blActive) {
  567. ShutDown3DHardware();
  568. NeedRVM = TRUE;
  569. }
  570. if (blActive) {
  571. Audio_Restore();
  572. NeedRVM = TRUE;
  573. }
  574. }
  575. if (message == WM_KEYDOWN) {
  576. if ((int)wParam == KeyMap.fkBinoc) ToggleBinocular();
  577. if ((int)wParam == KeyMap.fkCCall) ChangeCall();
  578. if ((int)wParam == KeyMap.fkRun ) ToggleRunMode();
  579. if ((int)wParam == KeyMap.fkCrouch) ToggleCrouchMode();
  580. if ((int)wParam == cheatcode[cheati]) {
  581. cheati++;
  582. if (cheati>6) { cheati=0; SwitchMode("Debug mode",DEBUG); }
  583. } else cheati=0;
  584. }
  585. switch (message) {
  586. case WM_CREATE: return 0;
  587. case WM_KEYDOWN: {
  588. BOOL CTRL = (GetKeyState(VK_SHIFT) & 0x8000);
  589. switch( (int)wParam ) {
  590. case '1':
  591. case '2':
  592. case '3':
  593. case '4':
  594. case '5':
  595. case '6': {
  596. if (Weapon.FTime) break;
  597. int w = ((int)wParam ) - '1';
  598. if (!ShotsLeft[w]) {
  599. AddMessage("No weapon");
  600. break;
  601. }
  602. TargetWeapon = w;
  603. if (!Weapon.state)
  604. CurrentWeapon = TargetWeapon;
  605. HideWeapon();
  606. break;
  607. }
  608. case 'U': if (DEBUG) ChangeViewR(0, 0, -2); break;
  609. case 'I': if (DEBUG) ChangeViewR(0, 0, +2); break;
  610. case 'O': if (DEBUG) ChangeViewR(0, -2, 0); break;
  611. //case 'P': if (DEBUG) ChangeViewR(0, +2, 0); break;
  612. case 219: if (DEBUG) ChangeViewR(-2, 0, 0); break;
  613. case 221: if (DEBUG) ChangeViewR(+2, 0, 0); break;
  614. /*
  615. case '0': wpshy=0; wpshz=0; wpnb=0; break;
  616. case '7': if (CTRL) wpshy-=0.25; else wpshy+=0.25;
  617. ShowShifts();
  618. break;
  619. case '8': if (CTRL) wpshz-=0.25; else wpshz+=0.25;
  620. ShowShifts();
  621. break;
  622. case '9': if (CTRL) wpnb-=0.005; else wpnb+=0.005;
  623. ShowShifts();
  624. break;*/
  625. case 'S': if (DEBUG && CTRL) SwitchMode("Slow mode",SLOW);
  626. break;
  627. case 'T': if (DEBUG && CTRL) SwitchMode("Timer",TIMER);
  628. break;
  629. case 'M': if (CTRL) SwitchMode("Draw 3D models",MODELS);
  630. break;
  631. case 'F': if (CTRL) SwitchMode("V.Fog",FOGENABLE);
  632. break;
  633. case 'L': if (CTRL) SwitchMode("Fly",FLY);
  634. break;
  635. case 'C': if (CTRL) SwitchMode("Clouds shadow",Clouds);
  636. break;
  637. case 'E': if (CTRL) SwitchMode("Env.Mapping",ENVMAP);
  638. break;
  639. case 'G': if (CTRL) SwitchMode("Gour.Mapping",GOUR);
  640. break;
  641. case 'P': if (CTRL) SwitchMode("Phong Mapping",PHONG);
  642. else if (DEBUG) ChangeViewR(0, +2, 0);
  643. break;
  644. case VK_TAB:
  645. if (!TrophyMode) ToggleMapMode();
  646. break;
  647. case VK_PAUSE:
  648. PAUSE = !PAUSE; EXITMODE = FALSE; ResetMousePos();
  649. break;
  650. case 'N':
  651. if (EXITMODE) EXITMODE = FALSE;
  652. break;
  653. case VK_ESCAPE:
  654. if (TrophyMode)
  655. {
  656. SaveTrophy();
  657. ExitTime = 1;
  658. } else {
  659. if (PAUSE) PAUSE = FALSE;
  660. else EXITMODE = !EXITMODE;
  661. if (ExitTime) EXITMODE = FALSE;
  662. ResetMousePos();
  663. }
  664. break;
  665. case 'Y':
  666. case VK_RETURN:
  667. if (EXITMODE ) {
  668. if (MyHealth) ExitTime = 4000; else ExitTime = 1;
  669. EXITMODE = FALSE;
  670. }
  671. break;
  672. case 'R':
  673. if (TrophyBody!=-1) RemoveCurrentTrophy();
  674. if (EXITMODE) {
  675. LoadTrophy();
  676. RestartMode = TRUE;
  677. _GameState = 0;
  678. //DoHalt("");
  679. }
  680. break;
  681. case VK_F9:
  682. ShutDown3DHardware();
  683. AudioStop();
  684. DoHalt("");
  685. break;
  686. case VK_F12: SaveScreenShot(); break;
  687. } // switch
  688. break; }
  689. case WM_DESTROY:
  690. PostQuitMessage(0);
  691. break;
  692. /*
  693. case WM_PAINT:
  694. case WM_ERASEBKGND:
  695. case WM_NCPAINT : break;
  696. */
  697. /*case WM_PAINT: {
  698. PAINTSTRUCT ps;
  699. HDC hdc = BeginPaint(hWnd, &ps );
  700. EndPaint(hWnd, &ps);
  701. return 0;
  702. } */
  703. default:
  704. return (DefWindowProc(hWnd, message, wParam, lParam));
  705. }
  706. return 0;
  707. }
  708. BOOL CreateMainWindow()
  709. {
  710. PrintLog("Creating main window...");
  711. WNDCLASS wc;
  712. wc.style = CS_OWNDC;
  713. wc.lpfnWndProc = (WNDPROC)MainWndProc;
  714. wc.cbClsExtra = 0;
  715. wc.cbWndExtra = 0;
  716. wc.hInstance = hInst;
  717. wc.hIcon = wc.hIcon = LoadIcon(hInst,"ACTION");
  718. wc.hCursor = NULL;
  719. wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
  720. wc.lpszMenuName = NULL;
  721. //wc.lpfnWndProc = NULL;
  722. wc.lpszClassName = "HuntRenderWindow";
  723. if (!RegisterClass(&wc)) return FALSE;
  724. hwndMain = CreateWindow(
  725. "HuntRenderWindow","Carnivores 2 Renderer",
  726. WS_VISIBLE | WS_POPUP,
  727. 0, 0, 0, 0, NULL, NULL, hInst, NULL );
  728. if (hwndMain)
  729. PrintLog("Ok.\n");
  730. return TRUE;
  731. }
  732. void ProcessShoot()
  733. {
  734. //if (HeadBackR) return;
  735. if (!ShotsLeft[CurrentWeapon]) return;
  736. TWeapon *wptr = &Weapon;
  737. if (UNDERWATER) {
  738. HideWeapon();
  739. return; }
  740. if (wptr->state == 2 && wptr->FTime==0) {
  741. wptr->FTime = 1;
  742. HeadBackR=64;
  743. //if (HeadBackR>64) HeadBackR=64;
  744. AddVoicev(wptr->chinfo[CurrentWeapon].SoundFX[1].length,
  745. wptr->chinfo[CurrentWeapon].SoundFX[1].lpData, 256);
  746. TrophyRoom.Last.smade++;
  747. for (int s=0; s<=WeapInfo[CurrentWeapon].TraceC; s++) {
  748. float rA = 0;
  749. float rB = 0;
  750. rA = siRand(128) * 0.00010 * (2.f - WeapInfo[CurrentWeapon].Prec);
  751. rB = siRand(128) * 0.00010 * (2.f - WeapInfo[CurrentWeapon].Prec);
  752. float ca = (float)f_cos(PlayerAlpha + wpnDAlpha + rA);
  753. float sa = (float)f_sin(PlayerAlpha + wpnDAlpha + rA);
  754. float cb = (float)f_cos(PlayerBeta + wpnDBeta + rB);
  755. float sb = (float)f_sin(PlayerBeta + wpnDBeta + rB);
  756. nv.x=sa;
  757. nv.y=0;
  758. nv.z=-ca;
  759. nv.x*=cb;
  760. nv.y=-sb;
  761. nv.z*=cb;
  762. MakeShot(PlayerX, PlayerY+HeadY, PlayerZ,
  763. PlayerX+nv.x * 256*ctViewR,
  764. PlayerY+nv.y * 256*ctViewR + HeadY,
  765. PlayerZ+nv.z * 256*ctViewR);
  766. }
  767. Vector3d v;
  768. v.x = PlayerX;
  769. v.y = PlayerY;
  770. v.z = PlayerZ;
  771. MakeNoise(v, ctViewR*200 * WeapInfo[CurrentWeapon].Loud);
  772. ShotsLeft[CurrentWeapon]--;
  773. }
  774. }
  775. void ProcessSlide()
  776. {
  777. if (NOCLIP || UNDERWATER) return;
  778. float ch = GetLandQHNoObj(PlayerX, PlayerZ);
  779. float mh = ch;
  780. float chh;
  781. int sd = 0;
  782. chh=GetLandQHNoObj(PlayerX - 16, PlayerZ); if (chh<mh) { mh = chh; sd = 1; }
  783. chh=GetLandQHNoObj(PlayerX + 16, PlayerZ); if (chh<mh) { mh = chh; sd = 2; }
  784. chh=GetLandQHNoObj(PlayerX, PlayerZ - 16); if (chh<mh) { mh = chh; sd = 3; }
  785. chh=GetLandQHNoObj(PlayerX, PlayerZ + 16); if (chh<mh) { mh = chh; sd = 4; }
  786. chh=GetLandQHNoObj(PlayerX - 12, PlayerZ - 12); if (chh<mh) { mh = chh; sd = 5; }
  787. chh=GetLandQHNoObj(PlayerX + 12, PlayerZ - 12); if (chh<mh) { mh = chh; sd = 6; }
  788. chh=GetLandQHNoObj(PlayerX - 12, PlayerZ + 12); if (chh<mh) { mh = chh; sd = 7; }
  789. chh=GetLandQHNoObj(PlayerX + 12, PlayerZ + 12); if (chh<mh) { mh = chh; sd = 8; }
  790. if (!NOCLIP)
  791. if (mh<ch-16) {
  792. float delta = (ch-mh) / 4;
  793. if (sd == 1) { PlayerX -= delta; }
  794. if (sd == 2) { PlayerX += delta; }
  795. if (sd == 3) { PlayerZ -= delta; }
  796. if (sd == 4) { PlayerZ += delta; }
  797. delta*=0.7f;
  798. if (sd == 5) { PlayerX -= delta; PlayerZ -= delta; }
  799. if (sd == 6) { PlayerX += delta; PlayerZ -= delta; }
  800. if (sd == 7) { PlayerX -= delta; PlayerZ += delta; }
  801. if (sd == 8) { PlayerX += delta; PlayerZ += delta; }
  802. }
  803. }
  804. void ProcessPlayerMovement()
  805. {
  806. POINT ms;
  807. GetCursorPos(&ms);
  808. if (REVERSEMS) ms.y = -ms.y+VideoCY*2;
  809. rav += (float)(ms.x-VideoCX) * (OptMsSens+64) / 600.f / 192.f;
  810. rbv += (float)(ms.y-VideoCY) * (OptMsSens+64) / 600.f / 192.f;
  811. if (KeyFlags & kfStrafe)
  812. SSpeed+= (float)rav * 10; else
  813. PlayerAlpha += rav;
  814. PlayerBeta += rbv;
  815. rav/=(2.f + (float)TimeDt/20.f);
  816. rbv/=(2.f + (float)TimeDt/20.f);
  817. ResetMousePos();
  818. if ( !(KeyFlags & (kfForward | kfBackward)))
  819. if (VSpeed>0) VSpeed=max(0,VSpeed-DeltaT*2);
  820. else VSpeed=min(0,VSpeed+DeltaT*2);
  821. if ( !(KeyFlags & (kfSLeft | kfSRight)))
  822. if (SSpeed>0) SSpeed=max(0,SSpeed-DeltaT*2);
  823. else SSpeed=min(0,SSpeed+DeltaT*2);
  824. if (KeyFlags & kfForward) if (VSpeed>0) VSpeed+=DeltaT; else VSpeed+=DeltaT*4;
  825. if (KeyFlags & kfBackward) if (VSpeed<0) VSpeed-=DeltaT; else VSpeed-=DeltaT*4;
  826. if (KeyFlags & kfSRight ) if (SSpeed>0) SSpeed+=DeltaT; else SSpeed+=DeltaT*4;
  827. if (KeyFlags & kfSLeft ) if (SSpeed<0) SSpeed-=DeltaT; else SSpeed-=DeltaT*4;
  828. if (SWIM) {
  829. if (VSpeed > 0.25f) VSpeed = 0.25f;
  830. if (VSpeed <-0.25f) VSpeed =-0.25f;
  831. if (SSpeed > 0.25f) SSpeed = 0.25f;
  832. if (SSpeed <-0.25f) SSpeed =-0.25f;
  833. }
  834. if ( RunMode && (HeadY > 190.f) && (Weapon.state==0)) {
  835. if (VSpeed > 0.7f) VSpeed = 0.7f;
  836. if (VSpeed <-0.7f) VSpeed =-0.7f;
  837. if (SSpeed > 0.7f) SSpeed = 0.7f;
  838. if (SSpeed <-0.7f) SSpeed =-0.7f;
  839. } else {
  840. if (VSpeed > 0.3f) VSpeed = 0.3f;
  841. if (VSpeed <-0.3f) VSpeed =-0.3f;
  842. if (SSpeed > 0.30f) SSpeed = 0.30f;
  843. if (SSpeed <-0.30f) SSpeed =-0.30f;
  844. }
  845. if (KeyboardState [KeyMap.fkFire] & 128) ProcessShoot();
  846. if (KeyboardState [KeyMap.fkShow] & 128) HideWeapon();
  847. if (BINMODE) {
  848. if (KeyboardState[VK_ADD ] & 128) BinocularPower+=BinocularPower * TimeDt / 4000.f;
  849. if (KeyboardState[VK_SUBTRACT] & 128) BinocularPower-=BinocularPower * TimeDt / 4000.f;
  850. if (BinocularPower < 1.5f) BinocularPower = 1.5f;
  851. if (BinocularPower > 3.0f) BinocularPower = 3.0f;
  852. }
  853. if (KeyFlags & kfCall) MakeCall();
  854. if (DEBUG)
  855. if (KeyboardState [VK_CONTROL] & 128)
  856. if (KeyFlags & kfBackward) VSpeed =-8; else VSpeed = 8;
  857. if (KeyFlags & kfJump)
  858. if (YSpeed == 0 && !SWIM) {
  859. YSpeed = 600 + (float)fabs(VSpeed) * 600;
  860. AddVoicev(fxJump.length, fxJump.lpData, 256);
  861. }
  862. //========= rotation =========//
  863. if (KeyFlags & kfRight) PlayerAlpha+=DeltaT*1.5f;
  864. if (KeyFlags & kfLeft ) PlayerAlpha-=DeltaT*1.5f;
  865. if (KeyFlags & kfLookUp) PlayerBeta-=DeltaT;
  866. if (KeyFlags & kfLookDn) PlayerBeta+=DeltaT;
  867. //========= movement ==========//
  868. ca = (float)f_cos(PlayerAlpha);
  869. sa = (float)f_sin(PlayerAlpha);
  870. cb = (float)f_cos(PlayerBeta);
  871. sb = (float)f_sin(PlayerBeta);
  872. nv.x=sa;
  873. nv.y=0;
  874. nv.z=-ca;
  875. PlayerNv = nv;
  876. if (UNDERWATER || FLY) {
  877. nv.x*=cb;
  878. nv.y=-sb;
  879. nv.z*=cb;
  880. PlayerNv = nv;
  881. } else {
  882. PlayerNv.x*=cb;
  883. PlayerNv.y=-sb;
  884. PlayerNv.z*=cb;
  885. }
  886. Vector3d sv = nv;
  887. nv.x*=(float)TimeDt*VSpeed;
  888. nv.y*=(float)TimeDt*VSpeed;
  889. nv.z*=(float)TimeDt*VSpeed;
  890. sv.x*=(float)TimeDt*SSpeed;
  891. sv.y=0;
  892. sv.z*=(float)TimeDt*SSpeed;
  893. if (!TrophyMode) {
  894. TrophyRoom.Last.path+=(TimeDt*VSpeed) / 128.f;
  895. TrophyRoom.Last.time+=TimeDt/1000.f;
  896. }
  897. //if (SWIM & (VSpeed>0.1) & (sb>0.60)) HeadY-=40;
  898. int mvi = 1 + TimeDt / 16;
  899. for (int mvc = 0; mvc<mvi; mvc++) {
  900. PlayerX+=nv.x / mvi;
  901. PlayerY+=nv.y / mvi;
  902. PlayerZ+=nv.z / mvi;
  903. PlayerX-=sv.z / mvi;
  904. PlayerZ+=sv.x / mvi;
  905. if (!NOCLIP) CheckCollision(PlayerX, PlayerZ);
  906. if (PlayerY <= GetLandQHNoObj(PlayerX, PlayerZ)+16) {
  907. ProcessSlide();
  908. ProcessSlide(); }
  909. }
  910. if (PlayerY <= GetLandQHNoObj(PlayerX, PlayerZ)+16) {
  911. ProcessSlide();
  912. ProcessSlide(); }
  913. //===========================================================
  914. }
  915. void ProcessDemoMovement()
  916. {
  917. BINMODE = FALSE;
  918. PAUSE = FALSE;
  919. MapMode = FALSE;
  920. if (DemoPoint.DemoTime>6*1000)
  921. if (!PAUSE) {
  922. EXITMODE = TRUE;
  923. ResetMousePos();
  924. }
  925. if (DemoPoint.DemoTime>12*1000) {
  926. //ResetMousePos();
  927. //DemoPoint.DemoTime = 0;
  928. //LoadTrophy();
  929. DoHalt("");
  930. return; }
  931. VSpeed = 0.f;
  932. DemoPoint.pos = Characters[DemoPoint.CIndex].pos;
  933. DemoPoint.pos.y+=256;
  934. Vector3d nv = SubVectors(DemoPoint.pos, CameraPos);
  935. Vector3d pp = DemoPoint.pos;
  936. pp.y = CameraPos.y;
  937. float l = VectorLength( SubVectors(pp, CameraPos) );
  938. float base = 824;
  939. if (DemoPoint.DemoTime==1)
  940. if (l < base) DemoPoint.DemoTime = 2;
  941. NormVector(nv, 1.0f);
  942. if (DemoPoint.DemoTime == 1) {
  943. DeltaFunc(CameraX, DemoPoint.pos.x, (float)fabs(nv.x) * TimeDt * 3.f);
  944. DeltaFunc(CameraZ, DemoPoint.pos.z, (float)fabs(nv.z) * TimeDt * 3.f);
  945. } else {
  946. DemoPoint.DemoTime+=TimeDt;
  947. CameraAlpha+=TimeDt / 1224.f;
  948. ca = (float)f_cos(CameraAlpha);
  949. sa = (float)f_sin(CameraAlpha);
  950. //float k = (base - l) / 350.f;
  951. DeltaFunc(CameraX, DemoPoint.pos.x - sa * base, (float)TimeDt );
  952. DeltaFunc(CameraZ, DemoPoint.pos.z + ca * base, (float)TimeDt );
  953. }
  954. float b = FindVectorAlpha( (float)
  955. sqrt ( (DemoPoint.pos.x - CameraX)*(DemoPoint.pos.x - CameraX) +
  956. (DemoPoint.pos.z - CameraZ)*(DemoPoint.pos.z - CameraZ) ),
  957. DemoPoint.pos.y - CameraY - 400.f);
  958. if (b>pi) b = b - 2*pi;
  959. DeltaFunc(CameraBeta, -b , TimeDt / 4000.f);
  960. float h = GetLandQH(CameraX, CameraZ);
  961. DeltaFunc(CameraY, h+128, TimeDt / 8.f);
  962. if (CameraY < h + 80) CameraY = h + 80;
  963. }
  964. void ProcessControls()
  965. {
  966. int _KeyFlags = KeyFlags;
  967. KeyFlags = 0;
  968. GetKeyboardState(KeyboardState);
  969. if (KeyboardState [KeyMap.fkStrafe] & 128) KeyFlags+=kfStrafe;
  970. if (KeyboardState [KeyMap.fkForward ] & 128) KeyFlags+=kfForward;
  971. if (KeyboardState [KeyMap.fkBackward] & 128) KeyFlags+=kfBackward;
  972. if (KeyboardState [KeyMap.fkUp ] & 128) KeyFlags+=kfLookUp;
  973. if (KeyboardState [KeyMap.fkDown ] & 128) KeyFlags+=kfLookDn;
  974. if (KeyFlags & kfStrafe) {
  975. if (KeyboardState [KeyMap.fkLeft ] & 128) KeyFlags+=kfSLeft;
  976. if (KeyboardState [KeyMap.fkRight] & 128) KeyFlags+=kfSRight;
  977. } else {
  978. if (KeyboardState [KeyMap.fkLeft ] & 128) KeyFlags+=kfLeft;
  979. if (KeyboardState [KeyMap.fkRight] & 128) KeyFlags+=kfRight;
  980. }
  981. if (KeyboardState [KeyMap.fkSLeft] & 128) KeyFlags+=kfSLeft;
  982. if (KeyboardState [KeyMap.fkSRight] & 128) KeyFlags+=kfSRight;
  983. if (KeyboardState [KeyMap.fkJump] & 128) KeyFlags+=kfJump;
  984. if (KeyboardState [KeyMap.fkCall] & 128)
  985. if (!(_KeyFlags & kfCall)) KeyFlags+=kfCall;
  986. DeltaT = (float)TimeDt / 1000.f;
  987. if ( DemoPoint.DemoTime) ProcessDemoMovement();
  988. if (!DemoPoint.DemoTime) ProcessPlayerMovement();
  989. //======= Y movement ===========//
  990. HeadAlpha = HeadBackR / 20000;
  991. HeadBeta =-HeadBackR / 10000;
  992. if (HeadBackR) {
  993. HeadBackR-=DeltaT*(80 + (32-(float)fabs(HeadBackR - 32))*4);
  994. if (HeadBackR<=0) { HeadBackR = 0; HeadBSpeed = 0; }
  995. }
  996. if (CrouchMode | (UNDERWATER) ) {
  997. if (HeadY<110.f) HeadY = 110.f;
  998. HeadY-=DeltaT*(60 + (HeadY-110)*5);
  999. if (HeadY<110.f) HeadY = 110.f;
  1000. } else {
  1001. if (HeadY>220.f) HeadY = 220.f;
  1002. HeadY+=DeltaT*(60 + (220 - HeadY) * 5);
  1003. if (HeadY>220.f) HeadY = 220.f;
  1004. }
  1005. float h = GetLandQH(PlayerX, PlayerZ);
  1006. float hu = GetLandCeilH(PlayerX, PlayerZ)-64;
  1007. float hwater = GetLandUpH(PlayerX, PlayerZ);
  1008. if (DemoPoint.DemoTime) goto SKIPYMOVE;
  1009. if (!UNDERWATER) {
  1010. if (PlayerY>h) YSpeed-=DeltaT*3000;
  1011. } else
  1012. if (YSpeed<0) {
  1013. YSpeed+=DeltaT*4000;
  1014. if (YSpeed>0) YSpeed=0;
  1015. }
  1016. if (FLY) YSpeed=0;
  1017. PlayerY+=YSpeed*DeltaT;
  1018. if (PlayerY+HeadY>hu) {
  1019. if (YSpeed>0) YSpeed=-1;
  1020. PlayerY = hu - HeadY;
  1021. if (PlayerY<h) {
  1022. PlayerY = h;
  1023. HeadY = hu - PlayerY;
  1024. if (HeadY<110) HeadY = 110;
  1025. }
  1026. }
  1027. if (PlayerY<h) {
  1028. if (YSpeed<-800) HeadY+=YSpeed/100;
  1029. if (PlayerY < h-80) PlayerY = h - 80;
  1030. PlayerY+=(h-PlayerY+32)*DeltaT*4;
  1031. if (PlayerY>h) PlayerY = h;
  1032. if (YSpeed<-600)
  1033. AddVoicev(fxStep[(RealTime % 3)].length,
  1034. fxStep[(RealTime % 3)].lpData, 64);
  1035. YSpeed = 0;
  1036. }
  1037. SKIPYMOVE:
  1038. SWIM = FALSE;
  1039. if (!UNDERWATER && (KeyFlags & kfJump) )
  1040. if (PlayerY<hwater-148) { SWIM = TRUE; PlayerY = hwater-148; YSpeed = 0; }
  1041. float _s = stepdy;
  1042. if (SWIM) stepdy = (float)f_sin((float)RealTime / 360) * 20;
  1043. else stepdy = (float)min(1.f,fabs(VSpeed) + (float)fabs(SSpeed)) * (float)f_sin((float)RealTime / 80.f) * 22.f;
  1044. float d = stepdy - _s;
  1045. if (!UNDERWATER)
  1046. if (PlayerY<h+64)
  1047. if (d<0 && stepdd >= 0)
  1048. if (ONWATER) {
  1049. AddWCircle(CameraX, CameraZ, 1.2);
  1050. AddVoicev(fxStepW[(RealTime % 3)].length,
  1051. fxStepW[(RealTime % 3)].lpData, 64+(int)(VSpeed*30.f));
  1052. }
  1053. else
  1054. AddVoicev(fxStep[(RealTime % 3)].length,
  1055. fxStep[(RealTime % 3)].lpData, 24+(int)(VSpeed*50.f));
  1056. stepdd = d;
  1057. if (PlayerBeta> 1.46f) PlayerBeta= 1.46f;
  1058. if (PlayerBeta<-1.26f) PlayerBeta=-1.26f;
  1059. //======== set camera pos ===================//
  1060. if (!DemoPoint.DemoTime) {
  1061. CameraAlpha = PlayerAlpha + HeadAlpha;
  1062. CameraBeta = PlayerBeta + HeadBeta;
  1063. CameraX = PlayerX - sa * HeadBackR;
  1064. CameraY = PlayerY + HeadY + stepdy;// + 2024;
  1065. CameraZ = PlayerZ + ca * HeadBackR;
  1066. }
  1067. if (CLIP3D) {
  1068. if (sb<0) BackViewR = 320.f - 1024.f * sb;
  1069. else BackViewR = 320.f + 512.f * sb;
  1070. BackViewRR = 380 + (int)(1024 * fabs(sb));
  1071. if (UNDERWATER) BackViewR -= 512.f * (float)min(0,sb);
  1072. } else {
  1073. BackViewR = 300;
  1074. BackViewRR = 380;
  1075. }
  1076. //==================== SWIM & UNDERWATER =========================//
  1077. ONWATER = (GetLandUpH(CameraX, CameraZ) > GetLandH(CameraX, CameraZ)) &&
  1078. (PlayerY < GetLandUpH(CameraX, CameraZ));
  1079. if (UNDERWATER) {
  1080. UNDERWATER = (GetLandUpH(CameraX, CameraZ)-4>= CameraY);
  1081. if (!UNDERWATER) {
  1082. HeadY+=20; CameraY+=20;
  1083. AddVoicev(fxWaterOut.length, fxWaterOut.lpData, 256);
  1084. AddWCircle(CameraX, CameraZ, 2.0);
  1085. }
  1086. } else {
  1087. UNDERWATER = (GetLandUpH(CameraX, CameraZ)+28 >= CameraY);
  1088. if (UNDERWATER) {
  1089. HeadY-=20; CameraY-=20;
  1090. BINMODE = FALSE;
  1091. AddVoicev(fxWaterIn.length, fxWaterIn.lpData, 256);
  1092. AddWCircle(CameraX, CameraZ, 2.0);
  1093. }
  1094. }
  1095. if (MyHealth)
  1096. if (UNDERWATER) {
  1097. MyHealth-=TimeDt*12;
  1098. //if ( !(Takt & 31)) AddElements(CameraX + sa*64*cb, CameraY - 32 - sb*64, CameraZ - ca*64*cb, 4);
  1099. if (MyHealth<=0)
  1100. AddDeadBody(NULL, HUNT_BREATH);
  1101. }
  1102. if (UNDERWATER)
  1103. if (Weapon.state) HideWeapon();
  1104. if (!UNDERWATER) UnderWaterT = 0;
  1105. else if (UnderWaterT<512) UnderWaterT += TimeDt; else UnderWaterT = 512;
  1106. if (UNDERWATER) {
  1107. CameraW = (float)VideoCX*(1.25f + (1.f+(float)f_cos(RealTime/180.f)) / 30 + (1.f - (float)f_sin(UnderWaterT/512.f*pi/2)) / 1.5f );
  1108. CameraH = (float)VideoCX*(1.25f + (1.f+(float)f_sin(RealTime/180.f)) / 30 - (1.f - (float)f_sin(UnderWaterT/512.f*pi/2)) / 16.f );
  1109. CameraH *=(WinH*1.3333f / WinW);
  1110. CameraAlpha+=(float)f_cos(RealTime/360.f) / 120;
  1111. CameraBeta +=(float)f_sin(RealTime/360.f) / 100;
  1112. CameraY-=(float)f_sin(RealTime/360.f) * 4;
  1113. int w = WMap[(((int)(CameraZ))>>8) ][ (((int)(CameraX))>>8) ];
  1114. FogsList[127].YBegin = (float)WaterList[w].wlevel;
  1115. FogsList[127].fogRGB = WaterList[w].fogRGB;
  1116. } else {
  1117. CameraW = (float)VideoCX*1.25f;
  1118. CameraH = CameraW * (WinH*1.3333f / WinW);
  1119. }
  1120. if (BINMODE) {
  1121. CameraW*=BinocularPower;
  1122. CameraH*=BinocularPower;
  1123. } else if (OPTICMODE) {
  1124. CameraW*=3.0f;
  1125. CameraH*=3.0f;
  1126. }
  1127. FOVK = CameraW / (VideoCX*1.25f);
  1128. InitClips();
  1129. if (SWIM) {
  1130. if (!(Takt & 31)) AddWCircle(CameraX, CameraZ, 1.5);
  1131. CameraBeta -=(float)f_cos(RealTime/360.f) / 80;
  1132. PlayerX+=DeltaT*32;
  1133. PlayerZ+=DeltaT*32;
  1134. }
  1135. CameraFogI = FogsMap [((int)CameraZ)>>9][((int)CameraX)>>9];
  1136. if (UNDERWATER) CameraFogI=127;
  1137. if (FogsList[CameraFogI].YBegin*ctHScale> CameraY)
  1138. CAMERAINFOG = (CameraFogI>0);
  1139. else
  1140. CAMERAINFOG = FALSE;
  1141. if (CAMERAINFOG)
  1142. if (MyHealth)
  1143. if (FogsList[CameraFogI].Mortal) {
  1144. if (MyHealth>100000) MyHealth = 100000;
  1145. MyHealth-=TimeDt*64;
  1146. if (MyHealth<=0)
  1147. AddDeadBody(NULL, HUNT_EAT);
  1148. }
  1149. int CameraAmb = AmbMap [((int)CameraZ)>>9][((int)CameraX)>>9];
  1150. if (UNDERWATER) {
  1151. SetAmbient(fxUnderwater.length,
  1152. fxUnderwater.lpData,
  1153. 240);
  1154. Audio_SetEnvironment(8, ctViewR*256);
  1155. } else {
  1156. SetAmbient(Ambient[CameraAmb].sfx.length,
  1157. Ambient[CameraAmb].sfx.lpData,
  1158. Ambient[CameraAmb].AVolume);
  1159. Audio_SetEnvironment(Ambient[CameraAmb].rdata[0].REnvir, ctViewR*256);
  1160. Env = Ambient[CameraAmb].rdata[0].REnvir;
  1161. if (Ambient[CameraAmb].RSFXCount) {
  1162. Ambient[CameraAmb].RndTime-=TimeDt;
  1163. if (Ambient[CameraAmb].RndTime<=0) {
  1164. Ambient[CameraAmb].RndTime = (Ambient[CameraAmb].rdata[0].RFreq / 2 + rRand(Ambient[CameraAmb].rdata[0].RFreq)) * 1000;
  1165. int rr = (rand() % Ambient[CameraAmb].RSFXCount);
  1166. int r = Ambient[CameraAmb].rdata[rr].RNumber;
  1167. AddVoice3dv(RandSound[r].length, RandSound[r].lpData,
  1168. CameraX + siRand(4096),
  1169. CameraY + siRand(256),
  1170. CameraZ + siRand(4096) ,
  1171. Ambient[CameraAmb].rdata[rr].RVolume);
  1172. }
  1173. }
  1174. }
  1175. if (NOCLIP) CameraY+=1024;
  1176. //======= results ==========//
  1177. if (CameraBeta> 1.46f) CameraBeta= 1.46f;
  1178. if (CameraBeta<-1.26f) CameraBeta=-1.26f;
  1179. PlayerPos.x = PlayerX;
  1180. PlayerPos.y = PlayerY;
  1181. PlayerPos.z = PlayerZ;
  1182. CameraPos.x = CameraX;
  1183. CameraPos.y = CameraY;
  1184. CameraPos.z = CameraZ;
  1185. }
  1186. void ProcessGame()
  1187. {
  1188. if (RestartMode) {
  1189. ShutDown3DHardware();
  1190. AudioStop();
  1191. NeedRVM = TRUE;
  1192. }
  1193. if (!_GameState) {
  1194. PrintLog("Entered game\n");
  1195. ReInitGame();
  1196. while (ShowCursor(FALSE)>=0);
  1197. }
  1198. _GameState = 1;
  1199. if (NeedRVM) {
  1200. SetWindowPos(hwndMain, HWND_TOP, 0,0,0,0, SWP_SHOWWINDOW);
  1201. SetFocus(hwndMain);
  1202. Activate3DHardware();
  1203. NeedRVM = FALSE;
  1204. }
  1205. ProcessSyncro();
  1206. if (!PAUSE || !MyHealth) {
  1207. ProcessControls();
  1208. AudioSetCameraPos(CameraX, CameraY, CameraZ, CameraAlpha, CameraBeta);
  1209. Audio_UploadGeometry();
  1210. // AnimateCharacters();
  1211. AnimateProcesses();
  1212. }
  1213. if (DEBUG || ObservMode || TrophyMode)
  1214. if (MyHealth) MyHealth = MAX_HEALTH;
  1215. if (DEBUG) ShotsLeft[CurrentWeapon] = WeapInfo[CurrentWeapon].Shots;
  1216. DrawScene();
  1217. if (!TrophyMode)
  1218. if (MapMode) DrawHMap();
  1219. DrawPostObjects();
  1220. ShowControlElements();
  1221. ShowVideo();
  1222. }
  1223. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  1224. LPSTR lpszCmdLine, int nCmdShow)
  1225. {
  1226. MSG msg;
  1227. hInst = hInstance;
  1228. CreateLog();
  1229. CreateMainWindow();
  1230. Init3DHardware();
  1231. InitEngine();
  1232. InitAudioSystem(hwndMain, hlog, OptSound);
  1233. StartLoading();
  1234. PrintLoad("Loading...");
  1235. PrintLog("== Loading resources ==\n");
  1236. hcArrow = LoadCursor(NULL, IDC_ARROW);
  1237. PrintLog("Loading common resources:");
  1238. PrintLoad("Loading common resources...");
  1239. if (OptDayNight==2)
  1240. LoadModelEx(SunModel, "HUNTDAT\\MOON.3DF");
  1241. else
  1242. LoadModelEx(SunModel, "HUNTDAT\\SUN2.3DF");
  1243. LoadModelEx(CompasModel, "HUNTDAT\\COMPAS.3DF");
  1244. LoadModelEx(Binocular, "HUNTDAT\\BINOCUL.3DF");
  1245. LoadCharacterInfo(WCircleModel , "HUNTDAT\\WCIRCLE2.CAR");
  1246. LoadCharacterInfo(ShipModel, "HUNTDAT\\ship2a.car");
  1247. LoadCharacterInfo(WindModel, "HUNTDAT\\WIND.CAR");
  1248. LoadWav("HUNTDAT\\SOUNDFX\\a_underw.wav", fxUnderwater);
  1249. LoadWav("HUNTDAT\\SOUNDFX\\STEPS\\hwalk1.wav", fxStep[0]);
  1250. LoadWav("HUNTDAT\\SOUNDFX\\STEPS\\hwalk2.wav", fxStep[1]);
  1251. LoadWav("HUNTDAT\\SOUNDFX\\STEPS\\hwalk3.wav", fxStep[2]);
  1252. LoadWav("HUNTDAT\\SOUNDFX\\STEPS\\footw1.wav", fxStepW[0]);
  1253. LoadWav("HUNTDAT\\SOUNDFX\\STEPS\\footw2.wav", fxStepW[1]);
  1254. LoadWav("HUNTDAT\\SOUNDFX\\STEPS\\footw3.wav", fxStepW[2]);
  1255. LoadWav("HUNTDAT\\SOUNDFX\\hum_die1.wav", fxScream[0]);
  1256. LoadWav("HUNTDAT\\SOUNDFX\\hum_die2.wav", fxScream[1]);
  1257. LoadWav("HUNTDAT\\SOUNDFX\\hum_die3.wav", fxScream[2]);
  1258. LoadWav("HUNTDAT\\SOUNDFX\\hum_die4.wav", fxScream[3]);
  1259. LoadPictureTGA(PausePic, "HUNTDAT\\MENU\\pause.tga"); conv_pic(PausePic);
  1260. LoadPictureTGA(ExitPic, "HUNTDAT\\MENU\\exit.tga"); conv_pic(ExitPic);
  1261. LoadPictureTGA(TrophyExit, "HUNTDAT\\MENU\\trophy_e.tga"); conv_pic(TrophyExit);
  1262. LoadPictureTGA(MapPic, "HUNTDAT\\MENU\\mapframe.tga"); conv_pic(MapPic);
  1263. LoadPictureTGA(TFX_ENVMAP, "HUNTDAT\\FX\\envmap.tga"); ApplyAlphaFlags(TFX_ENVMAP.lpImage, TFX_ENVMAP.W*TFX_ENVMAP.W);
  1264. LoadPictureTGA(TFX_SPECULAR, "HUNTDAT\\FX\\specular.tga"); ApplyAlphaFlags(TFX_SPECULAR.lpImage, TFX_SPECULAR.W*TFX_SPECULAR.W);
  1265. PrintLog(" Done.\n");
  1266. PrintLoad("Loading area...");
  1267. LoadResources();
  1268. PrintLoad("Starting game...");
  1269. PrintLog("Loading area: Done.\n");
  1270. EndLoading();
  1271. ProcessSyncro();
  1272. blActive = TRUE;
  1273. PrintLog("Entering messages loop.\n");
  1274. for( ; ; )
  1275. if( PeekMessage( &msg, NULL, NULL, NULL, PM_REMOVE ) ) {
  1276. if (msg.message == WM_QUIT) break;
  1277. TranslateMessage( &msg );
  1278. DispatchMessage( &msg );
  1279. } else {
  1280. if (QUITMODE==1) {
  1281. ShutDown3DHardware();
  1282. Audio_Shutdown();
  1283. DestroyWindow(hwndMain);
  1284. QUITMODE=2;
  1285. }
  1286. if (!QUITMODE)
  1287. if (blActive) ProcessGame();
  1288. else Sleep(100);
  1289. }
  1290. ShutDownEngine();
  1291. ShowCursor(TRUE);
  1292. PrintLog("Game normal shutdown.\n");
  1293. CloseLog();
  1294. return msg.wParam;
  1295. }