return valstr;
}
+float dotproduct(vector a, vector b)
+{
+ return a_x * b_x + a_y * b_y + a_z * b_z;
+}
+
vector cross(vector a, vector b)
{
return
float created_saved_value;
entity e;
- created_saved_value = FALSE;
-
+ created_saved_value = 0;
+
if not(tmp_cvar || tmp_value)
{
dprint("Error: Invalid usage of cvar_settemp(string, string); !\n");
- return FALSE;
+ return 0;
}
-
+
+ if(!cvar_type(tmp_cvar))
+ {
+ print(sprintf("Error: cvar %s doesn't exist!\n", tmp_cvar));
+ return 0;
+ }
+
for(e = world; (e = find(e, classname, "saved_cvar_value")); )
if(e.netname == tmp_cvar)
- goto saved; // skip creation
-
- // creating a new entity to keep track of this cvar
- e = spawn();
- e.classname = "saved_cvar_value";
- e.netname = strzone(tmp_cvar);
- e.message = strzone(cvar_string(tmp_cvar));
- created_saved_value = TRUE;
-
- // an entity for this cvar already exists
- :saved
-
+ created_saved_value = -1; // skip creation
+
+ if(created_saved_value != -1)
+ {
+ // creating a new entity to keep track of this cvar
+ e = spawn();
+ e.classname = "saved_cvar_value";
+ e.netname = strzone(tmp_cvar);
+ e.message = strzone(cvar_string(tmp_cvar));
+ created_saved_value = 1;
+ }
+
// update the cvar to the value given
cvar_set(tmp_cvar, tmp_value);
-
+
return created_saved_value;
}
float cvar_settemp_restore()
{
- float i;
- entity e;
- while((e = find(world, classname, "saved_cvar_value")))
+ float i = 0;
+ entity e = world;
+ while((e = find(e, classname, "saved_cvar_value")))
{
- cvar_set(e.netname, e.message);
- remove(e);
+ if(cvar_type(e.netname))
+ {
+ cvar_set(e.netname, e.message);
+ remove(e);
+ ++i;
+ }
+ else
+ print(sprintf("Error: cvar %s doesn't exist anymore! It can still be restored once it's manually recreated.\n", e.netname));
}
-
+
return i;
}
if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
if(strstrofs(strcat(",", pattern, ","), subpattern2, 0) < 0)
if(strstrofs(strcat(",", pattern, ","), subpattern3, 0) < 0)
- if((!subpattern4) || strstrofs(strcat(",", pattern, ","), subpattern4, 0) < 0)
- return 0;
+ {
+ if not(subpattern4)
+ return 0;
+ if(strstrofs(strcat(",", pattern, ","), subpattern4, 0) < 0)
+ return 0;
+ }
}
return 1;
}
}
to_execute_next_frame = strzone(s);
}
+
+float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float x)
+{
+ return
+ ((( startspeedfactor + endspeedfactor - 2
+ ) * x - 2 * startspeedfactor - endspeedfactor + 3
+ ) * x + startspeedfactor
+ ) * x;
+}
+
+float cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor)
+{
+ if(startspeedfactor < 0 || endspeedfactor < 0)
+ return FALSE;
+
+ /*
+ // if this is the case, the possible zeros of the first derivative are outside
+ // 0..1
+ We can calculate this condition as condition
+ if(se <= 3)
+ return TRUE;
+ */
+
+ // better, see below:
+ if(startspeedfactor <= 3 && endspeedfactor <= 3)
+ return TRUE;
+
+ // if this is the case, the first derivative has no zeros at all
+ float se = startspeedfactor + endspeedfactor;
+ float s_e = startspeedfactor - endspeedfactor;
+ if(3 * (se - 4) * (se - 4) + s_e * s_e <= 12) // an ellipse
+ return TRUE;
+
+ // Now let s <= 3, s <= 3, s+e >= 3 (triangle) then we get se <= 6 (top right corner).
+ // we also get s_e <= 6 - se
+ // 3 * (se - 4)^2 + (6 - se)^2
+ // is quadratic, has value 12 at 3 and 6, and value < 12 in between.
+ // Therefore, above "better" check works!
+
+ return FALSE;
+
+ // known good cases:
+ // (0, [0..3])
+ // (0.5, [0..3.8])
+ // (1, [0..4])
+ // (1.5, [0..3.9])
+ // (2, [0..3.7])
+ // (2.5, [0..3.4])
+ // (3, [0..3])
+ // (3.5, [0.2..2.3])
+ // (4, 1)
+}
+
+.float FindConnectedComponent_processing;
+void FindConnectedComponent(entity e, .entity fld, findNextEntityNearFunction_t nxt, isConnectedFunction_t iscon, entity pass)
+{
+ entity queue_start, queue_end;
+
+ // we build a queue of to-be-processed entities.
+ // queue_start is the next entity to be checked for neighbors
+ // queue_end is the last entity added
+
+ if(e.FindConnectedComponent_processing)
+ error("recursion or broken cleanup");
+
+ // start with a 1-element queue
+ queue_start = queue_end = e;
+ queue_end.fld = world;
+ queue_end.FindConnectedComponent_processing = 1;
+
+ // for each queued item:
+ for(; queue_start; queue_start = queue_start.fld)
+ {
+ // find all neighbors of queue_start
+ entity t;
+ for(t = world; (t = nxt(t, queue_start, pass)); )
+ {
+ if(t.FindConnectedComponent_processing)
+ continue;
+ if(iscon(t, queue_start, pass))
+ {
+ // it is connected? ADD IT. It will look for neighbors soon too.
+ queue_end.fld = t;
+ queue_end = t;
+ queue_end.fld = world;
+ queue_end.FindConnectedComponent_processing = 1;
+ }
+ }
+ }
+
+ // unmark
+ for(queue_start = e; queue_start; queue_start = queue_start.fld)
+ queue_start.FindConnectedComponent_processing = 0;
+}
+
+float Count_Proper_Strings(string improper, string...count)
+{
+ float i, total = 0;
+ string tmp;
+
+ for(i = 0; i < count; ++i)
+ {
+ tmp = ...(i, string);
+ if((tmp) && (tmp != improper)) { ++total; }
+ }
+
+ return total;
+}
+
+float Count_Proper_Floats(float improper, float...count)
+{
+ float i, total = 0;
+
+ for(i = 0; i < count; ++i)
+ {
+ if(...(i, float) != improper) { ++total; }
+ }
+
+ return total;
+}