From: Mario Date: Mon, 29 May 2017 12:58:47 +0000 (+1000) Subject: Partial fix for turret checkpoints (find doesn't work during spawning) X-Git-Tag: xonotic-v0.8.5~2747 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=01cc4bb5af8873b218ed12ccad850f6d0230e072;p=xonotic%2Fxonotic-data.pk3dir.git Partial fix for turret checkpoints (find doesn't work during spawning) --- diff --git a/qcsrc/common/turrets/sv_turrets.qc b/qcsrc/common/turrets/sv_turrets.qc index 4d598db54..ae8cd5323 100644 --- a/qcsrc/common/turrets/sv_turrets.qc +++ b/qcsrc/common/turrets/sv_turrets.qc @@ -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; diff --git a/qcsrc/common/turrets/turret/ewheel.qc b/qcsrc/common/turrets/turret/ewheel.qc index d2feb0823..cf53508b6 100644 --- a/qcsrc/common/turrets/turret/ewheel.qc +++ b/qcsrc/common/turrets/turret/ewheel.qc @@ -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; diff --git a/qcsrc/common/turrets/turret/walker.qc b/qcsrc/common/turrets/turret/walker.qc index 0a82a4a7b..d8c0a675d 100644 --- a/qcsrc/common/turrets/turret/walker.qc +++ b/qcsrc/common/turrets/turret/walker.qc @@ -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