1 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
2 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
3 string STR_PLAYER = "player";
4 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
5 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
7 // change that to actually calling strcat when running on an engine without
8 // unlimited tempstrings:
9 // string strcat1(string s) = #115; // FRIK_FILE
10 #define strcat1(s) (s)
15 void(string s) bcenterprint
17 // TODO replace by MSG_ALL (would show it to spectators too, though)?
20 if(clienttype(head) == CLIENTTYPE_REAL)
24 void(string s, float check_dangerous) ServerConsoleEcho =
27 if (checkextension("DP_SV_PRINT"))
36 ch = substring(s, 0, 1);
37 if(ch != "\"" && ch != "\r" && ch != "\n")
39 s = substring(s, 1, strlen(s) - 1);
50 void(string s, float check_dangerous) GameLogEcho =
55 if(cvar("sv_eventlog_files"))
60 matches = cvar("sv_eventlog_files_counter") + 1;
61 cvar_set("sv_eventlog_files_counter", ftos(matches));
64 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
65 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
66 logfile = fopen(fn, FILE_APPEND);
69 fputs(logfile, strcat(s, "\n"));
71 if(cvar("sv_eventlog_console"))
73 ServerConsoleEcho(s, check_dangerous);
80 // will be opened later
85 if(logfile_open && logfile >= 0)
92 float math_mod(float a, float b)
94 return a - (floor(a / b) * b);
97 void relocate_spawnpoint()
99 // nudge off the floor
100 setorigin(self, self.origin + '0 0 1');
102 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
103 if (trace_startsolid)
105 objerror("player spawn point in solid, mapper sucks!\n");
110 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
111 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
112 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
113 // BE CONSTANT OR strzoneD!
114 float(string haystack, string needle, float offset) strstr =
118 len = strlen(needle);
119 endpos = strlen(haystack) - len;
120 while(offset <= endpos)
122 found = substring(haystack, offset, len);
130 float NUM_NEAREST_ENTITIES = 4;
131 entity nearest_entity[NUM_NEAREST_ENTITIES];
132 float nearest_length[NUM_NEAREST_ENTITIES];
133 entity(vector point, .string field, string value, vector axismod) findnearest =
144 localhead = find(world, field, value);
147 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
148 dist = localhead.oldorigin;
150 dist = localhead.origin;
152 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
155 for(i = 0; i < num_nearest; ++i)
157 if(len < nearest_length[i])
161 // now i tells us where to insert at
162 // INSERTION SORT! YOU'VE SEEN IT! RUN!
163 if(i < NUM_NEAREST_ENTITIES)
165 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
167 nearest_length[j + 1] = nearest_length[j];
168 nearest_entity[j + 1] = nearest_entity[j];
170 nearest_length[i] = len;
171 nearest_entity[i] = localhead;
172 if(num_nearest < NUM_NEAREST_ENTITIES)
173 num_nearest = num_nearest + 1;
176 localhead = find(localhead, field, value);
179 // now use the first one from our list that we can see
180 for(i = 0; i < num_nearest; ++i)
182 traceline(point, nearest_entity[i].origin, TRUE, world);
183 if(trace_fraction == 1)
187 dprint("Nearest point (");
188 dprint(nearest_entity[0].netname);
189 dprint(") is not visible, using a visible one.\n");
191 return nearest_entity[i];
198 dprint("Not seeing any location point, using nearest as fallback.\n");
200 dprint("Candidates were: ");
201 for(j = 0; j < num_nearest; ++j)
205 dprint(nearest_entity[j].netname);
210 return nearest_entity[0];
213 void() target_location =
215 self.classname = "target_location";
216 // location name in netname
217 // eventually support: count, teamgame selectors, line of sight?
220 void() info_location =
222 self.classname = "target_location";
223 self.message = self.netname;
226 string NearestLocation(vector p)
231 loc = findnearest(p, classname, "target_location", '1 1 1');
238 loc = findnearest(p, target, "###item###", '1 1 4');
245 string(string msg) formatmessage =
252 msg_save = strzone(msg);
258 break; // too many replacements
260 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
263 replacement = substring(msg_save, p, 2);
264 escape = substring(msg_save, p + 1, 1);
267 else if(escape == "a")
268 replacement = ftos(floor(self.armorvalue));
269 else if(escape == "h")
270 replacement = ftos(floor(self.health));
271 else if(escape == "l")
272 replacement = NearestLocation(self.origin);
273 else if(escape == "y")
274 replacement = NearestLocation(self.cursor_trace_endpos);
275 else if(escape == "d")
276 replacement = NearestLocation(self.death_origin);
277 else if(escape == "w")
282 wep = self.switchweapon;
285 replacement = W_Name(wep);
287 else if(escape == "W")
289 if(self.items & IT_SHELLS) replacement = "shells";
290 else if(self.items & IT_NAILS) replacement = "bullets";
291 else if(self.items & IT_ROCKETS) replacement = "rockets";
292 else if(self.items & IT_CELLS) replacement = "cells";
293 else replacement = "batteries"; // ;)
295 else if(escape == "x")
297 replacement = self.cursor_trace_ent.netname;
298 if(!replacement || !self.cursor_trace_ent)
299 replacement = "nothing";
301 else if(escape == "p")
303 if(self.last_selected_player)
304 replacement = self.last_selected_player.netname;
306 replacement = "(nobody)";
308 msg = strcat(substring(msg_save, 0, p), replacement);
309 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
311 msg_save = strzone(msg);
314 msg = strcat(msg_save, "");
325 >0: receives a cvar from name=argv(f) value=argv(f+1)
327 void GetCvars_handleString(float f, .string field, string name)
332 strunzone(self.field);
339 strunzone(self.field);
340 self.field = strzone(argv(f + 1));
344 stuffcmd(self, strcat("sendcvar ", name, "\n"));
346 void GetCvars_handleFloat(float f, .float field, string name)
354 self.field = stof(argv(f + 1));
357 stuffcmd(self, strcat("sendcvar ", name, "\n"));
359 void GetCvars(float f)
361 GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
362 GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
363 GetCvars_handleFloat(f, cvar_cl_zoomfactor, "cl_zoomfactor");
364 GetCvars_handleFloat(f, cvar_cl_zoomspeed, "cl_zoomspeed");
365 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
366 GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
367 GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
368 GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
369 GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
372 float fexists(string f)
375 fh = fopen(f, FILE_READ);
382 void backtrace(string msg)
385 dev = cvar("developer");
386 cvar_set("developer", "1");
388 dprint("--- CUT HERE ---\nWARNING: ");
391 remove(world); // isn't there any better way to cause a backtrace?
392 dprint("\n--- CUT UNTIL HERE ---\n");
393 cvar_set("developer", ftos(dev));
396 void DistributeFragsAmongTeam(entity p, float targetteam, float factor)
408 // p.frags = 0; // do not harm the new team!
409 // return; // won't distribute negative scores
415 f = ceil(factor * p.frags);
416 p.frags = p.frags - f;
419 FOR_EACH_PLAYER(head)
421 if(head.team == targetteam)
427 FOR_EACH_PLAYER(head)
429 if(head.team == targetteam)
431 d = floor(f / nTeam);
432 head.frags = head.frags + d;
438 error("nPlayers in team changed!");
440 error(strcat("There were ", ftos(f), " frags left. BAD!"));
443 string Team_ColorCode(float teamid)
445 if(teamid == COLOR_TEAM1)
447 else if(teamid == COLOR_TEAM2)
449 else if(teamid == COLOR_TEAM3)
451 else if(teamid == COLOR_TEAM4)
457 string decolorize(string s)
466 ch1 = substring(s, 0, 1);
467 ch2 = substring(s, 1, 1);
472 out = strcat(out, "^^");
496 out = strcat(out, "^^");
498 s = substring(s, n, strlen(s) - n);
502 s = substring(s, 1, strlen(s) - 1);
503 out = strcat(out, ch1);
508 #define strdecolorize(s) decolorize(s)
509 #define strlennocol(s) strlen(decolorize(s))
511 #define CENTERPRIO_POINT 1
512 #define CENTERPRIO_REBALANCE 2
513 #define CENTERPRIO_VOTE 4
514 #define CENTERPRIO_NORMAL 5
515 #define CENTERPRIO_MAPVOTE 9
516 #define CENTERPRIO_ADMIN 99
517 .float centerprint_priority;
518 .float centerprint_expires;
519 void centerprint_atprio(entity e, float prio, string s)
521 if(intermission_running)
522 if(prio < CENTERPRIO_MAPVOTE)
524 if(time > e.centerprint_expires)
525 e.centerprint_priority = 0;
526 if(prio >= e.centerprint_priority)
528 e.centerprint_priority = prio;
529 e.centerprint_expires = time + e.cvar_scr_centertime;
530 centerprint_builtin(e, s);
533 void centerprint_expire(entity e, float prio)
535 if(prio == e.centerprint_priority)
537 e.centerprint_priority = 0;
538 centerprint_builtin(e, "");
541 void centerprint(entity e, string s)
543 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
548 // decolorizes and team colors the player name when needed
549 string playername(entity p)
552 if(teams_matter && !intermission_running && p.classname == "player")
554 t = Team_ColorCode(p.team);
555 return strcat(t, strdecolorize(p.netname));
561 // requires that m2>m1 in all coordinates, and that m4>m3
562 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;};
564 // requires the same, but is a stronger condition
565 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;};
567 float g_pickup_shells;
568 float g_pickup_shells_max;
569 float g_pickup_nails;
570 float g_pickup_nails_max;
571 float g_pickup_rockets;
572 float g_pickup_rockets_max;
573 float g_pickup_cells;
574 float g_pickup_cells_max;
575 float g_pickup_armorshard;
576 float g_pickup_armorshard_max;
577 float g_pickup_armor;
578 float g_pickup_armor_max;
579 float g_pickup_healthshard;
580 float g_pickup_healthshard_max;
581 float g_pickup_health;
582 float g_pickup_health_max;
583 float g_pickup_healthmega;
584 float g_pickup_healthmega_max;
586 void readlevelcvars(void)
588 g_pickup_shells = cvar("g_pickup_shells");
589 g_pickup_shells_max = cvar("g_pickup_shells_max");
590 g_pickup_nails = cvar("g_pickup_nails");
591 g_pickup_nails_max = cvar("g_pickup_nails_max");
592 g_pickup_rockets = cvar("g_pickup_rockets");
593 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
594 g_pickup_cells = cvar("g_pickup_cells");
595 g_pickup_cells_max = cvar("g_pickup_cells_max");
596 g_pickup_armorshard = cvar("g_pickup_armorshard");
597 g_pickup_armorshard_max = cvar("g_pickup_armorshard_max");
598 g_pickup_armor = cvar("g_pickup_armor");
599 g_pickup_armor_max = cvar("g_pickup_armor_max");
600 g_pickup_healthshard = cvar("g_pickup_healthshard");
601 g_pickup_healthshard_max = cvar("g_pickup_healthshard_max");
602 g_pickup_health = cvar("g_pickup_health");
603 g_pickup_health_max = cvar("g_pickup_health_max");
604 g_pickup_healthmega = cvar("g_pickup_healthmega");
605 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");