]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/target/spawn.qc
Bot AI: reduce powerup rating value
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / target / spawn.qc
index 74ac8fd99ad8899e6d556cbf9837929f0e2b2664..9c999ed4df4758612b9052a34aeb22101b85b905 100644 (file)
@@ -1,3 +1,4 @@
+#include "spawn.qh"
 #if defined(CSQC)
 #elif defined(MENUQC)
 #elif defined(SVQC)
@@ -11,8 +12,7 @@
 // "classname" "target_spawn"
 // "message" "fieldname value fieldname value ..."
 // "spawnflags"
-//   1 = call the spawn function
-//   2 = trigger on map load
+//   ON_MAPLOAD = trigger on map load
 
 float target_spawn_initialized;
 .void(entity this) target_spawn_spawnfunc;
@@ -21,14 +21,14 @@ float target_spawn_spawnfunc_field;
 .float target_spawn_id;
 float target_spawn_count;
 
-void target_spawn_helper_setmodel()
-{SELFPARAM();
-       _setmodel(self, self.model);
+void target_spawn_helper_setmodel(entity this)
+{
+       _setmodel(this, this.model);
 }
 
-void target_spawn_helper_setsize()
-{SELFPARAM();
-       setsize(self, self.mins, self.maxs);
+void target_spawn_helper_setsize(entity this)
+{
+       setsize(this, this.mins, this.maxs);
 }
 
 void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, entity t2, entity t3, entity t4, entity act, entity trigger)
@@ -54,7 +54,7 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti
                        data = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", key)));
                        if(data.y == 0) // undefined field, i.e., invalid type
                        {
-                               LOG_INFO("target_spawn: invalid/unknown entity key ", key, " specified, ignored!\n");
+                               LOG_INFO("target_spawn: invalid/unknown entity key ", key, " specified, ignored!");
                                continue;
                        }
                }
@@ -114,7 +114,7 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti
                                        if(time < act.pushltime)
                                                valueent = act.pusher;
                                        else
-                                               valueent = world;
+                                               valueent = NULL;
                                        value = "";
                                }
                                else if(value == "target")
@@ -144,12 +144,12 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti
                                }
                                else if(value == "time")
                                {
-                                       valueent = world;
+                                       valueent = NULL;
                                        value = ftos(time);
                                }
                                else
                                {
-                                       LOG_INFO("target_spawn: invalid/unknown variable replacement ", value, " specified, ignored!\n");
+                                       LOG_INFO("target_spawn: invalid/unknown variable replacement ", value, " specified, ignored!");
                                        continue;
                                }
 
@@ -162,13 +162,13 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti
                                {
                                        if(value != "")
                                        {
-                                               LOG_INFO("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!");
                                                continue;
                                        }
                                        data2 = stov(db_get(TemporaryDB, strcat("/target_spawn/field/", valuefield)));
                                        if(data2_y == 0) // undefined field, i.e., invalid type
                                        {
-                                               LOG_INFO("target_spawn: invalid/unknown entity key replacement ", valuefield, " specified, ignored!\n");
+                                               LOG_INFO("target_spawn: invalid/unknown entity key replacement ", valuefield, " specified, ignored!");
                                                continue;
                                        }
                                        value = getentityfieldstring(data2_x, valueent);
@@ -188,7 +188,7 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti
                                                        value = vtos(stov(value) + stov(valueoffset));
                                                        break;
                                                default:
-                                                       LOG_INFO("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!");
                                                        break;
                                        }
                                }
@@ -205,7 +205,7 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti
                                                        value = vtos(stov(value) + random() * data2_x * '1 0 0' + random() * data2_y * '0 1 0' + random() * data2_z * '0 0 1');
                                                        break;
                                                default:
-                                                       LOG_INFO("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!");
                                                        break;
                                        }
                                }
@@ -217,7 +217,7 @@ void target_spawn_edit_entity(entity this, entity e, string msg, entity kt, enti
                                value = strcat("target_spawn_helper", value);
                        putentityfieldstring(target_spawn_spawnfunc_field, e, value);
 
-                       WITHSELF(e, e.target_spawn_spawnfunc(e));
+                       e.target_spawn_spawnfunc(e);
 
                        // We called an external function, so we have to re-tokenize msg.
                        n = tokenize_console(msg);
@@ -238,10 +238,10 @@ void target_spawn_useon(entity e, entity this, entity actor, entity trigger)
                this,
                e,
                this.message,
-               find(world, targetname, this.killtarget),
-               find(world, targetname, this.target2),
-               find(world, targetname, this.target3),
-               find(world, targetname, this.target4),
+               find(NULL, targetname, this.killtarget),
+               find(NULL, targetname, this.target2),
+               find(NULL, targetname, this.target3),
+               find(NULL, targetname, this.target4),
                actor,
                trigger
        );
@@ -257,7 +257,7 @@ bool target_spawn_cancreate(entity this)
                return true;
 
        ++c; // increase count to not include MYSELF
-       for(e = world; (e = findfloat(e, target_spawn_id, this.target_spawn_id)); --c)
+       for(e = NULL; (e = findfloat(e, target_spawn_id, this.target_spawn_id)); --c)
                ;
 
        // if c now is 0, we have AT LEAST the given count (maybe more), so don't spawn any more
@@ -287,15 +287,17 @@ void target_spawn_use(entity this, entity actor, entity trigger)
        else
        {
                // edit entity
-               for(entity e = world; (e = find(e, targetname, this.target)); )
-                       target_spawn_useon(e, this, actor, trigger);
+               FOREACH_ENTITY_STRING(targetname, this.target,
+               {
+                       target_spawn_useon(it, this, actor, trigger);
+               });
        }
 }
 
 void target_spawn_spawnfirst(entity this)
 {
        entity act = this.target_spawn_activator;
-       if(this.spawnflags & 2)
+       if(this.spawnflags & ON_MAPLOAD)
                target_spawn_use(this, act, NULL);
 }
 
@@ -330,9 +332,9 @@ void initialize_field_db()
 spawnfunc(target_spawn)
 {
        initialize_field_db();
-       self.use = target_spawn_use;
-       self.message = strzone(strreplace("'", "\"", self.message));
-       self.target_spawn_id = ++target_spawn_count;
-       InitializeEntity(self, target_spawn_spawnfirst, INITPRIO_LAST);
+       this.use = target_spawn_use;
+       this.message = strzone(strreplace("'", "\"", this.message));
+       this.target_spawn_id = ++target_spawn_count;
+       InitializeEntity(this, target_spawn_spawnfirst, INITPRIO_LAST);
 }
 #endif