]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/vectormamamam.qc
Propagate this
[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()
61 {SELFPARAM();
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(self.target != "")
77                 self.wp00 = find(world, targetname, self.target);
78
79         if(self.target2 != "")
80                 self.wp01 = find(world, targetname, self.target2);
81
82         if(self.target3 != "")
83                 self.wp02 = find(world, targetname, self.target3);
84
85         if(self.target4 != "")
86                 self.wp03 = find(world, targetname, self.target4);
87
88         if(!self.wp00 && !self.wp01 && !self.wp02 && !self.wp03)
89                 objerror("No reference entity found, so there is nothing to move. Aborting.");
90
91         self.destvec = self.origin - func_vectormamamam_origin(self, 0);
92
93         entity controller;
94         controller = new(func_vectormamamam_controller);
95         controller.owner = self;
96         controller.nextthink = time + 1;
97         controller.think = func_vectormamamam_controller_think;
98 }
99
100 spawnfunc(func_vectormamamam)
101 {
102         if (self.noise != "")
103         {
104                 precache_sound(self.noise);
105                 soundto(MSG_INIT, self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
106         }
107
108         if(!self.targetfactor)
109                 self.targetfactor = 1;
110
111         if(!self.target2factor)
112                 self.target2factor = 1;
113
114         if(!self.target3factor)
115                 self.target3factor = 1;
116
117         if(!self.target4factor)
118                 self.target4factor = 1;
119
120         if(vlen(self.targetnormal))
121                 self.targetnormal = normalize(self.targetnormal);
122
123         if(vlen(self.target2normal))
124                 self.target2normal = normalize(self.target2normal);
125
126         if(vlen(self.target3normal))
127                 self.target3normal = normalize(self.target3normal);
128
129         if(vlen(self.target4normal))
130                 self.target4normal = normalize(self.target4normal);
131
132         self.blocked = generic_plat_blocked;
133         if(self.dmg && (self.message == ""))
134                 self.message = " was squished";
135     if(self.dmg && (self.message == ""))
136                 self.message2 = "was squished by";
137         if(self.dmg && (!self.dmgtime))
138                 self.dmgtime = 0.25;
139         self.dmgtime2 = time;
140
141         if(self.netname == "")
142                 self.netname = "1 0 0 0 1";
143
144         if (!InitMovingBrushTrigger())
145                 return;
146
147         // wait for targets to spawn
148         self.SUB_NEXTTHINK = self.SUB_LTIME + 999999999;
149         self.SUB_THINK = SUB_NullThink; // for PushMove
150
151         // Savage: Reduce bandwith, critical on e.g. nexdm02
152         self.effects |= EF_LOWPRECISION;
153
154         self.active = ACTIVE_ACTIVE;
155
156         InitializeEntity(self, func_vectormamamam_findtarget, INITPRIO_FINDTARGET);
157 }
158 #endif