X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fvehicles%2Fsv_vehicles.qc;h=3e75ae53016281ffd724fd85325d2499b3b5a60d;hb=46a44942030ee6350c6847bf0efe75a1e0d54c6b;hp=58d2dd47cdbdbf9275e549e689f3fcb710c7888c;hpb=153e558088db2813f7f7dd5367244b5470f4d425;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index 58d2dd47c..3e75ae530 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -1,20 +1,56 @@ -#include "vehicles.qh" #include "sv_vehicles.qh" -float SendAuxiliaryXhair(entity to, float sf) +#if 0 +bool vehicle_send(entity to, int sf) { + WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE); + WriteByte(MSG_ENTITY, sf); - WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR); + if(sf & VSF_SPAWN) + { + WriteByte(MSG_ENTITY, self.vehicleid); + } + + if(sf & VSF_SETUP) + { + // send stuff? + } - WriteByte(MSG_ENTITY, self.cnt); + if(sf & VSF_ENTER) + { + // player handles the .vehicle stuff, we need only set ourselves up for driving + + // send stuff? + } - WriteCoord(MSG_ENTITY, self.origin_x); - WriteCoord(MSG_ENTITY, self.origin_y); - WriteCoord(MSG_ENTITY, self.origin_z); + if(sf & VSF_EXIT) + { + // senf stuff? + } - WriteByte(MSG_ENTITY, rint(self.colormod_x * 255)); - WriteByte(MSG_ENTITY, rint(self.colormod_y * 255)); - WriteByte(MSG_ENTITY, rint(self.colormod_z * 255)); + if(sf & VSF_PRECACHE) + { + // send stuff?! + } + + return true; +} +#endif + +bool SendAuxiliaryXhair(entity this, entity to, int sf) +{ + + WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR); + + WriteByte(MSG_ENTITY, this.cnt); + + WriteCoord(MSG_ENTITY, this.origin_x); + WriteCoord(MSG_ENTITY, this.origin_y); + WriteCoord(MSG_ENTITY, this.origin_z); + + WriteByte(MSG_ENTITY, rint(this.colormod_x * 255)); + WriteByte(MSG_ENTITY, rint(this.colormod_y * 255)); + WriteByte(MSG_ENTITY, rint(this.colormod_z * 255)); return true; } @@ -51,41 +87,26 @@ void CSQCVehicleSetup(entity own, int vehicle_id) msg_entity = own; - WriteByte(MSG_ONE, SVC_TEMPENTITY); - WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP); + WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP); WriteByte(MSG_ONE, vehicle_id); } -vector targetdrone_getnewspot() -{ - vector spot; - int i; - for(i = 0; i < 100; ++i) - { - spot = self.origin + randomvec() * 1024; - tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self); - if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0) - return spot; - } - return self.origin; -} - -void vehicles_locktarget(float incr, float decr, float _lock_time) +void vehicles_locktarget(entity this, float incr, float decr, float _lock_time) { - if(self.lock_target && self.lock_target.deadflag != DEAD_NO) + if(this.lock_target && IS_DEAD(this.lock_target)) { - self.lock_target = world; - self.lock_strength = 0; - self.lock_time = 0; + this.lock_target = world; + this.lock_strength = 0; + this.lock_time = 0; } - if(self.lock_time > time) + if(this.lock_time > time) { - if(self.lock_target) - if(self.lock_soundtime < time) + if(this.lock_target) + if(this.lock_soundtime < time) { - self.lock_soundtime = time + 0.5; - play2(self.owner, "vehicles/locked.wav"); + this.lock_soundtime = time + 0.5; + play2(this.owner, "vehicles/locked.wav"); } return; @@ -93,61 +114,61 @@ void vehicles_locktarget(float incr, float decr, float _lock_time) if(trace_ent != world) { - if(SAME_TEAM(trace_ent, self)) + if(SAME_TEAM(trace_ent, this)) trace_ent = world; - if(trace_ent.deadflag != DEAD_NO) + if(IS_DEAD(trace_ent)) trace_ent = world; - if(!((trace_ent.vehicle_flags & VHF_ISVEHICLE) || (trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET))) + if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent))) trace_ent = world; if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0) trace_ent = world; // invisible } - if(self.lock_target == world && trace_ent != world) - self.lock_target = trace_ent; + if(this.lock_target == world && trace_ent != world) + this.lock_target = trace_ent; - if(self.lock_target && trace_ent == self.lock_target) + if(this.lock_target && trace_ent == this.lock_target) { - if(self.lock_strength != 1 && self.lock_strength + incr >= 1) + if(this.lock_strength != 1 && this.lock_strength + incr >= 1) { - play2(self.owner, "vehicles/lock.wav"); - self.lock_soundtime = time + 0.8; + play2(this.owner, "vehicles/lock.wav"); + this.lock_soundtime = time + 0.8; } - else if (self.lock_strength != 1 && self.lock_soundtime < time) + else if (this.lock_strength != 1 && this.lock_soundtime < time) { - play2(self.owner, "vehicles/locking.wav"); - self.lock_soundtime = time + 0.3; + play2(this.owner, "vehicles/locking.wav"); + this.lock_soundtime = time + 0.3; } } // Have a locking target // Trace hit current target - if(trace_ent == self.lock_target && trace_ent != world) + if(trace_ent == this.lock_target && trace_ent != world) { - self.lock_strength = min(self.lock_strength + incr, 1); - if(self.lock_strength == 1) - self.lock_time = time + _lock_time; + this.lock_strength = min(this.lock_strength + incr, 1); + if(this.lock_strength == 1) + this.lock_time = time + _lock_time; } else { if(trace_ent) - self.lock_strength = max(self.lock_strength - decr * 2, 0); + this.lock_strength = max(this.lock_strength - decr * 2, 0); else - self.lock_strength = max(self.lock_strength - decr, 0); + this.lock_strength = max(this.lock_strength - decr, 0); - if(self.lock_strength == 0) - self.lock_target = world; + if(this.lock_strength == 0) + this.lock_target = world; } } -vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power) +vector vehicles_force_fromtag_hover(entity this, string tag_name, float spring_length, float max_power) { - force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name)); + force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name)); v_forward = normalize(v_forward) * -1; - traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self); + traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this); force_fromtag_power = (1 - trace_fraction) * max_power; force_fromtag_normpower = force_fromtag_power / max_power; @@ -155,12 +176,11 @@ vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float return v_forward * force_fromtag_power; } -vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power) +vector vehicles_force_fromtag_maglev(entity this, string tag_name, float spring_length, float max_power) { - - force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name)); + force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name)); v_forward = normalize(v_forward) * -1; - traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self); + traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this); // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier) if(trace_fraction == 1.0) @@ -176,25 +196,25 @@ vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float } // projectile handling -void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) +void vehicles_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) { // Ignore damage from oterh projectiles from my owner (dont mess up volly's) - if(inflictor.owner == self.owner) + if(inflictor.owner == this.owner) return; - self.health -= damage; - self.velocity += force; - if(self.health < 1) + this.health -= damage; + this.velocity += force; + if(this.health < 1) { - self.takedamage = DAMAGE_NO; - self.event_damage = func_null; - self.think = self.use; - self.nextthink = time; + this.takedamage = DAMAGE_NO; + this.event_damage = func_null; + this.think = this.use; + this.nextthink = time; } } void vehicles_projectile_explode() -{ +{SELFPARAM(); if(self.owner && other != world) { if(other == self.owner.vehicle) @@ -217,7 +237,7 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound, float _dmg, float _radi, float _force, float _size, int _deahtype, float _projtype, float _health, bool _cull, bool _clianim, entity _owner) -{ +{SELFPARAM(); entity proj; proj = spawn(); @@ -239,7 +259,7 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound, proj.use = vehicles_projectile_explode; proj.owner = self; proj.realowner = _owner; - proj.think = SUB_Remove; + proj.think = SUB_Remove_self; proj.nextthink = time + 30; if(_health) @@ -252,11 +272,10 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound, proj.flags = FL_PROJECTILE | FL_NOTARGET; if(_mzlsound) - sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM); + _sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM); if(_mzlfx) - pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1); - + Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1); setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size); @@ -266,15 +285,15 @@ entity vehicles_projectile(string _mzlfx, string _mzlsound, } void vehicles_gib_explode() -{ - sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM); - pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1); - pointparticles(particleeffectnum("explosion_small"), self.wp00.origin + '0 0 64', '0 0 0', 1); +{SELFPARAM(); + sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM); + Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1); + Send_Effect(EFFECT_EXPLOSION_SMALL, self.wp00.origin + '0 0 64', '0 0 0', 1); remove(self); } void vehicles_gib_think() -{ +{SELFPARAM(); self.alpha -= 0.1; if(self.cnt >= time) remove(self); @@ -283,10 +302,11 @@ void vehicles_gib_think() } entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot) -{ +{SELFPARAM(); entity _gib = spawn(); - setmodel(_gib, _template.model); - setorigin(_gib, gettaginfo(self, gettagindex(self, _tag))); + _setmodel(_gib, _template.model); + vector org = gettaginfo(self, gettagindex(self, _tag)); + setorigin(_gib, org); _gib.velocity = _vel; _gib.movetype = MOVETYPE_TOSS; _gib.solid = SOLID_CORPSE; @@ -333,8 +353,8 @@ bool vehicle_addplayerslot( entity _owner, _slot.vehicle_hudmodel.viewmodelforclient = _slot; _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT); - setmodel(_slot.vehicle_hudmodel, _hud_model); - setmodel(_slot.vehicle_viewport, "null"); + _setmodel(_slot.vehicle_hudmodel, _hud_model); + setmodel(_slot.vehicle_viewport, MDL_Null); setattachment(_slot.vehicle_hudmodel, _slot, ""); setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, ""); @@ -361,7 +381,7 @@ vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string } void vehicles_reset_colors() -{ +{SELFPARAM(); entity e; float _effects = 0, _colormap; vector _glowmod, _colormod; @@ -420,15 +440,13 @@ void vehicles_reset_colors() void vehicles_clearreturn(entity veh) { - entity ret; // Remove "return helper", if any. - ret = findchain(classname, "vehicle_return"); - while(ret) + for (entity ret = findchain(classname, "vehicle_return"); ret; ret = ret.chain) { if(ret.wp00 == veh) { ret.classname = ""; - ret.think = SUB_Remove; + ret.think = SUB_Remove_self; ret.nextthink = time + 0.1; if(ret.waypointsprite_attached) @@ -436,14 +454,13 @@ void vehicles_clearreturn(entity veh) return; } - ret = ret.chain; } } void vehicles_spawn(); void vehicles_return() -{ - pointparticles(particleeffectnum("teleport"), self.wp00.origin + '0 0 64', '0 0 0', 1); +{SELFPARAM(); + Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1); self.wp00.think = vehicles_spawn; self.wp00.nextthink = time; @@ -455,7 +472,7 @@ void vehicles_return() } void vehicles_showwp_goaway() -{ +{SELFPARAM(); if(self.waypointsprite_attached) WaypointSprite_Kill(self.waypointsprite_attached); @@ -464,7 +481,7 @@ void vehicles_showwp_goaway() } void vehicles_showwp() -{ +{SELFPARAM(); entity oldself = world; vector rgb; @@ -479,8 +496,8 @@ void vehicles_showwp() self.nextthink = time +1; oldself = self; - self = spawn(); - setmodel(self, "null"); + setself(spawn()); + setmodel(self, MDL_Null); self.team = oldself.wp00.team; self.wp00 = oldself.wp00; setorigin(self, oldself.wp00.pos1); @@ -493,17 +510,18 @@ void vehicles_showwp() rgb = Team_ColorRGB(self.team); else rgb = '1 1 1'; - WaypointSprite_Spawn("vehicle", 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP, rgb); + entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle); + wp.colormod = rgb; if(self.waypointsprite_attached) { WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT); - if(oldself == world) + if(this == NULL) WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink); WaypointSprite_Ping(self.waypointsprite_attached); } - if(oldself != world) - self = oldself; + if(this) + setself(this); } void vehicles_setreturn(entity veh) @@ -512,13 +530,12 @@ void vehicles_setreturn(entity veh) vehicles_clearreturn(veh); - ret = spawn(); - ret.classname = "vehicle_return"; + ret = new(vehicle_return); ret.wp00 = veh; ret.team = veh.team; ret.think = vehicles_showwp; - if(veh.deadflag != DEAD_NO) + if(IS_DEAD(veh)) { ret.cnt = time + veh.respawntime; ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5); @@ -528,14 +545,14 @@ void vehicles_setreturn(entity veh) ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1); } - setmodel(ret, "null"); + setmodel(ret, MDL_Null); setorigin(ret, veh.pos1 + '0 0 96'); } void vehicle_use() -{ - dprint("vehicle ",self.netname, " used by ", activator.classname, "\n"); +{SELFPARAM(); + LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n"); self.tur_head.team = activator.team; @@ -544,9 +561,9 @@ void vehicle_use() else self.active = ACTIVE_ACTIVE; - if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO && !gameover) + if(self.active == ACTIVE_ACTIVE && !IS_DEAD(self) && !gameover) { - dprint("Respawning vehicle: ", self.netname, "\n"); + LOG_TRACE("Respawning vehicle: ", self.netname, "\n"); if(self.effects & EF_NODRAW) { self.think = vehicles_spawn; @@ -561,26 +578,26 @@ void vehicle_use() } void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale) -{ - if(self.regen_field < field_max) +{SELFPARAM(); + if(self.(regen_field) < field_max) if(timer + rpause < time) { if(_healthscale) regen = regen * (self.vehicle_health / self.max_health); - self.regen_field = min(self.regen_field + regen * delta_time, field_max); + self.(regen_field) = min(self.(regen_field) + regen * delta_time, field_max); if(self.owner) - self.owner.regen_field = (self.regen_field / field_max) * 100; + self.owner.(regen_field) = (self.(regen_field) / field_max) * 100; } } void shieldhit_think() -{ +{SELFPARAM(); self.alpha -= 0.1; if (self.alpha <= 0) { - //setmodel(self, ""); + // setmodel(self, MDL_Null); self.alpha = -1; self.effects |= EF_NODRAW; } @@ -590,31 +607,36 @@ void shieldhit_think() } } -void vehicles_painframe() +void vehicles_painframe(entity this) { - if(self.owner.vehicle_health <= 50) - if(self.pain_frame < time) + int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100)); + + if(myhealth <= 50) + if(this.pain_frame < time) { - float _ftmp; - _ftmp = self.owner.vehicle_health / 50; - self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp); - pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1); + float _ftmp = myhealth / 50; + this.pain_frame = time + max(0.1, 0.1 + (random() * 0.5 * _ftmp)); + Send_Effect(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1); - if(self.vehicle_flags & VHF_DMGSHAKE) - self.velocity += randomvec() * 30; + if(this.vehicle_flags & VHF_DMGSHAKE) + this.velocity += randomvec() * 30; - if(self.vehicle_flags & VHF_DMGROLL) - if(self.vehicle_flags & VHF_DMGHEADROLL) - self.tur_head.angles += randomvec(); + if(this.vehicle_flags & VHF_DMGROLL) + if(this.vehicle_flags & VHF_DMGHEADROLL) + this.tur_head.angles += randomvec(); else - self.angles += randomvec(); - + this.angles += randomvec(); } } -void vehicles_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) +void vehicles_frame(entity this, entity actor) { - self.dmg_time = time; + vehicles_painframe(this); +} + +void vehicles_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force) +{ + this.dmg_time = time; // WEAPONTODO if(DEATH_ISWEAPON(deathtype, WEP_VORTEX)) @@ -632,76 +654,77 @@ void vehicles_damage(entity inflictor, entity attacker, float damage, int deatht if(DEATH_ISWEAPON(deathtype, WEP_SEEKER)) damage *= autocvar_g_vehicles_tag_damagerate; - if(DEATH_WEAPONOFWEAPONDEATH(deathtype)) + if(DEATH_WEAPONOF(deathtype) != WEP_Null) damage *= autocvar_g_vehicles_weapon_damagerate; - self.enemy = attacker; + this.enemy = attacker; - self.pain_finished = time; + this.pain_finished = time; - if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0)) + if((this.vehicle_flags & VHF_HASSHIELD) && (this.vehicle_shield > 0)) { - if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world) + if (wasfreed(this.vehicle_shieldent) || this.vehicle_shieldent == world) { - self.vehicle_shieldent = spawn(); - self.vehicle_shieldent.effects = EF_LOWPRECISION; - - setmodel(self.vehicle_shieldent, "models/vhshield.md3"); - setattachment(self.vehicle_shieldent, self, ""); - setorigin(self.vehicle_shieldent, real_origin(self) - self.origin); - self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins); - self.vehicle_shieldent.think = shieldhit_think; + this.vehicle_shieldent = spawn(); + this.vehicle_shieldent.effects = EF_LOWPRECISION; + + setmodel(this.vehicle_shieldent, MDL_VEH_SHIELD); + setattachment(this.vehicle_shieldent, this, ""); + setorigin(this.vehicle_shieldent, real_origin(this) - this.origin); + this.vehicle_shieldent.scale = 256 / vlen(this.maxs - this.mins); + this.vehicle_shieldent.think = shieldhit_think; } - self.vehicle_shieldent.colormod = '1 1 1'; - self.vehicle_shieldent.alpha = 0.45; - self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles; - self.vehicle_shieldent.nextthink = time; - self.vehicle_shieldent.effects &= ~EF_NODRAW; + this.vehicle_shieldent.colormod = '1 1 1'; + this.vehicle_shieldent.alpha = 0.45; + this.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (this.origin + this.vehicle_shieldent.origin))) - this.angles; + this.vehicle_shieldent.nextthink = time; + this.vehicle_shieldent.effects &= ~EF_NODRAW; - self.vehicle_shield -= damage; + this.vehicle_shield -= damage; - if(self.vehicle_shield < 0) + if(this.vehicle_shield < 0) { - self.vehicle_health -= fabs(self.vehicle_shield); - self.vehicle_shieldent.colormod = '2 0 0'; - self.vehicle_shield = 0; - self.vehicle_shieldent.alpha = 0.75; + this.vehicle_health -= fabs(this.vehicle_shield); + this.vehicle_shieldent.colormod = '2 0 0'; + this.vehicle_shield = 0; + this.vehicle_shieldent.alpha = 0.75; if(sound_allowed(MSG_BROADCAST, attacker)) - spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER + spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER } else if(sound_allowed(MSG_BROADCAST, attacker)) - spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER + spamsound (this, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER } else { - self.vehicle_health -= damage; + this.vehicle_health -= damage; if(sound_allowed(MSG_BROADCAST, attacker)) - spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER + spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER } - if(self.damageforcescale < 1 && self.damageforcescale > 0) - self.velocity += force * self.damageforcescale; + if(this.damageforcescale < 1 && this.damageforcescale > 0) + this.velocity += force * this.damageforcescale; else - self.velocity += force; + this.velocity += force; - if(self.vehicle_health <= 0) + if(this.vehicle_health <= 0) { - if(self.owner) - if(self.vehicle_flags & VHF_DEATHEJECT) - vehicles_exit(VHEF_EJECT); + if(this.owner) + if(this.vehicle_flags & VHF_DEATHEJECT) + WITH(entity, self, this, vehicles_exit(VHEF_EJECT)); else - vehicles_exit(VHEF_RELEASE); + WITH(entity, self, this, vehicles_exit(VHEF_RELEASE)); - antilag_clear(self); + antilag_clear(this); - VEH_ACTION(self.vehicleid, VR_DEATH); - vehicles_setreturn(self); + Vehicle info = Vehicles_from(this.vehicleid); + info.vr_death(info, this); + vehicles_setreturn(this); } } @@ -710,14 +733,14 @@ float vehicles_crushable(entity e) if(IS_PLAYER(e) && time >= e.vehicle_enter_delay) return true; - if(e.flags & FL_MONSTER) + if(IS_MONSTER(e)) return true; return false; } void vehicles_impact(float _minspeed, float _speedfac, float _maxpain) -{ +{SELFPARAM(); if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT) return; @@ -729,7 +752,7 @@ void vehicles_impact(float _minspeed, float _speedfac, float _maxpain) if(_minspeed < wc) { float take = min(_speedfac * wc, _maxpain); - Damage (self, world, world, take, DEATH_FALL, self.origin, '0 0 0'); + Damage (self, world, world, take, DEATH_FALL.m_id, self.origin, '0 0 0'); self.play_time = time + 0.25; //dprint("wc: ", ftos(wc), "\n"); @@ -740,11 +763,11 @@ void vehicles_impact(float _minspeed, float _speedfac, float _maxpain) // vehicle enter/exit handling vector vehicles_findgoodexit(vector prefer_spot) -{ +{SELFPARAM(); //vector exitspot; float mysize; - tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner); + tracebox(self.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, self.owner); if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid) return prefer_spot; @@ -757,7 +780,7 @@ vector vehicles_findgoodexit(vector prefer_spot) v = randomvec(); v_z = 0; v = v2 + normalize(v) * mysize; - tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner); + tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, self.owner); if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid) return v; } @@ -788,14 +811,13 @@ vector vehicles_findgoodexit(vector prefer_spot) } void vehicles_exit(bool eject) -{ +{SELFPARAM(); entity _vehicle; entity _player; - entity _oldself = self; if(vehicles_exit_running) { - dprint("^1vehicles_exit allready running! this is not good..\n"); + LOG_TRACE("^1vehicles_exit allready running! this is not good..\n"); return; } @@ -807,7 +829,7 @@ void vehicles_exit(bool eject) if (_vehicle.vehicle_flags & VHF_PLAYERSLOT) { _vehicle.vehicle_exit(eject); - self = _oldself; + setself(this); vehicles_exit_running = false; return; } @@ -817,7 +839,7 @@ void vehicles_exit(bool eject) _player = _vehicle.owner; - self = _vehicle; + setself(_vehicle); if (_player) { @@ -833,7 +855,7 @@ void vehicles_exit(bool eject) WriteAngle(MSG_ONE, 0); } - setsize(_player, PL_MIN,PL_MAX); + setsize(_player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL)); _player.takedamage = DAMAGE_AIM; _player.solid = SOLID_SLIDEBOX; @@ -843,10 +865,10 @@ void vehicles_exit(bool eject) _player.alpha = 1; _player.PlayerPhysplug = func_null; _player.vehicle = world; - _player.view_ofs = PL_VIEW_OFS; + _player.view_ofs = STAT(PL_VIEW_OFS, NULL); _player.event_damage = PlayerDamage; _player.hud = HUD_NORMAL; - _player.switchweapon = _vehicle.switchweapon; + PS(_player).m_switchweapon = _vehicle.m_switchweapon; _player.last_vehiclecheck = time + 3; _player.vehicle_enter_delay = time + 2; @@ -854,7 +876,7 @@ void vehicles_exit(bool eject) } _vehicle.flags |= FL_NOTARGET; - if(_vehicle.deadflag == DEAD_NO) + if(!IS_DEAD(_vehicle)) _vehicle.avelocity = '0 0 0'; _vehicle.tur_head.nodrawtoclient = world; @@ -862,20 +884,16 @@ void vehicles_exit(bool eject) if(!teamplay) _vehicle.team = 0; - Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES); - Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle? + Kill_Notification(NOTIF_ONE, _player, MSG_CENTER, CPID_VEHICLES); + Kill_Notification(NOTIF_ONE, _player, MSG_CENTER, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle? WaypointSprite_Kill(_vehicle.wps_intruder); - vh_player = _player; - vh_vehicle = _vehicle; - MUTATOR_CALLHOOK(VehicleExit); - _player = vh_player; - _vehicle = vh_vehicle; + MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle); _vehicle.team = _vehicle.tur_head.team; - sound (_vehicle, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTEN_NORM); + sound (_vehicle, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM); _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle; _vehicle.phase = time + 1; @@ -885,16 +903,15 @@ void vehicles_exit(bool eject) vehicles_reset_colors(); _vehicle.owner = world; - CSQCMODEL_AUTOINIT(); - - self = _oldself; + CSQCMODEL_AUTOINIT(self); + setself(this); vehicles_exit_running = false; } void vehicles_touch() -{ - if(MUTATOR_CALLHOOK(VehicleTouch)) +{SELFPARAM(); + if(MUTATOR_CALLHOOK(VehicleTouch, self, other)) return; // Vehicle currently in use @@ -905,14 +922,16 @@ void vehicles_touch() if((self.origin_z + self.maxs_z) > (other.origin_z)) if(vehicles_crushable(other)) { - if(vlen(self.velocity) >= 30) - Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force); + if(vdist(self.velocity, >=, 30)) + Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH.m_id, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force); return; // Dont do selfdamage when hitting "soft targets". } - if(self.play_time < time) - VEH_ACTION(self.vehicleid, VR_IMPACT); + if(self.play_time < time) { + Vehicle info = Vehicles_from(self.vehicleid); + info.vr_impact(info, self); + } return; } @@ -923,8 +942,26 @@ void vehicles_touch() vehicles_enter(other, self); } -void vehicles_enter(entity pl, entity veh) +bool vehicle_impulse(entity this, int imp) { + entity v = this.vehicle; + if (!v) return false; + if (IS_DEAD(v)) return false; + bool(int) f = v.vehicles_impulse; + if (f && f(imp)) return true; + switch (imp) + { + case IMP_weapon_drop.impulse: + { + stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n"); + return true; + } + } + return false; +} + +void vehicles_enter(entity pl, entity veh) +{SELFPARAM(); // Remove this when bots know how to use vehicles if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots)) return; @@ -932,8 +969,8 @@ void vehicles_enter(entity pl, entity veh) if((!IS_PLAYER(pl)) || (veh.phase >= time) || (pl.vehicle_enter_delay >= time) - || (pl.frozen) - || (pl.deadflag != DEAD_NO) + || (STAT(FROZEN, pl)) + || (IS_DEAD(pl)) || (pl.vehicle) ) { return; } @@ -941,8 +978,7 @@ void vehicles_enter(entity pl, entity veh) if(veh.vehicle_flags & VHF_MULTISLOT) if(veh.owner) { - entity oldself = self; - self = veh; + setself(veh); other = pl; // TODO: fix if(!veh.gunner1) @@ -950,7 +986,7 @@ void vehicles_enter(entity pl, entity veh) if(veh.gun1.vehicle_enter) if(veh.gun1.vehicle_enter()) { - self = oldself; + setself(this); return; } @@ -959,11 +995,11 @@ void vehicles_enter(entity pl, entity veh) if(veh.gun2.vehicle_enter) if(veh.gun2.vehicle_enter()) { - self = oldself; + setself(this); return; } - self = oldself; + setself(this); } if(teamplay) @@ -971,14 +1007,14 @@ void vehicles_enter(entity pl, entity veh) if(DIFF_TEAM(pl, veh)) if(autocvar_g_vehicles_steal) { - entity head; - FOR_EACH_PLAYER(head) if(SAME_TEAM(head, veh)) - Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_VEHICLE_STEAL); + FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL)); Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF); - if(autocvar_g_vehicles_steal_show_waypoint) - WaypointSprite_Spawn("intruder", 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER, Team_ColorRGB(pl.team)); + if (autocvar_g_vehicles_steal_show_waypoint) { + entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER); + wp.colormod = Team_ColorRGB(pl.team); + } } else return; @@ -998,10 +1034,10 @@ void vehicles_enter(entity pl, entity veh) veh.vehicle_hudmodel.viewmodelforclient = pl; - tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, false, pl); + tracebox(pl.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), pl.origin, false, pl); pl.crouch = false; - pl.view_ofs = PL_VIEW_OFS; - setsize (pl, PL_MIN, PL_MAX); + pl.view_ofs = STAT(PL_VIEW_OFS, NULL); + setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL)); veh.event_damage = vehicles_damage; veh.nextthink = 0; @@ -1016,7 +1052,7 @@ void vehicles_enter(entity pl, entity veh) veh.colormap = pl.colormap; if(veh.tur_head) veh.tur_head.colormap = pl.colormap; - veh.switchweapon = pl.switchweapon; + veh.m_switchweapon = PS(pl).m_switchweapon; pl.hud = veh.vehicleid; pl.PlayerPhysplug = veh.PlayerPhysplug; @@ -1024,13 +1060,14 @@ void vehicles_enter(entity pl, entity veh) pl.vehicle_ammo2 = veh.vehicle_ammo2; pl.vehicle_reload1 = veh.vehicle_reload1; pl.vehicle_reload2 = veh.vehicle_reload2; + pl.vehicle_energy = veh.vehicle_energy; // Cant do this, hides attached objects too. //veh.exteriormodeltoclient = veh.owner; //veh.tur_head.exteriormodeltoclient = veh.owner; - pl.flags &= ~FL_ONGROUND; - veh.flags &= ~FL_ONGROUND; + UNSET_ONGROUND(pl); + UNSET_ONGROUND(veh); veh.team = pl.team; veh.flags -= FL_NOTARGET; @@ -1062,35 +1099,36 @@ void vehicles_enter(entity pl, entity veh) CSQCVehicleSetup(pl, veh.vehicleid); - vh_player = pl; - vh_vehicle = veh; - MUTATOR_CALLHOOK(VehicleEnter); + MUTATOR_CALLHOOK(VehicleEnter, pl, veh); - entity oldself = self; - self = veh; - CSQCModel_UnlinkEntity(); - VEH_ACTION(veh.vehicleid, VR_ENTER); - self = oldself; + setself(veh); + CSQCModel_UnlinkEntity(veh); + Vehicle info = Vehicles_from(veh.vehicleid); + info.vr_enter(info, veh); + setself(this); antilag_clear(pl); } void vehicles_think() -{ +{SELFPARAM(); self.nextthink = time; - + if(self.owner) self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode; - - VEH_ACTION(self.vehicleid, VR_THINK); - CSQCMODEL_AUTOUPDATE(); + Vehicle info = Vehicles_from(self.vehicleid); + info.vr_think(info, self); + + vehicles_painframe(self); + + CSQCMODEL_AUTOUPDATE(self); } // initialization void vehicles_spawn() -{ - dprint("Spawning vehicle: ", self.classname, "\n"); +{SELFPARAM(); + LOG_TRACE("Spawning vehicle: ", self.classname, "\n"); // disown & reset self.vehicle_hudmodel.viewmodelforclient = self; @@ -1121,34 +1159,33 @@ void vehicles_spawn() self.angles = self.pos2; setorigin(self, self.pos1); // Show it - pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1); + Send_Effect(EFFECT_TELEPORT, self.origin + '0 0 64', '0 0 0', 1); if(self.vehicle_controller) self.team = self.vehicle_controller.team; - entity head; // remove hooks (if any) - FOR_EACH_PLAYER(head) - if(head.hook.aiment == self) - RemoveGrapplingHook(head); + FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == self, RemoveGrapplingHook(it)); vehicles_reset_colors(); - VEH_ACTION(self.vehicleid, VR_SPAWN); + Vehicle info = Vehicles_from(self.vehicleid); + info.vr_spawn(info, self); - CSQCMODEL_AUTOINIT(); + CSQCMODEL_AUTOINIT(self); } -bool vehicle_initialize(int vehicle_id, bool nodrop) -{ +bool vehicle_initialize(entity veh, bool nodrop) +{SELFPARAM(); if(!autocvar_g_vehicles) return false; - entity veh = get_vehicleinfo(vehicle_id); - if(!veh.vehicleid) return false; - - if(!veh.tur_head) { VEH_ACTION(vehicle_id, VR_PRECACHE); } + + if(!veh.tur_head) { + Vehicle info = Vehicles_from(veh.vehicleid); + info.vr_precache(info); + } if(self.targetname && self.targetname != "") { @@ -1177,20 +1214,23 @@ bool vehicle_initialize(int vehicle_id, bool nodrop) if(self.team && (!teamplay || !autocvar_g_vehicles_teams)) self.team = 0; - self.vehicle_flags |= VHF_ISVEHICLE; + if(self.mdl == "" || !self.mdl) + _setmodel(self, veh.model); + else + _setmodel(self, self.mdl); - setmodel(self, veh.model); + self.vehicle_flags |= VHF_ISVEHICLE; - self.vehicle_viewport = spawn(); - self.vehicle_hudmodel = spawn(); - self.tur_head = spawn(); + self.vehicle_viewport = new(vehicle_viewport); + self.vehicle_hudmodel = new(vehicle_hudmodel); + self.tur_head = new(tur_head); self.tur_head.owner = self; self.takedamage = DAMAGE_NO; self.bot_attack = true; self.iscreature = true; self.teleportable = false; // no teleporting for vehicles, too buggy self.damagedbycontents = true; - self.vehicleid = vehicle_id; + self.vehicleid = veh.vehicleid; self.PlayerPhysplug = veh.PlayerPhysplug; self.event_damage = func_null; self.touch = vehicles_touch; @@ -1208,12 +1248,12 @@ bool vehicle_initialize(int vehicle_id, bool nodrop) if(autocvar_g_fullbrightplayers) self.effects |= EF_FULLBRIGHT; - setmodel(self.vehicle_hudmodel, veh.hud_model); - setmodel(self.vehicle_viewport, "null"); + _setmodel(self.vehicle_hudmodel, veh.hud_model); + setmodel(self.vehicle_viewport, MDL_Null); if(veh.head_model != "") { - setmodel(self.tur_head, veh.head_model); + _setmodel(self.tur_head, veh.head_model); setattachment(self.tur_head, self, veh.tag_head); setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud); setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view); @@ -1238,7 +1278,8 @@ bool vehicle_initialize(int vehicle_id, bool nodrop) self.pos2 = self.angles; self.tur_head.team = self.team; - VEH_ACTION(vehicle_id, VR_SETUP); + Vehicle info = Vehicles_from(veh.vehicleid); + info.vr_setup(info, veh); if(self.active == ACTIVE_NOT) self.nextthink = 0; // wait until activated