PageRenderTime 73ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/Game_DarkForces/ScriptFiles/CoreLogics.as

#
ActionScript | 4420 lines | 3416 code | 507 blank | 497 comment | 715 complexity | 2eaa4f9a0c0ef0ccce0408177b9cf406 MD5 | raw file
  1. /*
  2. *******obj variables********
  3. obj_Speed
  4. obj_dY
  5. obj_HP
  6. obj_Shields
  7. obj_Radius
  8. obj_Frame
  9. obj_Delay
  10. obj_FrameDelay
  11. obj_Alive
  12. obj_Action
  13. obj_Alerted
  14. obj_Yaw
  15. obj_dir_x
  16. obj_dir_y
  17. obj_dir_z
  18. obj_loc_x
  19. obj_loc_y
  20. obj_loc_z
  21. obj_uMsg
  22. *******player variables********
  23. *******obj Functions********
  24. Obj_SetMoveDir(float x, float y, float z)
  25. Obj_SetFlag(flag)
  26. Obj_ClearFlag(flag)
  27. Obj_UpdateLoc()
  28. Obj_SetProjectileData(string &type, string &projGraphic, string &projImpactGraph, string &fireSnd, string &hitSnd, int nDamage, float fSplashRng)
  29. *******sprite/wax functions*****
  30. Sprite_GetFrameCnt(action, view)
  31. *******logic Functions**********
  32. Logic_AddMsgMask(mask)
  33. *******map Functions**********
  34. Map_AddObject(type, file, logic, rot)
  35. float Map_GetFloorHeight()
  36. float Map_GetCeilingHeight()
  37. */
  38. const float dt = 1.0f/60.0f;
  39. //for now I have to duplicate engine enums...
  40. /*******Screen Flash Colors****/
  41. const int PLAYER_FLASH_RED =0;
  42. const int PLAYER_FLASH_GREEN=1;
  43. const int PLAYER_FLASH_BLUE =2;
  44. /*******STD. VALUES*********/
  45. const int FALSE = 0;
  46. const int TRUE = 1;
  47. const float PI = 3.141592653589793238f;
  48. const float TWO_PI = 6.283185307179586477f;
  49. /*******MESSAGE ENUMS*******/
  50. const int MSG_NRML_DAMAGE = 1; //called when an object recieves "normal" damage (such as blaster fire).
  51. const int MSG_MELEE_DAMAGE = 2; //called when an object recieves "melee" damage (such as Kyle's fist).
  52. const int MSG_ALERT = 4; //called when an object is "alerted"
  53. const int MSG_ANIM_LOOP = 8; //called when an animation loops, this can be used for transitions.
  54. const int MSG_PICKUP = 16; //called when the player collides with a pickup.
  55. const int MSG_MASTER_ON = 32; //sent to logics of objects in a sector when it recieves the master on message (INF).
  56. const int MSG_OBJ_DEAD = 64; //the logic was setup to handle an object's death.
  57. const int MSG_PROXIMITY = 128; //sent to a logic, when an object is nearby (use with player collision flag to make it only the player).
  58. /*******OBJECT FLAGS*******/
  59. const int OFLAGS_COLLIDE_PLAYER = 1;
  60. const int OFLAGS_COLLIDE_PROJECTILE = 2;
  61. const int OFLAGS_COLLIDE_OBJECTS = 8;
  62. const int OFLAGS_COLLIDE_PICKUP = 16;
  63. const int OFLAGS_COLLIDE_PROXIMITY = 32;
  64. const int OFLAGS_ENEMY = 64;
  65. const int OFLAGS_INVISIBLE = 1024;
  66. /*******AMMO TYPES********/
  67. const int AMMO_ENERGY = 0;
  68. const int AMMO_DETONATOR = 1;
  69. const int AMMO_POWER = 2;
  70. const int AMMO_MINE = 3;
  71. const int AMMO_MORTOR = 4;
  72. const int AMMO_PLASMA = 5;
  73. const int AMMO_MISSLE = 6;
  74. /*******Animation Actions*********/
  75. const int Anim_Moving = 0;
  76. const int Anim_Attacking = 1;
  77. const int Anim_Dying_Melee = 2;
  78. const int Anim_Dying_Nrml = 3;
  79. const int Anim_Dead = 4;
  80. const int Anim_Idle = 5;
  81. const int Anim_PAttack_FT = 6; //Primary attack follow through
  82. const int Anim_Sec_Attack = 7; //Secondary attack
  83. const int Anim_SAttack_FT = 8; //Secondary attack follow through.
  84. const int Anim_Injured = 12;
  85. /***********AI Routines*************/
  86. const int AI_State = 0;
  87. const int AI_Prev_State = 1;
  88. const int AI_Sec_State = 1;
  89. const int AI_Reaction = 2;
  90. const int AI_Dir = 3;
  91. const int AI_Sound = 4;
  92. const int AI_ProjGraph = 5;
  93. const int AI_ShootFT = 6;
  94. const int AI_Flags = 7;
  95. const int AI_Attack = 8;
  96. const int AI_Melee_Attack = 9;
  97. const int AI_Min_Reaction = 10;
  98. const int AI_Walk_Delay = 11;
  99. const int AI_Shoot_Cone = 12;
  100. const int AI_Shoot_Height = 13;
  101. const int AI_Shoot_Delay = 14;
  102. const int AI_MaxAttackRange = 15;
  103. //list of general AI states.
  104. const int AI_State_Look = 0; //look for the player but don't move - default state for standard enemies.
  105. const int AI_State_Chase = 1; //chase the player.
  106. const int AI_State_Wander = 2; //wander around - default state for generators.
  107. const int AI_State_Attack_Melee = 3; //melee attack.
  108. const int AI_State_Attack_Range = 4; //range attack (blaster, thermal detonator, etc.)
  109. const int AI_State_Wander_UG = 5; //wander state for units that travel underground - ie the sewer bugs...
  110. const int AI_State_Remote = 6; //special code for the Remote.
  111. const int AI_State_Transition = 256;
  112. //list of general AI flags.
  113. const int AI_Flags_None = 0;
  114. const int AI_Flags_Allow_Double_Shoot = 1;
  115. const int AI_Flags_Has_Melee = 2;
  116. const int AI_Flags_Floating = 4;
  117. const int AI_Flags_NoAlert = 8;
  118. const int AI_Flags_NoRangeAttck = 16;
  119. const int AI_Flags_Underground = 32;
  120. const int AI_Flags_SingleAttckOnly = 64;
  121. const int AI_Flags_FloatOnWater = 128;
  122. const int AI_Flags_Melee_Random = 256; //Don't always attack when in range, random chance.
  123. const int AI_Flags_ShootExp = 512;
  124. const int AI_Flags_MeleeWhileInjured = 1024;
  125. const int AI_Flags_JustFiredTwice = 2048;
  126. //misc. values.
  127. const float MeleeRange = 8.0f;
  128. const float MinRngAttackDist = 3.0f;
  129. //Setup for AI.
  130. void L_AI_SetupLogic()
  131. {
  132. Logic_AddMsgMask(MSG_NRML_DAMAGE);
  133. Logic_AddMsgMask(MSG_MELEE_DAMAGE);
  134. Logic_AddMsgMask(MSG_ALERT);
  135. }
  136. void L_AI_SetupObj(int HP, int inital_AI_state, int fireSound, int projGraph, int aiRngAttck, int aiMeleeAttck, bool bShootFT, int aiFlags)
  137. {
  138. Obj_SetMoveDir( obj_dir_x, obj_dir_y, 0.0f );
  139. obj_Speed = 0.1f;
  140. obj_dY = 0.015f;
  141. obj_HP = HP;
  142. obj_Radius = 2.0f;
  143. obj_Height = 7.8f;
  144. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  145. Obj_SetFlag(OFLAGS_COLLIDE_PROJECTILE);
  146. Obj_SetFlag(OFLAGS_COLLIDE_OBJECTS);
  147. Obj_SetFlag(OFLAGS_ENEMY);
  148. Obj_EnableAnim(1);
  149. //put into the "idle" action...
  150. obj_Action = Anim_Idle;
  151. obj_Frame = 0;
  152. obj_Delay = 15;
  153. obj_FrameDelay = 15;
  154. Obj_SetLocalVar(AI_State, inital_AI_state);
  155. Obj_SetLocalVar(AI_Prev_State, inital_AI_state);
  156. Obj_SetLocalVar(AI_Reaction, 5);
  157. Obj_SetLocalVar(AI_Sound, fireSound);
  158. Obj_SetLocalVar(AI_ProjGraph, projGraph);
  159. Obj_SetLocalVar(AI_ShootFT, bShootFT?1:0);
  160. Obj_SetLocalVar(AI_Flags, aiFlags);
  161. Obj_SetLocalVar(AI_Attack, aiRngAttck);
  162. Obj_SetLocalVar(AI_Melee_Attack, aiMeleeAttck);
  163. Obj_SetLocalVar(AI_Min_Reaction, Sprite_GetFrameCnt(Anim_Moving, 0)*5);//*15);
  164. Obj_SetLocalVar(AI_Walk_Delay, 15);
  165. Obj_SetLocalVar(AI_Shoot_Cone, 0.05f);
  166. Obj_SetLocalVar(AI_Shoot_Height, 0.0f);
  167. Obj_SetLocalVar(AI_Shoot_Delay, 15);
  168. Obj_SetLocalVar(AI_MaxAttackRange, 512);
  169. }
  170. int ChooseMoveDir(int nPlayerRel)
  171. {
  172. int f, l, r, b, dir;
  173. float px, py, pz, dx, dy;
  174. if ( nPlayerRel > 0 )
  175. {
  176. Player_GetLoc(px, py, pz);
  177. dx = px-obj_loc_x;
  178. dy = py-obj_loc_y;
  179. dir = Math_GetClosestDir(dx, dy);
  180. }
  181. else
  182. {
  183. //pick a direction at random...
  184. int r = Math_Rand();
  185. //8 directions, pick one...
  186. dir = r % 8;
  187. }
  188. Math_GetDir(dir, dx, dy);
  189. f = dir;
  190. //is this direction blocked?
  191. float p1_x = dx*obj_Speed + obj_loc_x;
  192. float p1_y = dy*obj_Speed + obj_loc_y;
  193. if ( Map_IsPathBlocked(p1_x, p1_y, obj_Radius, TRUE) )
  194. {
  195. //right or left?
  196. int dirTry;
  197. int r = Math_Rand();
  198. int a, b;
  199. if ( r < 50 ) { a = -1; b = +1; }
  200. else { a = +1; b = -1; }
  201. l = a; r = b;
  202. dirTry = dir+a;
  203. if ( dirTry > 7 ) dirTry -= 8;
  204. if ( dirTry < 0 ) dirTry += 8;
  205. Math_GetDir(dirTry, dx, dy);
  206. p1_x = dx*obj_Speed + obj_loc_x;
  207. p1_y = dy*obj_Speed + obj_loc_y;
  208. if ( Map_IsPathBlocked(p1_x, p1_y, obj_Radius, TRUE) )
  209. {
  210. dirTry = dir+b;
  211. if ( dirTry > 7 ) dirTry -= 8;
  212. if ( dirTry < 0 ) dirTry += 8;
  213. Math_GetDir(dirTry, dx, dy);
  214. p1_x = dx*obj_Speed + obj_loc_x;
  215. p1_y = dy*obj_Speed + obj_loc_y;
  216. if ( Map_IsPathBlocked(p1_x, p1_y, obj_Radius, TRUE) )
  217. {
  218. //left and right is blocked, try going backwards...
  219. r = Math_Rand();
  220. if ( r < 25 ) { dirTry = dir+3; }
  221. else if (r < 75) { dirTry = dir+4; }
  222. else { dirTry = dir+5; }
  223. if ( dirTry > 7 ) dirTry -= 8;
  224. if ( dirTry < 0 ) dirTry += 8;
  225. b = dirTry;
  226. Math_GetDir(dirTry, dx, dy);
  227. p1_x = dx*obj_Speed + obj_loc_x;
  228. p1_y = dy*obj_Speed + obj_loc_y;
  229. if ( Map_IsPathBlocked(p1_x, p1_y, obj_Radius, TRUE) )
  230. {
  231. //we'll try all the other directions now...
  232. for (int i=0; i<8; i++)
  233. {
  234. if ( i == f || i == l || i == r || i == b ) { continue; }
  235. Math_GetDir(i, dx, dy);
  236. p1_x = dx*obj_Speed + obj_loc_x;
  237. p1_y = dy*obj_Speed + obj_loc_y;
  238. if ( !Map_IsPathBlocked(p1_x, p1_y, obj_Radius, TRUE) )
  239. {
  240. Obj_LookAt(p1_x, p1_y, obj_loc_z, 1.0f, 0);
  241. return i;
  242. }
  243. }
  244. //can't move...
  245. return -1;
  246. }
  247. else
  248. {
  249. Obj_LookAt(p1_x, p1_y, obj_loc_z, 1.0f, 0);
  250. return dirTry;
  251. }
  252. }
  253. else
  254. {
  255. Obj_LookAt(p1_x, p1_y, obj_loc_z, 1.0f, 0);
  256. return dirTry;
  257. }
  258. }
  259. else
  260. {
  261. Obj_LookAt(p1_x, p1_y, obj_loc_z, 1.0f, 0);
  262. return dirTry;
  263. }
  264. }
  265. Obj_LookAt(p1_x, p1_y, obj_loc_z, 1.0f, 0);
  266. return dir;
  267. }
  268. //Chase the player.
  269. void L_AI_Chase(bool bTransition)
  270. {
  271. if ( bTransition )
  272. {
  273. obj_Action = Anim_Moving;
  274. obj_Frame = 0;
  275. obj_Delay = Obj_GetLocalVar(AI_Walk_Delay);//15;
  276. obj_FrameDelay = Obj_GetLocalVar(AI_Walk_Delay);//15;
  277. Obj_SetLocalVar( AI_Reaction, Obj_GetLocalVar(AI_Min_Reaction));
  278. Obj_SetLocalVar(AI_Prev_State, Obj_GetLocalVar(AI_State));
  279. Obj_SetLocalVar(AI_State, AI_State_Chase);
  280. //pick a direction.
  281. Obj_SetLocalVar( AI_Dir, ChooseMoveDir(1) );
  282. if ( Obj_GetLocalVarI(AI_Flags)&AI_Flags_Underground > 0 )
  283. {
  284. Obj_SetFlag(OFLAGS_INVISIBLE);
  285. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  286. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  287. }
  288. }
  289. int reaction = Obj_GetLocalVar(AI_Reaction);
  290. reaction--;
  291. if ( reaction <= 0 )
  292. {
  293. if ( Obj_GetLocalVarI(AI_Flags)&AI_Flags_Underground > 0 )
  294. {
  295. Obj_ClearFlag(OFLAGS_INVISIBLE);
  296. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  297. Obj_SetFlag(OFLAGS_COLLIDE_PROJECTILE);
  298. }
  299. Obj_SetLocalVar(AI_Reaction, 5);
  300. //we'll either attack or pick a direction to move in.
  301. float d = Obj_GetDistFromPlayer();
  302. if ( d < MeleeRange && (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Has_Melee)>0 )
  303. {
  304. //change of attack?
  305. int r = Math_Rand();
  306. int chance = 100;
  307. if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Melee_Random)>0 )
  308. {
  309. chance = 20;
  310. }
  311. //try melee attack if possible.
  312. if ( ( r < chance || chance == 100 ) && Map_HasPlayerLOS() == 1 )
  313. {
  314. Obj_SetLocalVar(AI_Prev_State, Obj_GetLocalVar(AI_State));
  315. Obj_SetLocalVar(AI_State,AI_State_Attack_Melee|AI_State_Transition);
  316. return;
  317. }
  318. else
  319. {
  320. //change direction.
  321. Obj_SetLocalVar( AI_Reaction, Obj_GetLocalVar(AI_Min_Reaction));
  322. //pick a direction.
  323. Obj_SetLocalVar( AI_Dir, ChooseMoveDir(1) );
  324. }
  325. }
  326. else
  327. {
  328. int r = Math_Rand();
  329. //the chance of shooting is proportional to the distance from the player.
  330. int t = d*0.5f;
  331. //units will always shoot atleast roughly half the time.
  332. if ( t > 60 ) t = 60;
  333. if ( r > t && Map_HasPlayerLOS() == 1 && d > MinRngAttackDist && d < Obj_GetLocalVar(AI_MaxAttackRange) && (Obj_GetLocalVarI(AI_Flags)&AI_Flags_NoRangeAttck)==0 )
  334. {
  335. Obj_SetLocalVar(AI_Prev_State, Obj_GetLocalVar(AI_State));
  336. Obj_SetLocalVar(AI_State,AI_State_Attack_Range|AI_State_Transition);
  337. return;
  338. }
  339. else
  340. {
  341. //change direction.
  342. Obj_SetLocalVar( AI_Reaction, Obj_GetLocalVar(AI_Min_Reaction));
  343. //pick a direction.
  344. Obj_SetLocalVar( AI_Dir, ChooseMoveDir(1) );
  345. if ( Obj_GetLocalVarI(AI_Flags)&AI_Flags_Underground > 0 )
  346. {
  347. Obj_SetFlag(OFLAGS_INVISIBLE);
  348. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  349. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  350. }
  351. }
  352. }
  353. }
  354. else
  355. {
  356. Obj_SetLocalVar(AI_Reaction, reaction);
  357. }
  358. //continue moving in the current direction unless it is blocked.
  359. float p1_x, p1_y;
  360. int dir = Obj_GetLocalVar(AI_Dir);
  361. if (dir == -1)
  362. {
  363. dir = ChooseMoveDir(1);
  364. if (dir > 0)
  365. {
  366. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  367. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  368. Obj_SetLocalVar( AI_Dir, dir );
  369. }
  370. else
  371. {
  372. if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  373. {
  374. //try moving down a little...
  375. obj_loc_z -= 0.02f;
  376. Obj_UpdateLoc();
  377. }
  378. }
  379. }
  380. else
  381. {
  382. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  383. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  384. if ( Map_IsPathBlocked(p1_x, p1_y, obj_Radius, TRUE) )
  385. {
  386. dir = ChooseMoveDir(1);
  387. if ( dir > 0 )
  388. {
  389. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  390. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  391. }
  392. else if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  393. {
  394. //try moving down a little...
  395. obj_loc_z -= 0.02f;
  396. Obj_UpdateLoc();
  397. }
  398. Obj_SetLocalVar( AI_Dir, dir );
  399. }
  400. }
  401. if ( dir > -1 )
  402. {
  403. //this will move toward (p1_x, p1_y) and colliding in the process.
  404. //treat drops as solid unless its a floating unit.
  405. float z = obj_loc_z;
  406. Map_CollideObj(p1_x, p1_y, obj_Radius, TRUE, (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 ? FALSE : TRUE, TRUE);
  407. if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  408. {
  409. obj_loc_z = z;
  410. Obj_UpdateLoc();
  411. }
  412. }
  413. else if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  414. {
  415. //try moving down a little...
  416. obj_loc_z -= 0.02f;
  417. Obj_UpdateLoc();
  418. }
  419. //move down toward the player...
  420. if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  421. {
  422. float px, py, pz;
  423. float ground_height = Map_GetFloorHeight(0, -1);
  424. float ceil_height = Map_GetCeilingHeight(-1);
  425. Player_GetLoc(px, py, pz);
  426. if ( obj_loc_z > pz+5.0f && obj_loc_z >= ground_height + 5.04f)
  427. {
  428. //try moving down a little...
  429. obj_loc_z -= 0.02f;
  430. Obj_UpdateLoc();
  431. }
  432. if ( obj_loc_z < pz+3.0f && obj_loc_z <= ceil_height-4.04f )
  433. {
  434. //try moving up a little...
  435. obj_loc_z += 0.02f;
  436. Obj_UpdateLoc();
  437. }
  438. }
  439. }
  440. //Wander around, player has not been sighted yet.
  441. void L_AI_Wander(bool bTransition)
  442. {
  443. if ( bTransition )
  444. {
  445. if ( Obj_GetLocalVarI(AI_Flags)&AI_Flags_Underground > 0 )
  446. {
  447. L_AI_Wander_UG(true);
  448. return;
  449. }
  450. obj_Action = Anim_Moving;
  451. obj_Frame = 0;
  452. obj_Delay = Obj_GetLocalVar(AI_Walk_Delay);//15;
  453. obj_FrameDelay = Obj_GetLocalVar(AI_Walk_Delay);//15;
  454. Obj_SetLocalVar( AI_Reaction, Obj_GetLocalVar(AI_Min_Reaction));
  455. Obj_SetLocalVar(AI_Prev_State, Obj_GetLocalVar(AI_State));
  456. Obj_SetLocalVar(AI_State, AI_State_Wander);
  457. //pick a direction.
  458. Obj_SetLocalVar( AI_Dir, ChooseMoveDir(0) );
  459. }
  460. int reaction = Obj_GetLocalVar(AI_Reaction);
  461. reaction--;
  462. if ( reaction <= 0 )
  463. {
  464. Obj_SetLocalVar( AI_Reaction, Obj_GetLocalVar(AI_Min_Reaction));
  465. //pick a direction.
  466. Obj_SetLocalVar( AI_Dir, ChooseMoveDir(0) );
  467. }
  468. else
  469. {
  470. Obj_SetLocalVar(AI_Reaction, reaction);
  471. }
  472. //continue moving in the current direction unless it is blocked.
  473. float p1_x, p1_y;
  474. int dir = Obj_GetLocalVar(AI_Dir);
  475. if (dir == -1)
  476. {
  477. dir = ChooseMoveDir(0);
  478. if (dir > 0)
  479. {
  480. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  481. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  482. Obj_SetLocalVar( AI_Dir, dir );
  483. }
  484. else
  485. {
  486. if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  487. {
  488. //try moving down a little...
  489. obj_loc_z -= 0.02f;
  490. Obj_UpdateLoc();
  491. }
  492. }
  493. }
  494. else
  495. {
  496. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  497. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  498. if ( Map_IsPathBlocked(p1_x, p1_y, obj_Radius, TRUE) )
  499. {
  500. dir = ChooseMoveDir(0);
  501. if ( dir > 0 )
  502. {
  503. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  504. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  505. }
  506. else if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  507. {
  508. //try moving down a little...
  509. obj_loc_z -= 0.02f;
  510. Obj_UpdateLoc();
  511. }
  512. Obj_SetLocalVar( AI_Dir, dir );
  513. }
  514. }
  515. if ( dir > -1 )
  516. {
  517. //this will move toward (p1_x, p1_y) and colliding in the process.
  518. //treat drops as solid unless its a floating unit.
  519. float z = obj_loc_z;
  520. Map_CollideObj(p1_x, p1_y, obj_Radius, TRUE, (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 ? FALSE : TRUE, TRUE);
  521. if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  522. {
  523. obj_loc_z = z;
  524. Obj_UpdateLoc();
  525. }
  526. }
  527. else if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  528. {
  529. //try moving down a little...
  530. obj_loc_z -= 0.02f;
  531. Obj_UpdateLoc();
  532. }
  533. }
  534. //Attempt to attack from range.
  535. bool L_AI_Attack(bool bMelee, bool bTransition, int meleeSnd, int meleeDmg)
  536. {
  537. //let the game know this enemy is attacking, so iMuse can be used appropriately.
  538. Obj_EnemyAttacking();
  539. if ( bTransition )
  540. {
  541. Obj_SetLocalVar(AI_State, bMelee?AI_State_Attack_Melee:AI_State_Attack_Range);
  542. }
  543. if ( bMelee )
  544. {
  545. //melee attack now...
  546. if ( bTransition )
  547. {
  548. obj_Action = Obj_GetLocalVarI(AI_Melee_Attack);
  549. obj_Frame = 0;
  550. obj_Delay = Obj_GetLocalVarI(AI_Shoot_Delay);
  551. obj_FrameDelay = Obj_GetLocalVarI(AI_Shoot_Delay);
  552. //play sound.
  553. if ( meleeSnd == 0 ) Sound_Play3D("INTSTUN.VOC", 1.0f);
  554. else if ( meleeSnd == 1 ) Sound_Play3D("CREATUR2.VOC", 1.0f);
  555. else if ( meleeSnd == 2 ) Sound_Play3D("AXE-1.VOC", 1.0f);
  556. else if ( meleeSnd == 3 ) Sound_Play3D("KELL-5.VOC", 1.0f);
  557. else if ( meleeSnd == 4 ) Sound_Play3D("SWORD-1.VOC", 1.0f);
  558. }
  559. else
  560. {
  561. if ( obj_Action == Obj_GetLocalVarI(AI_Melee_Attack) && obj_Frame == 0 && obj_Delay == Obj_GetLocalVarI(AI_Shoot_Delay) )
  562. {
  563. //melee...
  564. float d = Obj_GetDistFromPlayer();
  565. if ( d < MeleeRange )
  566. {
  567. Player_DmgHealth(meleeDmg);
  568. }
  569. //am I still in melee range? if so continue to attack...
  570. if ( d < MeleeRange && (Obj_GetLocalVarI(AI_Flags)&AI_Flags_SingleAttckOnly)==0 )
  571. {
  572. //play sound.
  573. if ( meleeSnd == 0 ) Sound_Play3D("INTSTUN.VOC", 1.0f);
  574. else if ( meleeSnd == 1 ) Sound_Play3D("CREATUR2.VOC", 1.0f);
  575. else if ( meleeSnd == 2 ) Sound_Play3D("AXE-1.VOC", 1.0f);
  576. else if ( meleeSnd == 3 ) Sound_Play3D("KELL-5.VOC", 1.0f);
  577. else if ( meleeSnd == 4 ) Sound_Play3D("SWORD-1.VOC", 1.0f);
  578. return true;
  579. }
  580. else
  581. {
  582. L_AI_Chase(true);
  583. return false;
  584. }
  585. }
  586. }
  587. }
  588. else
  589. {
  590. if ( bTransition )
  591. {
  592. obj_Action = Obj_GetLocalVarI(AI_Attack);
  593. obj_Frame = 0;
  594. obj_Delay = Obj_GetLocalVarI(AI_Shoot_Delay);
  595. obj_FrameDelay = Obj_GetLocalVarI(AI_Shoot_Delay);
  596. }
  597. else
  598. {
  599. if ( obj_Action == Obj_GetLocalVarI(AI_Attack) && obj_Frame == 0 && obj_Delay == Obj_GetLocalVarI(AI_Shoot_Delay) )
  600. {
  601. //shoot...
  602. if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_ShootExp) != 0 )
  603. {
  604. //Add an explosion at the player's position...
  605. if ( Map_HasPlayerLOS() == 1 )
  606. {
  607. float px, py, pz;
  608. Player_GetLoc(px, py, pz);
  609. //the direction from the object to the player.
  610. float dx = px - obj_loc_x;
  611. float dy = py - obj_loc_y;
  612. float nx, ny;
  613. Math_Normalize(dx, dy, nx, ny);
  614. //bias the explosion away from the player by 0.5 DFU, so that it is actually visible.
  615. px = px - nx*0.1f;
  616. py = py - ny*0.1f;
  617. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  618. Map_AddExplosion(px, py, pz, 10.0f, 30.0f, 0.0f, 1.0f, "CONCEXP.WAX", "CONCUSS5.VOC", false, Player_GetSector());
  619. }
  620. }
  621. else if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_NoRangeAttck)==0 )
  622. {
  623. int shoot = Obj_ShootPlayer( 0, Obj_GetLocalVar(AI_Shoot_Cone), Obj_GetLocalVar(AI_Sound), Obj_GetLocalVarI(AI_Shoot_Height) ); //use blaster bolts...
  624. if ( shoot == 0 )
  625. {
  626. L_AI_Chase(true);
  627. return false;
  628. }
  629. }
  630. if ( Obj_GetLocalVar(AI_ShootFT) > 0 )
  631. {
  632. obj_Frame = 0;
  633. obj_Delay = 15;
  634. obj_FrameDelay = 15;
  635. obj_Action = Anim_PAttack_FT;
  636. }
  637. else if ( obj_Speed > 0.3f && Map_HasPlayerLOS() == 1 )
  638. {
  639. obj_Action = Obj_GetLocalVarI(AI_Attack);
  640. obj_Frame = 0;
  641. obj_Delay = Obj_GetLocalVarI(AI_Shoot_Delay);
  642. obj_FrameDelay = Obj_GetLocalVarI(AI_Shoot_Delay);
  643. }
  644. else
  645. {
  646. L_AI_Chase(true);
  647. return false;
  648. }
  649. }
  650. else if ( obj_Action == Anim_PAttack_FT )
  651. {
  652. if ( obj_Frame == 0 && obj_Delay == 15 )
  653. {
  654. //we're done, now go back to chasing...
  655. int r = Math_Rand();
  656. //if we've already fired twice in a row, we can't do it again.
  657. if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_JustFiredTwice)>0 )
  658. {
  659. //Make sure to clear the flag so we can fire twice in a row again in the future.
  660. Obj_SetLocalVar( AI_Flags, Math_ClearBit(Obj_GetLocalVar(AI_Flags), AI_Flags_JustFiredTwice) );
  661. r = 100;
  662. }
  663. if ( (r<33) && (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Allow_Double_Shoot)>0 )
  664. {
  665. obj_Action = Obj_GetLocalVarI(AI_Attack);
  666. obj_Frame = 0;
  667. obj_Delay = Obj_GetLocalVarI(AI_Shoot_Delay);
  668. obj_FrameDelay = Obj_GetLocalVarI(AI_Shoot_Delay);
  669. //Note that we've fired twice in a row so that we don't fire again atleast until another chase sequence.
  670. Obj_SetLocalVar( AI_Flags, Obj_GetLocalVarI(AI_Flags)|AI_Flags_JustFiredTwice );
  671. }
  672. else
  673. {
  674. //Reposition ourselves... unless we're turrents.:)
  675. L_AI_Chase(true);
  676. return false;
  677. }
  678. }
  679. }
  680. }
  681. }
  682. return true;
  683. }
  684. void L_AI_Wander_UG(bool bTransition)
  685. {
  686. //States: Looking around, moving under ground, attacking.
  687. if ( bTransition )
  688. {
  689. obj_Action = 12;
  690. obj_Frame = 0;
  691. obj_Delay = 10;
  692. obj_FrameDelay = 10;
  693. Obj_SetLocalVar(AI_Reaction, Sprite_GetFrameCnt(12, 0)*obj_FrameDelay);
  694. Obj_SetLocalVar(AI_Sec_State, 0);
  695. Obj_SetLocalVar(AI_State, AI_State_Wander_UG);
  696. //pick a direction.
  697. Obj_SetLocalVar( AI_Dir, ChooseMoveDir(0) );
  698. }
  699. int reaction = Obj_GetLocalVar(AI_Reaction);
  700. reaction--;
  701. if ( reaction <= 0 )
  702. {
  703. //2 possible states: come up for "air" and move
  704. if ( Obj_GetLocalVarI(AI_Sec_State) < 2 && (obj_Action != Anim_Attacking) )
  705. {
  706. //go ahead and move now...
  707. obj_Action = Anim_Idle;
  708. Obj_SetLocalVar(AI_Sec_State, 2);
  709. int r = Math_Rand();
  710. Obj_SetLocalVar(AI_Reaction, 60+r*2);
  711. Obj_SetFlag(OFLAGS_INVISIBLE);
  712. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  713. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  714. obj_Frame = 0;
  715. obj_Delay = 15;
  716. obj_FrameDelay = 15;
  717. int dir = ChooseMoveDir(0);
  718. Obj_SetLocalVar( AI_Dir, dir );
  719. }
  720. else
  721. {
  722. if ( obj_Action == Anim_Attacking )
  723. {
  724. //let the game know this enemy is attacking, so iMuse can be used appropriately.
  725. Obj_EnemyAttacking();
  726. obj_Action = Anim_PAttack_FT;
  727. obj_FrameDelay = 10;
  728. //go ahead and do the attack and sound now...
  729. float d = Obj_GetDistFromPlayer();
  730. float px, py, pz;
  731. Player_GetLoc(px, py, pz);
  732. if ( d < MeleeRange && Math_Abs(obj_loc_z-pz)<7.0f )
  733. {
  734. Player_DmgHealth(20);
  735. }
  736. Sound_Play3D("CREATUR2.VOC", 1.0f);
  737. }
  738. else
  739. {
  740. //come up for "air" and look around or attack.
  741. //are we close enough to try a melee attack?
  742. float d = Obj_GetDistFromPlayer();
  743. if ( d < MeleeRange && Map_IsPlayerInSector(obj_Radius)==1 )
  744. {
  745. obj_Action = Anim_Attacking;
  746. Obj_SetLocalVar(AI_Sec_State, 1);
  747. obj_FrameDelay = 10;
  748. }
  749. else
  750. {
  751. obj_Action = 12;
  752. Obj_SetLocalVar(AI_Sec_State, 0);
  753. obj_FrameDelay = 10;
  754. }
  755. }
  756. obj_Frame = 0;
  757. obj_Delay = obj_FrameDelay;
  758. Obj_SetLocalVar(AI_Reaction, Sprite_GetFrameCnt(obj_Action, 0)*obj_FrameDelay);
  759. Obj_ClearFlag(OFLAGS_INVISIBLE);
  760. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  761. Obj_SetFlag(OFLAGS_COLLIDE_PROJECTILE);
  762. }
  763. }
  764. else
  765. {
  766. if ( Obj_GetLocalVarI(AI_Sec_State) == 2 )
  767. {
  768. int dir = Obj_GetLocalVarI( AI_Dir );
  769. if ( dir > -1 )
  770. {
  771. float dx, dy;
  772. Math_GetDir(dir, dx, dy);
  773. float p1_x = obj_loc_x + dx*obj_Speed;
  774. float p1_y = obj_loc_y + dy*obj_Speed;
  775. //this will move toward (p1_x, p1_y) and colliding in the process.
  776. //treat drops as solid unless its a floating unit.
  777. float z = obj_loc_z;
  778. Map_CollideObj(p1_x, p1_y, obj_Radius, TRUE, TRUE, FALSE);
  779. obj_loc_z = z;
  780. Obj_UpdateLoc();
  781. }
  782. if ( reaction < 55 )
  783. {
  784. //if the player is close enough and its moved far enough, then come up to attack...
  785. float d = Obj_GetDistFromPlayer();
  786. float px, py, pz;
  787. Player_GetLoc(px, py, pz);
  788. if ( d < MeleeRange && Math_Abs(obj_loc_z-pz)<7.0f )
  789. {
  790. if ( Map_IsPlayerInSector(obj_Radius)==1 )
  791. {
  792. //let the game know this enemy is attacking, so iMuse can be used appropriately.
  793. Obj_EnemyAttacking();
  794. obj_Action = Anim_Attacking;
  795. Obj_SetLocalVar(AI_Sec_State, 1);
  796. obj_FrameDelay = 10;
  797. obj_Frame = 0;
  798. obj_Delay = obj_FrameDelay;
  799. Obj_SetLocalVar(AI_Reaction, Sprite_GetFrameCnt(obj_Action, 0)*obj_FrameDelay);
  800. Obj_ClearFlag(OFLAGS_INVISIBLE);
  801. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  802. Obj_SetFlag(OFLAGS_COLLIDE_PROJECTILE);
  803. }
  804. }
  805. }
  806. }
  807. else if ( Obj_GetLocalVarI(AI_Sec_State) == 0 )
  808. {
  809. float d = Obj_GetDistFromPlayer();
  810. if ( d < MeleeRange )
  811. {
  812. if ( Map_IsPlayerInSector(obj_Radius)==1 )//Map_HasPlayerLOS() == 1 )
  813. {
  814. obj_Action = Anim_Attacking;
  815. Obj_SetLocalVar(AI_Sec_State, 1);
  816. obj_FrameDelay = 10;
  817. obj_Frame = 0;
  818. obj_Delay = obj_FrameDelay;
  819. reaction = Sprite_GetFrameCnt(obj_Action, 0)*obj_FrameDelay;
  820. }
  821. }
  822. }
  823. Obj_SetLocalVar(AI_Reaction, reaction);
  824. }
  825. }
  826. void L_AI_Remote(bool bTransition)
  827. {
  828. if ( obj_Action == Anim_Dead ) { return; }
  829. //States: Looking around, moving under ground, attacking.
  830. if ( bTransition )
  831. {
  832. obj_Action = Anim_Moving;
  833. obj_Frame = 0;
  834. obj_Delay = 10;
  835. obj_FrameDelay = 10;
  836. Obj_SetLocalVar(AI_Reaction, 60);
  837. Obj_SetLocalVar(AI_Sec_State, 0);
  838. Obj_SetLocalVar(AI_State, AI_State_Remote);
  839. //pick a direction.
  840. Obj_SetLocalVar( AI_Dir, ChooseMoveDir(1) );
  841. Obj_ClearFlag(OFLAGS_INVISIBLE);
  842. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  843. Obj_SetFlag(OFLAGS_COLLIDE_PROJECTILE);
  844. }
  845. int reaction = Obj_GetLocalVar(AI_Reaction);
  846. reaction--;
  847. if ( reaction <= 0 )
  848. {
  849. //if player is close enough... shoot and move or just move...
  850. float d = Obj_GetDistFromPlayer();
  851. if ( d < 120 )
  852. {
  853. if ( Map_HasPlayerLOS() == 1 )
  854. {
  855. reaction = 60;
  856. }
  857. else
  858. {
  859. reaction = 240;
  860. }
  861. }
  862. }
  863. else
  864. {
  865. Obj_SetLocalVar(AI_Reaction, reaction);
  866. }
  867. //continue moving in the current direction unless it is blocked.
  868. float p1_x, p1_y;
  869. int dir = Obj_GetLocalVar(AI_Dir);
  870. if (dir == -1)
  871. {
  872. dir = ChooseMoveDir(1);
  873. if (dir > 0)
  874. {
  875. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  876. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  877. Obj_SetLocalVar( AI_Dir, dir );
  878. }
  879. }
  880. else
  881. {
  882. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  883. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  884. if ( Map_IsPathBlocked(p1_x, p1_y, obj_Radius, TRUE) )
  885. {
  886. dir = ChooseMoveDir(1);
  887. if ( dir > 0 )
  888. {
  889. p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  890. p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  891. }
  892. else if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  893. {
  894. //try moving down a little...
  895. obj_loc_z -= 0.02f;
  896. Obj_UpdateLoc();
  897. }
  898. Obj_SetLocalVar( AI_Dir, dir );
  899. }
  900. }
  901. if ( dir > -1 )
  902. {
  903. //this will move toward (p1_x, p1_y) and colliding in the process.
  904. //treat drops as solid unless its a floating unit.
  905. float z = obj_loc_z;
  906. Map_CollideObj(p1_x, p1_y, obj_Radius, TRUE, (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 ? FALSE : TRUE, TRUE);
  907. obj_loc_z = z;
  908. Obj_UpdateLoc();
  909. }
  910. else
  911. {
  912. //try moving down a little...
  913. obj_loc_z -= 0.02f;
  914. Obj_UpdateLoc();
  915. }
  916. //move down toward the player...
  917. {
  918. float px, py, pz;
  919. float ground_height = Map_GetFloorHeight(0, -1);
  920. float ceil_height = Map_GetCeilingHeight(-1);
  921. Player_GetLoc(px, py, pz);
  922. if ( obj_loc_z > pz+5.0f && obj_loc_z >= ground_height + 5.04f)
  923. {
  924. //try moving down a little...
  925. obj_loc_z -= 0.02f;
  926. Obj_UpdateLoc();
  927. }
  928. if ( obj_loc_z < pz+3.0f && obj_loc_z <= ceil_height-4.04f )
  929. {
  930. //try moving up a little...
  931. obj_loc_z += 0.02f;
  932. Obj_UpdateLoc();
  933. }
  934. }
  935. }
  936. float ceil_dist = 5.0f;
  937. int L_AI_RunAIState(int meleeSnd, int meleeDmg)
  938. {
  939. int ret = 0;
  940. //I'm dead, there is nothing to do now. Eventually updates for this AI should just be shut off.
  941. if ( obj_Action == Anim_Dead )
  942. {
  943. float ground_height = Map_GetFloorHeight( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_FloatOnWater)>0 ? 1 : 0, -1 );
  944. //force gravity if this isn't a flying/floating unit.
  945. bool bUpdate = false;
  946. if ( obj_loc_z > ground_height )
  947. {
  948. obj_loc_z -= 0.4f;
  949. bUpdate = true;
  950. }
  951. if ( obj_loc_z < ground_height )
  952. {
  953. obj_loc_z = ground_height;
  954. bUpdate = true;
  955. }
  956. if (bUpdate) Obj_UpdateLoc();
  957. return 0;
  958. }
  959. bool bTrans = Math_IsBitSet( Obj_GetLocalVar(AI_State), AI_State_Transition );
  960. if ( bTrans )
  961. {
  962. Obj_SetLocalVar( AI_State, Math_ClearBit(Obj_GetLocalVar(AI_State), AI_State_Transition) );
  963. }
  964. int state = Obj_GetLocalVarI(AI_State);
  965. if ( obj_Action != Anim_Dying_Melee && obj_Action != Anim_Dying_Nrml && (obj_Action != Anim_Injured || state==AI_State_Wander_UG || state==AI_State_Remote) )
  966. {
  967. switch (state)
  968. {
  969. case AI_State_Look:
  970. obj_Action = Anim_Idle;
  971. break;
  972. case AI_State_Chase:
  973. L_AI_Chase(bTrans);
  974. break;
  975. case AI_State_Wander:
  976. L_AI_Wander(bTrans);
  977. break;
  978. case AI_State_Attack_Melee:
  979. L_AI_Attack(true, bTrans, meleeSnd, meleeDmg);
  980. break;
  981. case AI_State_Attack_Range:
  982. L_AI_Attack(false, bTrans, -1, 0);
  983. break;
  984. case AI_State_Wander_UG:
  985. L_AI_Wander_UG(bTrans);
  986. break;
  987. case AI_State_Remote:
  988. L_AI_Remote(bTrans);
  989. break;
  990. }
  991. }
  992. else if ( obj_Action == Anim_Dying_Melee && obj_Frame >= Sprite_GetFrameCnt(Anim_Dying_Melee, 0)-1 && obj_Delay < 1 )
  993. {
  994. obj_Action = Anim_Dead;
  995. ret = 1;
  996. }
  997. else if ( obj_Action == Anim_Dying_Nrml && obj_Frame >= Sprite_GetFrameCnt(Anim_Dying_Nrml, 0)-1 && obj_Delay < 1 )
  998. {
  999. obj_Action = Anim_Dead;
  1000. ret = 1;
  1001. }
  1002. else if ( state != AI_State_Wander_UG && state != AI_State_Remote && obj_Action == Anim_Injured && obj_Frame >= Sprite_GetFrameCnt(Anim_Injured, 0)-1 && obj_Delay < 1 )
  1003. {
  1004. if ( obj_Alive == 0 ) { obj_Action = Anim_Dead; ret = 1; }
  1005. else
  1006. {
  1007. float d = Obj_GetDistFromPlayer();
  1008. if ( d < MeleeRange && (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Has_Melee)>0 )
  1009. {
  1010. //try melee attack if possible.
  1011. L_AI_Attack(true, true, meleeSnd, meleeDmg);
  1012. }
  1013. else if ( (Obj_GetLocalVarI(AI_Flags)&AI_Flags_NoRangeAttck)==0 )
  1014. {
  1015. L_AI_Attack(false, true, -1, 0);
  1016. }
  1017. else
  1018. {
  1019. L_AI_Chase(true);
  1020. }
  1021. }
  1022. }
  1023. //fall to the ground if this is a ground based unit.
  1024. float ground_height = Map_GetFloorHeight( ((Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 || (Obj_GetLocalVarI(AI_Flags)&AI_Flags_FloatOnWater)>0) ? 1 : 0, -1 );
  1025. if ( obj_Action != Anim_Dying_Nrml && obj_Action != Anim_Dying_Melee && obj_Action != Anim_Dead && (Obj_GetLocalVarI(AI_Flags)&AI_Flags_Floating)>0 )
  1026. {
  1027. float ceil_height = Map_GetCeilingHeight(-1);
  1028. if ( obj_loc_z < ground_height + 5.0f )
  1029. {
  1030. obj_loc_z += 0.4f;
  1031. }
  1032. if ( obj_loc_z > ceil_height-ceil_dist )
  1033. {
  1034. obj_loc_z = ceil_height-ceil_dist;
  1035. }
  1036. }
  1037. else
  1038. {
  1039. //force gravity if this isn't a flying/floating unit.
  1040. if ( obj_loc_z > ground_height )
  1041. {
  1042. obj_loc_z -= 0.4f;
  1043. }
  1044. }
  1045. if ( obj_loc_z < ground_height )
  1046. {
  1047. obj_loc_z = ground_height;
  1048. }
  1049. Obj_UpdateLoc();
  1050. //Did I just die?
  1051. return ret;
  1052. }
  1053. bool L_AI_SendMsg(bool bSwapDeathAnim, int nDeathSnd, int nDmgSnd, int nAlertSnd)
  1054. {
  1055. bool bJustDied = false;
  1056. if ( obj_Alive == 1 )
  1057. {
  1058. switch (obj_uMsg)
  1059. {
  1060. case MSG_NRML_DAMAGE:
  1061. obj_HP -= msg_nVal;
  1062. if ( obj_HP <= 0 )
  1063. {
  1064. obj_HP = 0;
  1065. obj_Alive = 0;
  1066. obj_Frame = 0;
  1067. obj_Delay = 6;
  1068. obj_FrameDelay = 6;
  1069. obj_Action = bSwapDeathAnim ? Anim_Dying_Melee : Anim_Dying_Nrml;
  1070. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  1071. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  1072. Obj_ClearFlag(OFLAGS_COLLIDE_OBJECTS);
  1073. //-----------death---------------
  1074. if ( nDeathSnd == 0 ) Sound_Play3D("ST-DIE-1.VOC", 1.0f);
  1075. else if ( nDeathSnd == 1 ) Sound_Play3D("EX-SMALL.VOC", 1.0f);
  1076. else if ( nDeathSnd == 2 ) Sound_Play3D("PROBALM.VOC", 1.0f);
  1077. else if ( nDeathSnd == 3 ) { Sound_Play3D("REMOTE-2.VOC", 1.0f); obj_Action = Anim_Dead; }
  1078. else if ( nDeathSnd == 4 ) Sound_Play3D("CREATDIE.VOC", 1.0f);
  1079. else if ( nDeathSnd == 5 ) Sound_Play3D("REEYEE-3.VOC", 1.0f);
  1080. else if ( nDeathSnd == 6 ) Sound_Play3D("GAMOR-1.VOC", 1.0f);
  1081. else if ( nDeathSnd == 7 ) Sound_Play3D("BOSSKDIE.VOC", 1.0f);
  1082. else if ( nDeathSnd == 8 ) Sound_Play3D("KELL-7.VOC", 1.0f);
  1083. else if ( nDeathSnd == 9 ) Sound_Play3D("PHASE1C.VOC", 1.0f);
  1084. else if ( nDeathSnd == 10) Sound_Play3D("PHASE2C.VOC", 1.0f);
  1085. else if ( nDeathSnd == 11) Sound_Play3D("PHASE3C.VOC", 1.0f);
  1086. else if ( nDeathSnd == 12) Sound_Play3D("BOBA-4.VOC", 1.0f);
  1087. bJustDied = true;
  1088. Obj_JustDied();
  1089. }
  1090. else
  1091. {
  1092. int r = Math_Rand();
  1093. if ( obj_Speed > 0.3f )
  1094. {
  1095. //hack for DT's...
  1096. r = 0;
  1097. }
  1098. if ( nDmgSnd != 1 && ((Obj_GetLocalVarI(AI_Flags)&AI_Flags_MeleeWhileInjured)!=0 || r < 30) )
  1099. {
  1100. obj_Frame = 0;
  1101. obj_Delay = 15;
  1102. obj_Action = Anim_Injured;
  1103. }
  1104. //-----------damage sound---------------
  1105. if ( nDmgSnd == 0 ) Sound_Play3D("ST-HRT-1.VOC", 1.0f);
  1106. else if ( nDmgSnd == 1 ) Sound_Play3D("CREATHRT.VOC", 100.0f);
  1107. else if ( nDmgSnd == 2 ) Sound_Play3D("REEYEE-2.VOC", 1.0f);
  1108. else if ( nDmgSnd == 3 ) Sound_Play3D("GAMOR-2.VOC", 1.0f);
  1109. else if ( nDmgSnd == 4 ) Sound_Play3D("GAMOR-3.VOC", 1.0f);
  1110. else if ( nDmgSnd == 5 ) Sound_Play3D("KELL-5.VOC", 1.0f);
  1111. else if ( nDmgSnd == 6 ) Sound_Play3D("PHASE1B.VOC", 1.0f);
  1112. else if ( nDmgSnd == 7 ) Sound_Play3D("PHASE2B.VOC", 1.0f);
  1113. else if ( nDmgSnd == 8 ) Sound_Play3D("PHASE3B.VOC", 1.0f);
  1114. else if ( nDmgSnd == 9 ) Sound_Play3D("BOBA-3.VOC", 1.0f);
  1115. }
  1116. break;
  1117. case MSG_MELEE_DAMAGE:
  1118. //hack for now... double Melee damage.
  1119. if ( nDeathSnd == 8 )
  1120. obj_HP -= msg_nVal;
  1121. obj_HP -= msg_nVal;
  1122. if ( obj_HP <= 0 )
  1123. {
  1124. obj_HP = 0;
  1125. obj_Alive = 0;
  1126. obj_Frame = 0;
  1127. obj_Delay = 6;
  1128. obj_FrameDelay = 6;
  1129. obj_Action = bSwapDeathAnim ? Anim_Dying_Nrml : Anim_Dying_Melee;
  1130. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  1131. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  1132. Obj_ClearFlag(OFLAGS_COLLIDE_OBJECTS);
  1133. //-----------death---------------
  1134. if ( nDeathSnd == 0 ) Sound_Play3D("ST-DIE-1.VOC", 1.0f);
  1135. else if ( nDeathSnd == 1 ) Sound_Play3D("EX-SMALL.VOC", 1.0f);
  1136. else if ( nDeathSnd == 2 ) Sound_Play3D("PROBALM.VOC", 1.0f);
  1137. else if ( nDeathSnd == 3 ) { Sound_Play3D("REMOTE-2.VOC", 1.0f); obj_Action = Anim_Dead; }
  1138. else if ( nDeathSnd == 4 ) Sound_Play3D("CREATDIE.VOC", 1.0f);
  1139. else if ( nDeathSnd == 5 ) Sound_Play3D("REEYEE-3.VOC", 1.0f);
  1140. else if ( nDeathSnd == 6 ) Sound_Play3D("GAMOR-1.VOC", 1.0f);
  1141. else if ( nDeathSnd == 7 ) Sound_Play3D("BOSSKDIE.VOC", 1.0f);
  1142. else if ( nDeathSnd == 8 ) Sound_Play3D("KELL-7.VOC", 1.0f);
  1143. else if ( nDeathSnd == 9 ) Sound_Play3D("PHASE1C.VOC", 1.0f);
  1144. else if ( nDeathSnd == 10) Sound_Play3D("PHASE2C.VOC", 1.0f);
  1145. else if ( nDeathSnd == 11) Sound_Play3D("PHASE3C.VOC", 1.0f);
  1146. else if ( nDeathSnd == 12) Sound_Play3D("BOBA-4.VOC", 1.0f);
  1147. bJustDied = true;
  1148. Obj_JustDied();
  1149. }
  1150. else
  1151. {
  1152. int r = Math_Rand();
  1153. if ( obj_Speed > 0.3f )
  1154. {
  1155. //hack for DT's...
  1156. r = 0;
  1157. }
  1158. if ( nDmgSnd != 1 && ((Obj_GetLocalVarI(AI_Flags)&AI_Flags_MeleeWhileInjured)==0||r<30) )
  1159. {
  1160. obj_Frame = 0;
  1161. obj_Delay = 25;
  1162. obj_FrameDelay = 25;
  1163. obj_Action = Anim_Injured;
  1164. obj_loc_z += 0.5f;
  1165. Obj_UpdateLoc();
  1166. }
  1167. //-----------damage sound---------------
  1168. if ( nDmgSnd == 0 ) Sound_Play3D("ST-HRT-1.VOC", 1.0f);
  1169. else if ( nDmgSnd == 1 ) Sound_Play3D("CREATHRT.VOC", 100.0f);
  1170. else if ( nDmgSnd == 2 ) Sound_Play3D("REEYEE-2.VOC", 1.0f);
  1171. else if ( nDmgSnd == 3 ) Sound_Play3D("GAMOR-2.VOC", 1.0f);
  1172. else if ( nDmgSnd == 4 ) Sound_Play3D("GAMOR-3.VOC", 1.0f);
  1173. else if ( nDmgSnd == 5 ) Sound_Play3D("KELL-5.VOC", 1.0f);
  1174. else if ( nDmgSnd == 6 ) Sound_Play3D("PHASE1B.VOC", 1.0f);
  1175. else if ( nDmgSnd == 7 ) Sound_Play3D("PHASE2B.VOC", 1.0f);
  1176. else if ( nDmgSnd == 8 ) Sound_Play3D("PHASE3B.VOC", 1.0f);
  1177. else if ( nDmgSnd == 9 ) Sound_Play3D("BOBA-3.VOC", 1.0f);
  1178. }
  1179. break;
  1180. case MSG_ALERT:
  1181. {
  1182. if ( System_GetTimer(0) == 0 && (Obj_GetLocalVarI(AI_Flags)&AI_Flags_NoAlert)==0 )
  1183. {
  1184. if ( nAlertSnd == 0 )
  1185. {
  1186. int nAlert = System_GetGlobalVar(0);
  1187. //play alert sound...
  1188. switch (nAlert)
  1189. {
  1190. case 0:
  1191. Sound_Play3D("RANSTO01.VOC", 100.0f);
  1192. break;
  1193. case 1:
  1194. Sound_Play3D("RANSTO02.VOC", 100.0f);
  1195. break;
  1196. case 2:
  1197. Sound_Play3D("RANSTO03.VOC", 100.0f);
  1198. break;
  1199. case 3:
  1200. Sound_Play3D("RANSTO04.VOC", 100.0f);
  1201. break;
  1202. case 4:
  1203. Sound_Play3D("RANSTO05.VOC", 100.0f);
  1204. break;
  1205. case 5:
  1206. Sound_Play3D("RANSTO06.VOC", 100.0f);
  1207. break;
  1208. case 6:
  1209. Sound_Play3D("RANSTO07.VOC", 100.0f);
  1210. break;
  1211. case 7:
  1212. Sound_Play3D("RANSTO08.VOC", 100.0f);
  1213. break;
  1214. }
  1215. nAlert = (nAlert+1)%8;
  1216. System_SetGlobalVar(0, nAlert);
  1217. }
  1218. else if ( nAlertSnd == 1 )
  1219. {
  1220. Sound_Play3D("INTALERT.VOC", 100.0f);
  1221. }
  1222. else if ( nAlertSnd == 2 )
  1223. {
  1224. Sound_Play3D("PROBE-1.VOC", 100.0f);
  1225. }
  1226. else if ( nAlertSnd == 3 )
  1227. {
  1228. Sound_Play3D("REEYEE-1.VOC", 100.0f);
  1229. }
  1230. else if ( nAlertSnd == 4 )
  1231. {
  1232. Sound_Play3D("GAMOR-3.VOC", 100.0f);
  1233. }
  1234. else if ( nAlertSnd == 5 )
  1235. {
  1236. Sound_Play3D("BOSSK-1.VOC", 100.0f);
  1237. }
  1238. else if ( nAlertSnd == 6 )
  1239. {
  1240. Sound_Play3D("KELL-1.VOC", 100.0f);
  1241. }
  1242. else if ( nAlertSnd == 7 )
  1243. {
  1244. Sound_Play3D("PHASE1A.VOC", 100.0f);
  1245. }
  1246. else if ( nAlertSnd == 8 )
  1247. {
  1248. Sound_Play3D("PHASE2A.VOC", 100.0f);
  1249. }
  1250. else if ( nAlertSnd == 9 )
  1251. {
  1252. Sound_Play3D("PHASE3A.VOC", 100.0f);
  1253. }
  1254. else if ( nAlertSnd == 10 )
  1255. {
  1256. Sound_Play3D("BOBA-1.VOC", 100.0f);
  1257. }
  1258. //Reset the timer so we don't play alert sounds too often.
  1259. System_SetTimer(0, 120); //60 ticks per second, 2 second delay: 5*60 = 120
  1260. }
  1261. if ( obj_Action != Anim_Injured )
  1262. {
  1263. L_AI_Chase(true);
  1264. }
  1265. }
  1266. break;
  1267. }
  1268. }
  1269. return bJustDied;
  1270. }
  1271. /***********SPECIFIC ENEMY LOGICS***********/
  1272. //
  1273. // Logic STORM1
  1274. //
  1275. void L_STORM1_SetupLogic()
  1276. {
  1277. L_AI_SetupLogic();
  1278. }
  1279. void L_STORM1_SetupObj()
  1280. {
  1281. L_AI_SetupObj(20, AI_State_Look, 1, 0, Anim_Attacking, Anim_Sec_Attack, false, AI_Flags_None);
  1282. }
  1283. void L_STORM1_Update()
  1284. {
  1285. if ( L_AI_RunAIState(-1, 0) == 1 )
  1286. {
  1287. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IST-GUNI.FME", "RIFLE", 0);
  1288. }
  1289. }
  1290. void L_STORM1_SendMsg()
  1291. {
  1292. L_AI_SendMsg(true, 0, 0, 0);
  1293. }
  1294. //
  1295. // Logic TROOP
  1296. //
  1297. void L_TROOP_SetupLogic()
  1298. {
  1299. L_AI_SetupLogic();
  1300. }
  1301. void L_TROOP_SetupObj()
  1302. {
  1303. L_AI_SetupObj(20, AI_State_Look, 1, 0, Anim_Attacking, Anim_Sec_Attack, false, AI_Flags_None);
  1304. }
  1305. void L_TROOP_Update()
  1306. {
  1307. if ( L_AI_RunAIState(-1, 0) == 1 )
  1308. {
  1309. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IST-GUNI.FME", "RIFLE", 0);
  1310. }
  1311. }
  1312. void L_TROOP_SendMsg()
  1313. {
  1314. L_AI_SendMsg(true, 0, 0, 0);
  1315. }
  1316. //
  1317. // Logic I_OFFICER
  1318. //
  1319. void L_I_OFFICER_SetupLogic()
  1320. {
  1321. L_AI_SetupLogic();
  1322. }
  1323. void L_I_OFFICER_SetupObj()
  1324. {
  1325. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1326. }
  1327. void L_I_OFFICER_Update()
  1328. {
  1329. if ( L_AI_RunAIState(-1, 0) == 1 )
  1330. {
  1331. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IENERGY.FME", "ITEMENERGY", 0);
  1332. }
  1333. }
  1334. void L_I_OFFICER_SendMsg()
  1335. {
  1336. L_AI_SendMsg(false, 0, 0, 0);
  1337. }
  1338. //
  1339. // Logic I_OFFICERR
  1340. //
  1341. void L_I_OFFICERR_SetupLogic()
  1342. {
  1343. L_AI_SetupLogic();
  1344. }
  1345. void L_I_OFFICERR_SetupObj()
  1346. {
  1347. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1348. }
  1349. void L_I_OFFICERR_Update()
  1350. {
  1351. if ( L_AI_RunAIState(-1, 0) == 1 )
  1352. {
  1353. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IKEYR.FME", "RED", 0);
  1354. }
  1355. }
  1356. void L_I_OFFICERR_SendMsg()
  1357. {
  1358. L_AI_SendMsg(false, 0, 0, 0);
  1359. }
  1360. //
  1361. // Logic I_OFFICERB
  1362. //
  1363. void L_I_OFFICERB_SetupLogic()
  1364. {
  1365. L_AI_SetupLogic();
  1366. }
  1367. void L_I_OFFICERB_SetupObj()
  1368. {
  1369. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1370. }
  1371. void L_I_OFFICERB_Update()
  1372. {
  1373. if ( L_AI_RunAIState(-1, 0) == 1 )
  1374. {
  1375. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IKEYB.FME", "BLUE", 0);
  1376. }
  1377. }
  1378. void L_I_OFFICERB_SendMsg()
  1379. {
  1380. L_AI_SendMsg(false, 0, 0, 0);
  1381. }
  1382. //
  1383. // Logic I_OFFICERY
  1384. //
  1385. void L_I_OFFICERY_SetupLogic()
  1386. {
  1387. L_AI_SetupLogic();
  1388. }
  1389. void L_I_OFFICERY_SetupObj()
  1390. {
  1391. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1392. }
  1393. void L_I_OFFICERY_Update()
  1394. {
  1395. if ( L_AI_RunAIState(-1, 0) == 1 )
  1396. {
  1397. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IKEYY.FME", "YELLOW", 0);
  1398. }
  1399. }
  1400. void L_I_OFFICERY_SendMsg()
  1401. {
  1402. L_AI_SendMsg(false, 0, 0, 0);
  1403. }
  1404. //
  1405. // Logic I_OFFICER1
  1406. //
  1407. void L_I_OFFICER1_SetupLogic()
  1408. {
  1409. L_AI_SetupLogic();
  1410. }
  1411. void L_I_OFFICER1_SetupObj()
  1412. {
  1413. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1414. }
  1415. void L_I_OFFICER1_Update()
  1416. {
  1417. if ( L_AI_RunAIState(-1, 0) == 1 )
  1418. {
  1419. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE1", 0);
  1420. }
  1421. }
  1422. void L_I_OFFICER1_SendMsg()
  1423. {
  1424. L_AI_SendMsg(false, 0, 0, 0);
  1425. }
  1426. //
  1427. // Logic I_OFFICER2
  1428. //
  1429. void L_I_OFFICER2_SetupLogic()
  1430. {
  1431. L_AI_SetupLogic();
  1432. }
  1433. void L_I_OFFICER2_SetupObj()
  1434. {
  1435. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1436. }
  1437. void L_I_OFFICER2_Update()
  1438. {
  1439. if ( L_AI_RunAIState(-1, 0) == 1 )
  1440. {
  1441. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE2", 0);
  1442. }
  1443. }
  1444. void L_I_OFFICER2_SendMsg()
  1445. {
  1446. L_AI_SendMsg(false, 0, 0, 0);
  1447. }
  1448. //
  1449. // Logic I_OFFICER3
  1450. //
  1451. void L_I_OFFICER3_SetupLogic()
  1452. {
  1453. L_AI_SetupLogic();
  1454. }
  1455. void L_I_OFFICER3_SetupObj()
  1456. {
  1457. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1458. }
  1459. void L_I_OFFICER3_Update()
  1460. {
  1461. if ( L_AI_RunAIState(-1, 0) == 1 )
  1462. {
  1463. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE3", 0);
  1464. }
  1465. }
  1466. void L_I_OFFICER3_SendMsg()
  1467. {
  1468. L_AI_SendMsg(false, 0, 0, 0);
  1469. }
  1470. //
  1471. // Logic I_OFFICER4
  1472. //
  1473. void L_I_OFFICER4_SetupLogic()
  1474. {
  1475. L_AI_SetupLogic();
  1476. }
  1477. void L_I_OFFICER4_SetupObj()
  1478. {
  1479. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1480. }
  1481. void L_I_OFFICER4_Update()
  1482. {
  1483. if ( L_AI_RunAIState(-1, 0) == 1 )
  1484. {
  1485. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE4", 0);
  1486. }
  1487. }
  1488. void L_I_OFFICER4_SendMsg()
  1489. {
  1490. L_AI_SendMsg(false, 0, 0, 0);
  1491. }
  1492. //
  1493. // Logic I_OFFICER5
  1494. //
  1495. void L_I_OFFICER5_SetupLogic()
  1496. {
  1497. L_AI_SetupLogic();
  1498. }
  1499. void L_I_OFFICER5_SetupObj()
  1500. {
  1501. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1502. }
  1503. void L_I_OFFICER5_Update()
  1504. {
  1505. if ( L_AI_RunAIState(-1, 0) == 1 )
  1506. {
  1507. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE5", 0);
  1508. }
  1509. }
  1510. void L_I_OFFICER5_SendMsg()
  1511. {
  1512. L_AI_SendMsg(false, 0, 0, 0);
  1513. }
  1514. //
  1515. // Logic I_OFFICER6
  1516. //
  1517. void L_I_OFFICER6_SetupLogic()
  1518. {
  1519. L_AI_SetupLogic();
  1520. }
  1521. void L_I_OFFICER6_SetupObj()
  1522. {
  1523. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1524. }
  1525. void L_I_OFFICER6_Update()
  1526. {
  1527. if ( L_AI_RunAIState(-1, 0) == 1 )
  1528. {
  1529. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE6", 0);
  1530. }
  1531. }
  1532. void L_I_OFFICER6_SendMsg()
  1533. {
  1534. L_AI_SendMsg(false, 0, 0, 0);
  1535. }
  1536. //
  1537. // Logic I_OFFICER7
  1538. //
  1539. void L_I_OFFICER7_SetupLogic()
  1540. {
  1541. L_AI_SetupLogic();
  1542. }
  1543. void L_I_OFFICER7_SetupObj()
  1544. {
  1545. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1546. }
  1547. void L_I_OFFICER7_Update()
  1548. {
  1549. if ( L_AI_RunAIState(-1, 0) == 1 )
  1550. {
  1551. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE7", 0);
  1552. }
  1553. }
  1554. void L_I_OFFICER7_SendMsg()
  1555. {
  1556. L_AI_SendMsg(false, 0, 0, 0);
  1557. }
  1558. //
  1559. // Logic I_OFFICER8
  1560. //
  1561. void L_I_OFFICER8_SetupLogic()
  1562. {
  1563. L_AI_SetupLogic();
  1564. }
  1565. void L_I_OFFICER8_SetupObj()
  1566. {
  1567. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1568. }
  1569. void L_I_OFFICER8_Update()
  1570. {
  1571. if ( L_AI_RunAIState(-1, 0) == 1 )
  1572. {
  1573. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE8", 0);
  1574. }
  1575. }
  1576. void L_I_OFFICER8_SendMsg()
  1577. {
  1578. L_AI_SendMsg(false, 0, 0, 0);
  1579. }
  1580. //
  1581. // Logic I_OFFICER9
  1582. //
  1583. void L_I_OFFICER9_SetupLogic()
  1584. {
  1585. L_AI_SetupLogic();
  1586. }
  1587. void L_I_OFFICER9_SetupObj()
  1588. {
  1589. L_AI_SetupObj(10, AI_State_Look, 0, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_None);
  1590. }
  1591. void L_I_OFFICER9_Update()
  1592. {
  1593. if ( L_AI_RunAIState(-1, 0) == 1 )
  1594. {
  1595. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "DET_CODE.FME", "CODE9", 0);
  1596. }
  1597. }
  1598. void L_I_OFFICER9_SendMsg()
  1599. {
  1600. L_AI_SendMsg(false, 0, 0, 0);
  1601. }
  1602. //
  1603. // Logic COMMANDO
  1604. //
  1605. void L_COMMANDO_SetupLogic()
  1606. {
  1607. L_AI_SetupLogic();
  1608. }
  1609. void L_COMMANDO_SetupObj()
  1610. {
  1611. L_AI_SetupObj(30, AI_State_Look, 1, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_Allow_Double_Shoot);
  1612. }
  1613. void L_COMMANDO_Update()
  1614. {
  1615. if ( L_AI_RunAIState(-1, 0) == 1 )
  1616. {
  1617. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IST-GUNI.FME", "RIFLE", 0);
  1618. }
  1619. }
  1620. void L_COMMANDO_SendMsg()
  1621. {
  1622. L_AI_SendMsg(false, 0, 0, 0);
  1623. }
  1624. //
  1625. // Logic BOSSK
  1626. //
  1627. void L_BOSSK_SetupLogic()
  1628. {
  1629. L_AI_SetupLogic();
  1630. }
  1631. void L_BOSSK_SetupObj()
  1632. {
  1633. L_AI_SetupObj(50, AI_State_Look, 1, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_ShootExp);
  1634. }
  1635. void L_BOSSK_Update()
  1636. {
  1637. if ( L_AI_RunAIState(-1, 0) == 1 )
  1638. {
  1639. //if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IST-GUNI.FME", "RIFLE", 0);
  1640. }
  1641. }
  1642. void L_BOSSK_SendMsg()
  1643. {
  1644. L_AI_SendMsg(false, 7, 4, 5);
  1645. }
  1646. //
  1647. // Logic INT_DROID
  1648. //
  1649. void L_INT_DROID_SetupLogic()
  1650. {
  1651. L_AI_SetupLogic();
  1652. }
  1653. void L_INT_DROID_SetupObj()
  1654. {
  1655. L_AI_SetupObj(50, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, true, AI_Flags_Floating|AI_Flags_Has_Melee);
  1656. Obj_SetProjectileData("SPRITE", "WIDBALL.WAX", "WEMISS.WAX", "PROBFIR1.VOC", "EX-TINY1.VOC", 8, 0.0);
  1657. }
  1658. void L_INT_DROID_Update()
  1659. {
  1660. if ( L_AI_RunAIState(0, 5) == 1 )
  1661. {
  1662. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IPOWER.FME", "POWER", 0);
  1663. }
  1664. }
  1665. void L_INT_DROID_SendMsg()
  1666. {
  1667. L_AI_SendMsg(false, 1, -1, 1);
  1668. }
  1669. //
  1670. // Logic PROBE_DROID
  1671. //
  1672. void L_PROBE_DROID_SetupLogic()
  1673. {
  1674. L_AI_SetupLogic();
  1675. }
  1676. void L_PROBE_DROID_SetupObj()
  1677. {
  1678. L_AI_SetupObj(50, AI_State_Look, 1, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_Floating|AI_Flags_Allow_Double_Shoot);
  1679. Obj_SetLocalVar(AI_Min_Reaction, Sprite_GetFrameCnt(Anim_Moving, 0)*7);
  1680. }
  1681. void L_PROBE_DROID_Update()
  1682. {
  1683. ceil_dist = 10.0f;
  1684. if ( L_AI_RunAIState(-1, 0) == 1 )
  1685. {
  1686. if ( !Obj_In_Water() )
  1687. {
  1688. float ground_height = Map_GetFloorHeight(0, -1);
  1689. if ( obj_loc_z < ground_height+1.0f )
  1690. Map_AddObject("FRAME", "IPOWER.FME", "POWER", 0);
  1691. }
  1692. }
  1693. ceil_dist = 5.0f;
  1694. }
  1695. void L_PROBE_DROID_SendMsg()
  1696. {
  1697. bool bJustDied = L_AI_SendMsg(false, 2, -1, 2);
  1698. //this enemy explodes after it dies...
  1699. if ( bJustDied )
  1700. {
  1701. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  1702. Map_AddExplosion(obj_loc_x, obj_loc_y, Map_GetFloorHeight(0, -1), 10.0f, 20.0f, 1.0f, 0.5f, "MINEEXP.WAX", "EX-SMALL.VOC", false, -1);
  1703. }
  1704. }
  1705. //
  1706. // Logic REMOTE
  1707. //
  1708. void L_REMOTE_SetupLogic()
  1709. {
  1710. //we don't want standard alerts, this unit acts the same even if no players are present.
  1711. //Logic_AddMsgMask(MSG_NRML_DAMAGE);
  1712. //Logic_AddMsgMask(MSG_MELEE_DAMAGE);
  1713. }
  1714. void L_REMOTE_SetupObj()
  1715. {
  1716. //L_AI_SetupObj(20, AI_State_Remote|AI_State_Transition, 1, 0, Anim_Attacking, Anim_Sec_Attack, true, AI_Flags_Floating|AI_Flags_NoAlert);
  1717. //obj_Speed = 1.0f;
  1718. Obj_SetFlag(OFLAGS_INVISIBLE);
  1719. }
  1720. void L_REMOTE_Update()
  1721. {
  1722. /*
  1723. if ( L_AI_RunAIState(-1, 0) == 1 )
  1724. {
  1725. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IPOWER.FME", "POWER", 0);
  1726. }
  1727. */
  1728. }
  1729. void L_REMOTE_SendMsg()
  1730. {
  1731. //L_AI_SendMsg(false, 3, -1, 3);
  1732. }
  1733. //
  1734. // SEWER1
  1735. //
  1736. void L_SEWER1_SetupLogic()
  1737. {
  1738. //we don't want standard alerts, this unit acts the same even if no players are present.
  1739. Logic_AddMsgMask(MSG_NRML_DAMAGE);
  1740. Logic_AddMsgMask(MSG_MELEE_DAMAGE);
  1741. }
  1742. void L_SEWER1_SetupObj()
  1743. {
  1744. L_AI_SetupObj(30, AI_State_Wander_UG|AI_State_Transition, 1, 0, Anim_Moving, Anim_Attacking, true, AI_Flags_Has_Melee | AI_Flags_SingleAttckOnly | AI_Flags_NoRangeAttck | AI_Flags_Underground | AI_Flags_FloatOnWater);
  1745. obj_Speed = 0.1f;
  1746. }
  1747. void L_SEWER1_Update()
  1748. {
  1749. if ( L_AI_RunAIState(1, 20) == 1 )
  1750. {
  1751. //sewer bugs don't leave anything behind.
  1752. //Map_AddObject("FRAME", "IPOWER.FME", "POWER", 0);
  1753. }
  1754. }
  1755. void L_SEWER1_SendMsg()
  1756. {
  1757. L_AI_SendMsg(false, 4, 1, -1);
  1758. }
  1759. //
  1760. // REE_YEES
  1761. //
  1762. void L_REE_YEES_SetupLogic()
  1763. {
  1764. L_AI_SetupLogic();
  1765. }
  1766. void L_REE_YEES_SetupObj()
  1767. {
  1768. L_AI_SetupObj(30, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, true, AI_Flags_Has_Melee);
  1769. Obj_SetProjectileData("FRAME", "IDET.FME", "DETEXP.WAX", "PROBFIR1.VOC", "EX-SMALL.VOC", 20, 20.0);
  1770. Obj_SetLocalVar(AI_MaxAttackRange, 75);
  1771. }
  1772. void L_REE_YEES_Update()
  1773. {
  1774. if ( L_AI_RunAIState(0, 10) == 1 )
  1775. {
  1776. if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IDETS.FME", "DETONATORS", 0);
  1777. }
  1778. }
  1779. void L_REE_YEES_SendMsg()
  1780. {
  1781. L_AI_SendMsg(false, 5, 2, 3);
  1782. }
  1783. //
  1784. // REE_YEES2
  1785. //
  1786. void L_REE_YEES2_SetupLogic()
  1787. {
  1788. L_AI_SetupLogic();
  1789. }
  1790. void L_REE_YEES2_SetupObj()
  1791. {
  1792. L_AI_SetupObj(30, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, true, AI_Flags_Has_Melee | AI_Flags_NoRangeAttck);
  1793. Obj_SetProjectileData("FRAME", "IDET.FME", "DETEXP.WAX", "PROBFIR1.VOC", "EX-SMALL.VOC", 20, 20.0);
  1794. }
  1795. void L_REE_YEES2_Update()
  1796. {
  1797. if ( L_AI_RunAIState(0, 10) == 1 )
  1798. {
  1799. //no DT's, melee only.
  1800. //if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IDETS.FME", "DETONATORS", 0);
  1801. }
  1802. }
  1803. void L_REE_YEES2_SendMsg()
  1804. {
  1805. L_AI_SendMsg(false, 5, 2, 3);
  1806. }
  1807. //
  1808. // G_GUARD
  1809. //
  1810. void L_G_GUARD_SetupLogic()
  1811. {
  1812. L_AI_SetupLogic();
  1813. }
  1814. void L_G_GUARD_SetupObj()
  1815. {
  1816. //add AI_Flags_Melee_Random later...
  1817. L_AI_SetupObj(90, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, true, AI_Flags_Has_Melee | AI_Flags_NoRangeAttck | AI_Flags_SingleAttckOnly | AI_Flags_Melee_Random);
  1818. //Obj_SetProjectileData("FRAME", "IDET.FME", "DETEXP.WAX", "PROBFIR1.VOC", "EX-SMALL.VOC", 20, 20.0);
  1819. }
  1820. void L_G_GUARD_Update()
  1821. {
  1822. if ( L_AI_RunAIState(2, 40) == 1 )
  1823. {
  1824. //no DT's, melee only.
  1825. //if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IDETS.FME", "DETONATORS", 0);
  1826. }
  1827. }
  1828. void L_G_GUARD_SendMsg()
  1829. {
  1830. L_AI_SendMsg(false, 6, 3, 4);
  1831. }
  1832. //
  1833. // D_TROOP1
  1834. //
  1835. void L_D_TROOP1_SetupLogic()
  1836. {
  1837. L_AI_SetupLogic();
  1838. }
  1839. void L_D_TROOP1_SetupObj()
  1840. {
  1841. //add AI_Flags_Melee_Random later...
  1842. L_AI_SetupObj(180, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, true, AI_Flags_Has_Melee | AI_Flags_NoRangeAttck | AI_Flags_MeleeWhileInjured);
  1843. obj_Speed = 0.4f;
  1844. Obj_SetLocalVar(AI_Shoot_Delay, 5.0f);
  1845. Obj_SetLocalVar(AI_Walk_Delay, 10);
  1846. }
  1847. void L_D_TROOP1_Update()
  1848. {
  1849. if ( L_AI_RunAIState(4, 40) == 1 )
  1850. {
  1851. //no DT's, melee only.
  1852. //if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IDETS.FME", "DETONATORS", 0);
  1853. }
  1854. }
  1855. void L_D_TROOP1_SendMsg()
  1856. {
  1857. L_AI_SendMsg(false, 9, 6, 7);
  1858. }
  1859. //
  1860. // D_TROOP2
  1861. //
  1862. void L_D_TROOP2_SetupLogic()
  1863. {
  1864. L_AI_SetupLogic();
  1865. }
  1866. void L_D_TROOP2_SetupObj()
  1867. {
  1868. //add AI_Flags_Melee_Random later...
  1869. L_AI_SetupObj(180, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, false, AI_Flags_Floating|AI_Flags_Allow_Double_Shoot);
  1870. obj_Speed = 0.4f;
  1871. Obj_SetLocalVar(AI_Walk_Delay, 10);
  1872. Obj_SetLocalVar(AI_Shoot_Cone, 0.0f);
  1873. Obj_SetLocalVar(AI_Shoot_Height, 5.0f);
  1874. Obj_SetLocalVar(AI_Shoot_Delay, 1.0f);
  1875. Obj_SetProjectileData("SPRITE", "WPLASMA.WAX", "PLASEXP.WAX", "PLASMA4.VOC", "EX-TINY1.VOC", 30, 0.0);
  1876. }
  1877. void L_D_TROOP2_Update()
  1878. {
  1879. if ( L_AI_RunAIState(4, 40) == 1 )
  1880. {
  1881. //no DT's, melee only.
  1882. //if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IDETS.FME", "DETONATORS", 0);
  1883. }
  1884. }
  1885. void L_D_TROOP2_SendMsg()
  1886. {
  1887. L_AI_SendMsg(false, 10, 7, 8);
  1888. }
  1889. //
  1890. // D_TROOP3
  1891. //
  1892. void L_D_TROOP3_SetupLogic()
  1893. {
  1894. L_AI_SetupLogic();
  1895. }
  1896. void L_D_TROOP3_SetupObj()
  1897. {
  1898. //add AI_Flags_Melee_Random later...
  1899. L_AI_SetupObj(180, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, false, AI_Flags_Floating|AI_Flags_Allow_Double_Shoot);
  1900. obj_Speed = 0.4f;
  1901. Obj_SetLocalVar(AI_Walk_Delay, 10);
  1902. Obj_SetLocalVar(AI_Shoot_Cone, 0.0f);
  1903. Obj_SetLocalVar(AI_Shoot_Height, 5.0f);
  1904. Obj_SetLocalVar(AI_Shoot_Delay, 1.0f);
  1905. Obj_SetLocalVar(AI_Walk_Delay, 10);
  1906. Obj_SetProjectileData("SPRITE", "WPLASMA.WAX", "PLASEXP.WAX", "PLASMA4.VOC", "EX-TINY1.VOC", 30, 0.0);
  1907. }
  1908. void L_D_TROOP3_Update()
  1909. {
  1910. if ( L_AI_RunAIState(4, 40) == 1 )
  1911. {
  1912. //no DT's, melee only.
  1913. //if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IDETS.FME", "DETONATORS", 0);
  1914. }
  1915. }
  1916. void L_D_TROOP3_SendMsg()
  1917. {
  1918. L_AI_SendMsg(false, 11, 8, 9);
  1919. }
  1920. //
  1921. // BOBA_FETT
  1922. //
  1923. void L_BOBA_FETT_SetupLogic()
  1924. {
  1925. L_AI_SetupLogic();
  1926. }
  1927. void L_BOBA_FETT_SetupObj()
  1928. {
  1929. //add AI_Flags_Melee_Random later...
  1930. L_AI_SetupObj(180, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, false, AI_Flags_Floating|AI_Flags_Allow_Double_Shoot);
  1931. obj_Speed = 0.4f;
  1932. Obj_SetLocalVar(AI_Walk_Delay, 10);
  1933. Obj_SetLocalVar(AI_Shoot_Cone, 0.0f);
  1934. Obj_SetLocalVar(AI_Shoot_Height, 5.0f);
  1935. Obj_SetLocalVar(AI_Shoot_Delay, 10.0f);
  1936. Obj_SetLocalVar(AI_Walk_Delay, 10);
  1937. Obj_SetProjectileData("SPRITE", "BOBABALL.WAX", "BULLEXP.WAX", "BOBA-2.VOC", "EX-TINY1.VOC", 30, 0.0);
  1938. }
  1939. void L_BOBA_FETT_Update()
  1940. {
  1941. if ( L_AI_RunAIState(4, 40) == 1 )
  1942. {
  1943. //no DT's, melee only.
  1944. //if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IDETS.FME", "DETONATORS", 0);
  1945. }
  1946. }
  1947. void L_BOBA_FETT_SendMsg()
  1948. {
  1949. L_AI_SendMsg(false, 12, 9, 10);
  1950. }
  1951. //
  1952. // KELL
  1953. //
  1954. void L_KELL_SetupLogic()
  1955. {
  1956. L_AI_SetupLogic();
  1957. }
  1958. void L_KELL_SetupObj()
  1959. {
  1960. //Half HP until the fist damage is beefed up.
  1961. int HP = 180;
  1962. L_AI_SetupObj(HP, AI_State_Look, 1, 0, Anim_Sec_Attack, Anim_Attacking, true, AI_Flags_Has_Melee | AI_Flags_NoRangeAttck | AI_Flags_MeleeWhileInjured);
  1963. obj_Speed = 0.2f;
  1964. obj_Radius = 4.0f;
  1965. Obj_SetLocalVar(AI_Walk_Delay, 10);
  1966. }
  1967. void L_KELL_Update()
  1968. {
  1969. if ( L_AI_RunAIState(3, 20) == 1 )
  1970. {
  1971. //no DT's, melee only.
  1972. //if ( !Obj_In_Water() ) Map_AddObject("FRAME", "IDETS.FME", "DETONATORS", 0);
  1973. }
  1974. }
  1975. void L_KELL_SendMsg()
  1976. {
  1977. L_AI_SendMsg(false, 8, 5, 6);
  1978. }
  1979. //
  1980. // Logic TURRET
  1981. //
  1982. void L_TURRET_SetupLogic()
  1983. {
  1984. L_AI_SetupLogic();
  1985. }
  1986. void L_TURRET_SetupObj()
  1987. {
  1988. obj_Speed = 0.0f;
  1989. obj_dY = 0.015f;
  1990. obj_HP = 70;
  1991. obj_Radius = 2.0f;
  1992. obj_Height = -2.0f;
  1993. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  1994. Obj_SetFlag(OFLAGS_COLLIDE_PROJECTILE);
  1995. Obj_SetFlag(OFLAGS_COLLIDE_OBJECTS);
  1996. Obj_SetFlag(OFLAGS_ENEMY);
  1997. Obj_EnableAnim(1);
  1998. //put into the "idle" action...
  1999. obj_Action = Anim_Idle;
  2000. obj_Frame = 0;
  2001. obj_Delay = 15;
  2002. obj_FrameDelay = 15;
  2003. //Shoot delay...
  2004. Obj_SetLocalVar(1, 60);
  2005. }
  2006. void L_TURRET_Update()
  2007. {
  2008. int ret = 0;
  2009. //I'm dead, there is nothing to do now. Eventually updates for this AI should just be shut off.
  2010. if ( obj_Alive == 1 )
  2011. {
  2012. float px, py, pz, dx, dy, nx, ny;
  2013. Player_GetLoc(px, py, pz);
  2014. dx = px-obj_loc_x;
  2015. dy = py-obj_loc_y;
  2016. Math_Normalize(dx, dy, nx, ny);
  2017. float angle = obj_Yaw;
  2018. const float TwoPi = 6.283185307179586476925286766559f;
  2019. const float Pi = 3.1415926535897932384626433832795f;
  2020. const float shootEps = 0.1745f; //about 10 degrees.
  2021. int bShoot = 0;
  2022. if ( Math_Abs(dx) < 80.0f && Math_Abs(dy) < 80.0f )
  2023. {
  2024. if ( Map_HasPlayerLOS() == 1 )
  2025. {
  2026. if ( ny >= 0.0f )
  2027. {
  2028. angle = Math_ACos(-nx);
  2029. }
  2030. else
  2031. {
  2032. angle = TwoPi - Math_ACos(-nx);
  2033. }
  2034. const float PiOver2 = 1.570796326794896619231321692f;
  2035. angle += PiOver2;
  2036. if ( angle < 0 ) angle += TwoPi;
  2037. else if ( angle > TwoPi ) angle -= TwoPi;
  2038. //now rotate towards the player...
  2039. float dY = angle - obj_Yaw;
  2040. if ( Math_Abs(dY) > Pi )
  2041. {
  2042. if ( dY > 0.0f ) dY -= TwoPi;
  2043. else dY += TwoPi;
  2044. }
  2045. if ( Math_Abs(dY) < shootEps )
  2046. {
  2047. bShoot = 1;
  2048. }
  2049. if ( dY > 0.026f ) dY = 0.026f;
  2050. else if ( dY < -0.026f ) dY = -0.026f;
  2051. obj_Yaw += dY;
  2052. }
  2053. }
  2054. float shootDelay = Obj_GetLocalVar(1);
  2055. if ( shootDelay > 0.0f )
  2056. {
  2057. shootDelay -= 1.0f;
  2058. }
  2059. if ( bShoot == 1 && shootDelay <= 0.0f )
  2060. {
  2061. //now shoot at the player. :)
  2062. Obj_ShootPlayer( 0, 0.0f, 1, Obj_GetLocalVarI(AI_Shoot_Height) ); //use blaster bolts...
  2063. shootDelay = 60.0f;
  2064. }
  2065. Obj_SetLocalVar(1, shootDelay);
  2066. }
  2067. }
  2068. void L_TURRET_SendMsg()
  2069. {
  2070. if ( obj_Alive == 1 )
  2071. {
  2072. switch (obj_uMsg)
  2073. {
  2074. case MSG_NRML_DAMAGE:
  2075. obj_HP -= msg_nVal;
  2076. if ( obj_HP <= 0 )
  2077. {
  2078. obj_HP = 0;
  2079. obj_Alive = 0;
  2080. obj_Frame = 0;
  2081. obj_Action = Anim_Dead;
  2082. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2083. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  2084. Obj_ClearFlag(OFLAGS_COLLIDE_OBJECTS);
  2085. //-----------death---------------
  2086. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  2087. Map_AddExplosion(obj_loc_x, obj_loc_y, obj_loc_z, 10.0f, 0.0f, 0.0f, 0.25f, "MISSEXP.WAX", "EX-SMALL.VOC", false, -1);
  2088. Obj_Delete();
  2089. Obj_JustDied();
  2090. }
  2091. break;
  2092. case MSG_MELEE_DAMAGE:
  2093. obj_HP -= msg_nVal;
  2094. if ( obj_HP <= 0 )
  2095. {
  2096. obj_HP = 0;
  2097. obj_Alive = 0;
  2098. obj_Frame = 0;
  2099. obj_Action = Anim_Dead;
  2100. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2101. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  2102. Obj_ClearFlag(OFLAGS_COLLIDE_OBJECTS);
  2103. //-----------death---------------
  2104. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  2105. Map_AddExplosion(obj_loc_x, obj_loc_y, obj_loc_z, 10.0f, 0.0f, 0.0f, 0.25f, "MISSEXP.WAX", "EX-SMALL.VOC", false, -1);
  2106. Obj_Delete();
  2107. Obj_JustDied();
  2108. }
  2109. break;
  2110. case MSG_ALERT:
  2111. {
  2112. }
  2113. break;
  2114. }
  2115. }
  2116. }
  2117. /***********GENERATORS*******/
  2118. void GeneratorUpdate(string type, string file, string logic)
  2119. {
  2120. if ( Obj_GetLocalVar(7) == 0.0f ) { return; }
  2121. if ( Obj_GetLocalVar(0) == 0.0f && Obj_GetLocalVar(8) == 0.0f )
  2122. {
  2123. //start working...
  2124. //are there too many still alive?
  2125. if ( Obj_GetLocalVar(9) < Obj_GetLocalVar(2) && Obj_GetLocalVar(8) <= 0.0f )
  2126. {
  2127. //is the player in the correct range?
  2128. float d = Obj_GetDistFromPlayer();
  2129. if ( d >= Obj_GetLocalVar(3) && d <= Obj_GetLocalVar(4) )
  2130. {
  2131. //now make sure there is no LOS to the player.
  2132. if ( Map_HasPlayerLOS() == 0 )
  2133. {
  2134. //now go ahead and generate Probe Droid and set them to wander...
  2135. int hObj = Map_AddObject(type, file, logic, 0);
  2136. Obj_AddObjMsgHandler(hObj, MSG_OBJ_DEAD);
  2137. Obj_QueAddObj_SetLocalVar(AI_State, AI_State_Wander | AI_State_Transition);
  2138. int numAlive = Obj_GetLocalVar(9);
  2139. Obj_SetLocalVar(9, numAlive+1);
  2140. int numGen = Obj_GetLocalVar(10);
  2141. Obj_SetLocalVar(10, numGen+1);
  2142. if ( numGen >= Obj_GetLocalVar(5) )
  2143. {
  2144. //ok we're done here...
  2145. Obj_Delete();
  2146. }
  2147. Obj_SetLocalVar(8, Obj_GetLocalVar(1) );
  2148. }
  2149. }
  2150. }
  2151. else if ( Obj_GetLocalVar(8) > 0.0f )
  2152. {
  2153. float interval = Obj_GetLocalVar(8);
  2154. interval -= dt;
  2155. Obj_SetLocalVar(8, interval);
  2156. }
  2157. }
  2158. else
  2159. {
  2160. float delay = Obj_GetLocalVar(0);
  2161. if ( delay == 0.0f )
  2162. {
  2163. float interval = Obj_GetLocalVar(8) - dt;
  2164. if ( interval < 0.0f ) { interval = 0.0f; }
  2165. Obj_SetLocalVar(8, interval);
  2166. }
  2167. else
  2168. {
  2169. delay = delay - dt;
  2170. if ( delay < 0.0f ) { delay = 0.0f; }
  2171. Obj_SetLocalVar(0, delay);
  2172. }
  2173. }
  2174. }
  2175. void GeneratorSendMsg()
  2176. {
  2177. switch (obj_uMsg)
  2178. {
  2179. case MSG_MASTER_ON:
  2180. Obj_SetLocalVar(7, 1.0f);
  2181. break;
  2182. case MSG_OBJ_DEAD:
  2183. {
  2184. //remove the object message handler.
  2185. Obj_RemoveObjMsgHandler(msg_nVal, MSG_OBJ_DEAD);
  2186. //decrease the number alive counter.
  2187. int numAlive = Obj_GetLocalVar(9);
  2188. Obj_SetLocalVar(9, numAlive-1);
  2189. }
  2190. break;
  2191. }
  2192. }
  2193. void SetupGeneratorLogic()
  2194. {
  2195. Logic_AddMsgMask(MSG_MASTER_ON);
  2196. Logic_AddMsgMask(MSG_OBJ_DEAD);
  2197. }
  2198. //
  2199. // GENERATORPROBE_DROID
  2200. //
  2201. void L_GENERATORPROBE_DROID_SetupLogic()
  2202. {
  2203. SetupGeneratorLogic();
  2204. }
  2205. void L_GENERATORPROBE_DROID_SetupObj()
  2206. {
  2207. Obj_SetFlag(OFLAGS_INVISIBLE);
  2208. }
  2209. void L_GENERATORPROBE_DROID_Update()
  2210. {
  2211. GeneratorUpdate("SPRITE", "PROBE.WAX", "PROBE_DROID");
  2212. }
  2213. void L_GENERATORPROBE_DROID_SendMsg()
  2214. {
  2215. GeneratorSendMsg();
  2216. }
  2217. //
  2218. // GENERATORINT_DROID
  2219. //
  2220. void L_GENERATORINT_DROID_SetupLogic()
  2221. {
  2222. SetupGeneratorLogic();
  2223. }
  2224. void L_GENERATORINT_DROID_SetupObj()
  2225. {
  2226. Obj_SetFlag(OFLAGS_INVISIBLE);
  2227. }
  2228. void L_GENERATORINT_DROID_Update()
  2229. {
  2230. GeneratorUpdate("SPRITE", "INTDROID.WAX", "INT_DROID");
  2231. }
  2232. void L_GENERATORINT_DROID_SendMsg()
  2233. {
  2234. GeneratorSendMsg();
  2235. }
  2236. //
  2237. // GENERATORSTORM1
  2238. //
  2239. void L_GENERATORSTORM1_SetupLogic()
  2240. {
  2241. SetupGeneratorLogic();
  2242. }
  2243. void L_GENERATORSTORM1_SetupObj()
  2244. {
  2245. Obj_SetFlag(OFLAGS_INVISIBLE);
  2246. }
  2247. void L_GENERATORSTORM1_Update()
  2248. {
  2249. GeneratorUpdate("SPRITE", "STORMFIN.WAX", "STORM1");
  2250. }
  2251. void L_GENERATORSTORM1_SendMsg()
  2252. {
  2253. GeneratorSendMsg();
  2254. }
  2255. //
  2256. // GENERATORCOMMANDO
  2257. //
  2258. void L_GENERATORCOMMANDO_SetupLogic()
  2259. {
  2260. SetupGeneratorLogic();
  2261. }
  2262. void L_GENERATORCOMMANDO_SetupObj()
  2263. {
  2264. Obj_SetFlag(OFLAGS_INVISIBLE);
  2265. }
  2266. void L_GENERATORCOMMANDO_Update()
  2267. {
  2268. GeneratorUpdate("SPRITE", "COMMANDO.WAX", "COMMANDO");
  2269. }
  2270. void L_GENERATORCOMMANDO_SendMsg()
  2271. {
  2272. GeneratorSendMsg();
  2273. }
  2274. //
  2275. // GENERATORSEWER1
  2276. //
  2277. void L_GENERATORSEWER1_SetupLogic()
  2278. {
  2279. SetupGeneratorLogic();
  2280. }
  2281. void L_GENERATORSEWER1_SetupObj()
  2282. {
  2283. Obj_SetFlag(OFLAGS_INVISIBLE);
  2284. }
  2285. void L_GENERATORSEWER1_Update()
  2286. {
  2287. GeneratorUpdate("SPRITE", "SEWERBUG.WAX", "SEWER1");
  2288. }
  2289. void L_GENERATORSEWER1_SendMsg()
  2290. {
  2291. GeneratorSendMsg();
  2292. }
  2293. //
  2294. // GENERATORG_GUARD
  2295. //
  2296. void L_GENERATORG_GUARD_SetupLogic()
  2297. {
  2298. SetupGeneratorLogic();
  2299. }
  2300. void L_GENERATORG_GUARD_SetupObj()
  2301. {
  2302. Obj_SetFlag(OFLAGS_INVISIBLE);
  2303. }
  2304. void L_GENERATORG_GUARD_Update()
  2305. {
  2306. GeneratorUpdate("SPRITE", "GAMGUARD.WAX", "G_GUARD");
  2307. }
  2308. void L_GENERATORG_GUARD_SendMsg()
  2309. {
  2310. GeneratorSendMsg();
  2311. }
  2312. //
  2313. // GENERATORREE_YEES
  2314. //
  2315. void L_GENERATORREE_YEES_SetupLogic()
  2316. {
  2317. SetupGeneratorLogic();
  2318. }
  2319. void L_GENERATORREE_YEES_SetupObj()
  2320. {
  2321. Obj_SetFlag(OFLAGS_INVISIBLE);
  2322. }
  2323. void L_GENERATORREE_YEES_Update()
  2324. {
  2325. GeneratorUpdate("SPRITE", "REEYEES.WAX", "REE_YEES");
  2326. }
  2327. void L_GENERATORREE_YEES_SendMsg()
  2328. {
  2329. GeneratorSendMsg();
  2330. }
  2331. /***********DROIDS***********/
  2332. //
  2333. // Logic MOUSEBOT
  2334. //
  2335. void L_MOUSEBOT_SetupLogic()
  2336. {
  2337. Logic_AddMsgMask(0);
  2338. }
  2339. void L_MOUSEBOT_SetupObj()
  2340. {
  2341. Obj_SetMoveDir( obj_dir_x, obj_dir_y, 0.0f );
  2342. obj_Speed = 0.4f;
  2343. obj_dY = 0.015f;
  2344. Obj_SetLocalVar(0, 0.0f);
  2345. obj_Radius = 2.0f;
  2346. }
  2347. void L_MOUSEBOT_Update()
  2348. {
  2349. //now move around "randomly"
  2350. float p1_x = obj_loc_x + obj_dir_x*obj_Speed;
  2351. float p1_y = obj_loc_y + obj_dir_y*obj_Speed;
  2352. Map_SetStepSize(0.0f);
  2353. Map_CollideObj(p1_x, p1_y, obj_Radius, TRUE, TRUE, TRUE);
  2354. Map_RestoreStepSize();
  2355. //we hit all wall, drop or step.
  2356. if ( Map_GetWallHit() > -1 )
  2357. {
  2358. obj_Speed *= -1.0f;
  2359. }
  2360. obj_Yaw += obj_dY;
  2361. if ( obj_Yaw < 0.0f )
  2362. {
  2363. obj_Yaw += TWO_PI;
  2364. }
  2365. else if ( obj_Yaw > TWO_PI )
  2366. {
  2367. obj_Yaw -= TWO_PI;
  2368. }
  2369. int r = Math_Rand();
  2370. if ( r > 99 )
  2371. {
  2372. obj_Speed = -obj_Speed;
  2373. }
  2374. else if ( r > 90 )
  2375. {
  2376. obj_dY = -obj_dY;
  2377. }
  2378. //randomly play sounds, make sure there is a delay between when sounds can play.
  2379. float fSoundDelay = Obj_GetLocalVar(0);
  2380. if ( r > 35 && r < 37 && fSoundDelay <= 0.0f )
  2381. {
  2382. Sound_Play3D("EEEK-1.VOC", 0.0625f);
  2383. fSoundDelay = 240.0f;
  2384. }
  2385. else
  2386. {
  2387. fSoundDelay -= 1.0f;
  2388. }
  2389. Obj_SetLocalVar(0, fSoundDelay);
  2390. float dx = Math_Sin(obj_Yaw);
  2391. float dy = Math_Cos(obj_Yaw);
  2392. Obj_SetDir( dx, dy, 0.0f );
  2393. Obj_SetMoveDir( dx, dy, 0.0f );
  2394. }
  2395. void L_MOUSEBOT_SendMsg()
  2396. {
  2397. if ( obj_Alive == 1 )
  2398. {
  2399. }
  2400. }
  2401. /***********ITEMS***********/
  2402. //
  2403. // Logic ITEMSHIELD
  2404. //
  2405. void L_ITEMSHIELD_SetupLogic()
  2406. {
  2407. Logic_AddMsgMask(MSG_PICKUP);
  2408. }
  2409. void L_ITEMSHIELD_SetupObj()
  2410. {
  2411. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2412. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  2413. int light = Map_AddLight(0, 0, 2.0f, 10, 20, 128, 20);
  2414. Obj_SetLocalVar(0, light);
  2415. Obj_AttachLight(light);
  2416. }
  2417. void L_ITEMSHIELD_SendMsg()
  2418. {
  2419. switch (obj_uMsg)
  2420. {
  2421. case MSG_PICKUP:
  2422. {
  2423. int shields = Player_GetShields();
  2424. if ( shields < 200 )
  2425. {
  2426. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2427. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  2428. //now add shields...
  2429. shields += 20;
  2430. if ( shields > 200 ) shields = 200;
  2431. Player_SetShields( shields );
  2432. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  2433. Obj_Delete();
  2434. Sound_Play2D("KEY.VOC");
  2435. System_PrintIndex(114);
  2436. Map_RemoveLight( Obj_GetLocalVar(0) );
  2437. }
  2438. }
  2439. break;
  2440. }
  2441. }
  2442. //
  2443. // Logic SHIELD
  2444. //
  2445. void L_SHIELD_SetupLogic()
  2446. {
  2447. Logic_AddMsgMask(MSG_PICKUP);
  2448. }
  2449. void L_SHIELD_SetupObj()
  2450. {
  2451. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2452. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  2453. int light = Map_AddLight(0, 0, 2.0f, 10, 20, 128, 20);
  2454. Obj_SetLocalVar(0, light);
  2455. Obj_AttachLight(light);
  2456. }
  2457. void L_SHIELD_SendMsg()
  2458. {
  2459. L_ITEMSHIELD_SendMsg();
  2460. }
  2461. //
  2462. // POWER
  2463. //
  2464. void L_POWER_SetupLogic()
  2465. {
  2466. Logic_AddMsgMask(MSG_PICKUP);
  2467. }
  2468. void L_POWER_SetupObj()
  2469. {
  2470. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2471. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  2472. //int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  2473. //Obj_SetLocalVar(0, light);
  2474. //Obj_AttachLight(light);
  2475. }
  2476. void L_POWER_Update()
  2477. {
  2478. float ground_height = Map_GetFloorHeight(0, -1);
  2479. //force gravity if this isn't a flying/floating unit.
  2480. bool bUpdate = false;
  2481. if ( obj_loc_z > ground_height )
  2482. {
  2483. obj_loc_z -= 0.4f;
  2484. bUpdate = true;
  2485. }
  2486. if ( obj_loc_z < ground_height )
  2487. {
  2488. obj_loc_z = ground_height;
  2489. bUpdate = true;
  2490. }
  2491. if (bUpdate) Obj_UpdateLoc();
  2492. }
  2493. void L_POWER_SendMsg()
  2494. {
  2495. switch (obj_uMsg)
  2496. {
  2497. case MSG_PICKUP:
  2498. {
  2499. int power = Player_GetAmmo(AMMO_POWER);
  2500. if ( power < 500 )
  2501. {
  2502. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2503. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  2504. power += 10;
  2505. if ( power > 500 ) power = 500;
  2506. Player_SetAmmo( AMMO_POWER, power );
  2507. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  2508. Obj_Delete();
  2509. Sound_Play2D("KEY.VOC");
  2510. System_PrintIndex(201);
  2511. //Map_RemoveLight( Obj_GetLocalVar(0) );
  2512. }
  2513. }
  2514. break;
  2515. }
  2516. }
  2517. //
  2518. // SHELL
  2519. //
  2520. void L_SHELL_SetupLogic()
  2521. {
  2522. Logic_AddMsgMask(MSG_PICKUP);
  2523. }
  2524. void L_SHELL_SetupObj()
  2525. {
  2526. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2527. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  2528. //int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  2529. //Obj_SetLocalVar(0, light);
  2530. //Obj_AttachLight(light);
  2531. }
  2532. void L_SHELL_Update()
  2533. {
  2534. float ground_height = Map_GetFloorHeight(0, -1);
  2535. //force gravity if this isn't a flying/floating unit.
  2536. bool bUpdate = false;
  2537. if ( obj_loc_z > ground_height )
  2538. {
  2539. obj_loc_z -= 0.4f;
  2540. bUpdate = true;
  2541. }
  2542. if ( obj_loc_z < ground_height )
  2543. {
  2544. obj_loc_z = ground_height;
  2545. bUpdate = true;
  2546. }
  2547. if (bUpdate) Obj_UpdateLoc();
  2548. }
  2549. void L_SHELL_SendMsg()
  2550. {
  2551. switch (obj_uMsg)
  2552. {
  2553. case MSG_PICKUP:
  2554. {
  2555. int shells = Player_GetAmmo(AMMO_MORTOR);
  2556. if ( shells < 50 )
  2557. {
  2558. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2559. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  2560. shells += 1;
  2561. if ( shells > 50 ) shells = 50;
  2562. Player_SetAmmo( AMMO_MORTOR, shells );
  2563. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  2564. Obj_Delete();
  2565. Sound_Play2D("KEY.VOC");
  2566. System_PrintIndex(205);
  2567. //Map_RemoveLight( Obj_GetLocalVar(0) );
  2568. }
  2569. }
  2570. break;
  2571. }
  2572. }
  2573. //
  2574. // SHELLS
  2575. //
  2576. void L_SHELLS_SetupLogic()
  2577. {
  2578. Logic_AddMsgMask(MSG_PICKUP);
  2579. }
  2580. void L_SHELLS_SetupObj()
  2581. {
  2582. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2583. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  2584. //int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  2585. //Obj_SetLocalVar(0, light);
  2586. //Obj_AttachLight(light);
  2587. }
  2588. void L_SHELLS_Update()
  2589. {
  2590. float ground_height = Map_GetFloorHeight(0, -1);
  2591. //force gravity if this isn't a flying/floating unit.
  2592. bool bUpdate = false;
  2593. if ( obj_loc_z > ground_height )
  2594. {
  2595. obj_loc_z -= 0.4f;
  2596. bUpdate = true;
  2597. }
  2598. if ( obj_loc_z < ground_height )
  2599. {
  2600. obj_loc_z = ground_height;
  2601. bUpdate = true;
  2602. }
  2603. if (bUpdate) Obj_UpdateLoc();
  2604. }
  2605. void L_SHELLS_SendMsg()
  2606. {
  2607. switch (obj_uMsg)
  2608. {
  2609. case MSG_PICKUP:
  2610. {
  2611. int shells = Player_GetAmmo(AMMO_MORTOR);
  2612. if ( shells < 50 )
  2613. {
  2614. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2615. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  2616. shells += 5;
  2617. if ( shells > 50 ) shells = 50;
  2618. Player_SetAmmo( AMMO_MORTOR, shells );
  2619. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  2620. Obj_Delete();
  2621. Sound_Play2D("KEY.VOC");
  2622. System_PrintIndex(206);
  2623. //Map_RemoveLight( Obj_GetLocalVar(0) );
  2624. }
  2625. }
  2626. break;
  2627. }
  2628. }
  2629. //
  2630. // MINE
  2631. //
  2632. void L_MINE_SetupLogic()
  2633. {
  2634. Logic_AddMsgMask(MSG_PICKUP);
  2635. }
  2636. void L_MINE_SetupObj()
  2637. {
  2638. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2639. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  2640. //int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  2641. //Obj_SetLocalVar(0, light);
  2642. //Obj_AttachLight(light);
  2643. }
  2644. void L_MINE_Update()
  2645. {
  2646. float ground_height = Map_GetFloorHeight(0, -1);
  2647. //force gravity if this isn't a flying/floating unit.
  2648. bool bUpdate = false;
  2649. if ( obj_loc_z > ground_height )
  2650. {
  2651. obj_loc_z -= 0.4f;
  2652. bUpdate = true;
  2653. }
  2654. if ( obj_loc_z < ground_height )
  2655. {
  2656. obj_loc_z = ground_height;
  2657. bUpdate = true;
  2658. }
  2659. if (bUpdate) Obj_UpdateLoc();
  2660. }
  2661. void L_MINE_SendMsg()
  2662. {
  2663. switch (obj_uMsg)
  2664. {
  2665. case MSG_PICKUP:
  2666. {
  2667. int mines = Player_GetAmmo(AMMO_MINE);
  2668. if ( mines < 30 )
  2669. {
  2670. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2671. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  2672. mines += 1;
  2673. if ( mines > 30 ) mines = 30;
  2674. Player_SetAmmo( AMMO_MINE, mines );
  2675. Player_AddItem("MINES");
  2676. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  2677. Obj_Delete();
  2678. Sound_Play2D("KEY.VOC");
  2679. System_PrintIndex(109);
  2680. //Map_RemoveLight( Obj_GetLocalVar(0) );
  2681. }
  2682. }
  2683. break;
  2684. }
  2685. }
  2686. //
  2687. // MINES
  2688. //
  2689. void L_MINES_SetupLogic()
  2690. {
  2691. Logic_AddMsgMask(MSG_PICKUP);
  2692. }
  2693. void L_MINES_SetupObj()
  2694. {
  2695. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2696. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  2697. //int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  2698. //Obj_SetLocalVar(0, light);
  2699. //Obj_AttachLight(light);
  2700. }
  2701. void L_MINES_Update()
  2702. {
  2703. float ground_height = Map_GetFloorHeight(0, -1);
  2704. //force gravity if this isn't a flying/floating unit.
  2705. bool bUpdate = false;
  2706. if ( obj_loc_z > ground_height )
  2707. {
  2708. obj_loc_z -= 0.4f;
  2709. bUpdate = true;
  2710. }
  2711. if ( obj_loc_z < ground_height )
  2712. {
  2713. obj_loc_z = ground_height;
  2714. bUpdate = true;
  2715. }
  2716. if (bUpdate) Obj_UpdateLoc();
  2717. }
  2718. void L_MINES_SendMsg()
  2719. {
  2720. switch (obj_uMsg)
  2721. {
  2722. case MSG_PICKUP:
  2723. {
  2724. int mines = Player_GetAmmo(AMMO_MINE);
  2725. if ( mines < 30 )
  2726. {
  2727. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2728. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  2729. mines += 5;
  2730. if ( mines > 30 ) mines = 30;
  2731. Player_SetAmmo( AMMO_MINE, mines );
  2732. Player_AddItem("MINES");
  2733. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  2734. Obj_Delete();
  2735. Sound_Play2D("KEY.VOC");
  2736. System_PrintIndex(208);
  2737. //Map_RemoveLight( Obj_GetLocalVar(0) );
  2738. }
  2739. }
  2740. break;
  2741. }
  2742. }
  2743. //
  2744. // LAND_MINE
  2745. //
  2746. void L_LAND_MINE_SetupLogic()
  2747. {
  2748. Logic_AddMsgMask(MSG_PROXIMITY);
  2749. Logic_AddMsgMask(MSG_NRML_DAMAGE);
  2750. }
  2751. void L_LAND_MINE_SetupObj()
  2752. {
  2753. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2754. Obj_SetFlag(OFLAGS_COLLIDE_PROXIMITY);
  2755. //set a 1 second delay before the land mine can fire off.
  2756. Obj_SetLocalVar(0, 60.0f);
  2757. //int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  2758. //Obj_SetLocalVar(0, light);
  2759. //Obj_AttachLight(light);
  2760. }
  2761. void L_LAND_MINE_Update()
  2762. {
  2763. float ground_height = Map_GetFloorHeight(0, -1);
  2764. //force gravity if this isn't a flying/floating unit.
  2765. bool bUpdate = false;
  2766. if ( obj_loc_z > ground_height )
  2767. {
  2768. obj_loc_z -= 0.4f;
  2769. bUpdate = true;
  2770. }
  2771. if ( obj_loc_z < ground_height )
  2772. {
  2773. obj_loc_z = ground_height;
  2774. bUpdate = true;
  2775. }
  2776. if (bUpdate) Obj_UpdateLoc();
  2777. float delay = Obj_GetLocalVar(0);
  2778. if ( delay > 0.0f )
  2779. {
  2780. delay -= 1.0f;
  2781. }
  2782. else
  2783. {
  2784. delay = 0.0f;
  2785. }
  2786. Obj_SetLocalVar(0, delay);
  2787. }
  2788. void L_LAND_MINE_SendMsg()
  2789. {
  2790. if ( Obj_IsFlagSet(OFLAGS_COLLIDE_PROXIMITY) != 0 && Obj_GetLocalVar(0) == 0.0f )
  2791. {
  2792. switch (obj_uMsg)
  2793. {
  2794. case MSG_PROXIMITY:
  2795. {
  2796. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  2797. Map_AddExplosion(obj_loc_x, obj_loc_y, Map_GetFloorHeight(0, -1), 40.0f, 60.0f, 1.0f, 1.0f, "MINEEXP.WAX", "EX-SMALL.VOC", true, -1);
  2798. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2799. Obj_ClearFlag(OFLAGS_COLLIDE_PROXIMITY);
  2800. //play the trigger sound.
  2801. Sound_Play2D("BEEP-10.VOC");
  2802. }
  2803. break;
  2804. case MSG_NRML_DAMAGE:
  2805. {
  2806. if ( msg_nVal >= 40 )
  2807. {
  2808. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  2809. Map_AddExplosion(obj_loc_x, obj_loc_y, Map_GetFloorHeight(0, -1), 40.0f, 60.0f, 1.0f, 1.0f, "MINEEXP.WAX", "EX-SMALL.VOC", true, -1);
  2810. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2811. Obj_ClearFlag(OFLAGS_COLLIDE_PROXIMITY);
  2812. //play the trigger sound.
  2813. Sound_Play2D("BEEP-10.VOC");
  2814. }
  2815. }
  2816. break;
  2817. }
  2818. }
  2819. }
  2820. //
  2821. // LAND_MINE_PROX
  2822. //
  2823. void L_LAND_MINE_PROX_SetupLogic()
  2824. {
  2825. Logic_AddMsgMask(MSG_PROXIMITY);
  2826. Logic_AddMsgMask(MSG_NRML_DAMAGE);
  2827. }
  2828. void L_LAND_MINE_PROX_SetupObj()
  2829. {
  2830. Obj_SetFlag(OFLAGS_COLLIDE_OBJECTS);
  2831. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2832. Obj_SetFlag(OFLAGS_COLLIDE_PROXIMITY);
  2833. //set a 1 second delay before the land mine can fire off.
  2834. Obj_SetLocalVar(0, 60.0f);
  2835. //int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  2836. //Obj_SetLocalVar(0, light);
  2837. //Obj_AttachLight(light);
  2838. }
  2839. void L_LAND_MINE_PROX_Update()
  2840. {
  2841. float ground_height = Map_GetFloorHeight(0, -1);
  2842. //force gravity if this isn't a flying/floating unit.
  2843. bool bUpdate = false;
  2844. if ( obj_loc_z > ground_height )
  2845. {
  2846. obj_loc_z -= 0.4f;
  2847. bUpdate = true;
  2848. }
  2849. if ( obj_loc_z < ground_height )
  2850. {
  2851. obj_loc_z = ground_height;
  2852. bUpdate = true;
  2853. }
  2854. if (bUpdate) Obj_UpdateLoc();
  2855. float delay = Obj_GetLocalVar(0);
  2856. if ( delay > 0.0f )
  2857. {
  2858. delay -= 1.0f;
  2859. }
  2860. else
  2861. {
  2862. delay = 0.0f;
  2863. }
  2864. Obj_SetLocalVar(0, delay);
  2865. }
  2866. void L_LAND_MINE_PROX_SendMsg()
  2867. {
  2868. if ( Obj_IsFlagSet(OFLAGS_COLLIDE_PROXIMITY) != 0 && Obj_GetLocalVar(0) <= 0.0f )
  2869. {
  2870. switch (obj_uMsg)
  2871. {
  2872. case MSG_PROXIMITY:
  2873. {
  2874. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  2875. Map_AddExplosion(obj_loc_x, obj_loc_y, Map_GetFloorHeight(0, -1), 40.0f, 60.0f, 1.0f, 1.0f, "MINEEXP.WAX", "EX-SMALL.VOC", true, -1);
  2876. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2877. Obj_ClearFlag(OFLAGS_COLLIDE_PROXIMITY);
  2878. //play the trigger sound.
  2879. Sound_Play2D("BEEP-10.VOC");
  2880. }
  2881. break;
  2882. case MSG_NRML_DAMAGE:
  2883. {
  2884. if ( msg_nVal >= 40 )
  2885. {
  2886. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  2887. Map_AddExplosion(obj_loc_x, obj_loc_y, Map_GetFloorHeight(0, -1), 40.0f, 60.0f, 1.0f, 1.0f, "MINEEXP.WAX", "EX-SMALL.VOC", true, -1);
  2888. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2889. Obj_ClearFlag(OFLAGS_COLLIDE_PROXIMITY);
  2890. //play the trigger sound.
  2891. Sound_Play2D("BEEP-10.VOC");
  2892. }
  2893. }
  2894. break;
  2895. }
  2896. }
  2897. }
  2898. //
  2899. // LAND_MINE_AUTO
  2900. //
  2901. void L_LAND_MINE_AUTO_SetupLogic()
  2902. {
  2903. }
  2904. void L_LAND_MINE_AUTO_SetupObj()
  2905. {
  2906. //set a 3 second delay before the automatically exploding.
  2907. Obj_SetLocalVar(0, 180.0f);
  2908. }
  2909. void L_LAND_MINE_AUTO_Update()
  2910. {
  2911. float ground_height = Map_GetFloorHeight(0, -1);
  2912. //force gravity if this isn't a flying/floating unit.
  2913. bool bUpdate = false;
  2914. if ( obj_loc_z > ground_height )
  2915. {
  2916. obj_loc_z -= 0.4f;
  2917. bUpdate = true;
  2918. }
  2919. if ( obj_loc_z < ground_height )
  2920. {
  2921. obj_loc_z = ground_height;
  2922. bUpdate = true;
  2923. }
  2924. if (bUpdate) Obj_UpdateLoc();
  2925. float delay = Obj_GetLocalVar(0);
  2926. if ( delay > 0.0f )
  2927. {
  2928. delay -= 1.0f;
  2929. Obj_SetLocalVar(0, delay);
  2930. }
  2931. else
  2932. {
  2933. //EXPLODE!
  2934. //x, y, z, radius, damage, delay, scale, graphic (sprite), sound
  2935. Map_AddExplosion(obj_loc_x, obj_loc_y, Map_GetFloorHeight(0, -1), 40.0f, 60.0f, 0.0f, 1.0f, "MINEEXP.WAX", "EX-SMALL.VOC", false, -1);
  2936. Obj_Delete();
  2937. }
  2938. }
  2939. //
  2940. // MISSILE
  2941. //
  2942. void L_MISSILE_SetupLogic()
  2943. {
  2944. Logic_AddMsgMask(MSG_PICKUP);
  2945. }
  2946. void L_MISSILE_SetupObj()
  2947. {
  2948. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  2949. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  2950. int light = Map_AddLight(0, 0, 0, 5, 128, 0, 0);
  2951. Obj_SetLocalVar(0, light);
  2952. Obj_AttachLight(light);
  2953. }
  2954. void L_MISSILE_Update()
  2955. {
  2956. float ground_height = Map_GetFloorHeight(0, -1);
  2957. //force gravity if this isn't a flying/floating unit.
  2958. bool bUpdate = false;
  2959. if ( obj_loc_z > ground_height )
  2960. {
  2961. obj_loc_z -= 0.4f;
  2962. bUpdate = true;
  2963. }
  2964. if ( obj_loc_z < ground_height )
  2965. {
  2966. obj_loc_z = ground_height;
  2967. bUpdate = true;
  2968. }
  2969. if (bUpdate) Obj_UpdateLoc();
  2970. }
  2971. void L_MISSILE_SendMsg()
  2972. {
  2973. switch (obj_uMsg)
  2974. {
  2975. case MSG_PICKUP:
  2976. {
  2977. int missles = Player_GetAmmo(AMMO_MISSLE);
  2978. if ( missles < 20 )
  2979. {
  2980. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  2981. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  2982. missles += 1;
  2983. if ( missles > 20 ) missles = 20;
  2984. Player_SetAmmo( AMMO_MISSLE, missles );
  2985. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  2986. Obj_Delete();
  2987. Sound_Play2D("KEY.VOC");
  2988. System_PrintIndex(209);
  2989. Map_RemoveLight( Obj_GetLocalVar(0) );
  2990. }
  2991. }
  2992. break;
  2993. }
  2994. }
  2995. //
  2996. // MISSILES
  2997. //
  2998. void L_MISSILES_SetupLogic()
  2999. {
  3000. Logic_AddMsgMask(MSG_PICKUP);
  3001. }
  3002. void L_MISSILES_SetupObj()
  3003. {
  3004. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3005. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3006. int light = Map_AddLight(0, 0, 0, 15, 128, 0, 0);
  3007. Obj_SetLocalVar(0, light);
  3008. Obj_AttachLight(light);
  3009. }
  3010. void L_MISSILES_Update()
  3011. {
  3012. float ground_height = Map_GetFloorHeight(0, -1);
  3013. //force gravity if this isn't a flying/floating unit.
  3014. bool bUpdate = false;
  3015. if ( obj_loc_z > ground_height )
  3016. {
  3017. obj_loc_z -= 0.4f;
  3018. bUpdate = true;
  3019. }
  3020. if ( obj_loc_z < ground_height )
  3021. {
  3022. obj_loc_z = ground_height;
  3023. bUpdate = true;
  3024. }
  3025. if (bUpdate) Obj_UpdateLoc();
  3026. }
  3027. void L_MISSILES_SendMsg()
  3028. {
  3029. switch (obj_uMsg)
  3030. {
  3031. case MSG_PICKUP:
  3032. {
  3033. int missles = Player_GetAmmo(AMMO_MISSLE);
  3034. if ( missles < 20 )
  3035. {
  3036. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3037. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3038. missles += 5;
  3039. if ( missles > 20 ) missles = 20;
  3040. Player_SetAmmo( AMMO_MISSLE, missles );
  3041. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  3042. Obj_Delete();
  3043. Sound_Play2D("KEY.VOC");
  3044. System_PrintIndex(210);
  3045. Map_RemoveLight( Obj_GetLocalVar(0) );
  3046. }
  3047. }
  3048. break;
  3049. }
  3050. }
  3051. //
  3052. // PLASMA
  3053. //
  3054. void L_PLASMA_SetupLogic()
  3055. {
  3056. Logic_AddMsgMask(MSG_PICKUP);
  3057. }
  3058. void L_PLASMA_SetupObj()
  3059. {
  3060. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3061. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3062. int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  3063. Obj_SetLocalVar(0, light);
  3064. Obj_AttachLight(light);
  3065. }
  3066. void L_PLASMA_Update()
  3067. {
  3068. float ground_height = Map_GetFloorHeight(0, -1);
  3069. //force gravity if this isn't a flying/floating unit.
  3070. bool bUpdate = false;
  3071. if ( obj_loc_z > ground_height )
  3072. {
  3073. obj_loc_z -= 0.4f;
  3074. bUpdate = true;
  3075. }
  3076. if ( obj_loc_z < ground_height )
  3077. {
  3078. obj_loc_z = ground_height;
  3079. bUpdate = true;
  3080. }
  3081. if (bUpdate) Obj_UpdateLoc();
  3082. }
  3083. void L_PLASMA_SendMsg()
  3084. {
  3085. switch (obj_uMsg)
  3086. {
  3087. case MSG_PICKUP:
  3088. {
  3089. int plasma = Player_GetAmmo(AMMO_PLASMA);
  3090. if ( plasma < 400 )
  3091. {
  3092. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3093. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3094. plasma += 20;
  3095. if ( plasma > 400 ) plasma = 400;
  3096. Player_SetAmmo( AMMO_PLASMA, plasma );
  3097. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  3098. Obj_Delete();
  3099. Sound_Play2D("KEY.VOC");
  3100. System_PrintIndex(202);
  3101. Map_RemoveLight( Obj_GetLocalVar(0) );
  3102. }
  3103. }
  3104. break;
  3105. }
  3106. }
  3107. //
  3108. // ITEMENERGY
  3109. //
  3110. void L_ITEMENERGY_SetupLogic()
  3111. {
  3112. Logic_AddMsgMask(MSG_PICKUP);
  3113. }
  3114. void L_ITEMENERGY_SetupObj()
  3115. {
  3116. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3117. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3118. int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  3119. Obj_SetLocalVar(0, light);
  3120. Obj_AttachLight(light);
  3121. }
  3122. void L_ITEMENERGY_Update()
  3123. {
  3124. float ground_height = Map_GetFloorHeight(0, -1);
  3125. //force gravity if this isn't a flying/floating unit.
  3126. bool bUpdate = false;
  3127. if ( obj_loc_z > ground_height )
  3128. {
  3129. obj_loc_z -= 0.4f;
  3130. bUpdate = true;
  3131. }
  3132. if ( obj_loc_z < ground_height )
  3133. {
  3134. obj_loc_z = ground_height;
  3135. bUpdate = true;
  3136. }
  3137. if (bUpdate) Obj_UpdateLoc();
  3138. }
  3139. void L_ITEMENERGY_SendMsg()
  3140. {
  3141. switch (obj_uMsg)
  3142. {
  3143. case MSG_PICKUP:
  3144. {
  3145. int energy = Player_GetAmmo(AMMO_ENERGY);
  3146. if ( energy < 500 )
  3147. {
  3148. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3149. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3150. //now add shields...
  3151. energy += 15;
  3152. if ( energy > 500 ) energy = 500;
  3153. Player_SetAmmo( AMMO_ENERGY, energy );
  3154. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  3155. Obj_Delete();
  3156. Sound_Play2D("KEY.VOC");
  3157. System_PrintIndex(200);
  3158. Map_RemoveLight( Obj_GetLocalVar(0) );
  3159. }
  3160. }
  3161. break;
  3162. }
  3163. }
  3164. //
  3165. // ENERGY
  3166. //
  3167. void L_ENERGY_SetupLogic()
  3168. {
  3169. Logic_AddMsgMask(MSG_PICKUP);
  3170. }
  3171. void L_ENERGY_SetupObj()
  3172. {
  3173. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3174. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3175. int light = Map_AddLight(0, 0, 0, 5, 0, 0, 128);
  3176. Obj_SetLocalVar(0, light);
  3177. Obj_AttachLight(light);
  3178. }
  3179. void L_ENERGY_Update()
  3180. {
  3181. float ground_height = Map_GetFloorHeight(0, -1);
  3182. //force gravity if this isn't a flying/floating unit.
  3183. bool bUpdate = false;
  3184. if ( obj_loc_z > ground_height )
  3185. {
  3186. obj_loc_z -= 0.4f;
  3187. bUpdate = true;
  3188. }
  3189. if ( obj_loc_z < ground_height )
  3190. {
  3191. obj_loc_z = ground_height;
  3192. bUpdate = true;
  3193. }
  3194. if (bUpdate) Obj_UpdateLoc();
  3195. }
  3196. void L_ENERGY_SendMsg()
  3197. {
  3198. L_ITEMENERGY_SendMsg();
  3199. }
  3200. //
  3201. // DETONATOR
  3202. //
  3203. void L_DETONATOR_SetupLogic()
  3204. {
  3205. Logic_AddMsgMask(MSG_PICKUP);
  3206. }
  3207. void L_DETONATOR_SetupObj()
  3208. {
  3209. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3210. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3211. }
  3212. void L_DETONATOR_Update()
  3213. {
  3214. float ground_height = Map_GetFloorHeight(0, -1);
  3215. //force gravity if this isn't a flying/floating unit.
  3216. bool bUpdate = false;
  3217. if ( obj_loc_z > ground_height )
  3218. {
  3219. obj_loc_z -= 0.4f;
  3220. bUpdate = true;
  3221. }
  3222. if ( obj_loc_z < ground_height )
  3223. {
  3224. obj_loc_z = ground_height;
  3225. bUpdate = true;
  3226. }
  3227. if (bUpdate) Obj_UpdateLoc();
  3228. }
  3229. void L_DETONATOR_SendMsg()
  3230. {
  3231. switch (obj_uMsg)
  3232. {
  3233. case MSG_PICKUP:
  3234. {
  3235. int det = Player_GetAmmo(AMMO_DETONATOR);
  3236. if ( det < 50 )
  3237. {
  3238. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3239. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3240. //now add shields...
  3241. det += 3;
  3242. if ( det > 50 ) det = 50;
  3243. Player_SetAmmo( AMMO_DETONATOR, det );
  3244. Player_AddItem("DETONATOR");
  3245. Obj_Delete();
  3246. Sound_Play2D("KEY.VOC");
  3247. System_PrintIndex(102);
  3248. }
  3249. }
  3250. break;
  3251. }
  3252. }
  3253. //
  3254. // DETONATORS
  3255. //
  3256. void L_DETONATORS_SetupLogic()
  3257. {
  3258. Logic_AddMsgMask(MSG_PICKUP);
  3259. }
  3260. void L_DETONATORS_SetupObj()
  3261. {
  3262. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3263. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3264. }
  3265. void L_DETONATORS_Update()
  3266. {
  3267. float ground_height = Map_GetFloorHeight(0, -1);
  3268. //force gravity if this isn't a flying/floating unit.
  3269. bool bUpdate = false;
  3270. if ( obj_loc_z > ground_height )
  3271. {
  3272. obj_loc_z -= 0.4f;
  3273. bUpdate = true;
  3274. }
  3275. if ( obj_loc_z < ground_height )
  3276. {
  3277. obj_loc_z = ground_height;
  3278. bUpdate = true;
  3279. }
  3280. if (bUpdate) Obj_UpdateLoc();
  3281. }
  3282. void L_DETONATORS_SendMsg()
  3283. {
  3284. switch (obj_uMsg)
  3285. {
  3286. case MSG_PICKUP:
  3287. {
  3288. int det = Player_GetAmmo(AMMO_DETONATOR);
  3289. if ( det < 50 )
  3290. {
  3291. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3292. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3293. //now add shields...
  3294. det += 5;
  3295. if ( det > 50 ) det = 50;
  3296. Player_SetAmmo( AMMO_DETONATOR, det );
  3297. Player_AddItem("DETONATOR");
  3298. Obj_Delete();
  3299. Sound_Play2D("KEY.VOC");
  3300. System_PrintIndex(204);
  3301. }
  3302. }
  3303. break;
  3304. }
  3305. }
  3306. //
  3307. // LIFE
  3308. //
  3309. void L_LIFE_SetupLogic()
  3310. {
  3311. Logic_AddMsgMask(MSG_PICKUP);
  3312. }
  3313. void L_LIFE_SetupObj()
  3314. {
  3315. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3316. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3317. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 20, 20);
  3318. Obj_SetLocalVar(0, light);
  3319. Obj_AttachLight(light);
  3320. }
  3321. void L_LIFE_SendMsg()
  3322. {
  3323. switch (obj_uMsg)
  3324. {
  3325. case MSG_PICKUP:
  3326. {
  3327. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3328. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3329. Player_AddLife();
  3330. Player_QueueFlash( PLAYER_FLASH_BLUE, 0.1f );
  3331. Obj_Delete();
  3332. Sound_Play2D("BONUS.VOC");
  3333. System_PrintIndex(310);
  3334. Map_RemoveLight( Obj_GetLocalVar(0) );
  3335. }
  3336. break;
  3337. }
  3338. }
  3339. //
  3340. // Logic RED
  3341. //
  3342. void L_RED_SetupLogic()
  3343. {
  3344. Logic_AddMsgMask(MSG_PICKUP);
  3345. }
  3346. void L_RED_SetupObj()
  3347. {
  3348. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3349. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3350. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 0);
  3351. Obj_SetLocalVar(0, light);
  3352. Obj_AttachLight(light);
  3353. }
  3354. void L_RED_SendMsg()
  3355. {
  3356. switch (obj_uMsg)
  3357. {
  3358. case MSG_PICKUP:
  3359. {
  3360. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3361. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3362. Player_AddItem("REDKEY");
  3363. Obj_Delete();
  3364. Map_RemoveLight( Obj_GetLocalVar(0) );
  3365. Sound_Play2D("BONUS.VOC");
  3366. System_PrintIndex(300);
  3367. }
  3368. break;
  3369. }
  3370. }
  3371. //
  3372. // Logic ITEMRED
  3373. //
  3374. void L_ITEMRED_SetupLogic()
  3375. {
  3376. Logic_AddMsgMask(MSG_PICKUP);
  3377. }
  3378. void L_ITEMRED_SetupObj()
  3379. {
  3380. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3381. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3382. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 0);
  3383. Obj_SetLocalVar(0, light);
  3384. Obj_AttachLight(light);
  3385. }
  3386. void L_ITEMRED_SendMsg()
  3387. {
  3388. switch (obj_uMsg)
  3389. {
  3390. case MSG_PICKUP:
  3391. {
  3392. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3393. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3394. Player_AddItem("REDKEY");
  3395. Obj_Delete();
  3396. Map_RemoveLight( Obj_GetLocalVar(0) );
  3397. Sound_Play2D("BONUS.VOC");
  3398. System_PrintIndex(300);
  3399. }
  3400. break;
  3401. }
  3402. }
  3403. //
  3404. // Logic BLUE
  3405. //
  3406. void L_BLUE_SetupLogic()
  3407. {
  3408. Logic_AddMsgMask(MSG_PICKUP);
  3409. }
  3410. void L_BLUE_SetupObj()
  3411. {
  3412. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3413. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3414. int light = Map_AddLight(0, 0, 1.0f, 10, 0, 0, 255);
  3415. Obj_SetLocalVar(0, light);
  3416. Obj_AttachLight(light);
  3417. }
  3418. void L_BLUE_SendMsg()
  3419. {
  3420. switch (obj_uMsg)
  3421. {
  3422. case MSG_PICKUP:
  3423. {
  3424. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3425. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3426. Player_AddItem("BLUEKEY");
  3427. Obj_Delete();
  3428. Map_RemoveLight( Obj_GetLocalVar(0) );
  3429. Sound_Play2D("BONUS.VOC");
  3430. System_PrintIndex(302);
  3431. }
  3432. break;
  3433. }
  3434. }
  3435. //
  3436. // Logic ITEMBLUE
  3437. //
  3438. void L_ITEMBLUE_SetupLogic()
  3439. {
  3440. Logic_AddMsgMask(MSG_PICKUP);
  3441. }
  3442. void L_ITEMBLUE_SetupObj()
  3443. {
  3444. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3445. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3446. int light = Map_AddLight(0, 0, 1.0f, 10, 0, 0, 255);
  3447. Obj_SetLocalVar(0, light);
  3448. Obj_AttachLight(light);
  3449. }
  3450. void L_ITEMBLUE_SendMsg()
  3451. {
  3452. switch (obj_uMsg)
  3453. {
  3454. case MSG_PICKUP:
  3455. {
  3456. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3457. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3458. Player_AddItem("BLUEKEY");
  3459. Obj_Delete();
  3460. Map_RemoveLight( Obj_GetLocalVar(0) );
  3461. Sound_Play2D("BONUS.VOC");
  3462. System_PrintIndex(302);
  3463. }
  3464. break;
  3465. }
  3466. }
  3467. //
  3468. // Logic YELLOW
  3469. //
  3470. void L_YELLOW_SetupLogic()
  3471. {
  3472. Logic_AddMsgMask(MSG_PICKUP);
  3473. }
  3474. void L_YELLOW_SetupObj()
  3475. {
  3476. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3477. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3478. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 255, 0);
  3479. Obj_SetLocalVar(0, light);
  3480. Obj_AttachLight(light);
  3481. }
  3482. void L_YELLOW_SendMsg()
  3483. {
  3484. switch (obj_uMsg)
  3485. {
  3486. case MSG_PICKUP:
  3487. {
  3488. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3489. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3490. Player_AddItem("YELLOWKEY");
  3491. Obj_Delete();
  3492. Map_RemoveLight( Obj_GetLocalVar(0) );
  3493. Sound_Play2D("BONUS.VOC");
  3494. System_PrintIndex(301);
  3495. }
  3496. break;
  3497. }
  3498. }
  3499. //
  3500. // Logic CODE1
  3501. //
  3502. void L_CODE1_SetupObj()
  3503. {
  3504. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3505. Obj_SetLocalVar(0, light);
  3506. Obj_AttachLight(light);
  3507. }
  3508. void L_CODE1_Update()
  3509. {
  3510. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3511. {
  3512. Player_AddItem("CODE1");
  3513. Obj_Delete();
  3514. Map_RemoveLight( Obj_GetLocalVar(0) );
  3515. Sound_Play2D("BONUS.VOC");
  3516. System_PrintIndex(501);
  3517. }
  3518. }
  3519. //
  3520. // Logic CODE2
  3521. //
  3522. void L_CODE2_SetupObj()
  3523. {
  3524. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3525. Obj_SetLocalVar(0, light);
  3526. Obj_AttachLight(light);
  3527. }
  3528. void L_CODE2_Update()
  3529. {
  3530. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3531. {
  3532. Player_AddItem("CODE2");
  3533. Obj_Delete();
  3534. Map_RemoveLight( Obj_GetLocalVar(0) );
  3535. Sound_Play2D("BONUS.VOC");
  3536. System_PrintIndex(502);
  3537. }
  3538. }
  3539. //
  3540. // Logic CODE3
  3541. //
  3542. void L_CODE3_SetupObj()
  3543. {
  3544. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3545. Obj_SetLocalVar(0, light);
  3546. Obj_AttachLight(light);
  3547. }
  3548. void L_CODE3_Update()
  3549. {
  3550. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3551. {
  3552. Player_AddItem("CODE3");
  3553. Obj_Delete();
  3554. Map_RemoveLight( Obj_GetLocalVar(0) );
  3555. Sound_Play2D("BONUS.VOC");
  3556. System_PrintIndex(503);
  3557. }
  3558. }
  3559. //
  3560. // Logic CODE4
  3561. //
  3562. void L_CODE4_SetupObj()
  3563. {
  3564. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3565. Obj_SetLocalVar(0, light);
  3566. Obj_AttachLight(light);
  3567. }
  3568. void L_CODE4_Update()
  3569. {
  3570. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3571. {
  3572. Player_AddItem("CODE4");
  3573. Obj_Delete();
  3574. Map_RemoveLight( Obj_GetLocalVar(0) );
  3575. Sound_Play2D("BONUS.VOC");
  3576. System_PrintIndex(504);
  3577. }
  3578. }
  3579. //
  3580. // Logic CODE5
  3581. //
  3582. void L_CODE5_SetupObj()
  3583. {
  3584. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3585. Obj_SetLocalVar(0, light);
  3586. Obj_AttachLight(light);
  3587. }
  3588. void L_CODE5_Update()
  3589. {
  3590. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3591. {
  3592. Player_AddItem("CODE5");
  3593. Obj_Delete();
  3594. Map_RemoveLight( Obj_GetLocalVar(0) );
  3595. Sound_Play2D("BONUS.VOC");
  3596. System_PrintIndex(505);
  3597. }
  3598. }
  3599. //
  3600. // Logic CODE6
  3601. //
  3602. void L_CODE6_SetupObj()
  3603. {
  3604. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3605. Obj_SetLocalVar(0, light);
  3606. Obj_AttachLight(light);
  3607. }
  3608. void L_CODE6_Update()
  3609. {
  3610. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3611. {
  3612. Player_AddItem("CODE6");
  3613. Obj_Delete();
  3614. Map_RemoveLight( Obj_GetLocalVar(0) );
  3615. Sound_Play2D("BONUS.VOC");
  3616. System_PrintIndex(506);
  3617. }
  3618. }
  3619. //
  3620. // Logic CODE7
  3621. //
  3622. void L_CODE7_SetupObj()
  3623. {
  3624. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3625. Obj_SetLocalVar(0, light);
  3626. Obj_AttachLight(light);
  3627. }
  3628. void L_CODE7_Update()
  3629. {
  3630. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3631. {
  3632. Player_AddItem("CODE7");
  3633. Obj_Delete();
  3634. Map_RemoveLight( Obj_GetLocalVar(0) );
  3635. Sound_Play2D("BONUS.VOC");
  3636. System_PrintIndex(507);
  3637. }
  3638. }
  3639. //
  3640. // Logic CODE8
  3641. //
  3642. void L_CODE8_SetupObj()
  3643. {
  3644. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3645. Obj_SetLocalVar(0, light);
  3646. Obj_AttachLight(light);
  3647. }
  3648. void L_CODE8_Update()
  3649. {
  3650. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3651. {
  3652. Player_AddItem("CODE8");
  3653. Obj_Delete();
  3654. Map_RemoveLight( Obj_GetLocalVar(0) );
  3655. Sound_Play2D("BONUS.VOC");
  3656. System_PrintIndex(508);
  3657. }
  3658. }
  3659. //
  3660. // Logic CODE9
  3661. //
  3662. void L_CODE9_SetupObj()
  3663. {
  3664. int light = Map_AddLight(0, 0, 1.0f, 10, 255, 0, 255);
  3665. Obj_SetLocalVar(0, light);
  3666. Obj_AttachLight(light);
  3667. }
  3668. void L_CODE9_Update()
  3669. {
  3670. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3671. {
  3672. Player_AddItem("CODE9");
  3673. Obj_Delete();
  3674. Map_RemoveLight( Obj_GetLocalVar(0) );
  3675. Sound_Play2D("BONUS.VOC");
  3676. System_PrintIndex(509);
  3677. }
  3678. }
  3679. //
  3680. // Logic PLANS
  3681. //
  3682. void L_PLANS_SetupObj()
  3683. {
  3684. int light = Map_AddLight(0, 0, 0, 10, 255, 64, 0);
  3685. Obj_SetLocalVar(0, light);
  3686. Obj_AttachLight(light);
  3687. }
  3688. void L_PLANS_Update()
  3689. {
  3690. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 7.0f )
  3691. {
  3692. Player_AddItem("PLANS");
  3693. System_GoalItem(0);
  3694. Obj_Delete();
  3695. Map_RemoveLight( Obj_GetLocalVar(0) );
  3696. Sound_Play2D("BONUS.VOC");
  3697. System_PrintIndex(400);
  3698. }
  3699. }
  3700. //
  3701. // PHRIK
  3702. //
  3703. void L_PHRIK_SetupObj()
  3704. {
  3705. int light = Map_AddLight(0, 0, 0, 10, 255, 64, 0);
  3706. Obj_SetLocalVar(0, light);
  3707. Obj_AttachLight(light);
  3708. }
  3709. void L_PHRIK_Update()
  3710. {
  3711. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 7.0f )
  3712. {
  3713. Player_AddItem("PHRIK");
  3714. System_GoalItem(0);
  3715. Obj_Delete();
  3716. Map_RemoveLight( Obj_GetLocalVar(0) );
  3717. Sound_Play2D("BONUS.VOC");
  3718. System_PrintIndex(401);
  3719. }
  3720. }
  3721. //
  3722. // DT_WEAPON
  3723. //
  3724. void L_DT_WEAPON_SetupLogic()
  3725. {
  3726. Logic_AddMsgMask(MSG_PICKUP);
  3727. }
  3728. void L_DT_WEAPON_SetupObj()
  3729. {
  3730. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3731. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3732. }
  3733. void L_DT_WEAPON_SendMsg()
  3734. {
  3735. switch (obj_uMsg)
  3736. {
  3737. case MSG_PICKUP:
  3738. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3739. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3740. Player_AddItem("DT_WEAPON");
  3741. System_GoalItem(0);
  3742. Obj_Delete();
  3743. Sound_Play2D("BONUS.VOC");
  3744. System_PrintIndex(405);
  3745. break;
  3746. }
  3747. }
  3748. //
  3749. // NAVA
  3750. //
  3751. void L_NAVA_SetupObj()
  3752. {
  3753. int light = Map_AddLight(0, 0, 0, 10, 64, 64, 255);
  3754. Obj_SetLocalVar(0, light);
  3755. Obj_AttachLight(light);
  3756. }
  3757. void L_NAVA_Update()
  3758. {
  3759. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 7.0f )
  3760. {
  3761. Player_AddItem("NAVA_CARD");
  3762. System_GoalItem(0);
  3763. Map_RemoveLight( Obj_GetLocalVar(0) );
  3764. Obj_Delete();
  3765. Sound_Play2D("BONUS.VOC");
  3766. System_PrintIndex(402);
  3767. }
  3768. }
  3769. //
  3770. // PILE
  3771. //
  3772. void L_PILE_Update()
  3773. {
  3774. if ( Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 7.0f )
  3775. {
  3776. Player_AddItem("PILE");
  3777. System_GoalItem(0);
  3778. Map_RemoveLight( Obj_GetLocalVar(0) );
  3779. Obj_Delete();
  3780. Sound_Play2D("BONUS.VOC");
  3781. System_PrintIndex(312);
  3782. }
  3783. }
  3784. //
  3785. // DATATAPE
  3786. //
  3787. void L_DATATAPE_SetupLogic()
  3788. {
  3789. Logic_AddMsgMask(MSG_PICKUP);
  3790. }
  3791. void L_DATATAPE_SetupObj()
  3792. {
  3793. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3794. Obj_SetFlag(OFLAGS_COLLIDE_PICKUP);
  3795. obj_Radius = 4.0f;
  3796. obj_Height = 1.0f;
  3797. }
  3798. void L_DATATAPE_Update()
  3799. {
  3800. if ( Obj_IsFlagSet(OFLAGS_COLLIDE_PLAYER) != 0 && Obj_GetSqrDistFromPlayer() < obj_Radius*obj_Radius && Obj_GetHeightDistFromPlayer() < 6.0f )
  3801. {
  3802. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3803. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3804. Player_AddItem("DATATAPE");
  3805. System_GoalItem(1);
  3806. Obj_Delete();
  3807. Sound_Play2D("BONUS.VOC");
  3808. System_PrintIndex(405);
  3809. }
  3810. }
  3811. void L_DATATAPE_SendMsg()
  3812. {
  3813. if ( Obj_IsFlagSet(OFLAGS_COLLIDE_PLAYER) != 0 )
  3814. {
  3815. switch (obj_uMsg)
  3816. {
  3817. case MSG_PICKUP:
  3818. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3819. Obj_ClearFlag(OFLAGS_COLLIDE_PICKUP);
  3820. Player_AddItem("DATATAPE");
  3821. System_GoalItem(1);
  3822. Obj_Delete();
  3823. Sound_Play2D("BONUS.VOC");
  3824. System_PrintIndex(405);
  3825. break;
  3826. }
  3827. }
  3828. }
  3829. /**************MISC************/
  3830. //
  3831. // Logic UPDATE
  3832. //
  3833. void L_UPDATE_Update()
  3834. {
  3835. obj_Yaw += Obj_GetLocalVar(1);
  3836. }
  3837. //
  3838. // SCENERY
  3839. //
  3840. void L_SCENERY_SetupLogic()
  3841. {
  3842. Logic_AddMsgMask(MSG_NRML_DAMAGE);
  3843. Logic_AddMsgMask(MSG_MELEE_DAMAGE);
  3844. }
  3845. void L_SCENERY_SetupObj()
  3846. {
  3847. Obj_SetFlag(OFLAGS_COLLIDE_PLAYER);
  3848. Obj_SetFlag(OFLAGS_COLLIDE_PROJECTILE);
  3849. Obj_SetFlag(OFLAGS_COLLIDE_OBJECTS);
  3850. obj_Action = 0;
  3851. obj_Radius = 2.0f;
  3852. obj_Height = 10.0f;
  3853. int light = -1;
  3854. if ( Obj_CompareName("REDLIT") )
  3855. {
  3856. light = Map_AddLight(0, 0, 0, 20, 255, 0, 0);
  3857. obj_FrameDelay = 5;
  3858. }
  3859. else if ( Obj_CompareName("TALLIT1") )
  3860. {
  3861. light = Map_AddLight(0, 0, 0, 20, 64, 96, 128);
  3862. }
  3863. else if ( Obj_CompareName("LIT1") || Obj_CompareName("LIT2") )
  3864. {
  3865. light = Map_AddLight(0, 0, 0, 20, 64, 96, 128);
  3866. }
  3867. else if ( Obj_CompareName("ICEILIT2") )
  3868. {
  3869. light = Map_AddLight(0, 0, 0, 8, 64, 96, 128);
  3870. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3871. Obj_ClearFlag(OFLAGS_COLLIDE_OBJECTS);
  3872. }
  3873. Obj_SetLocalVar(0, light);
  3874. if ( light > -1 )
  3875. {
  3876. Obj_AttachLight(light);
  3877. }
  3878. }
  3879. void L_SCENERY_SendMsg()
  3880. {
  3881. if ( obj_Action == 1 ) { return; }
  3882. switch (obj_uMsg)
  3883. {
  3884. case MSG_NRML_DAMAGE:
  3885. obj_Action = 1;
  3886. obj_Frame = 0;
  3887. obj_Delay = 15;
  3888. obj_FrameDelay = 15;
  3889. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3890. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  3891. Obj_ClearFlag(OFLAGS_COLLIDE_OBJECTS);
  3892. if ( Obj_GetLocalVar(0) > -1 )
  3893. {
  3894. Map_RemoveLight( Obj_GetLocalVar(0) );
  3895. Obj_SetLocalVar(0, -1);
  3896. }
  3897. break;
  3898. case MSG_MELEE_DAMAGE:
  3899. obj_Action = 1;
  3900. obj_Frame = 0;
  3901. obj_Delay = 15;
  3902. obj_FrameDelay = 15;
  3903. Obj_ClearFlag(OFLAGS_COLLIDE_PLAYER);
  3904. Obj_ClearFlag(OFLAGS_COLLIDE_PROJECTILE);
  3905. Obj_ClearFlag(OFLAGS_COLLIDE_OBJECTS);
  3906. if ( Obj_GetLocalVar(0) > -1 )
  3907. {
  3908. Map_RemoveLight( Obj_GetLocalVar(0) );
  3909. Obj_SetLocalVar(0, -1);
  3910. }
  3911. break;
  3912. }
  3913. }