1 string wordwrap_buffer;
3 void wordwrap_buffer_put(string s)
5 wordwrap_buffer = strcat(wordwrap_buffer, s);
8 string wordwrap(string s, float l)
11 wordwrap_cb(s, l, wordwrap_buffer_put);
12 return wordwrap_buffer;
16 void wordwrap_buffer_sprint(string s)
18 wordwrap_buffer = strcat(wordwrap_buffer, s);
21 sprint(self, wordwrap_buffer);
26 void wordwrap_sprint(string s, float l)
29 wordwrap_cb(s, l, wordwrap_buffer_sprint);
30 if(wordwrap_buffer != "")
31 sprint(self, strcat(wordwrap_buffer, "\n"));
36 void wordwrap_cb(string s, float l, void(string) callback)
39 local float lleft, i, j, wlen;
43 for (i = 0;i < strlen(s);i++)
45 if (substring(s, i, 2) == "\\n")
51 else if (substring(s, i, 1) == " ")
61 for (j = i+1;j < strlen(s);j++)
62 // ^^ this skips over the first character of a word, which
63 // is ALWAYS part of the word
64 // this is safe since if i+1 == strlen(s), i will become
65 // strlen(s)-1 at the end of this block and the function
66 // will terminate. A space can't be the first character we
67 // read here, and neither can a \n be the start, since these
68 // two cases have been handled above.
70 c = substring(s, j, 1);
75 // we need to keep this tempstring alive even if substring is
76 // called repeatedly, so call strcat even though we're not
86 callback(substring(s, i, wlen));
94 float dist_point_line(vector p, vector l0, vector ldir)
96 ldir = normalize(ldir);
98 // remove the component in line direction
99 p = p - (p * ldir) * ldir;
101 // vlen of the remaining vector
105 void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
134 float median(float a, float b, float c)
137 return bound(a, b, c);
138 return bound(c, b, a);
141 // converts a number to a string with the indicated number of decimals
142 // works for up to 10 decimals!
143 string ftos_decimals(float number, float decimals)
149 // if negative, cut off the sign first
151 return strcat("-", ftos_decimals(-number, decimals));
152 // it now is always positive!
155 number = floor(number * pow(10, decimals) + 0.5);
158 result = ftos(number);
159 len = strlen(result);
160 // does it have a decimal point (should not happen)? If there is one, it is always at len-7)
161 // if ftos had fucked it up, which should never happen: "34278.000000"
163 if(substring(result, len - 7, 1) == ".")
165 dprint("ftos(integer) has comma? Can't be. Affected result: ", result, "\n");
166 result = substring(result, 0, len - 7);
171 return result; // don't insert a point for zero decimals
172 // is it too short? If yes, insert leading zeroes
175 result = strcat(substring("0000000000", 0, decimals - len + 1), result);
178 // and now... INSERT THE POINT!
179 tmp = substring(result, len - decimals, decimals);
180 result = strcat(substring(result, 0, len - decimals), ".", tmp);
185 vector colormapPaletteColor(float c, float isPants)
189 case 0: return '0.733 0.733 0.733';
190 case 1: return '0.451 0.341 0.122';
191 case 2: return '0.000 0.733 0.733';
192 case 3: return '0.000 1.000 0.000';
193 case 4: return '1.000 0.000 0.000';
194 case 5: return '0.000 0.502 1.000';
195 case 6: return '0.812 0.561 0.169';
196 case 7: return '0.718 0.529 0.420';
197 case 8: return '0.765 0.545 0.667';
198 case 9: return '1.000 0.000 1.000';
199 case 10: return '0.639 0.529 0.482';
200 case 11: return '0.310 0.388 0.341';
201 case 12: return '1.000 1.000 0.000';
202 case 13: return '0.000 0.000 1.000';
203 case 14: return '1.000 0.502 0.000';
207 '1 0 0' * (0.502 + 0.498 * sin(time / 2.7182818285 + 0.0000000000))
208 + '0 1 0' * (0.502 + 0.498 * sin(time / 2.7182818285 + 2.0943951024))
209 + '0 0 1' * (0.502 + 0.498 * sin(time / 2.7182818285 + 4.1887902048));
212 '1 0 0' * (0.502 + 0.498 * sin(time / 3.1415926536 + 5.2359877560))
213 + '0 1 0' * (0.502 + 0.498 * sin(time / 3.1415926536 + 3.1415926536))
214 + '0 0 1' * (0.502 + 0.498 * sin(time / 3.1415926536 + 1.0471975512));
215 default: return '0.000 0.000 0.000';