Convert dynent to a class
FossilOrigin-Name: d2b3ff790fee10ef4150cdb17f1c979e7001a420b2629b153b4dbf4c0b489704
This commit is contained in:
parent
410e244ed6
commit
90fc249052
26 changed files with 1447 additions and 1061 deletions
218
src/weapon.mm
218
src/weapon.mm
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "cube.h"
|
||||
|
||||
#import "DynamicEntity.h"
|
||||
#import "Projectile.h"
|
||||
|
||||
static const int MONSTERDAMAGEFACTOR = 4;
|
||||
|
@ -30,26 +31,26 @@ selectgun(int a, int b, int c)
|
|||
if (a < -1 || b < -1 || c < -1 || a >= NUMGUNS || b >= NUMGUNS ||
|
||||
c >= NUMGUNS)
|
||||
return;
|
||||
int s = player1->gunselect;
|
||||
if (a >= 0 && s != a && player1->ammo[a])
|
||||
int s = player1.gunselect;
|
||||
if (a >= 0 && s != a && player1.ammo[a])
|
||||
s = a;
|
||||
else if (b >= 0 && s != b && player1->ammo[b])
|
||||
else if (b >= 0 && s != b && player1.ammo[b])
|
||||
s = b;
|
||||
else if (c >= 0 && s != c && player1->ammo[c])
|
||||
else if (c >= 0 && s != c && player1.ammo[c])
|
||||
s = c;
|
||||
else if (s != GUN_RL && player1->ammo[GUN_RL])
|
||||
else if (s != GUN_RL && player1.ammo[GUN_RL])
|
||||
s = GUN_RL;
|
||||
else if (s != GUN_CG && player1->ammo[GUN_CG])
|
||||
else if (s != GUN_CG && player1.ammo[GUN_CG])
|
||||
s = GUN_CG;
|
||||
else if (s != GUN_SG && player1->ammo[GUN_SG])
|
||||
else if (s != GUN_SG && player1.ammo[GUN_SG])
|
||||
s = GUN_SG;
|
||||
else if (s != GUN_RIFLE && player1->ammo[GUN_RIFLE])
|
||||
else if (s != GUN_RIFLE && player1.ammo[GUN_RIFLE])
|
||||
s = GUN_RIFLE;
|
||||
else
|
||||
s = GUN_FIST;
|
||||
if (s != player1->gunselect)
|
||||
if (s != player1.gunselect)
|
||||
playsoundc(S_WEAPLOAD);
|
||||
player1->gunselect = s;
|
||||
player1.gunselect = s;
|
||||
// conoutf(@"%@ selected", (int)guns[s].name);
|
||||
}
|
||||
|
||||
|
@ -85,9 +86,9 @@ createrays(OFVector3D &from,
|
|||
|
||||
// if lineseg hits entity bounding box
|
||||
bool
|
||||
intersect(dynent *d, const OFVector3D &from, const OFVector3D &to)
|
||||
intersect(DynamicEntity *d, const OFVector3D &from, const OFVector3D &to)
|
||||
{
|
||||
OFVector3D v = to, w = d->o;
|
||||
OFVector3D v = to, w = d.o;
|
||||
const OFVector3D *p;
|
||||
vsub(v, from);
|
||||
vsub(w, from);
|
||||
|
@ -107,9 +108,9 @@ intersect(dynent *d, const OFVector3D &from, const OFVector3D &to)
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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 *
|
||||
|
@ -117,13 +118,13 @@ playerincrosshair()
|
|||
{
|
||||
if (demoplayback)
|
||||
return NULL;
|
||||
loopv(players)
|
||||
{
|
||||
dynent *o = players[i];
|
||||
if (!o)
|
||||
|
||||
for (id player in players) {
|
||||
if (player == [OFNull null])
|
||||
continue;
|
||||
if (intersect(o, player1->o, worldpos))
|
||||
return @(o->name);
|
||||
|
||||
if (intersect(player, player1.o, worldpos))
|
||||
return [player name];
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
@ -141,7 +142,7 @@ projreset()
|
|||
|
||||
void
|
||||
newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
|
||||
dynent *owner, int gun)
|
||||
DynamicEntity *owner, int gun)
|
||||
{
|
||||
for (size_t i = 0; i < MAXPROJ; i++) {
|
||||
Projectile *p = projs[i];
|
||||
|
@ -161,29 +162,31 @@ newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
|
|||
}
|
||||
|
||||
void
|
||||
hit(int target, int damage, dynent *d, dynent *at)
|
||||
hit(int target, int damage, DynamicEntity *d, DynamicEntity *at)
|
||||
{
|
||||
if (d == player1)
|
||||
selfdamage(damage, at == player1 ? -1 : -2, at);
|
||||
else if (d->monsterstate)
|
||||
else if (d.monsterstate)
|
||||
monsterpain(d, damage, at);
|
||||
else {
|
||||
addmsg(1, 4, SV_DAMAGE, target, damage, d->lifesequence);
|
||||
playsound(S_PAIN1 + rnd(5), &d->o);
|
||||
addmsg(1, 4, SV_DAMAGE, target, damage, d.lifesequence);
|
||||
OFVector3D loc = d.o;
|
||||
playsound(S_PAIN1 + rnd(5), &loc);
|
||||
}
|
||||
particle_splash(3, damage, 1000, d->o);
|
||||
demodamage(damage, d->o);
|
||||
particle_splash(3, damage, 1000, d.o);
|
||||
demodamage(damage, d.o);
|
||||
}
|
||||
|
||||
const float RL_RADIUS = 5;
|
||||
const float RL_DAMRAD = 7; // hack
|
||||
|
||||
static void
|
||||
radialeffect(dynent *o, const OFVector3D &v, int cn, int qdam, dynent *at)
|
||||
radialeffect(
|
||||
DynamicEntity *o, const OFVector3D &v, int cn, int qdam, DynamicEntity *at)
|
||||
{
|
||||
if (o->state != CS_ALIVE)
|
||||
if (o.state != CS_ALIVE)
|
||||
return;
|
||||
vdist(dist, temp, v, o->o);
|
||||
vdist(dist, temp, v, o.o);
|
||||
dist -= 2; // account for eye distance imprecision
|
||||
if (dist < RL_DAMRAD) {
|
||||
if (dist < 0)
|
||||
|
@ -191,7 +194,7 @@ radialeffect(dynent *o, const OFVector3D &v, int cn, int qdam, dynent *at)
|
|||
int damage = (int)(qdam * (1 - (dist / RL_DAMRAD)));
|
||||
hit(cn, damage, o, at);
|
||||
vmul(temp, (RL_DAMRAD - dist) * damage / 800);
|
||||
vadd(o->vel, temp);
|
||||
vadd(o.vel, temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,25 +214,32 @@ splash(Projectile *p, const OFVector3D &v, const OFVector3D &vold,
|
|||
if (!p.local)
|
||||
return;
|
||||
radialeffect(player1, v, -1, qdam, p.owner);
|
||||
loopv(players)
|
||||
{
|
||||
if (i == notthisplayer)
|
||||
|
||||
size_t i = 0;
|
||||
for (id player in players) {
|
||||
if (i == notthisplayer) {
|
||||
i++;
|
||||
continue;
|
||||
dynent *o = players[i];
|
||||
if (!o)
|
||||
continue;
|
||||
radialeffect(o, v, i, qdam, p.owner);
|
||||
}
|
||||
|
||||
if (player != [OFNull null])
|
||||
radialeffect(player, v, i, qdam, p.owner);
|
||||
|
||||
i++;
|
||||
}
|
||||
dvector &mv = getmonsters();
|
||||
loopv(mv) if (i != notthismonster)
|
||||
radialeffect(mv[i], v, i, qdam, p.owner);
|
||||
|
||||
i = 0;
|
||||
for (DynamicEntity *monster in getmonsters())
|
||||
if (i != notthismonster)
|
||||
radialeffect(monster, v, i, qdam, p.owner);
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
projdamage(dynent *o, Projectile *p, OFVector3D &v, int i, int im, int qdam)
|
||||
projdamage(
|
||||
DynamicEntity *o, Projectile *p, OFVector3D &v, int i, int im, int qdam)
|
||||
{
|
||||
if (o->state != CS_ALIVE)
|
||||
if (o.state != CS_ALIVE)
|
||||
return;
|
||||
if (intersect(o, p.o, v)) {
|
||||
splash(p, v, p.o, i, im, qdam);
|
||||
|
@ -246,8 +256,8 @@ moveprojectiles(float time)
|
|||
if (!p.inuse)
|
||||
continue;
|
||||
|
||||
int qdam = guns[p.gun].damage * (p.owner->quadmillis ? 4 : 1);
|
||||
if (p.owner->monsterstate)
|
||||
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;
|
||||
|
@ -256,19 +266,17 @@ moveprojectiles(float time)
|
|||
vmul(v, time / dtime);
|
||||
vadd(v, p.o) if (p.local)
|
||||
{
|
||||
loopv(players)
|
||||
{
|
||||
dynent *o = players[i];
|
||||
if (!o)
|
||||
continue;
|
||||
projdamage(o, p, v, i, -1, qdam);
|
||||
}
|
||||
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);
|
||||
dvector &mv = getmonsters();
|
||||
loopv(mv) if (!vreject(mv[i]->o, v, 10.0f) &&
|
||||
mv[i] != p.owner)
|
||||
projdamage(mv[i], p, v, -1, i, 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) {
|
||||
if (time == dtime)
|
||||
|
@ -288,11 +296,12 @@ moveprojectiles(float time)
|
|||
}
|
||||
}
|
||||
|
||||
// create visual effect from a shot
|
||||
void
|
||||
shootv(int gun, OFVector3D &from, OFVector3D &to, dynent *d,
|
||||
bool local) // create visual effect from a shot
|
||||
shootv(int gun, OFVector3D &from, OFVector3D &to, DynamicEntity *d, bool local)
|
||||
{
|
||||
playsound(guns[gun].sound, d == player1 ? NULL : &d->o);
|
||||
OFVector3D loc = d.o;
|
||||
playsound(guns[gun].sound, d == player1 ? NULL : &loc);
|
||||
int pspeed = 25;
|
||||
switch (gun) {
|
||||
case GUN_FIST:
|
||||
|
@ -313,7 +322,7 @@ shootv(int gun, OFVector3D &from, OFVector3D &to, dynent *d,
|
|||
case GUN_ICEBALL:
|
||||
case GUN_SLIMEBALL:
|
||||
pspeed = guns[gun].projspeed;
|
||||
if (d->monsterstate)
|
||||
if (d.monsterstate)
|
||||
pspeed /= 2;
|
||||
newprojectile(from, to, (float)pspeed, local, d, gun);
|
||||
break;
|
||||
|
@ -326,26 +335,27 @@ shootv(int gun, OFVector3D &from, OFVector3D &to, dynent *d,
|
|||
}
|
||||
|
||||
void
|
||||
hitpush(int target, int damage, dynent *d, dynent *at, OFVector3D &from,
|
||||
OFVector3D &to)
|
||||
hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
|
||||
OFVector3D &from, OFVector3D &to)
|
||||
{
|
||||
hit(target, damage, d, at);
|
||||
vdist(dist, v, from, to);
|
||||
vmul(v, damage / dist / 50);
|
||||
vadd(d->vel, v);
|
||||
vadd(d.vel, v);
|
||||
}
|
||||
|
||||
void
|
||||
raydamage(dynent *o, OFVector3D &from, OFVector3D &to, dynent *d, int i)
|
||||
raydamage(
|
||||
DynamicEntity *o, OFVector3D &from, OFVector3D &to, DynamicEntity *d, int i)
|
||||
{
|
||||
if (o->state != CS_ALIVE)
|
||||
if (o.state != CS_ALIVE)
|
||||
return;
|
||||
int qdam = guns[d->gunselect].damage;
|
||||
if (d->quadmillis)
|
||||
int qdam = guns[d.gunselect].damage;
|
||||
if (d.quadmillis)
|
||||
qdam *= 4;
|
||||
if (d->monsterstate)
|
||||
if (d.monsterstate)
|
||||
qdam /= MONSTERDAMAGEFACTOR;
|
||||
if (d->gunselect == GUN_SG) {
|
||||
if (d.gunselect == GUN_SG) {
|
||||
int damage = 0;
|
||||
loop(r, SGRAYS) if (intersect(o, from, sg[r])) damage += qdam;
|
||||
if (damage)
|
||||
|
@ -355,67 +365,67 @@ raydamage(dynent *o, OFVector3D &from, OFVector3D &to, dynent *d, int i)
|
|||
}
|
||||
|
||||
void
|
||||
shoot(dynent *d, OFVector3D &targ)
|
||||
shoot(DynamicEntity *d, const OFVector3D &targ)
|
||||
{
|
||||
int attacktime = lastmillis - d->lastaction;
|
||||
if (attacktime < d->gunwait)
|
||||
int attacktime = lastmillis - d.lastaction;
|
||||
if (attacktime < d.gunwait)
|
||||
return;
|
||||
d->gunwait = 0;
|
||||
if (!d->attacking)
|
||||
d.gunwait = 0;
|
||||
if (!d.attacking)
|
||||
return;
|
||||
d->lastaction = lastmillis;
|
||||
d->lastattackgun = d->gunselect;
|
||||
if (!d->ammo[d->gunselect]) {
|
||||
d.lastaction = lastmillis;
|
||||
d.lastattackgun = d.gunselect;
|
||||
if (!d.ammo[d.gunselect]) {
|
||||
playsoundc(S_NOAMMO);
|
||||
d->gunwait = 250;
|
||||
d->lastattackgun = -1;
|
||||
d.gunwait = 250;
|
||||
d.lastattackgun = -1;
|
||||
return;
|
||||
}
|
||||
if (d->gunselect)
|
||||
d->ammo[d->gunselect]--;
|
||||
OFVector3D from = d->o;
|
||||
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;
|
||||
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) {
|
||||
if (d.gunselect == GUN_FIST || d.gunselect == GUN_BITE) {
|
||||
vmul(unitv, 3); // punch range
|
||||
to = from;
|
||||
vadd(to, unitv);
|
||||
}
|
||||
if (d->gunselect == GUN_SG)
|
||||
if (d.gunselect == GUN_SG)
|
||||
createrays(from, to);
|
||||
|
||||
if (d->quadmillis && attacktime > 200)
|
||||
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),
|
||||
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;
|
||||
d.gunwait = guns[d.gunselect].attackdelay;
|
||||
|
||||
if (guns[d->gunselect].projspeed)
|
||||
if (guns[d.gunselect].projspeed)
|
||||
return;
|
||||
|
||||
loopv(players)
|
||||
{
|
||||
dynent *o = players[i];
|
||||
if (!o)
|
||||
continue;
|
||||
raydamage(o, from, to, d, i);
|
||||
size_t i = 0;
|
||||
for (id player in players) {
|
||||
if (player != [OFNull null])
|
||||
raydamage(player, from, to, d, i);
|
||||
i++;
|
||||
}
|
||||
|
||||
dvector &v = getmonsters();
|
||||
loopv(v) if (v[i] != d) raydamage(v[i], from, to, d, -2);
|
||||
for (DynamicEntity *monster in getmonsters())
|
||||
if (monster != d)
|
||||
raydamage(monster, from, to, d, -2);
|
||||
|
||||
if (d->monsterstate)
|
||||
if (d.monsterstate)
|
||||
raydamage(player1, from, to, d, -1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue