#ifdef REGISTER_WEAPON REGISTER_WEAPON( /* WEP_##id */ ARC, /* function */ W_Arc, /* ammotype */ ammo_cells, /* impulse */ 3, /* flags */ WEP_FLAG_NORMAL, /* rating */ BOT_PICKUP_RATING_HIGH, /* color */ '1 1 1', /* modelname */ "hlac", /* simplemdl */ "foobar", /* crosshair */ "gfx/crosshairhlac 0.7", /* wepimg */ "weaponhlac", /* refname */ "arc", /* wepname */ _("Arc") ); #define ARC_SETTINGS(w_cvar,w_prop) ARC_SETTINGS_LIST(w_cvar, w_prop, ARC, arc) #define ARC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \ w_cvar(id, sn, BOTH, ammo) \ w_cvar(id, sn, PRI, animtime) \ w_cvar(id, sn, PRI, botaimspeed) \ w_cvar(id, sn, PRI, botaimlifetime) \ w_cvar(id, sn, PRI, damage) \ w_cvar(id, sn, PRI, degreespersegment) \ w_cvar(id, sn, PRI, distancepersegment) \ w_cvar(id, sn, PRI, falloff_halflifedist) \ w_cvar(id, sn, PRI, falloff_maxdist) \ w_cvar(id, sn, PRI, falloff_mindist) \ w_cvar(id, sn, PRI, force) \ w_cvar(id, sn, PRI, maxangle) \ w_cvar(id, sn, PRI, nonplayerdamage) \ w_cvar(id, sn, PRI, range) \ w_cvar(id, sn, PRI, refire) \ w_cvar(id, sn, PRI, returnspeed) \ w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \ w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \ w_prop(id, sn, string, weaponreplace, weaponreplace) \ w_prop(id, sn, float, weaponstart, weaponstart) \ w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \ w_prop(id, sn, float, weaponthrowable, weaponthrowable) #ifndef MENUQC vector arc_shotorigin[4]; #define ARC_BT_MISS 0 #define ARC_BT_WALL 1 #define ARC_BT_HEAL 2 #define ARC_BT_HIT 3 #define ARC_BT_BURST_MISS 10 #define ARC_BT_BURST_WALL 11 #define ARC_BT_BURST_HEAL 12 #define ARC_BT_BURST_HIT 13 #define ARC_BT_BURSTMASK 10 #endif #ifdef SVQC #define ARC_MAX_SEGMENTS 20 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP) void ArcInit(void); .entity arc_beam; // used for beam .float BUTTON_ATCK_prev; // for better animation control .float lg_fire_prev; // for better animation control #define ARC_DEBUG #ifdef ARC_DEBUG .entity lg_ents[ARC_MAX_SEGMENTS]; // debug #endif .vector beam_dir; .vector beam_wantdir; .float beam_initialized; .float beam_type; #endif #else #ifdef SVQC void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); } float W_Arc_Beam_Send(entity to, float sf) { WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM); sf = sf & 0x7F; if(sound_allowed(MSG_BROADCAST, self.owner)) sf |= 0x80; WriteByte(MSG_ENTITY, sf); if(sf & 1) // main information { WriteByte(MSG_ENTITY, num_for_edict(self.owner)); WriteCoord(MSG_ENTITY, WEP_CVAR_PRI(arc, range)); } if(sf & 2) // want/aim direction { WriteCoord(MSG_ENTITY, self.beam_wantdir_x); WriteCoord(MSG_ENTITY, self.beam_wantdir_y); WriteCoord(MSG_ENTITY, self.beam_wantdir_z); } if(sf & 4) // beam direction { WriteCoord(MSG_ENTITY, self.beam_dir_x); WriteCoord(MSG_ENTITY, self.beam_dir_y); WriteCoord(MSG_ENTITY, self.beam_dir_z); } if(sf & 8) // beam type { WriteByte(MSG_ENTITY, self.beam_type); } return TRUE; } void W_Arc_Beam_Think(void) { float i, burst = TRUE; if(self != self.owner.arc_beam) { #ifdef ARC_DEBUG if(self.lg_ents[0]) { for(i = 0; i < ARC_MAX_SEGMENTS; ++i) remove(self.lg_ents[i]); } print("W_Arc_Beam_Think(): EXPIRING BEAM #1\n"); #endif remove(self); return; } if((self.owner.WEP_AMMO(ARC) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)) || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen) { if(self == self.owner.arc_beam) { self.owner.arc_beam = world; } // is this needed? I thought this is changed to world when removed ANYWAY #ifdef ARC_DEBUG if(self.lg_ents[0]) { for(i = 0; i < ARC_MAX_SEGMENTS; ++i) remove(self.lg_ents[i]); } print("W_Arc_Beam_Think(): EXPIRING BEAM #2\n"); #endif remove(self); return; } if(self.owner.BUTTON_ATCK2) { burst = ARC_BT_BURSTMASK; } // decrease ammo // todo: support burst ammo float dt = frametime; if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)) { if(WEP_CVAR_PRI(arc, ammo)) { dt = min(dt, self.owner.WEP_AMMO(ARC) / WEP_CVAR_PRI(arc, ammo)); self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - WEP_CVAR_PRI(arc, ammo) * frametime); } } makevectors(self.owner.v_angle); W_SetupShot_Range(self.owner, TRUE, 0, "", 0, WEP_CVAR_PRI(arc, damage) * dt, WEP_CVAR_PRI(arc, range)); // network information: want/aim direction if(self.beam_wantdir != w_shotdir) { self.SendFlags |= 2; self.beam_wantdir = w_shotdir; } if(!self.beam_initialized) { #ifdef ARC_DEBUG for(i = 0; i < ARC_MAX_SEGMENTS; ++i) self.lg_ents[i] = spawn(); #endif self.beam_dir = w_shotdir; self.beam_initialized = TRUE; } float segments; if(self.beam_dir != w_shotdir) { float angle = ceil(vlen(w_shotdir - self.beam_dir) * RAD2DEG); float anglelimit; if(angle && (angle > WEP_CVAR_PRI(arc, maxangle))) { // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor anglelimit = min(WEP_CVAR_PRI(arc, maxangle) / angle, 1); } else { // the radius is not too far yet, no worries :D anglelimit = 1; } // calculate how much we're going to move the end of the beam to the want position float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR_PRI(arc, returnspeed) * dt)), 1); self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor)); // network information: beam direction self.SendFlags |= 4; // this is where we calculate how many segments are needed float max_allowed_segments; #if 1 if(WEP_CVAR_PRI(arc, distancepersegment)) max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR_PRI(arc, distancepersegment)))); else max_allowed_segments = ARC_MAX_SEGMENTS; #endif if(WEP_CVAR_PRI(arc, degreespersegment)) { segments = min( max(1, ( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment) ) ), max_allowed_segments ); //segments = min( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment), max_allowed_segments ); } else { segments = 1; } } else { segments = 1; } vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR_PRI(arc, range))); #ifdef ARC_DEBUG //printf("segment count: %d\n", segments); //string segmentinfo = ""; #if 0 float totaldist = 0; #endif #endif float new_beam_type = 0; vector last_origin = w_shotorg; for(i = 1; i <= segments; ++i) { // this could probably be calculated in a better way float segmentblend = (i/segments); float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments); vector new_dir = normalize((w_shotdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend)); vector new_origin = last_origin + (new_dir * segmentdist); WarpZone_traceline_antilag( self.owner, last_origin, new_origin, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner) ); #ifdef ARC_DEBUG //APPEND_TO_STRING(segmentinfo, "^4, ", sprintf("^3org%s-dis'%f'", vtos(new_origin), segmentdist)); #endif float is_player = (trace_ent.classname == "player" || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER)); if(trace_ent && (trace_ent.takedamage == DAMAGE_AIM) && (is_player || WEP_CVAR_PRI(arc, nonplayerdamage))) { // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?) vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction); #ifdef ARC_DEBUG #if 0 totaldist += segmentdist * trace_fraction; #endif #endif float falloff = ExponentialFalloff( WEP_CVAR_PRI(arc, falloff_mindist), WEP_CVAR_PRI(arc, falloff_maxdist), WEP_CVAR_PRI(arc, falloff_halflifedist), vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg) ); if(is_player && SAME_TEAM(self.owner, trace_ent)) { // hit a team mate heal them now #ifdef ARC_DEBUG te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin); te_customflash(hitorigin, 80, 5, '0 1 0'); #if 0 printf( "W_Arc_Beam_Think(): HIT TEAM MATE: " "Hitorg: %s, Segments: %d, Distance: %f\n", vtos(hitorigin), i, totaldist ); #endif #endif new_beam_type = ARC_BT_HEAL; } else { float rootdamage; if(is_player) rootdamage = WEP_CVAR_PRI(arc, damage); else rootdamage = WEP_CVAR_PRI(arc, nonplayerdamage); if(accuracy_isgooddamage(self.owner, trace_ent)) { accuracy_add( self.owner, WEP_ARC, 0, rootdamage * dt * falloff ); } Damage( trace_ent, self.owner, self.owner, rootdamage * dt * falloff, WEP_ARC, hitorigin, WEP_CVAR_PRI(arc, force) * new_dir * dt * falloff ); #ifdef ARC_DEBUG te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin); te_customflash(hitorigin, 80, 5, '1 0 0'); #if 0 printf( "W_Arc_Beam_Think(): HIT ENTITY: " "Hitorg: %s, Segments: %d, Distance: %f\n", vtos(hitorigin), i, totaldist ); #endif #endif new_beam_type = ARC_BT_HIT; } break; } else if(trace_fraction != 1) { // we collided with geometry #ifdef ARC_DEBUG te_lightning1(self.lg_ents[i - 1], last_origin, trace_endpos); te_customflash(trace_endpos, 50, 2, '0 0 1'); #if 0 totaldist += segmentdist * trace_fraction; printf( "W_Arc_Beam_Think(): HIT WALL: " "Hitorg: %s, Segments: %d, Distance: %f\n", vtos(trace_endpos), i, totaldist ); #endif #endif new_beam_type = ARC_BT_WALL; break; } else { #ifdef ARC_DEBUG #if 0 totaldist += segmentdist; #endif te_lightning1(self.lg_ents[i - 1], last_origin, new_origin); #endif last_origin = new_origin; } } #ifdef ARC_DEBUG if(!new_beam_type) { #if 0 printf( "W_Arc_Beam_Think(): MISS: " "Shotorg: %s, Endpos: %s, Segments: %d: %s\n", vtos(w_shotorg), vtos(trace_endpos), i, segmentinfo ); #endif te_customflash(trace_endpos, 50, 2, '1 1 0'); } #endif // if we're bursting, use burst visual effects new_beam_type += burst; // network information: beam type if(new_beam_type != self.beam_type) { self.SendFlags |= 8; self.beam_type = new_beam_type; } self.owner.lg_fire_prev = time; self.nextthink = time; } // Attack functions ========================= void W_Arc_Beam(void) { print("W_Arc_Beam();\n"); // only play fire sound if 0.5 sec has passed since player let go the fire button if(time - self.lg_fire_prev > 0.5) sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM); entity beam, oldself; self.arc_beam = beam = spawn(); beam.classname = "W_Arc_Beam"; beam.solid = SOLID_NOT; beam.think = W_Arc_Beam_Think; beam.owner = self; beam.movetype = MOVETYPE_NONE; beam.shot_spread = 1; beam.bot_dodge = TRUE; beam.bot_dodgerating = WEP_CVAR_PRI(arc, damage); //Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send); oldself = self; self = beam; self.think(); self = oldself; } float W_Arc(float req) { switch(req) { case WR_AIM: { if(WEP_CVAR_PRI(arc, botaimspeed)) self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(arc, botaimspeed), 0, WEP_CVAR_PRI(arc, botaimlifetime), FALSE); else self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE); return TRUE; } case WR_THINK: { if(self.BUTTON_ATCK) { if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this! /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y) weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready); else*/ weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready); if(weapon_prepareattack(0, 0)) { if((!self.arc_beam) || wasfreed(self.arc_beam)) W_Arc_Beam(); if(!self.BUTTON_ATCK_prev) { weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready); self.BUTTON_ATCK_prev = 1; } } } else // todo { if(self.BUTTON_ATCK_prev != 0) { weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready); ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(arc, refire) * W_WeaponRateFactor(); } self.BUTTON_ATCK_prev = 0; } //if(self.BUTTON_ATCK2) //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire)) //{ // W_Arc_Attack2(); // self.arc_count = autocvar_g_balance_arc_secondary_count; // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack); // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor(); //} return TRUE; } case WR_INIT: { precache_model("models/weapons/g_arc.md3"); precache_model("models/weapons/v_arc.md3"); precache_model("models/weapons/h_arc.iqm"); //precache_sound("weapons/arc_bounce.wav"); precache_sound("weapons/arc_fire.wav"); precache_sound("weapons/arc_fire2.wav"); precache_sound("weapons/arc_impact.wav"); //precache_sound("weapons/arc_impact_combo.wav"); //precache_sound("weapons/W_Arc_Beam_fire.wav"); return TRUE; } case WR_CHECKAMMO1: { return !WEP_CVAR_PRI(arc, ammo) || (self.WEP_AMMO(ARC) > 0); } case WR_CHECKAMMO2: { return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo); } case WR_CONFIG: { ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS) return TRUE; } case WR_KILLMESSAGE: { if(w_deathtype & HITTYPE_SECONDARY) { return WEAPON_ELECTRO_MURDER_ORBS; } else { if(w_deathtype & HITTYPE_BOUNCE) return WEAPON_ELECTRO_MURDER_COMBO; else return WEAPON_ELECTRO_MURDER_BOLT; } } case WR_RESETPLAYER: { //self.arc_secondarytime = time; return TRUE; } } return FALSE; } void ArcInit(void) { WEP_ACTION(WEP_ARC, WR_INIT); arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1); arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2); arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3); arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4); ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP) } #endif #ifdef CSQC float W_Arc(float req) { switch(req) { case WR_IMPACTEFFECT: { vector org2; org2 = w_org + w_backoff * 6; if(w_deathtype & HITTYPE_SECONDARY) { pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1); if(!w_issilent) sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM); } else { pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1); if(!w_issilent) sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM); } return TRUE; } case WR_INIT: { precache_sound("weapons/arc_impact.wav"); precache_sound("weapons/arc_impact_combo.wav"); return TRUE; } case WR_ZOOMRETICLE: { // no weapon specific image for this weapon return FALSE; } } return FALSE; } #endif #endif