From: Jakob MG Date: Sun, 19 Jun 2011 14:24:34 +0000 (+0200) Subject: Cleanup & reorganice csqc a bit, remove code duplication and overhead from walker... X-Git-Tag: xonotic-v0.5.0~199^2^2~16 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=813817fff75452352982dd94bd2d6a34a819db3c;p=xonotic%2Fxonotic-data.pk3dir.git Cleanup & reorganice csqc a bit, remove code duplication and overhead from walker. give walker roam ability when idle. --- diff --git a/qcsrc/client/tturrets.qc b/qcsrc/client/tturrets.qc index 7dc0a214d..803671d2c 100644 --- a/qcsrc/client/tturrets.qc +++ b/qcsrc/client/tturrets.qc @@ -1,3 +1,8 @@ +string tid2info_base; +string tid2info_head; +string tid2info_name; +vector tid2info_min; +vector tid2info_max; void turrets_precache() { @@ -18,8 +23,6 @@ void turrets_precache() precache_model ("models/turrets/tesla_base.md3"); precache_model ("models/turrets/walker_head_minigun.md3"); precache_model ("models/turrets/walker_body.md3"); - precache_model ("models/turrets/walker_props.md3"); - precache_model ("models/turrets/walker_spawn.md3"); precache_model ("models/turrets/rocket.md3"); precache_sound ("turrets/phaser.wav"); @@ -27,9 +30,78 @@ void turrets_precache() precache_sound ("weapons/uzi_fire.wav"); } +void turret_tid2info(float _tid) +{ + tid2info_base = "models/turrets/base.md3"; + tid2info_min = '-32 -32 0'; + tid2info_max = '32 32 64'; + + switch(_tid) + { + case TID_EWHEEL: + tid2info_base = "models/turrets/ewheel-base2.md3"; + tid2info_head = "models/turrets/ewheel-gun1.md3"; + tid2info_name = "eWheel"; + break; + case TID_FLAC: + tid2info_head = "models/turrets/flac.md3"; + tid2info_name = "Flac Cannon"; + break; + case TID_FUSION: + tid2info_head = "models/turrets/reactor.md3"; + tid2info_name = "Fusion Reactor"; + tid2info_min = '-34 -34 0'; + tid2info_max = '34 34 90'; + break; + case TID_HELLION: + tid2info_head = "models/turrets/hellion.md3"; + tid2info_name = "Hellion"; + break; + case TID_HK: + tid2info_head = "models/turrets/hk.md3"; + tid2info_name = "Hunter-Killer"; + break; + case TID_MACHINEGUN: + tid2info_head = "models/turrets/machinegun.md3"; + tid2info_name = "Machinegun"; + break; + case TID_MLRS: + tid2info_head = "models/turrets/mlrs.md3"; + tid2info_name = "MLRS"; + break; + case TID_PHASER: + tid2info_head = "models/turrets/phaser.md3"; + tid2info_name = "Phaser"; + break; + case TID_PLASMA: + tid2info_head = "models/turrets/plasma.md3"; + tid2info_name = "Plasma"; + break; + case TID_PLASMA_DUAL: + tid2info_head = "models/turrets/plasmad.md3"; + tid2info_name = "Dual Plasma"; + break; + case TID_TESLA: + tid2info_base = "models/turrets/tesla_base.md3"; + tid2info_head = "models/turrets/tesla_head.md3"; + tid2info_name = "Tesla coil"; + tid2info_min = '-60 -60 0'; + tid2info_max ='60 60 128'; + break; + case TID_WALKER: + tid2info_base = "models/turrets/walker_body.md3"; + tid2info_head = "models/turrets/walker_head_minigun.md3"; + tid2info_name = "Walker"; + tid2info_min = '-70 -70 0'; + tid2info_max = '70 70 95'; + break; + } +} + void turret_remove() { - dprint("Removing turret type ", ftos(self.turret_type), "\n"); + turret_tid2info(self.turret_type); + dprint("Removing ", tid2info_name, " turrret.\n"); remove(self.tur_head); self.tur_head = world; @@ -38,6 +110,7 @@ void turret_remove() void turret_changeteam() { self.colormod = '0 0 0'; + switch(self.team) { case COLOR_TEAM1: // Red @@ -62,23 +135,25 @@ void turret_changeteam() void turret_head_draw() { + self.drawmask = MASK_NORMAL; +} + +void turret_draw() +{ float dt; + + self.drawmask = MASK_NORMAL; + dt = time - self.move_time; self.move_time = time; if(dt <= 0) return; - self.angles += dt * self.move_avelocity; - self.drawmask = MASK_NORMAL; -} + self.tur_head.angles += dt * self.tur_head.move_avelocity; -void turret_draw() -{ if (self.health < 127) if(random() < 0.25) - te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); - - self.drawmask = MASK_NORMAL; + te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); } void turret_moving_head_draw() @@ -89,6 +164,8 @@ void turret_moving_head_draw() void turret_moving_draw() { float dt; + + self.drawmask = MASK_NORMAL; dt = time - self.move_time; self.move_time = time; @@ -105,115 +182,48 @@ void turret_moving_draw() setorigin(self.tur_head, self.origin); self.tur_head.angles += dt * self.tur_head.move_avelocity; + //self.angles_y += (self.move_angles_y - self.angles_y)* dt; + if (self.health < 127) if(random() < 0.25) - te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); - - self.drawmask = MASK_NORMAL; + te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16); } -string tid2info_base; -string tid2info_head; -vector tid2info_min; -vector tid2info_max; -void turret_tid2info(float _tid) -{ - tid2info_base = "models/turrets/base.md3"; - tid2info_min = '-32 -32 0'; - tid2info_max = '32 32 64'; - - switch(_tid) - { - case TID_EWHEEL: - tid2info_base = "models/turrets/ewheel-base2.md3"; - tid2info_head = "models/turrets/ewheel-gun1.md3"; - break; - case TID_FLAC: - tid2info_head = "models/turrets/flac.md3"; - break; - case TID_FUSION: - tid2info_head = "models/turrets/reactor.md3"; - tid2info_min = '-34 -34 0'; - tid2info_max = '34 34 90'; - break; - case TID_HELLION: - tid2info_head = "models/turrets/hellion.md3"; - break; - case TID_HK: - tid2info_head = "models/turrets/hk.md3"; - break; - case TID_MACHINEGUN: - tid2info_head = "models/turrets/machinegun.md3"; - break; - case TID_MLRS: - tid2info_head = "models/turrets/mlrs.md3"; - break; - case TID_PHASER: - tid2info_head = "models/turrets/phaser.md3"; - break; - case TID_PLASMA: - tid2info_head = "models/turrets/plasma.md3"; - break; - case TID_PLASMA_DUAL: - tid2info_head = "models/turrets/plasmad.md3"; - break; - case TID_TESLA: - tid2info_base = "models/turrets/tesla_base.md3"; - tid2info_head = "models/turrets/tesla_head.md3"; - tid2info_min = '-60 -60 0'; - tid2info_max ='60 60 128'; - break; - case TID_WALKER: - tid2info_base = "models/turrets/walker_body.md3"; - tid2info_head = "models/turrets/walker_head_minigun.md3"; - tid2info_min = '-70 -70 0'; - tid2info_max = '70 70 95'; - break; - } -} - -//void(entity e, entity tagentity, string tagname) setattachment = #443; void turret_construct() { if(self.tur_head == world) self.tur_head = spawn(); turret_tid2info(self.turret_type); - - setorigin(self, self.origin); - - self.tur_head.classname = "turret_head"; - self.tur_head.owner = self; + dprint("Constructing ", tid2info_name , " turret (", ftos(self.turret_type), ")\n"); + setorigin(self, self.origin); setmodel(self, tid2info_base); setmodel(self.tur_head, tid2info_head); - - self.tur_head.move_movetype = MOVETYPE_NOCLIP; - self.move_movetype = MOVETYPE_NOCLIP; - self.tur_head.angles = self.angles; - setsize(self, tid2info_min, tid2info_max); setsize(self.tur_head, '0 0 0', '0 0 0'); - setorigin(self.tur_head, gettaginfo(self, gettagindex(self, "tag_head"))); - self.health = 255; - self.solid = SOLID_BBOX; - self.tur_head.solid = SOLID_NOT; - self.movetype = MOVETYPE_NOCLIP; - self.tur_head.movetype = MOVETYPE_NOCLIP; - self.draw = turret_draw; - self.tur_head.draw = turret_head_draw; - self.entremove = turret_remove; + + self.tur_head.classname = "turret_head"; + self.tur_head.owner = self; + self.tur_head.move_movetype = MOVETYPE_NOCLIP; + self.move_movetype = MOVETYPE_NOCLIP; + self.tur_head.angles = self.angles; + self.health = 255; + self.solid = SOLID_BBOX; + self.tur_head.solid = SOLID_NOT; + self.movetype = MOVETYPE_NOCLIP; + self.tur_head.movetype = MOVETYPE_NOCLIP; + self.draw = turret_draw; + self.tur_head.draw = turret_head_draw; + self.entremove = turret_remove; if(self.turret_type == TID_EWHEEL || self.turret_type == TID_WALKER) { - self.gravity = 1; - self.move_movetype = MOVETYPE_BOUNCE; - self.move_origin = self.origin; - self.move_time = time; - - self.movetype = MOVETYPE_NOCLIP; - self.tur_head.movetype = MOVETYPE_NOCLIP; + self.gravity = 1; + self.move_movetype = MOVETYPE_BOUNCE; + self.move_origin = self.origin; + self.move_time = time; self.draw = turret_moving_draw; self.tur_head.draw = turret_moving_head_draw; } @@ -221,7 +231,6 @@ void turret_construct() entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, float _explode); void turret_gibboom(); - void turret_gib_draw() { Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy); @@ -247,10 +256,11 @@ void turret_gib_draw() void turret_gibboom() { float i; + sound (self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM); pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1); - for (i = 1; i < 5; i = i +1) + for (i = 1; i < 5; i = i + 1) turret_gibtoss(strcat("models/turrets/head-gib", ftos(i), ".md3"), self.origin, self.velocity + randomvec() * 700, '0 0 0', FALSE); } @@ -261,10 +271,10 @@ entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, flo gib = spawn(); setorigin(gib, _from); setmodel(gib, _model); - gib.colormod = _cmod; - gib.solid = SOLID_CORPSE; - gib.draw = turret_gib_draw; - gib.cnt = _explode; + gib.colormod = _cmod; + gib.solid = SOLID_CORPSE; + gib.draw = turret_gib_draw; + gib.cnt = _explode; if(_explode) { @@ -274,12 +284,12 @@ entity turret_gibtoss(string _model, vector _from, vector _to, vector _cmod, flo else gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15); - gib.gravity = 1; - gib.move_movetype = MOVETYPE_BOUNCE; - gib.move_origin = gib.origin = _from; - gib.move_velocity = _to; - gib.move_avelocity = prandomvec() * 32; - gib.move_time = time; + gib.gravity = 1; + gib.move_movetype = MOVETYPE_BOUNCE; + gib.move_origin = gib.origin = _from; + gib.move_velocity = _to; + gib.move_avelocity = prandomvec() * 32; + gib.move_time = time; gib.damageforcescale = 1; return gib; @@ -294,7 +304,8 @@ void turret_die() sound (self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM); pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1); turret_tid2info(self.turret_type); - + dprint("Turret ", tid2info_name, " dies.\n"); + // Base if(self.turret_type == TID_EWHEEL) turret_gibtoss(tid2info_base, self.origin, self.velocity, '-1 -1 -1', FALSE); @@ -311,7 +322,7 @@ void turret_die() turret_gibtoss("models/turrets/base-gib4.md3", self.origin + '0 0 2', '0 0 50' + randomvec() * 150, '0 0 0', FALSE); } else - turret_gibtoss("models/turrets/base-gib1.md3", self.origin, '0 0 0', '0 0 0', TRUE); + turret_gibtoss("models/turrets/base-gib1.md3", self.origin + '0 0 4', '0 0 0', '0 0 0', TRUE); } headgib = turret_gibtoss(tid2info_head, self.origin + '0 0 32', '0 0 200' + randomvec() * 200, '-1 -1 -1', TRUE); @@ -329,7 +340,6 @@ void ent_turret() if(sf & TNSF_SETUP) { self.turret_type = ReadByte(); - dprint("Constructing turret type ", ftos(self.turret_type), "\n"); self.origin_x = ReadCoord(); self.origin_y = ReadCoord(); @@ -365,20 +375,18 @@ void ent_turret() self.velocity_y = ReadShort(); self.velocity_z = ReadShort(); - self.angles_y = ReadShort(); - - self.move_time = time; - self.move_velocity = self.velocity; - self.move_origin = self.origin; + self.angles_y = ReadShort(); + self.move_time = time; + self.move_velocity = self.velocity; + self.move_origin = self.origin; } if(sf & TNSF_ANIM) { self.frame1time = ReadCoord(); - self.frame = ReadByte(); + self.frame = ReadByte(); } - if(sf & TNSF_STATUS) { float _team; @@ -392,7 +400,6 @@ void ent_turret() } } - //if(sf == TNSF_DIE) if(self.health == 0) turret_die(); } diff --git a/qcsrc/qc-client.cbp b/qcsrc/qc-client.cbp index ea29777c3..5ca67b7c3 100644 --- a/qcsrc/qc-client.cbp +++ b/qcsrc/qc-client.cbp @@ -71,6 +71,9 @@ + + + @@ -80,15 +83,26 @@ + + + + + + + + + + + diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index f9dea3ac4..606de1c3b 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -1009,6 +1009,11 @@ float autocvar_g_turrets_unit_walker_std_rocket_speed; float autocvar_g_turrets_unit_walker_std_rocket_turnrate; float autocvar_g_turrets_unit_walker_std_rockets_range; float autocvar_g_turrets_unit_walker_std_rockets_range_min; +float autocvar_g_turrets_unit_walker_turn; +float autocvar_g_turrets_unit_walker_turn_walk; +float autocvar_g_turrets_unit_walker_turn_run; +float autocvar_g_turrets_unit_walker_turn_strafe; +float autocvar_g_turrets_unit_walker_turn_swim; float autocvar_g_use_ammunition; float autocvar_g_vehicle_racer_afterburn_cost; float autocvar_g_vehicle_racer_anglestabilizer; diff --git a/qcsrc/server/steerlib.qc b/qcsrc/server/steerlib.qc index d512cf95f..fe47fa305 100644 --- a/qcsrc/server/steerlib.qc +++ b/qcsrc/server/steerlib.qc @@ -424,7 +424,7 @@ vector steerlib_beamsteer(vector dir, float length, float step, float step_up, f vr = vectoangles(dir); //vr_x *= -1; - tracebox(self.origin , self.mins,self.maxs,self.origin + (dir * length) ,MOVE_NOMONSTERS,self); + tracebox(self.origin + '0 0 1' * step_up, self.mins, self.maxs, ('0 0 1' * step_up) + self.origin + (dir * length), MOVE_NOMONSTERS, self); if(trace_fraction == 1.0) { //te_lightning1(self,self.origin,self.origin + (dir * length)); diff --git a/qcsrc/server/tturrets/system/system_damage.qc b/qcsrc/server/tturrets/system/system_damage.qc index ac7455bd5..88358e771 100644 --- a/qcsrc/server/tturrets/system/system_damage.qc +++ b/qcsrc/server/tturrets/system/system_damage.qc @@ -118,8 +118,6 @@ void turret_stdproc_damage (entity inflictor, entity attacker, float damage, flo if (self.turrcaps_flags & TFL_TURRCAPS_MOVE) self.velocity = self.velocity + vforce; - - // FIXME: Better damage feedback? if (self.health <= 0) { diff --git a/qcsrc/server/tturrets/units/unit_walker.qc b/qcsrc/server/tturrets/units/unit_walker.qc index de6a0d2fd..7ff1277f8 100644 --- a/qcsrc/server/tturrets/units/unit_walker.qc +++ b/qcsrc/server/tturrets/units/unit_walker.qc @@ -10,7 +10,6 @@ #define ANIM_MEELE 9 #define ANIM_SWIM 10 #define ANIM_ROAM 11 - .float animflag; #define WALKER_MIN '-70 -70 0' @@ -35,7 +34,7 @@ void walker_meele_do_dmg() where = self.origin + v_forward * 128; e = findradius(where,32); - while (e) + while (e) { if (turret_validate_target(self,e,self.target_validate_flags)) if (e != self && e.owner != self) @@ -44,118 +43,12 @@ void walker_meele_do_dmg() e = e.chain; } } + void walker_setnoanim() { turrets_setframe(ANIM_NO, FALSE); - self.animflag = self.owner.frame; -} - -void walker_animate() -{ - vector real_angle; - float vz; - - real_angle = vectoangles(self.steerto) - self.angles; - vz = self.velocity_z; - - if (self.tur_head.frame != 0) - self.tur_head.frame = self.tur_head.frame + 1; - - if (self.tur_head.frame > 12) - self.tur_head.frame = 0; - - switch (self.animflag) - { - - case ANIM_NO: - turrets_setframe(0, FALSE); - movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop); - break; - - /* - case ANIM_REVERSE: - if ((self.frame < 5) || (self.frame > 25)) - self.frame = 25; - - self.frame = self.frame -1; - movelib_move_simple(v_forward * -1, autocvar_g_turrets_unit_walker_speed_walk, 0.6); - - if (self.frame < 5) - self.frame = 25; - - break; - */ - - case ANIM_TURN: - self.angles_y += bound(-15, shortangle_f(real_angle_y, self.angles_y), 15); - movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop); - break; - - case ANIM_WALK: - self.angles_y += bound(-10, shortangle_f(real_angle_y, self.angles_y), 10); - movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_walk, 0.6); - break; - - case ANIM_RUN: - self.angles_y += bound(-5, shortangle_f(real_angle_y, self.angles_y), 5); - movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_run, 0.6); - break; - - case ANIM_STRAFE_L: - self.angles_y += bound(-2.5, shortangle_f(real_angle_y, self.angles_y), 2.5); - movelib_move_simple(v_right * -1, autocvar_g_turrets_unit_walker_speed_walk, 0.8); - break; - - case ANIM_STRAFE_R: - self.angles_y += bound(-2.5, shortangle_f(real_angle_y, self.angles_y), 2.5); - movelib_move_simple(v_right, autocvar_g_turrets_unit_walker_speed_walk, 0.8); - break; - - case ANIM_JUMP: - self.velocity += '0 0 1' * autocvar_g_turrets_unit_walker_speed_jump; - break; - - case ANIM_LAND: - break; - - case ANIM_PAIN: - if(self.frame != ANIM_PAIN) - defer(0.25, walker_setnoanim); - - break; - - case ANIM_MEELE: - if(self.frame != ANIM_MEELE) - { - defer(0.41, walker_setnoanim); - defer(0.21, walker_meele_do_dmg); - } - - movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop); - break; - - case ANIM_SWIM: - self.angles_y += bound(-10, shortangle_f(real_angle_y, self.angles_y), 10); - self.angles_x += bound(-10, shortangle_f(real_angle_x, self.angles_x), 10); - movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_swim, 0.3); - vz = self.velocity_z + sin(time * 4) * 8; - break; - - case ANIM_ROAM: - self.angles_y += bound(-5, shortangle_f(real_angle_y, self.angles_y), 5); - movelib_move_simple(v_forward ,autocvar_g_turrets_unit_walker_speed_roam, 0.5); - break; - - } - - self.velocity_z = vz; - - if (self.flags & FL_ONGROUND) - movelib_groundalign4point(300, 100, 0.25); - + self.animflag = self.frame; } - - void walker_rocket_explode() { vector org2; @@ -202,9 +95,9 @@ void walker_rocket_think() if (self.cnt < time) { if (edist < 1000) - self.tur_shotorg = randomvec() * min(edist,64); + self.tur_shotorg = randomvec() * min(edist, 64); else - self.tur_shotorg = randomvec() * min(edist,256); + self.tur_shotorg = randomvec() * min(edist, 256); self.cnt = time + 0.5; } @@ -212,39 +105,32 @@ void walker_rocket_think() if (edist < 256) self.tur_shotorg = '0 0 0'; - if (self.tur_health < time) { - self.think = walker_rocket_explode; - self.nextthink = time; + self.think = walker_rocket_explode; + self.nextthink = time; return; } - if (self.shot_dmg != 1337) - if (random() < 0.01) - { - walker_rocket_loop(); - return; - } + if (self.shot_dmg != 1337 && random() < 0.01) + { + walker_rocket_loop(); + return; + } m_speed = vlen(self.velocity); // Enemy dead? just keep on the current heading then. - if ((self.enemy == world) || (self.enemy.deadflag != DEAD_NO)) - { - // Make sure we dont return to tracking a respawned entity + if (self.enemy == world || self.enemy.deadflag != DEAD_NO) self.enemy = world; - } if (self.enemy) { - itime = max(edist / m_speed,1); + itime = max(edist / m_speed, 1); newdir = steerlib_pull(self.enemy.origin + self.tur_shotorg); } else - { newdir = normalize(self.velocity); - } WALKER_ROCKET_MOVE; } @@ -305,13 +191,9 @@ void walker_rocket_loop() void walker_fire_rocket(vector org) { - entity rocket; - - - //self.angles_x *= -1; + fixedmakevectors(self.angles); - //self.angles_x *= -1; te_explosion (org); @@ -323,12 +205,9 @@ void walker_fire_rocket(vector org) rocket.classname = "walker_rocket"; rocket.owner = self; - rocket.bot_dodge = TRUE; rocket.bot_dodgerating = 50; - rocket.takedamage = DAMAGE_YES; - rocket.damageforcescale = 2; rocket.health = 25; rocket.tur_shotorg = randomvec() * 512; @@ -342,7 +221,7 @@ void walker_fire_rocket(vector org) rocket.event_damage = walker_rocket_damage; - rocket.nextthink = time;// + 0.25; + rocket.nextthink = time; rocket.movetype = MOVETYPE_FLY; rocket.velocity = normalize((v_forward + v_up * 0.5) + (randomvec() * 0.2)) * autocvar_g_turrets_unit_walker_std_rocket_speed; rocket.angles = vectoangles(rocket.velocity); @@ -354,38 +233,36 @@ void walker_fire_rocket(vector org) CSQCProjectile(rocket, FALSE, PROJECTILE_ROCKET, FALSE); // no culling, has fly sound } -void rv_think() +.vector enemy_last_loc; +.float enemy_last_time; +void walker_move_to(vector _target, float _dist) { - float f; - vector org; - entity oldself; - - if (self.owner.deadflag != DEAD_NO) + switch (self.waterlevel) { - remove(self); - return; + case WATERLEVEL_NONE: + if (_dist > 500) + self.animflag = ANIM_RUN; + else + self.animflag = ANIM_WALK; + case WATERLEVEL_WETFEET: + case WATERLEVEL_SWIMMING: + if (self.animflag != ANIM_SWIM) + self.animflag = ANIM_WALK; + else + self.animflag = ANIM_SWIM; + break; + case WATERLEVEL_SUBMERGED: + self.animflag = ANIM_SWIM; } - self.cnt = self.cnt -1; + self.moveto = _target; + self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95); - if (self.cnt < 0) + if(self.enemy) { - remove(self); - return; + self.enemy_last_loc = _target; + self.enemy_last_time = time; } - - if (self.cnt > 1) - f = gettagindex(self.owner,"tag_rocket01"); - else - f = gettagindex(self.owner,"tag_rocket02"); - - org = gettaginfo(self.owner,f); - - self.nextthink = time + 0.2; - oldself = self; - self = self.owner; - walker_fire_rocket(org); - self = oldself; } void walker_move_path() @@ -415,168 +292,220 @@ void walker_move_path() else self.pathcurrent = self.pathcurrent.path_next; - switch (self.waterlevel) - { - case 0: - self.animflag = ANIM_WALK; - case 1: - case 2: - if (self.animflag == ANIM_WALK) - self.animflag = ANIM_WALK; - else - self.animflag = ANIM_SWIM; - break; - case 3: - self.animflag = ANIM_SWIM; - } - self.moveto = self.pathcurrent.origin; self.steerto = steerlib_attract2(self.moveto,0.5,500,0.95); + walker_move_to(self.moveto, 0); } -.vector enemy_last_loc; -.float enemy_last_time; -void walker_move_enemy() -{ - switch (self.waterlevel) - { - case 0: - if (self.tur_dist_enemy > 500) - self.animflag = ANIM_RUN; - else - self.animflag = ANIM_WALK; - case 1: - case 2: - if (self.animflag != ANIM_SWIM) - self.animflag = ANIM_WALK; - else - self.animflag = ANIM_SWIM; - break; - case 3: - self.animflag = ANIM_SWIM; - } - - self.moveto = self.enemy.origin; - self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95); - self.enemy_last_loc = self.enemy.origin; - self.enemy_last_time = time; -} - -void walker_move_enemy_last_loc() -{ - switch (self.waterlevel) - { - case 0: - self.animflag = ANIM_WALK; - case 1: - case 2: - if (self.animflag != ANIM_SWIM) - self.animflag = ANIM_WALK; - else - self.animflag = ANIM_SWIM; - break; - case 3: - self.animflag = ANIM_SWIM; - } - - self.moveto = self.enemy_last_loc; - self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95); -} - - -void walker_move_idle_pause() -{ - self.moveto = self.origin; - self.steerto = v_forward; - self.animflag = ANIM_NO; -} - -void walker_move_idle_roam() -{ -} - -void walker_move_idle() -{ -} - -float walker_attack_meele() -{ - vector wish_angle; - - if (self.animflag == ANIM_SWIM || self.animflag == ANIM_MEELE) - return 0; - - wish_angle = angleofs(self, self.enemy); - - if (self.tur_dist_enemy > autocvar_g_turrets_unit_walker_std_meele_range) - return 0; - else - if (fabs(wish_angle_y) > 15) - return 0; - - self.moveto = self.enemy.origin; - self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95); - self.animflag = ANIM_MEELE; - - return 1; -} - -float walker_attack_rockets() -{ - if (self.tur_head.attack_finished_single > time) - return 0; - - if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_rockets_range_min) - return 0; - - if (self.tur_dist_enemy > autocvar_g_turrets_unit_walker_std_rockets_range) - return 0; - - entity rv; - - rv = spawn(); - rv.think = rv_think; - rv.nextthink = time; - rv.cnt = 4; - rv.owner = self; +.float idletime; - self.tur_head.attack_finished_single = time + autocvar_g_turrets_unit_walker_std_rocket_refire; - return 1; -} void walker_postthink() { fixedmakevectors(self.angles); - if ((self.spawnflags & TSF_NO_PATHBREAK) && self.pathcurrent) + if (self.spawnflags & TSF_NO_PATHBREAK && self.pathcurrent) walker_move_path(); else if (self.enemy == world) { - if(self.enemy_last_loc != '0 0 0') + if(self.pathcurrent) + walker_move_path(); + else { - if(vlen(self.origin - self.enemy_last_loc) < 128 || time - self.enemy_last_time > 10) - self.enemy_last_loc = '0 0 0'; + if(self.enemy_last_time != 0) + { + if(vlen(self.origin - self.enemy_last_loc) < 128 || time - self.enemy_last_time > 10) + self.enemy_last_time = 0; + else + walker_move_to(self.enemy_last_loc, 0); + } else - walker_move_enemy_last_loc(); + { + if(self.animflag != ANIM_NO) + { + traceline(self.origin + '0 0 64', self.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, self); + + if(trace_fraction != 1.0) + self.tur_head.idletime = -1337; + else + { + traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, self); + if(trace_fraction == 1.0) + self.tur_head.idletime = -1337; + } + + if(self.tur_head.idletime == -1337) + { + self.moveto = self.origin + randomvec() * 256; + self.tur_head.idletime = 0; + } + + self.moveto = self.moveto * 0.9 + ((self.origin + v_forward * 500) + randomvec() * 400) * 0.1; + self.moveto_z = self.origin_z + 64; + walker_move_to(self.moveto, 0); + } + + if(self.idletime < time) + { + if(random() < 0.5) + { + self.idletime = time + 1 + random() * 5; + self.moveto = self.origin; + self.animflag = ANIM_NO; + } + else + { + self.animflag = ANIM_WALK; + self.idletime = time + 4 + random() * 2; + self.moveto = self.origin + randomvec() * 256; + self.tur_head.moveto = self.moveto; + self.tur_head.idletime = 0; + } + } + } } - else if(self.pathcurrent) - walker_move_path(); - else - walker_move_idle_pause(); } else { - if not (self.animflag == ANIM_MEELE) - if not (walker_attack_rockets()) - walker_attack_meele(); + if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_meele_range && self.animflag != ANIM_MEELE) + { + vector wish_angle; + + wish_angle = angleofs(self, self.enemy); + if (self.animflag != ANIM_SWIM) + if (fabs(wish_angle_y) < 15) + { + self.moveto = self.enemy.origin; + self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95); + self.animflag = ANIM_MEELE; + } + } + else if (self.tur_head.attack_finished_single < time) + { + if(self.tur_head.shot_volly) + { + self.animflag = ANIM_NO; + + self.tur_head.shot_volly = self.tur_head.shot_volly -1; + if(self.tur_head.shot_volly == 0) + self.tur_head.attack_finished_single = time + autocvar_g_turrets_unit_walker_std_rocket_refire; + else + self.tur_head.attack_finished_single = time + 0.2; + + if(self.tur_head.shot_volly > 1) + walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket01"))); + else + walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket02"))); + } + else + { + if (self.tur_dist_enemy > autocvar_g_turrets_unit_walker_std_rockets_range_min) + if (self.tur_dist_enemy < autocvar_g_turrets_unit_walker_std_rockets_range) + self.tur_head.shot_volly = 4; + } + } + else + { + if (self.animflag != ANIM_MEELE) + walker_move_to(self.enemy.origin, self.tur_dist_enemy); + } + } + + //if(self.animflag != ANIM_NO) + { + vector real_angle; + float turny, turnx; + float vz; + + real_angle = vectoangles(self.steerto) - self.angles; + vz = self.velocity_z; + + switch (self.animflag) + { + case ANIM_NO: + movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop); + break; + + case ANIM_TURN: + turny = autocvar_g_turrets_unit_walker_turn; + movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop); + break; + + case ANIM_WALK: + turny = autocvar_g_turrets_unit_walker_turn_walk; + movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_walk, 0.6); + break; + + case ANIM_RUN: + turny = autocvar_g_turrets_unit_walker_turn_run; + movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_run, 0.6); + break; + + case ANIM_STRAFE_L: + turny = autocvar_g_turrets_unit_walker_turn_strafe; + movelib_move_simple(v_right * -1, autocvar_g_turrets_unit_walker_speed_walk, 0.8); + break; + + case ANIM_STRAFE_R: + turny = autocvar_g_turrets_unit_walker_turn_strafe; + movelib_move_simple(v_right, autocvar_g_turrets_unit_walker_speed_walk, 0.8); + break; + + case ANIM_JUMP: + self.velocity += '0 0 1' * autocvar_g_turrets_unit_walker_speed_jump; + break; + + case ANIM_LAND: + break; + + case ANIM_PAIN: + if(self.frame != ANIM_PAIN) + defer(0.25, walker_setnoanim); + + break; + + case ANIM_MEELE: + if(self.frame != ANIM_MEELE) + { + defer(0.41, walker_setnoanim); + defer(0.21, walker_meele_do_dmg); + } - if not (self.animflag == ANIM_MEELE) - walker_move_enemy(); + movelib_beak_simple(autocvar_g_turrets_unit_walker_speed_stop); + break; + + case ANIM_SWIM: + turny = autocvar_g_turrets_unit_walker_turn_swim; + turnx = autocvar_g_turrets_unit_walker_turn_swim; + + self.angles_x += bound(-10, shortangle_f(real_angle_x, self.angles_x), 10); + movelib_move_simple(v_forward, autocvar_g_turrets_unit_walker_speed_swim, 0.3); + vz = self.velocity_z + sin(time * 4) * 8; + break; + + case ANIM_ROAM: + turny = autocvar_g_turrets_unit_walker_turn_walk; + movelib_move_simple(v_forward ,autocvar_g_turrets_unit_walker_speed_roam, 0.5); + break; + } + + if(turny) + { + turny = bound( turny * -1, shortangle_f(real_angle_y, self.angles_y), turny ); + self.angles_y += turny; + } + + if(turnx) + { + turnx = bound( turnx * -1, shortangle_f(real_angle_x, self.angles_x), turnx ); + self.angles_x += turnx; + } + + self.velocity_z = vz; } - walker_animate(); if(self.origin != self.oldorigin) self.SendFlags |= TNSF_MOVE; @@ -592,8 +521,6 @@ void walker_attack() fireBallisticBullet (self.tur_shotorg, self.tur_shotdir_updated, self.shot_spread, self.shot_speed, 5, self.shot_dmg, 0, self.shot_force, DEATH_TURRET, 0, 1, autocvar_g_balance_uzi_bulletconstant); endFireBallisticBullet(); pointparticles(particleeffectnum("laser_muzzleflash"), self.tur_shotorg, self.tur_shotdir_updated * 1000, 1); - - self.tur_head.frame = self.tur_head.frame + 1; } diff --git a/unit_walker.cfg b/unit_walker.cfg index 7c36d0eb0..e08374945 100644 --- a/unit_walker.cfg +++ b/unit_walker.cfg @@ -8,6 +8,12 @@ set g_turrets_unit_walker_speed_swim 200 set g_turrets_unit_walker_speed_jump 800 set g_turrets_unit_walker_speed_stop 90 +set g_turrets_unit_walker_turn 20 +set g_turrets_unit_walker_turn_walk 15 +set g_turrets_unit_walker_turn_run 7 +set g_turrets_unit_walker_turn_swim 10 +set g_turrets_unit_walker_turn_strafe 5 + // Main machineguns prop's set g_turrets_unit_walker_std_shot_dmg 5 set g_turrets_unit_walker_std_shot_refire 0.05 @@ -48,7 +54,7 @@ set g_turrets_unit_walker_std_rocket_refire 10 set g_turrets_unit_walker_std_rocket_dmg 45 set g_turrets_unit_walker_std_rocket_radius 150 set g_turrets_unit_walker_std_rocket_force 150 -set g_turrets_unit_walker_std_rocket_turnrate 0.1 +set g_turrets_unit_walker_std_rocket_turnrate 0.05 set g_turrets_unit_walker_std_rocket_speed 1000 // Meele attack. Only happens when theres a target directly in front