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