C5_ACT2.C 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. /* Catacomb Armageddon Source Code
  2. * Copyright (C) 1993-2014 Flat Rock Software
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. // C3_PLAY.C
  19. #include "DEF.H"
  20. #pragma hdrstop
  21. /*
  22. =============================================================================
  23. LOCAL CONSTANTS
  24. =============================================================================
  25. */
  26. void SpawnSkeleton(int tilex, int tiley);
  27. #if 0
  28. #define MSHOTDAMAGE 2
  29. #define MSHOTSPEED 10000
  30. #define ESHOTDAMAGE 1
  31. #define ESHOTSPEED 5000
  32. #define SSHOTDAMAGE 3
  33. #define SSHOTSPEED 6500
  34. #define RANDOM_ATTACK 20
  35. #endif
  36. /*
  37. =============================================================================
  38. GLOBAL VARIABLES
  39. =============================================================================
  40. */
  41. boolean ShootPlayer (objtype *ob, short obclass, short speed, statetype *state);
  42. void T_ShootPlayer(objtype *ob);
  43. /*
  44. =============================================================================
  45. LOCAL VARIABLES
  46. =============================================================================
  47. */
  48. /*
  49. =============================================================================
  50. SKELETON IN WALL
  51. =============================================================================
  52. */
  53. void T_WallSkeleton(objtype *ob);
  54. statetype s_wallskel = {0,40,T_WallSkeleton,&s_wallskel};
  55. statetype s_wallskel2 = {0,1,NULL,NULL};
  56. enum wskel_modes {ws_wall1,ws_wall2,ws_wall3,ws_exit};
  57. //enum wskel_modes {ws_wall1,ws_exit};
  58. #define wskel_mode ob->temp1
  59. #define wskel_delay ob->temp2
  60. #define wskel_base ob->angle
  61. #define wskel_wallx ob->hitpoints
  62. #define wskel_wally ob->speed
  63. /*
  64. ===============
  65. =
  66. = SpawnWallSkeleton
  67. =
  68. ===============
  69. */
  70. void SpawnWallSkeleton(int tilex, int tiley)
  71. {
  72. char xofs[] = {0,0,-1,+1};
  73. char yofs[] = {-1,+1,0,0};
  74. objtype *ob;
  75. int wallx=tilex,wally=tiley,wallbase,wallmode,loop;
  76. unsigned tile,current_delay;
  77. for (loop=0; loop<4; loop++)
  78. {
  79. tile = *(mapsegs[0]+farmapylookup[tiley+yofs[loop]]+tilex+xofs[loop]);
  80. switch (tile)
  81. {
  82. // case WALL_SKELETON_CODE:
  83. // case WALL_SKELETON_CODE+1:
  84. // case WALL_SKELETON_CODE+2:
  85. // wallmode = ws_wall1+(tile-WALL_SKELETON_CODE);
  86. // wallbase = WALL_SKELETON_CODE;
  87. // goto foundtile;
  88. // break;
  89. case 66:
  90. case 68:
  91. // case 21:
  92. wallmode = ws_wall1+(tile-66);
  93. wallbase = 66;
  94. goto foundtile;
  95. // break;
  96. case 67:
  97. case 69:
  98. wallmode = ws_wall1+(tile-67);
  99. wallbase = 67;
  100. goto foundtile;
  101. // break;
  102. }
  103. }
  104. return;
  105. foundtile:;
  106. wallx += xofs[loop];
  107. wally += yofs[loop];
  108. SpawnNewObj(tilex,tiley,&s_wallskel,PIXRADIUS*35);
  109. ob = new;
  110. new->obclass = wallskelobj;
  111. new->speed = 1900;
  112. new->flags &= ~of_shootable;
  113. new->hitpoints = 12;
  114. // new->tilex = wallx;
  115. // new->tiley = wally;
  116. wskel_wallx = wallx;
  117. wskel_wally = wally;
  118. wskel_base = wallbase;
  119. new->active = no;
  120. wskel_mode = wallmode;
  121. tile = *(mapsegs[2]+farmapylookup[wally]+wallx);
  122. if (tile)
  123. wskel_delay = (tile>>8)*30;
  124. else
  125. {
  126. current_delay = (2*60)+random(4*60);
  127. wskel_delay = zombie_base_delay+current_delay;
  128. zombie_base_delay += current_delay;
  129. if (zombie_base_delay > 8*60)
  130. zombie_base_delay = 0;
  131. }
  132. }
  133. /*
  134. ===============
  135. =
  136. = T_WallSkeleton
  137. =
  138. ===============
  139. */
  140. void T_WallSkeleton(objtype *ob)
  141. {
  142. int x=wskel_wallx,y=wskel_wally;
  143. wskel_delay -= realtics;
  144. if (wskel_delay > 0)
  145. return;
  146. switch (wskel_mode)
  147. {
  148. case ws_wall2:
  149. if ((wskel_base == 66) || (wskel_base == 67))
  150. wskel_mode++;
  151. case ws_wall1:
  152. case ws_wall3:
  153. (unsigned)actorat[x][y]
  154. = tilemap[x][y]
  155. = *(mapsegs[0]+farmapylookup[y]+x)
  156. = wskel_base+(wskel_mode-ws_wall1);
  157. wskel_mode++;
  158. wskel_delay = (120);
  159. ob->active = always;
  160. break;
  161. case ws_exit:
  162. (unsigned)actorat[x][y]
  163. = tilemap[x][y]
  164. = *(mapsegs[0]+farmapylookup[y]+x)
  165. = 21;
  166. // = wskel_base;
  167. ob->tilex = ob->x >> TILESHIFT;
  168. ob->tiley = ob->y >> TILESHIFT;
  169. ob->obclass = skeletonobj;
  170. ob->speed = 2036;
  171. ob->flags |= of_shootable;
  172. ob->hitpoints = 12;
  173. ob->state = &s_skel_1;
  174. ob->ticcount = ob->state->tictime;
  175. break;
  176. }
  177. }
  178. /*
  179. =============================================================================
  180. SKELETONS
  181. =============================================================================
  182. */
  183. void T_Skeleton(objtype *ob);
  184. statetype s_skel_pause = {SKELETON_1PIC,40,NULL,&s_skel_2};
  185. statetype s_skel_1 = {SKELETON_1PIC,10,T_Skeleton,&s_skel_2};
  186. statetype s_skel_2 = {SKELETON_2PIC,10,T_Skeleton,&s_skel_3};
  187. statetype s_skel_3 = {SKELETON_3PIC,10,T_Skeleton,&s_skel_4};
  188. statetype s_skel_4 = {SKELETON_4PIC,10,T_Skeleton,&s_skel_1};
  189. statetype s_skel_attack1 = {SKELETON_ATTACK_1PIC,12,NULL,&s_skel_attack2};
  190. statetype s_skel_attack2 = {SKELETON_ATTACK_2PIC,12,NULL,&s_skel_attack3};
  191. statetype s_skel_attack3 = {SKELETON_ATTACK_3PIC,12,T_DoDamage,&s_skel_pause};
  192. statetype s_skel_ouch = {SKELETON_OUCHPIC,8,NULL,&s_skel_1};
  193. statetype s_skel_die1 = {SKELETON_OUCHPIC,18,NULL,&s_skel_die2};
  194. statetype s_skel_die2 = {SKELETON_DEATH_1PIC,18,NULL,&s_skel_die3};
  195. statetype s_skel_die3 = {SKELETON_DEATH_2PIC,18,NULL,&s_skel_die3};
  196. /*
  197. ===============
  198. =
  199. = SpawnSkeleton
  200. =
  201. ===============
  202. */
  203. void SpawnSkeleton(int tilex, int tiley)
  204. {
  205. SpawnNewObj(tilex,tiley,&s_skel_1,PIXRADIUS*35);
  206. new->obclass = skeletonobj;
  207. new->speed = 2036;
  208. new->flags |= of_shootable;
  209. new->hitpoints = EasyHitPoints(12);
  210. }
  211. /*
  212. ===============
  213. =
  214. = T_Skeleton
  215. =
  216. ===============
  217. */
  218. void T_Skeleton(objtype *ob)
  219. {
  220. if (Chase (ob,true) || (random(1000)<RANDOM_ATTACK))
  221. {
  222. ob->state = &s_skel_attack1;
  223. ob->ticcount = ob->state->tictime;
  224. return;
  225. }
  226. }
  227. /*
  228. =============================================================================
  229. EYE
  230. =============================================================================
  231. */
  232. void T_EyeMage (objtype *ob);
  233. boolean T_EyeShoot (objtype *ob, boolean eyeshot);
  234. void T_EyeShootPlayer (objtype *ob);
  235. extern statetype s_eye_shootplayer_1;
  236. extern statetype s_eye_shootplayer_2;
  237. statetype s_eye_pause = {EYE_WALK1PIC,40,NULL,&s_eye_2};
  238. statetype s_eye_1 = {EYE_WALK1PIC,20,T_EyeMage,&s_eye_2};
  239. statetype s_eye_2 = {EYE_WALK2PIC,20,T_EyeMage,&s_eye_3};
  240. statetype s_eye_3 = {EYE_WALK3PIC,20,T_EyeMage,&s_eye_4};
  241. statetype s_eye_4 = {EYE_WALK2PIC,20,T_EyeMage,&s_eye_1};
  242. statetype s_eye_shootplayer_1 = {EYE_SCOWLPIC,1,T_EyeShootPlayer,&s_eye_shootplayer_2};
  243. statetype s_eye_shootplayer_2 = {EYE_SCOWLPIC,20,NULL,&s_eye_1};
  244. statetype s_eye_ouch = {EYE_OUCH1PIC,8,NULL,&s_eye_ouch2};
  245. statetype s_eye_ouch2 = {EYE_OUCH2PIC,8,NULL,&s_eye_1};
  246. statetype s_eye_die1 = {EYE_DEATH1PIC,22,NULL,&s_eye_die2};
  247. statetype s_eye_die2 = {EYE_DEATH2PIC,22,NULL,&s_eye_die3};
  248. statetype s_eye_die3 = {EYE_DEATH2PIC,22,NULL,NULL};
  249. extern statetype s_eshot2;
  250. statetype s_eshot1 = {EYE_SHOT1PIC,8,&T_ShootPlayer,&s_eshot2};
  251. statetype s_eshot2 = {EYE_SHOT2PIC,8,&T_ShootPlayer,&s_eshot1};
  252. #define eye_mode ob->temp1
  253. #define eye_delay ob->temp2
  254. //-------------------------------------------------------------------------
  255. // SpawnEye()
  256. //-------------------------------------------------------------------------
  257. void SpawnEye(int tilex, int tiley)
  258. {
  259. objtype *ob;
  260. SpawnNewObj(tilex,tiley,&s_eye_1,PIXRADIUS*35);
  261. ob = new;
  262. new->obclass = eyeobj;
  263. new->speed = 1200;
  264. new->flags |= of_shootable;
  265. new->hitpoints = EasyHitPoints(15);
  266. eye_mode = em_other1;
  267. }
  268. //---------------------------------------------------------------------------
  269. // T_EyeShootPlayer
  270. //---------------------------------------------------------------------------
  271. void T_EyeShootPlayer (objtype *ob)
  272. {
  273. ShootPlayer(ob,eshotobj,ESHOTSPEED,&s_eshot1);
  274. }
  275. /*
  276. =============================================================================
  277. SUCCUBUS
  278. =============================================================================
  279. */
  280. void T_Succubus (objtype *ob);
  281. void T_SuccubusShot (objtype *ob);
  282. extern statetype s_succubus_pause;
  283. extern statetype s_succubus_walk1;
  284. extern statetype s_succubus_walk2;
  285. extern statetype s_succubus_walk3;
  286. extern statetype s_succubus_walk4;
  287. extern statetype s_succubus_shot1;
  288. extern statetype s_succubus_attack1;
  289. extern statetype s_succubus_attack2;
  290. extern statetype s_succubus_attack3;
  291. extern statetype s_succubus_death1;
  292. extern statetype s_succubus_death2;
  293. statetype s_succubus_pause = {SUCCUBUS_WALK2PIC,10,NULL,&s_succubus_walk3};
  294. statetype s_succubus_walk1 = {SUCCUBUS_WALK1PIC,10,T_EyeMage,&s_succubus_walk2};
  295. statetype s_succubus_walk2 = {SUCCUBUS_WALK2PIC,10,T_EyeMage,&s_succubus_walk3};
  296. statetype s_succubus_walk3 = {SUCCUBUS_WALK3PIC,10,T_EyeMage,&s_succubus_walk4};
  297. statetype s_succubus_walk4 = {SUCCUBUS_WALK4PIC,10,T_EyeMage,&s_succubus_walk1};
  298. statetype s_succubus_attack1 = {SUCCUBUS_ATTACK1PIC,15,NULL,&s_succubus_attack2};
  299. statetype s_succubus_attack2 = {SUCCUBUS_ATTACK1PIC,-1,T_SuccubusShot,&s_succubus_attack3};
  300. statetype s_succubus_attack3 = {SUCCUBUS_ATTACK2PIC,15,NULL,&s_succubus_pause};
  301. statetype s_succubus_ouch = {SUCCUBUS_OUCHPIC,15,NULL,&s_succubus_walk1};
  302. statetype s_succubus_death1 = {SUCCUBUS_DEATH1PIC,55,NULL,&s_succubus_death2};
  303. statetype s_succubus_death2 = {SUCCUBUS_DEATH2PIC,20,NULL,&s_succubus_death2};
  304. statetype s_succubus_shot1 = {SUCCUBUS_SHOT1PIC,12,&T_ShootPlayer,&s_succubus_shot1};
  305. /*
  306. ===============
  307. =
  308. = SpawnSuccubus
  309. =
  310. ===============
  311. */
  312. void SpawnSuccubus (int tilex, int tiley)
  313. {
  314. SpawnNewObj(tilex,tiley,&s_succubus_walk1,PIXRADIUS*30);
  315. new->obclass = succubusobj;
  316. new->speed = 2500;
  317. new->flags |= of_shootable;
  318. new->hitpoints = EasyHitPoints(12);
  319. }
  320. /*
  321. ===============
  322. =
  323. = T_SuccubusShot
  324. =
  325. ===============
  326. */
  327. void T_SuccubusShot (objtype *ob)
  328. {
  329. ShootPlayer(ob,sshotobj,ob->temp1 ? MSHOTSPEED : SSHOTSPEED,&s_succubus_shot1);
  330. // ob->state = &s_succubus_attack3;
  331. // ob->ticcount = ob->temp1 ? 7 : ob->state->tictime;
  332. }
  333. /*
  334. =============================================================================
  335. MAGE
  336. =============================================================================
  337. */
  338. void T_MageShoot (objtype *ob);
  339. extern statetype s_magepause;
  340. extern statetype s_mage1;
  341. extern statetype s_mage2;
  342. extern statetype s_mageattack1;
  343. extern statetype s_mageattack2;
  344. extern statetype s_mageattack3;
  345. extern statetype s_mageouch;
  346. extern statetype s_magedie1;
  347. extern statetype s_magedie2;
  348. statetype s_magepause = {MAGE1PIC,10,NULL,&s_mage2};
  349. statetype s_mage1 = {MAGE1PIC,20,T_EyeMage,&s_mage2};
  350. statetype s_mage2 = {MAGE2PIC,20,T_EyeMage,&s_mage1};
  351. //statetype s_mageattack1 = {MAGEATTACKPIC,20,NULL,&s_mageattack2};
  352. //statetype s_mageattack2 = {MAGEATTACKPIC,-1,T_MageShoot,&s_mageattack3};
  353. statetype s_mageattack3 = {MAGEATTACKPIC,30,NULL,&s_magepause};
  354. statetype s_mageouch = {MAGEOUCHPIC,10,NULL,&s_mage1};
  355. statetype s_magedie1 = {MAGEDIE1PIC,20,NULL,&s_magedie2};
  356. statetype s_magedie2 = {MAGEDIE2PIC,0,NULL,&s_magedie2};
  357. statetype s_mshot1 = {PSHOT1PIC,8,&T_ShootPlayer,&s_mshot2};
  358. statetype s_mshot2 = {PSHOT2PIC,8,&T_ShootPlayer,&s_mshot1};
  359. /*
  360. ===============
  361. =
  362. = SpawnMage
  363. =
  364. ===============
  365. */
  366. void SpawnMage (int tilex, int tiley)
  367. {
  368. SpawnNewObj(tilex,tiley,&s_mage1,PIXRADIUS*35);
  369. new->obclass = mageobj;
  370. new->speed = 3072;
  371. new->flags |= of_shootable;
  372. new->hitpoints = EasyHitPoints(12);
  373. }
  374. /*
  375. ===============
  376. =
  377. = T_EyeMage
  378. =
  379. = **********
  380. = ***NOTE*** This routine controls the thinks for the Eye, Mage, and Succubus.
  381. = **********
  382. =
  383. ===============
  384. */
  385. void T_EyeMage (objtype *ob)
  386. {
  387. fixed tempx,tempy;
  388. unsigned temp_tilex,temp_tiley;
  389. int angle;
  390. eye_delay -= realtics;
  391. if (eye_delay < 0)
  392. {
  393. eye_mode = random(em_dummy);
  394. eye_delay = (10*60);
  395. }
  396. tempx = player->x;
  397. tempy = player->y;
  398. temp_tilex = player->tilex;
  399. temp_tiley = player->tiley;
  400. switch (eye_mode)
  401. {
  402. case em_other1:
  403. case em_other2:
  404. case em_other3:
  405. case em_other4:
  406. player->x = ((long)other_x[eye_mode]<<TILESHIFT)+TILEGLOBAL/2;
  407. player->y = ((long)other_y[eye_mode]<<TILESHIFT)+TILEGLOBAL/2;
  408. player->tilex = other_x[eye_mode];
  409. player->tiley = other_y[eye_mode];
  410. break;
  411. }
  412. if (Chase(ob,true))
  413. eye_delay = 0;
  414. player->x = tempx;
  415. player->y = tempy;
  416. player->tilex = temp_tilex;
  417. player->tiley = temp_tiley;
  418. if (ob->obclass == mageobj) // do the mage shot
  419. {
  420. if (!random(10))
  421. if (ShootPlayer(ob,mshotobj,MSHOTSPEED,&s_mshot1))
  422. {
  423. ob->state = &s_mageattack3;
  424. ob->ticcount = ob->state->tictime;
  425. }
  426. }
  427. else
  428. if (ob->obclass == succubusobj) // do the succubus shot
  429. {
  430. angle = AngleNearPlayer(ob); // make sure angle is correct
  431. // - see AngleNearPlayer
  432. if (!random(5) && (angle != -1)) // if correct angle and random # attack
  433. {
  434. ob->state = &s_succubus_attack1; // change state to attack
  435. ob->ticcount = ob->state->tictime; // init ticcount - otherwise
  436. } // object may get hung in a
  437. } // endless state
  438. else
  439. {
  440. angle = AngleNearPlayer(ob); // do the eye shot
  441. if (!random(2) && (angle != -1))
  442. {
  443. ob->state = &s_eye_shootplayer_1;
  444. ob->ticcount = ob->state->tictime;
  445. }
  446. }
  447. }
  448. /*
  449. =============================================================================
  450. BUNNY
  451. =============================================================================
  452. */
  453. void T_HarmlessBunnyWalk(objtype *ob);
  454. void T_Bunny(objtype *ob);
  455. extern statetype s_bunny_left1;
  456. extern statetype s_bunny_left2;
  457. extern statetype s_bunny_left3;
  458. extern statetype s_bunny_right1;
  459. extern statetype s_bunny_right2;
  460. extern statetype s_bunny_right3;
  461. extern statetype s_bunny_meta1;
  462. extern statetype s_bunny_meta2;
  463. extern statetype s_bunny_walk1;
  464. extern statetype s_bunny_walk2;
  465. extern statetype s_bunny_attack1;
  466. extern statetype s_bunny_attack2;
  467. extern statetype s_bunny_pause;
  468. extern statetype s_bunny_death1;
  469. extern statetype s_bunny_death2;
  470. extern statetype s_bunny_death3;
  471. statetype s_bunny_left1 = {BUNNY_LEFT1PIC, 55, NULL, &s_bunny_left2};
  472. statetype s_bunny_left2 = {BUNNY_LEFT1PIC, 10, T_HarmlessBunnyWalk, &s_bunny_left1};
  473. statetype s_bunny_left3 = {BUNNY_LEFT2PIC, 30, NULL, &s_bunny_left1};
  474. statetype s_bunny_right1 = {BUNNY_RIGHT1PIC, 55, NULL, &s_bunny_right2};
  475. statetype s_bunny_right2 = {BUNNY_RIGHT1PIC, 10, T_HarmlessBunnyWalk, &s_bunny_right1};
  476. statetype s_bunny_right3 = {BUNNY_RIGHT2PIC, 30, NULL, &s_bunny_right1};
  477. statetype s_bunny_meta1 = {BUNNY_META1PIC, 30, NULL, &s_bunny_meta2};
  478. statetype s_bunny_meta2 = {BUNNY_META2PIC, 30, NULL, &s_bunny_walk1};
  479. statetype s_bunny_walk1 = {BUNNY_WALK1PIC, 25, T_Bunny, &s_bunny_walk2};
  480. statetype s_bunny_walk2 = {BUNNY_WALK2PIC, 25, T_Bunny, &s_bunny_walk1};
  481. statetype s_bunny_attack1 = {BUNNY_WALK1PIC, 25, NULL, &s_bunny_attack2};
  482. statetype s_bunny_attack2 = {BUNNY_WALK2PIC, 25, T_DoDamage, &s_bunny_walk1};
  483. statetype s_bunny_ouch = {BUNNY_OUCHPIC, 30, NULL, &s_bunny_pause};
  484. statetype s_bunny_pause = {BUNNY_WALK1PIC, 50, T_Bunny, &s_bunny_walk2};
  485. statetype s_bunny_death1 = {BUNNY_OUCHPIC, 40, NULL, &s_bunny_death2};
  486. statetype s_bunny_death2 = {BUNNY_DEATH1PIC, 50, NULL, &s_bunny_death3};
  487. statetype s_bunny_death3 = {BUNNY_DEATH2PIC, 20, NULL, &s_bunny_death3};
  488. #define bunny_dir_hop ob->temp1
  489. #define bunny_delay ob->temp2
  490. #define LEFTSIDE 0x8 // 1=left 0=right --side showing
  491. /*
  492. ===============
  493. =
  494. = SpawnBunny
  495. =
  496. ===============
  497. */
  498. void SpawnBunny (int tilex, int tiley)
  499. {
  500. SpawnNewObj(tilex,tiley,&s_bunny_left1,PIXRADIUS*35);
  501. new->obclass = hbunnyobj;
  502. new->speed = 1947;
  503. new->temp1 = (random(3))+2;
  504. new->temp2 = random(30);
  505. new->flags &= ~of_shootable;
  506. new->flags |= LEFTSIDE; //left side showing}
  507. }
  508. /*
  509. ===============
  510. =
  511. = T_HarmlessBunnyWalk
  512. =
  513. ===============
  514. */
  515. void T_HarmlessBunnyWalk(objtype *ob)
  516. {
  517. int valid_dir[8][2] = {{6,5}, {7,6}, {4,7}, {5,4}, {3,2}, {0,3}, {1,0}, {2,1}};
  518. long move;
  519. dirtype player_dir;
  520. fixed old_x, old_y;
  521. unsigned old_tilex, old_tiley;
  522. long old_distance;
  523. ob->temp2 -= realtics;
  524. if (ob->temp2 <= 0)
  525. {
  526. if (CheckHandAttack(ob))
  527. {
  528. ob->temp2 = -1;
  529. return;
  530. }
  531. actorat[ob->tilex][ob->tiley] = 0;
  532. ob->x = ((long)ob->tilex<<TILESHIFT)+TILEGLOBAL/2;
  533. ob->y = ((long)ob->tiley<<TILESHIFT)+TILEGLOBAL/2;
  534. ob->distance = TILEGLOBAL;
  535. ob->state = &s_bunny_meta1;
  536. ob->ticcount = ob->state->tictime;
  537. ob->obclass = bunnyobj;
  538. ob->flags |= of_shootable;
  539. ob->hitpoints = EasyHitPoints(10);
  540. ob->dir = nodir;
  541. ChaseThink(ob,true); // JTR - testing..
  542. return;
  543. }
  544. // The direction of the player isn't updated so it must be
  545. // calculated. This is done so the correct side (left/right)
  546. // of the bunny will be showed.
  547. if ((player->angle > 337) || (player->angle <= 22))
  548. player_dir = east;
  549. else
  550. if (player->angle <= 67)
  551. player_dir = northeast;
  552. else
  553. if (player->angle <= 112)
  554. player_dir = north;
  555. else
  556. if (player->angle <= 157)
  557. player_dir = northwest;
  558. else
  559. if (player->angle <= 202)
  560. player_dir = west;
  561. else
  562. if (player->angle <= 247)
  563. player_dir = southwest;
  564. else
  565. if (player->angle <= 292)
  566. player_dir = south;
  567. else
  568. if (player->angle <= 337)
  569. player_dir = southeast;
  570. if (ob->temp1)
  571. ob->temp1--;
  572. else
  573. ob->temp1 = (random(3))+2;
  574. if (ob->flags & LEFTSIDE)
  575. {
  576. if (ob->temp1)
  577. {
  578. if (valid_dir[player_dir][0] != ob->dir)
  579. {
  580. ob->dir = valid_dir[player_dir][0];
  581. }
  582. }
  583. else
  584. {
  585. ob->state = &s_bunny_right1;
  586. ob->ticcount = ob->state->tictime;
  587. ob->flags &= ~LEFTSIDE;
  588. ob->dir = valid_dir[player_dir][1];
  589. return;
  590. }
  591. }
  592. else
  593. {
  594. if (ob->temp1)
  595. {
  596. if (valid_dir[player_dir][1] != ob->dir)
  597. {
  598. ob->dir = valid_dir[player_dir][1];
  599. }
  600. }
  601. else
  602. {
  603. ob->state = &s_bunny_left1;
  604. ob->ticcount = ob->state->tictime;
  605. ob->flags |= LEFTSIDE;
  606. ob->dir = valid_dir[player_dir][2];
  607. return;
  608. }
  609. }
  610. move = ob->speed*tics;
  611. do
  612. {
  613. old_distance = ob->distance;
  614. old_x = ob->x;
  615. old_y = ob->y;
  616. old_tilex = ob->tilex;
  617. old_tiley = ob->tiley;
  618. MoveObj (ob, move);
  619. ob->tilex = ob->x >> TILESHIFT;
  620. ob->tiley = ob->y >> TILESHIFT;
  621. if (ob->tilex == old_tilex && ob->tiley == old_tiley)
  622. {
  623. break;
  624. }
  625. else
  626. if (actorat[ob->tilex][ob->tiley] == 0)
  627. {
  628. actorat[old_tilex][old_tiley] = 0;
  629. actorat[ob->tilex][ob->tiley] = ob;
  630. ob->distance = TILEGLOBAL;
  631. }
  632. else
  633. {
  634. ob->distance = old_distance;
  635. ob->x = old_x;
  636. ob->y = old_y;
  637. ob->tilex = old_tilex;
  638. ob->tiley = old_tiley;
  639. return;
  640. }
  641. } while (0);
  642. CalcBounds (ob);
  643. if (ob->flags & LEFTSIDE)
  644. ob->state = &s_bunny_left3;
  645. else
  646. ob->state = &s_bunny_right3;
  647. ob->ticcount = ob->state->tictime;
  648. }
  649. /*
  650. ===============
  651. =
  652. = T_Bunny
  653. =
  654. ===============
  655. */
  656. void T_Bunny(objtype *ob)
  657. {
  658. if (Chase (ob, true) || (random(1000)<RANDOM_ATTACK))
  659. {
  660. ob->state = &s_bunny_attack1;
  661. ob->ticcount = ob->state->tictime;
  662. return;
  663. }
  664. }