]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add a spawn_range field to the spawner, to auto create a trigger field around the...
authorMario <mario@smbclan.net>
Mon, 13 Mar 2017 05:13:05 +0000 (15:13 +1000)
committerMario <mario@smbclan.net>
Mon, 13 Mar 2017 05:13:05 +0000 (15:13 +1000)
qcsrc/common/monsters/sv_spawner.qc

index af4ce841d4ae2543dd7da1449b8e27562f48edc5..7e7f135613a27476e7a915eda437dc362c3370f8 100644 (file)
@@ -3,6 +3,7 @@
 bool autocvar_g_monster_spawner_copyfields = false; // just incase this gets too nasty
 
 .bool use_trigger_origin;
+.float spawn_range; // using a new field here, so as to not interfere with anything monsters might use
 
 void spawner_use(entity this, entity actor, entity trigger)
 {
@@ -40,9 +41,41 @@ void spawner_use(entity this, entity actor, entity trigger)
        e = spawnmonster(e, this.spawnmob, 0, this, this, org, false, true, this.monster_moveflags);
 }
 
+void spawner_trigger_touch(entity this, entity toucher)
+{
+       if(!toucher.iscreature || IS_DEAD(toucher) || toucher.health < 1)
+               return; // only players
+
+       spawner_use(this.owner, toucher, this);
+}
+
+void spawner_settargets(entity this)
+{
+       // if the spawner isn't targeted by anything, create a trigger around it based on its spawn range
+       if(this.spawn_range <= 0)
+               return;
+
+       IFTARGETED
+               return;
+
+       entity trigger = new(spawnertriggerfield);
+       set_movetype(trigger, MOVETYPE_NONE);
+       trigger.solid = SOLID_TRIGGER;
+       trigger.owner = this;
+       settouch(trigger, spawner_trigger_touch);
+
+       vector offset = '1 1 1.5' * this.spawn_range;
+       setsize(trigger, this.origin - offset, this.origin + offset);
+}
+
 spawnfunc(monster_spawner)
 {
        if(!autocvar_g_monsters || !this.spawnmob || this.spawnmob == "") { delete(this); return; }
 
        this.use = spawner_use;
+
+       if(!this.spawn_range)
+               this.spawn_range = 500; // default it so we can work without targets
+
+       InitializeEntity(this, spawner_settargets, INITPRIO_FINDTARGET);
 }