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