add a missing cvar
[divverent/nexuiz.git] / data / qcsrc / server / w_porto.qc
1 .entity porto_current;
2 .vector porto_v_angle; // holds "held" view angles
3 .float porto_v_angle_held;
4 .vector right_vector;
5
6 void W_Porto_Success (void)
7 {
8         if(self.owner == world)
9         {
10                 objerror("Cannot succeed successfully: no owner\n");
11                 return;
12         }
13
14         self.owner.porto_current = world;
15         remove(self);
16 }
17
18 string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo);
19 void W_Porto_Fail (float failhard)
20 {
21         if(self.owner == world)
22         {
23                 objerror("Cannot fail successfully: no owner\n");
24                 return;
25         }
26
27         // no portals here!
28         Portal_ClearWithID(self.owner, self.portal_id);
29         self.owner.porto_current = world;
30
31         if(!failhard && self.owner.playerid == self.playerid && self.owner.deadflag == DEAD_NO && !(self.owner.weapons & WEPBIT_PORTO))
32         {
33                 setsize (self, '-16 -16 0', '16 16 32');
34                 setorigin(self, self.origin + trace_plane_normal);
35                 if(move_out_of_solid(self))
36                 {
37                         self.flags = FL_ITEM;
38                         self.velocity = trigger_push_calculatevelocity(self.origin, self.owner, 128);
39                         tracetoss(self, self);
40                         if(vlen(trace_endpos - self.owner.origin) < 128)
41                         {
42                                 W_ThrowNewWeapon(self.owner, WEP_PORTO, 0, self.origin, self.velocity);
43                                 centerprint(self.owner, "^1Portal deployment failed.\n\n^2Catch it to try again!");
44                         }
45                 }
46         }
47         remove(self);
48 }
49
50 void W_Porto_Remove (entity p)
51 {
52         if(p.porto_current)
53         {
54                 entity oldself;
55                 oldself = self;
56                 self = p.porto_current;
57                 W_Porto_Fail(1);
58                 self = oldself;
59         }
60 }
61
62 void W_Porto_Think (void)
63 {
64         trace_plane_normal = '0 0 0';
65         if(self.owner.playerid != self.playerid)
66                 remove(self);
67         else
68                 W_Porto_Fail(0);
69 }
70
71 void W_Porto_Touch (void)
72 {
73         vector norm;
74
75         // do not use PROJECTILE_TOUCH here
76
77         if(other.classname == "portal")
78                 return; // handled by the portal
79
80         norm = trace_plane_normal;
81         if(trace_ent.iscreature)
82         {
83                 traceline(trace_ent.origin, trace_ent.origin + '0 0 2' * PL_MIN_z, MOVE_WORLDONLY, self);
84                 if(trace_fraction >= 1)
85                         return;
86                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
87                         return;
88                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
89                         return;
90         }
91
92         if(self.owner.playerid != self.playerid)
93         {
94                 sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
95                 remove(self);
96         }
97         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
98         {
99                 spamsound(self, CHAN_PROJECTILE, "porto/bounce.wav", VOL_BASE, ATTN_NORM);
100                 // just reflect
101                 self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * trace_plane_normal);
102                 self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * trace_plane_normal));
103         }
104         else if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
105         {
106                 sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
107                 W_Porto_Fail(0);
108         }
109         else if(self.effects & EF_RED)
110         {
111                 self.effects += EF_BLUE - EF_RED;
112                 if(Portal_SpawnInPortalAtTrace(self.owner, self.right_vector, self.portal_id))
113                 {
114                         sound(self, CHAN_PROJECTILE, "porto/create.wav", VOL_BASE, ATTN_NORM);
115                         trace_plane_normal = norm;
116                         centerprint(self.owner, "^1In^7-portal created.");
117                         self.right_vector = self.right_vector - 2 * trace_plane_normal * (self.right_vector * norm);
118                         self.angles = vectoangles(self.velocity - 2 * trace_plane_normal * (self.velocity * norm));
119                         CSQCProjectile(self, TRUE, PROJECTILE_PORTO_BLUE, TRUE); // change type
120                 }
121                 else
122                 {
123                         sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
124                         trace_plane_normal = norm;
125                         W_Porto_Fail(0);
126                 }
127         }
128         else
129         {
130                 if(self.owner.portal_in.portal_id == self.portal_id)
131                 {
132                         if(Portal_SpawnOutPortalAtTrace(self.owner, self.right_vector, self.portal_id))
133                         {
134                                 sound(self, CHAN_PROJECTILE, "porto/create.wav", VOL_BASE, ATTN_NORM);
135                                 trace_plane_normal = norm;
136                                 centerprint(self.owner, "^4Out^7-portal created.");
137                                 W_Porto_Success();
138                         }
139                         else
140                         {
141                                 sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
142                                 W_Porto_Fail(0);
143                         }
144                 }
145                 else
146                 {
147                         sound(self, CHAN_PROJECTILE, "porto/unsupported.wav", VOL_BASE, ATTN_NORM);
148                         W_Porto_Fail(0);
149                 }
150         }
151 }
152
153 void W_Porto_Attack (void)
154 {
155         local entity gren;
156
157         if not(self.items & IT_UNLIMITED_SUPERWEAPONS)
158                 self.weapons = self.weapons - (self.weapons & WEPBIT_PORTO);
159         W_SetupShot (self, FALSE, 4, "porto/fire.wav", 0);
160         // always shoot from the eye
161         w_shotdir = v_forward;
162         w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
163
164         //pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
165
166         gren = spawn ();
167         gren.owner = self;
168         gren.playerid = self.playerid;
169         gren.classname = "porto";
170         gren.bot_dodge = TRUE;
171         gren.bot_dodgerating = 200;
172         gren.movetype = MOVETYPE_BOUNCEMISSILE;
173         PROJECTILE_MAKETRIGGER(gren);
174         gren.effects = EF_RED;
175         gren.scale = 4;
176         setorigin(gren, w_shotorg);
177         setsize(gren, '0 0 0', '0 0 0');
178
179         gren.nextthink = time + cvar("g_balance_porto_primary_lifetime");
180         gren.think = W_Porto_Think;
181         gren.touch = W_Porto_Touch;
182         if(self.items & IT_STRENGTH)
183                 W_SetupProjectileVelocity(gren, cvar("g_balance_porto_primary_speed") * cvar("g_balance_powerup_strength_force"), 0);
184         else
185                 W_SetupProjectileVelocity(gren, cvar("g_balance_porto_primary_speed"), 0);
186
187         gren.angles = vectoangles (gren.velocity);
188         gren.flags = FL_PROJECTILE;
189
190         gren.portal_id = time;
191         self.porto_current = gren;
192         gren.playerid = self.playerid;
193         fixedmakevectors(vectoangles(gren.velocity));
194         gren.right_vector = v_right;
195
196         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
197
198         CSQCProjectile(gren, TRUE, PROJECTILE_PORTO_RED, TRUE);
199 }
200
201 void spawnfunc_weapon_porto (void)
202 {
203         weapon_defaultspawnfunc(WEP_PORTO);
204 }
205
206 float w_nexball_weapon(float req);
207 float w_porto(float req)
208 {
209         vector v_angle_save;
210
211         if (g_nexball) { return w_nexball_weapon(req); }
212         if (req == WR_AIM)
213         {
214                 self.BUTTON_ATCK = FALSE;
215                 self.BUTTON_ATCK2 = FALSE;
216                 if(bot_aim(cvar("g_balance_porto_primary_speed"), 0, cvar("g_balance_grenadelauncher_primary_lifetime"), FALSE))
217                         self.BUTTON_ATCK = TRUE;
218         }
219         else if (req == WR_THINK)
220         {
221                 if(self.porto_v_angle_held)
222                 {
223                         if(!self.BUTTON_ATCK2)
224                         {
225                                 self.porto_v_angle_held = 0;
226
227                                 ClientData_Touch(self);
228                         }
229                 }
230                 else
231                 {
232                         if(self.BUTTON_ATCK2)
233                         {
234                                 self.porto_v_angle = self.v_angle;
235                                 self.porto_v_angle_held = 1;
236
237                                 ClientData_Touch(self);
238                         }
239                 }
240                 v_angle_save = self.v_angle;
241                 if(self.porto_v_angle_held)
242                         makevectors(self.porto_v_angle); // override the previously set angles
243
244                 if (self.BUTTON_ATCK)
245                 if (!self.porto_current)
246                 if (!self.porto_forbidden)
247                 if (weapon_prepareattack(0, cvar("g_balance_porto_primary_refire")))
248                 {
249                         W_Porto_Attack();
250                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_porto_primary_animtime"), w_ready);
251                 }
252         }
253         else if (req == WR_PRECACHE)
254         {
255                 precache_model ("models/weapons/g_porto.md3");
256                 precache_model ("models/weapons/v_porto.md3");
257                 precache_model ("models/weapons/h_porto.dpm");
258                 precache_model ("models/portal.md3");
259                 precache_sound ("porto/bounce.wav");
260                 precache_sound ("porto/create.wav");
261                 precache_sound ("porto/expire.wav");
262                 precache_sound ("porto/explode.wav");
263                 precache_sound ("porto/fire.wav");
264                 precache_sound ("porto/unsupported.wav");
265         }
266         else if (req == WR_SETUP)
267                 weapon_setup(WEP_PORTO);
268         else if (req == WR_SUICIDEMESSAGE)
269                 w_deathtypestring = "did the impossible";
270         else if (req == WR_KILLMESSAGE)
271                 w_deathtypestring = "felt # doing the impossible to him";
272         else if (req == WR_RESETPLAYER)
273         {
274                 self.porto_current = world;
275         }
276         return TRUE;
277 };