1 /*
2 lights.c
3 */
4 #include "g_local.h"
5
6 /*
7 8===============>
8 FL_make
9 make the dang thing
10 <===============8
11 */
12
FL_make(edict_t * self)13 void FL_make(edict_t *self)
14 {
15 vec3_t start,forward,right,end;
16 int color;
17
18 if ( self->flashlight )
19 {
20 G_FreeEdict(self->flashlight);
21 self->flashlight = NULL;
22 return;
23 }
24
25 AngleVectors (self->client->v_angle, forward, right, NULL);
26
27 VectorSet(end,100 , 0, 0);
28 G_ProjectSource (self->s.origin, end, forward, right, start);
29
30 self->flashlight = G_Spawn ();
31 self->flashlight->owner = self;
32 self->flashlight->movetype = MOVETYPE_NOCLIP;
33 self->flashlight->solid = SOLID_NOT;
34 self->flashlight->classname = "flashlight";
35 self->flashlight->s.modelindex = gi.modelindex ("sprites/null/null.sp2");
36 self->flashlight->s.skinnum = 0;
37
38 //4 possible colors for flashlight
39 if (flashlight_color->value == 2) {
40 self->flashlight->s.effects = EF_BFG; //Green
41 gi.cprintf (self, PRINT_HIGH, "Green flashlight on.\n");
42 }
43 else if (flashlight_color->value == 3) {
44 self->flashlight->s.effects = EF_FLAG1; //Red
45 gi.cprintf (self, PRINT_HIGH, "Red flashlight on.\n");
46 } //particles
47 else if (flashlight_color->value == 4) {
48 self->flashlight->s.effects = EF_FLAG2; //Blue
49 gi.cprintf (self, PRINT_HIGH, "Blue flashlight on.\n");
50 }
51 else {
52 self->flashlight->s.effects = EF_HYPERBLASTER; //Yellow
53 gi.cprintf (self, PRINT_HIGH, "Flashlight on.\n");
54 }
55 self->flashlight->think = FL_think;
56 self->flashlight->nextthink = level.time + 0.1;
57 }
58
59
60
61 /*
62 8===============>
63 FL_make
64 make the dang thing
65 <===============8
66 */
67
FL_think(edict_t * self)68 void FL_think (edict_t *self)
69 {
70 vec3_t start,end,endp,offset;
71 vec3_t forward,right,up;
72 trace_t tr;
73
74 AngleVectors (self->owner->client->v_angle, forward, right, up);
75
76 VectorSet(offset,24 , 6, self->owner->viewheight-7);
77 G_ProjectSource (self->owner->s.origin, offset, forward, right, start);
78 VectorMA(start,8192,forward,end);
79
80 tr = gi.trace (start,NULL,NULL, end,self->owner,CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_DEADMONSTER);
81
82 if (tr.fraction != 1)
83 {
84 VectorMA(tr.endpos,-4,forward,endp);
85 VectorCopy(endp,tr.endpos);
86 }
87
88 if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client))
89 {
90 if ((tr.ent->takedamage) && (tr.ent != self->owner))
91 {
92 self->s.skinnum = 1;
93 }
94 }
95 else
96 self->s.skinnum = 0;
97
98 vectoangles(tr.plane.normal,self->s.angles);
99 VectorCopy(tr.endpos,self->s.origin);
100
101 gi.linkentity (self);
102 self->nextthink = level.time + 0.1;
103 }
104
elecshock(edict_t * ent)105 void elecshock(edict_t *ent)
106 {
107 int i;
108
109 ent->client->elec_shock_framenum-=1; // subtracts 1 from elec_shock_framenum
110 if (ent->client->elec_shock_framenum>0) // in case I screwed up and this gets called without the person being shocked.
111 {
112 ent->s.effects |= EF_COLOR_SHELL;
113 ent->s.renderfx |= RF_SHELL_BLUE; // these two lines add a blue shell to the person.
114 for (i=0 ; i<3 ; i++)
115 {
116 ent->client->kick_origin[i] = crandom() * 0.35;
117 ent->client->kick_angles[i] = crandom() * 0.7; // make the screen shake increase the multiplier fo the angles for a greater shaking effect
118 }
119 // unfortunatly you have to add the blueness to thier screen elsewhere (in p_view.c)
120 }
121 else
122 {
123 // the last frame will clean up all the effects
124 ent->s.effects &= ~EF_COLOR_SHELL;
125 ent->s.renderfx &= ~RF_SHELL_RED;
126 }
127 }
128 /*----------------------------------------
129 SP_LaserSight
130
131 Create/remove the laser sight entity
132 -----------------------------------------*/
133
134 #define lss self->lasersight
135
SP_LaserSight(edict_t * self)136 void SP_LaserSight(edict_t *self) {
137
138 vec3_t start,forward,right,end;
139
140 if ( lss ) {
141 G_FreeEdict(lss);
142 lss = NULL;
143 gi.bprintf (PRINT_HIGH, "lasersight off.");
144 return;
145 }
146
147 gi.bprintf (PRINT_HIGH, "lasersight on.");
148
149 AngleVectors (self->client->v_angle, forward, right, NULL);
150
151 VectorSet(end,100 , 0, 0);
152 G_ProjectSource (self->s.origin, end, forward, right, start);
153
154 lss = G_Spawn ();
155 lss->owner = self;
156 lss->movetype = MOVETYPE_NOCLIP;
157 lss->solid = SOLID_NOT;
158 lss->classname = "lasersight";
159 lss->s.modelindex = gi.modelindex ("sprites/null/null.sp2");
160 lss->s.effects |= EF_IONRIPPER;
161 lss->s.skinnum = 0;
162
163 lss->s.renderfx |= RF_FULLBRIGHT;
164
165 lss->think = LaserSightThink;
166 lss->nextthink = level.time + 0.1;
167 }
168
169
170 /*---------------------------------------------
171 LaserSightThink
172
173 Updates the sights position, angle, and shape
174 is the lasersight entity
175 ---------------------------------------------*/
176
LaserSightThink(edict_t * self)177 void LaserSightThink (edict_t *self)
178 {
179 vec3_t start,end,endp,offset;
180 vec3_t forward,right,up;
181 trace_t tr;
182
183 AngleVectors (self->owner->client->v_angle, forward, right, up);
184
185 VectorSet(offset,24 , 6, self->owner->viewheight-7);
186 G_ProjectSource (self->owner->s.origin, offset, forward, right, start);
187 VectorMA(start,8192,forward,end);
188
189 tr = gi.trace (start,NULL,NULL, end,self->owner,CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_DEADMONSTER);
190
191 if (tr.fraction != 1) {
192 VectorMA(tr.endpos,-4,forward,endp);
193 VectorCopy(endp,tr.endpos);
194 }
195
196 if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client)){
197 if ((tr.ent->takedamage) && (tr.ent != self->owner)) {
198 self->s.skinnum = 1;
199 }
200 }
201 else
202 self->s.skinnum = 0;
203
204 vectoangles(tr.plane.normal,self->s.angles);
205 VectorCopy(tr.endpos,self->s.origin);
206
207 gi.linkentity (self);
208 self->nextthink = level.time + 0.1;
209 }
210