]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/miscfunctions.qc
log carried keys as K in sv_eventlog frag output; update makebuild
[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), ")");
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 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
237 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
238 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
239 // BE CONSTANT OR strzoneD!
240 float(string haystack, string needle, float offset) strstr =
241 {
242         float len, endpos;
243         string found;
244         len = strlen(needle);
245         endpos = strlen(haystack) - len;
246         while(offset <= endpos)
247         {
248                 found = substring(haystack, offset, len);
249                 if(found == needle)
250                         return offset;
251                 offset = offset + 1;
252         }
253         return -1;
254 }
255
256 float NUM_NEAREST_ENTITIES = 4;
257 entity nearest_entity[NUM_NEAREST_ENTITIES];
258 float nearest_length[NUM_NEAREST_ENTITIES];
259 entity(vector point, .string field, string value, vector axismod) findnearest =
260 {
261         entity localhead;
262         float i;
263         float j;
264         float len;
265         vector dist;
266
267         float num_nearest;
268         num_nearest = 0;
269
270         localhead = find(world, field, value);
271         while(localhead)
272         {
273                 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
274                         dist = localhead.oldorigin;
275                 else
276                         dist = localhead.origin;
277                 dist = dist - point;
278                 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
279                 len = vlen(dist);
280
281                 for(i = 0; i < num_nearest; ++i)
282                 {
283                         if(len < nearest_length[i])
284                                 break;
285                 }
286
287                 // now i tells us where to insert at
288                 //   INSERTION SORT! YOU'VE SEEN IT! RUN!
289                 if(i < NUM_NEAREST_ENTITIES)
290                 {
291                         for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
292                         {
293                                 nearest_length[j + 1] = nearest_length[j];
294                                 nearest_entity[j + 1] = nearest_entity[j];
295                         }
296                         nearest_length[i] = len;
297                         nearest_entity[i] = localhead;
298                         if(num_nearest < NUM_NEAREST_ENTITIES)
299                                 num_nearest = num_nearest + 1;
300                 }
301
302                 localhead = find(localhead, field, value);
303         }
304
305         // now use the first one from our list that we can see
306         for(i = 0; i < num_nearest; ++i)
307         {
308                 traceline(point, nearest_entity[i].origin, TRUE, world);
309                 if(trace_fraction == 1)
310                 {
311                         if(i != 0)
312                         {
313                                 dprint("Nearest point (");
314                                 dprint(nearest_entity[0].netname);
315                                 dprint(") is not visible, using a visible one.\n");
316                         }
317                         return nearest_entity[i];
318                 }
319         }
320
321         if(num_nearest == 0)
322                 return world;
323
324         dprint("Not seeing any location point, using nearest as fallback.\n");
325         /* DEBUGGING CODE:
326         dprint("Candidates were: ");
327         for(j = 0; j < num_nearest; ++j)
328         {
329                 if(j != 0)
330                         dprint(", ");
331                 dprint(nearest_entity[j].netname);
332         }
333         dprint("\n");
334         */
335
336         return nearest_entity[0];
337 }
338
339 void() target_location =
340 {
341         self.classname = "target_location";
342         // location name in netname
343         // eventually support: count, teamgame selectors, line of sight?
344 };
345
346 void() info_location =
347 {
348         self.classname = "target_location";
349         self.message = self.netname;
350 };
351
352 string NearestLocation(vector p)
353 {
354         entity loc;
355         string ret;
356         ret = "somewhere";
357         loc = findnearest(p, classname, "target_location", '1 1 1');
358         if(loc)
359         {
360                 ret = loc.message;
361         }
362         else
363         {
364                 loc = findnearest(p, target, "###item###", '1 1 4');
365                 if(loc)
366                         ret = loc.netname;
367         }
368         return ret;
369 }
370
371 string(string msg) formatmessage =
372 {
373         float p;
374         float n;
375         string msg_save;
376         string escape;
377         string replacement;
378         msg_save = strzone(msg);
379         p = 0;
380         n = 7;
381         while(1)
382         {
383                 if(n < 1)
384                         break; // too many replacements
385                 n = n - 1;
386                 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
387                 if(p < 0)
388                         break;
389                 replacement = substring(msg_save, p, 2);
390                 escape = substring(msg_save, p + 1, 1);
391                 if(escape == "%")
392                         replacement = "%";
393                 else if(escape == "a")
394                         replacement = ftos(floor(self.armorvalue));
395                 else if(escape == "h")
396                         replacement = ftos(floor(self.health));
397                 else if(escape == "l")
398                         replacement = NearestLocation(self.origin);
399                 else if(escape == "y")
400                         replacement = NearestLocation(self.cursor_trace_endpos);
401                 else if(escape == "d")
402                         replacement = NearestLocation(self.death_origin);
403                 else if(escape == "w")
404                 {
405                         float wep;
406                         wep = self.weapon;
407                         if(!wep)
408                                 wep = self.switchweapon;
409                         if(!wep)
410                                 wep = self.cnt;
411                         replacement = W_Name(wep);
412                 }
413                 else if(escape == "W")
414                 {
415                         if(self.items & IT_SHELLS) replacement = "shells";
416                         else if(self.items & IT_NAILS) replacement = "bullets";
417                         else if(self.items & IT_ROCKETS) replacement = "rockets";
418                         else if(self.items & IT_CELLS) replacement = "cells";
419                         else replacement = "batteries"; // ;)
420                 }
421                 else if(escape == "x")
422                 {
423                         replacement = self.cursor_trace_ent.netname;
424                         if(!replacement || !self.cursor_trace_ent)
425                                 replacement = "nothing";
426                 }
427                 else if(escape == "p")
428                 {
429                         if(self.last_selected_player)
430                                 replacement = self.last_selected_player.netname;
431                         else
432                                 replacement = "(nobody)";
433                 }
434                 msg = strcat(substring(msg_save, 0, p), replacement);
435                 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
436                 strunzone(msg_save);
437                 msg_save = strzone(msg);
438                 p = p + 2;
439         }
440         msg = strcat(msg_save, "");
441         strunzone(msg_save);
442         return msg;
443 }
444
445 /*
446 =============
447 GetCvars
448 =============
449 Called with:
450   0:  sends the request
451   >0: receives a cvar from name=argv(f) value=argv(f+1)
452 */
453 void GetCvars_handleString(float f, .string field, string name)
454 {
455         if(f < 0)
456         {
457                 if(self.field)
458                         strunzone(self.field);
459         }
460         else if(f > 0)
461         {
462                 if(argv(f) == name)
463                 {
464                         if(self.field)
465                                 strunzone(self.field);
466                         self.field = strzone(argv(f + 1));
467                 }
468         }
469         else
470                 stuffcmd(self, strcat("sendcvar ", name, "\n"));
471 }
472 void GetCvars_handleFloat(float f, .float field, string name)
473 {
474         if(f < 0)
475         {
476         }
477         else if(f > 0)
478         {
479                 if(argv(f) == name)
480                         self.field = stof(argv(f + 1));
481         }
482         else
483                 stuffcmd(self, strcat("sendcvar ", name, "\n"));
484 }
485 void GetCvars(float f)
486 {
487         GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
488         GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
489         GetCvars_handleFloat(f, cvar_cl_zoomfactor, "cl_zoomfactor");
490         GetCvars_handleFloat(f, cvar_cl_zoomspeed, "cl_zoomspeed");
491         GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
492         GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
493         GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
494         GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
495         GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
496 }
497
498 float fexists(string f)
499 {
500         float fh;
501         fh = fopen(f, FILE_READ);
502         if(fh < 0)
503                 return FALSE;
504         fclose(fh);
505         return TRUE;
506 }
507
508 void backtrace(string msg)
509 {
510         float dev;
511         dev = cvar("developer");
512         cvar_set("developer", "1");
513         dprint("\n");
514         dprint("--- CUT HERE ---\nWARNING: ");
515         dprint(msg);
516         dprint("\n");
517         remove(world); // isn't there any better way to cause a backtrace?
518         dprint("\n--- CUT UNTIL HERE ---\n");
519         cvar_set("developer", ftos(dev));
520 }
521
522 void DistributeFragsAmongTeam(entity p, float targetteam, float factor)
523 {
524         float nTeam;
525         entity head;
526         float f;
527
528         if(!teams_matter)
529                 return;
530
531         //if(p.frags < 0)
532         //{
533         //      p.frags = 0; // do not harm the new team!
534         //      return; // won't distribute negative scores
535         //}
536
537         if(p.frags == -666)
538                 return;
539
540         f = ceil(factor * p.frags);
541         p.frags = p.frags - f;
542
543         nTeam = 0;
544         FOR_EACH_PLAYER(head)
545                 if(head != p)
546                         if(head.team == targetteam)
547                                 nTeam = nTeam + 1;
548
549         if(nTeam == 0)
550                 return;
551
552         DistributeEvenly_Init(f, nTeam);
553
554         FOR_EACH_PLAYER(head)
555                 if(head != p)
556                         if(head.team == targetteam)
557                                 head.frags = head.frags + DistributeEvenly_Get(1);
558 }
559
560 string Team_ColorCode(float teamid)
561 {
562         if(teamid == COLOR_TEAM1)
563                 return "^1";
564         else if(teamid == COLOR_TEAM2)
565                 return "^4";
566         else if(teamid == COLOR_TEAM3)
567                 return "^3";
568         else if(teamid == COLOR_TEAM4)
569                 return "^6";
570         else
571                 return "^7";
572 }
573
574 /*
575 string decolorize(string s)
576 {
577         string out;
578         out = "";
579         while(s != "")
580         {
581                 float n;
582                 string ch1, ch2;
583                 n = 1;
584                 ch1 = substring(s, 0, 1);
585                 ch2 = substring(s, 1, 1);
586                 if(ch1 == "^")
587                 {
588                         n = 2;
589                         if(ch2 == "^")
590                                 out = strcat(out, "^^");
591                         else if(ch2 == "0")
592                                 out = strcat1(out);
593                         else if(ch2 == "1")
594                                 out = strcat1(out);
595                         else if(ch2 == "2")
596                                 out = strcat1(out);
597                         else if(ch2 == "3")
598                                 out = strcat1(out);
599                         else if(ch2 == "4")
600                                 out = strcat1(out);
601                         else if(ch2 == "5")
602                                 out = strcat1(out);
603                         else if(ch2 == "6")
604                                 out = strcat1(out);
605                         else if(ch2 == "7")
606                                 out = strcat1(out);
607                         else if(ch2 == "8")
608                                 out = strcat1(out);
609                         else if(ch2 == "9")
610                                 out = strcat1(out);
611                         else
612                         {
613                                 n = 1;
614                                 out = strcat(out, "^^");
615                         }
616                         s = substring(s, n, strlen(s) - n);
617                 }
618                 else
619                 {
620                         s = substring(s, 1, strlen(s) - 1);
621                         out = strcat(out, ch1);
622                 }
623         }
624         return out;
625 }
626 #define strdecolorize(s) decolorize(s)
627 #define strlennocol(s) strlen(decolorize(s))
628 */
629
630 #define CENTERPRIO_POINT 1
631 #define CENTERPRIO_SPAM 2
632 #define CENTERPRIO_REBALANCE 2
633 #define CENTERPRIO_VOTE 4
634 #define CENTERPRIO_NORMAL 5
635 #define CENTERPRIO_MAPVOTE 9
636 #define CENTERPRIO_ADMIN 99
637 .float centerprint_priority;
638 .float centerprint_expires;
639 void centerprint_atprio(entity e, float prio, string s)
640 {
641         if(intermission_running)
642                 if(prio < CENTERPRIO_MAPVOTE)
643                         return;
644         if(time > e.centerprint_expires)
645                 e.centerprint_priority = 0;
646         if(prio >= e.centerprint_priority)
647         {
648                 e.centerprint_priority = prio;
649                 e.centerprint_expires = time + e.cvar_scr_centertime;
650                 centerprint_builtin(e, s);
651         }
652 }
653 void centerprint_expire(entity e, float prio)
654 {
655         if(prio == e.centerprint_priority)
656         {
657                 e.centerprint_priority = 0;
658                 centerprint_builtin(e, "");
659         }
660 }
661 void centerprint(entity e, string s)
662 {
663         centerprint_atprio(e, CENTERPRIO_NORMAL, s);
664 }
665
666 void VoteNag();
667
668 // decolorizes and team colors the player name when needed
669 string playername(entity p)
670 {
671         string t;
672         if(teams_matter && !intermission_running && p.classname == "player")
673         {
674                 t = Team_ColorCode(p.team);
675                 return strcat(t, strdecolorize(p.netname));
676         }
677         else
678                 return p.netname;
679 }
680
681 // requires that m2>m1 in all coordinates, and that m4>m3
682 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;};
683
684 // requires the same, but is a stronger condition
685 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;};
686
687 float g_pickup_shells;
688 float g_pickup_shells_max;
689 float g_pickup_nails;
690 float g_pickup_nails_max;
691 float g_pickup_rockets;
692 float g_pickup_rockets_max;
693 float g_pickup_cells;
694 float g_pickup_cells_max;
695 float g_pickup_armorshard;
696 float g_pickup_armorshard_max;
697 float g_pickup_armor;
698 float g_pickup_armor_max;
699 float g_pickup_healthshard;
700 float g_pickup_healthshard_max;
701 float g_pickup_health;
702 float g_pickup_health_max;
703 float g_pickup_healthmega;
704 float g_pickup_healthmega_max;
705
706 float start_items;
707 float start_switchweapon;
708 float start_ammo_shells;
709 float start_ammo_nails;
710 float start_ammo_rockets;
711 float start_ammo_cells;
712 float start_health;
713 float start_armorvalue;
714
715 void readlevelcvars(void)
716 {
717         g_pickup_shells                    = cvar("g_pickup_shells");
718         g_pickup_shells_max                = cvar("g_pickup_shells_max");
719         g_pickup_nails                     = cvar("g_pickup_nails");
720         g_pickup_nails_max                 = cvar("g_pickup_nails_max");
721         g_pickup_rockets                   = cvar("g_pickup_rockets");
722         g_pickup_rockets_max               = cvar("g_pickup_rockets_max");
723         g_pickup_cells                     = cvar("g_pickup_cells");
724         g_pickup_cells_max                 = cvar("g_pickup_cells_max");
725         g_pickup_armorshard                = cvar("g_pickup_armorshard");
726         g_pickup_armorshard_max            = cvar("g_pickup_armorshard_max");
727         g_pickup_armor                     = cvar("g_pickup_armor");
728         g_pickup_armor_max                 = cvar("g_pickup_armor_max");
729         g_pickup_healthshard               = cvar("g_pickup_healthshard");
730         g_pickup_healthshard_max           = cvar("g_pickup_healthshard_max");
731         g_pickup_health                    = cvar("g_pickup_health");
732         g_pickup_health_max                = cvar("g_pickup_health_max");
733         g_pickup_healthmega                = cvar("g_pickup_healthmega");
734         g_pickup_healthmega_max            = cvar("g_pickup_healthmega_max");
735
736         // initialize starting values for players
737         start_items = 0;
738         start_switchweapon = 0;
739         start_ammo_shells = 0;
740         start_ammo_nails = 0;
741         start_ammo_rockets = 0;
742         start_ammo_cells = 0;
743         start_health = cvar("g_balance_health_start");
744         start_armorvalue = cvar("g_balance_armor_start");
745
746         if(cvar("g_instagib"))
747         {
748                 start_items = IT_NEX;
749                 start_switchweapon = WEP_NEX;
750                 weapon_action(start_switchweapon, WR_PRECACHE);
751                 start_ammo_cells = 999;
752         }
753         else if(cvar("g_rocketarena"))
754         {
755                 start_items = IT_ROCKET_LAUNCHER;
756                 start_switchweapon = WEP_ROCKET_LAUNCHER;
757                 weapon_action(start_switchweapon, WR_PRECACHE);
758                 start_ammo_rockets = 999;
759         }
760         else if(cvar("g_nixnex"))
761         {
762                 start_items = 0;
763                 // will be done later
764         }
765         else if(cvar("g_minstagib"))
766         {
767                 start_health = 100;
768                 start_armorvalue = 0;
769                 start_items = IT_NEX;
770                 start_switchweapon = WEP_NEX;
771                 weapon_action(start_switchweapon, WR_PRECACHE);
772                 start_ammo_cells = cvar("g_minstagib_ammo_start");
773         }
774         else
775         {
776                 if(cvar("g_lms"))
777                 {
778                         start_ammo_shells = cvar("g_lms_start_ammo_shells");
779                         start_ammo_nails = cvar("g_lms_start_ammo_nails");
780                         start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
781                         start_ammo_cells = cvar("g_lms_start_ammo_cells");
782                         start_health = cvar("g_lms_start_health");
783                         start_armorvalue = cvar("g_lms_start_armor");
784                 }
785                 else if (cvar("g_use_ammunition")) {
786                         start_ammo_shells = cvar("g_start_ammo_shells");
787                         start_ammo_nails = cvar("g_start_ammo_nails");
788                         start_ammo_rockets = cvar("g_start_ammo_rockets");
789                         start_ammo_cells = cvar("g_start_ammo_cells");
790                 } else {
791                         start_ammo_shells = cvar("g_pickup_shells_max");
792                         start_ammo_nails = cvar("g_pickup_nails_max");
793                         start_ammo_rockets = cvar("g_pickup_rockets_max");
794                         start_ammo_cells = cvar("g_pickup_cells_max");
795                 }
796
797                 if (cvar("g_start_weapon_laser") || cvar("g_lms"))
798                 {
799                         start_items = start_items | IT_LASER;
800                         start_switchweapon = WEP_LASER;
801                         weapon_action(start_switchweapon, WR_PRECACHE);
802                 }
803                 if (cvar("g_start_weapon_shotgun") || cvar("g_lms"))
804                 {
805                         start_items = start_items | IT_SHOTGUN;
806                         start_switchweapon = WEP_SHOTGUN;
807                         weapon_action(start_switchweapon, WR_PRECACHE);
808                 }
809                 if (cvar("g_start_weapon_uzi") || cvar("g_lms"))
810                 {
811                         start_items = start_items | IT_UZI;
812                         start_switchweapon = WEP_UZI;
813                         weapon_action(start_switchweapon, WR_PRECACHE);
814                 }
815                 if (cvar("g_start_weapon_grenadelauncher") || cvar("g_lms"))
816                 {
817                         start_items = start_items | IT_GRENADE_LAUNCHER;
818                         start_switchweapon = WEP_GRENADE_LAUNCHER;
819                         weapon_action(start_switchweapon, WR_PRECACHE);
820                 }
821                 if (cvar("g_start_weapon_electro") || cvar("g_lms"))
822                 {
823                         start_items = start_items | IT_ELECTRO;
824                         start_switchweapon = WEP_ELECTRO;
825                         weapon_action(start_switchweapon, WR_PRECACHE);
826                 }
827                 if (cvar("g_start_weapon_crylink") || cvar("g_lms"))
828                 {
829                         start_items = start_items | IT_CRYLINK;
830                         start_switchweapon = WEP_CRYLINK;
831                         weapon_action(start_switchweapon, WR_PRECACHE);
832                 }
833                 if (cvar("g_start_weapon_nex") || cvar("g_lms"))
834                 {
835                         start_items = start_items | IT_NEX;
836                         start_switchweapon = WEP_NEX;
837                         weapon_action(start_switchweapon, WR_PRECACHE);
838                 }
839                 if (cvar("g_start_weapon_hagar") || cvar("g_lms"))
840                 {
841                         start_items = start_items | IT_HAGAR;
842                         start_switchweapon = WEP_HAGAR;
843                         weapon_action(start_switchweapon, WR_PRECACHE);
844                 }
845                 if (cvar("g_start_weapon_rocketlauncher") || cvar("g_lms"))
846                 {
847                         start_items = start_items | IT_ROCKET_LAUNCHER;
848                         start_switchweapon = WEP_ROCKET_LAUNCHER;
849                         weapon_action(start_switchweapon, WR_PRECACHE);
850                 }
851         }
852 }
853
854 /*
855 // TODO sound pack system
856 string soundpack;
857
858 string precache_sound_builtin (string s) = #19;
859 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
860 string precache_sound(string s)
861 {
862         return precache_sound_builtin(strcat(soundpack, s));
863 }
864 void play2(entity e, string filename)
865 {
866         stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
867 }
868 void sound(entity e, float chan, string samp, float vol, float atten)
869 {
870         sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
871 }
872 */
873
874 string precache_sound (string s) = #19;
875 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
876 void play2(entity e, string filename)
877 {
878         stuffcmd(e, strcat("play2 ", filename, "\n"));
879 }