]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/counter.qc
Merge branch 'master' into terencehill/bot_waypoints
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / trigger / counter.qc
1 #include "counter.qh"
2 #ifdef SVQC
3 void counter_reset(entity this);
4
5 void counter_use(entity this, entity actor, entity trigger)
6 {
7         entity store = this;
8         if(this.spawnflags & COUNTER_PER_PLAYER) // FIXME: multiple counters in the map will not function correctly, and upon trigger reset the player won't be able to use it again!
9         {
10                 if(!IS_PLAYER(actor))
11                         return;
12                 store = actor;
13         }
14
15         store.counter_cnt += 1;
16         if (store.counter_cnt > this.count)
17                 return;
18
19         bool doactivate = (this.spawnflags & COUNTER_FIRE_AT_COUNT);
20
21         if (store.counter_cnt == this.count)
22         {
23                 if(IS_PLAYER(actor) && !(this.spawnflags & SPAWNFLAG_NOMESSAGE))
24                         Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COMPLETED);
25
26                 doactivate = true;
27
28                 if(this.respawntime)
29                 {
30                         setthink(this, counter_reset);
31                         this.nextthink = time + this.respawntime;
32                 }
33         }
34         else
35         {
36                 if(IS_PLAYER(actor) && !(this.spawnflags & SPAWNFLAG_NOMESSAGE))
37                 {
38                         if((this.count - store.counter_cnt) >= 4)
39                                 Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER);
40                         else
41                                 Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER_FEWMORE, this.count - store.counter_cnt);
42                 }
43         }
44
45         if(doactivate)
46                 SUB_UseTargets(this, actor, trigger);
47 }
48
49 void counter_reset(entity this)
50 {
51         setthink(this, func_null);
52         this.nextthink = 0;
53         this.counter_cnt = 0;
54 }
55
56 /*QUAKED spawnfunc_trigger_counter (.5 .5 .5) ? nomessage COUNTER_FIRE_AT_COUNT
57 Acts as an intermediary for an action that takes multiple inputs.
58
59 If nomessage is not set, it will print "1 more.. " etc when triggered and "sequence complete" when finished.
60 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
61
62 If respawntime is set, it will re-enable itself after the time once the sequence has been completed
63
64 After the counter has been triggered "count" times (default 2), it will fire all of its targets.
65 */
66 spawnfunc(trigger_counter)
67 {
68         if (!this.count)
69                 this.count = 2;
70
71         this.counter_cnt = 0;
72         this.use = counter_use;
73         this.reset = counter_reset;
74 }
75 #endif