-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTURRET.QC
155 lines (120 loc) · 2.98 KB
/
TURRET.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*=============================
Turrets
This file contains all information required
to handle turrets. Some changes may have
to be made in ClientObituary().
=============================*/
float TURRET_INSTANT_FIRE = 1;
float TURRET_EXPLOSIVE_FIRE = 2;
void() turret_scanthink;
void() turret_attackthink;
void() turret_fire;
void() turret_projectiletouch;
void() turret_normal =
{
self.solid = SOLID_SLIDEBOX;
self.movetype = MOVETYPE_NONE;
precache_sound("enforcer/enfire.wav");
// set the defaults
if (!(self.model))
self.model = "progs/v_rock2.mdl";
if (!(self.health))
self.health = -1;
if (!(self.search_time))
self.search_time = 5;
if (!(self.speed))
self.speed = 0.2;
if (!(self.dmg))
self.dmg = 5;
self.weaponmodel = "progs/laser.mdl";
// if no weapon model, it must be instantaneous fire
if (!(self.weaponmodel))
self.spawnflags = self.spawnflags | TURRET_INSTANT_FIRE;
if (!(self.ammo_shells))
self.ammo_shells = -1;
if (!(self.currentammo))
self.currentammo = self.ammo_shells;
if (!(self.wait))
self.wait = -1;
if (!(self.lives))
self.lives = -1;
if (!(self.team_no))
self.team_no = -1;
if (!(self.numflames))
self.numflames = 1;
// projectile speed
if (!(self.aflag))
self.aflag = 1200;
// this is the radius damage done
if (self.all_active)
self.spawnflags = self.spawnflags | TURRET_EXPLOSIVE_FIRE;
setmodel(self, self.model);
setorigin(self, self.origin);
self.nextthink = time + 5; // don't come online for 5 seconds
self.think = turret_scanthink;
};
// scans for enemies
// don't do it too often
void() turret_scanthink =
{
local entity search;
bprint("t: scanning..\n");
search = checkclient();
if (visible(search) && search.health > 1)
{
// locked onto target
self.enemy = search;
self.think = turret_attackthink;
self.nextthink = 0.1;
return;
}
self.nextthink = time + self.search_time;
};
// attacks the same enemy repeatedly
void() turret_attackthink =
{
if (visible(self.enemy) && self.enemy.health > 1)
{
bprint("t: attacking..\n");
turret_fire();
// set angle to face the enemy
}
else
{
self.think = turret_scanthink;
}
self.nextthink = time + self.speed;
};
// fires the turret
void() turret_fire =
{
/* if (self.spawnflags & TURRET_INSTANT_FIRE)
{
// fire instant weapon
}
else
*/// {
newmis = spawn();
sound (self, CHAN_WEAPON, "enforcer/enfire.wav", 1, ATTN_NORM);
setorigin(newmis, self.origin + dir * 48);
setmodel(newmis, self.weaponmodel);
newmis.movetype = MOVETYPE_FLY;
newmis.solid = SOLID_BBOX;
newmis.effects = EF_DIMLIGHT;
newmis.velocity = normalize(self.enemy.origin - self.origin) * self.aflag;
newmis.dmg = self.dmg;
newmis.angles = vectoangles(newmis.velocity);
newmis.touch = turret_projectiletouch;
newmis.owner = self;
newmis.think = SUB_Remove;
newmis.nextthink = time + 5; // remove projectile after 5 seconds
// }
};
void() turret_projectiletouch =
{
if (other.takedamage)
{
T_Damage(other, self, self.owner, self.dmg);
}
remove(self);
};