Xonotic
gravity.qc
Go to the documentation of this file.
1 #include "gravity.qh"
2 #ifdef SVQC
3 .entity trigger_gravity_check;
4 void trigger_gravity_remove(entity own)
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 }
16 void trigger_gravity_check_think(entity this)
17 {
18  // This spawns when a player enters the gravity zone and checks if he 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)
24  trigger_gravity_remove(this.owner);
25  else
26  delete(this);
27  return;
28  }
29  else
30  {
31  this.count -= 1;
32  this.nextthink = time;
33  }
34 }
35 
36 // legacy
37 void trigger_gravity_use(entity this, entity actor, entity trigger)
38 {
39  this.setactive(this, ACTIVE_TOGGLE);
40 }
41 
42 void trigger_gravity_touch(entity this, entity toucher)
43 {
44  float g;
45 
46  if(this.active == ACTIVE_NOT)
47  return;
48 
49  EXACTTRIGGER_TOUCH(this, toucher);
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)
67  trigger_gravity_remove(toucher);
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 != "")
86  _sound (toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
88  }
89 }
90 
91 spawnfunc(trigger_gravity)
92 {
93  if(this.gravity == 1)
94  return;
95 
97  settouch(this, trigger_gravity_touch);
98  if(this.noise != "")
99  precache_sound(this.noise);
100 
101  this.active = ACTIVE_ACTIVE;
102  this.setactive = generic_setactive;
103  if(this.targetname && this.targetname != "")
104  {
105  // legacy use
106  this.use = trigger_gravity_use;
108  this.active = ACTIVE_NOT;
109  }
110 }
111 #endif
#define EXACTTRIGGER_INIT
Definition: common.qh:117
string noise
Definition: progsdefs.qc:209
const int GRAVITY_START_DISABLED
Definition: gravity.qh:5
const int ACTIVE_TOGGLE
Definition: defs.qh:40
#define EXACTTRIGGER_TOUCH(e, t)
Definition: common.qh:116
entity() spawn
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
float spawnflags
Definition: progsdefs.qc:191
entity owner
Definition: main.qh:73
float cnt
Definition: powerups.qc:24
void UpdateCSQCProjectile(entity e)
const int CH_TRIGGER
Definition: sound.qh:12
const int ACTIVE_ACTIVE
Definition: defs.qh:37
#define NULL
Definition: post.qh:17
#define backtrace(msg)
Definition: log.qh:105
const float VOL_BASE
Definition: sound.qh:36
const float ATTEN_NORM
Definition: sound.qh:30
float nextthink
Definition: csprogsdefs.qc:121
float gravity
Definition: items.qh:16
float count
Definition: powerups.qc:22
#define _sound(e, c, s, v, a)
Definition: sound.qh:50
string targetname
Definition: progsdefs.qc:194
int active
Definition: defs.qh:34
const int GRAVITY_STICKY
Definition: gravity.qh:4
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
#define setthink(e, f)
#define use
Definition: csprogsdefs.qh:50
const int ACTIVE_NOT
Definition: defs.qh:36
float time
Definition: csprogsdefs.qc:16