]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_campcheck.qc
Client-selectable physics configs
[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(autocvar_g_campcheck_interval)
29         {
30                 vector dist;
31
32                 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
33                 dist = self.prevorigin - self.origin;
34                 dist_z = 0;
35                 self.campcheck_traveled_distance += fabs(vlen(dist));
36
37                 if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime) || (round_handler_IsActive() && !round_handler_IsRoundStarted()))
38                 {
39                         self.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
40                         self.campcheck_traveled_distance = 0;
41                 }
42
43                 if(time > self.campcheck_nextcheck)
44                 {
45                         if(self.campcheck_traveled_distance < autocvar_g_campcheck_distance)
46                         {
47                                 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_CAMPCHECK);
48                                 if(self.vehicle)
49                                         Damage(self.vehicle, self, self, autocvar_g_campcheck_damage * 2, DEATH_CAMP, self.vehicle.origin, '0 0 0');
50                                 else
51                                         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');
52                         }
53                         self.campcheck_nextcheck = time + autocvar_g_campcheck_interval;
54                         self.campcheck_traveled_distance = 0;
55                 }
56         }
57
58         return FALSE;
59 }
60
61 MUTATOR_HOOKFUNCTION(campcheck_PlayerSpawn)
62 {
63         self.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
64         self.campcheck_traveled_distance = 0;
65
66         return FALSE;
67 }
68
69 MUTATOR_HOOKFUNCTION(campcheck_BuildMutatorsString)
70 {
71         ret_string = strcat(ret_string, ":CampCheck");
72         return FALSE;
73 }
74
75 MUTATOR_DEFINITION(mutator_campcheck)
76 {
77         MUTATOR_HOOK(PlayerDies, campcheck_PlayerDies, CBC_ORDER_ANY);
78         MUTATOR_HOOK(PlayerDamage_Calculate, campcheck_PlayerDamage, CBC_ORDER_ANY);
79         MUTATOR_HOOK(PlayerPreThink, campcheck_PlayerThink, CBC_ORDER_ANY);
80         MUTATOR_HOOK(PlayerSpawn, campcheck_PlayerSpawn, CBC_ORDER_ANY);
81         MUTATOR_HOOK(BuildMutatorsString, campcheck_BuildMutatorsString, CBC_ORDER_ANY);
82
83         return FALSE;
84 }