]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/func/vectormamamam.qc
Merge branch 'master' into terencehill/lms_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / func / vectormamamam.qc
1 #include "vectormamamam.qh"
2 #ifdef SVQC
3 // reusing some fields havocbots declared
4 .entity wp00, wp01, wp02, wp03;
5
6 .float targetfactor, target2factor, target3factor, target4factor;
7 .vector targetnormal, target2normal, target3normal, target4normal;
8
9 vector func_vectormamamam_origin(entity o, float timestep)
10 {
11         vector p;
12         entity e;
13         int myflags = o.spawnflags;
14         vector v = '0 0 0';
15
16         e = o.wp00;
17         if(e)
18         {
19                 p = e.origin + timestep * e.velocity;
20                 if(myflags & PROJECT_ON_TARGETNORMAL)
21                         v = v + (p * o.targetnormal) * o.targetnormal * o.targetfactor;
22                 else
23                         v = v + (p - (p * o.targetnormal) * o.targetnormal) * o.targetfactor;
24         }
25
26         e = o.wp01;
27         if(e)
28         {
29                 p = e.origin + timestep * e.velocity;
30                 if(myflags & PROJECT_ON_TARGET2NORMAL)
31                         v = v + (p * o.target2normal) * o.target2normal * o.target2factor;
32                 else
33                         v = v + (p - (p * o.target2normal) * o.target2normal) * o.target2factor;
34         }
35
36         e = o.wp02;
37         if(e)
38         {
39                 p = e.origin + timestep * e.velocity;
40                 if(myflags & PROJECT_ON_TARGET3NORMAL)
41                         v = v + (p * o.target3normal) * o.target3normal * o.target3factor;
42                 else
43                         v = v + (p - (p * o.target3normal) * o.target3normal) * o.target3factor;
44         }
45
46         e = o.wp03;
47         if(e)
48         {
49                 p = e.origin + timestep * e.velocity;
50                 if(myflags & PROJECT_ON_TARGET4NORMAL)
51                         v = v + (p * o.target4normal) * o.target4normal * o.target4factor;
52                 else
53                         v = v + (p - (p * o.target4normal) * o.target4normal) * o.target4factor;
54         }
55
56         return v;
57 }
58
59 void func_vectormamamam_controller_think(entity this)
60 {
61         this.nextthink = time + VECTORMAMAMAM_TIMESTEP;
62
63         if(this.owner.active != ACTIVE_ACTIVE)
64         {
65                 this.owner.velocity = '0 0 0';
66                 return;
67         }
68
69         if(this.owner.classname == "func_vectormamamam") // don't brake stuff if the func_vectormamamam was killtarget'ed
70                 this.owner.velocity = (this.owner.destvec + func_vectormamamam_origin(this.owner, VECTORMAMAMAM_TIMESTEP) - this.owner.origin) * 10;
71 }
72
73 void func_vectormamamam_findtarget(entity this)
74 {
75         if(this.target && this.target != "")
76                 this.wp00 = find(NULL, targetname, this.target);
77
78         if(this.target2 && this.target2 != "")
79                 this.wp01 = find(NULL, targetname, this.target2);
80
81         if(this.target3 && this.target3 != "")
82                 this.wp02 = find(NULL, targetname, this.target3);
83
84         if(this.target4 && this.target4 != "")
85                 this.wp03 = find(NULL, targetname, this.target4);
86
87         if(!this.wp00 && !this.wp01 && !this.wp02 && !this.wp03)
88                 objerror(this, "No reference entity found, so there is nothing to move. Aborting.");
89
90         this.destvec = this.origin - func_vectormamamam_origin(this, 0);
91
92         entity controller = new_pure(func_vectormamamam_controller);
93         controller.owner = this;
94         controller.nextthink = time + 1;
95         setthink(controller, func_vectormamamam_controller_think);
96 }
97
98 void func_vectormamamam_setactive(entity this, int astate)
99 {
100         if (astate == ACTIVE_TOGGLE)
101         {
102                 if(this.active == ACTIVE_ACTIVE)
103                         this.active = ACTIVE_NOT;
104                 else
105                         this.active = ACTIVE_ACTIVE;
106         }
107         else
108                 this.active = astate;
109
110         if(this.active  == ACTIVE_NOT)
111         {
112                 stopsound(this, CH_TRIGGER_SINGLE);
113         }
114         else
115         {
116                 if(this.noise && this.noise != "")
117                 {
118                         _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
119                 }
120         }
121 }
122
123 void func_vectormamamam_init_for_player(entity this, entity player)
124 {
125         if (this.noise && this.noise != "" && this.active == ACTIVE_ACTIVE && IS_REAL_CLIENT(player))
126         {
127                 msg_entity = player;
128                 soundto(MSG_ONE, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE, 0);
129         }
130 }
131
132 spawnfunc(func_vectormamamam)
133 {
134         if (this.noise != "")
135         {
136                 precache_sound(this.noise);
137         }
138
139         if(!this.targetfactor)
140                 this.targetfactor = 1;
141
142         if(!this.target2factor)
143                 this.target2factor = 1;
144
145         if(!this.target3factor)
146                 this.target3factor = 1;
147
148         if(!this.target4factor)
149                 this.target4factor = 1;
150
151         if(this.targetnormal)
152                 this.targetnormal = normalize(this.targetnormal);
153
154         if(this.target2normal)
155                 this.target2normal = normalize(this.target2normal);
156
157         if(this.target3normal)
158                 this.target3normal = normalize(this.target3normal);
159
160         if(this.target4normal)
161                 this.target4normal = normalize(this.target4normal);
162
163         setblocked(this, generic_plat_blocked);
164         if(this.dmg && (!this.message || this.message == ""))
165                 this.message = " was squished";
166     if(this.dmg && (!this.message2 || this.message2 == ""))
167                 this.message2 = "was squished by";
168         if(this.dmg && (!this.dmgtime))
169                 this.dmgtime = 0.25;
170         this.dmgtime2 = time;
171
172         if (!InitMovingBrushTrigger(this))
173                 return;
174
175         // wait for targets to spawn
176         this.nextthink = this.ltime + 999999999;
177         setthink(this, SUB_NullThink); // for PushMove
178
179         // Savage: Reduce bandwith, critical on e.g. nexdm02
180         this.effects |= EF_LOWPRECISION;
181
182         this.setactive = func_vectormamamam_setactive;
183         this.setactive(this, ACTIVE_ACTIVE);
184
185         // maybe send sound to new players
186         IL_PUSH(g_initforplayer, this);
187         this.init_for_player = func_vectormamamam_init_for_player;
188
189         InitializeEntity(this, func_vectormamamam_findtarget, INITPRIO_FINDTARGET);
190 }
191 #endif