Xonotic
counter.qc
Go to the documentation of this file.
1 #include "counter.qh"
2 
3 #ifdef SVQC
4 void counter_use(entity this, entity actor, entity trigger)
5 {
6  if(this.active != ACTIVE_ACTIVE)
7  return;
8 
9  entity store = this;
11  {
12  if(!IS_PLAYER(actor))
13  return;
14  entity mycounter = NULL;
15  IL_EACH(g_counters, it.realowner == actor && it.owner == this,
16  {
17  mycounter = it;
18  break;
19  });
20  if(!mycounter)
21  {
22  mycounter = new_pure(counter);
23  IL_PUSH(g_counters, mycounter);
24  mycounter.owner = this;
25  mycounter.realowner = actor;
26  mycounter.reset = counter_reset; // NOTE: this may be useless as the player deletes their counters upon respawning
27  mycounter.counter_cnt = 0;
28  }
29  store = mycounter;
30  }
31 
32  store.counter_cnt += 1;
33  if (store.counter_cnt > this.count)
34  return;
35 
36  bool doactivate = (this.spawnflags & COUNTER_FIRE_AT_COUNT);
37 
38  if (store.counter_cnt == this.count)
39  {
40  if(IS_PLAYER(actor) && !(this.spawnflags & SPAWNFLAG_NOMESSAGE))
41  Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COMPLETED);
42 
43  doactivate = true;
44 
45  if(this.respawntime)
46  {
47  setthink(store, counter_reset);
48  store.nextthink = time + this.respawntime;
49  }
50  }
51  else
52  {
53  if(IS_PLAYER(actor) && !(this.spawnflags & SPAWNFLAG_NOMESSAGE))
54  {
55  if((this.count - store.counter_cnt) >= 4)
56  Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER);
57  else
58  Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER_FEWMORE, this.count - store.counter_cnt);
59  }
60  }
61 
62  if(doactivate)
63  SUB_UseTargets(this, actor, trigger);
64 }
65 
66 void counter_reset(entity this)
67 {
68  setthink(this, func_null);
69  this.nextthink = 0;
70  this.counter_cnt = 0;
71  this.active = ACTIVE_ACTIVE;
72 }
73 
74 /*QUAKED spawnfunc_trigger_counter (.5 .5 .5) ? nomessage COUNTER_FIRE_AT_COUNT
75 Acts as an intermediary for an action that takes multiple inputs.
76 
77 If nomessage is not set, it will print "1 more.. " etc when triggered and "sequence complete" when finished.
78 If COUNTER_FIRE_AT_COUNT is set, it will also fire all of its targets at countdown, making it behave like trigger_mulitple with limited shots
79 
80 If respawntime is set, it will re-enable itself after the time once the sequence has been completed
81 
82 After the counter has been triggered "count" times (default 2), it will fire all of its targets.
83 */
84 spawnfunc(trigger_counter)
85 {
86  if (!this.count)
87  this.count = 2;
88 
89  this.counter_cnt = 0;
90  this.use = counter_use;
91  this.reset = counter_reset;
92  this.active = ACTIVE_ACTIVE;
93 }
94 #endif
#define IL_EACH(this, cond, body)
float respawntime
Definition: items.qh:36
entity() spawn
const int SPAWNFLAG_NOMESSAGE
Definition: defs.qh:16
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition: triggers.qc:366
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
float spawnflags
Definition: progsdefs.qc:191
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
const int COUNTER_PER_PLAYER
Definition: counter.qh:13
const int ACTIVE_ACTIVE
Definition: defs.qh:37
#define NULL
Definition: post.qh:17
float nextthink
Definition: csprogsdefs.qc:121
float count
Definition: powerups.qc:22
int active
Definition: defs.qh:34
#define new_pure(class)
purely logical entities (.origin doesn't work)
Definition: oo.qh:62
#define setthink(e, f)
#define use
Definition: csprogsdefs.qh:50
const int COUNTER_FIRE_AT_COUNT
Definition: counter.qh:12
float time
Definition: csprogsdefs.qc:16
#define IS_PLAYER(v)
Definition: utils.qh:9
var void func_null()