X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Futil.qc;h=deba86c289dc8f4966407fa6dd6f7c4f9e308ed8;hb=88b1f0b3a5ebd1a81795dc40d3b9a58a707fc32d;hp=87636d24e8446fddd1566e1b6c2e5edf9601e428;hpb=e2897355e6cd1ca18e9ab1547e188eab316ce79d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 87636d24e..deba86c28 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -1,20 +1,19 @@ #include "util.qh" #if defined(CSQC) - #include "../client/defs.qh" #include "constants.qh" #include "../client/mutators/events.qh" #include "mapinfo.qh" #include "notifications/all.qh" + #include "scores.qh" #include #elif defined(MENUQC) #elif defined(SVQC) #include "constants.qh" - #include "../server/autocvars.qh" - #include "../server/defs.qh" #include "../server/mutators/events.qh" #include "notifications/all.qh" #include + #include "scores.qh" #include "mapinfo.qh" #endif @@ -24,10 +23,9 @@ */ vector real_origin(entity ent) { - entity e; vector v = ((ent.absmin + ent.absmax) * 0.5); + entity e = ent.tag_entity; - e = ent.tag_entity; while(e) { v = v + ((e.absmin + e.absmax) * 0.5); @@ -184,6 +182,7 @@ void depthfirst(entity start, .entity up, .entity downleft, .entity right, void( } } +#ifdef GAMEQC string ScoreString(int pFlags, float pValue) { string valstr; @@ -215,6 +214,7 @@ string ScoreString(int pFlags, float pValue) return valstr; } +#endif // compressed vector format: // like MD3, just even shorter @@ -228,13 +228,13 @@ string ScoreString(int pFlags, float pValue) float lengthLogTable[128]; -float invertLengthLog(float x) +float invertLengthLog(float dist) { int l, r, m; - if(x >= lengthLogTable[127]) + if(dist >= lengthLogTable[127]) return 127; - if(x <= lengthLogTable[0]) + if(dist <= lengthLogTable[0]) return 0; l = 0; @@ -243,15 +243,15 @@ float invertLengthLog(float x) while(r - l > 1) { m = floor((l + r) / 2); - if(lengthLogTable[m] < x) + if(lengthLogTable[m] < dist) l = m; else r = m; } // now: r is >=, l is < - float lerr = (x - lengthLogTable[l]); - float rerr = (lengthLogTable[r] - x); + float lerr = (dist - lengthLogTable[l]); + float rerr = (lengthLogTable[r] - dist); if(lerr < rerr) return l; return r; @@ -263,26 +263,26 @@ vector decompressShortVector(int data) if(data == 0) return '0 0 0'; float p = (data & 0xF000) / 0x1000; - float y = (data & 0x0F80) / 0x80; + float q = (data & 0x0F80) / 0x80; int len = (data & 0x007F); - //print("\ndecompress: p ", ftos(p)); print("y ", ftos(y)); print("len ", ftos(len), "\n"); + //print("\ndecompress: p ", ftos(p)); print("q ", ftos(q)); print("len ", ftos(len), "\n"); if(p == 0) { out.x = 0; out.y = 0; - if(y == 31) + if(q == 31) out.z = -1; else out.z = +1; } else { - y = .19634954084936207740 * y; + q = .19634954084936207740 * q; p = .19634954084936207740 * p - 1.57079632679489661922; - out.x = cos(y) * cos(p); - out.y = sin(y) * cos(p); + out.x = cos(q) * cos(p); + out.y = sin(q) * cos(p); out.z = -sin(p); } @@ -326,7 +326,7 @@ float compressShortVector(vector vec) STATIC_INIT(compressShortVector) { float l = 1; - float f = pow(2, 1/8); + float f = (2 ** (1/8)); int i; for(i = 0; i < 128; ++i) { @@ -336,17 +336,19 @@ STATIC_INIT(compressShortVector) if(cvar("developer")) { - LOG_INFO("Verifying vector compression table...\n"); + LOG_INFO("Verifying vector compression table..."); for(i = 0x0F00; i < 0xFFFF; ++i) if(i != compressShortVector(decompressShortVector(i))) { - LOG_INFO("BROKEN vector compression: ", ftos(i)); - LOG_INFO(" -> ", vtos(decompressShortVector(i))); - LOG_INFO(" -> ", ftos(compressShortVector(decompressShortVector(i)))); - LOG_INFO("\n"); + LOG_INFOF( + "BROKEN vector compression: %s -> %s -> %s", + ftos(i), + vtos(decompressShortVector(i)), + ftos(compressShortVector(decompressShortVector(i))) + ); error("b0rk"); } - LOG_INFO("Done.\n"); + LOG_INFO("Done."); } } @@ -414,11 +416,11 @@ string fixPriorityList(string order, float from, float to, float subtract, float string mapPriorityList(string order, string(string) mapfunc) { string neworder; - float i, n; + float n; n = tokenize_console(order); neworder = ""; - for(i = 0; i < n; ++i) + for(float i = 0; i < n; ++i) neworder = strcat(neworder, mapfunc(argv(i)), " "); return substring(neworder, 0, strlen(neworder) - 1); @@ -426,15 +428,12 @@ string mapPriorityList(string order, string(string) mapfunc) string swapInPriorityList(string order, float i, float j) { - string s; - float w, n; - - n = tokenize_console(order); + float n = tokenize_console(order); if(i >= 0 && i < n && j >= 0 && j < n && i != j) { - s = ""; - for(w = 0; w < n; ++w) + string s = ""; + for(float w = 0; w < n; ++w) { if(w == i) s = strcat(s, argv(j), " "); @@ -599,7 +598,7 @@ float cvar_settemp(string tmp_cvar, string tmp_value) if(!cvar_type(tmp_cvar)) { - LOG_INFOF("Error: cvar %s doesn't exist!\n", tmp_cvar); + LOG_INFOF("Error: cvar %s doesn't exist!", tmp_cvar); return 0; } @@ -641,7 +640,7 @@ int cvar_settemp_restore() ++j; } else - LOG_INFOF("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", it.netname); + LOG_INFOF("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.", it.netname); }); #else @@ -655,7 +654,7 @@ int cvar_settemp_restore() ++j; } else - print(sprintf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", e.netname)); + print(sprintf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.", e.netname)); } #endif @@ -672,7 +671,6 @@ bool isCaretEscaped(string theText, float pos) int skipIncompleteTag(string theText, float pos, int len) { - int i = 0, ch = 0; int tag_start = -1; if(substring(theText, pos - 1, 1) == "^") @@ -680,7 +678,7 @@ int skipIncompleteTag(string theText, float pos, int len) if(isCaretEscaped(theText, pos - 1) || pos >= len) return 0; - ch = str2chr(theText, pos); + int ch = str2chr(theText, pos); if(ch >= '0' && ch <= '9') return 1; // ^[0-9] color code found else if (ch == 'x') @@ -690,7 +688,7 @@ int skipIncompleteTag(string theText, float pos, int len) } else { - for(i = 2; pos - i >= 0 && i <= 4; ++i) + for(int i = 2; pos - i >= 0 && i <= 4; ++i) { if(substring(theText, pos - i, 2) == "^x") { @@ -784,8 +782,7 @@ string find_last_color_code(string s) if (start == -1) // no caret found return ""; int len = strlen(s)-1; - int i; - for(i = len; i >= start; --i) + for(int i = len; i >= start; --i) { if(substring(s, i, 1) != "^") continue; @@ -1073,26 +1070,25 @@ vector get_shotvelocity(vector myvel, vector mydir, float spd, float newton_styl float compressShotOrigin(vector v) { - float x, y, z; - x = rint(v.x * 2); - y = rint(v.y * 4) + 128; - z = rint(v.z * 4) + 128; - if(x > 255 || x < 0) + float rx = rint(v.x * 2); + float ry = rint(v.y * 4) + 128; + float rz = rint(v.z * 4) + 128; + if(rx > 255 || rx < 0) { - LOG_INFO("shot origin ", vtos(v), " x out of bounds\n"); - x = bound(0, x, 255); + LOG_DEBUG("shot origin ", vtos(v), " x out of bounds\n"); + rx = bound(0, rx, 255); } - if(y > 255 || y < 0) + if(ry > 255 || ry < 0) { - LOG_INFO("shot origin ", vtos(v), " y out of bounds\n"); - y = bound(0, y, 255); + LOG_DEBUG("shot origin ", vtos(v), " y out of bounds\n"); + ry = bound(0, ry, 255); } - if(z > 255 || z < 0) + if(rz > 255 || rz < 0) { - LOG_INFO("shot origin ", vtos(v), " z out of bounds\n"); - z = bound(0, z, 255); + LOG_DEBUG("shot origin ", vtos(v), " z out of bounds\n"); + rz = bound(0, rz, 255); } - return x * 0x10000 + y * 0x100 + z; + return rx * 0x10000 + ry * 0x100 + rz; } vector decompressShotOrigin(int f) { @@ -1368,7 +1364,7 @@ void m_shutdown() { if(shutdown_running) { - LOG_INFO("Recursive shutdown detected! Only restoring cvars...\n"); + LOG_INFO("Recursive shutdown detected! Only restoring cvars..."); } else {