]> icculus.org git repositories - divverent/nexuiz.git/blob - attic/TeamNexuiz/game/gamec/tfmapitems.c
moved navnodeedit & TeamNexuiz to attic
[divverent/nexuiz.git] / attic / TeamNexuiz / game / gamec / tfmapitems.c
1 /****************\r
2         XavioR's Team Fortress Map Entities conversion\r
3                                                 ************/\r
4 /*\r
5 // Things needed to be added (probably):\r
6 prematch\r
7 */\r
8 \r
9 // Goal stuff\r
10 \r
11 \r
12 .float if_item_has_moved;\r
13 .float if_item_hasnt_moved;\r
14 .float remove_spawnpoint;\r
15 .float restore_spawnpoint;\r
16 .float remove_spawngroup;\r
17 .float restore_spawngroup;\r
18 .float display_item_status1;\r
19 .float display_item_status2;\r
20 .float display_item_status3;\r
21 .float display_item_status4;\r
22 .string team_str_home;\r
23 .string team_str_moved;\r
24 .string team_str_carried;\r
25 .string non_team_str_home;\r
26 .string non_team_str_moved;\r
27 .string non_team_str_carried;\r
28 .float ex_skill_min;\r
29 .float ex_skill_max;\r
30 .float increase_team1;\r
31 .float increase_team2;\r
32 .float increase_team3;\r
33 .float increase_team4;\r
34 \r
35 \r
36 // Temp defs that need to be moved to TFDefs\r
37 .string broadcast;\r
38 .string team_broadcast;\r
39 .string non_team_broadcast;\r
40 .string owners_team_broadcast;\r
41 .string netname_broadcast;\r
42 .string netname_team_broadcast;\r
43 .string netname_non_team_broadcast;\r
44 .string netname_owners_team_broadcast;\r
45 .string team_drop;\r
46 .string non_team_drop;\r
47 .string netname_team_drop;\r
48 .string netname_non_team_drop;\r
49 string team_menu_string/*    = ""*/;\r
50 .float all_active;\r
51 .float item_list;\r
52 float item_list_bit;\r
53 .float delay_time;\r
54 .float dont_do_triggerwork;\r
55 .float g_a;\r
56 .float g_e;\r
57 .string t_s_h;\r
58 .string t_s_m;\r
59 .string t_s_c;\r
60 .string n_s_h;\r
61 .string n_s_m;\r
62 .string n_s_c;\r
63 .string b_b;\r
64 .string b_t;\r
65 .string b_n;\r
66 .string b_o;\r
67 .string n_b;\r
68 .string n_t;\r
69 .string n_n;\r
70 .string n_o;\r
71 .string d_t;\r
72 .string d_n;\r
73 .string d_n_t;\r
74 .string d_n_n;\r
75 \r
76 // Temp defs that need functions\r
77 float prematch;\r
78 \r
79 \r
80 .float h_i_g, r_i_g, a_s, a_n, a_r, a_c, rv_s_h, rs_s_h, rv_gr, rs_gr, rs_g;\r
81 .float rv_g;\r
82 .vector goal_min, goal_max;\r
83 \r
84 // Prototypes\r
85 // Team Functions\r
86 void(float tno, float scoretoadd) TeamFortress_TeamIncreaseScore;\r
87 void(float all) TeamFortress_TeamShowScores;\r
88 float() TeamFortress_TeamGetWinner;\r
89 \r
90 // Functions to handle entity placement when spawned\r
91 void() TF_PlaceItem;\r
92 void() TF_StartItem;\r
93 void() TF_PlaceGoal;\r
94 void() TF_StartGoal;\r
95 \r
96 // Spawn functions for all Map Entities\r
97 float() CheckExistence;\r
98 void() info_tfdetect;\r
99 void() info_player_teamspawn;\r
100 void() info_tfgoal;\r
101 void() info_tfgoal_timer;\r
102 void() item_tfgoal;\r
103 \r
104 // AutoDetection Function\r
105 void(entity AD) ParseTFDetect;\r
106 \r
107 // Generic Functions\r
108 entity(float ino) Finditem;\r
109 entity(float gno) Findgoal;\r
110 entity(float gno) Findteamspawn;\r
111 void(entity Goal) InactivateGoal;\r
112 void(entity Goal) RestoreGoal;\r
113 void(entity Goal) RemoveGoal;\r
114 float(entity Goal, entity Player, entity AP) IsAffectedBy;\r
115 //void(entity Goal, entity Player, entity AP, float addb) Apply_Results;\r
116 //float(entity Goal, entity AP) APMeetsCriteria;\r
117 void(entity Goal) SetupRespawn;\r
118 void() DoRespawn;\r
119 void(entity Goal, entity AP) DoGoalWork;\r
120 void(entity Goal, entity AP) DoGroupWork;\r
121 void(entity Item, entity AP) DoItemGroupWork;\r
122 void(entity Goal, entity AP) DoTriggerWork;\r
123 void(entity Goal, entity AP, float addb) DoResults;\r
124 //void(entity Goal, entity Player) RemoveResults;\r
125 \r
126 // Goal Functions\r
127 void() tfgoal_touch;\r
128 void() info_tfgoal_use;\r
129 \r
130 // Timer Goal Functions\r
131 void() tfgoal_timer_tick;\r
132 \r
133 // Item Functions\r
134 void() item_tfgoal_touch;\r
135 void(entity Item, entity AP, entity Goal) tfgoalitem_GiveToPlayer;\r
136 void(entity Item, entity AP, float method) tfgoalitem_RemoveFromPlayer;\r
137 void() tfgoalitem_remove;\r
138 void(entity Item) tfgoalitem_drop;\r
139 void(entity Item) tfgoalitem_checkgoalreturn;\r
140 void() ReturnItem;\r
141 void(entity Goal, entity Player, entity Item) DisplayItemStatus;\r
142 \r
143 // CTF Support Functions\r
144 void() CTF_FlagCheck;\r
145 \r
146 \r
147 void () TF_PlaceItem;\r
148 void () TF_StartItem;\r
149 void () TF_PlaceGoal;\r
150 void () TF_StartGoal;\r
151 //void () TF_PlaceCamp;\r
152 //void () TF_StartCamp;\r
153 void () info_tfdetect;\r
154 //void () info_tfnocamp;\r
155 void () info_player_teamspawn;\r
156 void () info_tfgoal;\r
157 void () info_tfgoal_timer;\r
158 void () item_tfgoal;\r
159 entity (float gno) Findgoal;\r
160 entity (float gno) Findteamspawn;\r
161 void (entity Goal) InactivateGoal;\r
162 void (entity Goal) RestoreGoal;\r
163 void (entity Goal) RemoveGoal;\r
164 float (entity Goal,entity Player,entity AP) IsAffectedBy;\r
165 void (entity Goal,entity Player,entity AP,float addb) Apply_Results;\r
166 float (entity Goal,entity AP) APMeetsCriteria;\r
167 void (entity Goal) SetupRespawn;\r
168 void () DoRespawn;\r
169 void (entity Item,entity AP) DoItemGroupWork;\r
170 void (entity Goal,entity AP) DoTriggerWork;\r
171 void (entity Goal,entity Player) RemoveResults;\r
172 void () info_tfgoal_use;\r
173 void () tfgoal_timer_tick;\r
174 void () item_tfgoal_touch;\r
175 void () tfgoalitem_remove;\r
176 void (entity Item) tfgoalitem_drop;\r
177 void (entity Item) tfgoalitem_checkgoalreturn;\r
178 void () ReturnItem;\r
179 \r
180 \r
181 void() MoveFlag = \r
182 {\r
183         if ( (prematch) )// && (self.owner.items & 131072) )\r
184         {\r
185                 T_Damage (self.owner, self.owner, self.owner, 500);\r
186         }\r
187 \r
188         makevectors(self.owner.v_angle);\r
189         setorigin(self, self.owner.origin - v_forward * 25 + '0 0 20');\r
190         self.angles_x = self.owner.angles_z;\r
191         self.angles_y = self.owner.angles_y + 90;\r
192         self.angles_z = 0 - self.owner.angles_x;\r
193         self.nextthink = time + 0.010000;\r
194         self.think = MoveFlag;\r
195         if (self.owner.deadflag)\r
196         {\r
197                 // pablo\r
198                 //self.movetype = 10;\r
199                 //self.velocity = '0 0 100';\r
200                 //\r
201                 self.owner.effects = self.owner.effects - (self.owner.effects & 128);\r
202                 self.owner.effects = self.owner.effects - (self.owner.effects & 64);\r
203                 dremove(self);\r
204         }\r
205         if (!(self.owner.items & 131072) && !(self.owner.items & 262144))\r
206         {\r
207                 self.owner.effects = self.owner.effects - (self.owner.effects & 128);\r
208                 self.owner.effects = self.owner.effects - (self.owner.effects & 64);\r
209                 dremove(self);\r
210         }\r
211 };\r
212 \r
213 void (entity Goal) UpdateAbbreviations =\r
214 {\r
215         if ((Goal.has_abbreviated == 0))\r
216         {\r
217                 if (((Goal.g_a != 0) && (Goal.goal_activation == 0)))\r
218                 {\r
219                         Goal.goal_activation = Goal.g_a;\r
220                 }\r
221                 if (((Goal.g_e != 0) && (Goal.goal_effects == 0)))\r
222                 {\r
223                         Goal.goal_effects = Goal.g_e;\r
224                 }\r
225                 if (((Goal.g_e != 0) && (Goal.goal_effects == 0)))\r
226                 {\r
227                         Goal.goal_effects = Goal.g_e;\r
228                 }\r
229                 if (((Goal.h_i_g != 0) && (Goal.has_item_from_group == 0)))\r
230                 {\r
231                         Goal.has_item_from_group = Goal.h_i_g;\r
232                 }\r
233                 if (((Goal.hn_i_g != 0) && (Goal.hasnt_item_from_group == 0)))\r
234                 {\r
235                         Goal.hasnt_item_from_group = Goal.hn_i_g;\r
236                 }\r
237                 if (((Goal.r_i_g != 0) && (Goal.remove_item_group == 0)))\r
238                 {\r
239                         Goal.remove_item_group = Goal.r_i_g;\r
240                 }\r
241                 if (((Goal.a_s != 0) && (Goal.ammo_shells == 0)))\r
242                 {\r
243                         Goal.ammo_shells = Goal.a_s;\r
244                 }\r
245                 if (((Goal.a_n != 0) && (Goal.ammo_nails == 0)))\r
246                 {\r
247                         Goal.ammo_nails = Goal.a_n;\r
248                 }\r
249                 if (((Goal.a_r != 0) && (Goal.ammo_rockets == 0)))\r
250                 {\r
251                         Goal.ammo_rockets = Goal.a_r;\r
252                 }\r
253                 if (((Goal.a_c != 0) && (Goal.ammo_cells == 0)))\r
254                 {\r
255                         Goal.ammo_cells = Goal.a_c;\r
256                 }\r
257                 if (((Goal.rv_s_h != 0) && (Goal.remove_spawngroup == 0)))\r
258                 {\r
259                         Goal.remove_spawngroup = Goal.rv_s_h;\r
260                 }\r
261                 if (((Goal.rs_s_h != 0) && (Goal.restore_spawngroup == 0)))\r
262                 {\r
263                         Goal.restore_spawngroup = Goal.rs_s_h;\r
264                 }\r
265                 if (((Goal.rv_gr != 0) && (Goal.remove_group_no == 0)))\r
266                 {\r
267                         Goal.remove_group_no = Goal.rv_gr;\r
268                 }\r
269                 if (((Goal.rs_gr != 0) && (Goal.restore_group_no == 0)))\r
270                 {\r
271                         Goal.restore_group_no = Goal.rs_gr;\r
272                 }\r
273                 if (((Goal.rv_g != 0) && (Goal.remove_goal_no == 0)))\r
274                 {\r
275                         Goal.remove_goal_no = Goal.rv_g;\r
276                 }\r
277                 if (((Goal.rs_g != 0) && (Goal.restore_goal_no == 0)))\r
278                 {\r
279                         Goal.restore_goal_no = Goal.rs_g;\r
280                 }\r
281                 if ((Goal.t_s_h != string_null))\r
282                 {\r
283                         Goal.team_str_home = Goal.t_s_h;\r
284                 }\r
285                 if ((Goal.t_s_m != string_null))\r
286                 {\r
287                         Goal.team_str_moved = Goal.t_s_m;\r
288                 }\r
289                 if ((Goal.t_s_c != string_null))\r
290                 {\r
291                         Goal.team_str_carried = Goal.t_s_c;\r
292                 }\r
293                 if ((Goal.n_s_h != string_null))\r
294                 {\r
295                         Goal.non_team_str_home = Goal.n_s_h;\r
296                 }\r
297                 if ((Goal.n_s_m != string_null))\r
298                 {\r
299                         Goal.non_team_str_moved = Goal.n_s_m;\r
300                 }\r
301                 if ((Goal.n_s_c != string_null))\r
302                 {\r
303                         Goal.non_team_str_carried = Goal.n_s_c;\r
304                 }\r
305                 if ((Goal.b_b != string_null))\r
306                 {\r
307                         Goal.broadcast = Goal.b_b;\r
308                 }\r
309                 if ((Goal.b_t != string_null))\r
310                 {\r
311                         Goal.team_broadcast = Goal.b_t;\r
312                 }\r
313                 if ((Goal.b_n != string_null))\r
314                 {\r
315                         Goal.non_team_broadcast = Goal.b_n;\r
316                 }\r
317                 if ((Goal.b_o != string_null))\r
318                 {\r
319                         Goal.owners_team_broadcast = Goal.b_o;\r
320                 }\r
321                 if ((Goal.n_b != string_null))\r
322                 {\r
323                         Goal.netname_broadcast = Goal.n_b;\r
324                 }\r
325                 if ((Goal.n_t != string_null))\r
326                 {\r
327                         Goal.netname_team_broadcast = Goal.n_t;\r
328                 }\r
329                 if ((Goal.n_n != string_null))\r
330                 {\r
331                         Goal.netname_non_team_broadcast = Goal.n_n;\r
332                 }\r
333                 if ((Goal.n_o != string_null))\r
334                 {\r
335                         Goal.netname_owners_team_broadcast = Goal.n_o;\r
336                 }\r
337                 if ((Goal.d_t != string_null))\r
338                 {\r
339                         Goal.team_drop = Goal.d_t;\r
340                 }\r
341                 if ((Goal.d_n != string_null))\r
342                 {\r
343                         Goal.non_team_drop = Goal.d_n;\r
344                 }\r
345                 if ((Goal.d_n_t != string_null))\r
346                 {\r
347                         Goal.netname_team_drop = Goal.d_n_t;\r
348                 }\r
349                 if ((Goal.d_n_n != string_null))\r
350                 {\r
351                         Goal.netname_non_team_drop = Goal.d_n_n;\r
352                 }\r
353                 if ((flagem_checked == 0))\r
354                 {\r
355                         if ((cvar ("temp1") & 4096))\r
356                         {\r
357                                 toggleflags = (toggleflags | 4096);\r
358                         }\r
359                         if ((cvar ("temp1") & 8192))\r
360                         {\r
361                                 toggleflags = (toggleflags | 8192);\r
362                         }\r
363                         flagem_checked = 1;\r
364                 }\r
365                 if (((toggleflags & 4096) && !(toggleflags & 8192)))\r
366                 {\r
367                         if ((((Goal.mdl == "progs/b_s_key.mdl") || (Goal.mdl == "progs/m_s_key.mdl")) || (Goal.mdl == "progs/w_s_key.mdl")))\r
368                         {\r
369                                 Goal.mdl = "progs/tf_flag.mdl";\r
370                                 Goal.skin = 1;\r
371                         }\r
372                         else\r
373                         {\r
374                                 if ((((Goal.mdl == "progs/b_g_key.mdl") || (Goal.mdl == "progs/m_g_key.mdl")) || (Goal.mdl == "progs/w_g_key.mdl")))\r
375                                 {\r
376                                         Goal.mdl = "progs/tf_flag.mdl";\r
377                                         Goal.skin = 2;\r
378                                 }\r
379                         }\r
380                 }\r
381                 if ((toggleflags & 8192))\r
382                 {\r
383                         if ((((Goal.mdl == "progs/b_s_key.mdl") || (Goal.mdl == "progs/m_s_key.mdl")) || (Goal.mdl == "progs/w_s_key.mdl")))\r
384                         {\r
385                                 Goal.mdl = "progs/tf_stan.mdl";\r
386                                 Goal.skin = 1;\r
387                         }\r
388                         else\r
389                         {\r
390                                 if ((((Goal.mdl == "progs/b_g_key.mdl") || (Goal.mdl == "progs/m_g_key.mdl")) || (Goal.mdl == "progs/w_g_key.mdl")))\r
391                                 {\r
392                                         Goal.mdl = "progs/tf_stan.mdl";\r
393                                         Goal.skin = 2;\r
394                                 }\r
395                                 else\r
396                                 {\r
397                                         if ((Goal.mdl == "progs/tf_flag.mdl"))\r
398                                         {\r
399                                                 Goal.mdl = "progs/tf_stan.mdl";\r
400                                         }\r
401                                 }\r
402                         }\r
403                 }\r
404                 Goal.has_abbreviated = 1;\r
405         }\r
406 };\r
407 \r
408 void () TF_PlaceItem =\r
409 {\r
410         self.flags = 256.000000;\r
411         self.movetype = 0.000000;\r
412         self.velocity = '0.000000 0.000000 0.000000';\r
413         self.oldorigin = self.origin;\r
414         if ((self.goal_activation & 512.000000))\r
415         {\r
416                 self.effects = (self.effects | 8.000000);\r
417         }\r
418         if ((item_list_bit == 0.000000))\r
419         {\r
420                 item_list_bit = 1.000000;\r
421         }\r
422         self.item_list = item_list_bit;\r
423         item_list_bit = item_list_bit * 2.000000;\r
424 };\r
425 \r
426 void () TF_StartItem =\r
427 {\r
428 \r
429         UpdateAbbreviations (self);\r
430         self.nextthink = (time + 0.200000);\r
431         self.think = TF_PlaceItem;\r
432         if ((self.goal_state == 3.000000))\r
433         {\r
434                 RemoveGoal (self);\r
435         }\r
436 };\r
437 \r
438 void () TF_PlaceGoal =\r
439 {\r
440         if ((self.classname != "info_tfgoal_timer"))\r
441         {\r
442                 if ((self.goal_activation & 1.000000))\r
443                 {\r
444                         self.touch = tfgoal_touch;\r
445                 }\r
446         }\r
447         else\r
448         {\r
449                 self.think = tfgoal_timer_tick;\r
450                 self.nextthink = (time + self.search_time);\r
451                 self.classname = "info_tfgoal";\r
452         }\r
453         self.flags = 256.000000;\r
454         self.movetype = 0.000000;\r
455         self.velocity = '0.000000 0.000000 0.000000';\r
456         self.oldorigin = self.origin;\r
457 };\r
458 \r
459 void () TF_StartGoal =\r
460 {\r
461 \r
462         UpdateAbbreviations (self);\r
463         self.nextthink = (time + 0.200000);\r
464         self.think = TF_PlaceGoal;\r
465         self.use = info_tfgoal_use;\r
466         if ((self.goal_state == 3.000000))\r
467         {\r
468                 RemoveGoal (self);\r
469         }\r
470 };\r
471 \r
472 float() CheckExistence =\r
473 {\r
474 \r
475         UpdateAbbreviations (self);\r
476         if ((self.ex_skill_min && (skill <= self.ex_skill_min)))\r
477         {\r
478                 return (0.000000);\r
479         }\r
480         else\r
481         {\r
482                 if ((self.ex_skill_max && (skill >= self.ex_skill_max)))\r
483                 {\r
484                         return (0.000000);\r
485                 }\r
486         }\r
487         return (1.000000);\r
488 };\r
489 \r
490 /*                                                      // ORIG NETQUAKETF INFO_TFDETECT\r
491 void () info_tfdetect =\r
492 {\r
493         UpdateAbbreviations (self);\r
494 };\r
495 */\r
496 \r
497 /*void () info_tfdetect = \r
498 {\r
499    local entity te;\r
500    local string st;\r
501 \r
502    UpdateAbbreviations (self);\r
503 \r
504    //TIMELEFT TIMER\r
505    te = find (world,classname,"countdown");\r
506    if (te != world) \r
507    { \r
508            return;\r
509    }\r
510 \r
511    st = infokey (world,"time"); // Unfortunately DP Engine doesnt support this (qw funct)\r
512    if (st == "off")\r
513    {\r
514            return;\r
515    }\r
516    newmis = spawn ();\r
517    newmis.classname = "countdown";\r
518    newmis.no_grenades_1 = 0;\r
519    st = infokey (world,"timelimit");\r
520    newmis.health = stof(st);\r
521    newmis.think = review_timeleft;\r
522    newmis.nextthink = (time + 1);\r
523 \r
524 \r
525 // MESSAGE DISP CODE\r
526         if (haltloop1 != 1) \r
527         {\r
528                 local string msg1timer;\r
529 \r
530                 msg1timer = infokey (world, "svmsg1");\r
531                 msg1time = stof(msg1timer);\r
532 \r
533                 if (msg1time > 0)\r
534                 {\r
535                         display_message ();\r
536                 }\r
537                 haltloop1 = 1;\r
538         }\r
539 \r
540         if (haltloop2 != 1)\r
541         {\r
542                 local string msg2timer;\r
543 \r
544                 msg2timer = infokey (world, "svmsg2");\r
545                 msg2time = stof(msg2timer);\r
546 \r
547                 if (msg2time > 0)\r
548                 {\r
549                         pre_messagetimer2 ();\r
550                 }\r
551                 haltloop2 = 1;\r
552         }\r
553 \r
554         if (haltloop3 != 1)\r
555         {\r
556                 local string msg3timer;\r
557 \r
558                 msg3timer = infokey (world, "svmsg3");\r
559                 msg3time = stof(msg3timer);\r
560 \r
561                 if (msg3time > 0)\r
562                 {\r
563                         pre_messagetimer3 ();\r
564                 }\r
565                 haltloop3 = 1;\r
566         }\r
567         if (quotestart != 1) {\r
568         quotetimer ();\r
569         quotestart = 1;\r
570         }\r
571 // Auto Level-change fix\r
572 };*/\r
573 \r
574 /* Gold.  this is the old info_tfdetect... new one is above*/\r
575 void() info_tfdetect = \r
576 {\r
577         UpdateAbbreviations(self);\r
578         /*gold. next 6 lines are part of plexi's code for the "timeleft" command.\r
579         newmis = spawn ();\r
580         newmis.classname = "countdown";\r
581         newmis.netname = "countdown";\r
582         newmis.no_grenades_1 = 0;\r
583         newmis.think = review_timeleft;\r
584         newmis.nextthink = (time + 1);*/\r
585 };\r
586 \r
587 void() info_player_teamspawn = \r
588 {\r
589         local entity te;\r
590         if (CheckExistence() == 0)\r
591         {\r
592                 dremove(self);\r
593                 return;\r
594         }\r
595         if (number_of_teams < self.team_no)\r
596         {\r
597                 number_of_teams = self.team_no;\r
598         }\r
599         if (self.team_no <= 0)\r
600         {\r
601                 dprint("no team_no associated with info_player_teamspawn\n");\r
602                 dremove(self);\r
603         }\r
604         if (self.items != 0)\r
605         {\r
606                 te = Finditem(self.items);\r
607                 if (!te)\r
608                 {\r
609                         dprint("info_player_teamspawn specifies a GoalItem that does not exist\n");\r
610                         dremove(self);\r
611                 }\r
612         }\r
613         if (self.team_no == 1)\r
614         {\r
615                 self.team_str_home = "ts1";\r
616         }\r
617         else\r
618         {\r
619                 if (self.team_no == 2)\r
620                 {\r
621                         self.team_str_home = "ts2";\r
622                 }\r
623                 else\r
624                 {\r
625                         if (self.team_no == 3)\r
626                         {\r
627                                 self.team_str_home = "ts3";\r
628                         }\r
629                         else\r
630                         {\r
631                                 if (self.team_no == 4)\r
632                                 {\r
633                                         self.team_str_home = "ts4";\r
634                                 }\r
635                         }\r
636                 }\r
637         }\r
638 };\r
639 \r
640 void() i_p_t = \r
641 {\r
642         self.classname = "info_player_teamspawn";\r
643         info_player_teamspawn();\r
644 };\r
645 \r
646 void() info_tfgoal = \r
647 {\r
648         if (CheckExistence() == 0)\r
649         {\r
650                 dremove(self);\r
651                 return;\r
652         }\r
653         if (self.mdl)\r
654         {\r
655                 precache_model(self.mdl);\r
656                 precache_model2(self.mdl);\r
657                 setmodel(self, self.mdl);\r
658         }\r
659         if (self.noise)\r
660         {\r
661                 precache_sound(self.noise);\r
662                 precache_sound2(self.noise);\r
663         }\r
664         else\r
665         {\r
666                 if (self.mdl == "progs/backpack.mdl")\r
667                 {\r
668                         precache_sound("items/backpack.wav");\r
669                         precache_sound2("items/backpack.wav");\r
670                         self.noise = "items/backpack.wav";\r
671                 }\r
672         }\r
673         precache_sound("items/protect.wav");\r
674         precache_sound("items/protect2.wav");\r
675         precache_sound("items/protect3.wav");\r
676         precache_sound("items/suit.wav");\r
677         precache_sound("items/suit2.wav");\r
678         precache_sound("items/inv1.wav");\r
679         precache_sound("items/inv2.wav");\r
680         precache_sound("items/inv3.wav");\r
681         precache_sound("items/damage.wav");\r
682         precache_sound("items/damage2.wav");\r
683         precache_sound("items/damage3.wav");\r
684         self.solid = 1;\r
685         if (self.goal_state == 0)\r
686         {\r
687                 self.goal_state = 2;\r
688         }\r
689         if (self.goal_min != '0 0 0')\r
690         {\r
691                 setsize(self, self.goal_min, self.goal_max);\r
692         }\r
693         else\r
694         {\r
695                 setsize(self, '-16 -16 -24', '16 16 32');\r
696         }\r
697         TF_StartGoal();\r
698 };\r
699 \r
700 void() i_t_g = \r
701 {\r
702         self.classname = "info_tfgoal";\r
703         info_tfgoal();\r
704 };\r
705 \r
706 void() info_tfgoal_timer = \r
707 {\r
708         if (CheckExistence() == 0)\r
709         {\r
710                 dremove(self);\r
711                 return;\r
712         }\r
713         if (self.mdl)\r
714         {\r
715                 precache_model(self.mdl);\r
716                 precache_model2(self.mdl);\r
717                 setmodel(self, self.mdl);\r
718         }\r
719         if (self.noise)\r
720         {\r
721                 precache_sound(self.noise);\r
722                 precache_sound2(self.noise);\r
723         }\r
724         if (self.search_time <= 0)\r
725         {\r
726                 dprint("Timer Goal created with no specified time.\n");\r
727                 dremove(self);\r
728         }\r
729         self.solid = 0;\r
730         if (self.goal_state == 0)\r
731         {\r
732                 self.goal_state = 2;\r
733         }\r
734         setsize(self, '-16 -16 -24', '16 16 32');\r
735         TF_StartGoal();\r
736 };\r
737 \r
738 void() i_t_t = \r
739 {\r
740         self.classname = "info_tfgoal_timer";\r
741         info_tfgoal_timer();\r
742 };\r
743 \r
744 void() item_tfgoal = \r
745 {\r
746         if (CheckExistence() == 0)\r
747         {\r
748                 dremove(self);\r
749                 return;\r
750         }\r
751         if (self.mdl)\r
752         {\r
753                 precache_model(self.mdl);\r
754                 precache_model2(self.mdl);\r
755                 setmodel(self, self.mdl);\r
756         }\r
757         else\r
758         {\r
759                 self.mdl = "";\r
760                 setmodel(self, "");\r
761         }\r
762         precache_sound2("items/itembk2.wav");\r
763         if (self.noise)\r
764         {\r
765                 precache_sound(self.noise);\r
766                 precache_sound2(self.noise);\r
767         }\r
768         self.touch = item_tfgoal_touch;\r
769         if (self.goal_state == 0)\r
770         {\r
771                 self.goal_state = 2;\r
772         }\r
773         self.solid = 1;\r
774         setorigin(self, self.origin);\r
775         if (!(self.netname))\r
776         {\r
777                 self.netname = "goalitem";\r
778         }\r
779         if (self.pausetime <= 0)\r
780         {\r
781                 self.pausetime = 60;\r
782         }\r
783         if (self.delay != 0 && self.pausetime == 0)\r
784         {\r
785                 self.pausetime = self.delay;\r
786         }\r
787         setsize(self, '-16 -16 -24', '16 16 32');\r
788         TF_StartItem();\r
789 };\r
790 \r
791 void (entity AD) ParseTFDetect =\r
792 {\r
793         if ((AD.team_broadcast != string_null))\r
794         {\r
795                 team_menu_string = AD.team_broadcast;\r
796         }\r
797         localcmd (AD.message);\r
798         cvar_set ("sv_maxspeed", "500");\r
799         team1lives = AD.ammo_shells;\r
800         team2lives = AD.ammo_nails;\r
801         team3lives = AD.ammo_rockets;\r
802         team4lives = AD.ammo_cells;\r
803         if ((team1lives == 0))\r
804         {\r
805                 team1lives = -1;\r
806         }\r
807         if ((team2lives == 0))\r
808         {\r
809                 team2lives = -1;\r
810         }\r
811         if ((team3lives == 0))\r
812         {\r
813                 team3lives = -1;\r
814         }\r
815         if ((team4lives == 0))\r
816         {\r
817                 team4lives = -1;\r
818         }\r
819         /*if ((AD.hook_out == 1))               // Hook always allowed, right?\r
820         {\r
821                 allow_hook = 0;\r
822         }*/\r
823         team1maxplayers = AD.ammo_medikit;\r
824         team2maxplayers = AD.ammo_detpack;\r
825         team3maxplayers = AD.maxammo_medikit;\r
826         team4maxplayers = AD.maxammo_detpack;\r
827         if ((team1maxplayers == 0))\r
828         {\r
829                 team1maxplayers = 100;\r
830         }\r
831         if ((team2maxplayers == 0))\r
832         {\r
833                 team2maxplayers = 100;\r
834         }\r
835         if ((team3maxplayers == 0))\r
836         {\r
837                 team3maxplayers = 100;\r
838         }\r
839         if ((team4maxplayers == 0))\r
840         {\r
841                 team4maxplayers = 100;\r
842         }\r
843         illegalclasses = AD.playerclass;\r
844 //      illegalclasses = AD.class;\r
845         illegalclasses1 = AD.maxammo_shells;\r
846         illegalclasses2 = AD.maxammo_nails;\r
847         illegalclasses3 = AD.maxammo_rockets;\r
848         illegalclasses4 = AD.maxammo_cells;\r
849         civilianteams = 0;\r
850         if ((illegalclasses1 == -1))\r
851         {\r
852                 illegalclasses1 = 0;\r
853                 civilianteams = (civilianteams | 1);\r
854         }\r
855         if ((illegalclasses2 == -1))\r
856         {\r
857                 illegalclasses2 = 0;\r
858                 civilianteams = (civilianteams | 2);\r
859         }\r
860         if ((illegalclasses3 == -1))\r
861         {\r
862                 illegalclasses3 = 0;\r
863                 civilianteams = (civilianteams | 4);\r
864         }\r
865         if ((illegalclasses4 == -1))\r
866         {\r
867                 illegalclasses4 = 0;\r
868                 civilianteams = (civilianteams | 8);\r
869         }\r
870 };\r
871 \r
872 entity(float ino) Finditem = \r
873 {\r
874         local entity tg;\r
875         local string st;\r
876         tg = find(world, classname, "item_tfgoal");\r
877         while (tg)\r
878         {\r
879                 if (tg.goal_no == ino)\r
880                 {\r
881                         return tg;\r
882                 }\r
883                 tg = find(tg, classname, "item_tfgoal");\r
884         }\r
885         dprint("Could not find an item with a goal_no of ");\r
886         st = ftos(ino);\r
887         dprint(st);\r
888         dprint(".\n");\r
889         return world;\r
890 };\r
891 \r
892 /*entity(float gno) Findgoal =          // moved to tffunctions\r
893 {\r
894         local entity tg;\r
895         local string st;\r
896         tg = find(world, classname, "info_tfgoal");\r
897         while (tg)\r
898         {\r
899                 if (tg.goal_no == gno)\r
900                 {\r
901                         return tg;\r
902                 }\r
903                 tg = find(tg, classname, "info_tfgoal");\r
904         }\r
905         dprint("Could not find a goal with a goal_no of ");\r
906         st = ftos(gno);\r
907         dprint(st);\r
908         dprint(".\n");\r
909 };*/\r
910 \r
911 entity(float gno) Findteamspawn = \r
912 {\r
913         local entity tg;\r
914         local string st;\r
915         tg = find(world, classname, "info_player_teamspawn");\r
916         while (tg)\r
917         {\r
918                 if (tg.goal_no == gno)\r
919                 {\r
920                         return tg;\r
921                 }\r
922                 tg = find(tg, classname, "info_player_teamspawn");\r
923         }\r
924         dprint("Could not find a Teamspawn with a goal_no of ");\r
925         st = ftos(gno);\r
926         dprint(st);\r
927         dprint(".\n");\r
928 };\r
929 \r
930 void(entity Goal) InactivateGoal = \r
931 {\r
932         if (Goal.goal_state == 1)\r
933         {\r
934                 if (Goal.search_time == 0)\r
935                 {\r
936                         Goal.solid = 1;\r
937                 }\r
938                 Goal.goal_state = 2;\r
939                 if (Goal.mdl != string_null)\r
940                 {\r
941                         setmodel(Goal, Goal.mdl);\r
942                 }\r
943         }\r
944 };\r
945 \r
946 void(entity Goal) RestoreGoal = \r
947 {\r
948         if (Goal.goal_state == 3)\r
949         {\r
950                 if (Goal.search_time == 0)\r
951                 {\r
952                         Goal.solid = 1;\r
953                 }\r
954                 else\r
955                 {\r
956                         Goal.nextthink = time + Goal.search_time;\r
957                 }\r
958                 Goal.goal_state = 2;\r
959                 if (Goal.mdl != string_null)\r
960                 {\r
961                         setmodel(Goal, Goal.mdl);\r
962                 }\r
963         }\r
964 };\r
965 \r
966 void(entity Goal) RemoveGoal = \r
967 {\r
968         Goal.solid = 0;\r
969         Goal.goal_state = 3;\r
970         if (Goal.mdl != string_null)\r
971         {\r
972                 setmodel(Goal, string_null);\r
973         }\r
974 };\r
975 \r
976 float(entity Goal, entity Player, entity AP) IsAffectedBy = \r
977 {\r
978         local float genv;\r
979         //if (Player.playerclass == 0)\r
980         if (Player.class == 0)\r
981         {\r
982                 return 0;\r
983         }\r
984         if (Goal.goal_effects & 32)\r
985         {\r
986                 genv = pointcontents(Goal.origin);\r
987                 if (pointcontents(Player.origin) != genv)\r
988                 {\r
989                         return 0;\r
990                 }\r
991         }\r
992         if (Goal.t_length != 0)\r
993         {\r
994                 if (vlen(Goal.origin - Player.origin) <= Goal.t_length)\r
995                 {\r
996                         if (Goal.goal_effects & 16)\r
997                         {\r
998                                 traceline(Goal.origin, Player.origin, 1, Goal);\r
999                                 if (trace_fraction == 1)\r
1000                                 {\r
1001                                         return 1;\r
1002                                 }\r
1003                         }\r
1004                         else\r
1005                         {\r
1006                                 return 1;\r
1007                         }\r
1008                 }\r
1009         }\r
1010         if (Goal.classname != "info_tfgoal_timer")\r
1011         {\r
1012                 if (Goal.goal_effects & 1 && Player == AP)\r
1013                 {\r
1014                         return 1;\r
1015                 }\r
1016                 if (Goal.goal_effects & 2 && AP.team_no == Player.team_no)\r
1017                 {\r
1018                         return 1;\r
1019                 }\r
1020                 if (Goal.goal_effects & 4 && AP.team_no != Player.team_no)\r
1021                 {\r
1022                         return 1;\r
1023                 }\r
1024                 if (Goal.goal_effects & 8 && Player != AP)\r
1025                 {\r
1026                         return 1;\r
1027                 }\r
1028         }\r
1029         if (Goal.maxammo_shells != 0 && Player.team_no == Goal.maxammo_shells)\r
1030         {\r
1031                 return 1;\r
1032         }\r
1033         if (Goal.maxammo_nails != 0 && Player.team_no != Goal.maxammo_shells)\r
1034         {\r
1035                 return 1;\r
1036         }\r
1037         return 0;\r
1038 };\r
1039 \r
1040 void(entity Goal, entity Player, entity AP, float addb) Apply_Results = \r
1041 {\r
1042         local entity oldself;\r
1043         local entity te;\r
1044         local entity oldte;\r
1045         local float oa;\r
1046         stuffcmd(Player, "bf\n");\r
1047         if (Goal.classname == "item_tfgoal")\r
1048         {\r
1049                 Player.item_list = Player.item_list | Goal.item_list;\r
1050         }\r
1051         if (Player == AP)\r
1052         {\r
1053                 if (Goal.count != 0)\r
1054                 {\r
1055                         if (Player.team_no > 0)\r
1056                         {\r
1057                                 TeamFortress_TeamIncreaseScore(Player.team_no, Goal.count);\r
1058                                 TeamFortress_TeamShowScores(2);\r
1059                         }\r
1060                 }\r
1061         }\r
1062         if (addb)\r
1063         {\r
1064                 if (Player.health > 0)\r
1065                 {\r
1066                         if (Goal.health > 0)\r
1067                         {\r
1068                                 T_Heal(Player, Goal.health, 0);\r
1069                         }\r
1070                         if (Goal.health < 0)\r
1071                         {\r
1072                                 if (0 - Player.health > Goal.health)\r
1073                                 {\r
1074                                         Player.armorvalue = 0;\r
1075                                         T_Damage(Player, Goal, Goal, Player.health + 1);\r
1076                                 }\r
1077                                 else\r
1078                                 {\r
1079                                         oa = Player.armorvalue;\r
1080                                         Player.armorvalue = 0;\r
1081                                         T_Damage(Player, Goal, Goal, 0 - Goal.health);\r
1082                                         Player.armorvalue = oa;\r
1083                                 }\r
1084                         }\r
1085                 }\r
1086                 if (Player.health > 0)\r
1087                 {\r
1088                         if (Goal.armortype)\r
1089                         {\r
1090                                                                                                                 // Temp (i hope)\r
1091 //                              Player.armortype = Goal.armortype;              // Armor type needs to be tweaked in this game\r
1092                         }\r
1093                         Player.armorvalue = Player.armorvalue + Goal.armorvalue;\r
1094                         if (Goal.armorclass)\r
1095                         {\r
1096                                 Player.armorclass = Goal.armorclass;\r
1097                         }\r
1098                         if (Goal.gravity > 0)\r
1099                         {\r
1100                                 Player.gravity = Goal.gravity;\r
1101                         }\r
1102                         Player.ammo_shells = Player.ammo_shells + Goal.ammo_shells;\r
1103                         Player.ammo_nails = Player.ammo_nails + Goal.ammo_nails;\r
1104                         Player.ammo_rockets = Player.ammo_rockets + Goal.ammo_rockets;\r
1105                         Player.ammo_cells = Player.ammo_cells + Goal.ammo_cells;\r
1106                         Player.ammo_metal = Player.ammo_metal + Goal.ammo_metal;                // give metal\r
1107                         Player.ammo_medikit = Player.ammo_medikit + Goal.ammo_medikit;\r
1108                         Player.ammo_detpack = Player.ammo_detpack + Goal.ammo_detpack;\r
1109                         Player.no_grenades_1 = Player.no_grenades_1 + Goal.no_grenades_1;\r
1110                         Player.no_grenades_2 = Player.no_grenades_2 + Goal.no_grenades_2;\r
1111                         if (Player.no_grenades_1 > 4)\r
1112                         {\r
1113                                 Player.no_grenades_1 = 4;\r
1114                         }\r
1115                         if (Player.no_grenades_2 > 4)\r
1116                         {\r
1117                                 Player.no_grenades_2 = 4;\r
1118                         }\r
1119                         if (Player.ammo_detpack > Player.maxammo_detpack)\r
1120                         {\r
1121                                 Player.ammo_detpack = Player.maxammo_detpack;\r
1122                         }\r
1123                         if (Goal.invincible_finished > 0)\r
1124                         {\r
1125                                 Player.items = Player.items | 1048576;\r
1126                                 Player.invincible_time = 1;\r
1127                                 Player.invincible_finished = time + Goal.invincible_finished;\r
1128                                 if (Goal.classname == "item_tfgoal")\r
1129                                 {\r
1130                                         Player.tfstate = Player.tfstate | 32;\r
1131                                         Player.invincible_finished = time + 666;\r
1132                                 }\r
1133                         }\r
1134                         /*if (Goal.invisible_finished > 0)              // NexTF doesnt support invisibility?\r
1135                         {\r
1136                                 Player.items = Player.items | 524288;\r
1137                                 Player.invisible_time = 1;\r
1138                                 Player.invisible_finished = time + Goal.invisible_finished;\r
1139                                 if (Goal.classname == "item_tfgoal")\r
1140                                 {\r
1141                                         Player.tfstate = Player.tfstate | 64;\r
1142                                         Player.invisible_finished = time + 666;\r
1143                                 }\r
1144                         }*/\r
1145                         if (Goal.super_damage_finished > 0)\r
1146                         {\r
1147                                 Player.items = Player.items | 4194304;\r
1148                                 Player.super_time = 1;\r
1149                                 Player.super_damage_finished = time + Goal.super_damage_finished;\r
1150                                 if (Goal.classname == "item_tfgoal")\r
1151                                 {\r
1152                                         Player.tfstate = Player.tfstate | 128;\r
1153                                         Player.super_damage_finished = time + 666;\r
1154                                 }\r
1155                         }\r
1156                         if (Goal.radsuit_finished > 0)\r
1157                         {\r
1158                                 Player.items = Player.items | 2097152;\r
1159                                 Player.rad_time = 1;\r
1160                                 Player.radsuit_finished = time + Goal.radsuit_finished;\r
1161                                 if (Goal.classname == "item_tfgoal")\r
1162                                 {\r
1163                                         Player.tfstate = Player.tfstate | 256;\r
1164                                         Player.radsuit_finished = time + 666;\r
1165                                 }\r
1166                         }\r
1167                 }\r
1168                 Player.lives = Player.lives + Goal.lives;\r
1169                 Player.real_frags = /*Player.real_frags + */Goal.frags + Player.frags; // Fixed?\r
1170                 if (!(toggleflags & 128))\r
1171                 {\r
1172                         Player.frags = Player.real_frags;\r
1173                 }\r
1174                 \r
1175                 oldself = self;\r
1176                 self = Player;\r
1177                 TeamFortress_CheckClassStats();\r
1178                 //W_SetCurrentAmmo();           // This is automatic in nexuiz right?\r
1179                 self = oldself;\r
1180         }\r
1181         //if (Player.playerclass == 8 && (Goal.goal_result & 16)) // In nextf, spy class is "2"\r
1182         if (Player.class == CLASS_SPY && (Goal.goal_result & 16))\r
1183         {\r
1184                 self.immune_to_check = time + 4;\r
1185                 //Spy_RemoveDisguise(Player);           // Wazat -- help [incomplete]\r
1186         }\r
1187         if (Goal.items != 0 && Goal.classname != "item_tfgoal")\r
1188         {\r
1189                 te = Finditem(Goal.items);\r
1190                 if (te)\r
1191                 {\r
1192                         tfgoalitem_GiveToPlayer(te, Player, Goal);\r
1193                 }\r
1194         }\r
1195         if (Goal.axhitme != 0)\r
1196         {\r
1197                 te = Finditem(Goal.axhitme);\r
1198                 if (te.owner == Player)\r
1199                 {\r
1200                         tfgoalitem_RemoveFromPlayer(te, Player, 1);\r
1201                 }\r
1202         }\r
1203         if (Goal.remove_item_group != 0)\r
1204         {\r
1205                 te = find(world, classname, "item_tfgoal");\r
1206                 while (te)\r
1207                 {\r
1208                         if (te.group_no == Goal.remove_item_group && te.owner == AP)\r
1209                         {\r
1210                                 oldte = te;\r
1211                                 te = find(te, classname, "item_tfgoal");\r
1212                                 tfgoalitem_RemoveFromPlayer(oldte, Player, 1);\r
1213                         }\r
1214                         else\r
1215                         {\r
1216                                 te = find(te, classname, "item_tfgoal");\r
1217                         }\r
1218                 }\r
1219         }\r
1220         if (Goal.display_item_status1 != 0)\r
1221         {\r
1222                 te = Finditem(Goal.display_item_status1);\r
1223                 if (te)\r
1224                 {\r
1225                         DisplayItemStatus(Goal, Player, te);\r
1226                 }\r
1227                 else\r
1228                 {\r
1229                         sprint(Player,"Item is missing.\n");\r
1230                 }\r
1231         }\r
1232         if (Goal.display_item_status2 != 0)\r
1233         {\r
1234                 te = Finditem(Goal.display_item_status2);\r
1235                 if (te)\r
1236                 {\r
1237                         DisplayItemStatus(Goal, Player, te);\r
1238                 }\r
1239                 else\r
1240                 {\r
1241                         sprint(Player,"Item is missing.\n");\r
1242                 }\r
1243         }\r
1244         if (Goal.display_item_status3 != 0)\r
1245         {\r
1246                 te = Finditem(Goal.display_item_status3);\r
1247                 if (te)\r
1248                 {\r
1249                         DisplayItemStatus(Goal, Player, te);\r
1250                 }\r
1251                 else\r
1252                 {\r
1253                         sprint(Player,"Item is missing.\n");\r
1254                 }\r
1255         }\r
1256         if (Goal.display_item_status4 != 0)\r
1257         {\r
1258                 te = Finditem(Goal.display_item_status4);\r
1259                 if (te)\r
1260                 {\r
1261                         DisplayItemStatus(Goal, Player, te);\r
1262                 }\r
1263                 else\r
1264                 {\r
1265                         sprint(Player,"Item is missing.\n");\r
1266                 }\r
1267         }\r
1268         // New Team:Nexuiz function: "switch_teams" property -- switches all team-related objects to the opposite\r
1269         //      team (ie self.team_no equal to "1" is now equal to "2" and vise verse). It will not switch team items\r
1270         //      which have a "no_switch_team" property set.\r
1271         if (Goal.switch_teams)\r
1272         {\r
1273                 local entity t_ent;\r
1274 \r
1275                 t_ent = find (world,classname,"item_tfgoal");\r
1276                 while (t_ent)\r
1277                 {\r
1278                         if (t_ent.team_no && !t_ent.no_switch_team)\r
1279                         {\r
1280                                 if (t_ent.team_no == 1)\r
1281                                         t_ent.team_no = 2;\r
1282                                 if (t_ent.team_no == 2)\r
1283                                         t_ent.team_no = 1;\r
1284                         }\r
1285                         t_ent = find (t_ent, classname, "item_tfgoal");\r
1286                 }\r
1287                 t_ent = find (world,classname,"info_tfgoal");\r
1288                 while (t_ent)\r
1289                 {\r
1290                         if (t_ent.team_no && !t_ent.no_switch_team)\r
1291                         {\r
1292                                 if (t_ent.team_no == 1)\r
1293                                         t_ent.team_no = 2;\r
1294                                 if (t_ent.team_no == 2)\r
1295                                         t_ent.team_no = 1;\r
1296                         }\r
1297                         t_ent = find (t_ent, classname, "info_tfgoal");\r
1298                 }\r
1299                 t_ent = find (world,classname,"func_door");\r
1300                 while (t_ent)\r
1301                 {\r
1302                         if (t_ent.team_no && !t_ent.no_switch_team)\r
1303                         {\r
1304                                 if (t_ent.team_no == 1)\r
1305                                         t_ent.team_no = 2;\r
1306                                 if (t_ent.team_no == 2)\r
1307                                         t_ent.team_no = 1;\r
1308                         }\r
1309                         t_ent = find (t_ent, classname, "func_door");\r
1310                 }\r
1311                 t_ent = find (world,classname,"trigger_hurt");\r
1312                 while (t_ent)\r
1313                 {\r
1314                         if (t_ent.team_no && !t_ent.no_switch_team)\r
1315                         {\r
1316                                 if (t_ent.team_no == 1)\r
1317                                         t_ent.team_no = 2;\r
1318                                 if (t_ent.team_no == 2)\r
1319                                         t_ent.team_no = 1;\r
1320                         }\r
1321                         t_ent = find (t_ent, classname, "trigger_hurt");\r
1322                 }\r
1323                 t_ent = find (world,classname,"trigger_multiple");\r
1324                 while (t_ent)\r
1325                 {\r
1326                         if (t_ent.team_no && !t_ent.no_switch_team)\r
1327                         {\r
1328                                 if (t_ent.team_no == 1)\r
1329                                         t_ent.team_no = 2;t_ent.owned_by = 2;\r
1330                                 if (t_ent.team_no == 2)\r
1331                                         t_ent.team_no = 1;\r
1332                         }\r
1333                         t_ent = find (t_ent, classname, "trigger_multiple");\r
1334                 }\r
1335         }\r
1336         /*if (Player.autodiscard)               //Not a function in NexTF\r
1337         {\r
1338                 oldself = self;\r
1339                 self = Player;\r
1340                 TeamFortress_Discard ();\r
1341                 self = oldself;\r
1342         }*/\r
1343 };\r
1344 \r
1345 void(entity Goal, entity Player) RemoveResults = \r
1346 {\r
1347         local entity oldself;\r
1348         local entity te;\r
1349         local float puinvin;\r
1350         local float puinvis;\r
1351         local float puquad;\r
1352         local float purad;\r
1353         if (Goal.classname == "item_tfgoal")\r
1354         {\r
1355                 if (!(Player.item_list & Goal.item_list))\r
1356                 {\r
1357                         return;\r
1358                 }\r
1359                 if (Goal.goal_activation & 1024)\r
1360                 {\r
1361                         return;\r
1362                 }\r
1363                 Player.item_list = Player.item_list - (Player.item_list & Goal.item_list);\r
1364         }\r
1365         if (Goal.health > 0)\r
1366         {\r
1367                 TF_T_Damage(Player, Goal, Goal, Goal.health, 1, 0);\r
1368         }\r
1369         if (Goal.health < 0)\r
1370         {\r
1371                 T_Heal(Player, 0 - Goal.health, 0);\r
1372         }\r
1373         Player.lives = Player.lives - Goal.lives;\r
1374         Player.armortype = Player.armortype - Goal.armortype;\r
1375         Player.armorvalue = Player.armorvalue - Goal.armorvalue;\r
1376         Player.armorclass = Player.armorclass - (Player.armorclass & Goal.armorclass);\r
1377         Player.real_frags = Player.real_frags - Goal.frags;\r
1378         if (!(toggleflags & 128))\r
1379         {\r
1380                 Player.frags = Player.real_frags;\r
1381         }\r
1382         Player.ammo_shells = Player.ammo_shells - Goal.ammo_shells;\r
1383         Player.ammo_nails = Player.ammo_nails - Goal.ammo_nails;\r
1384         Player.ammo_rockets = Player.ammo_rockets - Goal.ammo_rockets;\r
1385         Player.ammo_cells = Player.ammo_cells - Goal.ammo_cells;\r
1386         Player.ammo_metal = Player.ammo_metal - Goal.ammo_metal;                // take metal\r
1387         Player.ammo_medikit = Player.ammo_medikit - Goal.ammo_medikit;\r
1388         Player.ammo_detpack = Player.ammo_detpack - Goal.ammo_detpack;\r
1389         Player.no_grenades_1 = Player.no_grenades_1 - Goal.no_grenades_1;\r
1390         Player.no_grenades_2 = Player.no_grenades_2 - Goal.no_grenades_2;\r
1391         puinvin = 0;\r
1392         puinvis = 0;\r
1393         puquad = 0;\r
1394         purad = 0;\r
1395         te = find(world, classname, "item_tfgoal");\r
1396         while (te)\r
1397         {\r
1398                 if (te.owner == Player && te != Goal)\r
1399                 {\r
1400                         if (te.invincible_finished > 0)\r
1401                         {\r
1402                                 puinvin = 1;\r
1403                         }\r
1404                         if (te.invisible_finished > 0)\r
1405                         {\r
1406                                 puinvis = 1;\r
1407                         }\r
1408                         if (te.super_damage_finished > 0)\r
1409                         {\r
1410                                 puquad = 1;\r
1411                         }\r
1412                         if (te.radsuit_finished > 0)\r
1413                         {\r
1414                                 purad = 1;\r
1415                         }\r
1416                 }\r
1417                 te = find(te, classname, "item_tfgoal");\r
1418         }\r
1419         if (Goal.invincible_finished > 0 && !puinvin)\r
1420         {\r
1421                 Player.tfstate = Player.tfstate - (Player.tfstate & 32);\r
1422                 Player.items = Player.items | 1048576;\r
1423                 Player.invincible_time = 1;\r
1424                 Player.invincible_finished = time + Goal.invincible_finished;\r
1425         }\r
1426         if (Goal.invisible_finished > 0 && !puinvis)\r
1427         {\r
1428                 Player.tfstate = Player.tfstate - (Player.tfstate & 64);\r
1429                 Player.items = Player.items | 524288;\r
1430                 Player.invisible_time = 1;\r
1431                 Player.invisible_finished = time + Goal.invisible_finished;\r
1432         }\r
1433         if (Goal.super_damage_finished > 0 && !puquad)\r
1434         {\r
1435                 Player.tfstate = Player.tfstate - (Player.tfstate & 128);\r
1436                 Player.items = Player.items | 4194304;\r
1437                 Player.super_time = 1;\r
1438                 Player.super_damage_finished = time + Goal.super_damage_finished;\r
1439         }\r
1440         if (Goal.radsuit_finished > 0 && !purad)\r
1441         {\r
1442                 Player.tfstate = Player.tfstate - (Player.tfstate & 256);\r
1443                 Player.items = Player.items | 2097152;\r
1444                 Player.rad_time = 1;\r
1445                 Player.radsuit_finished = time + Goal.radsuit_finished;\r
1446         }\r
1447         oldself = self;\r
1448         self = Player;\r
1449         TeamFortress_CheckClassStats();\r
1450         //W_SetCurrentAmmo();           // automatic in nexuiz?\r
1451         self = oldself;\r
1452 };\r
1453 \r
1454 float(entity Goal, entity AP) APMeetsCriteria = \r
1455 {\r
1456         local float gotone;\r
1457         local entity te;\r
1458         if (AP != world)\r
1459         {\r
1460                 if (Goal.team_no)\r
1461                 {\r
1462                         if (Goal.team_no != AP.team_no)\r
1463                         {\r
1464                                 return 0;\r
1465                         }\r
1466                 }\r
1467                 if (Goal.playerclass)\r
1468                 {\r
1469                         if (Goal.playerclass != AP.playerclass)\r
1470                         {\r
1471                                 return 0;\r
1472                         }\r
1473                 }\r
1474                 if (Goal.class)\r
1475                 {\r
1476                         if (Goal.class != AP.class)\r
1477                         {\r
1478                                 return 0;\r
1479                         }\r
1480                 }\r
1481                 if (Goal.items_allowed)\r
1482                 {\r
1483                         te = Finditem(Goal.items_allowed);\r
1484                         if (te.owner != AP)\r
1485                         {\r
1486                                 return 0;\r
1487                         }\r
1488                 }\r
1489         }\r
1490         if (Goal.if_goal_is_active)\r
1491         {\r
1492                 te = Findgoal(Goal.if_goal_is_active);\r
1493                 if (te.goal_state != 1)\r
1494                 {\r
1495                         return 0;\r
1496                 }\r
1497         }\r
1498         if (Goal.if_goal_is_inactive)\r
1499         {\r
1500                 te = Findgoal(Goal.if_goal_is_inactive);\r
1501                 if (te.goal_state != 2)\r
1502                 {\r
1503                         return 0;\r
1504                 }\r
1505         }\r
1506         if (Goal.if_goal_is_removed)\r
1507         {\r
1508                 te = Findgoal(Goal.if_goal_is_removed);\r
1509                 if (te.goal_state != 3)\r
1510                 {\r
1511                         return 0;\r
1512                 }\r
1513         }\r
1514         if (Goal.if_group_is_active)\r
1515         {\r
1516                 te = find(world, classname, "info_tfgoal");\r
1517                 while (te)\r
1518                 {\r
1519                         if (te.group_no == Goal.if_group_is_active)\r
1520                         {\r
1521                                 if (te.goal_state != 1)\r
1522                                 {\r
1523                                         return 0;\r
1524                                 }\r
1525                         }\r
1526                         te = find(te, classname, "info_tfgoal");\r
1527                 }\r
1528         }\r
1529         if (Goal.if_group_is_inactive)\r
1530         {\r
1531                 te = find(world, classname, "info_tfgoal");\r
1532                 while (te)\r
1533                 {\r
1534                         if (te.group_no == Goal.if_group_is_inactive)\r
1535                         {\r
1536                                 if (te.goal_state != 2)\r
1537                                 {\r
1538                                         return 0;\r
1539                                 }\r
1540                         }\r
1541                         te = find(te, classname, "info_tfgoal");\r
1542                 }\r
1543         }\r
1544         if (Goal.if_group_is_removed)\r
1545         {\r
1546                 te = find(world, classname, "info_tfgoal");\r
1547                 while (te)\r
1548                 {\r
1549                         if (te.group_no == Goal.if_group_is_removed)\r
1550                         {\r
1551                                 if (te.goal_state != 3)\r
1552                                 {\r
1553                                         return 0;\r
1554                                 }\r
1555                         }\r
1556                         te = find(te, classname, "info_tfgoal");\r
1557                 }\r
1558         }\r
1559         if (Goal.if_item_has_moved)\r
1560         {\r
1561                 te = Finditem(Goal.if_item_has_moved);\r
1562                 if (te)\r
1563                 {\r
1564                         if (te.goal_state != 1 && te.origin == te.oldorigin)\r
1565                         {\r
1566                                 return 0;\r
1567                         }\r
1568                 }\r
1569         }\r
1570         if (Goal.if_item_hasnt_moved)\r
1571         {\r
1572                 te = Finditem(Goal.if_item_hasnt_moved);\r
1573                 if (te)\r
1574                 {\r
1575                         if (te.goal_state == 1 || te.origin != te.oldorigin)\r
1576                         {\r
1577                                 return 0;\r
1578                         }\r
1579                 }\r
1580         }\r
1581         if (AP != world)\r
1582         {\r
1583                 gotone = 0;\r
1584                 if (Goal.has_item_from_group)\r
1585                 {\r
1586                         te = find(world, classname, "item_tfgoal");\r
1587                         while (te != world && !gotone)\r
1588                         {\r
1589                                 if (te.group_no == Goal.has_item_from_group && te.owner == AP)\r
1590                                 {\r
1591                                         gotone = 1;\r
1592                                 }\r
1593                                 te = find(te, classname, "item_tfgoal");\r
1594                         }\r
1595                         if (!gotone)\r
1596                         {\r
1597                                 return 0;\r
1598                         }\r
1599                 }\r
1600         }\r
1601         return 1;\r
1602 };\r
1603 \r
1604 void(entity Goal) SetupRespawn = \r
1605 {\r
1606         if (Goal.search_time != 0)\r
1607         {\r
1608                 InactivateGoal(Goal);\r
1609                 Goal.think = tfgoal_timer_tick;\r
1610                 Goal.nextthink = time + Goal.search_time;\r
1611                 return;\r
1612         }\r
1613         if (Goal.goal_result & 1)\r
1614         {\r
1615                 RemoveGoal(Goal);\r
1616                 return;\r
1617         }\r
1618         if (Goal.wait > 0)\r
1619         {\r
1620                 Goal.nextthink = time + Goal.wait;\r
1621                 Goal.think = DoRespawn;\r
1622                 return;\r
1623         }\r
1624         else\r
1625         {\r
1626                 if (Goal.wait == -1)\r
1627                 {\r
1628                         return;\r
1629                 }\r
1630         }\r
1631         InactivateGoal(Goal);\r
1632 };\r
1633 \r
1634 void() DoRespawn = \r
1635 {\r
1636         RestoreGoal(self);\r
1637         InactivateGoal(self);\r
1638 };\r
1639 \r
1640 float(entity Goal, entity AP) Activated = \r
1641 {\r
1642         local float APMet;\r
1643         local float RevAct;\r
1644         local float Act;\r
1645         if (Goal.goal_state == 1)\r
1646         {\r
1647                 return 0;\r
1648         }\r
1649         if (Goal.goal_state == 3)\r
1650         {\r
1651                 return 0;\r
1652         }\r
1653         if (Goal.goal_state == 4)\r
1654         {\r
1655                 return 0;\r
1656         }\r
1657         APMet = APMeetsCriteria(Goal, AP);\r
1658         if (Goal.classname == "item_tfgoal")\r
1659         {\r
1660                 RevAct = Goal.goal_activation & 64;\r
1661         }\r
1662         else\r
1663         {\r
1664                 RevAct = Goal.goal_activation & 4;\r
1665         }\r
1666         Act = 0;\r
1667         if (APMet)\r
1668         {\r
1669                 if (!RevAct)\r
1670                 {\r
1671                         Act = 1;\r
1672                 }\r
1673         }\r
1674         else\r
1675         {\r
1676                 if (RevAct)\r
1677                 {\r
1678                         Act = 1;\r
1679                 }\r
1680         }\r
1681         return Act;\r
1682 };\r
1683 \r
1684 void(entity Goal, entity AP) DoGoalWork = \r
1685 {\r
1686         local entity te;\r
1687         local entity RI;\r
1688         if (Goal.activate_goal_no != 0)\r
1689         {\r
1690                 te = Findgoal(Goal.activate_goal_no);\r
1691                 if (te)\r
1692                 {\r
1693                         AttemptToActivate(te, AP, Goal);\r
1694                 }\r
1695         }\r
1696         if (Goal.inactivate_goal_no != 0)\r
1697         {\r
1698                 te = Findgoal(Goal.inactivate_goal_no);\r
1699                 if (te)\r
1700                 {\r
1701                         InactivateGoal(te);\r
1702                 }\r
1703         }\r
1704         if (Goal.restore_goal_no != 0)\r
1705         {\r
1706                 te = Findgoal(Goal.restore_goal_no);\r
1707                 if (te)\r
1708                 {\r
1709                         RestoreGoal(te);\r
1710                 }\r
1711         }\r
1712         if (Goal.remove_goal_no != 0)\r
1713         {\r
1714                 te = Findgoal(Goal.remove_goal_no);\r
1715                 if (te)\r
1716                 {\r
1717                         RemoveGoal(te);\r
1718                 }\r
1719         }\r
1720         if (Goal.return_item_no != 0)\r
1721         {\r
1722                 te = Finditem(Goal.return_item_no);\r
1723                 if (te)\r
1724                 {\r
1725                         if (te.goal_state == 1)\r
1726                         {\r
1727                                 tfgoalitem_RemoveFromPlayer(te, te.owner, 1);\r
1728                         }\r
1729                         RI = spawn();\r
1730                         RI.enemy = te;\r
1731                         RI.think = ReturnItem;\r
1732                         RI.nextthink = time + 0.1;\r
1733                         te.solid = 0;\r
1734                 }\r
1735         }\r
1736         if (Goal.remove_spawnpoint != 0)\r
1737         {\r
1738                 te = Findteamspawn(Goal.remove_spawnpoint);\r
1739                 if (te)\r
1740                 {\r
1741                         te.goal_state = 3;\r
1742                         te.team_str_home = string_null;\r
1743                 }\r
1744         }\r
1745         if (Goal.restore_spawnpoint != 0)\r
1746         {\r
1747                 te = Findteamspawn(Goal.restore_spawnpoint);\r
1748                 if (te)\r
1749                 {\r
1750                         if (te.goal_state == 3)\r
1751                         {\r
1752                                 te.goal_state = 2;\r
1753                                 if (te.team_no == 1)\r
1754                                 {\r
1755                                         te.team_str_home = "ts1";\r
1756                                 }\r
1757                                 else\r
1758                                 {\r
1759                                         if (te.team_no == 2)\r
1760                                         {\r
1761                                                 te.team_str_home = "ts2";\r
1762                                         }\r
1763                                         else\r
1764                                         {\r
1765                                                 if (te.team_no == 3)\r
1766                                                 {\r
1767                                                         te.team_str_home = "ts3";\r
1768                                                 }\r
1769                                                 else\r
1770                                                 {\r
1771                                                         if (te.team_no == 4)\r
1772                                                         {\r
1773                                                                 te.team_str_home = "ts4";\r
1774                                                         }\r
1775                                                 }\r
1776                                         }\r
1777                                 }\r
1778                         }\r
1779                 }\r
1780         }\r
1781 };\r
1782 \r
1783 void(entity Goal, entity AP) DoGroupWork = \r
1784 {\r
1785         local string st;\r
1786         local entity tg;\r
1787         local float allset;\r
1788         if (Goal.all_active != 0)\r
1789         {\r
1790                 if (Goal.last_impulse == 0)\r
1791                 {\r
1792                         dprint("Goal ");\r
1793                         st = ftos(Goal.goal_no);\r
1794                         dprint(st);\r
1795                         dprint(" has a .all_active specified, but no .last_impulse\n");\r
1796                 }\r
1797                 else\r
1798                 {\r
1799                         allset = 1;\r
1800                         tg = find(world, classname, "info_tfgoal");\r
1801                         while (tg)\r
1802                         {\r
1803                                 if (tg.group_no == Goal.all_active)\r
1804                                 {\r
1805                                         if (tg.goal_state != 1)\r
1806                                         {\r
1807                                                 allset = 0;\r
1808                                         }\r
1809                                 }\r
1810                                 tg = find(tg, classname, "info_tfgoal");\r
1811                         }\r
1812                         if (allset)\r
1813                         {\r
1814                                 tg = Findgoal(Goal.last_impulse);\r
1815                                 if (tg)\r
1816                                 {\r
1817                                         DoResults(tg, AP, Goal.goal_result & 2);\r
1818                                 }\r
1819                         }\r
1820                 }\r
1821         }\r
1822         if (Goal.activate_group_no != 0)\r
1823         {\r
1824                 tg = find(world, classname, "info_tfgoal");\r
1825                 while (tg)\r
1826                 {\r
1827                         if (tg.group_no == Goal.activate_group_no)\r
1828                         {\r
1829                                 DoResults(tg, AP, 0);\r
1830                         }\r
1831                         tg = find(tg, classname, "info_tfgoal");\r
1832                 }\r
1833         }\r
1834         if (Goal.inactivate_group_no != 0)\r
1835         {\r
1836                 tg = find(world, classname, "info_tfgoal");\r
1837                 while (tg)\r
1838                 {\r
1839                         if (tg.group_no == Goal.inactivate_group_no)\r
1840                         {\r
1841                                 InactivateGoal(tg);\r
1842                         }\r
1843                         tg = find(tg, classname, "info_tfgoal");\r
1844                 }\r
1845         }\r
1846         if (Goal.remove_group_no != 0)\r
1847         {\r
1848                 tg = find(world, classname, "info_tfgoal");\r
1849                 while (tg)\r
1850                 {\r
1851                         if (tg.group_no == Goal.remove_group_no)\r
1852                         {\r
1853                                 RemoveGoal(tg);\r
1854                         }\r
1855                         tg = find(tg, classname, "info_tfgoal");\r
1856                 }\r
1857         }\r
1858         if (Goal.restore_group_no != 0)\r
1859         {\r
1860                 tg = find(world, classname, "info_tfgoal");\r
1861                 while (tg)\r
1862                 {\r
1863                         if (tg.group_no == Goal.restore_group_no)\r
1864                         {\r
1865                                 RestoreGoal(tg);\r
1866                         }\r
1867                         tg = find(tg, classname, "info_tfgoal");\r
1868                 }\r
1869         }\r
1870         if (Goal.remove_spawngroup != 0)\r
1871         {\r
1872                 tg = find(world, classname, "info_player_teamspawn");\r
1873                 while (tg)\r
1874                 {\r
1875                         if (tg.group_no == Goal.remove_spawngroup)\r
1876                         {\r
1877                                 tg.goal_state = 3;\r
1878                                 tg.team_str_home = string_null;\r
1879                         }\r
1880                         tg = find(tg, classname, "info_player_teamspawn");\r
1881                 }\r
1882         }\r
1883         if (Goal.restore_spawngroup != 0)\r
1884         {\r
1885                 tg = find(world, classname, "info_player_teamspawn");\r
1886                 while (tg)\r
1887                 {\r
1888                         if (tg.group_no == Goal.restore_spawngroup)\r
1889                         {\r
1890                                 tg.goal_state = 2;\r
1891                                 if (tg.team_no == 1)\r
1892                                 {\r
1893                                         tg.team_str_home = "ts1";\r
1894                                 }\r
1895                                 else\r
1896                                 {\r
1897                                         if (tg.team_no == 2)\r
1898                                         {\r
1899                                                 tg.team_str_home = "ts2";\r
1900                                         }\r
1901                                         else\r
1902                                         {\r
1903                                                 if (tg.team_no == 3)\r
1904                                                 {\r
1905                                                         tg.team_str_home = "ts3";\r
1906                                                 }\r
1907                                                 else\r
1908                                                 {\r
1909                                                         if (tg.team_no == 4)\r
1910                                                         {\r
1911                                                                 tg.team_str_home = "ts4";\r
1912                                                         }\r
1913                                                 }\r
1914                                         }\r
1915                                 }\r
1916                         }\r
1917                         tg = find(tg, classname, "info_player_teamspawn");\r
1918                 }\r
1919         }\r
1920 };\r
1921 \r
1922 void(entity Item, entity AP) DoItemGroupWork = \r
1923 {\r
1924         local entity tg;\r
1925         local entity carrier;\r
1926         local float allcarried;\r
1927         local string st;\r
1928         allcarried = 1;\r
1929         if (Item.distance != 0)\r
1930         {\r
1931                 if (Item.pain_finished == 0)\r
1932                 {\r
1933                         dprint("GoalItem ");\r
1934                         st = ftos(Item.goal_no);\r
1935                         dprint(st);\r
1936                         dprint(" has a .distance specified, but no .pain_finished\n");\r
1937                 }\r
1938                 tg = find(world, classname, "item_tfgoal");\r
1939                 while (tg)\r
1940                 {\r
1941                         if (tg.group_no == Item.distance)\r
1942                         {\r
1943                                 if (tg.goal_state != 1)\r
1944                                 {\r
1945                                         allcarried = 0;\r
1946                                 }\r
1947                         }\r
1948                         tg = find(tg, classname, "item_tfgoal");\r
1949                 }\r
1950                 if (allcarried == 1)\r
1951                 {\r
1952                         tg = Findgoal(Item.pain_finished);\r
1953                         if (tg)\r
1954                         {\r
1955                                 DoResults(tg, AP, Item.goal_result & 2);\r
1956                         }\r
1957                 }\r
1958         }\r
1959         allcarried = 1;\r
1960         if (Item.speed != 0)\r
1961         {\r
1962                 if (Item.attack_finished == 0)\r
1963                 {\r
1964                         dprint("GoalItem ");\r
1965                         st = ftos(Item.goal_no);\r
1966                         dprint(st);\r
1967                         dprint(" has a .speed specified, but no .attack_finished\n");\r
1968                 }\r
1969                 carrier = world;\r
1970                 tg = find(world, classname, "item_tfgoal");\r
1971                 while (tg)\r
1972                 {\r
1973                         if (tg.group_no == Item.speed)\r
1974                         {\r
1975                                 if (tg.goal_state != 1)\r
1976                                 {\r
1977                                         allcarried = 0;\r
1978                                 }\r
1979                                 else\r
1980                                 {\r
1981                                         if (carrier == world)\r
1982                                         {\r
1983                                                 carrier = tg.owner;\r
1984                                         }\r
1985                                         else\r
1986                                         {\r
1987                                                 if (carrier != tg.owner)\r
1988                                                 {\r
1989                                                         allcarried = 0;\r
1990                                                 }\r
1991                                         }\r
1992                                 }\r
1993                         }\r
1994                         tg = find(tg, classname, "item_tfgoal");\r
1995                 }\r
1996                 if (allcarried == 1)\r
1997                 {\r
1998                         tg = Findgoal(Item.attack_finished);\r
1999                         if (tg)\r
2000                         {\r
2001                                 DoResults(tg, AP, Item.goal_result & 2);\r
2002                         }\r
2003                 }\r
2004         }\r
2005 };\r
2006 \r
2007 void(entity Goal, entity AP) DoTriggerWork = \r
2008 {\r
2009         local entity t;\r
2010         if (Goal.killtarget)\r
2011         {\r
2012                 t = world;\r
2013                 do\r
2014                 {\r
2015                         t = find(t, targetname, Goal.killtarget);\r
2016                         if (t != world)\r
2017                         {\r
2018                                 remove(t);\r
2019                         }\r
2020                 } while (t != world);\r
2021         }\r
2022         if (Goal.target)\r
2023         {\r
2024                 t = world;\r
2025                 activator = AP;\r
2026                 do\r
2027                 {\r
2028                         t = find(t, targetname, Goal.target);\r
2029                         if (t == world)\r
2030                         {\r
2031                                 return;\r
2032                         }\r
2033                         stemp = self;\r
2034                         otemp = other;\r
2035                         self = t;\r
2036                         other = stemp;\r
2037                         if (self.use != SUB_Null)\r
2038                         {\r
2039                                 if (self.use)\r
2040                                 {\r
2041                                         self.use();\r
2042                                 }\r
2043                         }\r
2044                         self = stemp;\r
2045                         other = otemp;\r
2046                         activator = AP;\r
2047                 } while (t != world);\r
2048         }\r
2049 };\r
2050 \r
2051 void() DelayedResult = \r
2052 {\r
2053         if (self.enemy.goal_state == 4)\r
2054         {\r
2055                 DoResults(self.enemy, self.owner, self.weapon);\r
2056         }\r
2057         dremove(self);\r
2058 };\r
2059 \r
2060 void(entity Goal, entity AP, float addb) DoResults = \r
2061 {\r
2062         local entity te;\r
2063 \r
2064         local float winners;\r
2065 \r
2066         if (Goal.goal_state == 1)\r
2067         {\r
2068                 return;\r
2069         }\r
2070         if (Goal.delay_time > 0 && Goal.goal_state != 4)\r
2071         {\r
2072                 Goal.goal_state = 4;\r
2073                 te = spawn();\r
2074                 te.think = DelayedResult;\r
2075                 te.nextthink = time + Goal.delay_time;\r
2076                 te.owner = AP;\r
2077                 te.enemy = Goal;\r
2078                 te.weapon = addb;\r
2079                 return;\r
2080         }\r
2081         UpdateAbbreviations(Goal);\r
2082         Goal.goal_state = 2;\r
2083         if (Goal.noise)\r
2084         {\r
2085                 if (Goal.volume == 1)\r
2086                 {\r
2087                         sound(other, 3, Goal.noise, 1, 0);\r
2088                 }\r
2089                 else\r
2090                 {\r
2091                         sound(other, 3, Goal.noise, 1, 1);\r
2092                 }\r
2093         }\r
2094         winners = 0;\r
2095         if (Goal.increase_team1 != 0)\r
2096         {\r
2097                 TeamFortress_TeamIncreaseScore(1, Goal.increase_team1);\r
2098                 winners = 1;\r
2099         }\r
2100         if (Goal.increase_team2 != 0)\r
2101         {\r
2102                 TeamFortress_TeamIncreaseScore(2, Goal.increase_team2);\r
2103                 winners = 1;\r
2104         }\r
2105         if (Goal.increase_team3 != 0)\r
2106         {\r
2107                 TeamFortress_TeamIncreaseScore(3, Goal.increase_team3);\r
2108                 winners = 1;\r
2109         }\r
2110         if (Goal.increase_team4 != 0)\r
2111         {\r
2112                 TeamFortress_TeamIncreaseScore(4, Goal.increase_team4);\r
2113                 winners = 1;\r
2114         }\r
2115         if (winners == 1)\r
2116         {\r
2117                 TeamFortress_TeamShowScores(2);\r
2118         }\r
2119         te = find(world, classname, "player");\r
2120         while (te != world)\r
2121         {\r
2122                 if (Goal.broadcast != string_null && CTF_Map == 0)\r
2123                 {\r
2124                         CenterPrint2(te, "\n\n\n", Goal.broadcast);\r
2125                 }\r
2126                 if (Goal.netname_broadcast != string_null && CTF_Map == 0)\r
2127                 {\r
2128                         sprint(te,AP.netname);\r
2129                         sprint(te,Goal.netname_broadcast);\r
2130                 }\r
2131                 if (AP == te)\r
2132                 {\r
2133                         if (Goal.message != string_null)\r
2134                         {\r
2135                                 CenterPrint2(te, Goal.message, AP.netname);\r
2136                         }\r
2137                 }\r
2138                 else\r
2139                 {\r
2140                         if (AP.team_no == te.team_no)\r
2141                         {\r
2142                                 if (Goal.owners_team_broadcast != string_null && te.team_no == Goal.owned_by)\r
2143                                 {\r
2144                                         CenterPrint2(te, Goal.owners_team_broadcast, AP.netname);\r
2145                                 }\r
2146                                 else\r
2147                                 {\r
2148                                         if (Goal.team_broadcast != string_null)\r
2149                                         {\r
2150                                                 CenterPrint2(te, Goal.team_broadcast, AP.netname);\r
2151                                         }\r
2152                                 }\r
2153                                 if (Goal.netname_owners_team_broadcast != string_null && te.team_no == Goal.owned_by)\r
2154                                 {\r
2155                                         sprint(te,AP.netname);\r
2156                                         sprint(te,Goal.netname_owners_team_broadcast);\r
2157                                 }\r
2158                                 else\r
2159                                 {\r
2160                                         if (Goal.netname_team_broadcast != string_null)\r
2161                                         {\r
2162                                                 sprint(te,AP.netname);\r
2163                                                 sprint(te,Goal.netname_team_broadcast);\r
2164                                         }\r
2165                                 }\r
2166                         }\r
2167                         else\r
2168                         {\r
2169                                 if (Goal.owners_team_broadcast != string_null && te.team_no == Goal.owned_by)\r
2170                                 {\r
2171                                         CenterPrint2(te, Goal.owners_team_broadcast, AP.netname);\r
2172                                 }\r
2173                                 else\r
2174                                 {\r
2175                                         if (Goal.non_team_broadcast != string_null)\r
2176                                         {\r
2177                                                 CenterPrint2(te, Goal.non_team_broadcast, AP.netname);\r
2178                                         }\r
2179                                 }\r
2180                                 if (Goal.netname_owners_team_broadcast != string_null && te.team_no == Goal.owned_by)\r
2181                                 {\r
2182                                         sprint(te,AP.netname);\r
2183                                         sprint(te,Goal.netname_owners_team_broadcast);\r
2184                                 }\r
2185                                 else\r
2186                                 {\r
2187                                         if (Goal.netname_non_team_broadcast != string_null)\r
2188                                         {\r
2189                                                 sprint(te,AP.netname);\r
2190                                                 sprint(te,Goal.netname_non_team_broadcast);\r
2191                                         }\r
2192                                 }\r
2193                         }\r
2194                 }\r
2195                 if (IsAffectedBy(Goal, te, AP))\r
2196                 {\r
2197                         if (Goal.search_time != 0 && (Goal.goal_effects & 64))\r
2198                         {\r
2199                                 if (APMeetsCriteria(Goal, te))\r
2200                                 {\r
2201                                         Apply_Results(Goal, te, AP, addb);\r
2202                                 }\r
2203                         }\r
2204                         else\r
2205                         {\r
2206                                 Apply_Results(Goal, te, AP, addb);\r
2207                         }\r
2208                 }\r
2209                 te = find(te, classname, "player");\r
2210         }\r
2211         if (Goal.classname != "item_tfgoal")\r
2212         {\r
2213                 Goal.goal_state = 1;\r
2214         }\r
2215         if (Goal.goal_result & 4)\r
2216         {\r
2217                 TeamFortress_TeamShowScores(1);\r
2218                 winners = TeamFortress_TeamGetWinner();\r
2219                 te = find(world, classname, "player");\r
2220                 while (te)\r
2221                 {\r
2222                         te.takedamage = 0;\r
2223                         te.movetype = 0;\r
2224                         te.velocity = '0 0 0';\r
2225                         te.avelocity = '0 0 0';\r
2226                         te = find(te, classname, "player");\r
2227                 }\r
2228                 te = spawn();\r
2229                 te.nextthink = time + 5;\r
2230                 te.think = execute_changelevel;\r
2231 //              te.think = changelevel;                 // Wazat -- may need fixing\r
2232                 dremove(Goal);\r
2233                 return;\r
2234         }\r
2235 \r
2236         DoGroupWork(Goal, AP);\r
2237         DoGoalWork(Goal, AP);\r
2238         DoTriggerWork(Goal, AP);\r
2239         if (Goal.classname == "info_tfgoal")\r
2240         {\r
2241                 SetupRespawn(Goal);\r
2242         }\r
2243 };\r
2244 \r
2245 void() tfgoal_touch = \r
2246 {\r
2247         if (self.give != "")\r
2248                 ParseGive(self);\r
2249         if (!(self.goal_activation & 1))\r
2250         {\r
2251                 return;\r
2252         }\r
2253         if (other.classname != "player")\r
2254         {\r
2255                 return;\r
2256         }\r
2257         if (other.is_dead == 1)         // TEMP\r
2258         {\r
2259                 return;\r
2260         }\r
2261         if (self.goal_state == 1)\r
2262         {\r
2263                 return;\r
2264         }\r
2265         AttemptToActivate(self, other, self);\r
2266 };\r
2267 \r
2268 void() info_tfgoal_use = \r
2269 {\r
2270         AttemptToActivate(self, activator, self);\r
2271 };\r
2272 \r
2273 void() tfgoal_timer_tick = \r
2274 {\r
2275         if (self.goal_state != 3)\r
2276         {\r
2277                 if (APMeetsCriteria(self, world))\r
2278                 {\r
2279                         DoResults(self, world, 1);\r
2280                 }\r
2281                 else\r
2282                 {\r
2283                         InactivateGoal(self);\r
2284                         self.think = tfgoal_timer_tick;\r
2285                         self.nextthink = time + self.search_time;\r
2286                 }\r
2287         }\r
2288 };\r
2289 \r
2290 void() item_tfgoal_touch = \r
2291 {\r
2292         local entity te;\r
2293         if (other.is_dead == 1)         // TEMP\r
2294         {\r
2295                 return;\r
2296         }\r
2297         if (other.classname != "player")\r
2298         {\r
2299                 return;\r
2300         }\r
2301         if (other.health <= 0)\r
2302         {\r
2303                 return;\r
2304         }\r
2305         // for flag dropping\r
2306         if ( (self.tent == other) && (time < self.option5) )\r
2307         {\r
2308                 return;\r
2309         }\r
2310         if (Activated(self, other))\r
2311         {\r
2312                 tfgoalitem_GiveToPlayer(self, other, self);\r
2313                 self.goal_state = 1;\r
2314         }\r
2315         else\r
2316         {\r
2317                 if (self.else_goal != 0)\r
2318                 {\r
2319                         te = Findgoal(self.else_goal);\r
2320                         if (te)\r
2321                         {\r
2322                                 AttemptToActivate(te, other, self);\r
2323                         }\r
2324                 }\r
2325         }\r
2326 };\r
2327 \r
2328 void(entity Item, entity AP, entity Goal) tfgoalitem_GiveToPlayer = \r
2329 {\r
2330         Item.owner = AP;\r
2331         if (Item.mdl != string_null)\r
2332         {\r
2333                 setmodel(Item, string_null);\r
2334         }\r
2335         Item.solid = 0;\r
2336         if (Item.goal_activation & 1)\r
2337         {\r
2338                 AP.effects = AP.effects | 8;\r
2339         }\r
2340         if (Item.goal_activation & 2)\r
2341         {\r
2342                 TeamFortress_SetSpeed(AP);\r
2343         }\r
2344         if (Item.goal_activation & 512)\r
2345         {\r
2346                 Item.effects = Item.effects - (Item.effects | 8);\r
2347         }\r
2348 // NexTF Flags\r
2349         if (Item.items & 133701)\r
2350         {\r
2351                 AP.items = AP.items | 262144;\r
2352                 if (Item.team_no == 1)\r
2353                         AP.effects = AP.effects | EF_BLUE;\r
2354                 else if (Item.team_no == 2)\r
2355                         AP.effects = AP.effects | EF_RED;\r
2356                 newmis = spawn();\r
2357                 newmis.owner = AP;\r
2358                 newmis.movetype = 4;\r
2359                 newmis.solid = 0;\r
2360                 setsize(newmis, '0 0 0', '0 0 0');\r
2361                 newmis.angles = AP.angles;\r
2362                 newmis.nextthink = time + 0.5;\r
2363                 newmis.think = MoveFlag;\r
2364                 newmis.skin = 2;\r
2365                 setmodel(newmis, Item.mdl);\r
2366                 setorigin(newmis, AP.origin);\r
2367                 //eprint(AP);\r
2368         }\r
2369         else \r
2370         {\r
2371                 if (Item.items & 131072)\r
2372                 {\r
2373                         AP.items = AP.items | 131072;\r
2374                         AP.effects = AP.effects | 64;\r
2375                         newmis = spawn();\r
2376                         newmis.owner = AP;\r
2377                         newmis.movetype = 4;\r
2378                         newmis.solid = 0;\r
2379                         setsize(newmis, '0 0 0', '0 0 0');\r
2380                         newmis.angles = AP.angles;\r
2381                         newmis.nextthink = time + 0.5;\r
2382                         newmis.think = MoveFlag;\r
2383                         newmis.skin = 1;\r
2384                         setmodel(newmis, "progs/tf_flag.mdl");\r
2385                         setorigin(newmis, AP.origin);\r
2386                 }\r
2387                 if (Item.items & 262144)\r
2388                 {\r
2389                         AP.items = AP.items | 262144;\r
2390                         AP.effects = AP.effects | 128;\r
2391                         newmis = spawn();\r
2392                         newmis.owner = AP;\r
2393                         newmis.movetype = 4;\r
2394                         newmis.solid = 0;\r
2395                         setsize(newmis, '0 0 0', '0 0 0');\r
2396                         newmis.angles = AP.angles;\r
2397                         newmis.nextthink = time + 0.5;\r
2398                         newmis.think = MoveFlag;\r
2399                         newmis.skin = 2;\r
2400                         setmodel(newmis, "progs/tf_flag.mdl");\r
2401                         setorigin(newmis, AP.origin);\r
2402                 }\r
2403         }\r
2404         if (Goal != Item)\r
2405         {\r
2406                 if (Goal.goal_result & 8)\r
2407                 {\r
2408                         Item.goal_state = 1;\r
2409                         return;\r
2410                 }\r
2411         }\r
2412 /*      if (AP.playerclass == 8 && (Item.goal_result & 16))\r
2413         {\r
2414                 AP.is_unabletospy = 1;\r
2415         }*/\r
2416         if (AP.class == CLASS_SPY && (Item.goal_result & 16))\r
2417         {\r
2418                 AP.is_unabletospy = 1;\r
2419         }\r
2420         DoResults(Item, AP, 1);\r
2421         DoItemGroupWork(Item, AP);\r
2422 };\r
2423 \r
2424 void() ReturnItem = \r
2425 {\r
2426         self.enemy.goal_state = 2;\r
2427         self.enemy.solid = 1;\r
2428         self.enemy.movetype = 0;\r
2429         self.enemy.touch = item_tfgoal_touch;\r
2430         self.enemy.origin = self.enemy.oldorigin;\r
2431         if (self.enemy.mdl != string_null)\r
2432         {\r
2433                 setmodel(self.enemy, self.enemy.mdl);\r
2434         }\r
2435         setorigin(self.enemy, self.enemy.origin);\r
2436         //sound(self.enemy,"items/itembk2.wav", 1, 1);\r
2437         sound (self.enemy, 2, "items/itembk2.wav", 1, 1);\r
2438         tfgoalitem_checkgoalreturn(self.enemy);\r
2439         dremove(self);\r
2440 };\r
2441 \r
2442 void (entity Item, entity AP, float method) tfgoalitem_RemoveFromPlayer =\r
2443 {\r
2444         local entity te;\r
2445         local float lighton;\r
2446         local float slowon;\r
2447         local float key1on;\r
2448         local float key2on;\r
2449         local float spyoff;\r
2450         local entity DelayReturn;\r
2451 \r
2452         if ((Item == world))\r
2453         {\r
2454                 objerror ("error: tfgoalitem_RemoveFromPlayer(): Item == world");\r
2455                 return;\r
2456         }\r
2457         lighton = 0;\r
2458         slowon = 0;\r
2459         key1on = 0;\r
2460         key2on = 0;\r
2461         spyoff = 0;\r
2462         te = find (world, classname, "item_tfgoal");\r
2463         while (te)\r
2464         {\r
2465                 if (((te.owner == AP) && (te != Item)))\r
2466                 {\r
2467                         if ((te.goal_activation & 1))\r
2468                         {\r
2469                                 lighton = 1;\r
2470                         }\r
2471                         if ((te.goal_activation & 2))\r
2472                         {\r
2473                                 slowon = 1;\r
2474                         }\r
2475                         if ((te.items & 131072))\r
2476                         {\r
2477                                 key1on = 1;\r
2478                         }\r
2479                         if ((te.items & 262144))\r
2480                         {\r
2481                                 key2on = 1;\r
2482                         }\r
2483                         if ((te.goal_result & 16))\r
2484                         {\r
2485                                 spyoff = 1;\r
2486                         }\r
2487                 }\r
2488                 te = find (te, classname, "item_tfgoal");\r
2489         }\r
2490         if (!lighton)\r
2491         {\r
2492                 if ((AP.invincible_finished > (time + 3)))\r
2493                 {\r
2494                         lighton = 1;\r
2495                 }\r
2496                 else\r
2497                 {\r
2498                         if ((AP.super_damage_finished > (time + 3)))\r
2499                         {\r
2500                                 lighton = 1;\r
2501                         }\r
2502                 }\r
2503         }\r
2504         if (!lighton)\r
2505         {\r
2506                 AP.effects = (AP.effects - (AP.effects & 8));\r
2507                 AP.effects = (AP.effects - (AP.effects & 64));\r
2508                 AP.effects = (AP.effects - (AP.effects & 128));\r
2509         }\r
2510         if ((Item.goal_activation & 512))\r
2511         {\r
2512                 Item.effects = (Item.effects | 8);\r
2513         }\r
2514         if (!spyoff)\r
2515         {\r
2516                 AP.is_unabletospy = 0;\r
2517         }\r
2518         if (!key1on)\r
2519         {\r
2520                 AP.items = (AP.items - (AP.items & 131072));\r
2521         }\r
2522         if (!key2on)\r
2523         {\r
2524                 AP.items = (AP.items - (AP.items & 262144));\r
2525         }\r
2526         te = find (world, classname, "player");\r
2527         while ((te != world))\r
2528         {\r
2529                 if (IsAffectedBy (Item, te, AP))\r
2530                 {\r
2531                         RemoveResults (Item, te);\r
2532                 }\r
2533                 te = find (te, classname, "player");\r
2534         }\r
2535         if (((method == 0) || (method == 2)))\r
2536         {\r
2537                 te = find (world, classname, "player");\r
2538                 while ((te != world))\r
2539                 {\r
2540                         if ((te.team_no == Item.owned_by))\r
2541                         {\r
2542                                 if ((Item.team_drop != string_null))\r
2543                                 {\r
2544                                         CenterPrint2 (te, "\n\n\n", Item.team_drop);\r
2545                                 }\r
2546                                 if ((Item.netname_team_drop != string_null))\r
2547                                 {\r
2548                                         sprint (te, AP.netname);\r
2549                                         sprint (te, Item.netname_team_drop);\r
2550                                 }\r
2551                         }\r
2552                         else\r
2553                         {\r
2554                                 if ((Item.non_team_drop != string_null))\r
2555                                 {\r
2556                                         CenterPrint2 (te, "\n\n\n", Item.non_team_drop);\r
2557                                 }\r
2558                                 if ((Item.netname_non_team_drop != string_null))\r
2559                                 {\r
2560                                         sprint (te, AP.netname);\r
2561                                         sprint (te, Item.netname_non_team_drop);\r
2562                                 }\r
2563                         }\r
2564                         te = find (te, classname, "player");\r
2565                 }\r
2566                 if ((Item.goal_activation & 8))\r
2567                 {\r
2568                         DelayReturn = spawn ();\r
2569                         DelayReturn.enemy = Item;\r
2570                         if ((method == 0))\r
2571                         {\r
2572                                 DelayReturn.weapon = 0;\r
2573                         }\r
2574                         else\r
2575                         {\r
2576                                 DelayReturn.weapon = 1;\r
2577                         }\r
2578                         DelayReturn.think = ReturnItem;\r
2579                         DelayReturn.nextthink = (time + 0.5);\r
2580                 }\r
2581                 else\r
2582                 {\r
2583                         if ((Item.goal_activation & 4))\r
2584                         {\r
2585                                 if (((method == 2) && (Item.goal_activation & 4096)))\r
2586                                 {\r
2587                                         tfgoalitem_drop (Item/*, 1, AP*/);\r
2588                                 }\r
2589                                 else\r
2590                                 {\r
2591                                         tfgoalitem_drop (Item/*, 0, AP*/);\r
2592                                 }\r
2593                         }\r
2594                         else\r
2595                         {\r
2596                                 Item.owner = world;\r
2597                                 dremove (Item);\r
2598                                 TeamFortress_SetSpeed (AP);\r
2599                                 return;\r
2600                         }\r
2601                 }\r
2602                 Item.owner = world;\r
2603                 Item.flags = (Item.flags - (Item.flags & 512));\r
2604                 setsize (Item, Item.goal_min, Item.goal_max);\r
2605                 TeamFortress_SetSpeed (AP);\r
2606                 return;\r
2607         }\r
2608         else\r
2609         {\r
2610         if (method == 1)\r
2611         {\r
2612                         if (Item.goal_activation & 16)\r
2613                         {\r
2614                                 DelayReturn = spawn();\r
2615                                 DelayReturn.enemy = Item;\r
2616                                 DelayReturn.think = ReturnItem;\r
2617                                 DelayReturn.nextthink = time + 0.5;\r
2618                                 Item.owner = world;\r
2619                                 TeamFortress_SetSpeed(AP);\r
2620                                 return;\r
2621                         }\r
2622                         Item.solid = 0;\r
2623                         Item.owner = world;\r
2624                         TeamFortress_SetSpeed(AP);\r
2625                         return;\r
2626                 }\r
2627         }\r
2628         objerror ("Invalid method passed into tfgoalitem_RemoveFromPlayer\n");\r
2629 };\r
2630 \r
2631 // MTF's remove from player function\r
2632 /*void(entity Item, entity AP, float method) tfgoalitem_RemoveFromPlayer = \r
2633 {\r
2634         local entity te;\r
2635         local float lighton;\r
2636         local float slowon;\r
2637         local float key1on;\r
2638         local float key2on;\r
2639         local float spyoff;\r
2640         local string db1;\r
2641         local entity DelayReturn;\r
2642         if (Item == world)\r
2643         {\r
2644                 dprint("error: tfgoalitem_RemoveFromPlayer(): Item == world");\r
2645                 return;\r
2646         }\r
2647         lighton = 0;\r
2648         slowon = 0;\r
2649         key1on = 0;\r
2650         key2on = 0;\r
2651         spyoff = 0;\r
2652         te = find(world, classname, "item_tfgoal");\r
2653         while (te)\r
2654         {\r
2655                 if (te.owner == AP && te != Item)\r
2656                 {\r
2657                         if (te.goal_activation & 1)\r
2658                         {\r
2659                                 lighton = 1;\r
2660                         }\r
2661                         if (te.goal_activation & 2)\r
2662                         {\r
2663                                 slowon = 1;\r
2664                         }\r
2665                         if (te.items & 131072)\r
2666                         {\r
2667                                 key1on = 1;\r
2668                         }\r
2669                         if (te.items & 262144)\r
2670                         {\r
2671                                 key2on = 1;\r
2672                         }\r
2673                         if (te.goal_result & 16)\r
2674                         {\r
2675                                 spyoff = 1;\r
2676                         }\r
2677                 }\r
2678                 te = find(te, classname, "item_tfgoal");\r
2679         }\r
2680         if (!lighton)\r
2681         {\r
2682                 if (AP.invincible_finished > time + 3)\r
2683                 {\r
2684                         lighton = 1;\r
2685                 }\r
2686         }\r
2687         if (!lighton)\r
2688         {\r
2689                 AP.effects = AP.effects - (AP.effects & 8);\r
2690         }\r
2691         if (Item.goal_activation & 512)\r
2692         {\r
2693                 Item.effects = Item.effects | 8;\r
2694         }\r
2695         if (!spyoff)\r
2696         {\r
2697                 AP.is_unabletospy = 0;\r
2698         }\r
2699         if (!key1on)\r
2700         {\r
2701                 AP.items = AP.items - (AP.items & 131072);\r
2702         }\r
2703         if (!key2on)\r
2704         {\r
2705                 AP.items = AP.items - (AP.items & 262144);\r
2706         }\r
2707         te = find(world, classname, "player");\r
2708         while (te != world)\r
2709         {\r
2710                 if (IsAffectedBy(Item, te, AP))\r
2711                 {\r
2712                         RemoveResults(Item, te);\r
2713                 }\r
2714                 te = find(te, classname, "player");\r
2715         }\r
2716         if ((method == 0) || (method == 2))\r
2717         {\r
2718                 te = find(world, classname, "player");\r
2719                 while (te != world)\r
2720                 {\r
2721                         if (te.team_no == Item.owned_by)\r
2722                         {\r
2723                                 if (Item.team_drop != string_null)\r
2724                                 {\r
2725                                         CenterPrint2(te, "\n\n\n", Item.team_drop);\r
2726                                 }\r
2727                                 if (Item.netname_team_drop != string_null)\r
2728                                 {\r
2729                                         sprint(te,AP.netname);\r
2730                                         sprint(te,Item.netname_team_drop);\r
2731                                 }\r
2732                         }\r
2733                         else\r
2734                         {\r
2735                                 if (Item.non_team_drop != string_null)\r
2736                                 {\r
2737                                         CenterPrint2(te, "\n\n\n", Item.non_team_drop);\r
2738                                 }\r
2739                                 if (Item.netname_non_team_drop != string_null)\r
2740                                 {\r
2741                                         sprint(te,AP.netname);\r
2742                                         sprint(te,Item.netname_non_team_drop);\r
2743                                 }\r
2744                         }\r
2745                         te = find(te, classname, "player");\r
2746                 }\r
2747                 if (Item.goal_activation & 8)\r
2748                 {\r
2749                         DelayReturn = spawn();\r
2750                         DelayReturn.enemy = Item;\r
2751                         DelayReturn.think = ReturnItem;\r
2752                         DelayReturn.nextthink = time + 0.5;\r
2753                 }\r
2754                 else\r
2755                 {\r
2756                         if (Item.goal_activation & 4)\r
2757                         {\r
2758                                 if (method == 0)\r
2759                                         tfgoalitem_drop(Item);\r
2760                         }\r
2761                         else\r
2762                         {\r
2763                                 Item.owner = world;\r
2764                                 dremove(Item);\r
2765                                 TeamFortress_SetSpeed(AP);\r
2766                                 return;\r
2767                         }\r
2768                 }\r
2769                 Item.owner = world;\r
2770                 TeamFortress_SetSpeed(AP);\r
2771                 return;\r
2772         }\r
2773         if (method == 1)\r
2774         {\r
2775                 if (Item.goal_activation & 16)\r
2776                 {\r
2777                         DelayReturn = spawn();\r
2778                         DelayReturn.enemy = Item;\r
2779                         DelayReturn.think = ReturnItem;\r
2780                         DelayReturn.nextthink = time + 0.5;\r
2781                         Item.owner = world;\r
2782                         TeamFortress_SetSpeed(AP);\r
2783                         return;\r
2784                 }\r
2785                 Item.solid = 0;\r
2786                 Item.owner = world;\r
2787                 TeamFortress_SetSpeed(AP);\r
2788                 return;\r
2789         }\r
2790 \r
2791         dprint("Invalid method passed into tfgoalitem_RemoveFromPlayer\n");\r
2792 };*/\r
2793 \r
2794 void() tfgoalitem_dropthink = \r
2795 {\r
2796         local float pos;\r
2797         self.movetype = 10; //6;\r
2798         if (self.pausetime != 0)\r
2799         {\r
2800                 pos = pointcontents(self.origin);\r
2801                 if (pos == -4)\r
2802                 {\r
2803                         self.nextthink = time + self.pausetime / 4;\r
2804                 }\r
2805                 else\r
2806                 {\r
2807                         if (pos == -5)\r
2808                         {\r
2809                                 self.nextthink = time + 5;\r
2810                         }\r
2811                         else\r
2812                         {\r
2813                                 if (pos == -2 || pos == -6)\r
2814                                 {\r
2815                                         self.nextthink = time + 2;\r
2816                                 }\r
2817                                 else\r
2818                                 {\r
2819                                         self.nextthink = time + self.pausetime;\r
2820                                 }\r
2821                         }\r
2822                 }\r
2823                 self.think = tfgoalitem_remove;\r
2824         }\r
2825 };\r
2826 \r
2827 void(entity Item) tfgoalitem_drop = \r
2828 {\r
2829         Item.origin = Item.owner.origin - '0 0 8';\r
2830         //Item.velocity_z = 400;\r
2831         //Item.velocity_x = -50 + random() * 100;\r
2832         //Item.velocity_y = -50 + random() * 100;\r
2833         Item.velocity_z = 1;\r
2834         Item.velocity_x = 0;\r
2835         Item.velocity_y = 0;\r
2836         Item.goal_state = 2;\r
2837         Item.movetype = 6;\r
2838         Item.solid = 1;\r
2839         Item.touch = item_tfgoal_touch;\r
2840         setorigin(Item, Item.origin - '0 0 16');\r
2841         setsize(Item, '-16 -16 0', '16 16 56');\r
2842         if (Item.mdl != string_null)\r
2843         {\r
2844                 setmodel(Item, Item.mdl);\r
2845         }\r
2846         Item.nextthink = time + 5;\r
2847         Item.think = tfgoalitem_dropthink;\r
2848 };\r
2849 \r
2850 void() tfgoalitem_remove = \r
2851 {\r
2852         local entity te;\r
2853         if (self.goal_state == 1)\r
2854         {\r
2855                 return;\r
2856         }\r
2857         if (self.goal_activation & 32)\r
2858         {\r
2859                 self.solid = 1;\r
2860                 self.touch = item_tfgoal_touch;\r
2861                 self.origin = self.oldorigin;\r
2862                 if (self.mdl != string_null)\r
2863                 {\r
2864                         setmodel(self, self.mdl);\r
2865                 }\r
2866                 setorigin(self, self.origin);\r
2867                 //sound(self,"items/itembk2.wav", 1, 1);\r
2868                 tfgoalitem_checkgoalreturn(self);\r
2869                 if (self.noise3 != string_null || self.noise4 != string_null)\r
2870                 {\r
2871                         te = find(world, classname, "player");\r
2872                         while (te)\r
2873                         {\r
2874                                 if (te.team_no == self.owned_by)\r
2875                                 {\r
2876                                         CenterPrint2(te, "\n\n\n", self.noise3);\r
2877                                 }\r
2878                                 else\r
2879                                 {\r
2880                                         CenterPrint2(te, "\n\n\n", self.noise4);\r
2881                                 }\r
2882                                 te = find(te, classname, "player");\r
2883                         }\r
2884                 }\r
2885                 return;\r
2886         }\r
2887         dremove(self);\r
2888 };\r
2889 \r
2890 void(entity Item) tfgoalitem_checkgoalreturn = \r
2891 {\r
2892         local entity te;\r
2893         if (Item.impulse != 0)\r
2894         {\r
2895                 te = Findgoal(Item.impulse);\r
2896                 if (te)\r
2897                 {\r
2898                         te = Findgoal(Item.impulse);\r
2899                         if (te)\r
2900                         {\r
2901                                 AttemptToActivate(te, world, Item);\r
2902                         }\r
2903                 }\r
2904         }\r
2905 };\r
2906 \r
2907 void(entity Goal, entity Player, entity Item) DisplayItemStatus = \r
2908 {\r
2909         if (Item.goal_state == 1)\r
2910         {\r
2911                 if (Player.team_no == Item.owned_by)\r
2912                 {\r
2913                         sprint(Player,Goal.team_str_carried);\r
2914                 }\r
2915                 else\r
2916                 {\r
2917                         sprint(Player,Goal.non_team_str_carried);\r
2918                 }\r
2919                 sprint(Player," ");\r
2920                 if (Player == Item.owner)\r
2921                 {\r
2922                         sprint(Player," You");\r
2923                 }\r
2924                 else\r
2925                 {\r
2926                         sprint(Player,Item.owner.netname);\r
2927                 }\r
2928                 sprint(Player,".");\r
2929         }\r
2930         else\r
2931         {\r
2932                 if (Item.origin != Item.oldorigin)\r
2933                 {\r
2934                         if (Player.team_no == Item.owned_by)\r
2935                         {\r
2936                                 sprint(Player,Goal.team_str_moved);\r
2937                         }\r
2938                         else\r
2939                         {\r
2940                                 sprint(Player,Goal.non_team_str_moved);\r
2941                         }\r
2942                 }\r
2943                 else\r
2944                 {\r
2945                         if (Player.team_no == Item.owned_by)\r
2946                         {\r
2947                                 sprint(Player,Goal.team_str_home);\r
2948                         }\r
2949                         else\r
2950                         {\r
2951                                 sprint(Player,Goal.non_team_str_home);\r
2952                         }\r
2953                 }\r
2954         }\r
2955         sprint(Player,"\n");\r
2956 };\r
2957 \r
2958 void() info_player_team1 = \r
2959 {\r
2960         CTF_Map = 1;\r
2961         self.classname = "info_player_teamspawn";\r
2962         self.team_no = 2;\r
2963         self.goal_effects = 1;\r
2964         self.team_str_home = "ts2";\r
2965 };\r
2966 \r
2967 void() info_player_team2 = \r
2968 {\r
2969         CTF_Map = 1;\r
2970         self.classname = "info_player_teamspawn";\r
2971         self.team_no = 1;\r
2972         self.goal_effects = 1;\r
2973         self.team_str_home = "ts1";\r
2974 };\r
2975 \r
2976 void() info_player_team3 = \r
2977 {\r
2978         CTF_Map = 1;\r
2979         self.classname = "info_player_teamspawn";\r
2980         self.team_no = 3;\r
2981         self.goal_effects = 1;\r
2982         self.team_str_home = "ts3";\r
2983 };\r
2984 \r
2985 void() info_player_team4 = \r
2986 {\r
2987         CTF_Map = 1;\r
2988         self.classname = "info_player_teamspawn";\r
2989         self.team_no = 4;\r
2990         self.goal_effects = 1;\r
2991         self.team_str_home = "ts4";\r
2992 };\r
2993 \r
2994 void () item_ctf_flag;          // Team:Nexuiz CTF flag\r
2995 void () item_ctf_goal;          // Team:Nexuiz CTF goal\r
2996 void() item_flag_team2 = \r
2997 {\r
2998         team2maxplayers = 4;            //TEMP\r
2999         number_of_teams = 2;\r
3000 \r
3001         CTF_Map = 1;\r
3002 \r
3003         local entity egl;\r
3004         egl = spawn();\r
3005         setorigin(egl, self.origin);\r
3006         egl.allowteams = "red";\r
3007         egl.think = item_ctf_goal;\r
3008         egl.nextthink = time + 0.2;\r
3009         \r
3010         self.allowteams = "red";\r
3011         self.model = "models/flags/b_flag.md3";\r
3012         item_ctf_flag();\r
3013 /*\r
3014         local entity dp;\r
3015         precache_model("progs/w_s_key.mdl");\r
3016         precache_sound("ogre/ogwake.wav");\r
3017         precache_sound("boss2/pop2.wav");\r
3018         self.classname = "item_tfgoal";\r
3019         self.netname = "Team 1 Flag";\r
3020         self.broadcast = " ÇÏÔ the enemy team's flag!\n";\r
3021         self.deathtype = "You've got the enemy flag!\n";\r
3022         self.noise = "ogre/ogwake.wav";\r
3023         self.mdl = "progs/tf_flag.mdl";\r
3024         self.skin = 0;\r
3025         setmodel(self, self.mdl);\r
3026         self.goal_no = 1;\r
3027         self.goal_activation = 1 | 4 | 128 | 32 | 16 | 512;\r
3028         self.goal_effects = 1;\r
3029         self.pausetime = 128;\r
3030         setsize(self, '-16 -16 -24', '16 16 32');\r
3031         self.touch = item_tfgoal_touch;\r
3032         self.goal_state = 2;\r
3033         self.solid = 1;\r
3034         setorigin(self, self.origin);\r
3035         self.nextthink = time + 0.2;\r
3036         self.think = TF_PlaceItem;\r
3037         dp = spawn();\r
3038         dp.origin = self.origin;\r
3039         dp.classname = "info_tfgoal";\r
3040         dp.goal_activation = 1;\r
3041         dp.team_no = 1;\r
3042         dp.items_allowed = 2;\r
3043         dp.goal_no = 3;\r
3044         dp.goal_effects = 3;\r
3045         dp.broadcast = " ÃÁÐÔÕÒÅÄ the enemy flag!\n";\r
3046         dp.message = "You ÃÁÐÔÕÒÅÄ the enemy flag!\n";\r
3047         dp.noise = "boss2/pop2.wav";\r
3048         dp.goal_result = 2;\r
3049         dp.activate_goal_no = 5;\r
3050         dp.axhitme = 2;\r
3051         dp.count = 10;\r
3052         dp.frags = 10;\r
3053         dp.solid = 1;\r
3054         dp.goal_state = 2;\r
3055         setsize(dp, '-16 -16 -24', '16 16 32');\r
3056         dp.nextthink = time + 0.2;\r
3057         dp.think = TF_PlaceGoal;\r
3058         dp = spawn();\r
3059         dp.origin = dp.origin;\r
3060         dp.classname = "info_tfgoal";\r
3061         dp.goal_effects = 1;\r
3062         dp.frags = 5;\r
3063         dp.goal_activation = 0;\r
3064         dp.goal_no = 5;\r
3065         dp.solid = 0;\r
3066         dp.goal_state = 2;\r
3067         setsize(dp, '-16 -16 -24', '16 16 32');\r
3068         dp.nextthink = time + 0.2;\r
3069         dp.think = TF_PlaceGoal;*/\r
3070 };\r
3071 \r
3072 void() item_flag_team1 = \r
3073 {\r
3074         team1maxplayers = 4;            //TEMP\r
3075         CTF_Map = 1;\r
3076 \r
3077         local entity egl;\r
3078         egl = spawn();\r
3079         setorigin(egl, self.origin);\r
3080         egl.allowteams = "blue";\r
3081         egl.think = item_ctf_goal;\r
3082         egl.nextthink = time + 0.2;\r
3083 \r
3084         self.model = "models/flags/r_flag.md3";\r
3085         self.allowteams = "blue";\r
3086         item_ctf_flag();\r
3087 /*\r
3088         precache_model("progs/tf_flag.mdl");\r
3089         precache_sound("ogre/ogwake.wav");\r
3090         precache_sound("boss2/pop2.wav");\r
3091         self.classname = "item_tfgoal";\r
3092         self.netname = "Team 2 Flag";\r
3093         self.broadcast = " ÇÏÔ the enemy team's flag!\n";\r
3094         self.deathtype = "You've got the enemy flag!\n";\r
3095         self.noise = "ogre/ogwake.wav";\r
3096         self.mdl = "progs/tf_flag.mdl";\r
3097         setmodel(self, self.mdl);\r
3098         self.skin = 1;\r
3099         self.goal_no = 2;\r
3100         self.goal_activation = 1 | 4 | 128 | 32 | 16 | 512;\r
3101         self.goal_effects = 1;\r
3102         self.pausetime = 128;\r
3103         setsize(self, '-16 -16 -24', '16 16 32');\r
3104         self.touch = item_tfgoal_touch;\r
3105         self.goal_state = 2;\r
3106         self.solid = 1;\r
3107         setorigin(self, self.origin);\r
3108         self.nextthink = time + 0.2;\r
3109         self.think = TF_PlaceItem;\r
3110         dp = spawn();\r
3111         dp.origin = self.origin;\r
3112         dp.classname = "info_tfgoal";\r
3113         dp.goal_activation = 1;\r
3114         dp.team_no = 2;\r
3115         dp.items_allowed = 1;\r
3116         dp.goal_no = 4;\r
3117         dp.goal_effects = 3;\r
3118         dp.broadcast = " ÃÁÐÔÕÒÅÄ the enemy flag!\n";\r
3119         dp.message = "You ÃÁÐÔÕÒÅÄ the enemy flag!\n";\r
3120         dp.noise = "boss2/pop2.wav";\r
3121         dp.goal_result = 2;\r
3122         dp.activate_goal_no = 6;\r
3123         dp.axhitme = 1;\r
3124         dp.count = 10;\r
3125         dp.frags = 10;\r
3126         dp.solid = 1;\r
3127         dp.goal_state = 2;\r
3128         setsize(dp, '-16 -16 -24', '16 16 32');\r
3129         dp.nextthink = time + 0.2;\r
3130         dp.think = TF_PlaceGoal;\r
3131         dp = spawn();\r
3132         dp.origin = dp.origin;\r
3133         dp.classname = "info_tfgoal";\r
3134         dp.goal_effects = 1;\r
3135         dp.frags = 5;\r
3136         dp.goal_activation = 0;\r
3137         dp.goal_no = 6;\r
3138         dp.solid = 0;\r
3139         dp.goal_state = 2;\r
3140         setsize(dp, '-16 -16 -24', '16 16 32');\r
3141         dp.nextthink = time + 0.2;\r
3142         dp.think = TF_PlaceGoal;*/\r
3143 };\r
3144 \r
3145 void() CTF_FlagCheck = \r
3146 {\r
3147         local entity te;\r
3148         local float flagcount;\r
3149         local float pos;\r
3150         flagcount = 0;\r
3151         te = find(world, classname, "item_tfgoal");\r
3152         while (te != world)\r
3153         {\r
3154                 if (te.goal_no == 1)\r
3155                 {\r
3156                         pos = pointcontents(te.origin);\r
3157                         if (pos == -2 || pos == -6)\r
3158                         {\r
3159                                 dprint("*****BUG*****\nFlag(s) outside world.\nPlease report this.\n");\r
3160                                 te.nextthink = time + 0.2;\r
3161                                 te.think = tfgoalitem_remove;\r
3162                         }\r
3163                         flagcount = flagcount + 1;\r
3164                 }\r
3165                 else\r
3166                 {\r
3167                         if (te.goal_no == 2)\r
3168                         {\r
3169                                 pos = pointcontents(te.origin);\r
3170                                 if (pos == -2 || pos == -6)\r
3171                                 {\r
3172                                         dprint("*****BUG*****\nFlag(s) outside world.\nPlease report this.\n");\r
3173                                         te.nextthink = time + 0.2;\r
3174                                         te.think = tfgoalitem_remove;\r
3175                                 }\r
3176                                 flagcount = flagcount + 1;\r
3177                         }\r
3178                 }\r
3179                 te = find(te, classname, "item_tfgoal");\r
3180         }\r
3181         if (flagcount != 2)\r
3182         {\r
3183                 dprint("*****BUG*****\nFlag(s) missing.\nPlease report this.\n");\r
3184         }\r
3185         self.nextthink = time + 30;\r
3186 };