Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.85 KB | None | 0 0
  1. /*=======================================================//
  2. // field.QC - CustomTF 3.2.OfN - 30/1/2001 - //
  3. // by Sergio Fumaña Grunwaldt - OfteN [cp] //
  4. =========================================================//
  5. Field generator stuff - Written all by myself! :)
  6. I took the model and some sounds from deadlode mod
  7. One sound is from megaTF
  8. =========================================================*/
  9.  
  10. // field generator status flags, DO NOT MODIFY
  11.  
  12. #define FIELDGEN_ISOFF 0 // no field, not linked, and its not trying to link (several possible reasons)
  13. #define FIELDGEN_ISIDLE 1 // no field, not linked, trying to link with other generator
  14. #define FIELDGEN_ISDISABLED 2 // no field, linked, its disabled temporary (teammate passing thru field)
  15. #define FIELDGEN_ISENABLED 3 // field, linked, and cells enough, waiting for shock, only hum sound
  16. #define FIELDGEN_ISWORKING 4 // field, linked, glowing and all the field visual/sound effects are on
  17.  
  18. // field generator settings
  19.  
  20. #define FIELDGEN_WORKTIME 3 // seconds the generators remain "working", glowing and doing lightning after a shock
  21. #define FIELDGEN_WORKING_RATE 1 // interval in seconds for fieldgens to use cells
  22. #define FIELDGEN_LINKTIME 3.5 // seconds between tries to link with other generator (only visual)
  23. #define FIELDGEN_TIMEDISABLED 1.5 // time fieldgens remain disabled
  24. #define FIELDGEN_CELLSCOST 2 // cells cost for each "FIELDGEN_ISWORKING" pass
  25.  
  26. // force field settings
  27.  
  28. #define FIELD_DMG 250//160 //was 80 - normal damag when touching
  29. #define FIELD_DMGINSIDE 500//420 //was 120 - damage when trapped inside field
  30. #define FIELD_SOUNDSRATE 1 // Rate in seconds at which hum/shield sound is played
  31. #define FIELD_VISUALFACTOR 0.5 // 1 = always generate lightning for visuals, when working. 0 = never
  32.  
  33. /*===============================================================================================
  34.  
  35. EXPLANATION OF HOW THE ENTITY FIELDS ARE USED (thnx? np.. :P)
  36. ---------------------------------------------
  37.  
  38. For field generator entity:
  39. ---------------------------
  40.  
  41. .has_holo - Holds current status of every field generator, FIELDGEN_ISXXXX determines
  42. .has_sensor - Boolean value, determines if field generator is currently supporting a force field
  43. .martyr_enemy - This points to the force field, if none its always 'world'
  44. .no_grenades_1 - Controls delay between tries to link (only affects sound/flash, it tries to link every frame)
  45. .no_grenades_2 - Controls delay for field to go up again after beeing disabled
  46. .tp_grenades_1 - Controls delay of the WORKING status
  47. .has_teleporter - Used to flash generators when field is activated
  48. .has_camera - Controls delay between cells take
  49. .has_tesla - Boolean, forced status.
  50.  
  51. For force field entity:
  52. -----------------------
  53.  
  54. .demon_one - Points to the first field generator
  55. .demon_two - Points to the 2nd generator
  56. .has_holo - Hum sound running, boolean
  57. .has_sensor - Shield sound running, boolean
  58. .has_tesla - Controls delay between hums
  59. .has_sentry - Controls delay between shield sounds
  60. .cnt - Orientation of field (x or y)
  61. .dmg - Next damage the field will do
  62. .has_camera - Used to control the rate at which the field touch sound/visual effects are done (4hz)
  63.  
  64. ================================================================================================*/
  65.  
  66. void() CheckDistance;
  67. entity(entity fieldgen) Find_OtherGen;
  68. float(entity fieldgen1, entity fieldgen2) FieldGens_CanLink;
  69. float(entity fieldgen) FieldGen_CanIdle;
  70. float(entity fieldgen) IsValidFieldGen;
  71. float (vector targ, vector check) vis2orig;
  72. float(entity field) IsValidField;
  73. void(entity tfield, entity gen1) Field_UpdateSounds;
  74. void(entity tfield) Field_StopSounds;
  75. void(entity tfield) Field_MakeVisual;
  76. float(entity tfield) FieldIsImproved;
  77. float(entity tfield) FieldIsMalfunctioning;
  78. void() Field_touch;
  79. void() Field_touch_SUB;
  80. float(entity e1, entity e2) EntsTouching2;
  81. void(entity tfield, vector where, entity thing) FieldExplosion;
  82. void(entity field) PutFieldWork;
  83. float(entity tfield, entity who) Field_ItCanPass;
  84. float(entity tfield, entity who) Field_ShouldDamage;
  85.  
  86. #ifdef FIELD_FORCEMODE
  87. entity(entity myself) GetMyFieldGen;
  88. float(entity tfield) Field_GetForcedStatus;
  89. void(float value) SetFieldForcedStatus; // player function (self = player) cuts disabled time also
  90. float() GetFieldForcedStatus; // player
  91. #endif
  92.  
  93. //=========================================================================================
  94. // field generator model and sounds
  95.  
  96. void() Field_Precache =
  97. {
  98. precache_sound ("misc/null.wav");
  99. precache_sound2("misc/ffhum.wav");
  100. precache_sound2("misc/ffbeep.wav");
  101. precache_sound2("misc/ffield.wav");
  102. precache_sound2("misc/ffact.wav");
  103. precache_sound2("misc/fffail.wav");
  104. precache_model2("progs/ffgen2.mdl");
  105. };
  106.  
  107. //==================================================================================================
  108. // checks for field generators and removes itself if needed, checks for stuck entities inside field
  109.  
  110. void() Field_think =
  111. {
  112.  
  113. /* NOT NEEDED - if (self.classname != "force_field")
  114. {
  115. RPrint("BUG: Not a force field entity was in 'FieldThink()'!\n");
  116. return;
  117. }*/
  118.  
  119. self.has_camera = #FALSE; // resets flag for visuals
  120.  
  121. // check field generators, removal of this field if needed... (for safety only)
  122. if (!IsValidFieldGen(self.demon_one) || !IsValidFieldGen(self.demon_two))
  123. {
  124. #ifdef OMC_DEBUG
  125. // this doesnt get printed
  126. dprint("In Field_think one of the FGs arent working\n" );
  127.  
  128. #endif
  129. if (IsValidFieldGen(self.demon_one))
  130. {
  131. self.demon_one.has_sensor = #FALSE;
  132. self.demon_one.martyr_enemy = world;
  133. }
  134.  
  135. if (IsValidFieldGen(self.demon_two))
  136. {
  137. self.demon_two.has_sensor = #FALSE;
  138. self.demon_two.martyr_enemy = world;
  139. }
  140.  
  141. self.demon_one = world;
  142. self.demon_two = world;
  143.  
  144. dremove(self);
  145.  
  146. // report this, as it shouldnt happen
  147. RPrint("Debug: Field entity removed in Field_think()\n");
  148. return;
  149. }
  150. else
  151. self.nextthink = time + 0.25; // 4hz rate
  152.  
  153. // Make visuals if needed
  154. if (self.demon_one.has_holo == #FIELDGEN_ISWORKING)
  155. Field_MakeVisual(self);
  156.  
  157. // checks for anything stuck in field :)
  158. local entity te;
  159. local float frange;
  160.  
  161. frange = #FIELDGEN_RANGE;
  162.  
  163. if (FieldIsImproved(self) & #IMPROVED_FOUR)
  164. {
  165. #ifdef OMC_DEBUG
  166. dprint("In Field_think (self) & IMPROVED_FOUR\n" );
  167.  
  168. #endif
  169. frange = #FIELDGEN_HACKEDRANGE; // at least 1 hacked for range
  170.  
  171. if (self.demon_one.all_active & #IMPROVED_FOUR && self.demon_two.all_active & #IMPROVED_FOUR)
  172. frange = #FIELDGEN_HACKEDRANGE2; // both field generators hacked
  173.  
  174.  
  175. }
  176.  
  177. te = findradius(self.origin,frange);
  178. while (te)
  179. {
  180. if (te != self)
  181. if (te != self.demon_one)
  182. if (te != self.demon_two)
  183. if (te.velocity == '0 0 0')
  184. if (te.classname != "force_field")
  185. if (EntsTouching2(te,self))
  186. {
  187. #ifdef OMC_DEBUG
  188. // OMC doesnt ever get printed
  189. dprint("In Field_think somethings stuck in the field\n" );
  190.  
  191. #endif
  192. other = te;
  193. deathmsg = #DMSG_STUCK_FORCEFIELD;
  194. self.dmg = #FIELD_DMGINSIDE; // this gonna hurt
  195. Field_touch_SUB();
  196. }
  197.  
  198. te = te.chain;
  199. }
  200. };
  201.  
  202. //=============================================================================================
  203. // is one entity actually intersecting the other one? (this avoids using a stupid trigger)
  204.  
  205. float(entity e1, entity e2) EntsTouching2 =
  206. {
  207. #ifdef OMC_DEBUG
  208. dprint("In EntsTouching2\n" );
  209.  
  210. #endif
  211. if (e1.absmin_x > e2.absmax_x)
  212. return #FALSE;
  213. if (e1.absmin_y > e2.absmax_y)
  214. return #FALSE;
  215. if (e1.absmin_z > e2.absmax_z)
  216. return #FALSE;
  217.  
  218. if (e1.absmax_x < e2.absmin_x)
  219. return #FALSE;
  220. if (e1.absmax_y < e2.absmin_y)
  221. return #FALSE;
  222. if (e1.absmax_z < e2.absmin_z)
  223. return #FALSE;
  224.  
  225. return #TRUE;
  226. };
  227.  
  228. //=================================================================================
  229. // these 2 functions return the current hacks that should apply to the field
  230.  
  231. float(entity tfield) FieldIsImproved =
  232. {
  233.  
  234. #ifdef OMC_DEBUG
  235. dprint("In FieldIsImproved (checking any hacks)\n" );
  236.  
  237. #endif
  238.  
  239. if (IsValidFieldGen(tfield.demon_one) && IsValidFieldGen(tfield.demon_two))
  240. return tfield.demon_one.all_active | tfield.demon_two.all_active;
  241.  
  242. if (IsValidFieldGen(tfield.demon_one))
  243. return tfield.demon_one.all_active;
  244.  
  245. if (IsValidFieldGen(tfield.demon_two))
  246. return tfield.demon_two.all_active;
  247.  
  248. return 0;
  249. };
  250.  
  251. float(entity tfield) FieldIsMalfunctioning =
  252. {
  253.  
  254. #ifdef OMC_DEBUG
  255. dprint("In FieldIsMalfunctioning \n" );
  256.  
  257. #endif
  258.  
  259. if (IsValidFieldGen(tfield.demon_one) && IsValidFieldGen(tfield.demon_two))
  260. return tfield.demon_one.is_malfunctioning | tfield.demon_two.is_malfunctioning;
  261.  
  262. if (IsValidFieldGen(tfield.demon_one))
  263. return tfield.demon_one.is_malfunctioning;
  264.  
  265. if (IsValidFieldGen(tfield.demon_two))
  266. return tfield.demon_two.is_malfunctioning;
  267.  
  268. return 0;
  269. };
  270.  
  271. //=================================================================
  272. // disables force field
  273.  
  274. void(entity tfield, float timedisable) DisableField =
  275. {
  276. if (IsValidFieldGen(tfield.demon_one))
  277. {
  278. tfield.demon_one.has_holo = #FIELDGEN_ISDISABLED;
  279.  
  280. #ifdef OMC_DEBUG
  281. local string Str;
  282. Str = ftos(tfield.demon_one.no_grenades_2);
  283. dprint("In DisableField_1, before 1st field gen restart delay = " );
  284. dprint(Str);
  285. dprint("\n");
  286. #endif
  287.  
  288. if (tfield.demon_one.no_grenades_2 < time + timedisable)
  289. tfield.demon_one.no_grenades_2 = time + timedisable;
  290.  
  291. #ifdef OMC_DEBUG
  292. Str = ftos(tfield.demon_one.no_grenades_2);
  293. dprint("In DisableField_2, after 1st field gen restart delay = " );
  294. dprint(Str);
  295. dprint(", ");
  296. Str = ftos(timedisable);
  297. dprint("timedisable = " );
  298. dprint(Str);
  299. dprint("\n");
  300. #endif
  301. }
  302.  
  303. if (IsValidFieldGen(tfield.demon_two))
  304. {
  305. #ifdef OMC_DEBUG
  306. Str = ftos(tfield.demon_two.no_grenades_2);
  307. dprint("In DisableField_3, before 2nd field gen restart delay = " );
  308. dprint(Str);
  309. dprint("\n");
  310. #endif
  311. tfield.demon_two.has_holo = #FIELDGEN_ISDISABLED;
  312.  
  313. if (tfield.demon_two.no_grenades_2 < time + timedisable)
  314. tfield.demon_two.no_grenades_2 = time + timedisable;
  315.  
  316. #ifdef OMC_DEBUG
  317. Str = ftos(tfield.demon_two.no_grenades_2);
  318. dprint("In DisableField_4, after the 2nd field gen restart delay = " );
  319. dprint(Str);
  320. dprint("\n");
  321. #endif
  322. }
  323.  
  324. sound (tfield, #CHAN_VOICE, "misc/ffbeep.wav", 0.4, #ATTN_IDLE);
  325. };
  326.  
  327. //=========================================================================================
  328. // applies damage and makes the sound and visual effect for the forcefield shock
  329.  
  330. void() Field_touch_SUB =
  331. {
  332.  
  333.  
  334. #ifdef OMC_DEBUG
  335. /* The path for a friendlt teammate entering the fg is: SUB_1 SUB_5 SUB_6 */
  336. dprint("In Field_touch_SUB_1\n" );
  337.  
  338. #endif
  339. if (FieldIsMalfunctioning(self) & #SCREWUP_THREE) // reduce output
  340. self.dmg = 1;
  341.  
  342. #ifdef GIBABLE_CORPSES
  343. if (other.#corpseflag == #STRFLAG_CORPSE) // Corpses
  344. {
  345. #ifdef OMC_DEBUG
  346. dprint("In Field_touch_SUB_2\n" );
  347.  
  348. #endif
  349. if (Field_ItCanPass(self, other))
  350. {
  351. #ifdef OMC_DEBUG
  352. dprint("In Field_touch_SUB_3\n" );
  353.  
  354. #endif
  355. DisableField(self,#FIELDGEN_TIMEDISABLED);
  356. return;
  357. }
  358. else
  359. {
  360. #ifdef OMC_DEBUG
  361. dprint("In Field_touch_SUB_4\n" );
  362.  
  363. #endif
  364. if (Field_ShouldDamage(self,other))
  365. TF_T_Damage (other, self, self.real_owner, self.dmg, 0, #TF_TD_ELECTRICITY);
  366. }
  367. }
  368. else
  369. #endif
  370. if (other.classname == "player" && other.health > 0) // PLAYERS (alive)
  371. {
  372. #ifdef OMC_DEBUG
  373. dprint("In Field_touch_SUB_5 player is alive\n" );
  374.  
  375. #endif
  376. if (other.playerclass == #PC_UNDEFINED) // Observers (they have 1 hp)
  377. return;
  378.  
  379. if (Field_ItCanPass(self, other))
  380. {
  381. #ifdef OMC_DEBUG
  382. dprint("In Field_touch_SUB_6 it can pass \n" );
  383.  
  384. #endif
  385. DisableField(self,#FIELDGEN_TIMEDISABLED);
  386. return;
  387. }
  388. else
  389. {
  390. #ifdef OMC_DEBUG
  391. dprint("In Field_touch_SUB_7\n" );
  392.  
  393. #endif
  394. if (Field_ShouldDamage(self,other))
  395. TF_T_Damage (other, self, self.real_owner, self.dmg, #TF_TD_NOTTEAM, #TF_TD_ELECTRICITY);
  396. }
  397. }
  398. else // non player entities (or player heads)
  399. {
  400. if (IsMonster(other))
  401. {
  402. if (Field_ItCanPass(self, other))
  403. {
  404. DisableField(self,#FIELDGEN_TIMEDISABLED);
  405. return;
  406. }
  407. else if (Field_ShouldDamage(self,other))
  408. TF_T_Damage (other, self, self.real_owner, self.dmg, #TF_TD_NOTTEAM, #TF_TD_ELECTRICITY);
  409. }
  410. else // non-monsters non-alive-players entities (EVERYTHING ELSE)
  411. {
  412. #ifdef OMC_DEBUG
  413. dprint("In Field_touch_SUB_8\n" );
  414.  
  415. #endif
  416. // excludes entities that shouldnt be moved, doors plats etc..
  417. if(other.movetype == #MOVETYPE_NONE
  418. || other.movetype == #MOVETYPE_PUSH
  419. || other == world)
  420. return;
  421.  
  422. if (other.flags & #FL_ONGROUND)
  423. other.velocity_z = other.velocity_z + 100 + 160*random();
  424.  
  425. other.flags = other.flags - (other.flags & #FL_ONGROUND);
  426.  
  427. if (self.cnt) // Y Alignment
  428. {
  429. if (other.origin_x < self.origin_x)
  430. other.velocity_x = (0 - other.velocity_x) - (80 + 100 * random());
  431. else
  432. other.velocity_x = (0 - other.velocity_x) + (80 + 100 * random());
  433. }
  434. else // X Alignment
  435. {
  436. if (other.origin_y < self.origin_y)
  437. other.velocity_y = (0 - other.velocity_y) - (80 + 100 * random());
  438. else
  439. other.velocity_y = (0 - other.velocity_y) + (80 + 100 * random());
  440. }
  441. }
  442. }
  443.  
  444. // Do the effects for shock
  445. FieldExplosion(self,other.origin,other);
  446. PutFieldWork(self);
  447. };
  448.  
  449. #ifdef FIELD_FORCEMODE
  450.  
  451. //==========================================================================
  452. // gets one of our field generators
  453.  
  454. entity(entity myself) GetMyFieldGen =
  455. {
  456. #ifdef OMC_DEBUG
  457. dprint("In GetMyFieldGen \n" );
  458.  
  459. #endif
  460. local entity te;
  461. local float foundit;
  462. te = world;
  463. foundit = #FALSE;
  464.  
  465. te = find(world, classname, "building_fieldgen");
  466. while (te != world && foundit == #FALSE)
  467. {
  468. if (te.real_owner == myself) // is it ours?
  469. foundit = #TRUE; // yeah, found it
  470.  
  471. if (foundit == #FALSE) // our search must continue...
  472. te = find(te, classname, "building_fieldgen");
  473. }
  474.  
  475. return te;
  476. };
  477.  
  478. //=========================================================================
  479. // these functions retrieve and set the current 'forced status' on a field
  480.  
  481. float(entity tfield) Field_GetForcedStatus =
  482. {
  483. #ifdef OMC_DEBUG
  484. dprint("In Field_GetForcedStatus \n" );
  485.  
  486. #endif
  487. if (IsValidFieldGen(tfield.demon_one) && IsValidFieldGen(tfield.demon_two))
  488. {
  489. if (tfield.demon_two.has_tesla || tfield.demon_one.has_tesla)
  490. return #TRUE;
  491. }
  492. else if (IsValidFieldGen(tfield.demon_one))
  493. {
  494. if (tfield.demon_one.has_tesla)
  495. return #TRUE;
  496. }
  497. else if (IsValidFieldGen(tfield.demon_two))
  498. {
  499. if (tfield.demon_two.has_tesla)
  500. return #TRUE;
  501. }
  502.  
  503. return #FALSE;
  504. };
  505.  
  506. //==============================================================================
  507. // player functions called on menu.qc to disable/enable forced status on field
  508.  
  509. void(float value) SetFieldForcedStatus =
  510. {
  511. #ifdef OMC_DEBUG
  512. dprint("In SetFieldForcedStatus\n" );
  513.  
  514. #endif
  515. local entity gen1, gen2;
  516. gen1 = GetMyFieldGen(self);
  517. gen2 = Find_OtherGen(gen1);
  518.  
  519. if (IsValidFieldGen(gen1))
  520. {
  521. gen1.has_tesla = value;
  522. if (value)
  523. gen1.no_grenades_2 = time;
  524. }
  525.  
  526. if (IsValidFieldGen(gen2))
  527. {
  528. gen2.has_tesla = value;
  529. if (value)
  530. gen2.no_grenades_2 = time;
  531. }
  532. };
  533.  
  534. float() GetFieldForcedStatus =
  535. {
  536. local entity gen1, gen2;
  537. gen1 = GetMyFieldGen(self);
  538. gen2 = Find_OtherGen(gen1);
  539.  
  540. if (IsValidFieldGen(gen1) && IsValidFieldGen(gen2))
  541. {
  542. if (gen1.has_tesla || gen2.has_tesla)
  543. return #TRUE;
  544. }
  545. else if (IsValidFieldGen(gen1))
  546. return gen1.has_tesla;
  547. else if (IsValidFieldGen(gen2))
  548. return gen2.has_tesla;
  549.  
  550. return #FALSE;
  551.  
  552. };
  553.  
  554. #endif
  555.  
  556. //=========================================================================
  557. // returns TRUE if 'who' entity should be able to pass thru the field
  558.  
  559. float(entity tfield, entity who) Field_ItCanPass =
  560. {
  561. #ifdef OMC_DEBUG
  562. dprint("In Field_ItCanPass\n" );
  563.  
  564. #endif
  565.  
  566. #ifdef FIELD_TEST
  567. return #FALSE;
  568. #endif
  569.  
  570. if (FieldIsMalfunctioning(tfield) & #SCREWUP_ONE) // Malfunctioning, always block
  571. return #FALSE;
  572.  
  573. if (who == tfield.real_owner) // field owner - always pass
  574. return #TRUE;
  575.  
  576. #ifdef FIELD_FORCEMODE
  577.  
  578. if (Field_GetForcedStatus(tfield))
  579. return #FALSE;
  580.  
  581. #endif
  582.  
  583. if (who.classname == "player") // PLAYERS
  584. {
  585. if (Teammate(who.team_no, tfield.real_owner.team_no)) // teammate
  586. return #TRUE;
  587.  
  588. if (Teammate(who.undercover_team, tfield.real_owner.team_no)) // spies disguised as our team
  589. return #TRUE;
  590. }
  591. else if (IsMonster(who)) // MONSTERS/ARMY
  592. {
  593. if (Teammate(who.real_owner.team_no, tfield.real_owner.team_no)) // team monster
  594. return #TRUE;
  595. }
  596. #ifdef GIBABLE_CORPSES
  597. else if (who.#corpseflag == #STRFLAG_CORPSE) // CORPSES
  598. {
  599. if (Teammate(who.team_no, tfield.real_owner.team_no)) // team corpse
  600. return #TRUE;
  601. }
  602. #endif
  603.  
  604. return #FALSE;
  605. };
  606.  
  607. //=========================================================================
  608. // returns TRUE if 'who' entity should be damaged by the field
  609.  
  610. float(entity tfield, entity who) Field_ShouldDamage =
  611. {
  612.  
  613. #ifdef OMC_DEBUG
  614. dprint("In Field_ShouldDamage\n" );
  615.  
  616. #endif
  617.  
  618.  
  619.  
  620. #ifdef FIELD_TEST
  621. return #TRUE;
  622. #endif
  623.  
  624. if (FieldIsMalfunctioning(tfield) & #SCREWUP_ONE) // Malfunctioning, hurts always
  625. return #TRUE;
  626.  
  627. if (who.classname == "player") // PLAYERS
  628. {
  629. if (who == tfield.real_owner) // field owner
  630. return #FALSE;
  631.  
  632. if (Teammate(who.team_no, tfield.real_owner.team_no)) // teammate
  633. return #FALSE;
  634.  
  635. if (Teammate(who.undercover_team, tfield.real_owner.team_no)) // spies disguised as our team
  636. return #FALSE;
  637. }
  638. else if (IsMonster(who)) // MONSTERS/ARMY
  639. {
  640. if (Teammate(who.real_owner.team_no, tfield.real_owner.team_no)) // team monster
  641. return #FALSE;
  642. }
  643. #ifdef GIBABLE_CORPSES
  644. else if (who.#corpseflag == #STRFLAG_CORPSE) // CORPSES
  645. {
  646. if (Teammate(who.team_no, tfield.real_owner.team_no)) // team corpse
  647. return #FALSE;
  648. }
  649. #endif
  650.  
  651. return #TRUE;
  652. };
  653.  
  654. //=============================================================================
  655. // applies the particle effect and electric sound (at max 4hz rate)
  656.  
  657. void(entity tfield, vector where, entity thing) FieldExplosion =
  658. {
  659. if (!tfield.has_camera)
  660. {
  661. if (thing == world || thing.is_removed) return;
  662.  
  663. local vector whereFX;
  664. whereFX = where;
  665. whereFX_z = tfield.origin_z;
  666.  
  667. spawnFOG(whereFX);
  668. sound(tfield,#CHAN_BODY,"effects/crunch.wav",0.5,#ATTN_NORM);
  669.  
  670. tfield.has_camera = #TRUE; // cya soon (this gets reset on every field think)
  671. }
  672. };
  673.  
  674. //================================================================
  675. // Refresh working time for the force field
  676.  
  677. void(entity field) PutFieldWork =
  678. {
  679. #ifdef OMC_DEBUG
  680. dprint("In PutFieldWork \n" );
  681.  
  682. #endif
  683. if (IsValidFieldGen(field.demon_one))
  684. field.demon_one.tp_grenades_1 = time + #FIELDGEN_WORKTIME;
  685. if (IsValidFieldGen(field.demon_two))
  686. field.demon_two.tp_grenades_1 = time + #FIELDGEN_WORKTIME;
  687. };
  688.  
  689. //==============================================================
  690. // Force field touch function
  691.  
  692. void() Field_touch =
  693. {
  694. #ifdef OMC_DEBUG
  695. dprint("In Field_touch\n" );
  696.  
  697. #endif
  698. if (other.classname == "force_field") return; //avoid weird loops with other fields
  699.  
  700. self.dmg = #FIELD_DMG;
  701.  
  702. deathmsg = #DMSG_FORCEFIELD;
  703. Field_touch_SUB();
  704. };
  705.  
  706. //===================================================================================
  707. // creates the force field between the 2 generators (only if none currently on)
  708.  
  709. void(entity gen1, entity gen2) Create_Field =
  710. {
  711. #ifdef OMC_DEBUG
  712. dprint("In Create_Field\n" );
  713.  
  714. #endif
  715. // Check for existing force field, and abort if any
  716. if (gen1.has_sensor || gen2.has_sensor)
  717. {
  718. #ifdef OMC_DEBUG
  719.  
  720. // THE BUG!!!!
  721. // After a teammate enters the FG, it deactivates briefly, so they can pass.
  722. // In FTE the line (gen1.has_sensor || gen2.has_sensor) is TRUE and the following gets printed.
  723. // In cpqwsv the following line doesnt run, and the program flow goes straight to FieldGen_think_5
  724.  
  725.  
  726. dprint("In Create_Field FTE thinks forcefield is up\n" );
  727.  
  728. #endif
  729. return;
  730. }
  731.  
  732. if (gen1.martyr_enemy != world || gen2.martyr_enemy != world) // 2nd CHECK
  733. {
  734. #ifdef OMC_DEBUG
  735. // GROUND ZERO
  736. dprint("In Create_Field FTE thinks forcefield isnt set to world\n" );
  737. #endif
  738. return;
  739. }
  740.  
  741. // already checked b4 on CanLink -> CanIdle
  742. /*if (!IsValidFieldGen(gen1) || !IsValidFieldGen(gen2))
  743. return;*/
  744.  
  745. gen1.has_holo = #FIELDGEN_ISENABLED;
  746. gen2.has_holo = #FIELDGEN_ISENABLED;
  747.  
  748. gen1.has_sensor = #TRUE;
  749. gen2.has_sensor = #TRUE;
  750.  
  751. local entity tfield;
  752.  
  753. // generate field
  754. tfield = spawn();
  755. tfield.classname = "force_field";
  756. tfield.owner = world;
  757. tfield.real_owner = gen1.real_owner; // --> player
  758.  
  759. tfield.think = Field_think;
  760. tfield.touch = Field_touch;
  761. tfield.nextthink = time + 0.25;
  762.  
  763. // set pos and size
  764. tfield.origin = gen1.origin + '0 0 32';
  765. tfield.absmin_z = gen1.origin_z - 32;
  766. tfield.absmax_z = gen1.origin_z + 32;
  767.  
  768. tfield.mins_z = 0 - 32;
  769. tfield.maxs_z = 32;
  770. tfield.size_z = 64;
  771.  
  772. local float diff;
  773.  
  774. if (gen1.origin_x == gen2.origin_x)
  775. {
  776. tfield.cnt = 0;
  777.  
  778. tfield.origin_x = gen1.origin_x;
  779. tfield.absmin_x = gen1.origin_x - 2;
  780. tfield.absmax_x = gen1.origin_x + 2;
  781.  
  782. tfield.maxs_x = 2;
  783. tfield.mins_x = 0 - 2;
  784. tfield.size_x = 4;
  785.  
  786. if (gen1.origin_y > gen2.origin_y)
  787. {
  788. diff = (gen1.origin_y - gen2.origin_y)/2;
  789.  
  790. tfield.origin_y = gen1.origin_y - diff;
  791. tfield.absmin_y = gen2.origin_y;
  792. tfield.absmax_y = gen1.origin_y;
  793.  
  794. tfield.maxs_y = diff;
  795. tfield.mins_y = 0 - diff;
  796. tfield.size_y = diff * 2;
  797. }
  798. else
  799. {
  800. diff = (gen2.origin_y - gen1.origin_y)/2;
  801.  
  802. tfield.origin_y = gen2.origin_y - diff;
  803. tfield.absmin_y = gen1.origin_y;
  804. tfield.absmax_y = gen2.origin_y;
  805.  
  806. tfield.maxs_y = diff;
  807. tfield.mins_y = 0 - diff;
  808. tfield.size_y = diff * 2;
  809. }
  810. }
  811. else
  812. {
  813. tfield.cnt = 1;
  814.  
  815. tfield.origin_y = gen1.origin_y;
  816. tfield.absmin_y = gen1.origin_y - 2;
  817. tfield.absmax_y = gen1.origin_y + 2;
  818.  
  819. tfield.maxs_y = 2;
  820. tfield.mins_y = 0 - 2;
  821. tfield.size_y = 4;
  822.  
  823. if (gen1.origin_x > gen2.origin_x)
  824. {
  825. diff = (gen1.origin_x - gen2.origin_x)/2;
  826.  
  827. tfield.origin_x = gen1.origin_x - diff;
  828. tfield.absmin_x = gen2.origin_x;
  829. tfield.absmax_x = gen1.origin_x;
  830.  
  831. tfield.maxs_x = diff;
  832. tfield.mins_x = 0 - diff;
  833. tfield.size_x = diff * 2;
  834.  
  835. }
  836. else
  837. {
  838. diff = (gen2.origin_x - gen1.origin_x)/2;
  839.  
  840. tfield.origin_x = gen2.origin_x - diff;
  841. tfield.absmin_x = gen1.origin_x;
  842. tfield.absmax_x = gen2.origin_x;
  843.  
  844. tfield.maxs_x = diff;
  845. tfield.mins_x = 0 - diff;
  846. tfield.size_x = diff * 2;
  847. }
  848. }
  849. //============================= !!!!!!!!!! ===================
  850. // OMC_FG I think the problem is here ->
  851. // apply stuff
  852. tfield.movetype = #MOVETYPE_NONE;
  853. tfield.solid = #SOLID_BBOX;
  854. setsize(tfield, tfield.mins, tfield.maxs);
  855. setorigin(tfield, tfield.origin);
  856.  
  857. // assign the pointers on the field generators
  858. gen1.martyr_enemy = tfield;
  859. gen2.martyr_enemy = tfield;
  860.  
  861. // assign the pointers to generators on ourselves
  862. tfield.demon_one = gen1;
  863. tfield.demon_two = gen2;
  864.  
  865. // make activation sound
  866. sound (tfield, #CHAN_VOICE, "misc/ffact.wav", 0.2, #ATTN_NORM);
  867.  
  868. // initialize sound flags on field
  869. tfield.has_sensor = #FALSE;
  870. tfield.has_holo = #FALSE;
  871.  
  872. // flash generators
  873. gen1.effects = #EF_DIMLIGHT | #EF_RED;
  874. gen1.has_teleporter = #TRUE;
  875. gen1.skin = 2;
  876. gen2.effects = #EF_DIMLIGHT | #EF_RED;
  877. gen2.has_teleporter = #TRUE;
  878. gen2.skin = 2;
  879. };
  880.  
  881. //=================================================================
  882. // removes the force field (if any)
  883.  
  884. void(entity gen1, entity gen2) Remove_Field =
  885. {
  886. #ifdef OMC_DEBUG
  887. dprint("In Remove_Field\n" );
  888.  
  889. #endif
  890. local float soundsoff;
  891. soundsoff = #FALSE;
  892.  
  893. if (IsValidFieldGen(gen1))
  894. {
  895. gen1.has_sensor = #FALSE;
  896.  
  897. if (IsValidField(gen1.martyr_enemy))
  898. {
  899. Field_StopSounds(gen1.martyr_enemy); // Stops sounds on force field
  900. soundsoff = #TRUE;
  901.  
  902. dremove(gen1.martyr_enemy);
  903. gen1.martyr_enemy = world;
  904. }
  905. }
  906.  
  907. if (IsValidFieldGen(gen2))
  908. {
  909. gen2.has_sensor = #FALSE;
  910.  
  911. if (IsValidField(gen2.martyr_enemy))
  912. {
  913. if (!soundsoff)
  914. Field_StopSounds(gen2.martyr_enemy); // Stops sounds on force field if not done
  915.  
  916. dremove(gen2.martyr_enemy);
  917. gen2.martyr_enemy = world;
  918. }
  919. }
  920. };
  921.  
  922. //======================================================================
  923. // The following 2 functions are used for safety everywhere
  924.  
  925. float(entity field) IsValidField =
  926. {
  927. if (field == world)
  928. return #FALSE;
  929.  
  930. if (field.classname != "force_field")
  931. return #FALSE;
  932.  
  933. return #TRUE;
  934. };
  935.  
  936. float(entity fieldgen) IsValidFieldGen =
  937. {
  938. if (fieldgen == world)
  939. return #FALSE;
  940.  
  941. if (fieldgen.classname != "building_fieldgen")
  942. return #FALSE;
  943.  
  944. return #TRUE;
  945. };
  946.  
  947. //========================================================
  948. // starts or removes sounds on the field
  949.  
  950. void(entity tfield, entity gen1) Field_UpdateSounds =
  951. {
  952. #ifdef OMC_DEBUG
  953. dprint("In Field_UpdateSounds\n" );
  954.  
  955. #endif
  956. //.has_holo : hum
  957. //.has_sensor : shield
  958.  
  959. if (IsValidField(tfield)) // only if there is a field currently
  960. {
  961. local float playhum, playshield;
  962.  
  963. playhum = #FALSE;
  964. playshield = #FALSE;
  965.  
  966. /*if (gen1.has_holo == #FIELDGEN_ISOFF) // for some reason we r not working
  967. {
  968. playhum = #FALSE;
  969. playshield = #FALSE;
  970. }
  971. else if (gen1.has_holo == #FIELDGEN_ISIDLE) // awaiting for link
  972. {
  973. playhum = #FALSE;
  974. playshield = #FALSE;
  975. }
  976. else if (gen1.has_holo == #FIELDGEN_ISDISABLED) // teammate passing thru the field?
  977. {
  978. playhum = #FALSE;
  979. playshield = #FALSE;
  980. }
  981. else*/
  982.  
  983. if (gen1.has_holo == #FIELDGEN_ISENABLED)
  984. {
  985. playhum = #TRUE;
  986. playshield = #FALSE;
  987. }
  988. else if (gen1.has_holo == #FIELDGEN_ISWORKING)
  989. {
  990. playhum = #TRUE;
  991. playshield = #TRUE;
  992. }
  993.  
  994. // ok, lets update the sounds if needed..
  995. if (!playhum)
  996. {
  997. if (tfield.has_holo)
  998. {
  999. sound(tfield,#CHAN_MISC,"misc/null.wav",0.5,#ATTN_NORM);
  1000. tfield.has_holo = #FALSE;
  1001. }
  1002. }
  1003. else
  1004. {
  1005. if (!tfield.has_holo || tfield.has_tesla < time)
  1006. {
  1007. sound(tfield,#CHAN_MISC,"misc/ffhum.wav",0.4,#ATTN_NORM);
  1008. tfield.has_tesla = time + #FIELD_SOUNDSRATE;
  1009. tfield.has_holo = #TRUE;
  1010. }
  1011. }
  1012.  
  1013. if (!playshield)
  1014. {
  1015. if (tfield.has_sensor)
  1016. {
  1017. sound(tfield,#CHAN_ITEM,"misc/null.wav",0.5,#ATTN_NORM);
  1018. tfield.has_sensor = #FALSE;
  1019. }
  1020. }
  1021. else
  1022. {
  1023. if (!tfield.has_sensor || tfield.has_sentry < time)
  1024. {
  1025. //TODO?: lower volume as (FIELDGEN_WORKTIME - time) decreases
  1026.  
  1027. sound(tfield,#CHAN_ITEM,"misc/ffield.wav",0.5,#ATTN_NORM);
  1028. tfield.has_sentry = time + #FIELD_SOUNDSRATE;
  1029. tfield.has_sensor = #TRUE;
  1030. }
  1031. }
  1032. }
  1033. };
  1034.  
  1035. //====================================================================
  1036. // Called on each force field removal to stop any sounds from it
  1037.  
  1038. void(entity tfield) Field_StopSounds =
  1039. {
  1040. // We dont do any check because this function is called with everything already checked
  1041. sound(tfield,#CHAN_ITEM,"misc/null.wav",0.5,#ATTN_NORM);
  1042. sound(tfield,#CHAN_MISC,"misc/null.wav",0.5,#ATTN_NORM);
  1043. tfield.has_sensor = #FALSE;
  1044. tfield.has_holo = #FALSE;
  1045. };
  1046.  
  1047. //====================================================================
  1048. // do the lightning stuff while field is FIELDGEN_ISWORKING
  1049.  
  1050. void(entity tfield) Field_MakeVisual =
  1051. {
  1052. // To avoid some overhead, only do visual lightning effect sometimes
  1053. if (random() < #FIELD_VISUALFACTOR)
  1054. return;
  1055.  
  1056. if (IsValidField(tfield))
  1057. {
  1058. local float fx, fy;
  1059. local vector tmpvec;
  1060.  
  1061. if (tfield.cnt)
  1062. {
  1063. fy = tfield.origin_y;
  1064. fx = tfield.origin_x + (tfield.size_x/2 - tfield.size_x * random());
  1065. }
  1066. else
  1067. {
  1068. fx = tfield.origin_x;
  1069. fy = tfield.origin_y + (tfield.size_y/2 - tfield.size_y * random());
  1070. }
  1071.  
  1072. tmpvec_x = fx;
  1073. tmpvec_y = fy;
  1074. tmpvec_z = tfield.origin_z - 12;
  1075.  
  1076. WriteByte (#MSG_BROADCAST, #SVC_TEMPENTITY);
  1077.  
  1078. if (random() > 0.5)
  1079. WriteByte (#MSG_BROADCAST, #TE_LIGHTNING2);
  1080. else
  1081. WriteByte (#MSG_BROADCAST, #TE_LIGHTNING1);
  1082.  
  1083. WriteEntity (#MSG_BROADCAST, tfield);
  1084.  
  1085. if (random() > 0.5)
  1086. {
  1087. WriteCoord (#MSG_BROADCAST, fx);
  1088. WriteCoord (#MSG_BROADCAST, fy);
  1089. WriteCoord (#MSG_BROADCAST, tfield.origin_z - 12);
  1090. WriteCoord (#MSG_BROADCAST, fx);
  1091. WriteCoord (#MSG_BROADCAST, fy);
  1092. WriteCoord (#MSG_BROADCAST, tfield.origin_z + 12);
  1093. }
  1094. else
  1095. {
  1096. WriteCoord (#MSG_BROADCAST, fx);
  1097. WriteCoord (#MSG_BROADCAST, fy);
  1098. WriteCoord (#MSG_BROADCAST, tfield.origin_z + 22);
  1099. WriteCoord (#MSG_BROADCAST, fx);
  1100. WriteCoord (#MSG_BROADCAST, fy);
  1101. WriteCoord (#MSG_BROADCAST, tfield.origin_z - 2);
  1102. }
  1103.  
  1104. #ifdef QUAKE_WORLD
  1105. multicast (tmpvec, #MULTICAST_PHS);
  1106. #endif
  1107. }
  1108. };
  1109.  
  1110. //==================================================
  1111. // called every frame by the field generators
  1112.  
  1113. void() FieldGen_think =
  1114. {
  1115. local entity othergen;
  1116. othergen = Find_OtherGen(self); // get our brother
  1117.  
  1118.  
  1119. #ifdef OMC_DEBUG
  1120. local string Str;
  1121.  
  1122. #endif
  1123.  
  1124.  
  1125.  
  1126. // Create the force field if it's possible, or remove it if not and exists
  1127. if (FieldGens_CanLink(self,othergen))
  1128. {
  1129. #ifdef OMC_DEBUG
  1130.  
  1131. dprint("FieldGen_think FieldGens_CAN Link\n" );
  1132.  
  1133. #endif
  1134. // OMC_GROUND minus 1
  1135. Create_Field(self,othergen); // checks redundancy itself
  1136. }
  1137.  
  1138. else
  1139. {
  1140. #ifdef OMC_DEBUG
  1141. dprint("FieldGen_think FieldGens_CANT Link\n" );
  1142.  
  1143. #endif
  1144.  
  1145. Remove_Field(self,othergen); // checks redundancy itself
  1146. }
  1147.  
  1148.  
  1149. // field gens main loop (ai? heh.. my cat is smarter than these force fields)
  1150. if (self.has_holo == #FIELDGEN_ISOFF) // for some reason we r not working
  1151. {
  1152. #ifdef OMC_DEBUG
  1153. dprint("FieldGen_think_1 (FIELDGEN_ISOFF) \n" );
  1154.  
  1155. #endif
  1156. self.effects = 0;
  1157. self.skin = 0;
  1158.  
  1159. if (FieldGen_CanIdle(self)) // can we go idle?
  1160. {
  1161. #ifdef OMC_DEBUG
  1162. dprint("FieldGen_think_1 fieldgen can idle\n" );
  1163.  
  1164. #endif
  1165. self.has_holo = #FIELDGEN_ISIDLE;
  1166. }
  1167. }
  1168. else if (self.has_holo == #FIELDGEN_ISIDLE) // trying to link
  1169. {
  1170. #ifdef OMC_DEBUG
  1171. dprint("FieldGen_think_2 (trying to link)\n" );
  1172.  
  1173. #endif
  1174. self.effects = 0;
  1175. self.skin = 0;
  1176.  
  1177. if (self.no_grenades_1 < time) // trying to link sound/flash time
  1178. {
  1179. #ifdef OMC_DEBUG
  1180. Str=ftos(self.no_grenades_1);
  1181. dprint("FieldGen_think_2.5 self.no_grenades_1: " );
  1182. dprint(Str);
  1183. dprint(", time = " );
  1184. Str=ftos(time);
  1185. dprint(Str);
  1186. dprint("\n" );
  1187.  
  1188. #endif
  1189. sound (self, #CHAN_WEAPON, "misc/fffail.wav", 0.5, #ATTN_IDLE);
  1190. self.skin = 1;
  1191. self.effects = #EF_DIMLIGHT;
  1192. self.no_grenades_1 = time + #FIELDGEN_LINKTIME;
  1193. }
  1194. }
  1195. else if (self.has_holo == #FIELDGEN_ISDISABLED) // teammate passing thru the field?
  1196. {
  1197. #ifdef OMC_DEBUG
  1198. dprint("FieldGen_think_3 - teammate passing thru the field\n" );
  1199.  
  1200. #endif
  1201. self.effects = 0;
  1202. self.skin = 0;
  1203.  
  1204.  
  1205. // OMC_THIS IS WHERE THE PROBLEM IS
  1206. // time check
  1207. if (self.no_grenades_2 < time) // can we go idle?
  1208. {
  1209. #ifdef OMC_DEBUG
  1210. dprint("FieldGen_think_4 (fieldgen is idle)\n" );
  1211.  
  1212. #endif
  1213. self.has_holo = #FIELDGEN_ISIDLE;
  1214. self.tp_grenades_1 = 0;
  1215. }
  1216. }
  1217. else if (self.has_holo == #FIELDGEN_ISENABLED) // we r ready and linked
  1218. {
  1219. #ifdef OMC_DEBUG
  1220. dprint("FieldGen_think_5\n" );
  1221.  
  1222. #endif
  1223. if (!self.has_teleporter)
  1224. {
  1225. self.effects = 0;
  1226. self.skin = 1;
  1227. }
  1228.  
  1229. // omc_FTE THIS IS THERE THE PROBLEM MIGHT BE
  1230. if (self.has_sensor == #FALSE)
  1231. {
  1232. #ifdef OMC_DEBUG
  1233. dprint("FieldGen_think 5.5 self.has_sensor is FALSE, self.has_holo just got set to FIELDGEN_ISIDLE \n" );
  1234.  
  1235. #endif
  1236. self.has_holo = #FIELDGEN_ISIDLE;
  1237. }
  1238.  
  1239. if (self.tp_grenades_1 >= time)
  1240. self.has_holo = #FIELDGEN_ISWORKING;
  1241. }
  1242. else if (self.has_holo == #FIELDGEN_ISWORKING) // hopefully after killing some1..
  1243. {
  1244. #ifdef OMC_DEBUG
  1245. dprint("FieldGen_think_6\n" );
  1246.  
  1247. #endif
  1248. self.effects = #EF_DIMLIGHT;
  1249. self.skin = 2;
  1250.  
  1251. if (self.has_camera <= time)
  1252. {
  1253. self.ammo_cells = self.ammo_cells - #FIELDGEN_CELLSCOST;
  1254.  
  1255. if (self.ammo_cells <= 24 && self.ammo_cells > 24 - #FIELDGEN_CELLSCOST)
  1256. sprint(self.real_owner,#PRINT_HIGH,"Your field generator is low on cells\n");
  1257. else if (self.ammo_cells < #FIELDGEN_CELLSCOST)
  1258. sprint(self.real_owner,#PRINT_HIGH,"Your field generator has run out of cells\n");
  1259.  
  1260. self.has_camera = time + #FIELDGEN_WORKING_RATE;
  1261. }
  1262.  
  1263. if (self.has_sensor == #FALSE)
  1264. {
  1265. #ifdef OMC_DEBUG
  1266. dprint("FieldGen_think_6.5 .has_sensor == FALSE\n" );
  1267.  
  1268. #endif
  1269.  
  1270. self.has_holo = #FIELDGEN_ISIDLE;
  1271. }
  1272. else if (self.tp_grenades_1 <= time)
  1273. self.has_holo = #FIELDGEN_ISENABLED;
  1274. }
  1275.  
  1276. if (!FieldGen_CanIdle(self)) // turn us off if needed
  1277. self.has_holo = #FIELDGEN_ISOFF;
  1278.  
  1279. Field_UpdateSounds(self.martyr_enemy,self); // update force field sounds
  1280.  
  1281. self.has_teleporter = #FALSE; // resets 'flash' status bypass
  1282. self.nextthink = time + 0.1;
  1283. };
  1284.  
  1285. //=======================================================================
  1286. // returns TRUE if the generator could currently go to idle status
  1287.  
  1288. float(entity fieldgen) FieldGen_CanIdle =
  1289. {
  1290.  
  1291. if (!(IsValidFieldGen(fieldgen)))
  1292. {
  1293. #ifdef OMC_DEBUG
  1294. dprint("FieldGen_CanIdle IsValidFieldGen returning false\n" );
  1295.  
  1296. #endif
  1297.  
  1298. return #FALSE;
  1299. }
  1300.  
  1301. if (fieldgen.ammo_cells >= #FIELDGEN_CELLSCOST &&
  1302. !(fieldgen.is_malfunctioning & #SCREWUP_FOUR)
  1303. && fieldgen.health > 0)
  1304. {
  1305. #ifdef OMC_DEBUG
  1306. dprint("FieldGen_CanIdle returning TRUE\n" );
  1307.  
  1308. #endif
  1309. return #TRUE;
  1310. }
  1311.  
  1312. #ifdef OMC_DEBUG
  1313. dprint("FieldGen_CanIdle returning (default) false\n" );
  1314.  
  1315. #endif
  1316.  
  1317. return #FALSE;
  1318. };
  1319.  
  1320. //=======================================================================
  1321. // returns TRUE if both generators could currently generate the field
  1322.  
  1323. float(entity fieldgen1, entity fieldgen2) FieldGens_CanLink =
  1324. {
  1325.  
  1326. //!!!!!!!!!!!!!!!
  1327. // OMC bug 25 oct 2010 ok this returns false if teammate walks through!!
  1328. //!!!!!!!!!!!!!!!!!!
  1329.  
  1330.  
  1331.  
  1332. if (!(IsValidFieldGen(fieldgen1)) || !(IsValidFieldGen(fieldgen2)))
  1333. {
  1334. #ifdef OMC_DEBUG
  1335. dprint("FieldGens_CanLink_1\n" );
  1336.  
  1337. #endif
  1338. return #FALSE;
  1339. }
  1340.  
  1341. if (!visible2(fieldgen1,fieldgen2))
  1342. {
  1343. #ifdef OMC_DEBUG
  1344. dprint("FieldGens_CanLink_2 can't see them\n" );
  1345.  
  1346. #endif
  1347. return #FALSE;
  1348. }
  1349.  
  1350. local float r;
  1351. r = vlen(fieldgen1.origin - fieldgen2.origin); // get distance between generators
  1352.  
  1353. // Both fieldgens hacked
  1354. if ((fieldgen1.all_active & #IMPROVED_FOUR && fieldgen2.all_active & #IMPROVED_FOUR) && r > #FIELDGEN_HACKEDRANGE2)
  1355. {
  1356. #ifdef OMC_DEBUG
  1357. dprint("FieldGens_CanLink_3 both FGs hacked\n" );
  1358.  
  1359. #endif
  1360. return #FALSE;
  1361. }
  1362.  
  1363. // Only 1 fieldgen hacked
  1364. if ( ((fieldgen1.all_active & #IMPROVED_FOUR && !(fieldgen2.all_active & #IMPROVED_FOUR)) || (fieldgen2.all_active & #IMPROVED_FOUR && !(fieldgen1.all_active & #IMPROVED_FOUR))) && r > #FIELDGEN_HACKEDRANGE)
  1365. {
  1366. #ifdef OMC_DEBUG
  1367. dprint("FieldGens_CanLink_4\n" );
  1368.  
  1369. #endif
  1370. return #FALSE;
  1371. }
  1372.  
  1373. // None hacked for range
  1374. if (r > #FIELDGEN_RANGE && !(fieldgen1.all_active & #IMPROVED_FOUR || fieldgen2.all_active & #IMPROVED_FOUR))
  1375. {
  1376. #ifdef OMC_DEBUG
  1377. dprint("FieldGens_CanLink_5 none hacked\n" );
  1378.  
  1379. #endif
  1380. return #FALSE;
  1381. }
  1382.  
  1383. if (fieldgen1.origin_z != fieldgen2.origin_z) // Different heights?
  1384. {
  1385. #ifdef OMC_DEBUG
  1386. dprint("FieldGens_CanLink_6 different heights\n" );
  1387.  
  1388. #endif
  1389. return #FALSE;
  1390. }
  1391.  
  1392. if (fieldgen1.origin_x != fieldgen2.origin_x && fieldgen1.origin_y != fieldgen2.origin_y) // Unaligned?
  1393. {
  1394. #ifdef OMC_DEBUG
  1395. dprint("FieldGens_CanLink_7 not aligned\n" );
  1396.  
  1397. #endif
  1398. return #FALSE;
  1399. }
  1400.  
  1401. if (fieldgen1.has_holo == #FIELDGEN_ISDISABLED || fieldgen2.has_holo == #FIELDGEN_ISDISABLED)
  1402. {
  1403. #ifdef OMC_DEBUG
  1404. dprint("FieldGens_CanLink_8 FGs are disabled\n" );
  1405.  
  1406. #endif
  1407. return #FALSE;
  1408. }
  1409.  
  1410. if (fieldgen1.has_holo == #FIELDGEN_ISOFF || fieldgen2.has_holo == #FIELDGEN_ISOFF)
  1411. {
  1412. #ifdef OMC_DEBUG
  1413. dprint("FieldGens_CanLink_9 FGs are off\n" );
  1414.  
  1415. #endif
  1416. return #FALSE;
  1417. }
  1418.  
  1419. // Return TRUE only if basic conditions on CanIdle() are meet
  1420. if (FieldGen_CanIdle(fieldgen1) && FieldGen_CanIdle(fieldgen2))
  1421. {
  1422. #ifdef OMC_DEBUG
  1423. dprint("FieldGens_CanLink_10 -basic conditions on CanIdle() are met\n" );
  1424.  
  1425. #endif
  1426. return #TRUE;
  1427. }
  1428.  
  1429. return #FALSE;
  1430. };
  1431.  
  1432. //=============================================================================================
  1433. // initialize field generator stuff just after beeing built, called on engineer.qc
  1434.  
  1435. void(entity fieldgen) FieldGen_Built =
  1436. {
  1437. fieldgen.touch = SUB_Null;
  1438. fieldgen.think = FieldGen_think;
  1439. fieldgen.nextthink = time + 0.1;
  1440. fieldgen.has_holo = #FIELDGEN_ISIDLE; // we start on IDLE status (searching for other gen to link)
  1441. fieldgen.has_sensor = #FALSE;
  1442. fieldgen.no_grenades_1 = time + 3;
  1443. fieldgen.martyr_enemy = world;
  1444. };
  1445.  
  1446. //==============================================================
  1447. // returns our other generator (if any)
  1448.  
  1449. entity(entity fieldgen) Find_OtherGen =
  1450. {
  1451. local entity te;
  1452. local float foundit;
  1453. te = world;
  1454. foundit = #FALSE;
  1455.  
  1456. te = find(world, classname, "building_fieldgen");
  1457. while (te != world && foundit == #FALSE)
  1458. {
  1459. if (te.real_owner == fieldgen.real_owner) // is it ours?
  1460. if (te != fieldgen) // and not the same generator..
  1461. foundit = #TRUE; // yeah, found it
  1462.  
  1463. if (foundit == #FALSE) // our search must continue...
  1464. te = find(te, classname, "building_fieldgen");
  1465. }
  1466.  
  1467. return te;
  1468. };
  1469.  
  1470. //=========================================================================================
  1471. // returns the place where field gen will be built related to player current pos and yaw
  1472. // called on engineer.qc, place is the origin passed where other kind of buildings are placed
  1473.  
  1474. vector(vector place) WhereGen =
  1475. {
  1476. // if we have no field generator currently, it can be placed anywhere
  1477. if (self.has_fieldgen == 0) return place;
  1478.  
  1479. local vector retval;
  1480. local float r, distx, disty, foundit;
  1481. local entity te;
  1482.  
  1483. foundit = #FALSE;
  1484.  
  1485. // find the other generator
  1486. te = find(world, classname, "building_fieldgen");
  1487. while (te != world && foundit == #FALSE)
  1488. {
  1489. if (te.real_owner == self) // is it ours?
  1490. foundit = #TRUE; // yeah, found it
  1491.  
  1492. if (foundit == #FALSE) // our search must continue...
  1493. te = find(te, classname, "building_fieldgen");
  1494. }
  1495.  
  1496. // check for error getting the other gen
  1497. if (te == world || te.classname != "building_fieldgen" || foundit == #FALSE)
  1498. {
  1499. RPrint("BUG: Error in field generator placement routine. 'WhereGen()'\n");
  1500. return place;
  1501. }
  1502.  
  1503. // calculate the new generator pos
  1504. distx = fabs(place_x - te.origin_x);
  1505. disty = fabs(place_y - te.origin_y);
  1506. retval = place;
  1507.  
  1508. if (distx < disty)
  1509. {
  1510. retval_x = te.origin_x; // adjust it in line
  1511.  
  1512. r = vlen(self.origin - retval); // get distance from us (player)
  1513. if (r > 200) // we r too far away?
  1514. retval = place; // then bypass the calc
  1515. }
  1516. else
  1517. {
  1518. retval_y = te.origin_y; // adjust line up
  1519.  
  1520. r = vlen(self.origin - retval); // get distance from us (player)
  1521. if (r > 200) // we r too far away?
  1522. retval = place; // then bypass the calc
  1523. }
  1524.  
  1525. // print message if they wont link
  1526. if (!vis2orig(te.origin,retval))
  1527. sprint(self, #PRINT_HIGH, "Your field generators won't link, there are obstacles between them!\n");
  1528.  
  1529. r = vlen(te.origin - retval); // get distance between generators
  1530. if (te.all_active & #IMPROVED_FOUR && r > #FIELDGEN_HACKEDRANGE)
  1531. sprint(self, #PRINT_HIGH, "Your field generators are too far away to link, even hacked\n");
  1532.  
  1533. if (r > #FIELDGEN_RANGE && !(te.all_active & #IMPROVED_FOUR))
  1534. sprint(self, #PRINT_HIGH, "Your field generators are too far away to link\n");
  1535.  
  1536. /*if (retval_z != te.origin_z)
  1537. sprint(self, #PRINT_HIGH, "Your field generators are at different heights, they won't link\n");*/
  1538.  
  1539. if (retval_x != te.origin_x && retval_y != te.origin_y)
  1540. sprint(self, #PRINT_HIGH, "Your field generators are not lined up, they won't link\n");
  1541.  
  1542. // return the final building place
  1543. return retval;
  1544. };
  1545.  
  1546. //======================================================================
  1547. // damn! our field generator was destroyed. Force field must go down..
  1548.  
  1549. void() FieldGen_Die =
  1550. {
  1551. self.real_owner.has_fieldgen = self.real_owner.has_fieldgen - 1;
  1552. if (self.real_owner.has_fieldgen < 0) self.real_owner.has_fieldgen = 0;
  1553.  
  1554. WriteByte (#MSG_BROADCAST, #SVC_TEMPENTITY);
  1555. WriteByte (#MSG_BROADCAST, #TE_EXPLOSION);
  1556. WriteCoord (#MSG_BROADCAST, self.origin_x);
  1557. WriteCoord (#MSG_BROADCAST, self.origin_y);
  1558. WriteCoord (#MSG_BROADCAST, self.origin_z);
  1559. #ifdef QUAKE_WORLD
  1560. multicast (self.origin, #MULTICAST_PHS);
  1561. #endif
  1562.  
  1563. // check if field should be removed..
  1564. local entity othergen;
  1565. othergen = Find_OtherGen(self);
  1566.  
  1567. if (IsValidFieldGen(othergen))
  1568. Remove_Field(self, othergen);
  1569. else
  1570. Remove_Field(self, world); // extra removal, not needed i think...
  1571.  
  1572. sprint(self.real_owner, #PRINT_HIGH, "Your field generator was destroyed.\n");
  1573.  
  1574. local entity sprite;
  1575.  
  1576. sprite = SpawnSprite(1,#SPRITE_AIRBURST,self.origin,'0 0 0',#SPRITEMOVE_UPSLOW,0.1);
  1577.  
  1578. if (sprite)
  1579. {
  1580. sprite.effects = #EF_DIMLIGHT;
  1581.  
  1582. if (self.real_owner.team_no == 1)
  1583. sprite.effects = #EF_DIMLIGHT | #EF_BLUE;
  1584. else if (self.real_owner.team_no == 2)
  1585. sprite.effects = #EF_DIMLIGHT | #EF_RED;
  1586. }
  1587.  
  1588. ThrowGib("progs/tesgib3.mdl", -70,#TRUE,0,0, #FALSE);
  1589.  
  1590. dremove(self);
  1591. };
  1592.  
  1593. //=========================================================================
  1594. // Engineer has used a Spanner on the field generator
  1595.  
  1596. void(entity field) Engineer_UseFieldGen =
  1597. {
  1598. self.building = field;
  1599.  
  1600. if (Teammate(self.building.real_owner.team_no,self.team_no) && self.building.is_malfunctioning & #SCREWUP_THREE)
  1601. {
  1602. sprint(self,#PRINT_HIGH,"Trapped field generator, have a nice day!\n");
  1603.  
  1604. deathmsg = #DMSG_FGTRAP;
  1605. sound (self, #CHAN_MISC, "effects/crunch.wav", 1, #ATTN_NONE);
  1606. TF_T_Damage(self, self, self, self.health + 60, 0, #TF_TD_OTHER);
  1607. return;
  1608. }
  1609.  
  1610. local entity dist_checker;
  1611. local string st;
  1612.  
  1613. sprint(self, #PRINT_HIGH, "Field Generator has ");
  1614. st = ftos(field.health);
  1615. sprint(self, #PRINT_HIGH, st);
  1616. sprint(self, #PRINT_HIGH, "¯");
  1617. st = ftos(field.max_health);
  1618. sprint(self, #PRINT_HIGH, st);
  1619. sprint(self, #PRINT_HIGH, " èåáìôè, ");
  1620. st = ftos(field.ammo_cells);
  1621. sprint(self, #PRINT_HIGH, st);
  1622. sprint(self, #PRINT_HIGH, "¯");
  1623. st = ftos(field.maxammo_cells);
  1624. sprint(self, #PRINT_HIGH, st);
  1625. sprint(self, #PRINT_HIGH, " ãåììó\n");
  1626.  
  1627. // Pop up the menu
  1628. self.current_menu = #MENU_ENGINEER_FIX_FIELDGEN;
  1629. self.menu_count = #MENU_REFRESH_RATE;
  1630.  
  1631. //dodgy
  1632. if (teamplay != 0 && !Teammate(self.building.real_owner.team_no,self.team_no)) {
  1633. Menu_EngineerFix_FieldGen_Input(4);
  1634. return;
  1635. }
  1636.  
  1637. // Start a Distance checker, which removes the menu if the player
  1638. // gets too far away from the field generator.
  1639. dist_checker = spawn();
  1640. dist_checker.classname = "timer";
  1641. dist_checker.owner = self;
  1642. dist_checker.enemy = field;
  1643. dist_checker.think = CheckDistance;
  1644. dist_checker.nextthink = time + 0.3;
  1645. };
  1646.  
  1647. //===========================================================================
  1648. // Any external code should use this function, where needed
  1649.  
  1650. void(entity tfield, vector where, entity thing) FieldEvent =
  1651. {
  1652. FieldExplosion(tfield, where, thing);
  1653. PutFieldWork(tfield);
  1654. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement