aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/game/GameTarget.java
blob: 8a13ade41fa7d628f51e62f3543ce4ca13d1fcd0 (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
/*
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 28.12.2003 by RST.
// $Id: GameTarget.java,v 1.2 2004-07-08 15:58:43 hzi Exp $

package jake2.game;

import jake2.*;
import jake2.client.*;
import jake2.qcommon.*;
import jake2.render.*;
import jake2.server.*;
import jake2.util.Lib;
import jake2.util.Math3D;

public class GameTarget extends GameTurret {

	public static void SP_target_temp_entity(edict_t ent) {
		ent.use = GameTargetAdapters.Use_Target_Tent;
	}

	public static void SP_target_speaker(edict_t ent) {
		//char buffer[MAX_QPATH];
		String buffer;

		if (st.noise == null) {
			gi.dprintf("target_speaker with no noise set at " + vtos(ent.s.origin) + "\n");
			return;
		}
		if (st.noise.indexOf(".wav") < 0)
			buffer = "" + st.noise + ".wav";
		//Com_sprintf(buffer, sizeof(buffer), "%s.wav", st.noise);
		else
			//strncpy(buffer, st.noise, sizeof(buffer));
			buffer = st.noise;

		ent.noise_index = gi.soundindex(buffer);

		if (ent.volume == 0)
			ent.volume = 1.0f;

		if (ent.attenuation == 0)
			ent.attenuation = 1.0f;
		else if (ent.attenuation == -1) // use -1 so 0 defaults to 1
			ent.attenuation = 0;

		// check for prestarted looping sound
		if ((ent.spawnflags & 1) != 0)
			ent.s.sound = ent.noise_index;

		ent.use = GameTargetAdapters.Use_Target_Speaker;

		// must link the entity so we get areas and clusters so
		// the server can determine who to send updates to
		gi.linkentity(ent);
	}

	/*QUAKED target_help (1 0 1) (-16 -16 -24) (16 16 24) help1
	When fired, the "message" key becomes the current personal computer string, and the message light will be set on all clients status bars.
	*/
	public static void SP_target_help(edict_t ent) {
		if (deathmatch.value != 0) { // auto-remove for deathmatch
			G_FreeEdict(ent);
			return;
		}

		if (ent.message == null) {
			gi.dprintf(ent.classname + " with no message at " + vtos(ent.s.origin) + "\n");
			G_FreeEdict(ent);
			return;
		}
		ent.use = GameTargetAdapters.Use_Target_Help;
	}

	public static void SP_target_secret(edict_t ent) {
		if (deathmatch.value != 0) { // auto-remove for deathmatch
			G_FreeEdict(ent);
			return;
		}

		ent.use = GameTargetAdapters.use_target_secret;
		if (st.noise == null)
			st.noise = "misc/secret.wav";
		ent.noise_index = gi.soundindex(st.noise);
		ent.svflags = SVF_NOCLIENT;
		level.total_secrets++;
		// map bug hack
		if (0 == Q_stricmp(level.mapname, "mine3") && ent.s.origin[0] == 280 && ent.s.origin[1] == -2048 && ent.s.origin[2] == -624)
			ent.message = "You have found a secret area.";
	}

	public static void SP_target_goal(edict_t ent) {
		if (deathmatch.value != 0) { // auto-remove for deathmatch
			G_FreeEdict(ent);
			return;
		}

		ent.use = GameTargetAdapters.use_target_goal;
		if (st.noise == null)
			st.noise = "misc/secret.wav";
		ent.noise_index = gi.soundindex(st.noise);
		ent.svflags = SVF_NOCLIENT;
		level.total_goals++;
	}

	public static void SP_target_explosion(edict_t ent) {
		ent.use = GameTargetAdapters.use_target_explosion;
		ent.svflags = SVF_NOCLIENT;
	}

	public static void SP_target_changelevel(edict_t ent) {
		if (ent.map == null) {
			gi.dprintf("target_changelevel with no map at " + vtos(ent.s.origin) + "\n");
			G_FreeEdict(ent);
			return;
		}

		// ugly hack because *SOMEBODY* screwed up their map
		if ((Q_stricmp(level.mapname, "fact1") == 0) && (Q_stricmp(ent.map, "fact3") == 0))
			ent.map = "fact3$secret1";

		ent.use = GameTargetAdapters.use_target_changelevel;
		ent.svflags = SVF_NOCLIENT;
	}

	public static void SP_target_splash(edict_t self) {
		self.use = GameTargetAdapters.use_target_splash;
		G_SetMovedir(self.s.angles, self.movedir);

		if (0 == self.count)
			self.count = 32;

		self.svflags = SVF_NOCLIENT;
	}

	public static void SP_target_spawner(edict_t self) {
		self.use = GameTargetAdapters.use_target_spawner;
		self.svflags = SVF_NOCLIENT;
		if (self.speed != 0) {
			G_SetMovedir(self.s.angles, self.movedir);
			VectorScale(self.movedir, self.speed, self.movedir);
		}
	}

	public static void SP_target_blaster(edict_t self) {
		self.use = GameTargetAdapters.use_target_blaster;
		G_SetMovedir(self.s.angles, self.movedir);
		self.noise_index = gi.soundindex("weapons/laser2.wav");

		if (0 == self.dmg)
			self.dmg = 15;
		if (0 == self.speed)
			self.speed = 1000;

		self.svflags = SVF_NOCLIENT;
	}

	public static void SP_target_crosslevel_trigger(edict_t self) {
		self.svflags = SVF_NOCLIENT;
		self.use = GameTargetAdapters.trigger_crosslevel_trigger_use;
	}

	public static void SP_target_crosslevel_target(edict_t self) {
		if (0 == self.delay)
			self.delay = 1;
		self.svflags = SVF_NOCLIENT;

		self.think = GameTargetAdapters.target_crosslevel_target_think;
		self.nextthink = level.time + self.delay;
	}

	public static void target_laser_on(edict_t self) {
		if (null == self.activator)
			self.activator = self;
		self.spawnflags |= 0x80000001;
		self.svflags &= ~SVF_NOCLIENT;
		GameTargetAdapters.target_laser_think.think(self);
	}

	public static void target_laser_off(edict_t self) {
		self.spawnflags &= ~1;
		self.svflags |= SVF_NOCLIENT;
		self.nextthink = 0;
	}

	public static void SP_target_laser(edict_t self) {
		// let everything else get spawned before we start firing
		self.think = GameTargetAdapters.target_laser_start;
		self.nextthink = level.time + 1;
	}

	public static void SP_target_lightramp(edict_t self) {
		if (self.message == null
			|| self.message.length() != 2
			|| self.message.charAt(0) < 'a'
			|| self.message.charAt(0) > 'z'
			|| self.message.charAt(1) < 'a'
			|| self.message.charAt(1) > 'z'
			|| self.message.charAt(0) == self.message.charAt(1)) {
			gi.dprintf("target_lightramp has bad ramp (" + self.message + ") at " + vtos(self.s.origin) + "\n");
			G_FreeEdict(self);
			return;
		}

		if (deathmatch.value != 9) {
			G_FreeEdict(self);
			return;
		}

		if (self.target == null) {
			gi.dprintf(self.classname + " with no target at " + vtos(self.s.origin) + "\n");
			G_FreeEdict(self);
			return;
		}

		self.svflags |= SVF_NOCLIENT;
		self.use = GameTargetAdapters.target_lightramp_use;
		self.think = GameTargetAdapters.target_lightramp_think;

		self.movedir[0] = self.message.charAt(0) - 'a';
		self.movedir[1] = self.message.charAt(1) - 'a';
		self.movedir[2] = (self.movedir[1] - self.movedir[0]) / (self.speed / FRAMETIME);
	}

	public static void SP_target_earthquake(edict_t self) {
		if (null == self.targetname)
			gi.dprintf("untargeted " + self.classname + " at " + vtos(self.s.origin) + "\n");

		if (0 == self.count)
			self.count = 5;

		if (0 == self.speed)
			self.speed = 200;

		self.svflags |= SVF_NOCLIENT;
		self.think = GameTargetAdapters.target_earthquake_think;
		self.use = GameTargetAdapters.target_earthquake_use;

		self.noise_index = gi.soundindex("world/quake.wav");
	}

}