]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/assault.qc
target_objective_decrease is now only triggerable once per round. Added
[divverent/nexuiz.git] / data / qcsrc / server / assault.qc
1
2 // attacker spawn point
3 void info_player_attacker() {
4         self.team = COLOR_TEAM1; // red, gets swapped every round
5         info_player_deathmatch();
6 }
7
8 // defender spawn point
9 void info_player_defender() {
10         self.team = COLOR_TEAM2; // blue, gets swapped every round
11         info_player_deathmatch();
12 }
13
14 // reset this objective. Used when spawning an objective
15 // and when a new round starts
16 void assault_objective_reset() {
17         if(self.spawnflags) { // first objective
18                 self.health = 100;
19                 self.nextthink = time + 0.1;
20         } else {
21                 self.health = ASSAULT_VALUE_INACTIVE;
22         }
23 }
24
25 void assault_objective_use() {
26         // activate objective
27         self.health = 100; 
28         self.nextthink = time + 0.1;
29 }
30
31 void assault_objective_think() {
32         
33         if(self.health < 0) {
34                 local entity ent;
35                 ent = find(world, targetname, self.target);
36                 self = ent;
37                 self.use();
38         } else {
39                 self.nextthink = time + 0.1;
40         }
41         
42 }
43
44 void target_objective() {
45         self.classname = "target_objective";
46         self.think = assault_objective_think;
47         self.use = assault_objective_use;
48         assault_objective_reset();
49 }
50
51 // decrease the health of targeted objectives
52 void assault_objective_decrease() {
53         // can only be triggered once per round
54         if(self.cnt > 0)
55                 return;
56
57         local entity ent;
58         local entity oldself;
59         ent = find(world, targetname, self.target);
60         while(ent) {
61                 ent.health = ent.health - self.dmg;
62                 ent = find(ent, targetname, self.target);
63         }
64
65         self.cnt = 1;
66 }
67
68 // this entity should target an objective and be targeted by triggers
69 void target_objective_decrease() {
70         self.cnt = 0;
71         self.classname = "target_objective_decrease";
72
73         if(!self.dmg) {
74                 self.dmg = 101;
75         }
76         self.use = assault_objective_decrease;
77 }
78
79 // trigger new round
80 // reset objectives, toggle spawnpoints, reset triggers, ...
81 void assault_new_round() {
82         
83         // this assumes self.classname == "func_assault_roundend"!
84         self.cnt = self.cnt + 1;
85
86         // swap spawn point teams
87         local entity ent;
88         local entity oldself;
89
90         ent = find(world, classname, "info_player_deathmatch");
91         while (ent)
92         {
93                 oldself = self;
94                 self = ent;
95                 if(self.team == COLOR_TEAM1) {
96                         self.team = COLOR_TEAM2;
97                 } else {
98                         self.team = COLOR_TEAM1;
99                 }
100                 self = oldself;
101
102                 ent = find(ent, classname, "info_player_deathmatch");
103         } 
104
105         // reset all objectives
106         ent = find(world, classname, "target_objective");
107         while (ent)
108         {
109                 oldself = self;
110                 self = ent;
111                 assault_objective_reset();
112                 self = oldself;
113
114                 ent = find(ent, classname, "target_objective");
115         } 
116
117         // reset all target_objective_decrease
118         ent = find(world, classname, "target_objective_decrease");
119         while (ent)
120         {
121                 ent.cnt = 0;
122                 ent = find(ent, classname, "target_objective_decrease");
123         } 
124
125
126         // actually restart round... how to do that?
127 }
128
129 void target_assault_roundend() {
130         self.cnt = 0; // round counter
131         self.classname = "target_assault_roundend";
132         self.use = assault_new_round;
133         
134 }