]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/vectormamamam.qc
Merge branch 'terencehill/v_deathtilt_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / vectormamamam.qc
1 #ifdef SVQC
2 // reusing some fields havocbots declared
3 .entity wp00, wp01, wp02, wp03;
4
5 .float targetfactor, target2factor, target3factor, target4factor;
6 .vector targetnormal, target2normal, target3normal, target4normal;
7
8 vector func_vectormamamam_origin(entity o, float t)
9 {
10         vector v, p;
11         float f;
12         entity e;
13
14         f = o.spawnflags;
15         v = '0 0 0';
16
17         e = o.wp00;
18         if(e)
19         {
20                 p = e.origin + t * e.velocity;
21                 if(f & 1)
22                         v = v + (p * o.targetnormal) * o.targetnormal * o.targetfactor;
23                 else
24                         v = v + (p - (p * o.targetnormal) * o.targetnormal) * o.targetfactor;
25         }
26
27         e = o.wp01;
28         if(e)
29         {
30                 p = e.origin + t * e.velocity;
31                 if(f & 2)
32                         v = v + (p * o.target2normal) * o.target2normal * o.target2factor;
33                 else
34                         v = v + (p - (p * o.target2normal) * o.target2normal) * o.target2factor;
35         }
36
37         e = o.wp02;
38         if(e)
39         {
40                 p = e.origin + t * e.velocity;
41                 if(f & 4)
42                         v = v + (p * o.target3normal) * o.target3normal * o.target3factor;
43                 else
44                         v = v + (p - (p * o.target3normal) * o.target3normal) * o.target3factor;
45         }
46
47         e = o.wp03;
48         if(e)
49         {
50                 p = e.origin + t * e.velocity;
51                 if(f & 8)
52                         v = v + (p * o.target4normal) * o.target4normal * o.target4factor;
53                 else
54                         v = v + (p - (p * o.target4normal) * o.target4normal) * o.target4factor;
55         }
56
57         return v;
58 }
59
60 void func_vectormamamam_controller_think(entity this)
61 {
62         self.nextthink = time + 0.1;
63
64         if(self.owner.active != ACTIVE_ACTIVE)
65         {
66                 self.owner.velocity = '0 0 0';
67                 return;
68         }
69
70         if(self.owner.classname == "func_vectormamamam") // don't brake stuff if the func_vectormamamam was killtarget'ed
71                 self.owner.velocity = (self.owner.destvec + func_vectormamamam_origin(self.owner, 0.1) - self.owner.origin) * 10;
72 }
73
74 void func_vectormamamam_findtarget(entity this)
75 {
76         if(this.target != "")
77                 this.wp00 = find(world, targetname, this.target);
78
79         if(this.target2 != "")
80                 this.wp01 = find(world, targetname, this.target2);
81
82         if(this.target3 != "")
83                 this.wp02 = find(world, targetname, this.target3);
84
85         if(this.target4 != "")
86                 this.wp03 = find(world, targetname, this.target4);
87
88         if(!this.wp00 && !this.wp01 && !this.wp02 && !this.wp03)
89                 objerror("No reference entity found, so there is nothing to move. Aborting.");
90
91         this.destvec = this.origin - func_vectormamamam_origin(this, 0);
92
93         entity controller;
94         controller = new(func_vectormamamam_controller);
95         controller.owner = this;
96         controller.nextthink = time + 1;
97         setthink(controller, func_vectormamamam_controller_think);
98 }
99
100 spawnfunc(func_vectormamamam)
101 {
102         if (this.noise != "")
103         {
104                 precache_sound(this.noise);
105                 soundto(MSG_INIT, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
106         }
107
108         if(!this.targetfactor)
109                 this.targetfactor = 1;
110
111         if(!this.target2factor)
112                 this.target2factor = 1;
113
114         if(!this.target3factor)
115                 this.target3factor = 1;
116
117         if(!this.target4factor)
118                 this.target4factor = 1;
119
120         if(vlen(this.targetnormal))
121                 this.targetnormal = normalize(this.targetnormal);
122
123         if(vlen(this.target2normal))
124                 this.target2normal = normalize(this.target2normal);
125
126         if(vlen(this.target3normal))
127                 this.target3normal = normalize(this.target3normal);
128
129         if(vlen(this.target4normal))
130                 this.target4normal = normalize(this.target4normal);
131
132         this.blocked = generic_plat_blocked;
133         if(this.dmg && (this.message == ""))
134                 this.message = " was squished";
135     if(this.dmg && (this.message == ""))
136                 this.message2 = "was squished by";
137         if(this.dmg && (!this.dmgtime))
138                 this.dmgtime = 0.25;
139         this.dmgtime2 = time;
140
141         if(this.netname == "")
142                 this.netname = "1 0 0 0 1";
143
144         if (!InitMovingBrushTrigger(this))
145                 return;
146
147         // wait for targets to spawn
148         this.SUB_NEXTTHINK = this.SUB_LTIME + 999999999;
149         SUB_THINK(this, SUB_NullThink); // for PushMove
150
151         // Savage: Reduce bandwith, critical on e.g. nexdm02
152         this.effects |= EF_LOWPRECISION;
153
154         this.active = ACTIVE_ACTIVE;
155
156         InitializeEntity(this, func_vectormamamam_findtarget, INITPRIO_FINDTARGET);
157 }
158 #endif