summaryrefslogtreecommitdiffstats
path: root/src/jake2/game/gclient_t.java
blob: cdccd029c55dfca170bf866923b437c05d657cf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

// Created on 31.10.2003 by RST.
// $Id: gclient_t.java,v 1.4 2004-09-10 19:02:56 salomo Exp $

package jake2.game;

import jake2.qcommon.Com;
import jake2.util.Lib;
import jake2.util.QuakeFile;

import java.awt.event.ItemListener;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;

public class gclient_t
{

	public gclient_t(int index)
	{
		this.index = index;
	}
	//	this structure is cleared on each PutClientInServer(),
	//	except for 'client->pers'

	// known to server
	public player_state_t ps = new player_state_t(); // communicated by server to clients
	public int ping;

	// private to game
	public client_persistant_t pers = new client_persistant_t();
	public client_respawn_t resp = new client_respawn_t();
	public pmove_state_t old_pmove = new pmove_state_t(); // for detecting out-of-pmove changes

	public boolean showscores; // set layout stat
	public boolean showinventory; // set layout stat
	public boolean showhelp;
	public boolean showhelpicon;

	public int ammo_index;

	public int buttons;
	public int oldbuttons;
	public int latched_buttons;

	public boolean weapon_thunk;

	public gitem_t newweapon;

	// sum up damage over an entire frame, so
	// shotgun blasts give a single big kick
	public int damage_armor; // damage absorbed by armor
	public int damage_parmor; // damage absorbed by power armor
	public int damage_blood; // damage taken out of health
	public int damage_knockback; // impact damage
	public float[] damage_from = { 0, 0, 0 }; // origin for vector calculation

	public float killer_yaw; // when dead, look at killer

	public int weaponstate;
	public float[] kick_angles = { 0, 0, 0 }; // weapon kicks
	public float[] kick_origin = { 0, 0, 0 };
	public float v_dmg_roll, v_dmg_pitch, v_dmg_time; // damage kicks
	public float fall_time, fall_value; // for view drop on fall
	public float damage_alpha;
	public float bonus_alpha;
	public float[] damage_blend = { 0, 0, 0 };
	public float[] v_angle = { 0, 0, 0 }; // aiming direction
	public float bobtime; // so off-ground doesn't change it
	public float[] oldviewangles = { 0, 0, 0 };
	public float[] oldvelocity = { 0, 0, 0 };

	public float next_drown_time;
	public int old_waterlevel;
	public int breather_sound;

	public int machinegun_shots; // for weapon raising

	// animation vars
	public int anim_end;
	public int anim_priority;
	public boolean anim_duck;
	public boolean anim_run;

	// powerup timers
	public float quad_framenum;
	public float invincible_framenum;
	public float breather_framenum;
	public float enviro_framenum;

	public boolean grenade_blew_up;
	public float grenade_time;
	public int silencer_shots;
	public int weapon_sound;

	public float pickup_msg_time;

	public float flood_locktill; // locked from talking
	public float flood_when[] = new float[10]; // when messages were said
	public int flood_whenhead; // head pointer for when said

	public float respawn_time; // can respawn when time > this

	public edict_t chase_target; // player we are chasing
	public boolean update_chase; // need to update chase info?

	public int index;




	public void clear()
	{
		player_state_t ps = new player_state_t();
		pers = new client_persistant_t();
		resp = new client_respawn_t();
		old_pmove = new pmove_state_t();

		buttons = oldbuttons = latched_buttons = 0;
		weapon_thunk = false;
		newweapon = null;
		damage_armor = 0;
		damage_parmor = 0;
		damage_blood = 0;
		damage_knockback = 0;
		killer_yaw = 0;
		damage_from = new float[3];
		kick_angles = new float[3];
		kick_origin = new float[3];
		v_dmg_roll = v_dmg_pitch = v_dmg_time = 0;
		fall_time = fall_value = 0;
		damage_alpha = 0;
		bonus_alpha = 0;
		damage_blend = new float[3];
		v_angle = new float[3];
		bobtime = 0;

		oldviewangles = new float[3];

		oldvelocity = new float[3];

		next_drown_time = 0;

		old_waterlevel = 0;
		anim_end = 0;
		anim_priority = 0;
		anim_duck = false;
		anim_run = false;

	}

