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