Xonotic
door_rotating.qc
Go to the documentation of this file.
1 #include "door_rotating.qh"
2 /*QUAKED spawnfunc_func_door_rotating (0 .5 .8) ? START_OPEN BIDIR DOOR_DONT_LINK BIDIR_IN_DOWN x TOGGLE X_AXIS Y_AXIS
3 if two doors touch, they are assumed to be connected and operate as a unit.
4 
5 TOGGLE causes the door to wait in both the start and end states for a trigger event.
6 
7 BIDIR makes the door work bidirectional, so that the opening direction is always away from the requestor.
8 The usage of bidirectional doors requires two manually instantiated triggers (trigger_multiple), the one to open it in the other direction
9 must have set trigger_reverse to 1.
10 BIDIR_IN_DOWN will the door prevent from reopening while closing if it is triggered from the other side.
11 
12 START_OPEN causes the door to move to its destination when spawned, and operate in reverse. It is used to temporarily or permanently close off an area when triggered (not usefull for touch or takedamage doors).
13 
14 "message" is printed when the door is touched if it is a trigger door and it hasn't been fired yet
15 "angle" determines the destination angle for opening. negative values reverse the direction.
16 "targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door.
17 "health" if set, door must be shot open
18 "speed" movement speed (100 default)
19 "wait" wait before returning (3 default, -1 = never return)
20 "dmg" damage to inflict when blocked (2 default)
21 "sounds"
22 0) no sound
23 1) stone
24 2) base
25 3) stone chain
26 4) screechy metal
27 FIXME: only one sound set available at the time being
28 */
29 
30 #ifdef GAMEQC
31 void door_rotating_hit_top(entity this)
32 {
33  if (this.noise1 != "")
35  this.state = STATE_TOP;
36  if (this.spawnflags & DOOR_TOGGLE)
37  return; // don't come down automatically
38  setthink(this, door_rotating_go_down);
39  this.nextthink = this.ltime + this.wait;
40 }
41 
42 void door_rotating_hit_bottom(entity this)
43 {
44  if (this.noise1 != "")
46  if (this.lip==666) // this.lip is used to remember reverse opening direction for door_rotating
47  {
48  this.pos2 = '0 0 0' - this.pos2;
49  this.lip = 0;
50  }
51  this.state = STATE_BOTTOM;
52 }
53 
54 void door_rotating_go_down(entity this)
55 {
56  if (this.noise2 != "")
58  if (this.max_health)
59  {
60  this.takedamage = DAMAGE_YES;
62  }
63 
64  this.state = STATE_DOWN;
65  SUB_CalcAngleMove (this, this.pos1, TSPEED_LINEAR, this.speed, door_rotating_hit_bottom);
66 }
67 
68 void door_rotating_go_up(entity this, entity oth)
69 {
70  if (this.state == STATE_UP)
71  return; // already going up
72 
73  if (this.state == STATE_TOP)
74  { // reset top wait time
75  this.nextthink = this.ltime + this.wait;
76  return;
77  }
78  if (this.noise2 != "")
80  this.state = STATE_UP;
81  SUB_CalcAngleMove (this, this.pos2, TSPEED_LINEAR, this.speed, door_rotating_hit_top);
82 
83  string oldmessage;
84  oldmessage = this.message;
85  this.message = "";
86  SUB_UseTargets(this, NULL, oth); // TODO: is oth needed here?
87  this.message = oldmessage;
88 }
89 #endif
90 
91 #ifdef SVQC
92 void door_rotating_reset(entity this)
93 {
94  this.angles = this.pos1;
95  this.avelocity = '0 0 0';
96  this.state = STATE_BOTTOM;
97  setthink(this, func_null);
98  this.nextthink = 0;
99 }
100 
101 void door_rotating_init_startopen(entity this)
102 {
103  this.angles = this.movedir;
104  this.pos2 = '0 0 0';
105  this.pos1 = this.movedir;
106 }
107 
108 spawnfunc(func_door_rotating)
109 {
110  //if (!this.deathtype) // map makers can override this
111  // this.deathtype = " got in the way";
112 
113  // I abuse "movedir" for denoting the axis for now
114  if (this.spawnflags & DOOR_ROTATING_XAXIS)
115  this.movedir = '0 0 1';
116  else if (this.spawnflags & DOOR_ROTATING_YAXIS)
117  this.movedir = '1 0 0';
118  else // Z
119  this.movedir = '0 1 0';
120 
121  if (this.angles_y==0) this.angles_y = 90;
122 
123  this.movedir = this.movedir * this.angles_y;
124  this.angles = '0 0 0';
125 
126  this.avelocity = this.movedir;
127  if (!InitMovingBrushTrigger(this))
128  return;
129  this.velocity = '0 0 0';
130  //this.effects |= EF_LOWPRECISION;
131  this.classname = "door_rotating";
132 
133  setblocked(this, door_blocked);
134  this.use = door_use;
135 
136  this.pos1 = '0 0 0';
137  this.pos2 = this.movedir;
138 
139 // DOOR_START_OPEN is to allow an entity to be lighted in the closed position
140 // but spawn in the open position
141  if (this.spawnflags & DOOR_START_OPEN)
142  InitializeEntity(this, door_rotating_init_startopen, INITPRIO_SETLOCATION);
143 
144  door_init_shared(this);
145  if (!this.speed)
146  {
147  this.speed = 50;
148  }
149  this.lip = 0; // this.lip is used to remember reverse opening direction for door_rotating
150 
151  settouch(this, door_touch);
152 
153 // LinkDoors can't be done until all of the doors have been spawned, so
154 // the sizes can be detected properly.
155  InitializeEntity(this, LinkDoors, INITPRIO_LINKDOORS);
156 
157  this.reset = door_rotating_reset;
158 }
159 #endif
float state
Definition: subs.qh:32
const int DOOR_ROTATING_XAXIS
Definition: door_rotating.qh:7
float speed
Definition: subs.qh:41
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
Definition: cl_resources.qc:15
const int DOOR_START_OPEN
Definition: door.qh:7
void door_use(entity this, entity actor, entity trigger)
Definition: door.qc:255
entity() spawn
#define STATE_TOP
Definition: sys-pre.qh:30
const int TSPEED_LINEAR
Definition: subs.qh:71
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition: triggers.qc:366
string noise2
Definition: progsdefs.qc:209
const int DOOR_ROTATING_YAXIS
Definition: door_rotating.qh:8
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
string classname
Definition: csprogsdefs.qc:107
vector avelocity
Definition: csprogsdefs.qc:105
float ltime
Definition: progsdefs.qc:107
#define STATE_DOWN
Definition: sys-pre.qh:33
float spawnflags
Definition: progsdefs.qc:191
void door_blocked(entity this, entity blocker)
Definition: door.qc:28
RES_HEALTH
Definition: ent_cs.qc:126
vector movedir
Definition: progsdefs.qc:203
float wait
Definition: subs.qh:39
string noise1
Definition: progsdefs.qc:209
string message
Definition: powerups.qc:19
#define NULL
Definition: post.qh:17
float max_health
const float VOL_BASE
Definition: sound.qh:36
float takedamage
Definition: progsdefs.qc:147
const float ATTEN_NORM
Definition: sound.qh:30
float nextthink
Definition: csprogsdefs.qc:121
const int CH_TRIGGER_SINGLE
Definition: sound.qh:13
void door_touch(entity this, entity toucher)
Definition: door.qc:294
#define STATE_UP
Definition: sys-pre.qh:32
void LinkDoors(entity this)
Definition: door.qc:429
void InitializeEntity(entity e, void(entity this) func, int order)
Definition: world.qc:2146
float lip
Definition: subs.qh:40
#define _sound(e, c, s, v, a)
Definition: sound.qh:50
vector pos1
Definition: subs.qh:50
#define setthink(e, f)
void SUB_CalcAngleMove(entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
Definition: subs.qc:331
vector angles
Definition: csprogsdefs.qc:104
#define use
Definition: csprogsdefs.qh:50
vector velocity
Definition: csprogsdefs.qc:103
vector pos2
Definition: subs.qh:50
var void func_null()
float DAMAGE_YES
Definition: progsdefs.qc:283
#define STATE_BOTTOM
Definition: sys-pre.qh:31
const int DOOR_TOGGLE
Definition: door.qh:11