80d6a6be29fa146940ccf242cfddb9c90413e2ea
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / onslaught / onslaught.qc
1 #include "onslaught.qh"
2
3 #ifdef GAMEQC
4 REGISTER_NET_LINKED(ENT_ONSCAMERA)
5 #endif
6
7 #ifdef CSQC
8
9 entity generator_camera;
10 NET_HANDLE(ENT_ONSCAMERA, bool isnew)
11 {
12         this.origin = ReadVector();
13         setorigin(this, this.origin);
14
15         this.angles_x = ReadAngle();
16         this.angles_y = ReadAngle();
17         this.angles_z = ReadAngle();
18
19         this.drawmask  = MASK_NORMAL;
20         setmodel(this, MDL_Null); // give it a size for clientcamera
21         setsize(this, '-1 -1 -1', '1 1 1');
22
23         generator_camera = this;
24         return true;
25 }
26
27 REGISTER_MUTATOR(cl_ons, true);
28
29 float ons_roundlost;
30 vector generator_origin;
31 vector autocvar_cl_eventchase_generator_viewoffset = '0 0 80';
32 float autocvar_cl_eventchase_generator_distance = 400;
33 MUTATOR_HOOKFUNCTION(cl_ons, WantEventchase)
34 {
35         ons_roundlost = STAT(ROUNDLOST);
36         entity gen = NULL;
37         if(ons_roundlost)
38         {
39                 IL_EACH(g_onsgenerators, it.health <= 0,
40                 {
41                         gen = it;
42                         break;
43                 });
44                 if(!gen)
45                         ons_roundlost = false; // don't enforce the 3rd person camera if there is no dead generator to show
46         }
47
48         if(ons_roundlost)
49         {
50                 generator_origin = gen.origin;
51                 return true;
52         }
53         return false;
54 }
55
56 MUTATOR_HOOKFUNCTION(cl_ons, CustomizeEventchase)
57 {
58         if(ons_roundlost)
59         {
60                 M_ARGV(0, vector) = generator_camera.origin;
61                 M_ARGV(1, vector) = autocvar_cl_eventchase_generator_viewoffset;
62                 M_ARGV(0, float) = autocvar_cl_eventchase_generator_distance;
63                 return true;
64         }
65         return false;
66 }
67
68 #endif