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