Remove _all indirection
[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, PlayerDamage_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(!STAT(FROZEN, player))
44         if(!PHYS_INPUT_BUTTON_CHAT(player))
45         if(autocvar_g_campcheck_interval)
46         {
47                 vector dist;
48
49                 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
50                 dist = player.prevorigin - player.origin;
51                 dist.z = 0;
52                 player.campcheck_traveled_distance += fabs(vlen(dist));
53
54                 if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime) || (round_handler_IsActive() && !round_handler_IsRoundStarted()))
55                 {
56                         player.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
57                         player.campcheck_traveled_distance = 0;
58                 }
59
60                 if(time > player.campcheck_nextcheck)
61                 {
62                         if(player.campcheck_traveled_distance < autocvar_g_campcheck_distance)
63                         {
64                                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_CAMPCHECK);
65                                 if(player.vehicle)
66                                         Damage(player.vehicle, NULL, NULL, autocvar_g_campcheck_damage * 2, DEATH_CAMP.m_id, player.vehicle.origin, '0 0 0');
67                                 else
68                                         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');
69                         }
70                         player.campcheck_nextcheck = time + autocvar_g_campcheck_interval;
71                         player.campcheck_traveled_distance = 0;
72                 }
73
74                 return;
75         }
76
77         player.campcheck_nextcheck = time + autocvar_g_campcheck_interval; // one of the above checks failed, so keep the timer up to date
78 }
79
80 MUTATOR_HOOKFUNCTION(campcheck, PlayerSpawn)
81 {
82         entity player = M_ARGV(0, entity);
83
84         player.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
85         player.campcheck_traveled_distance = 0;
86 }
87
88 MUTATOR_HOOKFUNCTION(campcheck, BuildMutatorsString)
89 {
90         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":CampCheck");
91 }