]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_campcheck.qc
Merge branch 'master' into TimePath/issue-1170
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_campcheck.qc
1 .float campcheck_nextcheck;
2 .float campcheck_traveled_distance;
3
4 MUTATOR_HOOKFUNCTION(campcheck_PlayerDies)
5 {
6         Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_CAMPCHECK);
7
8         return FALSE;
9 }
10
11 MUTATOR_HOOKFUNCTION(campcheck_PlayerDamage)
12 {
13         if(IS_PLAYER(frag_target))
14         if(IS_PLAYER(frag_attacker))
15         if(frag_attacker != frag_target)
16         {
17                 frag_target.campcheck_traveled_distance = autocvar_g_campcheck_distance;
18                 frag_attacker.campcheck_traveled_distance = autocvar_g_campcheck_distance;
19         }
20
21         return FALSE;
22 }
23
24 MUTATOR_HOOKFUNCTION(campcheck_PlayerThink)
25 {
26         if(IS_PLAYER(self))
27         if(self.deadflag == DEAD_NO)
28         if(!self.frozen)
29         if(autocvar_g_campcheck_interval)
30         {
31                 vector dist;
32
33                 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
34                 dist = self.prevorigin - self.origin;
35                 dist_z = 0;
36                 self.campcheck_traveled_distance += fabs(vlen(dist));
37
38                 if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime) || (round_handler_IsActive() && !round_handler_IsRoundStarted()))
39                 {
40                         self.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
41                         self.campcheck_traveled_distance = 0;
42                 }
43
44                 if(time > self.campcheck_nextcheck)
45                 {
46                         if(self.campcheck_traveled_distance < autocvar_g_campcheck_distance)
47                         {
48                                 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_CAMPCHECK);
49                                 if(self.vehicle)
50                                         Damage(self.vehicle, self, self, autocvar_g_campcheck_damage * 2, DEATH_CAMP, self.vehicle.origin, '0 0 0');
51                                 else
52                                         Damage(self, self, self, bound(0, autocvar_g_campcheck_damage, self.health + self.armorvalue * autocvar_g_balance_armor_blockpercent + 5), DEATH_CAMP, self.origin, '0 0 0');
53                         }
54                         self.campcheck_nextcheck = time + autocvar_g_campcheck_interval;
55                         self.campcheck_traveled_distance = 0;
56                 }
57         }
58
59         return FALSE;
60 }
61
62 MUTATOR_HOOKFUNCTION(campcheck_PlayerSpawn)
63 {
64         self.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
65         self.campcheck_traveled_distance = 0;
66
67         return FALSE;
68 }
69
70 MUTATOR_HOOKFUNCTION(campcheck_BuildMutatorsString)
71 {
72         ret_string = strcat(ret_string, ":CampCheck");
73         return FALSE;
74 }
75
76 MUTATOR_DEFINITION(mutator_campcheck)
77 {
78         MUTATOR_HOOK(PlayerDies, campcheck_PlayerDies, CBC_ORDER_ANY);
79         MUTATOR_HOOK(PlayerDamage_Calculate, campcheck_PlayerDamage, CBC_ORDER_ANY);
80         MUTATOR_HOOK(PlayerPreThink, campcheck_PlayerThink, CBC_ORDER_ANY);
81         MUTATOR_HOOK(PlayerSpawn, campcheck_PlayerSpawn, CBC_ORDER_ANY);
82         MUTATOR_HOOK(BuildMutatorsString, campcheck_BuildMutatorsString, CBC_ORDER_ANY);
83
84         return FALSE;
85 }