#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)
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);
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;
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;
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))
METHOD(EWheel, tr_setup, void(EWheel this, entity it))
{
- entity e;
-
if(it.move_movetype == MOVETYPE_WALK)
{
it.velocity = '0 0 0';
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;
.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)
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;
}
}
#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))
{
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)
{
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