-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkots_abilities.c
2263 lines (1923 loc) · 61.4 KB
/
kots_abilities.c
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "kots_abilities.h"
#include "kots_items.h"
#include "kots_runes.h"
#include "kots_utils.h"
#include "kots_weapon.h"
#include "kots_pickups.h"
#include "kots_pweapon.h"
#include "kots_hook.h"
#include "kots_weapondamage.h"
typedef struct ammotypes_s
{
char *ammotype;
int weapons[2];
int weaponcount;
} ammotypes_t;
const int AmmoTypeLength = 6;
ammotypes_t ammo_types[] = {
{"Shells", {WEAP_SHOTGUN, WEAP_SUPERSHOTGUN}, 2},
{"Bullets", {WEAP_MACHINEGUN, WEAP_CHAINGUN}, 2},
{"Grenades", {WEAP_GRENADES, WEAP_GRENADELAUNCHER}, 2},
{"Rockets", {WEAP_ROCKETLAUNCHER}, 1},
{"Cells", {WEAP_HYPERBLASTER, WEAP_BFG}, 2},
{"Slugs", {WEAP_RAILGUN}, 1}
};
void Kots_CheckFastWeaponSwitch(edict_t *ent)
{
if (ent->character->cur_dexterity >= 1)
{
if (ent->client->weaponstate != WEAPON_FIRING, WEAPON_READY, WEAPON_ACTIVATING)
ChangeWeapon(ent);
}
}
void Kots_CharacterDoDamageBasedSkills(edict_t *targ, edict_t *attacker, int health, int total, int realtotal)
{
if (targ != attacker)
{
//keep the means of death it may change mid frame based on stuff like empathy
int modBefore = meansOfDeath;
//don't do this stuff when the attacker is dead
if (attacker->health > 0)
{
//Since monsters can do a ton of damage they should only vamp what is really done
if (!attacker->client)
{
if (health > targ->health)
Kots_CharacterCheckVampire(targ, attacker, targ->health);
else
Kots_CharacterCheckVampire(targ, attacker, health);
}
else
Kots_CharacterCheckVampire(targ, attacker, health);
Kots_CharacterCheckAmmoSteal(targ, attacker, total);
Kots_CharacterCheckQuadRage(targ, attacker, realtotal);
//Since monsters do a ton of damage don't empathy more damage than was really done
if (!attacker->client)
Kots_CharacterCheckEmpathyDamage(targ, attacker, realtotal);
else
Kots_CharacterCheckEmpathyDamage(targ, attacker, total);
//SWB - moved here because this needs to take place
//after monster bonuses and other things that cause invulnerability to damage
if (targ->character->bideon && targ->character->bidestart > level.time - 10)
targ->character->bidedmg += total / 2; // 50%
}
Kots_CharacterCheckKnock(targ, attacker, total);
Kots_CharacterCheckPoison(targ, attacker, total);
Kots_CheckArmorKnock(targ, attacker, total);
//restore means of death in case it changed;
meansOfDeath = modBefore;
}
}
void Kots_CharacterFly(edict_t *ent)
{
if (ent->character->is_loggedin)
{
if (ent->character->cur_wisdom < 3)
gi.cprintf(ent, PRINT_HIGH, "You do not have the ability to fly.\n");
else if (ent->character->cubes < 1)
gi.cprintf(ent, PRINT_HIGH, "You do not have enough cubes.\n");
else if (ent->character->next_empdone > level.time)
gi.cprintf(ent, PRINT_HIGH, "You were hit by an EMP Shockwave and this ability is currently disabled!\n"); //hit by emp shockwave can't fly
else
{
if (!ent->character->is_flying)
{
ent->character->is_flying = true;
//if our next cube usage will not be immediately then use a cube now
if (ent->character->next_fast_regen >= level.time + 0.1)
ent->character->cubes -= 1;
}
else
ent->character->is_flying = false;
}
}
}
void Kots_CharacterLand(edict_t *ent)
{
ent->character->is_flying = false;
}
void Kots_CharacterHighJumpToggle(edict_t *ent, char *value)
{
if (Q_stricmp(value, "on") == 0)
ent->character->using_highjump = true;
else if (Q_stricmp(value, "off") == 0)
ent->character->using_highjump = false;
else if (!ent->character->using_highjump)
ent->character->using_highjump = true;
else
ent->character->using_highjump = false;
if (ent->character->using_highjump)
gi.cprintf(ent, PRINT_HIGH, "KOTS Jump is enabled.\n");
else
gi.cprintf(ent, PRINT_HIGH, "KOTS Jump is disabled.\n");
}
void Kots_CharacterCheckDoubleJump(edict_t *ent, pmove_t *pm)
{
if (pm->groundentity != NULL || pm->waterlevel >= 2)
{
ent->character->canDoubleJump = true;
return;
}
else if (!ent->character->canDoubleJump)
return;
//no double jumps from anywhere in water
if (pm->waterlevel)
return;
if (ent->character->cur_strength < 2)
return;
if (!ent->character->using_highjump)
return;
if (pm->cmd.upmove < 10)
return;
// must wait for jump to be released
if (pm->s.pm_flags & PMF_JUMP_HELD)
return;
if (pm->s.pm_type == PM_DEAD)
return;
if (ent->client->pers.spectator)
return;
ent->character->canDoubleJump = false;
pm->s.pm_flags |= PMF_JUMP_HELD;
pm->s.velocity[2] += 270 * 8;
if (pm->s.velocity[2] < 270 * 8)
pm->s.velocity[2] = 270 * 8;
//keep us from taking fall damage
VectorClear(ent->client->oldvelocity);
if (ent->character->cur_dexterity < 2)
{
gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
PlayerNoise(ent, ent->s.origin, PNOISE_SELF);
}
}
void Kots_CharacterCheckFly(edict_t *ent, pmove_t *pm)
{
if (ent->character->is_flying)
{
//must meet the minimum velocity to get up off the ground
if (ent->groundentity)
{
//ent->groundentity = NULL;
pm->s.velocity[2] = 270 * 6;
}
else //once in the air move at half jump velocity
{
pm->s.velocity[2] += 270 * 5; // Aldarn - Modified so you move upwards slightly more
if (pm->s.velocity[2] > 270 * 5)
pm->s.velocity[2] = 270 * 5;
}
//keep us from taking fall damage
VectorClear(ent->client->oldvelocity);
}
}
void Kots_CharacterFlyUseCubes(edict_t *ent)
{
if (ent->character->is_flying)
{
if (ent->character->cubes < 1)
ent->character->is_flying = false;
else
ent->character->cubes -= 1;
}
}
void Kots_CharacterCheckHealthRegen(edict_t *ent)
{
int startHealth = Kots_CharacterGetStartHealth(ent);
int maxHealth = Kots_CharacterGetMaxRegenHealth(ent);
int regen = 0;
if (ent->character->cur_karma >= 10)
regen = 12;
else if (ent->character->cur_karma >= 7)
regen = 9;
else if (ent->character->cur_karma >= 5)
regen = 4;
else if (ent->character->cur_karma >= 3)
regen = 2;
else
return;
if (ent->health < 50)
regen *= 2;
else if (ent->health >= startHealth)
{
if (ent->character->cur_karma >= 10)
regen = 2;
else if (ent->character->cur_karma >= 7)
regen = 1;
else
return;
} else if (ent->character->cur_karma < 7 && ent->health + regen > startHealth)
regen = (startHealth - ent->health);
if (regen > 0)
{
if (ent->health < maxHealth)
{
ent->health += regen;
// Sound is annoying!
//if (ent->health < startHealth)
// gi.sound(ent, CHAN_ITEM, gi.soundindex("items/l_health.wav"), 1, ATTN_NORM, 0);
if (ent->health > maxHealth)
ent->health = maxHealth;
}
}
}
void Kots_CharacterCheckArmorRegen(edict_t *ent)
{
if (!ent->client)
return;
if (ent->character->cur_technical >= 5)
{
int maxarmor = Kots_CharacterGetMaxArmorRegen(ent);
int index = ITEM_INDEX(FindItem("Body Armor"));
if (ent->client->pers.inventory[index] < maxarmor)
{
if (ent->character->cur_technical >= 7)
ent->client->pers.inventory[index] += 4;
else
ent->client->pers.inventory[index] += 2;
if (ent->client->pers.inventory[index] > maxarmor)
ent->client->pers.inventory[index] = maxarmor;
}
}
}
void Kots_CharacterCheckTballRegen(edict_t *ent)
{
if (ent->character->rune && ent->character->rune->tball_regen > 0)
{
//tballs regen every 5 seconds so if this isn't a multiple of 5 then exit now
if ((int)ent->character->next_regen % 5)
return;
//maximum of 8 tballs at a time
if (ent->character->tballs <= 0)
ent->character->tballs = 1;
else if (ent->character->tballs < 8)
ent->character->tballs++;
}
}
void Kots_CharacterCheckAmmoRegen(edict_t *ent)
{
if (!ent->client)
return;
if (ent->character->cur_strength >= 7)
{
int i, j, count;
if (ent->character->cur_strength < 10)
{
//strength 7-9 regenerate every 3 seconds
if ((int)ent->character->next_regen % 3)
return;
} //strength 10+ regen every 2 seconds
else if ((int)ent->character->next_regen % 2)
return;
for (i = 0; i < AmmoTypeLength; i++)
{
count = 0;
//for every weapon level 2 or more we get 20% of the base pickup
for (j = 0; j < ammo_types[i].weaponcount; j++)
{
if (Kots_CharacterGetCurrentWeaponLevel(ent, ammo_types[i].weapons[j]) >= 2)
++count;
}
if (count > 0)
{
int max, index;
gitem_t *ammo = FindItem(ammo_types[i].ammotype);
max = Kots_CharacterGetMaxAmmo(ent, ammo->tag);
index = ITEM_INDEX(ammo);
switch (ammo->tag)
{
case AMMO_BULLETS:
case AMMO_CELLS:
ent->client->pers.inventory[index] += count * ammo->quantity * 0.10;
break;
default:
ent->client->pers.inventory[index] += count * ammo->quantity * 0.20;
break;
}
//ensure we don't go over max ammo
if (ent->client->pers.inventory[index] > max)
ent->client->pers.inventory[index] = max;
}
}
}
}
void Kots_CharacterCheckCubeRegen(edict_t *ent)
{
if (ent->character->cur_wisdom >= 7)
{
if ((int)ent->character->next_regen % 2)
return;
Kots_CharacterPickupCubes(ent, 1);
}
}
void Kots_CharacterLiftItem(edict_t *ent)
{
edict_t *targ = NULL, *who = NULL, *best = NULL;
float bd = 0, d = 0, dx = 0, dy = 0;
vec3_t forward, dir;
int count = 0;
if (ent->character->cubes < 2)
{
gi.cprintf(ent, PRINT_HIGH, "You do not have enough cubes.\n");
return;
}
AngleVectors(ent->client->v_angle, forward, NULL, NULL);
while ((targ = findradius(targ, ent->s.origin, 2000)) != NULL)
{
if (++count >= MAX_EDICTS)
break;
if (!targ->item)
continue;
if (!(targ->spawnflags & (DROPPED_PLAYER_ITEM| DROPPED_ITEM)) && !(targ->item->tag & KOTS_ITEM_LIFTABLE))
continue;
//if (!(targ->item->tag & KOTS_ITEM_LIFTABLE) &&
//(!targ->owner || !targ->item->weapmodel))
//continue;
who = targ;
VectorSubtract(who->s.origin, ent->s.origin, dir);
VectorNormalize(dir);
d = DotProduct(forward, dir);
//give preferred items a small boost in dot product if they meet min reqs
if (d >= 0.90 && targ->item->tag & KOTS_ITEM_LIFT_PREFERRED)
d += 0.25;
if (d > bd && loc_CanSee(ent, who))
{
bd = d;
best = who;
}
}
if (bd < 0.90)
return;
if (best == NULL)
return;
targ = best;
dy = ent->s.origin[1] - targ->s.origin[1];
dx = ent->s.origin[0] - targ->s.origin[0];
VectorSet (targ->velocity, dx, dy, 400);
//track who lifted/tossed item last and when for kills
targ->target_ent = ent;
targ->wait = level.time;
//remove the cubes used
ent->character->cubes -= 2;
//uncloak the character if cloaked
Kots_CharacterUncloak(ent);
}
void Kots_CharacterTossItem(edict_t *ent)
{
edict_t *targ = NULL, *who = NULL, *best = NULL;
float bd = 0, d = 0, dx = 0, dy = 0, absx, absy;
vec3_t forward, dir;
int count = 0;
if (ent->character->cubes < 2)
{
gi.cprintf(ent, PRINT_HIGH, "You do not have enough cubes.\n");
return;
}
AngleVectors(ent->client->v_angle, forward, NULL, NULL);
while ((targ = findradius(targ, ent->s.origin, 2000)) != NULL)
{
if (++count >= MAX_EDICTS)
break;
if (!targ->item)
continue;
if (!(targ->spawnflags & (DROPPED_PLAYER_ITEM| DROPPED_ITEM)) && !(targ->item->tag & KOTS_ITEM_LIFTABLE))
continue;
who = targ;
VectorSubtract(who->s.origin, ent->s.origin, dir);
VectorNormalize(dir);
d = DotProduct(forward, dir);
//give preferred items a small boost in dot product if they meet min reqs
if (d >= 0.90 && targ->item->tag & KOTS_ITEM_LIFT_PREFERRED)
d += 0.25;
if (d > bd && loc_CanSee(ent, who))
{
bd = d;
best = who;
}
}
if (bd < 0.90)
return;
if (best == NULL)
return;
targ = best;
dy = targ->s.origin[1] - ent->s.origin[1];
dx = targ->s.origin[0] - ent->s.origin[0];
absx = abs(dx);
absy = abs(dy);
//if x is greater than y we scale based on x because it's our biggest velocity
if (absx > absy)
{
//check minimum velocity
if (absx < 150.0)
{
dy *= 100.0 / absx;
dx *= 100.0 / absx;
}
//check maximum velocty
else if (absy > 600.0)
{
dx *= 600.0 / absy;
dy *= 600.0 / absy;
}
}
else //otherwise scale from y
{
//check minimum velocity
if (absy < 150.0)
{
dx *= 100.0 / absy;
dy *= 100.0 / absy;
}
//check maximum veloctys
else if (absx > 600.0)
{
dy *= 600.0 / absx;
dx *= 600.0 / absx;
}
}
VectorSet (targ->velocity, dx * 2, dy * 2, 400);
//track who lifted/tossed item last and when for kills
targ->target_ent = ent;
targ->wait = level.time;
//remove the cubes used
ent->character->cubes -= 2;
//uncloak the character if cloaked
Kots_CharacterUncloak(ent);
}
void Kots_CharacterToggleCloaking(edict_t *ent, char *value)
{
if (Q_stricmp(value, "on") == 0)
Kots_CharacterCloak(ent);
else if (Q_stricmp(value, "off") == 0)
Kots_CharacterUncloak(ent);
else if (!ent->character->is_cloaked && ent->character->next_cloak < level.time)
Kots_CharacterCloak(ent);
else
Kots_CharacterUncloak(ent);
}
void Kots_CharacterCloak(edict_t *ent)
{
if (ent->character->cur_wisdom < 5)
gi.cprintf(ent, PRINT_HIGH, "You do not have the ability to cloak.\n");
else if (ent == spreewar.warent)
gi.cprintf(ent, PRINT_HIGH, "You can't cloak while you are on a spree war!\n");
else if (ent->character->next_empdone > level.time)
gi.cprintf(ent, PRINT_HIGH, "You were hit by an EMP Shockwave and this ability is currently disabled!\n"); //hit by emp shockwave can't cloak
else if (!ent->character->is_flashlighted && ent->character->next_empdone <= level.time)
{
//don't allow cloaking while weapon is still firing
if (ent->client->weaponstate == WEAPON_FIRING)
return;
//if we're not cloaked
if (!ent->character->is_cloaked && ent->character->next_cloak < level.time)
{
if (ent->character->cur_wisdom >= 7)
ent->character->next_cloak = level.time + 1.0;
else
ent->character->next_cloak = level.time + 2.0;
gi.bprintf(PRINT_HIGH, "%s cloaks.\n", ent->character->name);
gi.sound(ent, CHAN_AUTO, gi.soundindex("misc/spawn1.wav"), 1, ATTN_NORM, 0);
}
}
}
void Kots_CharacterUncloak(edict_t *ent)
{
//TODO: Maybe use this in the future
// But what about accidentally firing right after spawn?
//anything that causes us to uncloak should cause us to lose our spawn invuln
/*
if (ent->character->next_candamage > level.time)
{
if (ent->client)
{
//remove only spawn invuln from client
ent->client->invincible_framenum -= self->character->next_candamage - level.time;
}
ent->character->next_candamage = 0;
}
*/
if (ent->character->is_cloaked || ent->character->next_cloak > level.time)
{
gi.cprintf(ent, PRINT_HIGH, "Cloaking deactivated.\n");
ent->character->next_cloak = 0;
ent->character->is_cloaked = false;
}
}
void Kots_CharacterCloakUseCubes(edict_t *ent)
{
if (ent->character->is_cloaked)
{
if (ent->character->cubes > 1)
ent->character->cubes -= 1;
else
Kots_CharacterUncloak(ent);
}
}
void Kots_CharacterCheckCloak(edict_t *ent)
{
//reset noclient, we'll determine this later
ent->svflags &= ~SVF_NOCLIENT;
if (ent->health <= 0)
return;
if (ent->character->next_cloak && ent->character->next_cloak <= level.time)
{
ent->character->is_cloaked = true;
ent->character->next_cloak = 0; //reset cloak time
}
if (ent->character->next_cloak > level.time)
ent->s.renderfx |= RF_TRANSLUCENT;
else if (ent->character->is_cloaked)
{
if (ent->character->is_flashlighted)
{
if (ent->character->is_flashlighted == KOTS_FLASHLIGHT_MASTER)
ent->s.effects |= EF_SPHERETRANS; //alpha 0.6
else
ent->s.effects |= EF_SPHERETRANS | EF_TRACKER; //alpha 0.3
}
else
{
ent->svflags |= SVF_NOCLIENT;
if (ent->client)
{
VectorSet(ent->client->damage_blend, 0, 0, 0);
ent->client->damage_alpha = 0.33;
}
}
}
}
void Kots_CharacterToggleFlashlight(edict_t *ent, char *value)
{
if (Q_stricmp(value, "on") == 0)
Kots_CharacterFlashlightOn(ent);
else if (Q_stricmp(value, "off") == 0)
Kots_CharacterFlashlightOff(ent);
else if (!ent->client->pers.kots_persist.using_flashlight || !ent->character->flashlight)
Kots_CharacterFlashlightOn(ent);
else
Kots_CharacterFlashlightOff(ent);
}
void Kots_CharacterFlashlightOn(edict_t *ent)
{
if (ent->character->cur_spirit < 1)
gi.cprintf(ent, PRINT_HIGH, "You do not have the ability to use the flashlight.\n");
else
{
gi.cprintf(ent, PRINT_HIGH, "Flashlight activated.\n");
ent->client->pers.kots_persist.using_flashlight = true;
if (ent->character->flashlight)
G_FreeEdict(ent->character->flashlight);
ent->character->flashlight = G_Spawn();
ent->character->flashlight->owner = ent;
ent->character->flashlight->movetype = MOVETYPE_NOCLIP;
ent->character->flashlight->solid = SOLID_NOT;
ent->character->flashlight->classname = "flashlight";
ent->character->flashlight->s.modelindex = gi.modelindex("models/objects/flash/tris.md2");
//ent->character->flashlight->s.modelindex = gi.modelindex("models/objects/smoke/tris.md2");
ent->character->flashlight->s.skinnum = 0;
ent->character->flashlight->s.renderfx = RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_FULLBRIGHT;
ent->character->flashlight->s.effects = EF_SPHERETRANS | EF_HYPERBLASTER;
ent->character->flashlight->think = Kots_CharacterFlashlightThink;
ent->character->flashlight->nextthink = level.time + 0.1;
VectorSet(ent->character->flashlight->mins, -2, -2, -2);
VectorSet(ent->character->flashlight->maxs, 2, 2, 2);
}
}
void Kots_CharacterFlashlightOff(edict_t *ent)
{
if (ent->client->pers.kots_persist.using_flashlight)
{
gi.cprintf(ent, PRINT_HIGH, "Flashlight deactivated.\n");
ent->client->pers.kots_persist.using_flashlight = false;
if (ent->character->flashlight)
G_FreeEdict(ent->character->flashlight);
}
ent->character->flashlight = NULL;
}
void Kots_CharacterFlashlightThink(edict_t *self)
{
if (!self->owner || !self->owner->inuse || !self->owner->character || !self->owner->character->is_loggedin
|| !self->owner->client || !self->owner->client->pers.kots_persist.using_flashlight)
{
if (self->owner)
self->owner->character->flashlight = NULL;
G_FreeEdict(self);
return;
}
else if (self->owner->health <= 0)
{
//hide the flashlight while dead
self->svflags |= SVF_NOCLIENT;
}
else
{
vec3_t start, end, offset;
vec3_t forward, right;
trace_t tr;
AngleVectors(self->owner->client->v_angle, forward, right, NULL);
VectorSet(offset, 8 , 6, self->owner->viewheight - 7);
P_ProjectSource(self->owner->client, self->owner->s.origin, offset, forward, right, start);
VectorMA(start, 8192, forward, end);
//perform initial trace with a wider area
tr = gi.trace(start, self->mins, self->maxs, end, self->owner, CONTENTS_SOLID | CONTENTS_MONSTER | MASK_WATER);
//only go through transparent water
if ((tr.contents & MASK_WATER) && (tr.surface->flags & (SURF_TRANS33 | SURF_TRANS66)))
tr = gi.trace(tr.endpos, NULL, NULL, end, tr.ent, CONTENTS_SOLID | CONTENTS_MONSTER | MASK_WATER);
//if we didn't find a living character in our path do a tace without the width
if (tr.ent->character && tr.ent->health > 0)
{
float recloak_time = 1.0;
//if already cloaking this will make them somewhat visible
if (self->owner->character->spirit >= 7)
{
tr.ent->character->is_flashlighted = KOTS_FLASHLIGHT_MASTER;
recloak_time = 1.0;
}
else
{
tr.ent->character->is_flashlighted = KOTS_FLASHLIGHT_NORM;
if (self->owner->character->spirit >= 5)
recloak_time = 0.5;
else
recloak_time = 0.25;
}
//prevent from cloaking if not fully clocked
if (tr.ent->character->next_cloak > level.time)
tr.ent->character->next_cloak = 0;
else
{
float new_time;
if (tr.ent->character->cur_wisdom >= 7)
new_time = level.time + (1.0 * recloak_time);
else
new_time = level.time + (2.0 * recloak_time);
if (new_time > tr.ent->character->next_unflashlight)
tr.ent->character->next_unflashlight = new_time;
}
}
VectorCopy(tr.endpos, self->s.origin);
//make sure the entity is visible
self->svflags &= ~SVF_NOCLIENT;
gi.linkentity (self);
}
self->nextthink = level.time + 0.1;
}
void Kots_CharacterHook(edict_t *ent)
{
if (ent->character->cur_dexterity >= 3)
{
int cubes;
if (ent->character->cur_dexterity >= 10)
cubes = 1;
else if (ent->character->cur_dexterity >= 7)
cubes = 3;
else
cubes = 5;
if (ent->character->cubes < cubes)
{
gi.cprintf(ent, PRINT_HIGH, "Not enough cubes to use the hook.\n");
return;
}
//uncloak the character if cloaked
Kots_CharacterUncloak(ent);
ent->character->cubes -= cubes; // Aldarn - negate cubes
CTFGrappleFire (ent, vec3_origin, 10, 0);
}
else
gi.cprintf(ent, PRINT_HIGH, "You do not have the power to use the hook yet.\n");
}
void Kots_CharacterUnhook(edict_t *ent)
{
CTFPlayerResetGrapple(ent);
}
void Kots_CharacterKnockWeapon(edict_t *ent)
{
if (!ent->client)
return;
if (ent->client->pers.weapon)
{
if (ent->client->pers.weapon->weapmodel != WEAP_SABRE && ent->client->pers.weapon->weapmodel != WEAP_GRENADES)
{
gitem_t *oldweapon = ent->client->pers.weapon;
Use_Weapon(ent, FindItem("Sabre"));
ChangeWeapon(ent);
Drop_Weapon(ent, oldweapon);
gi.sound(ent, CHAN_AUTO, gi.soundindex("gladiator/GLDSRCH1.WAV"), 1, ATTN_NORM, 0);
}
}
}
void Kots_CharacterCheckKnock(edict_t *targ, edict_t *attacker, int damage)
{
int knock;
if (targ->character->cur_dexterity >= 10)
return;
if (attacker->character->cur_strength < 5)
return;
if (attacker->client && !attacker->client->pers.kots_persist.using_knock)
return;
if (targ->character->next_knock > level.time)
return;
targ->character->knockdamage += damage;
if (attacker->character->cur_strength >= 7)
knock = 160;
else if (attacker->character->cur_strength >= 5)
knock = 280;
if (targ->character->knockdamage > knock)
{
float chance = 0.5;
if (targ->character->cur_dexterity >= 7)
chance -= 0.06 * targ->character->cur_dexterity;
else if (targ->character->cur_dexterity > 0)
chance -= 0.02 * targ->character->cur_dexterity;
if (Kots_RandRound(chance))
Kots_CharacterKnockWeapon(targ);
targ->character->knockdamage = 0;
targ->character->next_knock = level.time + 2;
}
}
void Kots_CharacterCheckKnockCounter(edict_t *ent)
{
if (ent->character->knockdamage > 0)
{
if (ent->character->cur_dexterity >= 7)
ent->character->knockdamage -= 30;
else if (ent->character->cur_dexterity >= 5)
ent->character->knockdamage -= 20;
else
ent->character->knockdamage -= 10;
if (ent->character->knockdamage < 0)
ent->character->knockdamage = 0;
}
}
void Kots_CharacterToggleKnock(edict_t *ent, char *value)
{
if (Q_stricmp(value, "on") == 0)
ent->client->pers.kots_persist.using_knock = true;
else if (Q_stricmp(value, "off") == 0)
ent->client->pers.kots_persist.using_knock = false;
else if (!ent->client->pers.kots_persist.using_knock)
ent->client->pers.kots_persist.using_knock = true;
else
ent->client->pers.kots_persist.using_knock = false;
if (ent->client->pers.kots_persist.using_knock)
gi.cprintf(ent, PRINT_HIGH, "Weapon knock is enabled.\n");
else
gi.cprintf(ent, PRINT_HIGH, "Weapon knock is disabled.\n");
}
void Kots_CharacterCheckVampire(edict_t *targ, edict_t *attacker, int damage)
{
//check for vampire (health steal)
//don't steal while using empathy
if (attacker->character->cur_wisdom >= 1 && !targ->character->using_empathy)
{
//no stealing health over max
if (attacker->health < attacker->max_health)
{
//only receive 50% health steal from monsters
if (!(attacker->svflags & SVF_MONSTER) && (targ->svflags & SVF_MONSTER))
damage /= 2;
//steal 25% of the health
attacker->health += Kots_RandMultiply(damage, 0.25);
//ensure we don't steal over our max
if (attacker->health > attacker->max_health)
attacker->health = attacker->max_health;
}
}
}
void Kots_CharacterCheckAmmoSteal(edict_t *targ, edict_t *attacker, int damage)
{
//check for dexterity ammo steal
if (attacker->character->cur_dexterity >= 5)
{
if (targ->client && targ->character->cur_karma < 10)
{
int ammoindex, ammosteal;
gitem_t *ammo = NULL;
//randomly pick an ammo index
ammoindex = rand() % AmmoTypeLength;
ammo = FindItem(ammo_types[ammoindex].ammotype);
ammoindex = ITEM_INDEX(ammo);
if (targ->client->pers.inventory[ammoindex] > 0)
{
if (attacker->character->cur_dexterity >= 7)
ammosteal = (ammo->quantity / 50.0) * (damage * 0.25);
else
ammosteal = (ammo->quantity / 50.0) * (damage * 0.125);
//perform karma reduction
if (targ->character->cur_karma >= 7)
ammosteal = Kots_RandMultiply(ammosteal, 0.1 * targ->character->cur_karma);
else if (targ->character->cur_karma > 0)
ammosteal = Kots_RandMultiply(ammosteal, 0.05 * targ->character->cur_karma);
//if no ammo is stolen then that's too bad
//ensure that at least 1 is stolen
if (ammosteal > 0)
{
//ensure that we don't steal more than they have
if (ammosteal > targ->client->pers.inventory[ammoindex])
ammosteal = targ->client->pers.inventory[ammoindex];
//steal the ammo
targ->client->pers.inventory[ammoindex] -= ammosteal;
//monsters don't use it but still steal it
if (attacker->client)
attacker->client->pers.inventory[ammoindex] += ammosteal;
}
}
}
}
}
void Kots_CharacterPlayerId(edict_t *ent)
{
//karma sight is pointless for monsters
if (!ent->client)
return;
if (ent->character->cur_karma < 1)
{
ent->character->karma_id_ent = NULL;
return;
}
if (level.time >= ent->character->next_karma_id)
{
edict_t *targ = NULL, *who = NULL, *best = NULL;
float bd = 0, d = 0;
vec3_t forward, dir;
int count = 0;
AngleVectors(ent->client->v_angle, forward, NULL, NULL);
while ((targ = findradius(targ, ent->s.origin, 2000)) != NULL)
{
if (++count >= MAX_EDICTS)
break;
if (!targ->character || !targ->character->is_loggedin || targ->health <= 0 || targ == ent)
continue;