]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/target/spawn.qc
Merge branch 'terencehill/menu_optimization' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / target / spawn.qc
index d661b98eb494f299b79f7f9f705d7a923eb06222..96c266f6cc57315e2436e3f752321b83405a5ab8 100644 (file)
@@ -1,4 +1,12 @@
+#if defined(CSQC)
+#elif defined(MENUQC)
+#elif defined(SVQC)
+    #include <common/util.qh>
+    #include <server/defs.qh>
+#endif
+
 #ifdef SVQC
+
 // spawner entity
 // "classname" "target_spawn"
 // "message" "fieldname value fieldname value ..."
 //   2 = trigger on map load
 
 float target_spawn_initialized;
-.void() target_spawn_spawnfunc;
+.void(entity this) target_spawn_spawnfunc;
 float target_spawn_spawnfunc_field;
 .entity target_spawn_activator;
 .float target_spawn_id;
 float target_spawn_count;
 
 void target_spawn_helper_setmodel()
-{
-       setmodel(self, self.model);
+{SELFPARAM();
+       _setmodel(self, self.model);
 }
 
 void target_spawn_helper_setsize()
-{
+{SELFPARAM();
        setsize(self, self.mins, self.maxs);
 }
 
 void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity t3, entity t4, entity act)
-{
+{SELFPARAM();
        float i, n, valuefieldpos;
        string key, value, valuefield, valueoffset, valueoffsetrandom;
        entity valueent;
        vector data, data2;
-       entity oldself;
        entity oldactivator;
 
        n = tokenize_console(msg);
@@ -40,15 +47,15 @@ void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity
                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");
+                               LOG_INFO("target_spawn: invalid/unknown entity key ", key, " specified, ignored!\n");
                                continue;
                        }
                }
@@ -143,26 +150,26 @@ void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity
                                }
                                else
                                {
-                                       print("target_spawn: invalid/unknown variable replacement ", value, " specified, ignored!\n");
+                                       LOG_INFO("target_spawn: invalid/unknown variable replacement ", value, " specified, ignored!\n");
                                        continue;
                                }
 
                                if(valuefield == "")
                                {
                                        if(value == "")
-                                               value = ftos(num_for_edict(valueent));
+                                               value = ftos(etof(valueent));
                                }
                                else
                                {
                                        if(value != "")
                                        {
-                                               print("target_spawn: try to get a field of a non-entity, ignored!\n");
+                                               LOG_INFO("target_spawn: try to get a field of a non-entity, ignored!\n");
                                                continue;
                                        }
                                        data2 = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", valuefield)));
                                        if(data2_y == 0) // undefined field, i.e., invalid type
                                        {
-                                               print("target_spawn: invalid/unknown entity key replacement ", valuefield, " specified, ignored!\n");
+                                               LOG_INFO("target_spawn: invalid/unknown entity key replacement ", valuefield, " specified, ignored!\n");
                                                continue;
                                        }
                                        value = getentityfieldstring(data2_x, valueent);
@@ -170,7 +177,7 @@ void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity
 
                                if(valueoffset != "")
                                {
-                                       switch(data_y)
+                                       switch(data.y)
                                        {
                                                case FIELD_STRING:
                                                        value = strcat(value, valueoffset);
@@ -182,14 +189,14 @@ void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity
                                                        value = vtos(stov(value) + stov(valueoffset));
                                                        break;
                                                default:
-                                                       print("target_spawn: only string, float and vector fields can do calculations, calculation ignored!\n");
+                                                       LOG_INFO("target_spawn: only string, float and vector fields can do calculations, calculation ignored!\n");
                                                        break;
                                        }
                                }
 
                                if(valueoffsetrandom != "")
                                {
-                                       switch(data_y)
+                                       switch(data.y)
                                        {
                                                case FIELD_FLOAT:
                                                        value = ftos(stof(value) + random() * stof(valueoffsetrandom));
@@ -199,7 +206,7 @@ void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity
                                                        value = vtos(stov(value) + random() * data2_x * '1 0 0' + random() * data2_y * '0 1 0' + random() * data2_z * '0 0 1');
                                                        break;
                                                default:
-                                                       print("target_spawn: only float and vector fields can do random calculations, calculation ignored!\n");
+                                                       LOG_INFO("target_spawn: only float and vector fields can do random calculations, calculation ignored!\n");
                                                        break;
                                        }
                                }
@@ -211,28 +218,26 @@ void target_spawn_edit_entity(entity e, string msg, entity kt, entity t2, entity
                                value = strcat("target_spawn_helper", value);
                        putentityfieldstring(target_spawn_spawnfunc_field, e, value);
 
-                       oldself = self;
                        oldactivator = activator;
 
-                       self = e;
                        activator = act;
-
-                       self.target_spawn_spawnfunc();
-
-                       self = oldself;
+                       WITH(entity, self, e, e.target_spawn_spawnfunc(e));
                        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)
-{
+{SELFPARAM();
        self.target_spawn_activator = activator;
        target_spawn_edit_entity(
                e,
@@ -246,7 +251,7 @@ void target_spawn_useon(entity e)
 }
 
 float target_spawn_cancreate()
-{
+{SELFPARAM();
        float c;
        entity e;
 
@@ -265,7 +270,7 @@ float target_spawn_cancreate()
 }
 
 void target_spawn_use()
-{
+{SELFPARAM();
        entity e;
 
        if(self.target == "")
@@ -274,6 +279,7 @@ void target_spawn_use()
                if(!target_spawn_cancreate())
                        return;
                e = spawn();
+               e.spawnfunc_checked = true;
                target_spawn_useon(e);
                e.target_spawn_id = self.target_spawn_id;
        }
@@ -292,7 +298,7 @@ void target_spawn_use()
 }
 
 void target_spawn_spawnfirst()
-{
+{SELFPARAM();
        activator = self.target_spawn_activator;
        if(self.spawnflags & 2)
                target_spawn_use();
@@ -304,7 +310,7 @@ void initialize_field_db()
        {
                float n, i;
                string fn;
-               vector prev, new;
+               vector prev, next;
                float ft;
 
                n = numentityfields();
@@ -312,11 +318,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;
                        }
@@ -326,7 +332,7 @@ void initialize_field_db()
        }
 }
 
-void spawnfunc_target_spawn()
+spawnfunc(target_spawn)
 {
        initialize_field_db();
        self.use = target_spawn_use;