]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/target_spawn.qc
Improve scrolling in the players list too (server info dialog)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / target_spawn.qc
index e04e2cad88f5cb33bd2639ff3f56df2593ccbdbf..6ebb837b5f9ed32e88787e2662af4a49729d6b2b 100644 (file)
@@ -1,3 +1,8 @@
+#include "_all.qh"
+
+.entity pusher;
+.float pushltime;
+
 // spawner entity
 // "classname" "target_spawn"
 // "message" "fieldname value fieldname value ..."
@@ -22,7 +27,7 @@ void target_spawn_helper_setsize()
        setsize(self, self.mins, self.maxs);
 }
 
-void target_spawn_useon(entity e)
+void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity t3, entity t4, entity act)
 {
        float i, n, valuefieldpos;
        string key, value, valuefield, valueoffset, valueoffsetrandom;
@@ -30,15 +35,8 @@ void target_spawn_useon(entity e)
        vector data, data2;
        entity oldself;
        entity oldactivator;
-       entity kt, t2, t3, t4;
 
-       n = tokenize_console(self.message);
-       self.target_spawn_activator = activator;
-
-       kt = find(world, targetname, self.killtarget);
-       t2 = find(world, targetname, self.target2);
-       t3 = find(world, targetname, self.target3);
-       t4 = find(world, targetname, self.target4);
+       n = tokenize_console(msg);
 
        for(i = 0; i < n-1; i += 2)
        {
@@ -46,13 +44,13 @@ void target_spawn_useon(entity e)
                value = argv(i+1);
                if(key == "$")
                {
-                       data_x = -1;
-                       data_y = FIELD_STRING;
+                       data.x = -1;
+                       data.y = FIELD_STRING;
                }
                else
                {
                        data = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", key)));
-                       if(data_y == 0) // undefined field, i.e., invalid type
+                       if(data.y == 0) // undefined field, i.e., invalid type
                        {
                                print("target_spawn: invalid/unknown entity key ", key, " specified, ignored!\n");
                                continue;
@@ -101,7 +99,7 @@ void target_spawn_useon(entity e)
                                }
                                else if(value == "activator")
                                {
-                                       valueent = activator;
+                                       valueent = act;
                                        value = "";
                                }
                                else if(value == "other")
@@ -111,8 +109,8 @@ void target_spawn_useon(entity e)
                                }
                                else if(value == "pusher")
                                {
-                                       if(time < activator.pushltime)
-                                               valueent = activator.pusher;
+                                       if(time < act.pushltime)
+                                               valueent = act.pusher;
                                        else
                                                valueent = world;
                                        value = "";
@@ -176,7 +174,7 @@ void target_spawn_useon(entity e)
 
                                if(valueoffset != "")
                                {
-                                       switch(data_y)
+                                       switch(data.y)
                                        {
                                                case FIELD_STRING:
                                                        value = strcat(value, valueoffset);
@@ -195,7 +193,7 @@ void target_spawn_useon(entity e)
 
                                if(valueoffsetrandom != "")
                                {
-                                       switch(data_y)
+                                       switch(data.y)
                                        {
                                                case FIELD_FLOAT:
                                                        value = ftos(stof(value) + random() * stof(valueoffsetrandom));
@@ -221,22 +219,39 @@ void target_spawn_useon(entity e)
                        oldactivator = activator;
 
                        self = e;
-                       activator = oldself.target_spawn_activator;
+                       activator = act;
 
                        self.target_spawn_spawnfunc();
 
                        self = oldself;
                        activator = oldactivator;
+
+                       // We called an external function, so we have to re-tokenize msg.
+                       n = tokenize_console(msg);
                }
                else
                {
-                       if(data_y == FIELD_VECTOR)
+                       if(data.y == FIELD_VECTOR)
                                value = strreplace("'", "", value); // why?!?
-                       putentityfieldstring(data_x, e, value);
+                       putentityfieldstring(data.x, e, value);
                }
        }
 }
 
+void target_spawn_useon(entity e)
+{
+       self.target_spawn_activator = activator;
+       target_spawn_edit_entity(
+               e,
+               self.message,
+               find(world, targetname, self.killtarget),
+               find(world, targetname, self.target2),
+               find(world, targetname, self.target3),
+               find(world, targetname, self.target4),
+               activator
+       );
+}
+
 float target_spawn_cancreate()
 {
        float c;
@@ -249,7 +264,7 @@ float target_spawn_cancreate()
        ++c; // increase count to not include MYSELF
        for(e = world; (e = findfloat(e, target_spawn_id, self.target_spawn_id)); --c)
                ;
-       
+
        // if c now is 0, we have AT LEAST the given count (maybe more), so don't spawn any more
        if(c == 0)
                return 0;
@@ -296,7 +311,7 @@ void initialize_field_db()
        {
                float n, i;
                string fn;
-               vector prev, new;
+               vector prev, next;
                float ft;
 
                n = numentityfields();
@@ -304,11 +319,11 @@ void initialize_field_db()
                {
                        fn = entityfieldname(i);
                        ft = entityfieldtype(i);
-                       new = i * '1 0 0' + ft * '0 1 0' + '0 0 1';
+                       next = i * '1 0 0' + ft * '0 1 0' + '0 0 1';
                        prev = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", fn)));
-                       if(prev_y == 0)
+                       if(prev.y == 0)
                        {
-                               db_put(TemporaryDB, strcat("/target_spawn/field/", fn), vtos(new));
+                               db_put(TemporaryDB, strcat("/target_spawn/field/", fn), vtos(next));
                                if(fn == "target_spawn_spawnfunc")
                                        target_spawn_spawnfunc_field = i;
                        }