1 void() info_player_deathmatch; // needed for the other spawnpoints
3 void move_out_of_solid_expand(entity e, vector by)
6 tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
12 // adjust origin in the other direction...
13 e.origin = e.origin - by * (1 - trace_fraction);
17 void move_out_of_solid(entity e)
22 traceline(o, o, MOVE_WORLDONLY, e);
25 dprint("origin is in solid too! (", vtos(o), ")");
29 tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
37 move_out_of_solid_expand(e, '1 0 0' * m0_x); e.mins_x = m0_x;
38 move_out_of_solid_expand(e, '1 0 0' * m1_x); e.maxs_x = m1_x;
39 move_out_of_solid_expand(e, '0 1 0' * m0_y); e.mins_y = m0_y;
40 move_out_of_solid_expand(e, '0 1 0' * m1_y); e.maxs_y = m1_y;
41 move_out_of_solid_expand(e, '0 0 1' * m0_z); e.mins_z = m0_z;
42 move_out_of_solid_expand(e, '0 0 1' * m1_z); e.maxs_z = m1_z;
43 setorigin(e, e.origin);
45 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
48 dprint("could not get out of solid (", vtos(o), ")");
53 // converts a number to a string with the indicated number of decimals
54 // works for up to 10 decimals!
55 string ftos_decimals(float number, float decimals)
61 // if negative, cut off the sign first
63 return strcat("-", ftos_decimals(-number, decimals));
64 // it now is always positive!
67 number = floor(number * pow(10, decimals) + 0.5);
70 result = ftos(number);
72 // does it have a decimal point (should not happen)? If there is one, it is always at len-7)
73 // if ftos had fucked it up, which should never happen: "34278.000000"
75 if(substring(result, len - 7, 1) == ".")
77 dprint("ftos(integer) has comma? Can't be. Affected result: ", result, "\n");
78 result = substring(result, 0, len - 7);
82 // is it too short? If yes, insert leading zeroes
85 result = strcat(substring("0000000000", 0, decimals - len + 1), result);
88 // and now... INSERT THE POINT!
89 tmp = substring(result, len - decimals, decimals);
90 result = strcat(substring(result, 0, len - decimals), ".", tmp);
94 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
95 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
96 string STR_PLAYER = "player";
97 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
98 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
100 // change that to actually calling strcat when running on an engine without
101 // unlimited tempstrings:
102 // string strcat1(string s) = #115; // FRIK_FILE
103 #define strcat1(s) (s)
108 void(string s) bcenterprint
110 // TODO replace by MSG_ALL (would show it to spectators too, though)?
112 FOR_EACH_PLAYER(head)
113 if(clienttype(head) == CLIENTTYPE_REAL)
114 centerprint(head, s);
117 void(string s, float check_dangerous) ServerConsoleEcho =
120 if (checkextension("DP_SV_PRINT"))
129 ch = substring(s, 0, 1);
130 if(ch != "\"" && ch != "\r" && ch != "\n")
132 s = substring(s, 1, strlen(s) - 1);
143 void(string s, float check_dangerous) GameLogEcho =
148 if(cvar("sv_eventlog_files"))
153 matches = cvar("sv_eventlog_files_counter") + 1;
154 cvar_set("sv_eventlog_files_counter", ftos(matches));
157 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
158 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
159 logfile = fopen(fn, FILE_APPEND);
162 fputs(logfile, strcat(s, "\n"));
164 if(cvar("sv_eventlog_console"))
166 ServerConsoleEcho(s, check_dangerous);
173 // will be opened later
176 void() GameLogClose =
178 if(logfile_open && logfile >= 0)
185 float math_mod(float a, float b)
187 return a - (floor(a / b) * b);
190 void relocate_spawnpoint()
192 // nudge off the floor
193 setorigin(self, self.origin + '0 0 1');
195 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
196 if (trace_startsolid)
198 objerror("player spawn point in solid, mapper sucks!\n");
202 if(cvar("g_spawnpoints_autodrop"))
204 setsize(self, PL_MIN, PL_MAX);
209 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
210 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
211 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
212 // BE CONSTANT OR strzoneD!
213 float(string haystack, string needle, float offset) strstr =
217 len = strlen(needle);
218 endpos = strlen(haystack) - len;
219 while(offset <= endpos)
221 found = substring(haystack, offset, len);
229 float NUM_NEAREST_ENTITIES = 4;
230 entity nearest_entity[NUM_NEAREST_ENTITIES];
231 float nearest_length[NUM_NEAREST_ENTITIES];
232 entity(vector point, .string field, string value, vector axismod) findnearest =
243 localhead = find(world, field, value);
246 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
247 dist = localhead.oldorigin;
249 dist = localhead.origin;
251 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
254 for(i = 0; i < num_nearest; ++i)
256 if(len < nearest_length[i])
260 // now i tells us where to insert at
261 // INSERTION SORT! YOU'VE SEEN IT! RUN!
262 if(i < NUM_NEAREST_ENTITIES)
264 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
266 nearest_length[j + 1] = nearest_length[j];
267 nearest_entity[j + 1] = nearest_entity[j];
269 nearest_length[i] = len;
270 nearest_entity[i] = localhead;
271 if(num_nearest < NUM_NEAREST_ENTITIES)
272 num_nearest = num_nearest + 1;
275 localhead = find(localhead, field, value);
278 // now use the first one from our list that we can see
279 for(i = 0; i < num_nearest; ++i)
281 traceline(point, nearest_entity[i].origin, TRUE, world);
282 if(trace_fraction == 1)
286 dprint("Nearest point (");
287 dprint(nearest_entity[0].netname);
288 dprint(") is not visible, using a visible one.\n");
290 return nearest_entity[i];
297 dprint("Not seeing any location point, using nearest as fallback.\n");
299 dprint("Candidates were: ");
300 for(j = 0; j < num_nearest; ++j)
304 dprint(nearest_entity[j].netname);
309 return nearest_entity[0];
312 void() target_location =
314 self.classname = "target_location";
315 // location name in netname
316 // eventually support: count, teamgame selectors, line of sight?
319 void() info_location =
321 self.classname = "target_location";
322 self.message = self.netname;
325 string NearestLocation(vector p)
330 loc = findnearest(p, classname, "target_location", '1 1 1');
337 loc = findnearest(p, target, "###item###", '1 1 4');
344 string(string msg) formatmessage =
351 msg_save = strzone(msg);
357 break; // too many replacements
359 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
362 replacement = substring(msg_save, p, 2);
363 escape = substring(msg_save, p + 1, 1);
366 else if(escape == "a")
367 replacement = ftos(floor(self.armorvalue));
368 else if(escape == "h")
369 replacement = ftos(floor(self.health));
370 else if(escape == "l")
371 replacement = NearestLocation(self.origin);
372 else if(escape == "y")
373 replacement = NearestLocation(self.cursor_trace_endpos);
374 else if(escape == "d")
375 replacement = NearestLocation(self.death_origin);
376 else if(escape == "w")
381 wep = self.switchweapon;
384 replacement = W_Name(wep);
386 else if(escape == "W")
388 if(self.items & IT_SHELLS) replacement = "shells";
389 else if(self.items & IT_NAILS) replacement = "bullets";
390 else if(self.items & IT_ROCKETS) replacement = "rockets";
391 else if(self.items & IT_CELLS) replacement = "cells";
392 else replacement = "batteries"; // ;)
394 else if(escape == "x")
396 replacement = self.cursor_trace_ent.netname;
397 if(!replacement || !self.cursor_trace_ent)
398 replacement = "nothing";
400 else if(escape == "p")
402 if(self.last_selected_player)
403 replacement = self.last_selected_player.netname;
405 replacement = "(nobody)";
407 msg = strcat(substring(msg_save, 0, p), replacement);
408 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
410 msg_save = strzone(msg);
413 msg = strcat(msg_save, "");
424 >0: receives a cvar from name=argv(f) value=argv(f+1)
426 void GetCvars_handleString(float f, .string field, string name)
431 strunzone(self.field);
438 strunzone(self.field);
439 self.field = strzone(argv(f + 1));
443 stuffcmd(self, strcat("sendcvar ", name, "\n"));
445 void GetCvars_handleFloat(float f, .float field, string name)
453 self.field = stof(argv(f + 1));
456 stuffcmd(self, strcat("sendcvar ", name, "\n"));
458 void GetCvars(float f)
460 GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
461 GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
462 GetCvars_handleFloat(f, cvar_cl_zoomfactor, "cl_zoomfactor");
463 GetCvars_handleFloat(f, cvar_cl_zoomspeed, "cl_zoomspeed");
464 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
465 GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
466 GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
467 GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
468 GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
471 float fexists(string f)
474 fh = fopen(f, FILE_READ);
481 void backtrace(string msg)
484 dev = cvar("developer");
485 cvar_set("developer", "1");
487 dprint("--- CUT HERE ---\nWARNING: ");
490 remove(world); // isn't there any better way to cause a backtrace?
491 dprint("\n--- CUT UNTIL HERE ---\n");
492 cvar_set("developer", ftos(dev));
495 void DistributeFragsAmongTeam(entity p, float targetteam, float factor)
507 // p.frags = 0; // do not harm the new team!
508 // return; // won't distribute negative scores
514 f = ceil(factor * p.frags);
515 p.frags = p.frags - f;
518 FOR_EACH_PLAYER(head)
520 if(head.team == targetteam)
526 FOR_EACH_PLAYER(head)
528 if(head.team == targetteam)
530 d = floor(f / nTeam);
531 head.frags = head.frags + d;
537 error("nPlayers in team changed!");
539 error(strcat("There were ", ftos(f), " frags left. BAD!"));
542 string Team_ColorCode(float teamid)
544 if(teamid == COLOR_TEAM1)
546 else if(teamid == COLOR_TEAM2)
548 else if(teamid == COLOR_TEAM3)
550 else if(teamid == COLOR_TEAM4)
557 string decolorize(string s)
566 ch1 = substring(s, 0, 1);
567 ch2 = substring(s, 1, 1);
572 out = strcat(out, "^^");
596 out = strcat(out, "^^");
598 s = substring(s, n, strlen(s) - n);
602 s = substring(s, 1, strlen(s) - 1);
603 out = strcat(out, ch1);
608 #define strdecolorize(s) decolorize(s)
609 #define strlennocol(s) strlen(decolorize(s))
612 #define CENTERPRIO_POINT 1
613 #define CENTERPRIO_REBALANCE 2
614 #define CENTERPRIO_VOTE 4
615 #define CENTERPRIO_NORMAL 5
616 #define CENTERPRIO_MAPVOTE 9
617 #define CENTERPRIO_ADMIN 99
618 .float centerprint_priority;
619 .float centerprint_expires;
620 void centerprint_atprio(entity e, float prio, string s)
622 if(intermission_running)
623 if(prio < CENTERPRIO_MAPVOTE)
625 if(time > e.centerprint_expires)
626 e.centerprint_priority = 0;
627 if(prio >= e.centerprint_priority)
629 e.centerprint_priority = prio;
630 e.centerprint_expires = time + e.cvar_scr_centertime;
631 centerprint_builtin(e, s);
634 void centerprint_expire(entity e, float prio)
636 if(prio == e.centerprint_priority)
638 e.centerprint_priority = 0;
639 centerprint_builtin(e, "");
642 void centerprint(entity e, string s)
644 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
649 // decolorizes and team colors the player name when needed
650 string playername(entity p)
653 if(teams_matter && !intermission_running && p.classname == "player")
655 t = Team_ColorCode(p.team);
656 return strcat(t, strdecolorize(p.netname));
662 // requires that m2>m1 in all coordinates, and that m4>m3
663 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;};
665 // requires the same, but is a stronger condition
666 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;};
668 float g_pickup_shells;
669 float g_pickup_shells_max;
670 float g_pickup_nails;
671 float g_pickup_nails_max;
672 float g_pickup_rockets;
673 float g_pickup_rockets_max;
674 float g_pickup_cells;
675 float g_pickup_cells_max;
676 float g_pickup_armorshard;
677 float g_pickup_armorshard_max;
678 float g_pickup_armor;
679 float g_pickup_armor_max;
680 float g_pickup_healthshard;
681 float g_pickup_healthshard_max;
682 float g_pickup_health;
683 float g_pickup_health_max;
684 float g_pickup_healthmega;
685 float g_pickup_healthmega_max;
687 void readlevelcvars(void)
689 g_pickup_shells = cvar("g_pickup_shells");
690 g_pickup_shells_max = cvar("g_pickup_shells_max");
691 g_pickup_nails = cvar("g_pickup_nails");
692 g_pickup_nails_max = cvar("g_pickup_nails_max");
693 g_pickup_rockets = cvar("g_pickup_rockets");
694 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
695 g_pickup_cells = cvar("g_pickup_cells");
696 g_pickup_cells_max = cvar("g_pickup_cells_max");
697 g_pickup_armorshard = cvar("g_pickup_armorshard");
698 g_pickup_armorshard_max = cvar("g_pickup_armorshard_max");
699 g_pickup_armor = cvar("g_pickup_armor");
700 g_pickup_armor_max = cvar("g_pickup_armor_max");
701 g_pickup_healthshard = cvar("g_pickup_healthshard");
702 g_pickup_healthshard_max = cvar("g_pickup_healthshard_max");
703 g_pickup_health = cvar("g_pickup_health");
704 g_pickup_health_max = cvar("g_pickup_health_max");
705 g_pickup_healthmega = cvar("g_pickup_healthmega");
706 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");
710 // TODO sound pack system
713 string precache_sound_builtin (string s) = #19;
714 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
715 string precache_sound(string s)
717 return precache_sound_builtin(strcat(soundpack, s));
719 void play2(entity e, string filename)
721 stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
723 void sound(entity e, float chan, string samp, float vol, float atten)
725 sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
729 string precache_sound (string s) = #19;
730 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
731 void play2(entity e, string filename)
733 stuffcmd(e, strcat("play2 ", filename, "\n"));