~agrip-hackers/sns/trunk

« back to all changes in this revision

Viewing changes to zq-repo/qc/qw/buttons.qc

  • Committer: Matthew Tylee Atkinson
  • Date: 2008-03-07 20:15:20 UTC
  • Revision ID: mta@agrip.org.uk-20080307201520-uj9sa2jrytx91b2t
Remove non-SNS components.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
        buttons.qc
3
 
 
4
 
        button and multiple button
5
 
 
6
 
        Copyright (C) 1996-1997  Id Software, Inc.
7
 
 
8
 
        This program is free software; you can redistribute it and/or
9
 
        modify it under the terms of the GNU General Public License
10
 
        as published by the Free Software Foundation; either version 2
11
 
        of the License, or (at your option) any later version.
12
 
 
13
 
        This program is distributed in the hope that it will be useful,
14
 
        but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 
 
17
 
        See the GNU General Public License for more details.
18
 
 
19
 
        You should have received a copy of the GNU General Public License
20
 
        along with this program; if not, write to:
21
 
 
22
 
                Free Software Foundation, Inc.
23
 
                59 Temple Place - Suite 330
24
 
                Boston, MA  02111-1307, USA
25
 
 
26
 
*/
27
 
 
28
 
void button_return ();
29
 
 
30
 
void button_wait ()
31
 
{
32
 
        self.state = STATE_TOP;
33
 
        self.nextthink = self.ltime + self.wait;
34
 
        self.think = button_return;
35
 
        activator = self.enemy;
36
 
        SUB_UseTargets();
37
 
        self.frame = 1;                 // use alternate textures
38
 
}
39
 
 
40
 
void button_done ()
41
 
{
42
 
        self.state = STATE_BOTTOM;
43
 
}
44
 
 
45
 
void button_return ()
46
 
{
47
 
        self.state = STATE_DOWN;
48
 
        SUB_CalcMove (self.pos1, self.speed, button_done);
49
 
        self.frame = 0;                 // use normal textures
50
 
        if (self.health)
51
 
                self.takedamage = DAMAGE_YES;   // can be shot again
52
 
}
53
 
 
54
 
 
55
 
void button_blocked ()
56
 
{       // do nothing, just don't come all the way back out
57
 
}
58
 
 
59
 
 
60
 
void button_fire ()
61
 
{
62
 
        if (self.state == STATE_UP || self.state == STATE_TOP)
63
 
                return;
64
 
 
65
 
        sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
66
 
 
67
 
        self.state = STATE_UP;
68
 
        SUB_CalcMove (self.pos2, self.speed, button_wait);
69
 
}
70
 
 
71
 
 
72
 
void button_use ()
73
 
{
74
 
        self.enemy = activator;
75
 
        button_fire ();
76
 
}
77
 
 
78
 
void button_touch ()
79
 
{
80
 
        if (other.classname != "player")
81
 
                return;
82
 
        self.enemy = other;
83
 
        button_fire ();
84
 
}
85
 
 
86
 
void button_killed ()
87
 
{
88
 
        self.enemy = damage_attacker;
89
 
        self.health = self.max_health;
90
 
        self.takedamage = DAMAGE_NO;    // wil be reset upon return
91
 
        button_fire ();
92
 
}
93
 
 
94
 
 
95
 
/*QUAKED func_button (0 .5 .8) ?
96
 
When a button is touched, it moves some distance in the direction of its angle, triggers all of its targets, waits some time, then returns to its original position where it can be triggered again.
97
 
 
98
 
"angle"         determines the opening direction
99
 
"target"        all entities with a matching targetname will be used
100
 
"speed"         override the default 40 speed
101
 
"wait"          override the default 1 second wait (-1 = never return)
102
 
"lip"           override the default 4 pixel lip remaining at end of move
103
 
"health"        if set, the button must be killed instead of touched
104
 
"sounds"
105
 
0) steam metal
106
 
1) wooden clunk
107
 
2) metallic click
108
 
3) in-out
109
 
*/
110
 
void func_button ()
111
 
{
112
 
        if (self.sounds == 0)
113
 
        {
114
 
                precache_sound ("buttons/airbut1.wav");
115
 
                self.noise = "buttons/airbut1.wav";
116
 
        }
117
 
        if (self.sounds == 1)
118
 
        {
119
 
                precache_sound ("buttons/switch21.wav");
120
 
                self.noise = "buttons/switch21.wav";
121
 
        }
122
 
        if (self.sounds == 2)
123
 
        {
124
 
                precache_sound ("buttons/switch02.wav");
125
 
                self.noise = "buttons/switch02.wav";
126
 
        }
127
 
        if (self.sounds == 3)
128
 
        {
129
 
                precache_sound ("buttons/switch04.wav");
130
 
                self.noise = "buttons/switch04.wav";
131
 
        }
132
 
 
133
 
        SetMovedir ();
134
 
 
135
 
        self.movetype = MOVETYPE_PUSH;
136
 
        self.solid = SOLID_BSP;
137
 
        setmodel (self, self.model);
138
 
 
139
 
        self.blocked = button_blocked;
140
 
        self.use = button_use;
141
 
 
142
 
        if (self.health)
143
 
        {
144
 
                self.max_health = self.health;
145
 
                self.th_die = button_killed;
146
 
                self.takedamage = DAMAGE_YES;
147
 
        }
148
 
        else
149
 
                self.touch = button_touch;
150
 
 
151
 
        if (!self.speed)
152
 
                self.speed = 40;
153
 
        if (!self.wait)
154
 
                self.wait = 1;
155
 
        if (!self.lip)
156
 
                self.lip = 4;
157
 
 
158
 
        self.state = STATE_BOTTOM;
159
 
 
160
 
        self.pos1 = self.origin;
161
 
        self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
162
 
}
163