Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
gravity.qc
Go to the documentation of this file.
1#include "gravity.qh"
2#ifdef SVQC
5{
6 if(own.trigger_gravity_check.owner == own)
7 {
9 own.gravity = own.trigger_gravity_check.gravity;
10 delete(own.trigger_gravity_check);
11 }
12 else
13 backtrace("Removing a trigger_gravity_check with no valid owner");
14 own.trigger_gravity_check = NULL;
15}
17{
18 // This spawns when a player enters the gravity zone and checks if they left.
19 // Each frame, this.count is set to 2 by trigger_gravity_touch() and decreased by 1 here.
20 // It the player has left the gravity trigger, this will be allowed to reach 0 and indicate that.
21 if(this.count <= 0)
22 {
23 if(this.owner.trigger_gravity_check == this)
25 else
26 delete(this);
27 return;
28 }
29 else
30 {
31 this.count -= 1;
32 this.nextthink = time;
33 }
34}
35
36// legacy
37void trigger_gravity_use(entity this, entity actor, entity trigger)
38{
39 this.setactive(this, ACTIVE_TOGGLE);
40}
41
43{
44 float g;
45
46 if(this.active == ACTIVE_NOT)
47 return;
48
50
51 g = this.gravity;
52
53 if (!(this.spawnflags & GRAVITY_STICKY))
54 {
55 if(toucher.trigger_gravity_check)
56 {
57 if(this == toucher.trigger_gravity_check.enemy)
58 {
59 // same?
60 // NOTE: see explanation in trigger_gravity_check_think
61 toucher.trigger_gravity_check.count = 2; // gravity one more frame...
62 return;
63 }
64
65 // compare prio
66 if(this.cnt > toucher.trigger_gravity_check.enemy.cnt)
68 else
69 return;
70 }
71 toucher.trigger_gravity_check = new_pure(trigger_gravity_checker);
72 toucher.trigger_gravity_check.enemy = this;
73 toucher.trigger_gravity_check.owner = toucher;
74 toucher.trigger_gravity_check.gravity = toucher.gravity;
75 setthink(toucher.trigger_gravity_check, trigger_gravity_check_think);
76 toucher.trigger_gravity_check.nextthink = time;
77 toucher.trigger_gravity_check.count = 2;
78 if(toucher.gravity)
79 g *= toucher.gravity;
80 }
81
82 if (toucher.gravity != g)
83 {
84 toucher.gravity = g;
85 if(this.noise != "")
88 }
89}
90
91spawnfunc(trigger_gravity)
92{
93 if(this.gravity == 1)
94 return;
95
98 if(this.noise != "")
100
101 this.active = ACTIVE_ACTIVE;
102 this.setactive = generic_setactive;
103 if(this.targetname && this.targetname != "")
104 {
105 // legacy use
108 this.active = ACTIVE_NOT;
109 }
110}
111#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
float count
Definition powerups.qc:22
float gravity
Definition items.qh:17
entity owner
Definition main.qh:87
int spawnflags
Definition ammo.qh:15
float time
float nextthink
#define use
void UpdateCSQCProjectile(entity e)
const int ACTIVE_TOGGLE
Definition defs.qh:40
const int ACTIVE_NOT
Definition defs.qh:36
int active
Definition defs.qh:34
const int ACTIVE_ACTIVE
Definition defs.qh:37
void trigger_gravity_remove(entity own)
Definition gravity.qc:4
void trigger_gravity_touch(entity this, entity toucher)
Definition gravity.qc:42
entity trigger_gravity_check
Definition gravity.qc:3
void trigger_gravity_use(entity this, entity actor, entity trigger)
Definition gravity.qc:37
void trigger_gravity_check_think(entity this)
Definition gravity.qc:16
const int GRAVITY_START_DISABLED
Definition gravity.qh:5
const int GRAVITY_STICKY
Definition gravity.qh:4
#define EXACTTRIGGER_TOUCH(e, t)
Definition common.qh:115
#define EXACTTRIGGER_INIT
Definition common.qh:116
#define backtrace(msg)
Definition log.qh:99
string precache_sound(string sample)
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
#define NULL
Definition post.qh:14
#define setthink(e, f)
entity entity toucher
Definition self.qh:72
#define settouch(e, f)
Definition self.qh:73
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
#define _sound(e, c, s, v, a)
Definition sound.qh:43
const float ATTEN_NORM
Definition sound.qh:30
#define spawnfunc(id)
Definition spawnfunc.qh:96
string noise
Definition subs.qh:83
void generic_setactive(entity this, int act)
Definition triggers.qc:46
string targetname
Definition triggers.qh:56