]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/generator.qc
Merge branch 'master' into Mario/monsters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / generator.qc
1 #ifdef CSQC
2 float generator_precached;
3
4 void generator_precache()
5 {
6         if(generator_precached)
7                 return; // already precached
8                 
9         precache_model("models/onslaught/generator.md3");
10         precache_model("models/onslaught/generator_dead.md3");
11         precache_model("models/onslaught/generator_dmg1.md3");
12         precache_model("models/onslaught/generator_dmg2.md3");
13         precache_model("models/onslaught/generator_dmg3.md3");
14         precache_model("models/onslaught/generator_dmg4.md3");
15         precache_model("models/onslaught/generator_dmg5.md3");
16         precache_model("models/onslaught/generator_dmg6.md3");
17         precache_model("models/onslaught/generator_dmg7.md3");
18         precache_model("models/onslaught/generator_dmg8.md3");
19         precache_model("models/onslaught/generator_dmg9.md3");
20         precache_model("models/onslaught/generator_dead.md3");
21         
22         generator_precached = TRUE;
23 }
24
25 void generator_draw() { } // TODO
26
27 .float max_health;
28 void generator_damage(float hp)
29 {
30         if(hp <= 0)
31                 setmodel(self, "models/onslaught/generator_dead.md3");
32         else if(hp < self.max_health * 0.10)
33                 setmodel(self, "models/onslaught/generator_dmg9.md3");
34         else if(hp < self.max_health * 0.20)
35                 setmodel(self, "models/onslaught/generator_dmg8.md3");
36         else if(hp < self.max_health * 0.30)
37                 setmodel(self, "models/onslaught/generator_dmg7.md3");
38         else if(hp < self.max_health * 0.40)
39                 setmodel(self, "models/onslaught/generator_dmg6.md3");
40         else if(hp < self.max_health * 0.50)
41                 setmodel(self, "models/onslaught/generator_dmg5.md3");
42         else if(hp < self.max_health * 0.60)
43                 setmodel(self, "models/onslaught/generator_dmg4.md3");
44         else if(hp < self.max_health * 0.70)
45                 setmodel(self, "models/onslaught/generator_dmg3.md3");
46         else if(hp < self.max_health * 0.80)
47                 setmodel(self, "models/onslaught/generator_dmg2.md3");
48         else if(hp < self.max_health * 0.90)
49                 setmodel(self, "models/onslaught/generator_dmg1.md3");
50         else if(hp <= self.max_health || hp >= self.max_health)
51                 setmodel(self, "models/onslaught/generator.md3");
52                 
53         setsize(self, GENERATOR_MIN, GENERATOR_MAX);
54 }
55
56 void generator_construct()
57 {       
58         self.netname = "Generator";
59
60         setorigin(self, self.origin);
61         setmodel(self, "models/onslaught/generator.md3");
62         setsize(self, GENERATOR_MIN, GENERATOR_MAX);
63         
64         self.move_movetype      = MOVETYPE_NOCLIP;
65         self.solid                      = SOLID_BBOX;
66         self.movetype           = MOVETYPE_NOCLIP; 
67         self.move_origin        = self.origin;
68         self.move_time          = time;
69         self.drawmask           = MASK_NORMAL;  
70         self.alpha                      = 1;
71         self.draw                       = generator_draw;
72 }
73
74 .vector glowmod;
75 void generator_changeteam()
76 {
77         self.glowmod = Team_ColorRGB(self.team - 1);
78         self.teamradar_color = Team_ColorRGB(self.team - 1);
79         
80         if(self.team)
81                 self.colormap = 1024 + (self.team - 1) * 17;
82 }
83
84 void ent_generator()
85 {
86         float sf;
87         sf = ReadByte();
88
89         if(sf & GSF_SETUP)
90         {
91                 self.origin_x = ReadCoord();
92                 self.origin_y = ReadCoord();
93                 self.origin_z = ReadCoord();
94                 setorigin(self, self.origin);
95                 
96                 self.health = ReadByte();
97                 self.max_health = ReadByte();
98                 
99                 generator_precache();
100                 generator_construct();
101                 self.colormap = 1024;
102                 self.glowmod = '1 1 0'; 
103         }
104
105         if(sf & GSF_STATUS)
106         {
107                 float _tmp;
108                 _tmp = ReadByte();
109                 if(_tmp != self.team)
110                 {                       
111                         self.team = _tmp;                               
112                         generator_changeteam();
113                 }
114                 
115                 _tmp = ReadByte();
116                 
117                 if(_tmp != self.health)
118                         generator_damage(_tmp);
119                 
120                 //if(_tmp == 0 && self.health != 0)
121                         //generator_die();
122
123                 self.health = _tmp;
124         }
125 }
126 #endif // CSQC
127
128 #ifdef SVQC
129 float generator_send(entity to, float sf)
130 {
131         WriteByte(MSG_ENTITY, ENT_CLIENT_GENERATOR);    
132         WriteByte(MSG_ENTITY, sf);
133         if(sf & GSF_SETUP)
134         {
135             WriteCoord(MSG_ENTITY, self.origin_x);
136             WriteCoord(MSG_ENTITY, self.origin_y);
137             WriteCoord(MSG_ENTITY, self.origin_z);
138                 
139                 WriteByte(MSG_ENTITY, self.health);
140                 WriteByte(MSG_ENTITY, self.max_health);
141     }
142     
143     if(sf & GSF_STATUS)
144     {
145                 WriteByte(MSG_ENTITY, self.team);
146         
147         if(self.health <= 0)
148             WriteByte(MSG_ENTITY, 0);
149         else
150             WriteByte(MSG_ENTITY, ceil((self.health / self.max_health) * 255));
151     }
152     
153         return TRUE;
154 }
155
156 void generator_link(void() spawnproc)
157 {
158     Net_LinkEntity(self, TRUE, 0, generator_send);
159     self.think      = spawnproc;
160     self.nextthink  = time;
161 }
162 #endif // SVQC