forked from QwazyWabbitWOS/W-O-R-Rampage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflashlight.c
141 lines (125 loc) · 3.97 KB
/
flashlight.c
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
//****************************************************
// Flashlight
//****************************************************
#include "g_local.h"
void FlashlightReset(edict_t* self)
{
if (self->owner->client && self->owner->client->flashlight)
{
float volume = 1.0f;
if (self->owner->client->silencer_shots)
volume = 0.2f;
gi.sound(self->owner, CHAN_AUTO, gi.soundindex("misc/flashlight.wav"), volume, ATTN_NORM, 0.0f);
self->owner->client->flashlight = NULL;
self->owner->client->flashtype = 0;
}
G_FreeEdict(self);
}
void flashlight_think(edict_t* self)
{
vec3_t forward, right, up, offset, start, end;
trace_t tr;
int content = (CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_DEADMONSTER);
if (level.intermissiontime || !self->owner->inuse || self->owner->deadflag)
{
FlashlightReset(self);
return;
}
AngleVectors(self->owner->client->v_angle, forward, right, up);
VectorSet(offset, 0, 8, self->owner->viewheight - 8.0f);
P_ProjectSource(self->owner->client, self->owner->s.origin, offset, forward, right, start);
VectorMA(start, 8192, forward, end);
tr = gi.trace(start, NULL, NULL, end, self->owner, content);
if (flashlightmode->value)
self->svflags &= ~SVF_NOCLIENT;
else
{
if (!((tr.surface) && (tr.surface->flags & SURF_SKY)) && tr.fraction < 1.0)
self->svflags &= ~SVF_NOCLIENT;
else
self->svflags |= SVF_NOCLIENT;
}
vectoangles(tr.plane.normal, self->s.angles);
VectorCopy(tr.endpos, self->s.origin);
self->nextthink = level.time + FRAMETIME;
if (flashlightmode->value)
{
//QW// new, nice white flashlight
gi.WriteByte(svc_temp_entity);
gi.WriteByte(TE_FLASHLIGHT);
gi.WritePosition(self->s.origin);
gi.WriteShort(self - g_edicts);
gi.multicast(self->s.origin, MULTICAST_PVS);
}
gi.linkentity(self);
}
void Use_Flashlight(edict_t* player)
{
if (player->client->flashlight)
{
if (player->client->flashtype == 0)
{
player->client->flashtype = 1;
player->client->flashlight->s.effects = 0;
player->client->flashlight->s.renderfx = RF_TRANSLUCENT;
gi.linkentity(player->client->flashlight);
}
else if (player->client->flashtype == 1)
{
player->client->flashtype = 2;
player->client->flashlight->s.effects = EF_HYPERBLASTER;
gi.linkentity(player->client->flashlight);
}
else
{
player->client->flashtype = 0;
FlashlightReset(player->client->flashlight);
}
}
else
{
float volume = 1.0;
if (player->client->silencer_shots)
volume = 0.2f;
gi.sound(player, CHAN_AUTO, gi.soundindex("misc/flashlight.wav"), volume, ATTN_NORM, 0);
player->client->flashlight = G_Spawn();
VectorCopy(player->s.origin, player->client->flashlight->s.origin);
player->client->flashlight->movetype = MOVETYPE_NOCLIP;
player->client->flashlight->clipmask = MASK_SHOT;
player->client->flashlight->solid = SOLID_NOT;
player->client->flashlight->owner = player;
player->client->flashlight->nextthink = level.time + FRAMETIME;
player->client->flashlight->think = flashlight_think;
player->client->flashlight->classname = "flashlight";
player->client->flashlight->svflags = SVF_NOCLIENT;
player->client->flashlight->s.frame = 0;
player->client->flashlight->s.skinnum = 0;
player->client->flashlight->s.modelindex = 0;
VectorClear(player->client->flashlight->mins);
VectorClear(player->client->flashlight->maxs);
if (flashlightmode->value == 0)
{
//QW// old, dim flashlight
player->client->flashlight->s.effects = EF_HYPERBLASTER;
player->client->flashlight->s.renderfx |= RF_TRANSLUCENT;
player->client->flashlight->s.renderfx |= RF_FULLBRIGHT;
player->client->flashlight->s.modelindex = gi.modelindex("models/objects/dummy/tris.md2");
}
gi.linkentity(player->client->flashlight);
}
}
void Cmd_Flashlight(edict_t* ent)
{
if (!ent->client || ent->health <= 0)
return;
if (ent->client->flashlight == NULL)
{
gi.cprintf(ent, PRINT_HIGH, "Flashlight On\n");
Use_Flashlight(ent);
}
else
{
gi.cprintf(ent, PRINT_HIGH, "Flashlight Off\n");
FlashlightReset(ent->client->flashlight);
}
}