PlayerDamage_Calculate -> Damage_Calculate
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / campcheck / sv_campcheck.qc
1 #include "sv_campcheck.qh"
2
3 float autocvar_g_campcheck_damage;
4 float autocvar_g_campcheck_distance;
5 float autocvar_g_campcheck_interval;
6
7 REGISTER_MUTATOR(campcheck, cvar("g_campcheck"));
8
9 .float campcheck_nextcheck;
10 .float campcheck_traveled_distance;
11
12 MUTATOR_HOOKFUNCTION(campcheck, PlayerDies)
13 {
14         entity frag_target = M_ARGV(2, entity);
15
16         Kill_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CPID_CAMPCHECK);
17 }
18
19 MUTATOR_HOOKFUNCTION(campcheck, Damage_Calculate)
20 {
21         entity frag_attacker = M_ARGV(1, entity);
22         entity frag_target = M_ARGV(2, entity);
23
24         if(IS_PLAYER(frag_target))
25         if(IS_PLAYER(frag_attacker))
26         if(frag_attacker != frag_target)
27         {
28                 frag_target.campcheck_traveled_distance = autocvar_g_campcheck_distance;
29                 frag_attacker.campcheck_traveled_distance = autocvar_g_campcheck_distance;
30         }
31 }
32
33 MUTATOR_HOOKFUNCTION(campcheck, PlayerPreThink)
34 {
35         entity player = M_ARGV(0, entity);
36
37         if(!gameover)
38         if(!warmup_stage) // don't consider it camping during warmup?
39         if(time >= game_starttime)
40         if(IS_PLAYER(player))
41         if(IS_REAL_CLIENT(player)) // bots may camp, but that's no reason to constantly kill them
42         if(!IS_DEAD(player))
43         if(!forbidWeaponUse(player))
44         if(!STAT(FROZEN, player))
45         if(!PHYS_INPUT_BUTTON_CHAT(player))
46         if(autocvar_g_campcheck_interval)
47         {
48                 vector dist;
49
50                 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
51                 dist = player.prevorigin - player.origin;
52                 dist.z = 0;
53                 player.campcheck_traveled_distance += fabs(vlen(dist));
54
55                 if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime) || (round_handler_IsActive() && !round_handler_IsRoundStarted()))
56                 {
57                         player.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
58                         player.campcheck_traveled_distance = 0;
59                 }
60
61                 if(time > player.campcheck_nextcheck)
62                 {
63                         if(player.campcheck_traveled_distance < autocvar_g_campcheck_distance)
64                         {
65                                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_CAMPCHECK);
66                                 if(player.vehicle)
67                                         Damage(player.vehicle, NULL, NULL, autocvar_g_campcheck_damage * 2, DEATH_CAMP.m_id, player.vehicle.origin, '0 0 0');
68                                 else
69                                         Damage(player, NULL, NULL, bound(0, autocvar_g_campcheck_damage, player.health + player.armorvalue * autocvar_g_balance_armor_blockpercent + 5), DEATH_CAMP.m_id, player.origin, '0 0 0');
70                         }
71                         player.campcheck_nextcheck = time + autocvar_g_campcheck_interval;
72                         player.campcheck_traveled_distance = 0;
73                 }
74
75                 return;
76         }
77
78         player.campcheck_nextcheck = time + autocvar_g_campcheck_interval; // one of the above checks failed, so keep the timer up to date
79 }
80
81 MUTATOR_HOOKFUNCTION(campcheck, PlayerSpawn)
82 {
83         entity player = M_ARGV(0, entity);
84
85         player.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
86         player.campcheck_traveled_distance = 0;
87 }
88
89 MUTATOR_HOOKFUNCTION(campcheck, BuildMutatorsString)
90 {
91         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":CampCheck");
92 }