]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Partial fix for turret checkpoints (find doesn't work during spawning)
authorMario <mario@smbclan.net>
Mon, 29 May 2017 12:58:47 +0000 (22:58 +1000)
committerMario <mario@smbclan.net>
Mon, 29 May 2017 12:58:47 +0000 (22:58 +1000)
qcsrc/common/turrets/sv_turrets.qc
qcsrc/common/turrets/turret/ewheel.qc
qcsrc/common/turrets/turret/walker.qc

index 4d598db543a1ba0f006702b26f1f31119590eb80..ae8cd5323b49dfcd6a3789089e1396bf601a0b56 100644 (file)
@@ -1245,6 +1245,30 @@ void turret_initparams(entity tur)
        #undef TRY
 }
 
+void turret_findtarget(entity this)
+{
+       entity e = find(NULL, classname, "turret_manager");
+       if(!e)
+       {
+               e = new(turret_manager);
+               setthink(e, turrets_manager_think);
+               e.nextthink = time + 2;
+       }
+       
+       entity targ = find(NULL, targetname, this.target);
+       if(targ.classname == "turret_checkpoint")
+               return; // turrets don't defend checkpoints?
+
+       if (!targ)
+       {
+               this.target = "";
+               LOG_TRACE("Turret has invalid defendpoint!");
+       }
+
+       this.tur_defend = targ;
+       this.idle_aim = this.tur_head.angles + angleofs(this.tur_head, targ);
+}
+
 bool turret_initialize(entity this, Turret tur)
 {
        if(!autocvar_g_turrets)
@@ -1260,14 +1284,6 @@ bool turret_initialize(entity this, Turret tur)
                IL_PUSH(g_bot_targets, this);
        }
 
-       entity e = find(NULL, classname, "turret_manager");
-       if(!e)
-       {
-               e = new(turret_manager);
-               setthink(e, turrets_manager_think);
-               e.nextthink = time + 2;
-       }
-
        if(!(this.spawnflags & TSF_SUSPENDED))
                droptofloor(this);
 
@@ -1341,6 +1357,7 @@ bool turret_initialize(entity this, Turret tur)
        this.takedamage                         = DAMAGE_AIM;
        set_movetype(this, MOVETYPE_NOCLIP);
        this.view_ofs                           = '0 0 0';
+       this.idle_aim                           = '0 0 0';
        this.turret_firecheckfunc       = turret_firecheck;
        this.event_damage                       = turret_damage;
        this.use                                        = turret_use;
@@ -1363,21 +1380,8 @@ bool turret_initialize(entity this, Turret tur)
 
        this.weaponentities[0] = this; // lol
 
-       if(!this.tur_defend)
-       if(this.target != "")
-       {
-               this.tur_defend = find(NULL, targetname, this.target);
-               if (this.tur_defend == NULL)
-               {
-                       this.target = "";
-                       LOG_TRACE("Turret has invalid defendpoint!");
-               }
-       }
-
-       if (this.tur_defend)
-               this.idle_aim = this.tur_head.angles + angleofs(this.tur_head, this.tur_defend);
-       else
-               this.idle_aim = '0 0 0';
+       if(!this.tur_defend && this.target != "")
+               InitializeEntity(this, turret_findtarget, INITPRIO_FINDTARGET);
 
 #ifdef TURRET_DEBUG
        this.tur_debug_start = this.nextthink;
index d2feb0823c44933e89fe013cf66daf41864c2af0..cf53508b6f63adca3314782182b8739c9bba5b17 100644 (file)
@@ -113,6 +113,29 @@ void ewheel_move_idle(entity this)
         movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop));
 }
 
+void ewheel_findtarget(entity this)
+{
+    entity e = find(NULL, targetname, this.target);
+    if (!e)
+    {
+        LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!");
+        this.target = "";
+    }
+
+    if (e.classname != "turret_checkpoint")
+        LOG_TRACE("Warning: not a turret path");
+    else
+    {
+
+#ifdef EWHEEL_FANCYPATH
+        this.pathcurrent = pathlib_astar(this, this.origin, e.origin);
+        this.pathgoal = e;
+#else
+        this.pathcurrent  = e;
+#endif
+    }
+}
+
 spawnfunc(turret_ewheel) { if(!turret_initialize(this, TUR_EWHEEL)) delete(this); }
 
 METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
