]> icculus.org git repositories - divverent/nexuiz.git/blob - TeamNexuiz/game/gamec/domination.c
bumps for morphed's teleporter model
[divverent/nexuiz.git] / TeamNexuiz / game / gamec / domination.c
1 \r
2 /*\r
3 Domination as a plugin for netquake mods\r
4 by LordHavoc (lordhavoc@ghdigital.com)\r
5 \r
6 How to add domination points to a mod:\r
7 1. Add this line to progs.src above world.qc:\r
8 domination.qc\r
9 2. Comment out all lines in ClientObituary in client.qc that begin with targ.frags  or attacker.frags.\r
10 3. Add this above worldspawn in world.qc:\r
11 void() dom_init;\r
12 4. Add this line to the end of worldspawn in world.qc:\r
13 dom_init();\r
14 \r
15 Note: The only teams who can use dom control points are identified by dom_team entities (if none exist these default to red and blue and use only quake models/sounds).\r
16 */\r
17 \r
18 void() dom_spawnteams;\r
19 \r
20 void() dompointthink =\r
21 {\r
22         local entity head;\r
23         self.nextthink = time + 3;\r
24         if (!self.goalentity.netname)\r
25                 return;\r
26         head = find(head, classname, "player");\r
27         while (head)\r
28         {\r
29                 if (head.team == self.goalentity.team)\r
30                         head.frags = head.frags + 1;\r
31                 head = find(head, classname, "player");\r
32         }\r
33 };\r
34 \r
35 void() dompointtouch =\r
36 {\r
37         local entity head;\r
38         if (other.classname != "player")\r
39                 return;\r
40         if (other.health < 1)\r
41                 return;\r
42         // only valid teams can claim it\r
43         head = find(world, classname, "dom_team");\r
44         while (head && head.team != other.team)\r
45                 head = find(head, classname, "dom_team");\r
46         if (!head || head.netname == "" || head == self.goalentity)\r
47                 return;\r
48 \r
49         self.goalentity = head;\r
50         self.model = head.mdl;\r
51         self.modelindex = head.dmg;\r
52         self.skin = head.skin;\r
53 \r
54         bprint(head.message);\r
55         bprint("\n");\r
56 \r
57         if (head.noise != "")\r
58                 sound(self, CHAN_BODY, head.noise, 1, ATTN_NORM);\r
59         if (head.noise1 != "")\r
60                 sound(self, CHAN_VOICE, head.noise1, 1, ATTN_NONE);\r
61 };\r
62 \r
63 /*QUAKED dom_team (0 .5 .8) (-16 -16 -24) (16 16 32)\r
64 Team declaration for Domination gameplay, this allows you to decide what team\r
65 names and control point models are used in your map.\r
66 \r
67 Note: If you use dom_team entities you must define at least 3 and only two\r
68 can have netname set!  The nameless team owns all control points at start.\r
69 \r
70 Keys:\r
71 "netname"\r
72  Name of the team (for example Red, Blue, Green, Yellow, Life, Death, etc)\r
73 "cnt"\r
74  Scoreboard color of the team (for example 4 is red and 13 is blue)\r
75 "model"\r
76  Model to use for control points owned by this team (for example\r
77  "progs/b_g_key.mdl" is a gold keycard, and "progs/b_s_key.mdl" is a silver\r
78  keycard)\r
79 "skin"\r
80  Skin of the model to use (for team skins on a single model)\r
81 "noise"\r
82  Sound to play when this team captures a point.\r
83  (this is a localized sound, like a small alarm or other effect)\r
84 "noise1"\r
85  Narrator speech to play when this team captures a point.\r
86  (this is a global sound, like "Red team has captured a control point")\r
87 "message"\r
88  Message to show when a team captures a point\r
89  (for example "Red team has captured a control point", or\r
90   "The forces of light have captured a mana well")\r
91 */\r
92 \r
93 void() dom_team =\r
94 {\r
95         precache_model(self.model);\r
96         if (self.noise != "")\r
97                 precache_sound(self.noise);\r
98         if (self.noise1 != "")\r
99                 precache_sound(self.noise1);\r
100         self.classname = "dom_team";\r
101         setmodel(self, self.model);\r
102         self.mdl = self.model;\r
103         self.dmg = self.modelindex;\r
104         self.model = "";\r
105         self.modelindex = 0;\r
106         // this would have to be changed if used in quakeworld\r
107         self.team = self.cnt + 1;\r
108 };\r
109 \r
110 void() dom_controlpoint_setup =\r
111 {\r
112         local entity head;\r
113         // find the dom_team representing unclaimed points\r
114         head = find(world, classname, "dom_team");\r
115         while(head && head.netname != "")\r
116                 head = find(head, classname, "dom_team");\r
117         if (!head)\r
118                 objerror("no dom_team with netname \"\" found\n");\r
119 \r
120         // copy important properties from dom_team entity\r
121         self.goalentity = head;\r
122         setmodel(self, head.mdl);\r
123         self.skin = head.skin;\r
124 \r
125         self.think = dompointthink;\r
126         self.nextthink = time;\r
127         self.touch = dompointtouch;\r
128         self.solid = SOLID_TRIGGER;\r
129         setsize(self, '-16 -16 -24', '16 16 32');\r
130         setorigin(self, self.origin);\r
131         droptofloor(0, 0);\r
132 };\r
133 \r
134 /*QUAKED dom_controlpoint (0 .5 .8) (-16 -16 -24) (16 16 32)\r
135 Control point for Domination gameplay.\r
136 */\r
137 void() dom_controlpoint =\r
138 {\r
139         self.think = dom_controlpoint_setup;\r
140         self.nextthink = time + 0.1;\r
141 };\r
142 \r
143 // code from here on is just to support maps that don't have control point and team entities\r
144 void(string teamname, float teamcolor, string pointmodel, float pointskin, string capsound, string capnarration, string capmessage) dom_spawnteam =\r
145 {\r
146         local entity oldself;\r
147         oldself = self;\r
148         self = spawn();\r
149         self.classname = "dom_team";\r
150         self.netname = teamname;\r
151         self.cnt = teamcolor;\r
152         self.model = pointmodel;\r
153         self.skin = pointskin;\r
154         self.noise = capsound;\r
155         self.noise1 = capnarration;\r
156         self.message = capmessage;\r
157 \r
158         // this code is identical to dom_team\r
159         setmodel(self, self.model);\r
160         self.mdl = self.model;\r
161         self.dmg = self.modelindex;\r
162         self.model = "";\r
163         self.modelindex = 0;\r
164         // this would have to be changed if used in quakeworld\r
165         self.team = self.cnt + 1;\r
166 \r
167         //eprint(self);\r
168         self = oldself;\r
169 };\r
170 \r
171 void(vector org) dom_spawnpoint =\r
172 {\r
173         local entity oldself;\r
174         oldself = self;\r
175         self = spawn();\r
176         self.classname = "dom_controlpoint";\r
177         self.think = dom_controlpoint;\r
178         self.nextthink = time;\r
179         self.origin = org;\r
180         dom_controlpoint();\r
181         self = oldself;\r
182 };\r
183 \r
184 void() dom_spawnteams =\r
185 {\r
186         // LordHavoc: edit this if you want to change defaults\r
187         dom_spawnteam("Red", 4, "models/domination/dom_red.md3", 0, "domination/claim.wav", "", "Red team has captured a control point");\r
188         dom_spawnteam("Blue", 13, "models/domination/dom_blue.md3", 0, "domination/claim.wav", "", "Blue team has captured a control point");\r
189         dom_spawnteam("Green", 3, "models/domination/dom_green.md3", 0, "domination/claim.wav", "", "Green team has captured a control point");\r
190         dom_spawnteam("Yellow", 12, "models/domination/dom_yellow.md3", 0, "domination/claim.wav", "", "Yellow team has captured a control point");\r
191         dom_spawnteam("", 0, "models/domination/dom_unclaimed.md3", 0, "", "", "");\r
192 };\r
193 \r
194 void() dom_delayedinit =\r
195 {\r
196         local entity head;\r
197         // if no teams are found, spawn defaults\r
198         if (find(world, classname, "dom_team") == world)\r
199                 dom_spawnteams();\r
200         // if no control points are found, spawn defaults\r
201         if (find(world, classname, "dom_controlpoint") == world)\r
202         {\r
203                 // here follow default domination points for each map\r
204                 /*\r
205                 if (world.model == "maps/e1m1.bsp")\r
206                 {\r
207                         dom_spawnpoint('0 0 0');\r
208                 }\r
209                 else\r
210                 */\r
211                 {\r
212                         // if no supported map was found, make every deathmatch spawn a point\r
213                         head = find(world, classname, "info_player_deathmatch");\r
214                         while (head)\r
215                         {\r
216                                 dom_spawnpoint(head.origin);\r
217                                 head = find(head, classname, "info_player_deathmatch");\r
218                         }\r
219                 }\r
220         }\r
221 };\r
222 \r
223 void() dom_init =\r
224 {\r
225         local entity e;\r
226         // we have to precache default models/sounds even if they might not be\r
227         // used because worldspawn is executed before any other entities are read,\r
228         // so we don't even know yet if this map is set up for domination...\r
229         precache_model("models/domination/dom_red.md3");\r
230         precache_model("models/domination/dom_blue.md3");\r
231         precache_model("models/domination/dom_green.md3");\r
232         precache_model("models/domination/dom_yellow.md3");\r
233         precache_model("models/domination/dom_unclaimed.md3");\r
234         precache_sound("domination/claim.wav");\r
235         e = spawn();\r
236         e.think = dom_delayedinit;\r
237         e.nextthink = time + 0.1;\r
238 };\r
239 \r