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