5 /* ammotype */ ammo_cells,
7 /* flags */ WEP_FLAG_NORMAL,
8 /* rating */ BOT_PICKUP_RATING_HIGH,
10 /* modelname */ "hlac",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairhlac 0.7",
13 /* wepimg */ "weaponhlac",
15 /* wepname */ _("Arc")
18 #define ARC_SETTINGS(w_cvar,w_prop) ARC_SETTINGS_LIST(w_cvar, w_prop, ARC, arc)
19 #define ARC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, BOTH, ammo) \
21 w_cvar(id, sn, PRI, animtime) \
22 w_cvar(id, sn, PRI, botaimspeed) \
23 w_cvar(id, sn, PRI, botaimlifetime) \
24 w_cvar(id, sn, PRI, damage) \
25 w_cvar(id, sn, PRI, degreespersegment) \
26 w_cvar(id, sn, PRI, distancepersegment) \
27 w_cvar(id, sn, PRI, falloff_halflifedist) \
28 w_cvar(id, sn, PRI, falloff_maxdist) \
29 w_cvar(id, sn, PRI, falloff_mindist) \
30 w_cvar(id, sn, PRI, force) \
31 w_cvar(id, sn, PRI, maxangle) \
32 w_cvar(id, sn, PRI, nonplayerdamage) \
33 w_cvar(id, sn, PRI, range) \
34 w_cvar(id, sn, PRI, refire) \
35 w_cvar(id, sn, PRI, returnspeed) \
36 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
37 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
38 w_prop(id, sn, string, weaponreplace, weaponreplace) \
39 w_prop(id, sn, float, weaponstart, weaponstart) \
40 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
41 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
44 vector arc_shotorigin[4];
47 #define ARC_BT_ENEMY 3
50 #define ARC_MAX_SEGMENTS 20
51 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
53 .entity arc_beam; // used for beam
54 .float BUTTON_ATCK_prev; // for better animation control
55 .float lg_fire_prev; // for better animation control
58 .entity lg_ents[ARC_MAX_SEGMENTS]; // debug
62 .float beam_initialized;
67 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
69 float W_Arc_Beam_Send(entity to, float sf)
71 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
73 if(sound_allowed(MSG_BROADCAST, self.owner))
75 WriteByte(MSG_ENTITY, sf);
76 if(sf & 1) // main information
78 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
79 WriteCoord(MSG_ENTITY, WEP_CVAR_PRI(arc, range));
81 if(sf & 2) // want/aim direction
83 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
84 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
85 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
87 if(sf & 4) // beam direction
89 WriteCoord(MSG_ENTITY, self.beam_dir_x);
90 WriteCoord(MSG_ENTITY, self.beam_dir_y);
91 WriteCoord(MSG_ENTITY, self.beam_dir_z);
93 if(sf & 8) // beam type
95 WriteByte(MSG_ENTITY, self.beam_type);
99 void W_Arc_Beam_Think(void)
102 if(self != self.owner.arc_beam)
105 print("W_Arc_Beam_Think(): EXPIRING BEAM #1\n");
110 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)
112 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; } // is this needed? I thought this is changed to world when removed ANYWAY
116 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
117 remove(self.lg_ents[i]);
119 print("W_Arc_Beam_Think(): EXPIRING BEAM #2\n");
126 float dt = frametime;
127 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
129 if(WEP_CVAR_PRI(arc, ammo))
131 dt = min(dt, self.owner.WEP_AMMO(ARC) / WEP_CVAR_PRI(arc, ammo));
132 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - WEP_CVAR_PRI(arc, ammo) * frametime);
136 makevectors(self.owner.v_angle);
138 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, WEP_CVAR_PRI(arc, damage) * dt, WEP_CVAR_PRI(arc, range));
140 // network information: want/aim direction
141 if(self.beam_wantdir != w_shotdir)
144 self.beam_wantdir = w_shotdir;
147 if(!self.beam_initialized)
150 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
151 self.lg_ents[i] = spawn();
154 self.beam_dir = w_shotdir;
155 self.beam_initialized = TRUE;
159 if(self.beam_dir != w_shotdir)
161 float angle = ceil(vlen(w_shotdir - self.beam_dir) * RAD2DEG);
163 if(angle && (angle > WEP_CVAR_PRI(arc, maxangle)))
165 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
166 anglelimit = min(WEP_CVAR_PRI(arc, maxangle) / angle, 1);
170 // the radius is not too far yet, no worries :D
174 // calculate how much we're going to move the end of the beam to the want position
175 float blendfactor = bound(0, anglelimit * (1 - (WEP_CVAR_PRI(arc, returnspeed) * dt)), 1);
176 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
178 // network information: beam direction
181 // this is where we calculate how many segments are needed
182 float max_allowed_segments;
185 if(WEP_CVAR_PRI(arc, distancepersegment))
186 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR_PRI(arc, distancepersegment))));
188 max_allowed_segments = ARC_MAX_SEGMENTS;
191 if(WEP_CVAR_PRI(arc, degreespersegment))
193 segments = min( max(1, ( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment) ) ), max_allowed_segments );
194 //segments = min( min(angle, WEP_CVAR_PRI(arc, maxangle)) / WEP_CVAR_PRI(arc, degreespersegment), max_allowed_segments );
196 else { segments = 1; }
203 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR_PRI(arc, range)));
206 //printf("segment count: %d\n", segments);
207 //string segmentinfo = "";
213 float new_beam_type = 0;
214 vector last_origin = w_shotorg;
215 for(i = 1; i <= segments; ++i)
217 // this could probably be calculated in a better way
218 float segmentblend = (i/segments);
219 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
221 vector new_dir = normalize((w_shotdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend));
222 vector new_origin = last_origin + (new_dir * segmentdist);
224 WarpZone_traceline_antilag(
230 ANTILAG_LATENCY(self.owner)
234 //APPEND_TO_STRING(segmentinfo, "^4, ", sprintf("^3org%s-dis'%f'", vtos(new_origin), segmentdist));
237 float is_player = (trace_ent.classname == "player" || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER));
238 if(trace_ent && (trace_ent.takedamage == DAMAGE_AIM) && (is_player || WEP_CVAR_PRI(arc, nonplayerdamage)))
240 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
241 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
244 totaldist += segmentdist * trace_fraction;
248 float falloff = ExponentialFalloff(
249 WEP_CVAR_PRI(arc, falloff_mindist),
250 WEP_CVAR_PRI(arc, falloff_maxdist),
251 WEP_CVAR_PRI(arc, falloff_halflifedist),
252 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
255 if(is_player && SAME_TEAM(self.owner, trace_ent))
257 // hit a team mate heal them now
259 te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin);
260 te_customflash(hitorigin, 80, 5, '0 1 0');
263 "W_Arc_Beam_Think(): HIT TEAM MATE: "
264 "Hitorg: %s, Segments: %d, Distance: %f\n",
271 new_beam_type = ARC_BT_HEAL;
277 rootdamage = WEP_CVAR_PRI(arc, damage);
279 rootdamage = WEP_CVAR_PRI(arc, nonplayerdamage);
281 if(accuracy_isgooddamage(self.owner, trace_ent))
287 rootdamage * dt * falloff
295 rootdamage * dt * falloff,
298 WEP_CVAR_PRI(arc, force) * new_dir * dt * falloff
302 te_lightning1(self.lg_ents[i - 1], last_origin, hitorigin);
303 te_customflash(hitorigin, 80, 5, '1 0 0');
306 "W_Arc_Beam_Think(): HIT ENEMY: "
307 "Hitorg: %s, Segments: %d, Distance: %f\n",
314 new_beam_type = ARC_BT_ENEMY;
318 else if(trace_fraction != 1)
320 // we collided with geometry
322 te_lightning1(self.lg_ents[i - 1], last_origin, trace_endpos);
323 te_customflash(trace_endpos, 50, 2, '0 0 1');
325 totaldist += segmentdist * trace_fraction;
327 "W_Arc_Beam_Think(): HIT WALL: "
328 "Hitorg: %s, Segments: %d, Distance: %f\n",
335 new_beam_type = ARC_BT_WALL;
342 totaldist += segmentdist;
344 te_lightning1(self.lg_ents[i - 1], last_origin, new_origin);
346 last_origin = new_origin;
355 "W_Arc_Beam_Think(): MISS: "
356 "Shotorg: %s, Endpos: %s, Segments: %d: %s\n",
363 te_customflash(trace_endpos, 50, 2, '1 1 0');
367 // network information: beam type
368 if(new_beam_type != self.beam_type)
371 self.beam_type = new_beam_type;
374 self.owner.lg_fire_prev = time;
375 self.nextthink = time;
378 // Attack functions =========================
379 void W_Arc_Beam(void)
381 print("W_Arc_Beam();\n");
382 // only play fire sound if 0.5 sec has passed since player let go the fire button
383 if(time - self.lg_fire_prev > 0.5)
384 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
386 entity beam, oldself;
388 self.arc_beam = beam = spawn();
389 beam.classname = "W_Arc_Beam";
390 beam.solid = SOLID_NOT;
391 beam.think = W_Arc_Beam_Think;
393 beam.movetype = MOVETYPE_NONE;
394 beam.shot_spread = 1;
395 beam.bot_dodge = TRUE;
396 beam.bot_dodgerating = WEP_CVAR_PRI(arc, damage);
397 //Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
405 float W_Arc(float req)
411 if(WEP_CVAR_PRI(arc, botaimspeed))
412 self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(arc, botaimspeed), 0, WEP_CVAR_PRI(arc, botaimlifetime), FALSE);
414 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
421 if(self.BUTTON_ATCK_prev) // TODO: Find another way to implement this!
422 /*if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
423 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
425 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
427 if(weapon_prepareattack(0, 0))
429 if((!self.arc_beam) || wasfreed(self.arc_beam))
432 if(!self.BUTTON_ATCK_prev)
434 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
435 self.BUTTON_ATCK_prev = 1;
441 if(self.BUTTON_ATCK_prev != 0)
443 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(arc, animtime), w_ready);
444 ATTACK_FINISHED(self) = time + WEP_CVAR_PRI(arc, refire) * W_WeaponRateFactor();
446 self.BUTTON_ATCK_prev = 0;
449 //if(self.BUTTON_ATCK2)
450 //if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
453 // self.arc_count = autocvar_g_balance_arc_secondary_count;
454 // weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
455 // self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
462 precache_model("models/weapons/g_arc.md3");
463 precache_model("models/weapons/v_arc.md3");
464 precache_model("models/weapons/h_arc.iqm");
465 //precache_sound("weapons/arc_bounce.wav");
466 precache_sound("weapons/arc_fire.wav");
467 precache_sound("weapons/arc_fire2.wav");
468 precache_sound("weapons/arc_impact.wav");
469 //precache_sound("weapons/arc_impact_combo.wav");
470 //precache_sound("weapons/W_Arc_Beam_fire.wav");
475 return !WEP_CVAR_PRI(arc, ammo) || (self.WEP_AMMO(ARC) > 0);
479 return self.WEP_AMMO(ARC) >= WEP_CVAR_SEC(arc, ammo);
483 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
488 if(w_deathtype & HITTYPE_SECONDARY)
490 return WEAPON_ELECTRO_MURDER_ORBS;
494 if(w_deathtype & HITTYPE_BOUNCE)
495 return WEAPON_ELECTRO_MURDER_COMBO;
497 return WEAPON_ELECTRO_MURDER_BOLT;
502 //self.arc_secondarytime = time;
511 WEP_ACTION(WEP_ARC, WR_INIT);
512 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
513 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
514 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
515 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
516 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
520 float W_Arc(float req)
524 case WR_IMPACTEFFECT:
527 org2 = w_org + w_backoff * 6;
529 if(w_deathtype & HITTYPE_SECONDARY)
531 pointparticles(particleeffectnum("arc_ballexplode"), org2, '0 0 0', 1);
533 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
537 pointparticles(particleeffectnum("arc_impact"), org2, '0 0 0', 1);
539 sound(self, CH_SHOTS, "weapons/arc_impact.wav", VOL_BASE, ATTN_NORM);
546 precache_sound("weapons/arc_impact.wav");
547 precache_sound("weapons/arc_impact_combo.wav");
552 // no weapon specific image for this weapon