@@ -162,8 +185,6 @@ METHOD(EWheel, tr_death, void(EWheel this, entity it))
 
 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
 {
-    entity e;
-
     if(it.move_movetype == MOVETYPE_WALK)
     {
         it.velocity = '0 0 0';
@@ -172,27 +193,7 @@ METHOD(EWheel, tr_setup, void(EWheel this, entity it))
         setorigin(it, it.pos1);
 
         if (it.target != "")
-        {
-            e = find(NULL, targetname, it.target);
-            if (!e)
-            {
-                LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!");
-                it.target = "";
-            }
-
-            if (e.classname != "turret_checkpoint")
-                LOG_TRACE("Warning: not a turret path");
-            else
-            {
-
-#ifdef EWHEEL_FANCYPATH
-                it.pathcurrent = pathlib_astar(it, it.origin, e.origin);
-                it.pathgoal = e;
-#else
-                it.pathcurrent  = e;
-#endif
-            }
-        }
+            InitializeEntity(it, ewheel_findtarget, INITPRIO_FINDTARGET);
     }
 
     it.iscreature                              = true;
index 0a82a4a7bcef08cd1db7c03cdbcc925ca6c0474f..d8c0a675d5c0b1175be5a3f6d79c6e086df88f3d 100644 (file)
@@ -43,8 +43,6 @@ const int ANIM_ROAM       = 11;
 .float animflag;
 .float idletime;
 
-#define WALKER_PATH(this, s, e) pathlib_astar(this, s, e)
-
 bool walker_firecheck(entity this)
 {
     if (this.animflag == ANIM_MELEE)
@@ -299,7 +297,7 @@ void walker_move_path(entity this)
 
                 if (this.pathgoal.enemy)
                 {
-                    this.pathcurrent = WALKER_PATH(this, this.pathgoal.origin, this.pathgoal.enemy.origin);
+                    this.pathcurrent = pathlib_astar(this, this.pathgoal.origin, this.pathgoal.enemy.origin);
                     this.pathgoal = this.pathgoal.enemy;
                 }
             }
@@ -326,6 +324,30 @@ void walker_move_path(entity this)
 #endif
 }
 
+void walker_findtarget(entity this)
+{
+    entity e = find(NULL, targetname, this.target);
+    if (!e)
+    {
+        LOG_TRACE("Initital waypoint for walker does NOT exist, fix your map!");
+        this.target = "";
+    }
+
+    if (e.classname != "turret_checkpoint")
+        LOG_TRACE("Warning: not a turrret path");
+    else
+    {
+#ifdef WALKER_FANCYPATHING
+        this.pathcurrent = pathlib_astar(this, this.origin, e.origin);
+        this.pathgoal = e;
+#else
+        this.pathcurrent = e;
+#endif
+    }
+
+    // TODO: this doesn't reset target, so tur_defend will be the checkpoint too!
+}
+
 spawnfunc(turret_walker) { if(!turret_initialize(this, TUR_WALKER)) delete(this); }
 
 METHOD(WalkerTurret, tr_think, void(WalkerTurret thistur, entity it))
@@ -550,8 +572,6 @@ METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
 {
     it.ticrate = 0.05;
 
-    entity e;
-
     // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
     if(it.move_movetype == MOVETYPE_WALK)
     {
@@ -587,26 +607,7 @@ METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
     it.turret_firecheckfunc = walker_firecheck;
 
     if (it.target != "")
-    {
-        e = find(NULL, targetname, it.target);
-        if (!e)
-        {
-            LOG_TRACE("Initital waypoint for walker does NOT exsist, fix your map!");
-            it.target = "";
-        }
-
-        if (e.classname != "turret_checkpoint")
-            LOG_TRACE("Warning: not a turrret path");
-        else
-        {
-#ifdef WALKER_FANCYPATHING
-            it.pathcurrent = WALKER_PATH(it, it.origin, e.origin);
-            it.pathgoal = e;
-#else
-            it.pathcurrent = e;
-#endif
-        }
-    }
+        InitializeEntity(it, walker_findtarget, INITPRIO_FINDTARGET);
 }
 
 #endif // SVQC