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
|
}
}
// if lineseg hits entity bounding box
static bool
intersect(DynamicEntity *d, const OFVector3D *from, const OFVector3D *to)
{
OFVector3D v = *to, w = d.o;
const OFVector3D *p;
vsub(v, *from);
vsub(w, *from);
float c1 = dotprod(w, v);
if (c1 <= 0)
p = from;
else {
float c2 = dotprod(v, v);
if (c2 <= c1)
p = to;
else {
float f = c1 / c2;
vmul(v, f);
vadd(v, *from);
p = &v;
}
}
return (p->x <= d.o.x + d.radius && p->x >= d.o.x - d.radius &&
p->y <= d.o.y + d.radius && p->y >= d.o.y - d.radius &&
p->z <= d.o.z + d.aboveeye && p->z >= d.o.z - d.eyeheight);
}
OFString *
playerincrosshair()
{
if (demoplayback)
return NULL;
for (id player in players) {
if (player == [OFNull null])
continue;
OFVector3D o = player1.o;
if (intersect(player, &o, &worldpos))
return [player name];
}
return nil;
}
|
|
|
|
>
|
|
|
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
|
}
}
// if lineseg hits entity bounding box
static bool
intersect(DynamicEntity *d, const OFVector3D *from, const OFVector3D *to)
{
OFVector3D v = *to, w = d.origin;
const OFVector3D *p;
vsub(v, *from);
vsub(w, *from);
float c1 = dotprod(w, v);
if (c1 <= 0)
p = from;
else {
float c2 = dotprod(v, v);
if (c2 <= c1)
p = to;
else {
float f = c1 / c2;
vmul(v, f);
vadd(v, *from);
p = &v;
}
}
return (p->x <= d.origin.x + d.radius &&
p->x >= d.origin.x - d.radius && p->y <= d.origin.y + d.radius &&
p->y >= d.origin.y - d.radius && p->z <= d.origin.z + d.aboveEye &&
p->z >= d.origin.z - d.eyeHeight);
}
OFString *
playerincrosshair()
{
if (demoplayback)
return NULL;
for (id player in players) {
if (player == [OFNull null])
continue;
OFVector3D o = player1.origin;
if (intersect(player, &o, &worldpos))
return [player name];
}
return nil;
}
|
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
return;
}
}
void
hit(int target, int damage, DynamicEntity *d, DynamicEntity *at)
{
OFVector3D o = d.o;
if (d == player1)
selfdamage(damage, at == player1 ? -1 : -2, at);
else if (d.monsterstate)
monsterpain(d, damage, at);
else {
addmsg(1, 4, SV_DAMAGE, target, damage, d.lifesequence);
playsound(S_PAIN1 + rnd(5), &o);
}
particle_splash(3, damage, 1000, &o);
demodamage(damage, &o);
}
const float RL_RADIUS = 5;
const float RL_DAMRAD = 7; // hack
static void
radialeffect(
DynamicEntity *o, const OFVector3D *v, int cn, int qdam, DynamicEntity *at)
{
if (o.state != CS_ALIVE)
return;
vdist(dist, temp, *v, o.o);
dist -= 2; // account for eye distance imprecision
if (dist < RL_DAMRAD) {
if (dist < 0)
dist = 0;
int damage = (int)(qdam * (1 - (dist / RL_DAMRAD)));
hit(cn, damage, o, at);
vmul(temp, (RL_DAMRAD - dist) * damage / 800);
vadd(o.vel, temp);
}
}
void
splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold,
int notthisplayer, int notthismonster, int qdam)
{
|
|
|
|
|
|
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
return;
}
}
void
hit(int target, int damage, DynamicEntity *d, DynamicEntity *at)
{
OFVector3D o = d.origin;
if (d == player1)
selfdamage(damage, at == player1 ? -1 : -2, at);
else if (d.monsterState)
monsterpain(d, damage, at);
else {
addmsg(1, 4, SV_DAMAGE, target, damage, d.lifeSequence);
playsound(S_PAIN1 + rnd(5), &o);
}
particle_splash(3, damage, 1000, &o);
demodamage(damage, &o);
}
const float RL_RADIUS = 5;
const float RL_DAMRAD = 7; // hack
static void
radialeffect(
DynamicEntity *o, const OFVector3D *v, int cn, int qdam, DynamicEntity *at)
{
if (o.state != CS_ALIVE)
return;
vdist(dist, temp, *v, o.origin);
dist -= 2; // account for eye distance imprecision
if (dist < RL_DAMRAD) {
if (dist < 0)
dist = 0;
int damage = (int)(qdam * (1 - (dist / RL_DAMRAD)));
hit(cn, damage, o, at);
vmul(temp, (RL_DAMRAD - dist) * damage / 800);
vadd(o.velocity, temp);
}
}
void
splash(Projectile *p, const OFVector3D *v, const OFVector3D *vold,
int notthisplayer, int notthismonster, int qdam)
{
|
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
{
for (size_t i = 0; i < MAXPROJ; i++) {
Projectile *p = projs[i];
if (!p.inuse)
continue;
int qdam = guns[p.gun].damage * (p.owner.quadmillis ? 4 : 1);
if (p.owner.monsterstate)
qdam /= MONSTERDAMAGEFACTOR;
vdist(dist, v, p.o, p.to);
float dtime = dist * 1000 / p.speed;
if (time > dtime)
dtime = time;
vmul(v, time / dtime);
vadd(v, p.o);
if (p.local) {
for (id player in players)
if (player != [OFNull null])
projdamage(player, p, &v, i, -1, qdam);
if (p.owner != player1)
projdamage(player1, p, &v, -1, -1, qdam);
for (DynamicEntity *monster in getmonsters())
if (!vreject(monster.o, v, 10.0f) &&
monster != p.owner)
projdamage(monster, p, &v, -1, i, qdam);
}
if (p.inuse) {
OFVector3D po = p.o;
if (time == dtime)
|
|
|
|
|
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
{
for (size_t i = 0; i < MAXPROJ; i++) {
Projectile *p = projs[i];
if (!p.inuse)
continue;
int qdam = guns[p.gun].damage * (p.owner.quadMillis ? 4 : 1);
if (p.owner.monsterState)
qdam /= MONSTERDAMAGEFACTOR;
vdist(dist, v, p.o, p.to);
float dtime = dist * 1000 / p.speed;
if (time > dtime)
dtime = time;
vmul(v, time / dtime);
vadd(v, p.o);
if (p.local) {
for (id player in players)
if (player != [OFNull null])
projdamage(player, p, &v, i, -1, qdam);
if (p.owner != player1)
projdamage(player1, p, &v, -1, -1, qdam);
for (DynamicEntity *monster in getmonsters())
if (!vreject(monster.origin, v, 10.0f) &&
monster != p.owner)
projdamage(monster, p, &v, -1, i, qdam);
}
if (p.inuse) {
OFVector3D po = p.o;
if (time == dtime)
|
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
break;
case GUN_RL:
case GUN_FIREBALL:
case GUN_ICEBALL:
case GUN_SLIMEBALL:
pspeed = guns[gun].projspeed;
if (d.monsterstate)
pspeed /= 2;
newprojectile(from, to, (float)pspeed, local, d, gun);
break;
case GUN_RIFLE:
particle_splash(0, 50, 200, to);
particle_trail(1, 500, from, to);
break;
}
}
void
hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
const OFVector3D *from, const OFVector3D *to)
{
hit(target, damage, d, at);
vdist(dist, v, *from, *to);
vmul(v, damage / dist / 50);
vadd(d.vel, v);
}
void
raydamage(DynamicEntity *o, const OFVector3D *from, const OFVector3D *to,
DynamicEntity *d, int i)
{
if (o.state != CS_ALIVE)
return;
int qdam = guns[d.gunselect].damage;
if (d.quadmillis)
qdam *= 4;
if (d.monsterstate)
qdam /= MONSTERDAMAGEFACTOR;
if (d.gunselect == GUN_SG) {
int damage = 0;
loop(r, SGRAYS) if (intersect(o, from, &sg[r])) damage += qdam;
if (damage)
hitpush(i, damage, o, d, from, to);
} else if (intersect(o, from, to))
hitpush(i, qdam, o, d, from, to);
}
void
shoot(DynamicEntity *d, const OFVector3D *targ)
{
int attacktime = lastmillis - d.lastaction;
if (attacktime < d.gunwait)
return;
d.gunwait = 0;
if (!d.attacking)
return;
d.lastaction = lastmillis;
d.lastattackgun = d.gunselect;
if (!d.ammo[d.gunselect]) {
playsoundc(S_NOAMMO);
d.gunwait = 250;
d.lastattackgun = -1;
return;
}
if (d.gunselect)
d.ammo[d.gunselect]--;
OFVector3D from = d.o;
OFVector3D to = *targ;
from.z -= 0.2f; // below eye
vdist(dist, unitv, from, to);
vdiv(unitv, dist);
OFVector3D kickback = unitv;
vmul(kickback, guns[d.gunselect].kickamount * -0.01f);
vadd(d.vel, kickback);
if (d.pitch < 80.0f)
d.pitch += guns[d.gunselect].kickamount * 0.05f;
if (d.gunselect == GUN_FIST || d.gunselect == GUN_BITE) {
vmul(unitv, 3); // punch range
to = from;
vadd(to, unitv);
}
if (d.gunselect == GUN_SG)
createrays(&from, &to);
if (d.quadmillis && attacktime > 200)
playsoundc(S_ITEMPUP);
shootv(d.gunselect, &from, &to, d, true);
if (!d.monsterstate)
addmsg(1, 8, SV_SHOT, d.gunselect, (int)(from.x * DMF),
(int)(from.y * DMF), (int)(from.z * DMF), (int)(to.x * DMF),
(int)(to.y * DMF), (int)(to.z * DMF));
d.gunwait = guns[d.gunselect].attackdelay;
if (guns[d.gunselect].projspeed)
return;
[players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) {
if (player != [OFNull null])
raydamage(player, &from, &to, d, i);
}];
for (DynamicEntity *monster in getmonsters())
if (monster != d)
raydamage(monster, &from, &to, d, -2);
if (d.monsterstate)
raydamage(player1, &from, &to, d, -1);
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
break;
case GUN_RL:
case GUN_FIREBALL:
case GUN_ICEBALL:
case GUN_SLIMEBALL:
pspeed = guns[gun].projspeed;
if (d.monsterState)
pspeed /= 2;
newprojectile(from, to, (float)pspeed, local, d, gun);
break;
case GUN_RIFLE:
particle_splash(0, 50, 200, to);
particle_trail(1, 500, from, to);
break;
}
}
void
hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
const OFVector3D *from, const OFVector3D *to)
{
hit(target, damage, d, at);
vdist(dist, v, *from, *to);
vmul(v, damage / dist / 50);
vadd(d.velocity, v);
}
void
raydamage(DynamicEntity *o, const OFVector3D *from, const OFVector3D *to,
DynamicEntity *d, int i)
{
if (o.state != CS_ALIVE)
return;
int qdam = guns[d.gunSelect].damage;
if (d.quadMillis)
qdam *= 4;
if (d.monsterState)
qdam /= MONSTERDAMAGEFACTOR;
if (d.gunSelect == GUN_SG) {
int damage = 0;
loop(r, SGRAYS) if (intersect(o, from, &sg[r])) damage += qdam;
if (damage)
hitpush(i, damage, o, d, from, to);
} else if (intersect(o, from, to))
hitpush(i, qdam, o, d, from, to);
}
void
shoot(DynamicEntity *d, const OFVector3D *targ)
{
int attacktime = lastmillis - d.lastAction;
if (attacktime < d.gunWait)
return;
d.gunWait = 0;
if (!d.attacking)
return;
d.lastAction = lastmillis;
d.lastAttackGun = d.gunSelect;
if (!d.ammo[d.gunSelect]) {
playsoundc(S_NOAMMO);
d.gunWait = 250;
d.lastAttackGun = -1;
return;
}
if (d.gunSelect)
d.ammo[d.gunSelect]--;
OFVector3D from = d.origin;
OFVector3D to = *targ;
from.z -= 0.2f; // below eye
vdist(dist, unitv, from, to);
vdiv(unitv, dist);
OFVector3D kickback = unitv;
vmul(kickback, guns[d.gunSelect].kickamount * -0.01f);
vadd(d.velocity, kickback);
if (d.pitch < 80.0f)
d.pitch += guns[d.gunSelect].kickamount * 0.05f;
if (d.gunSelect == GUN_FIST || d.gunSelect == GUN_BITE) {
vmul(unitv, 3); // punch range
to = from;
vadd(to, unitv);
}
if (d.gunSelect == GUN_SG)
createrays(&from, &to);
if (d.quadMillis && attacktime > 200)
playsoundc(S_ITEMPUP);
shootv(d.gunSelect, &from, &to, d, true);
if (!d.monsterState)
addmsg(1, 8, SV_SHOT, d.gunSelect, (int)(from.x * DMF),
(int)(from.y * DMF), (int)(from.z * DMF), (int)(to.x * DMF),
(int)(to.y * DMF), (int)(to.z * DMF));
d.gunWait = guns[d.gunSelect].attackdelay;
if (guns[d.gunSelect].projspeed)
return;
[players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) {
if (player != [OFNull null])
raydamage(player, &from, &to, d, i);
}];
for (DynamicEntity *monster in getmonsters())
if (monster != d)
raydamage(monster, &from, &to, d, -2);
if (d.monsterState)
raydamage(player1, &from, &to, d, -1);
}
|