]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/w_laser.c
add secondary function for laser: switch to last used weapon
[divverent/nexuiz.git] / data / qcsrc / server / gamec / w_laser.c
1 void() laser_ready_01;
2 void() laser_fire1_01;
3 void() laser_fire2_01;
4 void() laser_deselect_01;
5 void() laser_select_01;
6
7 void() W_LastUsedWeapon;
8
9 float() laser_check = {return TRUE;};
10
11 void(float req) w_laser =
12 {
13         if (req == WR_IDLE)
14                 laser_ready_01();
15         else if (req == WR_FIRE1)
16                 weapon_prepareattack(laser_check, laser_check, laser_fire1_01, cvar("g_balance_laser_refire"));
17         else if (req == WR_FIRE2)
18                 self.switchweapon = self.cnt;
19         else if (req == WR_RAISE)
20                 laser_select_01();
21         else if (req == WR_UPDATECOUNTS)
22                 self.currentammo = 1;
23         else if (req == WR_DROP)
24                 laser_deselect_01();
25         else if (req == WR_SETUP)
26                 weapon_setup(WEP_LASER, "w_laser.zym", 0);
27         else if (req == WR_CHECKAMMO)
28                 weapon_hasammo = laser_check();
29 };
30
31 void W_Laser_Touch (void)
32 {
33         vector  dir;
34
35         if (other == self.owner)
36                 return;
37         else if (pointcontents (self.origin) == CONTENT_SKY)
38         {
39                 remove (self);
40                 return;
41         }
42
43         dir = normalize (self.owner.origin - self.origin);
44
45         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
46         WriteByte (MSG_BROADCAST, TE_FLAMEJET);
47         WriteCoord (MSG_BROADCAST, self.origin_x);
48         WriteCoord (MSG_BROADCAST, self.origin_y);
49         WriteCoord (MSG_BROADCAST, self.origin_z);
50         WriteCoord (MSG_BROADCAST, 0);          // SeienAbunae: groan... Useless clutter
51         WriteCoord (MSG_BROADCAST, 0);
52         WriteCoord (MSG_BROADCAST, 0);
53         WriteByte (MSG_BROADCAST, 155);
54
55         te_customflash(self.origin, 160, 0.2, '1 0 0');
56
57
58         self.event_damage = SUB_Null;
59         RadiusDamage (self, self.owner, cvar("g_balance_laser_damage"), cvar("g_balance_laser_edgedamage"), cvar("g_balance_laser_radius"), world, cvar("g_balance_laser_force"), IT_LASER);
60         sound (self, CHAN_BODY, "weapons/laserimpact.ogg", 1, ATTN_NORM);
61
62         remove (self);
63 }
64
65 void W_Laser_Attack (void)
66 {
67         local entity missile;
68         local vector org;
69
70         local vector trueaim;
71         trueaim = W_TrueAim();
72
73         sound (self, CHAN_WEAPON, "weapons/lasergun_fire.ogg", 1, ATTN_NORM);
74         if (self.items & IT_STRENGTH) {
75                 sound (self, CHAN_AUTO, "weapons/strength_fire.ogg", 1, ATTN_NORM);
76         }
77         
78         org = self.origin + self.view_ofs + v_forward * 15 + v_right * 5 + v_up * -12;
79         //te_customflash(org, 160, 0.2, '1 0 0');
80
81         missile = spawn ();
82         missile.owner = self;
83         missile.classname = "laserbolt";
84
85         missile.movetype = MOVETYPE_FLY;
86         missile.solid = SOLID_BBOX;
87
88         setmodel (missile, "models/laser.mdl");
89         setsize (missile, '0 0 0', '0 0 0');
90         setorigin (missile, org);
91
92         missile.velocity = normalize(trueaim - org) * cvar("g_balance_laser_speed");
93         missile.angles = vectoangles (missile.velocity);
94         //missile.glow_color = 250; // 244, 250
95         //missile.glow_size = 120;
96         missile.touch = W_Laser_Touch;
97         missile.think = SUB_Remove;
98         missile.nextthink = time + 9;
99
100         missile.effects = EF_FULLBRIGHT | EF_FULLBRIGHT | EF_LOWPRECISION;
101 }
102
103 // weapon frames
104
105 void()  laser_ready_01 =
106 {
107         weapon_thinkf(WFRAME_IDLE, 0.1, laser_ready_01);
108         self.weaponentity.state = WS_READY;
109 };
110 void()  laser_select_01 =       
111 {
112         weapon_thinkf(-1, cvar("g_balance_weaponswitchdelay"), w_ready);
113         weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
114 };
115 void()  laser_deselect_01 =
116 {
117         weapon_thinkf(-1, cvar("g_balance_weaponswitchdelay"), w_clear);
118         weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
119 };
120 void()  laser_fire1_01 =
121 {
122         weapon_doattack(laser_check, laser_check, W_Laser_Attack);
123         weapon_thinkf(WFRAME_FIRE1, 0.3, laser_ready_01);
124 };