]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/miscfunctions.qc
update extensions.qh;
[divverent/nexuiz.git] / data / qcsrc / server / miscfunctions.qc
1 void() info_player_deathmatch; // needed for the other spawnpoints
2 string ColoredTeamName(float t);
3
4 float DistributeEvenly_amount;
5 float DistributeEvenly_totalweight;
6 void DistributeEvenly_Init(float amount, float totalweight)
7 {
8         if(DistributeEvenly_amount)
9         {
10                 dprint("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
11                 dprint(ftos(DistributeEvenly_totalweight), " left!)\n");
12         }
13         if(totalweight == 0)
14                 DistributeEvenly_amount = 0;
15         else
16                 DistributeEvenly_amount = amount;
17         DistributeEvenly_totalweight = totalweight;
18 }
19 float DistributeEvenly_Get(float weight)
20 {
21         float f;
22         if(weight <= 0)
23                 return 0;
24         f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
25         DistributeEvenly_totalweight -= weight;
26         DistributeEvenly_amount -= f;
27         return f;
28 }
29
30 void move_out_of_solid_expand(entity e, vector by)
31 {
32         float eps = 0.0625;
33         tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
34         if(trace_startsolid)
35                 return;
36         if(trace_fraction < 1)
37         {
38                 // hit something
39                 // adjust origin in the other direction...
40                 e.origin = e.origin - by * (1 - trace_fraction);
41         }
42 }
43
44 void move_out_of_solid(entity e)
45 {
46         vector o, m0, m1;
47
48         o = e.origin;
49         traceline(o, o, MOVE_WORLDONLY, e);
50         if(trace_startsolid)
51         {
52                 dprint("origin is in solid too! (", vtos(o), ")");
53                 return;
54         }
55
56         tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
57         if(!trace_startsolid)
58                 return;
59
60         m0 = e.mins;
61         m1 = e.maxs;
62         e.mins = '0 0 0';
63         e.maxs = '0 0 0';
64         move_out_of_solid_expand(e, '1 0 0' * m0_x); e.mins_x = m0_x;
65         move_out_of_solid_expand(e, '1 0 0' * m1_x); e.maxs_x = m1_x;
66         move_out_of_solid_expand(e, '0 1 0' * m0_y); e.mins_y = m0_y;
67         move_out_of_solid_expand(e, '0 1 0' * m1_y); e.maxs_y = m1_y;
68         move_out_of_solid_expand(e, '0 0 1' * m0_z); e.mins_z = m0_z;
69         move_out_of_solid_expand(e, '0 0 1' * m1_z); e.maxs_z = m1_z;
70         setorigin(e, e.origin);
71
72         tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
73         if(trace_startsolid)
74         {
75                 dprint("could not get out of solid (", vtos(o), ")\n");
76                 return;
77         }
78 }
79
80 // converts a number to a string with the indicated number of decimals
81 // works for up to 10 decimals!
82 string ftos_decimals(float number, float decimals)
83 {
84         string result;
85         string tmp;
86         float len;
87
88         // if negative, cut off the sign first
89         if(number < 0)
90                 return strcat("-", ftos_decimals(-number, decimals));
91         // it now is always positive!
92
93         // 3.516 -> 352
94         number = floor(number * pow(10, decimals) + 0.5);
95
96         // 352 -> "352"
97         result = ftos(number);
98         len = strlen(result);
99         // does it have a decimal point (should not happen)? If there is one, it is always at len-7)
100                 // if ftos had fucked it up, which should never happen: "34278.000000"
101         if(len >= 7)
102                 if(substring(result, len - 7, 1) == ".")
103                 {
104                         dprint("ftos(integer) has comma? Can't be. Affected result: ", result, "\n");
105                         result = substring(result, 0, len - 7);
106                         len -= 7;
107                 }
108                 // "34278"
109         // is it too short? If yes, insert leading zeroes
110         if(len <= decimals)
111         {
112                 result = strcat(substring("0000000000", 0, decimals - len + 1), result);
113                 len = decimals + 1;
114         }
115         // and now... INSERT THE POINT!
116         tmp = substring(result, len - decimals, decimals);
117         result = strcat(substring(result, 0, len - decimals), ".", tmp);
118         return result;
119 }
120
121 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
122 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
123 string STR_PLAYER = "player";
124 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
125 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
126
127 // change that to actually calling strcat when running on an engine without
128 // unlimited tempstrings:
129 // string strcat1(string s) = #115; // FRIK_FILE
130 #define strcat1(s) (s)
131
132 float logfile_open;
133 float logfile;
134
135 void(string s) bcenterprint
136 {
137         // TODO replace by MSG_ALL (would show it to spectators too, though)?
138         entity head;
139         FOR_EACH_PLAYER(head)
140                 if(clienttype(head) == CLIENTTYPE_REAL)
141                         centerprint(head, s);
142 }
143
144 void(string s, float check_dangerous) ServerConsoleEcho =
145 {
146         local string ch;
147         if (checkextension("DP_SV_PRINT"))
148                 print(s, "\n");
149         else
150         {
151                 localcmd("echo \"");
152                 if(check_dangerous)
153                 {
154                         while(strlen(s))
155                         {
156                                 ch = substring(s, 0, 1);
157                                 if(ch != "\"" && ch != "\r" && ch != "\n")
158                                         localcmd(ch);
159                                 s = substring(s, 1, strlen(s) - 1);
160                         }
161                 }
162                 else
163                 {
164                         localcmd(s);
165                 }
166                 localcmd("\"\n");
167         }
168 }
169
170 void(string s, float check_dangerous) GameLogEcho =
171 {
172         string fn;
173         float matches;
174
175         if(cvar("sv_eventlog_files"))
176         {
177                 if(!logfile_open)
178                 {
179                         logfile_open = TRUE;
180                         matches = cvar("sv_eventlog_files_counter") + 1;
181                         cvar_set("sv_eventlog_files_counter", ftos(matches));
182                         fn = ftos(matches);
183                         if(strlen(fn) < 8)
184                                 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
185                         fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
186                         logfile = fopen(fn, FILE_APPEND);
187                 }
188                 if(logfile >= 0)
189                         fputs(logfile, strcat(s, "\n"));
190         }
191         if(cvar("sv_eventlog_console"))
192         {
193                 ServerConsoleEcho(s, check_dangerous);
194         }
195 }
196
197 void() GameLogInit =
198 {
199         logfile_open = 0;
200         // will be opened later
201 }
202
203 void() GameLogClose =
204 {
205         if(logfile_open && logfile >= 0)
206         {
207                 fclose(logfile);
208                 logfile = -1;
209         }
210 }
211
212 float math_mod(float a, float b)
213 {
214         return a - (floor(a / b) * b);
215 }
216
217 void relocate_spawnpoint()
218 {
219         // nudge off the floor
220         setorigin(self, self.origin + '0 0 1');
221
222         tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
223         if (trace_startsolid)
224         {
225                 objerror("player spawn point in solid, mapper sucks!\n");
226                 return;
227         }
228
229         if(cvar("g_spawnpoints_autodrop"))
230         {
231                 setsize(self, PL_MIN, PL_MAX);
232                 droptofloor();
233         }
234 }
235
236 #define strstr strstrofs
237 /*
238 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
239 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
240 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
241 // BE CONSTANT OR strzoneD!
242 float(string haystack, string needle, float offset) strstr =
243 {
244         float len, endpos;
245         string found;
246         len = strlen(needle);
247         endpos = strlen(haystack) - len;
248         while(offset <= endpos)
249         {
250                 found = substring(haystack, offset, len);
251                 if(found == needle)
252                         return offset;
253                 offset = offset + 1;
254         }
255         return -1;
256 }
257 */
258
259 float NUM_NEAREST_ENTITIES = 4;
260 entity nearest_entity[NUM_NEAREST_ENTITIES];
261 float nearest_length[NUM_NEAREST_ENTITIES];
262 entity(vector point, .string field, string value, vector axismod) findnearest =
263 {
264         entity localhead;
265         float i;
266         float j;
267         float len;
268         vector dist;
269
270         float num_nearest;
271         num_nearest = 0;
272
273         localhead = find(world, field, value);
274         while(localhead)
275         {
276                 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
277                         dist = localhead.oldorigin;
278                 else
279                         dist = localhead.origin;
280                 dist = dist - point;
281                 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
282                 len = vlen(dist);
283
284                 for(i = 0; i < num_nearest; ++i)
285                 {
286                         if(len < nearest_length[i])
287                                 break;
288                 }
289
290                 // now i tells us where to insert at
291                 //   INSERTION SORT! YOU'VE SEEN IT! RUN!
292                 if(i < NUM_NEAREST_ENTITIES)
293                 {
294                         for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
295                         {
296                                 nearest_length[j + 1] = nearest_length[j];
297                                 nearest_entity[j + 1] = nearest_entity[j];
298                         }
299                         nearest_length[i] = len;
300                         nearest_entity[i] = localhead;
301                         if(num_nearest < NUM_NEAREST_ENTITIES)
302                                 num_nearest = num_nearest + 1;
303                 }
304
305                 localhead = find(localhead, field, value);
306         }
307
308         // now use the first one from our list that we can see
309         for(i = 0; i < num_nearest; ++i)
310         {
311                 traceline(point, nearest_entity[i].origin, TRUE, world);
312                 if(trace_fraction == 1)
313                 {
314                         if(i != 0)
315                         {
316                                 dprint("Nearest point (");
317                                 dprint(nearest_entity[0].netname);
318                                 dprint(") is not visible, using a visible one.\n");
319                         }
320                         return nearest_entity[i];
321                 }
322         }
323
324         if(num_nearest == 0)
325                 return world;
326
327         dprint("Not seeing any location point, using nearest as fallback.\n");
328         /* DEBUGGING CODE:
329         dprint("Candidates were: ");
330         for(j = 0; j < num_nearest; ++j)
331         {
332                 if(j != 0)
333                         dprint(", ");
334                 dprint(nearest_entity[j].netname);
335         }
336         dprint("\n");
337         */
338
339         return nearest_entity[0];
340 }
341
342 void() target_location =
343 {
344         self.classname = "target_location";
345         // location name in netname
346         // eventually support: count, teamgame selectors, line of sight?
347 };
348
349 void() info_location =
350 {
351         self.classname = "target_location";
352         self.message = self.netname;
353 };
354
355 string NearestLocation(vector p)
356 {
357         entity loc;
358         string ret;
359         ret = "somewhere";
360         loc = findnearest(p, classname, "target_location", '1 1 1');
361         if(loc)
362         {
363                 ret = loc.message;
364         }
365         else
366         {
367                 loc = findnearest(p, target, "###item###", '1 1 4');
368                 if(loc)
369                         ret = loc.netname;
370         }
371         return ret;
372 }
373
374 string(string msg) formatmessage =
375 {
376         float p;
377         float n;
378         string msg_save;
379         string escape;
380         string replacement;
381         msg_save = strzone(msg);
382         p = 0;
383         n = 7;
384         while(1)
385         {
386                 if(n < 1)
387                         break; // too many replacements
388                 n = n - 1;
389                 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
390                 if(p < 0)
391                         break;
392                 replacement = substring(msg_save, p, 2);
393                 escape = substring(msg_save, p + 1, 1);
394                 if(escape == "%")
395                         replacement = "%";
396                 else if(escape == "a")
397                         replacement = ftos(floor(self.armorvalue));
398                 else if(escape == "h")
399                         replacement = ftos(floor(self.health));
400                 else if(escape == "l")
401                         replacement = NearestLocation(self.origin);
402                 else if(escape == "y")
403                         replacement = NearestLocation(self.cursor_trace_endpos);
404                 else if(escape == "d")
405                         replacement = NearestLocation(self.death_origin);
406                 else if(escape == "w")
407                 {
408                         float wep;
409                         wep = self.weapon;
410                         if(!wep)
411                                 wep = self.switchweapon;
412                         if(!wep)
413                                 wep = self.cnt;
414                         replacement = W_Name(wep);
415                 }
416                 else if(escape == "W")
417                 {
418                         if(self.items & IT_SHELLS) replacement = "shells";
419                         else if(self.items & IT_NAILS) replacement = "bullets";
420                         else if(self.items & IT_ROCKETS) replacement = "rockets";
421                         else if(self.items & IT_CELLS) replacement = "cells";
422                         else replacement = "batteries"; // ;)
423                 }
424                 else if(escape == "x")
425                 {
426                         replacement = self.cursor_trace_ent.netname;
427                         if(!replacement || !self.cursor_trace_ent)
428                                 replacement = "nothing";
429                 }
430                 else if(escape == "p")
431                 {
432                         if(self.last_selected_player)
433                                 replacement = self.last_selected_player.netname;
434                         else
435                                 replacement = "(nobody)";
436                 }
437                 msg = strcat(substring(msg_save, 0, p), replacement);
438                 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
439                 strunzone(msg_save);
440                 msg_save = strzone(msg);
441                 p = p + 2;
442         }
443         msg = strcat(msg_save, "");
444         strunzone(msg_save);
445         return msg;
446 }
447
448 /*
449 =============
450 GetCvars
451 =============
452 Called with:
453   0:  sends the request
454   >0: receives a cvar from name=argv(f) value=argv(f+1)
455 */
456 void GetCvars_handleString(float f, .string field, string name)
457 {
458         if(f < 0)
459         {
460                 if(self.field)
461                         strunzone(self.field);
462         }
463         else if(f > 0)
464         {
465                 if(argv(f) == name)
466                 {
467                         if(self.field)
468                                 strunzone(self.field);
469                         self.field = strzone(argv(f + 1));
470                 }
471         }
472         else
473                 stuffcmd(self, strcat("sendcvar ", name, "\n"));
474 }
475 void GetCvars_handleFloat(float f, .float field, string name)
476 {
477         if(f < 0)
478         {
479         }
480         else if(f > 0)
481         {
482                 if(argv(f) == name)
483                         self.field = stof(argv(f + 1));
484         }
485         else
486                 stuffcmd(self, strcat("sendcvar ", name, "\n"));
487 }
488 void GetCvars(float f)
489 {
490         GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
491         GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
492         GetCvars_handleFloat(f, cvar_cl_zoomfactor, "cl_zoomfactor");
493         GetCvars_handleFloat(f, cvar_cl_zoomspeed, "cl_zoomspeed");
494         GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
495         GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
496         GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
497         GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
498         GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
499         GetCvars_handleFloat(f, cvar_cl_handicap, "cl_handicap");
500 }
501
502 float fexists(string f)
503 {
504         float fh;
505         fh = fopen(f, FILE_READ);
506         if(fh < 0)
507                 return FALSE;
508         fclose(fh);
509         return TRUE;
510 }
511
512 void backtrace(string msg)
513 {
514         float dev;
515         dev = cvar("developer");
516         cvar_set("developer", "1");
517         dprint("\n");
518         dprint("--- CUT HERE ---\nWARNING: ");
519         dprint(msg);
520         dprint("\n");
521         remove(world); // isn't there any better way to cause a backtrace?
522         dprint("\n--- CUT UNTIL HERE ---\n");
523         cvar_set("developer", ftos(dev));
524 }
525
526 void DistributeFragsAmongTeam(entity p, float targetteam, float factor)
527 {
528         float nTeam;
529         entity head;
530         float f;
531
532         if(!teams_matter)
533                 return;
534
535         //if(p.frags < 0)
536         //{
537         //      p.frags = 0; // do not harm the new team!
538         //      return; // won't distribute negative scores
539         //}
540
541         if(p.frags == -666)
542                 return;
543
544         f = ceil(factor * p.frags);
545         p.frags = p.frags - f;
546
547         nTeam = 0;
548         FOR_EACH_PLAYER(head)
549                 if(head != p)
550                         if(head.team == targetteam)
551                                 nTeam = nTeam + 1;
552
553         if(nTeam == 0)
554                 return;
555
556         DistributeEvenly_Init(f, nTeam);
557
558         FOR_EACH_PLAYER(head)
559                 if(head != p)
560                         if(head.team == targetteam)
561                                 head.frags = head.frags + DistributeEvenly_Get(1);
562 }
563
564 string Team_ColorCode(float teamid)
565 {
566         if(teamid == COLOR_TEAM1)
567                 return "^1";
568         else if(teamid == COLOR_TEAM2)
569                 return "^4";
570         else if(teamid == COLOR_TEAM3)
571                 return "^3";
572         else if(teamid == COLOR_TEAM4)
573                 return "^6";
574         else
575                 return "^7";
576 }
577
578 /*
579 string decolorize(string s)
580 {
581         string out;
582         out = "";
583         while(s != "")
584         {
585                 float n;
586                 string ch1, ch2;
587                 n = 1;
588                 ch1 = substring(s, 0, 1);
589                 ch2 = substring(s, 1, 1);
590                 if(ch1 == "^")
591                 {
592                         n = 2;
593                         if(ch2 == "^")
594                                 out = strcat(out, "^^");
595                         else if(ch2 == "0")
596                                 out = strcat1(out);
597                         else if(ch2 == "1")
598                                 out = strcat1(out);
599                         else if(ch2 == "2")
600                                 out = strcat1(out);
601                         else if(ch2 == "3")
602                                 out = strcat1(out);
603                         else if(ch2 == "4")
604                                 out = strcat1(out);
605                         else if(ch2 == "5")
606                                 out = strcat1(out);
607                         else if(ch2 == "6")
608                                 out = strcat1(out);
609                         else if(ch2 == "7")
610                                 out = strcat1(out);
611                         else if(ch2 == "8")
612                                 out = strcat1(out);
613                         else if(ch2 == "9")
614                                 out = strcat1(out);
615                         else
616                         {
617                                 n = 1;
618                                 out = strcat(out, "^^");
619                         }
620                         s = substring(s, n, strlen(s) - n);
621                 }
622                 else
623                 {
624                         s = substring(s, 1, strlen(s) - 1);
625                         out = strcat(out, ch1);
626                 }
627         }
628         return out;
629 }
630 #define strdecolorize(s) decolorize(s)
631 #define strlennocol(s) strlen(decolorize(s))
632 */
633
634 #define CENTERPRIO_POINT 1
635 #define CENTERPRIO_SPAM 2
636 #define CENTERPRIO_REBALANCE 2
637 #define CENTERPRIO_VOTE 4
638 #define CENTERPRIO_NORMAL 5
639 #define CENTERPRIO_MAPVOTE 9
640 #define CENTERPRIO_ADMIN 99
641 .float centerprint_priority;
642 .float centerprint_expires;
643 void centerprint_atprio(entity e, float prio, string s)
644 {
645         if(intermission_running)
646                 if(prio < CENTERPRIO_MAPVOTE)
647                         return;
648         if(time > e.centerprint_expires)
649                 e.centerprint_priority = 0;
650         if(prio >= e.centerprint_priority)
651         {
652                 e.centerprint_priority = prio;
653                 e.centerprint_expires = time + e.cvar_scr_centertime;
654                 centerprint_builtin(e, s);
655         }
656 }
657 void centerprint_expire(entity e, float prio)
658 {
659         if(prio == e.centerprint_priority)
660         {
661                 e.centerprint_priority = 0;
662                 centerprint_builtin(e, "");
663         }
664 }
665 void centerprint(entity e, string s)
666 {
667         centerprint_atprio(e, CENTERPRIO_NORMAL, s);
668 }
669
670 void VoteNag();
671
672 // decolorizes and team colors the player name when needed
673 string playername(entity p)
674 {
675         string t;
676         if(teams_matter && !intermission_running && p.classname == "player")
677         {
678                 t = Team_ColorCode(p.team);
679                 return strcat(t, strdecolorize(p.netname));
680         }
681         else
682                 return p.netname;
683 }
684
685 vector(vector m1, vector m2) randompos =
686 {
687         local vector v;
688         m2 = m2 - m1;
689         v_x = m2_x * random() + m1_x;
690         v_y = m2_y * random() + m1_y;
691         v_z = m2_z * random() + m1_z;
692         return  v;
693 };
694
695 // requires that m2>m1 in all coordinates, and that m4>m3
696 float(vector m1, vector m2, vector m3, vector m4) boxesoverlap = {return m2_x >= m3_x && m1_x <= m4_x && m2_y >= m3_y && m1_y <= m4_y && m2_z >= m3_z && m1_z <= m4_z;};
697
698 // requires the same, but is a stronger condition
699 float(vector smins, vector smaxs, vector bmins, vector bmaxs) boxinsidebox = {return smins_x >= bmins_x && smaxs_x <= bmaxs_x && smins_y >= bmins_y && smaxs_y <= bmaxs_y && smins_z >= bmins_z && smaxs_z <= bmaxs_z;};
700
701 float g_pickup_shells;
702 float g_pickup_shells_max;
703 float g_pickup_nails;
704 float g_pickup_nails_max;
705 float g_pickup_rockets;
706 float g_pickup_rockets_max;
707 float g_pickup_cells;
708 float g_pickup_cells_max;
709 float g_pickup_armorshard;
710 float g_pickup_armorshard_max;
711 float g_pickup_armor;
712 float g_pickup_armor_max;
713 float g_pickup_healthshard;
714 float g_pickup_healthshard_max;
715 float g_pickup_health;
716 float g_pickup_health_max;
717 float g_pickup_healthmega;
718 float g_pickup_healthmega_max;
719
720 float start_items;
721 float start_switchweapon;
722 float start_ammo_shells;
723 float start_ammo_nails;
724 float start_ammo_rockets;
725 float start_ammo_cells;
726 float start_health;
727 float start_armorvalue;
728
729 void readlevelcvars(void)
730 {
731         g_pickup_shells                    = cvar("g_pickup_shells");
732         g_pickup_shells_max                = cvar("g_pickup_shells_max");
733         g_pickup_nails                     = cvar("g_pickup_nails");
734         g_pickup_nails_max                 = cvar("g_pickup_nails_max");
735         g_pickup_rockets                   = cvar("g_pickup_rockets");
736         g_pickup_rockets_max               = cvar("g_pickup_rockets_max");
737         g_pickup_cells                     = cvar("g_pickup_cells");
738         g_pickup_cells_max                 = cvar("g_pickup_cells_max");
739         g_pickup_armorshard                = cvar("g_pickup_armorshard");
740         g_pickup_armorshard_max            = cvar("g_pickup_armorshard_max");
741         g_pickup_armor                     = cvar("g_pickup_armor");
742         g_pickup_armor_max                 = cvar("g_pickup_armor_max");
743         g_pickup_healthshard               = cvar("g_pickup_healthshard");
744         g_pickup_healthshard_max           = cvar("g_pickup_healthshard_max");
745         g_pickup_health                    = cvar("g_pickup_health");
746         g_pickup_health_max                = cvar("g_pickup_health_max");
747         g_pickup_healthmega                = cvar("g_pickup_healthmega");
748         g_pickup_healthmega_max            = cvar("g_pickup_healthmega_max");
749
750         // initialize starting values for players
751         start_items = 0;
752         start_switchweapon = 0;
753         start_ammo_shells = 0;
754         start_ammo_nails = 0;
755         start_ammo_rockets = 0;
756         start_ammo_cells = 0;
757         start_health = cvar("g_balance_health_start");
758         start_armorvalue = cvar("g_balance_armor_start");
759
760         if(cvar("g_instagib"))
761         {
762                 start_items = IT_NEX;
763                 start_switchweapon = WEP_NEX;
764                 weapon_action(start_switchweapon, WR_PRECACHE);
765                 start_ammo_cells = 999;
766         }
767         else if(cvar("g_rocketarena"))
768         {
769                 start_items = IT_ROCKET_LAUNCHER;
770                 start_switchweapon = WEP_ROCKET_LAUNCHER;
771                 weapon_action(start_switchweapon, WR_PRECACHE);
772                 start_ammo_rockets = 999;
773         }
774         else if(cvar("g_nixnex"))
775         {
776                 start_items = 0;
777                 // will be done later
778         }
779         else if(cvar("g_minstagib"))
780         {
781                 start_health = 100;
782                 start_armorvalue = 0;
783                 start_items = IT_NEX;
784                 start_switchweapon = WEP_NEX;
785                 weapon_action(start_switchweapon, WR_PRECACHE);
786                 start_ammo_cells = cvar("g_minstagib_ammo_start");
787         }
788         else
789         {
790                 if(cvar("g_lms"))
791                 {
792                         start_ammo_shells = cvar("g_lms_start_ammo_shells");
793                         start_ammo_nails = cvar("g_lms_start_ammo_nails");
794                         start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
795                         start_ammo_cells = cvar("g_lms_start_ammo_cells");
796                         start_health = cvar("g_lms_start_health");
797                         start_armorvalue = cvar("g_lms_start_armor");
798                 }
799                 else if (cvar("g_use_ammunition")) {
800                         start_ammo_shells = cvar("g_start_ammo_shells");
801                         start_ammo_nails = cvar("g_start_ammo_nails");
802                         start_ammo_rockets = cvar("g_start_ammo_rockets");
803                         start_ammo_cells = cvar("g_start_ammo_cells");
804                 } else {
805                         start_ammo_shells = cvar("g_pickup_shells_max");
806                         start_ammo_nails = cvar("g_pickup_nails_max");
807                         start_ammo_rockets = cvar("g_pickup_rockets_max");
808                         start_ammo_cells = cvar("g_pickup_cells_max");
809                 }
810
811                 if (cvar("g_start_weapon_laser") || cvar("g_lms"))
812                 {
813                         start_items = start_items | IT_LASER;
814                         start_switchweapon = WEP_LASER;
815                         weapon_action(start_switchweapon, WR_PRECACHE);
816                 }
817                 if (cvar("g_start_weapon_shotgun") || cvar("g_lms"))
818                 {
819                         start_items = start_items | IT_SHOTGUN;
820                         start_switchweapon = WEP_SHOTGUN;
821                         weapon_action(start_switchweapon, WR_PRECACHE);
822                 }
823                 if (cvar("g_start_weapon_uzi") || cvar("g_lms"))
824                 {
825                         start_items = start_items | IT_UZI;
826                         start_switchweapon = WEP_UZI;
827                         weapon_action(start_switchweapon, WR_PRECACHE);
828                 }
829                 if (cvar("g_start_weapon_grenadelauncher") || cvar("g_lms"))
830                 {
831                         start_items = start_items | IT_GRENADE_LAUNCHER;
832                         start_switchweapon = WEP_GRENADE_LAUNCHER;
833                         weapon_action(start_switchweapon, WR_PRECACHE);
834                 }
835                 if (cvar("g_start_weapon_electro") || cvar("g_lms"))
836                 {
837                         start_items = start_items | IT_ELECTRO;
838                         start_switchweapon = WEP_ELECTRO;
839                         weapon_action(start_switchweapon, WR_PRECACHE);
840                 }
841                 if (cvar("g_start_weapon_crylink") || cvar("g_lms"))
842                 {
843                         start_items = start_items | IT_CRYLINK;
844                         start_switchweapon = WEP_CRYLINK;
845                         weapon_action(start_switchweapon, WR_PRECACHE);
846                 }
847                 if (cvar("g_start_weapon_nex") || cvar("g_lms"))
848                 {
849                         start_items = start_items | IT_NEX;
850                         start_switchweapon = WEP_NEX;
851                         weapon_action(start_switchweapon, WR_PRECACHE);
852                 }
853                 if (cvar("g_start_weapon_hagar") || cvar("g_lms"))
854                 {
855                         start_items = start_items | IT_HAGAR;
856                         start_switchweapon = WEP_HAGAR;
857                         weapon_action(start_switchweapon, WR_PRECACHE);
858                 }
859                 if (cvar("g_start_weapon_rocketlauncher") || cvar("g_lms"))
860                 {
861                         start_items = start_items | IT_ROCKET_LAUNCHER;
862                         start_switchweapon = WEP_ROCKET_LAUNCHER;
863                         weapon_action(start_switchweapon, WR_PRECACHE);
864                 }
865         }
866 }
867
868 /*
869 // TODO sound pack system
870 string soundpack;
871
872 string precache_sound_builtin (string s) = #19;
873 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
874 string precache_sound(string s)
875 {
876         return precache_sound_builtin(strcat(soundpack, s));
877 }
878 void play2(entity e, string filename)
879 {
880         stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
881 }
882 void sound(entity e, float chan, string samp, float vol, float atten)
883 {
884         sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
885 }
886 */
887
888 string precache_sound (string s) = #19;
889 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
890 void play2(entity e, string filename)
891 {
892         stuffcmd(e, strcat("play2 ", filename, "\n"));
893 }
894
895 void play2team(float t, string filename)
896 {
897         local entity head;
898         FOR_EACH_REALPLAYER(head)
899         {
900                 if (head.team == t)
901                         play2(head, filename);
902         }
903 }