	/** Reads a game client from the file. */
	public void read(QuakeFile f) throws IOException
	{

		ps.load(f);

		ping = f.readInt();

		pers.read(f);
		resp.read(f);

		old_pmove.load(f);

		showscores = f.readInt() != 0;
		showinventory = f.readInt() != 0;
		showhelp = f.readInt() != 0;
		showhelpicon = f.readInt() != 0;
		ammo_index = f.readInt();

		buttons = f.readInt();
		oldbuttons = f.readInt();
		latched_buttons = f.readInt();

		weapon_thunk=f.readInt()!=0;
		
		newweapon=f.readItem();
		

		damage_armor = f.readInt();
		damage_parmor = f.readInt();
		damage_blood = f.readInt();
		damage_knockback = f.readInt();

		damage_from[0] = f.readFloat();
		damage_from[1] = f.readFloat();
		damage_from[2] = f.readFloat();

		killer_yaw = f.readFloat();

		weaponstate = f.readInt();

		kick_angles[0] = f.readFloat();
		kick_angles[1] = f.readFloat();
		kick_angles[2] = f.readFloat();

		kick_origin[0] = f.readFloat();
		kick_origin[1] = f.readFloat();
		kick_origin[2] = f.readFloat();

		v_dmg_roll = f.readFloat();
		v_dmg_pitch = f.readFloat();
		v_dmg_time = f.readFloat();
		fall_time = f.readFloat();
		fall_value = f.readFloat();
		damage_alpha = f.readFloat();
		bonus_alpha = f.readFloat();

		damage_blend[0] = f.readFloat();
		damage_blend[1] = f.readFloat();
		damage_blend[2] = f.readFloat();

		v_angle[0] = f.readFloat();
		v_angle[1] = f.readFloat();
		v_angle[2] = f.readFloat();

		bobtime = f.readFloat();

		oldviewangles[0] = f.readFloat();
		oldviewangles[1] = f.readFloat();
		oldviewangles[2] = f.readFloat();

		oldvelocity[0] = f.readFloat();
		oldvelocity[1] = f.readFloat();
		oldvelocity[2] = f.readFloat();

		next_drown_time = f.readFloat();

		old_waterlevel = f.readInt();
		breather_sound = f.readInt();
		machinegun_shots = f.readInt();
		anim_end = f.readInt();
		anim_priority = f.readInt();
		anim_duck = f.readInt() != 0;
		anim_run = f.readInt() != 0;

		quad_framenum = f.readFloat();
		invincible_framenum = f.readFloat();
		breather_framenum = f.readFloat();
		enviro_framenum = f.readFloat();

		grenade_blew_up = f.readInt() != 0;
		grenade_time = f.readFloat();
		silencer_shots = f.readInt();
		weapon_sound = f.readInt();
		pickup_msg_time = f.readFloat();
		flood_locktill = f.readFloat();
		flood_when[0] = f.readFloat();
		flood_when[1] = f.readFloat();
		flood_when[2] = f.readFloat();
		flood_when[3] = f.readFloat();
		flood_when[4] = f.readFloat();
		flood_when[5] = f.readFloat();
		flood_when[6] = f.readFloat();
		flood_when[7] = f.readFloat();
		flood_when[8] = f.readFloat();
		flood_when[9] = f.readFloat();
		flood_whenhead = f.readInt();
		respawn_time = f.readFloat();
		chase_target = f.readEdictRef();
		update_chase = f.readInt() != 0;
		
		if (f.readInt() != 8765)
			System.err.println("game client load failed for num=" + index);
	}
	
	/** Writes a game_client_t (a player) to a file. */ 
	public void write(QuakeFile f) throws IOException
	{
		ps.write(f);

		f.writeInt(ping);

		pers.write(f);
		resp.write(f);

		old_pmove.write(f);

		f.writeInt(showscores?1:0);
		f.writeInt(showinventory?1:0);
		f.writeInt(showhelp?1:0);
		f.writeInt(showhelpicon?1:0);
		f.writeInt(ammo_index);

		f.writeInt(buttons);
		f.writeInt(oldbuttons);
		f.writeInt(latched_buttons);

		f.writeInt(weapon_thunk?1:0);
		f.writeItem(newweapon);
		

		f.writeInt(damage_armor);
		f.writeInt(damage_parmor);
		f.writeInt(damage_blood);
		f.writeInt(damage_knockback);

		f.writeFloat(damage_from[0]);
		f.writeFloat(damage_from[1]);
		f.writeFloat(damage_from[2]);

		f.writeFloat(killer_yaw);

		f.writeInt(weaponstate);

		f.writeFloat(kick_angles[0]);
		f.writeFloat(kick_angles[1]);
		f.writeFloat(kick_angles[2]);

		f.writeFloat(kick_origin[0]);
		f.writeFloat(kick_origin[1]);
		f.writeFloat(kick_origin[2]);

		f.writeFloat(v_dmg_roll);
		f.writeFloat(v_dmg_pitch);
		f.writeFloat(v_dmg_time);
		f.writeFloat(fall_time);
		f.writeFloat(fall_value);
		f.writeFloat(damage_alpha);
		f.writeFloat(bonus_alpha);

		f.writeFloat(damage_blend[0]);
		f.writeFloat(damage_blend[1]);
		f.writeFloat(damage_blend[2]);

		f.writeFloat(v_angle[0]);
		f.writeFloat(v_angle[1]);
		f.writeFloat(v_angle[2]);

		f.writeFloat(bobtime);

		f.writeFloat(oldviewangles[0]);
		f.writeFloat(oldviewangles[1]);
		f.writeFloat(oldviewangles[2]);

		f.writeFloat(oldvelocity[0]);
		f.writeFloat(oldvelocity[1]);
		f.writeFloat(oldvelocity[2]);

		f.writeFloat(next_drown_time);

		f.writeInt(old_waterlevel);
		f.writeInt(breather_sound);
		f.writeInt(machinegun_shots);
		f.writeInt(anim_end);
		f.writeInt(anim_priority);
		f.writeInt(anim_duck?1:0);
		f.writeInt(anim_run?1:0);

		f.writeFloat(quad_framenum);
		f.writeFloat(invincible_framenum);
		f.writeFloat(breather_framenum);
		f.writeFloat(enviro_framenum);

		f.writeInt(grenade_blew_up?1:0);
		f.writeFloat(grenade_time);
		f.writeInt(silencer_shots);
		f.writeInt(weapon_sound);
		f.writeFloat(pickup_msg_time);
		f.writeFloat(flood_locktill);
		f.writeFloat(flood_when[0]);
		f.writeFloat(flood_when[1]);
		f.writeFloat(flood_when[2]);
		f.writeFloat(flood_when[3]);
		f.writeFloat(flood_when[4]);
		f.writeFloat(flood_when[5]);
		f.writeFloat(flood_when[6]);
		f.writeFloat(flood_when[7]);
		f.writeFloat(flood_when[8]);
		f.writeFloat(flood_when[9]);
		f.writeInt(flood_whenhead);
		f.writeFloat(respawn_time);
		f.writeEdictRef(chase_target);
		f.writeInt(update_chase?1:0);
		
		f.writeInt(8765);
	}
}