1 /*
2 ==============================================================================
3 
4 BERSERK
5 
6 ==============================================================================
7 */
8 
9 #include "g_local.h"
10 #include "m_berserk.h"
11 
12 
13 static int sound_pain;
14 static int sound_die;
15 static int sound_idle;
16 static int sound_punch;
17 static int sound_sight;
18 static int sound_search;
19 
berserk_sight(edict_t * self,edict_t * other)20 void berserk_sight (edict_t *self, edict_t *other)
21 {
22 	gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
23 }
24 
berserk_search(edict_t * self)25 void berserk_search (edict_t *self)
26 {
27 	gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
28 }
29 
30 
31 void berserk_fidget (edict_t *self);
32 mframe_t berserk_frames_stand [] =
33 {
34 	ai_stand, 0, berserk_fidget,
35 	ai_stand, 0, NULL,
36 	ai_stand, 0, NULL,
37 	ai_stand, 0, NULL,
38 	ai_stand, 0, NULL
39 };
40 mmove_t berserk_move_stand = {FRAME_stand1, FRAME_stand5, berserk_frames_stand, NULL};
41 
berserk_stand(edict_t * self)42 void berserk_stand (edict_t *self)
43 {
44 	self->monsterinfo.currentmove = &berserk_move_stand;
45 }
46 
47 mframe_t berserk_frames_stand_fidget [] =
48 {
49 	ai_stand, 0, NULL,
50 	ai_stand, 0, NULL,
51 	ai_stand, 0, NULL,
52 	ai_stand, 0, NULL,
53 	ai_stand, 0, NULL,
54 	ai_stand, 0, NULL,
55 	ai_stand, 0, NULL,
56 	ai_stand, 0, NULL,
57 	ai_stand, 0, NULL,
58 	ai_stand, 0, NULL,
59 	ai_stand, 0, NULL,
60 	ai_stand, 0, NULL,
61 	ai_stand, 0, NULL,
62 	ai_stand, 0, NULL,
63 	ai_stand, 0, NULL,
64 	ai_stand, 0, NULL,
65 	ai_stand, 0, NULL,
66 	ai_stand, 0, NULL,
67 	ai_stand, 0, NULL,
68 	ai_stand, 0, NULL
69 };
70 mmove_t berserk_move_stand_fidget = {FRAME_standb1, FRAME_standb20, berserk_frames_stand_fidget, berserk_stand};
71 
berserk_fidget(edict_t * self)72 void berserk_fidget (edict_t *self)
73 {
74 	if (self->monsterinfo.aiflags & AI_STAND_GROUND)
75 		return;
76 	if (random() > 0.15)
77 		return;
78 
79 	self->monsterinfo.currentmove = &berserk_move_stand_fidget;
80 	gi.sound (self, CHAN_WEAPON, sound_idle, 1, ATTN_IDLE, 0);
81 }
82 
83 
84 mframe_t berserk_frames_walk [] =
85 {
86 	ai_walk, 9.1, NULL,
87 	ai_walk, 6.3, NULL,
88 	ai_walk, 4.9, NULL,
89 	ai_walk, 6.7, NULL,
90 	ai_walk, 6.0, NULL,
91 	ai_walk, 8.2, NULL,
92 	ai_walk, 7.2, NULL,
93 	ai_walk, 6.1, NULL,
94 	ai_walk, 4.9, NULL,
95 	ai_walk, 4.7, NULL,
96 	ai_walk, 4.7, NULL,
97 	ai_walk, 4.8, NULL
98 };
99 mmove_t berserk_move_walk = {FRAME_walkc1, FRAME_walkc11, berserk_frames_walk, NULL};
100 
berserk_walk(edict_t * self)101 void berserk_walk (edict_t *self)
102 {
103 	self->monsterinfo.currentmove = &berserk_move_walk;
104 }
105 
106 /*
107 
108   *****************************
109   SKIPPED THIS FOR NOW!
110   *****************************
111 
112    Running -> Arm raised in air
113 
114 void()	berserk_runb1	=[	$r_att1 ,	berserk_runb2	] {ai_run(21);};
115 void()	berserk_runb2	=[	$r_att2 ,	berserk_runb3	] {ai_run(11);};
116 void()	berserk_runb3	=[	$r_att3 ,	berserk_runb4	] {ai_run(21);};
117 void()	berserk_runb4	=[	$r_att4 ,	berserk_runb5	] {ai_run(25);};
118 void()	berserk_runb5	=[	$r_att5 ,	berserk_runb6	] {ai_run(18);};
119 void()	berserk_runb6	=[	$r_att6 ,	berserk_runb7	] {ai_run(19);};
120 // running with arm in air : start loop
121 void()	berserk_runb7	=[	$r_att7 ,	berserk_runb8	] {ai_run(21);};
122 void()	berserk_runb8	=[	$r_att8 ,	berserk_runb9	] {ai_run(11);};
123 void()	berserk_runb9	=[	$r_att9 ,	berserk_runb10	] {ai_run(21);};
124 void()	berserk_runb10	=[	$r_att10 ,	berserk_runb11	] {ai_run(25);};
125 void()	berserk_runb11	=[	$r_att11 ,	berserk_runb12	] {ai_run(18);};
126 void()	berserk_runb12	=[	$r_att12 ,	berserk_runb7	] {ai_run(19);};
127 // running with arm in air : end loop
128 */
129 
130 
131 mframe_t berserk_frames_run1 [] =
132 {
133 	ai_run, 21, NULL,
134 	ai_run, 11, NULL,
135 	ai_run, 21, NULL,
136 	// PMM .. from NULL
137 	ai_run, 25, monster_done_dodge,
138 	ai_run, 18, NULL,
139 	ai_run, 19, NULL
140 };
141 mmove_t berserk_move_run1 = {FRAME_run1, FRAME_run6, berserk_frames_run1, NULL};
142 
berserk_run(edict_t * self)143 void berserk_run (edict_t *self)
144 {
145 	monster_done_dodge (self);
146 	if (self->monsterinfo.aiflags & AI_STAND_GROUND)
147 		self->monsterinfo.currentmove = &berserk_move_stand;
148 	else
149 		self->monsterinfo.currentmove = &berserk_move_run1;
150 }
151 
152 
berserk_attack_spike(edict_t * self)153 void berserk_attack_spike (edict_t *self)
154 {
155 	static	vec3_t	aim = {MELEE_DISTANCE, 0, -24};
156 	fire_hit (self, aim, (15 + (rand() % 6)), 400);		//	Faster attack -- upwards and backwards
157 }
158 
159 
berserk_swing(edict_t * self)160 void berserk_swing (edict_t *self)
161 {
162 	gi.sound (self, CHAN_WEAPON, sound_punch, 1, ATTN_NORM, 0);
163 }
164 
165 mframe_t berserk_frames_attack_spike [] =
166 {
167 		ai_charge, 0, NULL,
168 		ai_charge, 0, NULL,
169 		ai_charge, 0, berserk_swing,
170 		ai_charge, 0, berserk_attack_spike,
171 		ai_charge, 0, NULL,
172 		ai_charge, 0, NULL,
173 		ai_charge, 0, NULL,
174 		ai_charge, 0, NULL
175 };
176 mmove_t berserk_move_attack_spike = {FRAME_att_c1, FRAME_att_c8, berserk_frames_attack_spike, berserk_run};
177 
178 
berserk_attack_club(edict_t * self)179 void berserk_attack_club (edict_t *self)
180 {
181 	vec3_t	aim;
182 
183 	VectorSet (aim, MELEE_DISTANCE, self->mins[0], -4);
184 	fire_hit (self, aim, (5 + (rand() % 6)), 400);		// Slower attack
185 }
186 
187 mframe_t berserk_frames_attack_club [] =
188 {
189 	ai_charge, 0, NULL,
190 	ai_charge, 0, NULL,
191 	ai_charge, 0, NULL,
192 	ai_charge, 0, NULL,
193 	ai_charge, 0, berserk_swing,
194 	ai_charge, 0, NULL,
195 	ai_charge, 0, NULL,
196 	ai_charge, 0, NULL,
197 	ai_charge, 0, berserk_attack_club,
198 	ai_charge, 0, NULL,
199 	ai_charge, 0, NULL,
200 	ai_charge, 0, NULL
201 };
202 mmove_t berserk_move_attack_club = {FRAME_att_c9, FRAME_att_c20, berserk_frames_attack_club, berserk_run};
203 
204 
berserk_strike(edict_t * self)205 void berserk_strike (edict_t *self)
206 {
207 	//FIXME play impact sound
208 }
209 
210 
211 mframe_t berserk_frames_attack_strike [] =
212 {
213 	ai_move, 0, NULL,
214 	ai_move, 0, NULL,
215 	ai_move, 0, NULL,
216 	ai_move, 0, berserk_swing,
217 	ai_move, 0, NULL,
218 	ai_move, 0, NULL,
219 	ai_move, 0, NULL,
220 	ai_move, 0, berserk_strike,
221 	ai_move, 0, NULL,
222 	ai_move, 0, NULL,
223 	ai_move, 0, NULL,
224 	ai_move, 0, NULL,
225 	ai_move, 9.7, NULL,
226 	ai_move, 13.6, NULL
227 };
228 
229 mmove_t berserk_move_attack_strike = {FRAME_att_c21, FRAME_att_c34, berserk_frames_attack_strike, berserk_run};
230 
231 
berserk_melee(edict_t * self)232 void berserk_melee (edict_t *self)
233 {
234 	monster_done_dodge (self);
235 
236 	if ((rand() % 2) == 0)
237 		self->monsterinfo.currentmove = &berserk_move_attack_spike;
238 	else
239 		self->monsterinfo.currentmove = &berserk_move_attack_club;
240 }
241 
242 
243 /*
244 void() 	berserk_atke1	=[	$r_attb1,	berserk_atke2	] {ai_run(9);};
245 void() 	berserk_atke2	=[	$r_attb2,	berserk_atke3	] {ai_run(6);};
246 void() 	berserk_atke3	=[	$r_attb3,	berserk_atke4	] {ai_run(18.4);};
247 void() 	berserk_atke4	=[	$r_attb4,	berserk_atke5	] {ai_run(25);};
248 void() 	berserk_atke5	=[	$r_attb5,	berserk_atke6	] {ai_run(14);};
249 void() 	berserk_atke6	=[	$r_attb6,	berserk_atke7	] {ai_run(20);};
250 void() 	berserk_atke7	=[	$r_attb7,	berserk_atke8	] {ai_run(8.5);};
251 void() 	berserk_atke8	=[	$r_attb8,	berserk_atke9	] {ai_run(3);};
252 void() 	berserk_atke9	=[	$r_attb9,	berserk_atke10	] {ai_run(17.5);};
253 void() 	berserk_atke10	=[	$r_attb10,	berserk_atke11	] {ai_run(17);};
254 void() 	berserk_atke11	=[	$r_attb11,	berserk_atke12	] {ai_run(9);};
255 void() 	berserk_atke12	=[	$r_attb12,	berserk_atke13	] {ai_run(25);};
256 void() 	berserk_atke13	=[	$r_attb13,	berserk_atke14	] {ai_run(3.7);};
257 void() 	berserk_atke14	=[	$r_attb14,	berserk_atke15	] {ai_run(2.6);};
258 void() 	berserk_atke15	=[	$r_attb15,	berserk_atke16	] {ai_run(19);};
259 void() 	berserk_atke16	=[	$r_attb16,	berserk_atke17	] {ai_run(25);};
260 void() 	berserk_atke17	=[	$r_attb17,	berserk_atke18	] {ai_run(19.6);};
261 void() 	berserk_atke18	=[	$r_attb18,	berserk_run1	] {ai_run(7.8);};
262 */
263 
264 
265 mframe_t berserk_frames_pain1 [] =
266 {
267 	ai_move, 0, NULL,
268 	ai_move, 0, NULL,
269 	ai_move, 0, NULL,
270 	ai_move, 0, NULL
271 };
272 mmove_t berserk_move_pain1 = {FRAME_painc1, FRAME_painc4, berserk_frames_pain1, berserk_run};
273 
274 
275 mframe_t berserk_frames_pain2 [] =
276 {
277 	ai_move, 0, NULL,
278 	ai_move, 0, NULL,
279 	ai_move, 0, NULL,
280 	ai_move, 0, NULL,
281 	ai_move, 0, NULL,
282 	ai_move, 0, NULL,
283 	ai_move, 0, NULL,
284 	ai_move, 0, NULL,
285 	ai_move, 0, NULL,
286 	ai_move, 0, NULL,
287 	ai_move, 0, NULL,
288 	ai_move, 0, NULL,
289 	ai_move, 0, NULL,
290 	ai_move, 0, NULL,
291 	ai_move, 0, NULL,
292 	ai_move, 0, NULL,
293 	ai_move, 0, NULL,
294 	ai_move, 0, NULL,
295 	ai_move, 0, NULL,
296 	ai_move, 0, NULL
297 };
298 mmove_t berserk_move_pain2 = {FRAME_painb1, FRAME_painb20, berserk_frames_pain2, berserk_run};
299 
berserk_pain(edict_t * self,edict_t * other,float kick,int damage)300 void berserk_pain (edict_t *self, edict_t *other, float kick, int damage)
301 {
302 	if (self->health < (self->max_health / 2))
303 		self->s.skinnum = 1;
304 
305 	if (level.time < self->pain_debounce_time)
306 		return;
307 
308 	self->pain_debounce_time = level.time + 3;
309 	gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
310 
311 	if (skill->value == 3)
312 		return;		// no pain anims in nightmare
313 
314 	monster_done_dodge (self);
315 
316 	if ((damage < 20) || (random() < 0.5))
317 		self->monsterinfo.currentmove = &berserk_move_pain1;
318 	else
319 		self->monsterinfo.currentmove = &berserk_move_pain2;
320 }
321 
322 
berserk_dead(edict_t * self)323 void berserk_dead (edict_t *self)
324 {
325 	VectorSet (self->mins, -16, -16, -24);
326 	VectorSet (self->maxs, 16, 16, -8);
327 	self->movetype = MOVETYPE_TOSS;
328 	self->svflags |= SVF_DEADMONSTER;
329 	self->nextthink = 0;
330 	gi.linkentity (self);
331 }
332 
333 
334 mframe_t berserk_frames_death1 [] =
335 {
336 	ai_move, 0, NULL,
337 	ai_move, 0, NULL,
338 	ai_move, 0, NULL,
339 	ai_move, 0, NULL,
340 	ai_move, 0, NULL,
341 	ai_move, 0, NULL,
342 	ai_move, 0, NULL,
343 	ai_move, 0, NULL,
344 	ai_move, 0, NULL,
345 	ai_move, 0, NULL,
346 	ai_move, 0, NULL,
347 	ai_move, 0, NULL,
348 	ai_move, 0, NULL
349 
350 };
351 mmove_t berserk_move_death1 = {FRAME_death1, FRAME_death13, berserk_frames_death1, berserk_dead};
352 
353 
354 mframe_t berserk_frames_death2 [] =
355 {
356 	ai_move, 0, NULL,
357 	ai_move, 0, NULL,
358 	ai_move, 0, NULL,
359 	ai_move, 0, NULL,
360 	ai_move, 0, NULL,
361 	ai_move, 0, NULL,
362 	ai_move, 0, NULL,
363 	ai_move, 0, NULL
364 };
365 mmove_t berserk_move_death2 = {FRAME_deathc1, FRAME_deathc8, berserk_frames_death2, berserk_dead};
366 
367 
berserk_die(edict_t * self,edict_t * inflictor,edict_t * attacker,int damage,vec3_t point)368 void berserk_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
369 {
370 	int		n;
371 
372 	if (self->health <= self->gib_health)
373 	{
374 		gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
375 		for (n= 0; n < 2; n++)
376 			ThrowGib (self, "models/objects/gibs/bone/tris.md2", damage, GIB_ORGANIC);
377 		for (n= 0; n < 4; n++)
378 			ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
379 		ThrowHead (self, "models/objects/gibs/head2/tris.md2", damage, GIB_ORGANIC);
380 		self->deadflag = DEAD_DEAD;
381 		return;
382 	}
383 
384 	if (self->deadflag == DEAD_DEAD)
385 		return;
386 
387 	gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
388 	self->deadflag = DEAD_DEAD;
389 	self->takedamage = DAMAGE_YES;
390 
391 	if (damage >= 50)
392 		self->monsterinfo.currentmove = &berserk_move_death1;
393 	else
394 		self->monsterinfo.currentmove = &berserk_move_death2;
395 }
396 
397 //===========
398 //PGM
berserk_jump_now(edict_t * self)399 void berserk_jump_now (edict_t *self)
400 {
401 	vec3_t	forward,up;
402 
403 	monster_jump_start (self);
404 
405 	AngleVectors (self->s.angles, forward, NULL, up);
406 	VectorMA(self->velocity, 100, forward, self->velocity);
407 	VectorMA(self->velocity, 300, up, self->velocity);
408 }
409 
berserk_jump2_now(edict_t * self)410 void berserk_jump2_now (edict_t *self)
411 {
412 	vec3_t	forward,up;
413 
414 	monster_jump_start (self);
415 
416 	AngleVectors (self->s.angles, forward, NULL, up);
417 	VectorMA(self->velocity, 150, forward, self->velocity);
418 	VectorMA(self->velocity, 400, up, self->velocity);
419 }
420 
berserk_jump_wait_land(edict_t * self)421 void berserk_jump_wait_land (edict_t *self)
422 {
423 	if(self->groundentity == NULL)
424 	{
425 		self->monsterinfo.nextframe = self->s.frame;
426 
427 		if(monster_jump_finished (self))
428 			self->monsterinfo.nextframe = self->s.frame + 1;
429 	}
430 	else
431 		self->monsterinfo.nextframe = self->s.frame + 1;
432 }
433 
434 mframe_t berserk_frames_jump [] =
435 {
436 	ai_move, 0, NULL,
437 	ai_move, 0, NULL,
438 	ai_move, 0, NULL,
439 	ai_move, 0, berserk_jump_now,
440 	ai_move, 0, NULL,
441 	ai_move, 0, NULL,
442 	ai_move, 0, berserk_jump_wait_land,
443 	ai_move, 0, NULL,
444 	ai_move, 0, NULL
445 };
446 mmove_t berserk_move_jump = { FRAME_jump1, FRAME_jump9, berserk_frames_jump, berserk_run };
447 
448 mframe_t berserk_frames_jump2 [] =
449 {
450 	ai_move, -8, NULL,
451 	ai_move, -4, NULL,
452 	ai_move, -4, NULL,
453 	ai_move, 0, berserk_jump_now,
454 	ai_move, 0, NULL,
455 	ai_move, 0, NULL,
456 	ai_move, 0, berserk_jump_wait_land,
457 	ai_move, 0, NULL,
458 	ai_move, 0, NULL
459 };
460 mmove_t berserk_move_jump2 = { FRAME_jump1, FRAME_jump9, berserk_frames_jump2, berserk_run };
461 
berserk_jump(edict_t * self)462 void berserk_jump (edict_t *self)
463 {
464 	if(!self->enemy)
465 		return;
466 
467 	monster_done_dodge (self);
468 
469 	if(self->enemy->s.origin[2] > self->s.origin[2])
470 		self->monsterinfo.currentmove = &berserk_move_jump2;
471 	else
472 		self->monsterinfo.currentmove = &berserk_move_jump;
473 }
474 
berserk_blocked(edict_t * self,float dist)475 qboolean berserk_blocked (edict_t *self, float dist)
476 {
477 	if(blocked_checkjump (self, dist, 256, 40))
478 	{
479 		berserk_jump(self);
480 		return true;
481 	}
482 
483 	if(blocked_checkplat (self, dist))
484 		return true;
485 
486 	return false;
487 }
488 //PGM
489 //===========
490 
berserk_sidestep(edict_t * self)491 void berserk_sidestep (edict_t *self)
492 {
493 	// if we're jumping, don't dodge
494 	if ((self->monsterinfo.currentmove == &berserk_move_jump) ||
495 		(self->monsterinfo.currentmove == &berserk_move_jump2))
496 	{
497 		return;
498 	}
499 
500 	// don't check for attack; the eta should suffice for melee monsters
501 
502 	if (self->monsterinfo.currentmove != &berserk_move_run1)
503 		self->monsterinfo.currentmove = &berserk_move_run1;
504 }
505 
506 
507 /*QUAKED monster_berserk (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
508 */
SP_monster_berserk(edict_t * self)509 void SP_monster_berserk (edict_t *self)
510 {
511 	if (deathmatch->value)
512 	{
513 		G_FreeEdict (self);
514 		return;
515 	}
516 
517 	// pre-caches
518 	sound_pain  = gi.soundindex ("berserk/berpain2.wav");
519 	sound_die   = gi.soundindex ("berserk/berdeth2.wav");
520 	sound_idle  = gi.soundindex ("berserk/beridle1.wav");
521 	sound_punch = gi.soundindex ("berserk/attack.wav");
522 	sound_search = gi.soundindex ("berserk/bersrch1.wav");
523 	sound_sight = gi.soundindex ("berserk/sight.wav");
524 
525 	self->s.modelindex = gi.modelindex("models/monsters/berserk/tris.md2");
526 	VectorSet (self->mins, -16, -16, -24);
527 	VectorSet (self->maxs, 16, 16, 32);
528 	self->movetype = MOVETYPE_STEP;
529 	self->solid = SOLID_BBOX;
530 
531 	self->health = 240;
532 	self->gib_health = -60;
533 	self->mass = 250;
534 
535 	self->pain = berserk_pain;
536 	self->die = berserk_die;
537 
538 	self->monsterinfo.stand = berserk_stand;
539 	self->monsterinfo.walk = berserk_walk;
540 	self->monsterinfo.run = berserk_run;
541 	// pmm
542 //	self->monsterinfo.dodge = NULL;
543 	self->monsterinfo.dodge = M_MonsterDodge;
544 	self->monsterinfo.sidestep = berserk_sidestep;
545 	// pmm
546 	self->monsterinfo.attack = NULL;
547 	self->monsterinfo.melee = berserk_melee;
548 	self->monsterinfo.sight = berserk_sight;
549 	self->monsterinfo.search = berserk_search;
550 	self->monsterinfo.blocked = berserk_blocked;		//PGM
551 
552 	self->monsterinfo.currentmove = &berserk_move_stand;
553 	self->monsterinfo.scale = MODEL_SCALE;
554 
555 	gi.linkentity (self);
556 
557 	walkmonster_start (self);
558 }
559