-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathfunc_bob.qc
134 lines (110 loc) · 3.29 KB
/
func_bob.qc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* Copyright (C) 1996-2022 id Software LLC
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
See file, 'COPYING', for details.
*/
const float FUNC_BOB_NONSOLID = 1;
const float FUNC_BOB_START_ON = 2;
const float FUNC_BOB_THINKINTERVAL = 0.05;
vector func_bob_GetPositionForAngle(float an)
{
self.count += (an);
self.count = mod(self.count, 360);
float dd = sin(self.count);
vector offs = self.dest * dd;
if(self.dest2)
{
float ddc = cos(self.count);
offs+= (self.dest2 * ddc);
}
return offs;
}
void func_bob_blocked()
{
if(self.attack_finished > time) return;
T_Damage(other, self, self, self.dmg);
self.attack_finished = time + 0.5;
}
/*
We have two different strategies for movement here.
For solid bobbers, we use the think function and set a velocity. This allows us to stand smoothly on the bobber and be blocked by it.
For non solid bobbers, the engine does not like having something nonsolid that moves apparently, so instead we just set its position each frame.
*/
// Used by non-solid bobbers
void func_bob_tick(float dt)
{
vector offs = func_bob_GetPositionForAngle(self.avelocity_x * dt);
setorigin(self, offs);
}
// Used by solid bobbers
void func_bob_think()
{
vector offs = func_bob_GetPositionForAngle(self.avelocity_x * FUNC_BOB_THINKINTERVAL);
vector diff = offs - self.origin;
self.velocity = diff * (1/FUNC_BOB_THINKINTERVAL);
self.nextthink = self.ltime + FUNC_BOB_THINKINTERVAL;
}
void func_bob_use()
{
if(self.state)
{
if(self.solid)
{
self.velocity = '0 0 0';
self.nextthink = -1;
}
else
{
RemoveFrameTickEntity(self);
}
}
else
{
if(self.solid)
{
func_bob_think();
}
else
{
RegisterFrameTickEntity(self);
}
}
self.state = 1 - self.state;
}
void func_bob()
{
setmodel(self, self.model);
setorigin(self, self.origin);
if(!self.dest) self.dest = '0 0 64';
if(!self.wait) self.wait = 10;
if(!self.dmg) self.dmg = 1;
self.avelocity_x = 360 / self.wait;
self.count = 360 * self.delay;
self.use = func_bob_use;
self.tick = func_bob_tick;
self.think = func_bob_think;
self.blocked = func_bob_blocked;
if(self.spawnflags & FUNC_BOB_NONSOLID)
{
self.movetype = MOVETYPE_NONE;
self.solid = SOLID_NOT;
}
else
{
self.movetype = MOVETYPE_PUSH;
self.solid = SOLID_BSP;
}
if(self.spawnflags & FUNC_BOB_START_ON)
{
func_bob_use();
}
}