]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/client.qc
*** empty log message ***
[divverent/nexuiz.git] / qcsrc / client.qc
1
2 void info_player_start (void)
3 {
4 }
5
6 void info_player_deathmatch (void)
7 {
8 }
9
10 /*
11 =============
12 SelectSpawnPoint
13
14 Finds a point to respawn
15 =============
16 */
17 entity SelectSpawnPoint (void)
18 {
19         entity  spot, thing;
20         float   pcount;
21
22         spot = findchain (classname, "info_player_deathmatch");
23         
24         while (spot)
25         {
26                 pcount = 0;
27                 thing = findradius (spot.origin, 100);
28                 while (thing)
29                 {
30                         if (thing.classname == "player")
31                                 pcount = pcount + 1;
32                         thing = thing.chain;
33                 }
34                 if (!pcount)
35                         return spot;
36                         
37                 spot = spot.chain;
38         }
39         
40         if (spot == world)
41         {
42                 spot = findchain (classname, "info_player_start");
43                 if (spot == world)
44                         error ("No startpoint found\n");
45                 return spot;
46         }
47         
48         return spot;
49 }
50
51
52 /*
53 =============
54 PutClientInServer
55
56 Called when a client spawns in the server
57 =============
58 */
59 void PutClientInServer (void)
60 {
61         entity  spot;
62         
63         spot = SelectSpawnPoint ();
64         
65         self.classname = "player";
66         self.movetype = MOVETYPE_WALK;
67         self.solid = SOLID_SLIDEBOX;
68         self.flags = FL_CLIENT;
69         self.takedamage = DAMAGE_YES;
70         self.health = 125;
71         
72         self.ammo_shells = 100;
73         self.ammo_nails = 100;
74         self.ammo_rockets = 100;
75         self.ammo_cells = 100;
76         
77         self.deadflag = DEAD_NO;
78         
79         self.view_ofs = PL_VIEW_OFS;
80         self.angles = spot.angles;
81         setmodel (self, "models/player/player.zym");
82         setsize (self, PL_MIN, PL_MAX);
83         setorigin (self, spot.origin);
84         
85         self.items = IT_LASER | IT_UZI | IT_SHOTGUN | IT_GRENADE_LAUNCHER | IT_ELECTRO | IT_CRYLINK | IT_NEX | IT_HAGAR | IT_ROCKET_LAUNCHER;
86         self.weapon = IT_UZI;
87         
88         self.event_hurt = PlayerHurt;
89         self.event_die = PlayerDie;
90         
91         self.statdraintime = time + 5;
92         self.button0 = self.button1 = self.button2 = self.button3 = 0;
93         
94         W_UpdateWeapon ();
95         W_UpdateAmmo ();
96 }
97
98 /*
99 =============
100 SetNewParms
101 =============
102 */
103 void SetNewParms (void)
104 {
105         
106 }
107
108 /*
109 =============
110 SetChangeParms
111 =============
112 */
113 void SetChangeParms (void)
114 {
115         
116 }
117
118 /*
119 =============
120 ClientKill
121
122 Called when a client types 'kill' in the console
123 =============
124 */
125 void ClientKill (void)
126 {
127         
128 }
129
130 /*
131 =============
132 ClientConnect
133
134 Called when a client connects to the server
135 =============
136 */
137 void ClientConnect (void)
138 {
139         ClientInRankings();
140         bprint (self.netname);
141         bprint (" connected\n");
142 }
143
144 /*
145 =============
146 ClientDisconnect
147
148 Called when a client disconnects from the server
149 =============
150 */
151 void ClientDisconnect (void)
152 {
153         ClientDisconnected();
154         bprint (self.netname);
155         bprint (" disconnected\n");
156 }
157
158 /*
159 =============
160 PlayerJump
161
162 When you press the jump key
163 =============
164 */
165 void PlayerJump (void)
166 {
167         if (self.deadflag != DEAD_NO)
168         {
169                 if (self.death_time < time)
170                         PutClientInServer();
171
172                 return;
173         }
174         if (!(self.flags & FL_ONGROUND))
175                 return;
176         if (!(self.flags & FL_JUMPRELEASED))
177                 return;
178         
179         self.velocity_z = self.velocity_z + 270;
180         
181         self.flags = self.flags - FL_ONGROUND;
182         self.flags = self.flags - FL_JUMPRELEASED;
183 }
184
185 /*
186 =============
187 PlayerPreThink
188
189 Called every frame for each client before the physics are run
190 =============
191 */
192 .float attack_finished;
193 void PlayerPreThink (void)
194 {
195         if (BotPreFrame())
196                 return;
197                 
198         if (self.attack_finished < time)
199         {
200                 if (self.button0)
201                         W_Attack ();
202                 else if (self.button3)
203                         W_SecondaryAttack ();
204         }
205
206         if (self.button2)
207                 PlayerJump ();
208         else
209                 self.flags = self.flags | FL_JUMPRELEASED;
210
211         if (self.deadflag != DEAD_NO)
212         {
213                 self.angles = self.dead_angles;
214                 return;
215         }
216
217         if (self.weapon == IT_NEX && self.button3)
218                 self.viewzoom = 0.1;
219         else if (self.viewzoom != 1)
220                 self.viewzoom = 1;
221                 
222         if (self.statdraintime < time)
223         {
224                 if (self.health > 100)
225                         self.health = self.health - 1;
226                 if (self.armorvalue > 100)
227                         self.armorvalue = self.armorvalue - 1;
228                         
229                 self.statdraintime = time + 1;
230         }
231 }
232
233 /*
234 =============
235 PlayerPostThink
236
237 Called every frame for each client after the physics are run
238 =============
239 */
240 void PlayerPostThink (void)
241 {
242         if (BotPostFrame())
243                 return;
244
245         ImpulseCommands ();
246 }