]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/vehicles/sv_vehicles.qc
Merge branch 'master' into terencehill/dynamic_hud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / sv_vehicles.qc
1 #include "sv_vehicles.qh"
2
3 #if 0
4 bool vehicle_send(entity to, int sf)
5 {
6         WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
7         WriteByte(MSG_ENTITY, sf);
8
9         if(sf & VSF_SPAWN)
10         {
11                 WriteByte(MSG_ENTITY, self.vehicleid);
12         }
13
14         if(sf & VSF_SETUP)
15         {
16                 // send stuff?
17         }
18
19         if(sf & VSF_ENTER)
20         {
21                 // player handles the .vehicle stuff, we need only set ourselves up for driving
22
23                 // send stuff?
24         }
25
26         if(sf & VSF_EXIT)
27         {
28                 // senf stuff?
29         }
30
31         if(sf & VSF_PRECACHE)
32         {
33                 // send stuff?!
34         }
35
36         return true;
37 }
38 #endif
39
40 bool SendAuxiliaryXhair(entity this, entity to, int sf)
41 {
42
43         WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
44
45         WriteByte(MSG_ENTITY, this.cnt);
46
47         WriteCoord(MSG_ENTITY, this.origin_x);
48         WriteCoord(MSG_ENTITY, this.origin_y);
49         WriteCoord(MSG_ENTITY, this.origin_z);
50
51         WriteByte(MSG_ENTITY, rint(this.colormod_x * 255));
52         WriteByte(MSG_ENTITY, rint(this.colormod_y * 255));
53         WriteByte(MSG_ENTITY, rint(this.colormod_z * 255));
54
55         return true;
56 }
57
58 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
59 {
60         if(!IS_REAL_CLIENT(own))
61                 return;
62
63         entity axh;
64
65         axh_id = bound(0, axh_id, MAX_AXH);
66         axh = own.(AuxiliaryXhair[axh_id]);
67
68         if(axh == world || wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
69         {
70                 axh                                      = spawn();
71                 axh.cnt                          = axh_id;
72                 axh.drawonlytoclient    = own;
73                 axh.owner                          = own;
74                 Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
75         }
76
77         setorigin(axh, loc);
78         axh.colormod                    = clr;
79         axh.SendFlags              = 0x01;
80         own.(AuxiliaryXhair[axh_id]) = axh;
81 }
82
83 void CSQCVehicleSetup(entity own, int vehicle_id)
84 {
85         if(!IS_REAL_CLIENT(own))
86                 return;
87
88         msg_entity = own;
89
90         WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP);
91         WriteByte(MSG_ONE, vehicle_id);
92 }
93
94 void vehicles_locktarget(entity this, float incr, float decr, float _lock_time)
95 {
96         if(this.lock_target && IS_DEAD(this.lock_target))
97         {
98                 this.lock_target        = world;
99                 this.lock_strength  = 0;
100                 this.lock_time    = 0;
101         }
102
103         if(this.lock_time > time)
104         {
105                 if(this.lock_target)
106                 if(this.lock_soundtime < time)
107                 {
108                         this.lock_soundtime = time + 0.5;
109                         play2(this.owner, "vehicles/locked.wav");
110                 }
111
112                 return;
113         }
114
115         if(trace_ent != world)
116         {
117                 if(SAME_TEAM(trace_ent, this))
118                         trace_ent = world;
119
120                 if(IS_DEAD(trace_ent))
121                         trace_ent = world;
122
123                 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
124                         trace_ent = world;
125
126                 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
127                         trace_ent = world; // invisible
128         }
129
130         if(this.lock_target == world && trace_ent != world)
131                 this.lock_target = trace_ent;
132
133         if(this.lock_target && trace_ent == this.lock_target)
134         {
135                 if(this.lock_strength != 1 && this.lock_strength + incr >= 1)
136                 {
137                         play2(this.owner, "vehicles/lock.wav");
138                         this.lock_soundtime = time + 0.8;
139                 }
140                 else if (this.lock_strength != 1 && this.lock_soundtime < time)
141                 {
142                         play2(this.owner, "vehicles/locking.wav");
143                         this.lock_soundtime = time + 0.3;
144                 }
145         }
146
147         // Have a locking target
148         // Trace hit current target
149         if(trace_ent == this.lock_target && trace_ent != world)
150         {
151                 this.lock_strength = min(this.lock_strength + incr, 1);
152                 if(this.lock_strength == 1)
153                         this.lock_time = time + _lock_time;
154         }
155         else
156         {
157                 if(trace_ent)
158                         this.lock_strength = max(this.lock_strength - decr * 2, 0);
159                 else
160                         this.lock_strength = max(this.lock_strength - decr, 0);
161
162                 if(this.lock_strength == 0)
163                         this.lock_target = world;
164         }
165 }
166
167 vector vehicles_force_fromtag_hover(entity this, string tag_name, float spring_length, float max_power)
168 {
169         force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
170         v_forward  = normalize(v_forward) * -1;
171         traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, this);
172
173         force_fromtag_power = (1 - trace_fraction) * max_power;
174         force_fromtag_normpower = force_fromtag_power / max_power;
175
176         return v_forward  * force_fromtag_power;
177 }
178
179 vector vehicles_force_fromtag_maglev(entity this, string tag_name, float spring_length, float max_power)
180 {
181         force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
182         v_forward  = normalize(v_forward) * -1;
183         traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, this);
184
185         // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
186         if(trace_fraction == 1.0)
187         {
188                 force_fromtag_normpower = -0.25;
189                 return '0 0 -200';
190         }
191
192         force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
193         force_fromtag_normpower = force_fromtag_power / max_power;
194
195         return v_forward  * force_fromtag_power;
196 }
197
198 // projectile handling
199 void vehicles_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
200 {
201         // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
202         if(inflictor.owner == this.owner)
203                 return;
204
205         this.health -= damage;
206         this.velocity += force;
207         if(this.health < 1)
208         {
209                 this.takedamage = DAMAGE_NO;
210                 this.event_damage = func_null;
211                 this.think = this.use;
212                 this.nextthink = time;
213         }
214 }
215
216 void vehicles_projectile_explode()
217 {SELFPARAM();
218         if(self.owner && other != world)
219         {
220                 if(other == self.owner.vehicle)
221                         return;
222
223                 if(other == self.owner.vehicle.tur_head)
224                         return;
225         }
226
227         PROJECTILE_TOUCH;
228
229         self.event_damage = func_null;
230         RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
231
232         remove (self);
233 }
234
235 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
236                                                    vector _org, vector _vel,
237                                                    float _dmg, float _radi, float _force,  float _size,
238                                                    int _deahtype, float _projtype, float _health,
239                                                    bool _cull, bool _clianim, entity _owner)
240 {
241     TC(Sound, _mzlsound);
242         entity proj;
243
244         proj = spawn();
245
246         PROJECTILE_MAKETRIGGER(proj);
247         setorigin(proj, _org);
248
249         proj.shot_dmg            = _dmg;
250         proj.shot_radius          = _radi;
251         proj.shot_force    = _force;
252         proj.totalfrags    = _deahtype;
253         proj.solid                      = SOLID_BBOX;
254         proj.movetype            = MOVETYPE_FLYMISSILE;
255         proj.flags                      = FL_PROJECTILE;
256         proj.bot_dodge          = true;
257         proj.bot_dodgerating  = _dmg;
258         proj.velocity            = _vel;
259         proj.touch                      = vehicles_projectile_explode;
260         proj.use                          = vehicles_projectile_explode;
261         proj.owner                      = this;
262         proj.realowner          = _owner;
263         proj.think                      = SUB_Remove_self;
264         proj.nextthink          = time + 30;
265
266         if(_health)
267         {
268                 proj.takedamage    = DAMAGE_AIM;
269                 proj.event_damage        = vehicles_projectile_damage;
270                 proj.health                = _health;
271         }
272         else
273                 proj.flags                 = FL_PROJECTILE | FL_NOTARGET;
274
275         if(_mzlsound != SND_Null)
276                 sound (this, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
277
278         if(_mzlfx)
279                 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
280
281         setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
282
283         CSQCProjectile(proj, _clianim, _projtype, _cull);
284
285         return proj;
286 }
287
288 void vehicles_gib_explode()
289 {SELFPARAM();
290         sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
291         Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
292         Send_Effect(EFFECT_EXPLOSION_SMALL, self.wp00.origin + '0 0 64', '0 0 0', 1);
293         remove(self);
294 }
295
296 void vehicles_gib_think()
297 {SELFPARAM();
298         self.alpha -= 0.1;
299         if(self.cnt >= time)
300                 remove(self);
301         else
302                 self.nextthink = time + 0.1;
303 }
304
305 entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
306 {SELFPARAM();
307         entity _gib = spawn();
308         _setmodel(_gib, _template.model);
309         vector org = gettaginfo(self, gettagindex(self, _tag));
310         setorigin(_gib, org);
311         _gib.velocity = _vel;
312         _gib.movetype = MOVETYPE_TOSS;
313         _gib.solid = SOLID_CORPSE;
314         _gib.colormod = '-0.5 -0.5 -0.5';
315         _gib.effects = EF_LOWPRECISION;
316         _gib.avelocity = _rot;
317
318         if(_burn)
319                 _gib.effects |= EF_FLAME;
320
321         if(_explode)
322         {
323                 _gib.think = vehicles_gib_explode;
324                 _gib.nextthink = time + random() * _explode;
325                 _gib.touch = vehicles_gib_explode;
326         }
327         else
328         {
329                 _gib.cnt = time + _maxtime;
330                 _gib.think = vehicles_gib_think;
331                 _gib.nextthink = time + _maxtime - 1;
332                 _gib.alpha = 1;
333         }
334         return _gib;
335 }
336
337 bool vehicle_addplayerslot(     entity _owner,
338                                                                 entity _slot,
339                                                                 int _hud,
340                                                                 string _hud_model,
341                                                                 bool(entity) _framefunc,
342                                                                 void(bool) _exitfunc, float() _enterfunc)
343 {
344         if(!(_owner.vehicle_flags & VHF_MULTISLOT))
345                 _owner.vehicle_flags |= VHF_MULTISLOT;
346
347         _slot.PlayerPhysplug = _framefunc;
348         _slot.vehicle_exit = _exitfunc;
349         _slot.vehicle_enter = _enterfunc;
350         _slot.hud = _hud;
351         _slot.vehicle_flags = VHF_PLAYERSLOT;
352         _slot.vehicle_viewport = spawn();
353         _slot.vehicle_hudmodel = spawn();
354         _slot.vehicle_hudmodel.viewmodelforclient = _slot;
355         _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
356
357         _setmodel(_slot.vehicle_hudmodel, _hud_model);
358         setmodel(_slot.vehicle_viewport, MDL_Null);
359
360         setattachment(_slot.vehicle_hudmodel, _slot, "");
361         setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
362
363         return true;
364 }
365
366 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
367                                                  float _pichlimit_min, float _pichlimit_max,
368                                                  float _rotlimit_min, float _rotlimit_max, float _aimspeed)
369 {
370         vector vtmp, vtag;
371         float ftmp;
372         vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
373         vtmp = vectoangles(normalize(_target - vtag));
374         vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
375         vtmp = AnglesTransform_Normalize(vtmp, true);
376         ftmp = _aimspeed * frametime;
377         vtmp_y = bound(-ftmp, vtmp_y, ftmp);
378         vtmp_x = bound(-ftmp, vtmp_x, ftmp);
379         _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
380         _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
381         return vtag;
382 }
383
384 void vehicles_reset_colors()
385 {SELFPARAM();
386         entity e;
387         float _effects = 0, _colormap;
388         vector _glowmod, _colormod;
389
390         if(autocvar_g_nodepthtestplayers)
391                 _effects |= EF_NODEPTHTEST;
392
393         if(autocvar_g_fullbrightplayers)
394                 _effects |= EF_FULLBRIGHT;
395
396         if(self.team)
397                 _colormap = 1024 + (self.team - 1) * 17;
398         else
399                 _colormap = 1024;
400
401         _glowmod  = '0 0 0';
402         _colormod = '0 0 0';
403
404         // Find all ents attacked to main model and setup effects, colormod etc.
405         e = findchainentity(tag_entity, self);
406         while(e)
407         {
408                 if(e != self.vehicle_shieldent)
409                 {
410                         e.effects   = _effects; //  | EF_LOWPRECISION;
411                         e.colormod  = _colormod;
412                         e.colormap  = _colormap;
413                         e.alpha  = 1;
414                 }
415                 e = e.chain;
416         }
417         // Also check head tags
418         e = findchainentity(tag_entity, self.tur_head);
419         while(e)
420         {
421                 if(e != self.vehicle_shieldent)
422                 {
423                         e.effects   = _effects; //  | EF_LOWPRECISION;
424                         e.colormod  = _colormod;
425                         e.colormap  = _colormap;
426                         e.alpha  = 1;
427                 }
428                 e = e.chain;
429         }
430
431         self.vehicle_hudmodel.effects  = self.effects  = _effects; // | EF_LOWPRECISION;
432         self.vehicle_hudmodel.colormod = self.colormod = _colormod;
433         self.vehicle_hudmodel.colormap = self.colormap = _colormap;
434         self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
435
436         self.alpha       = 1;
437         self.avelocity = '0 0 0';
438         self.velocity  = '0 0 0';
439         self.effects   = _effects;
440 }
441
442 void vehicles_clearreturn(entity veh)
443 {
444         // Remove "return helper", if any.
445         for (entity ret = findchain(classname, "vehicle_return"); ret; ret = ret.chain)
446         {
447                 if(ret.wp00 == veh)
448                 {
449                         ret.classname   = "";
450                         ret.think          = SUB_Remove_self;
451                         ret.nextthink   = time + 0.1;
452
453                         if(ret.waypointsprite_attached)
454                                 WaypointSprite_Kill(ret.waypointsprite_attached);
455
456                         return;
457                 }
458         }
459 }
460
461 void vehicles_spawn();
462 void vehicles_return()
463 {SELFPARAM();
464         Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
465
466         self.wp00.think  = vehicles_spawn;
467         self.wp00.nextthink = time;
468
469         if(self.waypointsprite_attached)
470                 WaypointSprite_Kill(self.waypointsprite_attached);
471
472         remove(self);
473 }
474
475 void vehicles_showwp_goaway()
476 {SELFPARAM();
477         if(self.waypointsprite_attached)
478                 WaypointSprite_Kill(self.waypointsprite_attached);
479
480         remove(self);
481
482 }
483
484 void vehicles_showwp()
485 {SELFPARAM();
486         entity oldself = world;
487         vector rgb;
488
489         if(self.cnt)
490         {
491                 self.think        = vehicles_return;
492                 self.nextthink  = self.cnt;
493         }
494         else
495         {
496                 self.think        = vehicles_return;
497                 self.nextthink  = time +1;
498
499                 oldself = self;
500                 setself(spawn());
501                 setmodel(self, MDL_Null);
502                 self.team = oldself.wp00.team;
503                 self.wp00 = oldself.wp00;
504                 setorigin(self, oldself.wp00.pos1);
505
506                 self.nextthink = time + 5;
507                 self.think = vehicles_showwp_goaway;
508         }
509
510         if(teamplay && self.team)
511                 rgb = Team_ColorRGB(self.team);
512         else
513                 rgb = '1 1 1';
514         entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle);
515         wp.colormod = rgb;
516         if(self.waypointsprite_attached)
517         {
518                 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
519                 if(this == NULL)
520                         WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
521                 WaypointSprite_Ping(self.waypointsprite_attached);
522         }
523
524         if(this)
525                 setself(this);
526 }
527
528 void vehicles_setreturn(entity veh)
529 {
530         entity ret;
531
532         vehicles_clearreturn(veh);
533
534         ret = new(vehicle_return);
535         ret.wp00           = veh;
536         ret.team                = veh.team;
537         ret.think          = vehicles_showwp;
538
539         if(IS_DEAD(veh))
540         {
541                 ret.cnt          = time + veh.respawntime;
542                 ret.nextthink   = min(time + veh.respawntime, time + veh.respawntime - 5);
543         }
544         else
545         {
546                 ret.nextthink   = min(time + veh.respawntime, time + veh.respawntime - 1);
547         }
548
549         setmodel(ret, MDL_Null);
550         setorigin(ret, veh.pos1 + '0 0 96');
551
552 }
553
554 void vehicle_use()
555 {SELFPARAM();
556         LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
557
558         self.tur_head.team = activator.team;
559
560         if(self.tur_head.team == 0)
561                 self.active = ACTIVE_NOT;
562         else
563                 self.active = ACTIVE_ACTIVE;
564
565         if(self.active == ACTIVE_ACTIVE && !IS_DEAD(self) && !gameover)
566         {
567                 LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
568                 if(self.effects & EF_NODRAW)
569                 {
570                         self.think = vehicles_spawn;
571                         self.nextthink = time + 3;
572                 }
573                 else
574                 {
575                         vehicles_setreturn(self);
576                         vehicles_reset_colors();
577                 }
578         }
579 }
580
581 void vehicles_regen(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
582 {
583         if(this.(regen_field) < field_max)
584         if(timer + rpause < time)
585         {
586                 if(_healthscale)
587                         regen = regen * (this.vehicle_health / this.max_health);
588
589                 this.(regen_field) = min(this.(regen_field) + regen * delta_time, field_max);
590
591                 if(this.owner)
592                         this.owner.(regen_field) = (this.(regen_field) / field_max) * 100;
593         }
594 }
595
596 void shieldhit_think()
597 {SELFPARAM();
598         self.alpha -= 0.1;
599         if (self.alpha <= 0)
600         {
601                 // setmodel(self, MDL_Null);
602                 self.alpha = -1;
603                 self.effects |= EF_NODRAW;
604         }
605         else
606         {
607                 self.nextthink = time + 0.1;
608         }
609 }
610
611 void vehicles_painframe(entity this)
612 {
613         int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
614
615         if(myhealth <= 50)
616         if(this.pain_frame < time)
617         {
618                 float _ftmp = myhealth / 50;
619                 this.pain_frame = time + max(0.1, 0.1 + (random() * 0.5 * _ftmp));
620                 Send_Effect(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
621
622                 if(this.vehicle_flags & VHF_DMGSHAKE)
623                         this.velocity += randomvec() * 30;
624
625                 if(this.vehicle_flags & VHF_DMGROLL)
626                         if(this.vehicle_flags & VHF_DMGHEADROLL)
627                                 this.tur_head.angles += randomvec();
628                         else
629                                 this.angles += randomvec();
630         }
631 }
632
633 void vehicles_frame(entity this, entity actor)
634 {
635         vehicles_painframe(this);
636 }
637
638 void vehicles_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
639 {
640         this.dmg_time = time;
641
642         // WEAPONTODO
643         if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
644                 damage *= autocvar_g_vehicles_vortex_damagerate;
645
646         if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
647                 damage *= autocvar_g_vehicles_machinegun_damagerate;
648
649         if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
650                 damage *= autocvar_g_vehicles_rifle_damagerate;
651
652         if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
653                 damage *= autocvar_g_vehicles_vaporizer_damagerate;
654
655         if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
656                 damage *= autocvar_g_vehicles_tag_damagerate;
657
658         if(DEATH_WEAPONOF(deathtype) != WEP_Null)
659                 damage *= autocvar_g_vehicles_weapon_damagerate;
660
661         this.enemy = attacker;
662
663         this.pain_finished = time;
664
665         if((this.vehicle_flags & VHF_HASSHIELD) && (this.vehicle_shield > 0))
666         {
667                 if (wasfreed(this.vehicle_shieldent) || this.vehicle_shieldent == world)
668                 {
669                         this.vehicle_shieldent = spawn();
670                         this.vehicle_shieldent.effects = EF_LOWPRECISION;
671
672                         setmodel(this.vehicle_shieldent, MDL_VEH_SHIELD);
673                         setattachment(this.vehicle_shieldent, this, "");
674                         setorigin(this.vehicle_shieldent, real_origin(this) - this.origin);
675                         this.vehicle_shieldent.scale       = 256 / vlen(this.maxs - this.mins);
676                         this.vehicle_shieldent.think       = shieldhit_think;
677                 }
678
679                 this.vehicle_shieldent.colormod = '1 1 1';
680                 this.vehicle_shieldent.alpha = 0.45;
681                 this.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (this.origin + this.vehicle_shieldent.origin))) - this.angles;
682                 this.vehicle_shieldent.nextthink = time;
683                 this.vehicle_shieldent.effects &= ~EF_NODRAW;
684
685                 this.vehicle_shield -= damage;
686
687                 if(this.vehicle_shield < 0)
688                 {
689                         this.vehicle_health -= fabs(this.vehicle_shield);
690                         this.vehicle_shieldent.colormod = '2 0 0';
691                         this.vehicle_shield = 0;
692                         this.vehicle_shieldent.alpha = 0.75;
693
694                         if(sound_allowed(MSG_BROADCAST, attacker))
695                                 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);   // FIXME: PLACEHOLDER
696                 }
697                 else
698                         if(sound_allowed(MSG_BROADCAST, attacker))
699                                 spamsound (this, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM);  // FIXME: PLACEHOLDER
700
701         }
702         else
703         {
704                 this.vehicle_health -= damage;
705
706                 if(sound_allowed(MSG_BROADCAST, attacker))
707                         spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);  // FIXME: PLACEHOLDER
708         }
709
710         if(this.damageforcescale < 1 && this.damageforcescale > 0)
711                 this.velocity += force * this.damageforcescale;
712         else
713                 this.velocity += force;
714
715         if(this.vehicle_health <= 0)
716         {
717                 if(this.owner)
718                         if(this.vehicle_flags & VHF_DEATHEJECT)
719                                 WITH(entity, self, this, vehicles_exit(VHEF_EJECT));
720                         else
721                                 WITH(entity, self, this, vehicles_exit(VHEF_RELEASE));
722
723
724                 antilag_clear(this, this);
725
726                 Vehicle info = Vehicles_from(this.vehicleid);
727                 info.vr_death(info, this);
728                 vehicles_setreturn(this);
729         }
730 }
731
732 float vehicles_crushable(entity e)
733 {
734         if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
735                 return true;
736
737         if(IS_MONSTER(e))
738                 return true;
739
740         return false;
741 }
742
743 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
744 {SELFPARAM();
745         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
746                 return;
747
748         if(self.play_time < time)
749         {
750                 float wc = vlen(self.velocity - self.oldvelocity);
751                 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
752                 //dprint("vel: ", vtos(self.velocity), "\n");
753                 if(_minspeed < wc)
754                 {
755                         float take = min(_speedfac * wc, _maxpain);
756                         Damage (self, world, world, take, DEATH_FALL.m_id, self.origin, '0 0 0');
757                         self.play_time = time + 0.25;
758
759                         //dprint("wc: ", ftos(wc), "\n");
760                         //dprint("take: ", ftos(take), "\n");
761                 }
762         }
763 }
764
765 // vehicle enter/exit handling
766 vector vehicles_findgoodexit(vector prefer_spot)
767 {SELFPARAM();
768         //vector exitspot;
769         float mysize;
770
771         tracebox(self.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, self.owner);
772         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
773                 return prefer_spot;
774
775         mysize = 1.5 * vlen(self.maxs - self.mins);
776         float i;
777         vector v, v2;
778         v2 = 0.5 * (self.absmin + self.absmax);
779         for(i = 0; i < 100; ++i)
780         {
781                 v = randomvec();
782                 v_z = 0;
783                 v = v2 + normalize(v) * mysize;
784                 tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, self.owner);
785                 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
786                         return v;
787         }
788
789         /*
790         exitspot = (self.origin + '0 0 48') + v_forward * mysize;
791         tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
792         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
793                 return exitspot;
794
795         exitspot = (self.origin + '0 0 48') - v_forward * mysize;
796         tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
797         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
798                 return exitspot;
799
800         exitspot = (self.origin + '0 0 48') + v_right * mysize;
801         tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
802         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
803                 return exitspot;
804
805         exitspot = (self.origin + '0 0 48') - v_right * mysize;
806         tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
807         if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
808                 return exitspot;
809         */
810
811         return self.origin;
812 }
813
814 void vehicles_exit(bool eject)
815 {SELFPARAM();
816         entity _vehicle;
817         entity _player;
818
819         if(vehicles_exit_running)
820         {
821                 LOG_TRACE("^1vehicles_exit allready running! this is not good..\n");
822                 return;
823         }
824
825         vehicles_exit_running = true;
826         if(IS_CLIENT(self))
827         {
828                 _vehicle = self.vehicle;
829
830                 if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
831                 {
832                         _vehicle.vehicle_exit(eject);
833                         setself(this);
834                         vehicles_exit_running = false;
835                         return;
836                 }
837         }
838         else
839                 _vehicle = self;
840
841         _player = _vehicle.owner;
842
843         setself(_vehicle);
844
845         if (_player)
846         {
847                 if (IS_REAL_CLIENT(_player))
848                 {
849                         msg_entity = _player;
850                         WriteByte (MSG_ONE, SVC_SETVIEWPORT);
851                         WriteEntity( MSG_ONE, _player);
852
853                         WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
854                         WriteAngle(MSG_ONE, 0);
855                         WriteAngle(MSG_ONE, _vehicle.angles_y);
856                         WriteAngle(MSG_ONE, 0);
857                 }
858
859                 setsize(_player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
860
861                 _player.takedamage              = DAMAGE_AIM;
862                 _player.solid                   = SOLID_SLIDEBOX;
863                 _player.movetype                = MOVETYPE_WALK;
864                 _player.effects            &= ~EF_NODRAW;
865                 _player.teleportable    = TELEPORT_NORMAL;
866                 _player.alpha                   = 1;
867                 _player.PlayerPhysplug  = func_null;
868                 _player.vehicle                 = world;
869                 _player.view_ofs                = STAT(PL_VIEW_OFS, NULL);
870                 _player.event_damage    = PlayerDamage;
871                 _player.hud                             = HUD_NORMAL;
872                 PS(_player).m_switchweapon = _vehicle.m_switchweapon;
873                 _player.last_vehiclecheck = time + 3;
874                 _player.vehicle_enter_delay = time + 2;
875
876                 CSQCVehicleSetup(_player, HUD_NORMAL);
877         }
878         _vehicle.flags |= FL_NOTARGET;
879
880         if(!IS_DEAD(_vehicle))
881                 _vehicle.avelocity = '0 0 0';
882
883         _vehicle.tur_head.nodrawtoclient = world;
884
885         if(!teamplay)
886                 _vehicle.team = 0;
887
888         Kill_Notification(NOTIF_ONE, _player, MSG_CENTER, CPID_VEHICLES);
889         Kill_Notification(NOTIF_ONE, _player, MSG_CENTER, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
890
891         WaypointSprite_Kill(_vehicle.wps_intruder);
892
893         MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle);
894
895         _vehicle.team = _vehicle.tur_head.team;
896
897         sound (_vehicle, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
898         _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
899         _vehicle.phase = time + 1;
900
901         _vehicle.vehicle_exit(eject);
902
903         vehicles_setreturn(_vehicle);
904         vehicles_reset_colors();
905         _vehicle.owner = world;
906
907         CSQCMODEL_AUTOINIT(self);
908
909         setself(this);
910         vehicles_exit_running = false;
911 }
912
913 void vehicles_touch()
914 {SELFPARAM();
915         if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
916                 return;
917
918         // Vehicle currently in use
919         if(self.owner)
920         {
921                 if(!forbidWeaponUse(self.owner))
922                 if(other != world)
923                 if((self.origin_z + self.maxs_z) > (other.origin_z))
924                 if(vehicles_crushable(other))
925                 {
926                         if(vdist(self.velocity, >=, 30))
927                                 Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH.m_id, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
928
929                         return; // Dont do selfdamage when hitting "soft targets".
930                 }
931
932                 if(self.play_time < time) {
933                         Vehicle info = Vehicles_from(self.vehicleid);
934                         info.vr_impact(info, self);
935                 }
936
937                 return;
938         }
939
940         if(autocvar_g_vehicles_enter)
941                 return;
942
943         vehicles_enter(other, self);
944 }
945
946 bool vehicle_impulse(entity this, int imp)
947 {
948         entity v = this.vehicle;
949         if (!v) return false;
950         if (IS_DEAD(v)) return false;
951         bool(int) f = v.vehicles_impulse;
952         if (f && f(imp)) return true;
953         switch (imp)
954         {
955                 case IMP_weapon_drop.impulse:
956                 {
957                         stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
958                         return true;
959                 }
960         }
961         return false;
962 }
963
964 void vehicles_enter(entity pl, entity veh)
965 {SELFPARAM();
966    // Remove this when bots know how to use vehicles
967         if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
968                 return;
969
970         if((!IS_PLAYER(pl))
971         || (veh.phase >= time)
972         || (pl.vehicle_enter_delay >= time)
973         || (STAT(FROZEN, pl))
974         || (IS_DEAD(pl))
975         || (pl.vehicle)
976         ) { return; }
977
978         if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
979         if(veh.vehicle_flags & VHF_MULTISLOT)
980         if(veh.owner)
981         {
982                 setself(veh);
983                 other = pl; // TODO: fix
984
985                 if(!veh.gunner1)
986                 if(time >= veh.gun1.phase)
987                 if(veh.gun1.vehicle_enter)
988                 if(veh.gun1.vehicle_enter())
989                 {
990                         setself(this);
991                         return;
992                 }
993
994                 if(!veh.gunner2)
995                 if(time >= veh.gun2.phase)
996                 if(veh.gun2.vehicle_enter)
997                 if(veh.gun2.vehicle_enter())
998                 {
999                         setself(this);
1000                         return;
1001                 }
1002
1003                 setself(this);
1004         }
1005
1006         if(teamplay)
1007         if(veh.team)
1008         if(DIFF_TEAM(pl, veh))
1009         if(autocvar_g_vehicles_steal)
1010         {
1011                 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL));
1012
1013                 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
1014
1015                 if (autocvar_g_vehicles_steal_show_waypoint) {
1016                         entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
1017                         wp.colormod = Team_ColorRGB(pl.team);
1018                 }
1019         }
1020         else return;
1021
1022         RemoveGrapplingHook(pl);
1023
1024         veh.vehicle_ammo1 = 0;
1025         veh.vehicle_ammo2 = 0;
1026         veh.vehicle_reload1 = 0;
1027         veh.vehicle_reload2 = 0;
1028         veh.vehicle_energy = 0;
1029
1030         veh.owner = pl;
1031         pl.vehicle = veh;
1032
1033         // .viewmodelforclient works better.
1034         //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
1035
1036         veh.vehicle_hudmodel.viewmodelforclient = pl;
1037
1038         tracebox(pl.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), pl.origin, false, pl);
1039         pl.crouch = false;
1040         pl.view_ofs = STAT(PL_VIEW_OFS, NULL);
1041         setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
1042
1043         veh.event_damage        = vehicles_damage;
1044         veh.nextthink           = 0;
1045         pl.angles                       = veh.angles;
1046         pl.takedamage           = DAMAGE_NO;
1047         pl.solid                        = SOLID_NOT;
1048         pl.movetype                     = MOVETYPE_NOCLIP;
1049         pl.teleportable         = false;
1050         pl.alpha                        = -1;
1051         pl.event_damage         = func_null;
1052         pl.view_ofs                     = '0 0 0';
1053         veh.colormap            = pl.colormap;
1054         if(veh.tur_head)
1055                 veh.tur_head.colormap = pl.colormap;
1056         veh.m_switchweapon = PS(pl).m_switchweapon;
1057         pl.hud = veh.vehicleid;
1058         pl.PlayerPhysplug = veh.PlayerPhysplug;
1059
1060         pl.vehicle_ammo1 = veh.vehicle_ammo1;
1061         pl.vehicle_ammo2 = veh.vehicle_ammo2;
1062         pl.vehicle_reload1 = veh.vehicle_reload1;
1063         pl.vehicle_reload2 = veh.vehicle_reload2;
1064         pl.vehicle_energy = veh.vehicle_energy;
1065
1066         // Cant do this, hides attached objects too.
1067         //veh.exteriormodeltoclient = veh.owner;
1068         //veh.tur_head.exteriormodeltoclient = veh.owner;
1069
1070         UNSET_ONGROUND(pl);
1071         UNSET_ONGROUND(veh);
1072
1073         veh.team = pl.team;
1074         veh.flags -= FL_NOTARGET;
1075
1076         if (IS_REAL_CLIENT(pl))
1077         {
1078                 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1079
1080                 msg_entity = pl;
1081                 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1082                 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1083
1084                 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1085                 if(veh.tur_head)
1086                 {
1087                         WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1088                         WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1089                         WriteAngle(MSG_ONE, 0);                                                                   // roll
1090                 }
1091                 else
1092                 {
1093                         WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1094                         WriteAngle(MSG_ONE, veh.angles_y);        // yaw
1095                         WriteAngle(MSG_ONE, 0);                           // roll
1096                 }
1097         }
1098
1099         vehicles_clearreturn(veh);
1100
1101         CSQCVehicleSetup(pl, veh.vehicleid);
1102
1103         MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1104
1105         setself(veh);
1106         CSQCModel_UnlinkEntity(veh);
1107         Vehicle info = Vehicles_from(veh.vehicleid);
1108         info.vr_enter(info, veh);
1109         setself(this);
1110
1111         antilag_clear(pl, CS(pl));
1112 }
1113
1114 void vehicles_think()
1115 {SELFPARAM();
1116         self.nextthink = time;
1117
1118         if(self.owner)
1119                 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1120
1121         Vehicle info = Vehicles_from(self.vehicleid);
1122         info.vr_think(info, self);
1123
1124         vehicles_painframe(self);
1125
1126         CSQCMODEL_AUTOUPDATE(self);
1127 }
1128
1129 // initialization
1130 void vehicles_spawn()
1131 {SELFPARAM();
1132         LOG_TRACE("Spawning vehicle: ", self.classname, "\n");
1133
1134         // disown & reset
1135         self.vehicle_hudmodel.viewmodelforclient = self;
1136
1137         self.owner                              = world;
1138         self.touch                              = vehicles_touch;
1139         self.event_damage               = vehicles_damage;
1140         self.iscreature                 = true;
1141         self.teleportable               = false; // no teleporting for vehicles, too buggy
1142         self.damagedbycontents  = true;
1143         self.movetype                   = MOVETYPE_WALK;
1144         self.solid                              = SOLID_SLIDEBOX;
1145         self.takedamage                 = DAMAGE_AIM;
1146         self.deadflag                   = DEAD_NO;
1147         self.bot_attack                 = true;
1148         self.flags                              = FL_NOTARGET;
1149         self.avelocity                  = '0 0 0';
1150         self.velocity                   = '0 0 0';
1151         self.think                              = vehicles_think;
1152         self.nextthink                  = time;
1153
1154         // Reset locking
1155         self.lock_strength = 0;
1156         self.lock_target = world;
1157         self.misc_bulletcounter = 0;
1158
1159         // Return to spawn
1160         self.angles = self.pos2;
1161         setorigin(self, self.pos1);
1162         // Show it
1163         Send_Effect(EFFECT_TELEPORT, self.origin + '0 0 64', '0 0 0', 1);
1164
1165         if(self.vehicle_controller)
1166                 self.team = self.vehicle_controller.team;
1167
1168         FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == self, RemoveGrapplingHook(it));
1169
1170         vehicles_reset_colors();
1171
1172         Vehicle info = Vehicles_from(self.vehicleid);
1173         info.vr_spawn(info, self);
1174
1175         CSQCMODEL_AUTOINIT(self);
1176 }
1177
1178 bool vehicle_initialize(entity veh, bool nodrop)
1179 {SELFPARAM();
1180         if(!autocvar_g_vehicles)
1181                 return false;
1182
1183         if(!veh.vehicleid)
1184                 return false;
1185
1186         if(!veh.tur_head) {
1187                 Vehicle info = Vehicles_from(veh.vehicleid);
1188                 info.vr_precache(info);
1189         }
1190
1191         if(self.targetname && self.targetname != "")
1192         {
1193                 self.vehicle_controller = find(world, target, self.targetname);
1194                 if(!self.vehicle_controller)
1195                 {
1196                         bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1197                         self.active = ACTIVE_ACTIVE;
1198                 }
1199                 else
1200                 {
1201                         self.team = self.vehicle_controller.team;
1202                         self.use = vehicle_use;
1203
1204                         if(teamplay)
1205                         {
1206                                 if(self.vehicle_controller.team == 0)
1207                                         self.active = ACTIVE_NOT;
1208                                 else
1209                                         self.active = ACTIVE_ACTIVE;
1210                         }
1211                 }
1212         }
1213         else { self.active = ACTIVE_ACTIVE; }
1214
1215         if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
1216                 self.team = 0;
1217
1218         if(self.mdl == "" || !self.mdl)
1219                 _setmodel(self, veh.model);
1220         else
1221                 _setmodel(self, self.mdl);
1222
1223         self.vehicle_flags |= VHF_ISVEHICLE;
1224
1225         self.vehicle_viewport           = new(vehicle_viewport);
1226         self.vehicle_hudmodel           = new(vehicle_hudmodel);
1227         self.tur_head                           = new(tur_head);
1228         self.tur_head.owner                     = self;
1229         self.takedamage                         = DAMAGE_NO;
1230         self.bot_attack                         = true;
1231         self.iscreature                         = true;
1232         self.teleportable                       = false; // no teleporting for vehicles, too buggy
1233         self.damagedbycontents          = true;
1234         self.vehicleid                          = veh.vehicleid;
1235         self.PlayerPhysplug                     = veh.PlayerPhysplug;
1236         self.event_damage                       = func_null;
1237         self.touch                                      = vehicles_touch;
1238         self.think                                      = vehicles_spawn;
1239         self.nextthink                          = time;
1240         self.effects                            = EF_NODRAW;
1241         self.dphitcontentsmask          = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1242
1243         if(autocvar_g_playerclip_collisions)
1244                 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1245
1246         if(autocvar_g_nodepthtestplayers)
1247                 self.effects |= EF_NODEPTHTEST;
1248
1249         if(autocvar_g_fullbrightplayers)
1250                 self.effects |= EF_FULLBRIGHT;
1251
1252         _setmodel(self.vehicle_hudmodel, veh.hud_model);
1253         setmodel(self.vehicle_viewport, MDL_Null);
1254
1255         if(veh.head_model != "")
1256         {
1257                 _setmodel(self.tur_head, veh.head_model);
1258                 setattachment(self.tur_head, self, veh.tag_head);
1259                 setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
1260                 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1261         }
1262         else
1263         {
1264                 setattachment(self.tur_head, self, "");
1265                 setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
1266                 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1267         }
1268
1269         setsize(self, veh.mins, veh.maxs);
1270
1271         if(!nodrop)
1272         {
1273                 setorigin(self, self.origin);
1274                 tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1275                 setorigin(self, trace_endpos);
1276         }
1277
1278         self.pos1 = self.origin;
1279         self.pos2 = self.angles;
1280         self.tur_head.team = self.team;
1281
1282         Vehicle info = Vehicles_from(veh.vehicleid);
1283         info.vr_setup(info, veh);
1284
1285         if(self.active == ACTIVE_NOT)
1286                 self.nextthink = 0; // wait until activated
1287         else if(autocvar_g_vehicles_delayspawn)
1288                 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1289         else
1290                 self.nextthink = time + game_starttime;
1291
1292         if(MUTATOR_CALLHOOK(VehicleSpawn))
1293                 return false;
1294
1295         return true;
1296 }