Clean up DynamicEntity
FossilOrigin-Name: b787ad5a04fc238a69b9e48b3bdfccde416f636a021eef0d955445b5ab92252b
This commit is contained in:
parent
fd2b1dddf0
commit
a7db00c740
24 changed files with 561 additions and 540 deletions
93
src/weapon.m
93
src/weapon.m
|
@ -32,7 +32,7 @@ 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;
|
||||
int s = player1.gunSelect;
|
||||
if (a >= 0 && s != a && player1.ammo[a])
|
||||
s = a;
|
||||
else if (b >= 0 && s != b && player1.ammo[b])
|
||||
|
@ -49,9 +49,9 @@ selectgun(int a, int b, int c)
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ createrays(const OFVector3D *from, const OFVector3D *to)
|
|||
static bool
|
||||
intersect(DynamicEntity *d, const OFVector3D *from, const OFVector3D *to)
|
||||
{
|
||||
OFVector3D v = *to, w = d.o;
|
||||
OFVector3D v = *to, w = d.origin;
|
||||
const OFVector3D *p;
|
||||
vsub(v, *from);
|
||||
vsub(w, *from);
|
||||
|
@ -109,9 +109,10 @@ intersect(DynamicEntity *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.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 *
|
||||
|
@ -124,7 +125,7 @@ playerincrosshair()
|
|||
if (player == [OFNull null])
|
||||
continue;
|
||||
|
||||
OFVector3D o = player1.o;
|
||||
OFVector3D o = player1.origin;
|
||||
if (intersect(player, &o, &worldpos))
|
||||
return [player name];
|
||||
}
|
||||
|
@ -169,13 +170,13 @@ newprojectile(const OFVector3D *from, const OFVector3D *to, float speed,
|
|||
void
|
||||
hit(int target, int damage, DynamicEntity *d, DynamicEntity *at)
|
||||
{
|
||||
OFVector3D o = d.o;
|
||||
OFVector3D o = d.origin;
|
||||
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);
|
||||
addmsg(1, 4, SV_DAMAGE, target, damage, d.lifeSequence);
|
||||
playsound(S_PAIN1 + rnd(5), &o);
|
||||
}
|
||||
particle_splash(3, damage, 1000, &o);
|
||||
|
@ -191,7 +192,7 @@ radialeffect(
|
|||
{
|
||||
if (o.state != CS_ALIVE)
|
||||
return;
|
||||
vdist(dist, temp, *v, o.o);
|
||||
vdist(dist, temp, *v, o.origin);
|
||||
dist -= 2; // account for eye distance imprecision
|
||||
if (dist < RL_DAMRAD) {
|
||||
if (dist < 0)
|
||||
|
@ -199,7 +200,7 @@ radialeffect(
|
|||
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.velocity, temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,8 +266,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;
|
||||
|
@ -283,7 +284,7 @@ moveprojectiles(float time)
|
|||
projdamage(player1, p, &v, -1, -1, qdam);
|
||||
|
||||
for (DynamicEntity *monster in getmonsters())
|
||||
if (!vreject(monster.o, v, 10.0f) &&
|
||||
if (!vreject(monster.origin, v, 10.0f) &&
|
||||
monster != p.owner)
|
||||
projdamage(monster, p, &v, -1, i, qdam);
|
||||
}
|
||||
|
@ -312,7 +313,7 @@ void
|
|||
shootv(int gun, const OFVector3D *from, const OFVector3D *to, DynamicEntity *d,
|
||||
bool local)
|
||||
{
|
||||
OFVector3D loc = d.o;
|
||||
OFVector3D loc = d.origin;
|
||||
playsound(guns[gun].sound, d == player1 ? NULL : &loc);
|
||||
int pspeed = 25;
|
||||
switch (gun) {
|
||||
|
@ -334,7 +335,7 @@ shootv(int gun, const OFVector3D *from, const OFVector3D *to, DynamicEntity *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;
|
||||
|
@ -353,7 +354,7 @@ hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
|
|||
hit(target, damage, d, at);
|
||||
vdist(dist, v, *from, *to);
|
||||
vmul(v, damage / dist / 50);
|
||||
vadd(d.vel, v);
|
||||
vadd(d.velocity, v);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -362,12 +363,12 @@ raydamage(DynamicEntity *o, const OFVector3D *from, const OFVector3D *to,
|
|||
{
|
||||
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)
|
||||
|
@ -379,52 +380,52 @@ raydamage(DynamicEntity *o, const OFVector3D *from, const OFVector3D *to,
|
|||
void
|
||||
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;
|
||||
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.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.vel, kickback);
|
||||
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;
|
||||
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;
|
||||
|
||||
[players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) {
|
||||
|
@ -436,6 +437,6 @@ shoot(DynamicEntity *d, const OFVector3D *targ)
|
|||
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