]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/assault.qc
target_objective_decrease only fires if activator.team matches the
[divverent/nexuiz.git] / data / qcsrc / server / assault.qc
1
2 // attacker spawn point
3 void info_player_attacker() {
4         info_player_deathmatch();
5         self.team = COLOR_TEAM1; // red, gets swapped every round
6 }
7
8 // defender spawn point
9 void info_player_defender() {
10         info_player_deathmatch();
11         self.team = COLOR_TEAM2; // blue, gets swapped every round
12 }
13
14 // reset this objective. Used when spawning an objective
15 // and when a new round starts
16 void assault_objective_reset() {
17         self.health = ASSAULT_VALUE_INACTIVE;
18 }
19
20 void assault_objective_use() {
21         // activate objective
22         self.health = 100; 
23         self.nextthink = time + 0.1;
24 }
25
26 void assault_objective_think() {
27         local entity oldself;   
28         if(self.health < 0) {
29                 //self.effects = 0;
30                 local entity ent;
31                 ent = find(world, targetname, self.target);
32                 while(ent) {
33                         oldself = self;
34                         self = ent;
35                         self.use();
36                         self = oldself;
37                         ent = find(ent, targetname, self.target);
38                         
39                 }
40         } else {
41                 //self.effects = EF_STARDUST;
42                 self.nextthink = time + 0.1;
43         }
44         
45 }
46
47 void target_objective() {
48         self.classname = "target_objective";
49         self.think = assault_objective_think;
50         self.use = assault_objective_use;
51         assault_objective_reset();
52 }
53
54
55 void assault_objective_decrease_think() {
56
57         local entity objective;
58         local float found;
59         found = 0;
60         objective = find(world, targetname, self.target);
61         while(objective && found == 0) {
62                 if(objective.classname == "target_objective") {
63                         found = 1;
64                         if(objective.health < ASSAULT_VALUE_INACTIVE) { // targeted objective is active
65                                 if(self.cnt == 1 && self.max_health >= ASSAULT_VALUE_INACTIVE) { 
66                                         // decrease was fired already, but objective did recover (round reset)
67                                         self.cnt = 0;
68                                 }
69                         } else { // objective isn't active
70                                 self.cnt = 1;
71                         }
72                         self.max_health = objective.health; // save current objective status for next think
73                 }
74         }
75
76         if(self.cnt == 0) {
77                 if(self.model != self.mdl)
78                         setmodel(self, self.mdl);
79         } else {
80                 self.model = "";
81         }
82
83         self.nextthink = time + 0.2;
84 }
85
86
87 // decrease the health of targeted objectives
88 void assault_objective_decrease() {
89
90         if(activator.team != self.team)
91                 return;
92
93         local entity ent;
94         ent = find(world, targetname, self.target);
95         while(ent) {
96                 if(ent.health > 0 && ent.health < ASSAULT_VALUE_INACTIVE)
97                         ent.health = ent.health - self.dmg;
98                 ent = find(ent, targetname, self.target);
99         }
100
101         self.cnt = 1;
102 }
103
104 // this entity should target an objective and be targeted by triggers
105 void target_objective_decrease() {
106
107         self.classname = "target_objective_decrease";
108
109         if(!self.dmg) {
110                 self.dmg = 101;
111         }
112         self.cnt = 0; // not used yet
113         self.use = assault_objective_decrease;
114         self.mdl = "models/sprites/here.sp2";
115         self.effects = EF_NODEPTHTEST;
116         self.team = COLOR_TEAM1; // red team, swaps every round
117         self.health = ASSAULT_VALUE_INACTIVE;
118         self.max_health = ASSAULT_VALUE_INACTIVE;
119         self.think = assault_objective_decrease_think;
120         self.nextthink = time;
121 }
122
123
124 void assault_destructible_reset() {
125         self.health = self.max_health;
126         self.model = self.mdl;
127         self.solid = SOLID_BSP;
128         self.cnt = 0; // not active
129         if(self.spawnflags)
130                 self.use();
131 }
132
133 void assault_destructible_use() {
134         self.cnt = 1; // mark active
135         self.takedamage = DAMAGE_YES;
136         self.nextthink = time + 0.1;
137 }
138
139 void assault_destructible_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) {
140
141         if(self.cnt > 0 && self.team == attacker.team)  
142                 self.health = self.health - damage;
143
144 }
145
146
147 void assault_destructible_think() {
148         local entity oldself;
149
150         if(self.cnt > 0 && self.health < 0) {
151                 self.model = "";
152                 self.takedamage = DAMAGE_NO;
153                 self.solid = SOLID_NOT;
154                 local entity ent;
155                 ent = find(world, targetname, self.target);
156                 while(ent) {
157                         oldself = self;
158                         self = ent;
159                         self.use();
160                         self = oldself;
161                         ent = find(ent, targetname, self.target);
162                 }
163         } else {
164                 self.nextthink = time + 0.1;
165         }
166 }
167
168 // destructible walls that can be used to trigger target_objective_decrease
169 void func_assault_destructible() {
170         if(!self.health)
171                 self.health = 100;
172
173         self.max_health = self.health;
174         
175         self.cnt = 0; // not yet activated
176
177         self.classname = "func_assault_destructible";
178         self.team = COLOR_TEAM1; // red team, gets swapped every round
179         self.mdl = self.model;
180         setmodel(self, self.mdl);
181
182         self.solid = SOLID_BSP;
183         self.think = assault_destructible_think;
184         self.use = assault_destructible_use;
185         self.event_damage = assault_destructible_damage;
186
187 }
188
189
190 // trigger new round
191 // reset objectives, toggle spawnpoints, reset triggers, ...
192 void assault_new_round() {
193         
194         // this assumes self.classname == "func_assault_roundend"!
195         self.cnt = self.cnt + 1;
196
197         // swap spawn point teams
198         local entity ent;
199         local entity oldself;
200
201         ent = find(world, classname, "info_player_deathmatch");
202         while (ent)
203         {
204                 oldself = self;
205                 self = ent;
206                 if(self.team == COLOR_TEAM1) {
207                         self.team = COLOR_TEAM2;
208                 } else {
209                         self.team = COLOR_TEAM1;
210                 }
211                 self = oldself;
212
213                 ent = find(ent, classname, "info_player_deathmatch");
214         } 
215
216         // reset all objectives
217         ent = find(world, classname, "target_objective");
218         while (ent)
219         {
220                 oldself = self;
221                 self = ent;
222                 assault_objective_reset();
223                 self = oldself;
224
225                 ent = find(ent, classname, "target_objective");
226         } 
227
228         // reset all target_object_decrease
229         ent = find(world, classname, "target_objective_decrease");
230         while (ent)
231         {
232                 if(ent.team == COLOR_TEAM1) {
233                         ent.team = COLOR_TEAM2;
234                 } else {
235                         ent.team = COLOR_TEAM1;
236                 }
237                 ent.cnt = 0;
238                 ent = find(ent, classname, "target_objective_decrease");
239         } 
240
241         // reset all func_assault_destructible
242         ent = find(world, classname, "func_assault_destructible");
243         while (ent)
244         {
245                 oldself = self;
246                 self = ent;
247                 assault_destructible_reset();
248                 if(self.team == COLOR_TEAM1) {
249                         self.team = COLOR_TEAM2;
250                 } else {
251                         self.team = COLOR_TEAM1;
252                 }
253                 self = oldself;
254                 ent = find(ent, classname, "func_assault_destructible");
255         }
256
257         ent = find(world, classname, "target_assault_roundstart");
258         while (ent)
259         {
260                 oldself = self;
261                 self = ent;
262                 self.use();
263                 self = oldself;
264                 ent = find(ent, classname, "target_assault_roundstart");
265         }
266
267         // actually restart round... how to do that?
268 }
269
270 void target_assault_roundend() {
271         self.cnt = 0; // round counter
272         self.classname = "target_assault_roundend";
273         self.use = assault_new_round;
274 }
275
276 void assault_roundstart_use() {
277         local entity ent;
278         local entity oldself;
279         ent = find(world, targetname, self.target);
280         while(ent) {
281                 oldself = self;
282                 self = ent;
283                 self.use();
284                 self = oldself;
285                 ent = find(ent, targetname, self.target);
286         }
287 }
288
289 void target_assault_roundstart() {
290         self.classname = "target_assault_roundstart";
291         self.use = assault_roundstart_use;
292         self.think = assault_roundstart_use;
293         self.nextthink = time + 0.1;
294 }
295
296