1 void move_out_of_solid_expand(entity e, vector by)
4 tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
10 // adjust origin in the other direction...
11 e.origin = e.origin - by * (1 - trace_fraction);
15 void move_out_of_solid(entity e)
20 traceline(o, o, MOVE_WORLDONLY, e);
23 dprint("origin is in solid too! (", vtos(o), ")");
27 tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
35 move_out_of_solid_expand(e, '1 0 0' * m0_x); e.mins_x = m0_x;
36 move_out_of_solid_expand(e, '1 0 0' * m1_x); e.maxs_x = m1_x;
37 move_out_of_solid_expand(e, '0 1 0' * m0_y); e.mins_y = m0_y;
38 move_out_of_solid_expand(e, '0 1 0' * m1_y); e.maxs_y = m1_y;
39 move_out_of_solid_expand(e, '0 0 1' * m0_z); e.mins_z = m0_z;
40 move_out_of_solid_expand(e, '0 0 1' * m1_z); e.maxs_z = m1_z;
41 setorigin(e, e.origin);
43 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
46 dprint("could not get out of solid (", vtos(o), ")");
51 // converts a number to a string with the indicated number of decimals
52 // works for up to 10 decimals!
53 string ftos_decimals(float number, float decimals)
59 // if negative, cut off the sign first
61 return strcat("-", ftos_decimals(-number, decimals));
62 // it now is always positive!
65 number = floor(number * pow(10, decimals) + 0.5);
68 result = ftos(number);
70 // does it have a decimal point (should not happen)? If there is one, it is always at len-7)
71 // if ftos had fucked it up, which should never happen: "34278.000000"
73 if(substring(result, len - 7, 1) == ".")
75 dprint("ftos(integer) has comma? Can't be. Affected result: ", result, "\n");
76 result = substring(result, 0, len - 7);
80 // is it too short? If yes, insert leading zeroes
83 result = strcat(substring("0000000000", 0, decimals - len + 1), result);
86 // and now... INSERT THE POINT!
87 tmp = substring(result, len - decimals, decimals);
88 result = strcat(substring(result, 0, len - decimals), ".", tmp);
92 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
93 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
94 string STR_PLAYER = "player";
95 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
96 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
98 // change that to actually calling strcat when running on an engine without
99 // unlimited tempstrings:
100 // string strcat1(string s) = #115; // FRIK_FILE
101 #define strcat1(s) (s)
106 void(string s) bcenterprint
108 // TODO replace by MSG_ALL (would show it to spectators too, though)?
110 FOR_EACH_PLAYER(head)
111 if(clienttype(head) == CLIENTTYPE_REAL)
112 centerprint(head, s);
115 void(string s, float check_dangerous) ServerConsoleEcho =
118 if (checkextension("DP_SV_PRINT"))
127 ch = substring(s, 0, 1);
128 if(ch != "\"" && ch != "\r" && ch != "\n")
130 s = substring(s, 1, strlen(s) - 1);
141 void(string s, float check_dangerous) GameLogEcho =
146 if(cvar("sv_eventlog_files"))
151 matches = cvar("sv_eventlog_files_counter") + 1;
152 cvar_set("sv_eventlog_files_counter", ftos(matches));
155 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
156 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
157 logfile = fopen(fn, FILE_APPEND);
160 fputs(logfile, strcat(s, "\n"));
162 if(cvar("sv_eventlog_console"))
164 ServerConsoleEcho(s, check_dangerous);
171 // will be opened later
174 void() GameLogClose =
176 if(logfile_open && logfile >= 0)
183 float math_mod(float a, float b)
185 return a - (floor(a / b) * b);
188 void relocate_spawnpoint()
193 setsize(self, PL_MIN, PL_MAX);
195 // nudge off the floor
196 setorigin(self, self.origin + '0 0 1');
198 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
199 if (trace_startsolid)
201 objerror("player spawn point in solid, mapper sucks!\n");
205 // drop the spawn point onto the floor
206 // NOTE: a later version might not do this any more
210 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
211 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
212 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
213 // BE CONSTANT OR strzoneD!
214 float(string haystack, string needle, float offset) strstr =
218 len = strlen(needle);
219 endpos = strlen(haystack) - len;
220 while(offset <= endpos)
222 found = substring(haystack, offset, len);
230 float NUM_NEAREST_ENTITIES = 4;
231 entity nearest_entity[NUM_NEAREST_ENTITIES];
232 float nearest_length[NUM_NEAREST_ENTITIES];
233 entity(vector point, .string field, string value, vector axismod) findnearest =
244 localhead = find(world, field, value);
247 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
248 dist = localhead.oldorigin;
250 dist = localhead.origin;
252 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
255 for(i = 0; i < num_nearest; ++i)
257 if(len < nearest_length[i])
261 // now i tells us where to insert at
262 // INSERTION SORT! YOU'VE SEEN IT! RUN!
263 if(i < NUM_NEAREST_ENTITIES)
265 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
267 nearest_length[j + 1] = nearest_length[j];
268 nearest_entity[j + 1] = nearest_entity[j];
270 nearest_length[i] = len;
271 nearest_entity[i] = localhead;
272 if(num_nearest < NUM_NEAREST_ENTITIES)
273 num_nearest = num_nearest + 1;
276 localhead = find(localhead, field, value);
279 // now use the first one from our list that we can see
280 for(i = 0; i < num_nearest; ++i)
282 traceline(point, nearest_entity[i].origin, TRUE, world);
283 if(trace_fraction == 1)
287 dprint("Nearest point (");
288 dprint(nearest_entity[0].netname);
289 dprint(") is not visible, using a visible one.\n");
291 return nearest_entity[i];
298 dprint("Not seeing any location point, using nearest as fallback.\n");
300 dprint("Candidates were: ");
301 for(j = 0; j < num_nearest; ++j)
305 dprint(nearest_entity[j].netname);
310 return nearest_entity[0];
313 void() target_location =
315 self.classname = "target_location";
316 // location name in netname
317 // eventually support: count, teamgame selectors, line of sight?
320 void() info_location =
322 self.classname = "target_location";
323 self.message = self.netname;
326 string NearestLocation(vector p)
331 loc = findnearest(p, classname, "target_location", '1 1 1');
338 loc = findnearest(p, target, "###item###", '1 1 4');
345 string(string msg) formatmessage =
352 msg_save = strzone(msg);
358 break; // too many replacements
360 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
363 replacement = substring(msg_save, p, 2);
364 escape = substring(msg_save, p + 1, 1);
367 else if(escape == "a")
368 replacement = ftos(floor(self.armorvalue));
369 else if(escape == "h")
370 replacement = ftos(floor(self.health));
371 else if(escape == "l")
372 replacement = NearestLocation(self.origin);
373 else if(escape == "y")
374 replacement = NearestLocation(self.cursor_trace_endpos);
375 else if(escape == "d")
376 replacement = NearestLocation(self.death_origin);
377 else if(escape == "w")
382 wep = self.switchweapon;
385 replacement = W_Name(wep);
387 else if(escape == "W")
389 if(self.items & IT_SHELLS) replacement = "shells";
390 else if(self.items & IT_NAILS) replacement = "bullets";
391 else if(self.items & IT_ROCKETS) replacement = "rockets";
392 else if(self.items & IT_CELLS) replacement = "cells";
393 else replacement = "batteries"; // ;)
395 else if(escape == "x")
397 replacement = self.cursor_trace_ent.netname;
398 if(!replacement || !self.cursor_trace_ent)
399 replacement = "nothing";
401 else if(escape == "p")
403 if(self.last_selected_player)
404 replacement = self.last_selected_player.netname;
406 replacement = "(nobody)";
408 msg = strcat(substring(msg_save, 0, p), replacement);
409 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
411 msg_save = strzone(msg);
414 msg = strcat(msg_save, "");
425 >0: receives a cvar from name=argv(f) value=argv(f+1)
427 void GetCvars_handleString(float f, .string field, string name)
432 strunzone(self.field);
439 strunzone(self.field);
440 self.field = strzone(argv(f + 1));
444 stuffcmd(self, strcat("sendcvar ", name, "\n"));
446 void GetCvars_handleFloat(float f, .float field, string name)
454 self.field = stof(argv(f + 1));
457 stuffcmd(self, strcat("sendcvar ", name, "\n"));
459 void GetCvars(float f)
461 GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
462 GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
463 GetCvars_handleFloat(f, cvar_cl_zoomfactor, "cl_zoomfactor");
464 GetCvars_handleFloat(f, cvar_cl_zoomspeed, "cl_zoomspeed");
465 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
466 GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
467 GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
468 GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
469 GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
472 float fexists(string f)
475 fh = fopen(f, FILE_READ);
482 void backtrace(string msg)
485 dev = cvar("developer");
486 cvar_set("developer", "1");
488 dprint("--- CUT HERE ---\nWARNING: ");
491 remove(world); // isn't there any better way to cause a backtrace?
492 dprint("\n--- CUT UNTIL HERE ---\n");
493 cvar_set("developer", ftos(dev));
496 void DistributeFragsAmongTeam(entity p, float targetteam, float factor)
508 // p.frags = 0; // do not harm the new team!
509 // return; // won't distribute negative scores
515 f = ceil(factor * p.frags);
516 p.frags = p.frags - f;
519 FOR_EACH_PLAYER(head)
521 if(head.team == targetteam)
527 FOR_EACH_PLAYER(head)
529 if(head.team == targetteam)
531 d = floor(f / nTeam);
532 head.frags = head.frags + d;
538 error("nPlayers in team changed!");
540 error(strcat("There were ", ftos(f), " frags left. BAD!"));
543 string Team_ColorCode(float teamid)
545 if(teamid == COLOR_TEAM1)
547 else if(teamid == COLOR_TEAM2)
549 else if(teamid == COLOR_TEAM3)
551 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))
611 #define CENTERPRIO_POINT 1
612 #define CENTERPRIO_REBALANCE 2
613 #define CENTERPRIO_VOTE 4
614 #define CENTERPRIO_NORMAL 5
615 #define CENTERPRIO_MAPVOTE 9
616 #define CENTERPRIO_ADMIN 99
617 .float centerprint_priority;
618 .float centerprint_expires;
619 void centerprint_atprio(entity e, float prio, string s)
621 if(intermission_running)
622 if(prio < CENTERPRIO_MAPVOTE)
624 if(time > e.centerprint_expires)
625 e.centerprint_priority = 0;
626 if(prio >= e.centerprint_priority)
628 e.centerprint_priority = prio;
629 e.centerprint_expires = time + e.cvar_scr_centertime;
630 centerprint_builtin(e, s);
633 void centerprint_expire(entity e, float prio)
635 if(prio == e.centerprint_priority)
637 e.centerprint_priority = 0;
638 centerprint_builtin(e, "");
641 void centerprint(entity e, string s)
643 centerprint_atprio(e, CENTERPRIO_NORMAL, s);
648 // decolorizes and team colors the player name when needed
649 string playername(entity p)
652 if(teams_matter && !intermission_running && p.classname == "player")
654 t = Team_ColorCode(p.team);
655 return strcat(t, strdecolorize(p.netname));
661 // requires that m2>m1 in all coordinates, and that m4>m3
662 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;};
664 // requires the same, but is a stronger condition
665 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;};
667 float g_pickup_shells;
668 float g_pickup_shells_max;
669 float g_pickup_nails;
670 float g_pickup_nails_max;
671 float g_pickup_rockets;
672 float g_pickup_rockets_max;
673 float g_pickup_cells;
674 float g_pickup_cells_max;
675 float g_pickup_armorshard;
676 float g_pickup_armorshard_max;
677 float g_pickup_armor;
678 float g_pickup_armor_max;
679 float g_pickup_healthshard;
680 float g_pickup_healthshard_max;
681 float g_pickup_health;
682 float g_pickup_health_max;
683 float g_pickup_healthmega;
684 float g_pickup_healthmega_max;
686 void readlevelcvars(void)
688 g_pickup_shells = cvar("g_pickup_shells");
689 g_pickup_shells_max = cvar("g_pickup_shells_max");
690 g_pickup_nails = cvar("g_pickup_nails");
691 g_pickup_nails_max = cvar("g_pickup_nails_max");
692 g_pickup_rockets = cvar("g_pickup_rockets");
693 g_pickup_rockets_max = cvar("g_pickup_rockets_max");
694 g_pickup_cells = cvar("g_pickup_cells");
695 g_pickup_cells_max = cvar("g_pickup_cells_max");
696 g_pickup_armorshard = cvar("g_pickup_armorshard");
697 g_pickup_armorshard_max = cvar("g_pickup_armorshard_max");
698 g_pickup_armor = cvar("g_pickup_armor");
699 g_pickup_armor_max = cvar("g_pickup_armor_max");
700 g_pickup_healthshard = cvar("g_pickup_healthshard");
701 g_pickup_healthshard_max = cvar("g_pickup_healthshard_max");
702 g_pickup_health = cvar("g_pickup_health");
703 g_pickup_health_max = cvar("g_pickup_health_max");
704 g_pickup_healthmega = cvar("g_pickup_healthmega");
705 g_pickup_healthmega_max = cvar("g_pickup_healthmega_max");