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