]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_porto.qc
handle casings using the "shell" tag; make them go left instead of right (fits better...
[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 float 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                 sound(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");
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         gren.solid = SOLID_BBOX;
174         gren.effects = EF_RED;
175         gren.scale = 4;
176         setorigin(gren, w_shotorg);
177
178         gren.nextthink = time + cvar("g_balance_porto_primary_lifetime");
179         gren.think = W_Porto_Think;
180         gren.touch = W_Porto_Touch;
181         gren.velocity = w_shotdir * cvar("g_balance_porto_primary_speed");
182         if(self.items & IT_STRENGTH)
183                 gren.velocity = gren.velocity * cvar("g_balance_powerup_strength_force");
184         W_SetupProjectileVelocity(gren);
185
186         gren.angles = vectoangles (gren.velocity);
187         gren.flags = FL_PROJECTILE;
188
189         gren.portal_id = time;
190         self.porto_current = gren;
191         gren.playerid = self.playerid;
192         fixedmakevectors(vectoangles(gren.velocity));
193         gren.right_vector = v_right;
194
195         gren.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
196
197         CSQCProjectile(gren, TRUE, PROJECTILE_PORTO_RED, TRUE);
198 }
199
200 void spawnfunc_weapon_porto (void)
201 {
202         weapon_defaultspawnfunc(WEP_PORTO);
203 }
204
205 float w_porto(float req)
206 {
207         vector v_angle_save;
208
209         if (req == WR_AIM)
210         {
211                 self.BUTTON_ATCK = FALSE;
212                 self.BUTTON_ATCK2 = FALSE;
213                 if(bot_aim(cvar("g_balance_porto_primary_speed"), 0, cvar("g_balance_grenadelauncher_primary_lifetime"), FALSE))
214                         self.BUTTON_ATCK = TRUE;
215         }
216         else if (req == WR_THINK)
217         {
218                 if(self.porto_v_angle_held)
219                 {
220                         if(!self.BUTTON_ATCK2)
221                         {
222                                 self.porto_v_angle_held = 0;
223
224                                 ClientData_Touch(self);
225                         }
226                 }
227                 else
228                 {
229                         if(self.BUTTON_ATCK2)
230                         {
231                                 self.porto_v_angle = self.v_angle;
232                                 self.porto_v_angle_held = 1;
233
234                                 ClientData_Touch(self);
235                         }
236                 }
237                 v_angle_save = self.v_angle;
238                 if(self.porto_v_angle_held)
239                         makevectors(self.porto_v_angle); // override the previously set angles
240
241                 if (self.BUTTON_ATCK)
242                 if (!self.porto_current)
243                 if (!self.porto_forbidden)
244                 if (weapon_prepareattack(0, cvar("g_balance_porto_primary_refire")))
245                 {
246                         W_Porto_Attack();
247                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_porto_primary_animtime"), w_ready);
248                 }
249         }
250         else if (req == WR_PRECACHE)
251         {
252                 precache_model ("models/weapons/g_porto.md3");
253                 precache_model ("models/weapons/v_porto.md3");
254                 precache_model ("models/weapons/w_porto.zym");
255                 precache_model ("models/portal.md3");
256                 precache_sound ("porto/bounce.wav");
257                 precache_sound ("porto/create.wav");
258                 precache_sound ("porto/expire.wav");
259                 precache_sound ("porto/explode.wav");
260                 precache_sound ("porto/fire.wav");
261                 precache_sound ("porto/unsupported.wav");
262         }
263         else if (req == WR_SETUP)
264                 weapon_setup(WEP_PORTO);
265         else if (req == WR_SUICIDEMESSAGE)
266                 w_deathtypestring = "did the impossible";
267         else if (req == WR_KILLMESSAGE)
268                 w_deathtypestring = "felt # doing the impossible to him";
269         return TRUE;
270 };