weapon.mm: Some cleanups
FossilOrigin-Name: 3d4489fdbbc0cbf6515be7986569ca914232cc99a22550ed935c99b766574312
This commit is contained in:
parent
a94e06cb3b
commit
e45c8234e8
1 changed files with 48 additions and 51 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
struct guninfo {
|
struct guninfo {
|
||||||
short sound, attackdelay, damage, projspeed, part, kickamount;
|
short sound, attackdelay, damage, projspeed, part, kickamount;
|
||||||
char *name;
|
OFString *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
const int MONSTERDAMAGEFACTOR = 4;
|
const int MONSTERDAMAGEFACTOR = 4;
|
||||||
|
@ -13,15 +13,15 @@ const float SGSPREAD = 2;
|
||||||
OFVector3D sg[SGRAYS];
|
OFVector3D sg[SGRAYS];
|
||||||
|
|
||||||
guninfo guns[NUMGUNS] = {
|
guninfo guns[NUMGUNS] = {
|
||||||
{S_PUNCH1, 250, 50, 0, 0, 1, "fist"},
|
{S_PUNCH1, 250, 50, 0, 0, 1, @"fist"},
|
||||||
{S_SG, 1400, 10, 0, 0, 20, "shotgun"}, // *SGRAYS
|
{S_SG, 1400, 10, 0, 0, 20, @"shotgun"}, // *SGRAYS
|
||||||
{S_CG, 100, 30, 0, 0, 7, "chaingun"},
|
{S_CG, 100, 30, 0, 0, 7, @"chaingun"},
|
||||||
{S_RLFIRE, 800, 120, 80, 0, 10, "rocketlauncher"},
|
{S_RLFIRE, 800, 120, 80, 0, 10, @"rocketlauncher"},
|
||||||
{S_RIFLE, 1500, 100, 0, 0, 30, "rifle"},
|
{S_RIFLE, 1500, 100, 0, 0, 30, @"rifle"},
|
||||||
{S_FLAUNCH, 200, 20, 50, 4, 1, "fireball"},
|
{S_FLAUNCH, 200, 20, 50, 4, 1, @"fireball"},
|
||||||
{S_ICEBALL, 200, 40, 30, 6, 1, "iceball"},
|
{S_ICEBALL, 200, 40, 30, 6, 1, @"iceball"},
|
||||||
{S_SLIMEBALL, 200, 30, 160, 7, 1, "slimeball"},
|
{S_SLIMEBALL, 200, 30, 160, 7, 1, @"slimeball"},
|
||||||
{S_PIGR1, 250, 50, 0, 0, 1, "bite"},
|
{S_PIGR1, 250, 50, 0, 0, 1, @"bite"},
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -50,23 +50,21 @@ selectgun(int a, int b, int c)
|
||||||
if (s != player1->gunselect)
|
if (s != player1->gunselect)
|
||||||
playsoundc(S_WEAPLOAD);
|
playsoundc(S_WEAPLOAD);
|
||||||
player1->gunselect = s;
|
player1->gunselect = s;
|
||||||
// conoutf(@"%s selected", (int)guns[s].name);
|
// conoutf(@"%s selected", (int)guns[s].name.UTF8String);
|
||||||
};
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
reloadtime(int gun)
|
reloadtime(int gun)
|
||||||
{
|
{
|
||||||
return guns[gun].attackdelay;
|
return guns[gun].attackdelay;
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
weapon(OFString *a1, OFString *a2, OFString *a3)
|
weapon(OFString *a1, OFString *a2, OFString *a3)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
selectgun((a1.length > 0 ? (int)a1.longLongValue : -1),
|
||||||
selectgun(a1.UTF8String[0] ? atoi(a1.UTF8String) : -1,
|
(a2.length > 0 ? (int)a2.longLongValue : -1),
|
||||||
a2.UTF8String[0] ? atoi(a2.UTF8String) : -1,
|
(a3.length > 0 ? (int)a3.longLongValue : -1));
|
||||||
a3.UTF8String[0] ? atoi(a3.UTF8String) : -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
COMMAND(weapon, ARG_3STR)
|
COMMAND(weapon, ARG_3STR)
|
||||||
|
|
||||||
|
@ -82,8 +80,8 @@ createrays(OFVector3D &from,
|
||||||
OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD);
|
OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD);
|
||||||
sg[i] = to;
|
sg[i] = to;
|
||||||
vadd(sg[i], r);
|
vadd(sg[i], r);
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
intersect(dynent *d, OFVector3D &from,
|
intersect(dynent *d, OFVector3D &from,
|
||||||
|
@ -105,13 +103,13 @@ intersect(dynent *d, OFVector3D &from,
|
||||||
vmul(v, f);
|
vmul(v, f);
|
||||||
vadd(v, from);
|
vadd(v, from);
|
||||||
p = &v;
|
p = &v;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
return p->x <= d->o.x + d->radius && p->x >= d->o.x - d->radius &&
|
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->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;
|
p->z <= d->o.z + d->aboveeye && p->z >= d->o.z - d->eyeheight);
|
||||||
};
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
playerincrosshair()
|
playerincrosshair()
|
||||||
|
@ -125,9 +123,9 @@ playerincrosshair()
|
||||||
continue;
|
continue;
|
||||||
if (intersect(o, player1->o, worldpos))
|
if (intersect(o, player1->o, worldpos))
|
||||||
return o->name;
|
return o->name;
|
||||||
};
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
};
|
}
|
||||||
|
|
||||||
const int MAXPROJ = 100;
|
const int MAXPROJ = 100;
|
||||||
struct projectile {
|
struct projectile {
|
||||||
|
@ -136,14 +134,13 @@ struct projectile {
|
||||||
dynent *owner;
|
dynent *owner;
|
||||||
int gun;
|
int gun;
|
||||||
bool inuse, local;
|
bool inuse, local;
|
||||||
};
|
} projs[MAXPROJ];
|
||||||
projectile projs[MAXPROJ];
|
|
||||||
|
|
||||||
void
|
void
|
||||||
projreset()
|
projreset()
|
||||||
{
|
{
|
||||||
loopi(MAXPROJ) projs[i].inuse = false;
|
loopi(MAXPROJ) projs[i].inuse = false;
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
|
newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
|
||||||
|
@ -162,8 +159,8 @@ newprojectile(OFVector3D &from, OFVector3D &to, float speed, bool local,
|
||||||
p->owner = owner;
|
p->owner = owner;
|
||||||
p->gun = gun;
|
p->gun = gun;
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
hit(int target, int damage, dynent *d, dynent *at)
|
hit(int target, int damage, dynent *d, dynent *at)
|
||||||
|
@ -178,7 +175,7 @@ hit(int target, int damage, dynent *d, dynent *at)
|
||||||
};
|
};
|
||||||
particle_splash(3, damage, 1000, d->o);
|
particle_splash(3, damage, 1000, d->o);
|
||||||
demodamage(damage, d->o);
|
demodamage(damage, d->o);
|
||||||
};
|
}
|
||||||
|
|
||||||
const float RL_RADIUS = 5;
|
const float RL_RADIUS = 5;
|
||||||
const float RL_DAMRAD = 7; // hack
|
const float RL_DAMRAD = 7; // hack
|
||||||
|
@ -197,8 +194,8 @@ radialeffect(dynent *o, OFVector3D &v, int cn, int qdam, dynent *at)
|
||||||
hit(cn, damage, o, at);
|
hit(cn, damage, o, at);
|
||||||
vmul(temp, (RL_DAMRAD - dist) * damage / 800);
|
vmul(temp, (RL_DAMRAD - dist) * damage / 800);
|
||||||
vadd(o->vel, temp);
|
vadd(o->vel, temp);
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
splash(projectile *p, OFVector3D &v, OFVector3D &vold, int notthisplayer,
|
splash(projectile *p, OFVector3D &v, OFVector3D &vold, int notthisplayer,
|
||||||
|
@ -224,12 +221,12 @@ splash(projectile *p, OFVector3D &v, OFVector3D &vold, int notthisplayer,
|
||||||
if (!o)
|
if (!o)
|
||||||
continue;
|
continue;
|
||||||
radialeffect(o, v, i, qdam, p->owner);
|
radialeffect(o, v, i, qdam, p->owner);
|
||||||
};
|
}
|
||||||
dvector &mv = getmonsters();
|
dvector &mv = getmonsters();
|
||||||
loopv(mv) if (i != notthismonster)
|
loopv(mv) if (i != notthismonster)
|
||||||
radialeffect(mv[i], v, i, qdam, p->owner);
|
radialeffect(mv[i], v, i, qdam, p->owner);
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
projdamage(dynent *o, projectile *p, OFVector3D &v, int i, int im, int qdam)
|
projdamage(dynent *o, projectile *p, OFVector3D &v, int i, int im, int qdam)
|
||||||
|
@ -239,8 +236,8 @@ projdamage(dynent *o, projectile *p, OFVector3D &v, int i, int im, int qdam)
|
||||||
if (intersect(o, p->o, v)) {
|
if (intersect(o, p->o, v)) {
|
||||||
splash(p, v, p->o, i, im, qdam);
|
splash(p, v, p->o, i, im, qdam);
|
||||||
hit(i, qdam, o, p->owner);
|
hit(i, qdam, o, p->owner);
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
moveprojectiles(float time)
|
moveprojectiles(float time)
|
||||||
|
@ -289,8 +286,8 @@ moveprojectiles(float time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p->o = v;
|
p->o = v;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
shootv(int gun, OFVector3D &from, OFVector3D &to, dynent *d,
|
shootv(int gun, OFVector3D &from, OFVector3D &to, dynent *d,
|
||||||
|
@ -305,7 +302,7 @@ shootv(int gun, OFVector3D &from, OFVector3D &to, dynent *d,
|
||||||
case GUN_SG: {
|
case GUN_SG: {
|
||||||
loopi(SGRAYS) particle_splash(0, 5, 200, sg[i]);
|
loopi(SGRAYS) particle_splash(0, 5, 200, sg[i]);
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
|
|
||||||
case GUN_CG:
|
case GUN_CG:
|
||||||
particle_splash(0, 100, 250, to);
|
particle_splash(0, 100, 250, to);
|
||||||
|
@ -326,8 +323,8 @@ shootv(int gun, OFVector3D &from, OFVector3D &to, dynent *d,
|
||||||
particle_splash(0, 50, 200, to);
|
particle_splash(0, 50, 200, to);
|
||||||
particle_trail(1, 500, from, to);
|
particle_trail(1, 500, from, to);
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
hitpush(int target, int damage, dynent *d, dynent *at, OFVector3D &from,
|
hitpush(int target, int damage, dynent *d, dynent *at, OFVector3D &from,
|
||||||
|
@ -356,7 +353,7 @@ raydamage(dynent *o, OFVector3D &from, OFVector3D &to, dynent *d, int i)
|
||||||
hitpush(i, damage, o, d, from, to);
|
hitpush(i, damage, o, d, from, to);
|
||||||
} else if (intersect(o, from, to))
|
} else if (intersect(o, from, to))
|
||||||
hitpush(i, qdam, o, d, from, to);
|
hitpush(i, qdam, o, d, from, to);
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
shoot(dynent *d, OFVector3D &targ)
|
shoot(dynent *d, OFVector3D &targ)
|
||||||
|
@ -374,7 +371,7 @@ shoot(dynent *d, OFVector3D &targ)
|
||||||
d->gunwait = 250;
|
d->gunwait = 250;
|
||||||
d->lastattackgun = -1;
|
d->lastattackgun = -1;
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
if (d->gunselect)
|
if (d->gunselect)
|
||||||
d->ammo[d->gunselect]--;
|
d->ammo[d->gunselect]--;
|
||||||
OFVector3D from = d->o;
|
OFVector3D from = d->o;
|
||||||
|
@ -393,7 +390,7 @@ shoot(dynent *d, OFVector3D &targ)
|
||||||
vmul(unitv, 3); // punch range
|
vmul(unitv, 3); // punch range
|
||||||
to = from;
|
to = from;
|
||||||
vadd(to, unitv);
|
vadd(to, unitv);
|
||||||
};
|
}
|
||||||
if (d->gunselect == GUN_SG)
|
if (d->gunselect == GUN_SG)
|
||||||
createrays(from, to);
|
createrays(from, to);
|
||||||
|
|
||||||
|
@ -415,11 +412,11 @@ shoot(dynent *d, OFVector3D &targ)
|
||||||
if (!o)
|
if (!o)
|
||||||
continue;
|
continue;
|
||||||
raydamage(o, from, to, d, i);
|
raydamage(o, from, to, d, i);
|
||||||
};
|
}
|
||||||
|
|
||||||
dvector &v = getmonsters();
|
dvector &v = getmonsters();
|
||||||
loopv(v) if (v[i] != d) raydamage(v[i], from, to, d, -2);
|
loopv(v) if (v[i] != d) raydamage(v[i], from, to, d, -2);
|
||||||
|
|
||||||
if (d->monsterstate)
|
if (d->monsterstate)
|
||||||
raydamage(player1, from, to, d, -1);
|
raydamage(player1, from, to, d, -1);
|
||||||
};
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue