cleanup shotgun code

no functional changes, only cleanup
This commit is contained in:
ac-stef
2015-07-12 20:22:49 +02:00
parent a78d08d4ca
commit 380b8a1ebf
6 changed files with 37 additions and 166 deletions
-5
View File
@@ -75,11 +75,6 @@ enum { GUN_KNIFE = 0, GUN_PISTOL, GUN_CARBINE, GUN_SHOTGUN, GUN_SUBGUN, GUN_SNIP
#define SGMAXDMGABS 105
#define SGMAXDMGLOC 84
#define SGBONUSDIST 80
#define SGSEGDMG_O 3
#define SGSEGDMG_M 6
#define SGSEGDMG_C 4
#define SGSPREAD 2.25
#define EXPDAMRAD 10
struct itemstat { int add, start, max, sound; };
+2 -7
View File
@@ -682,7 +682,7 @@ extern void particle_trail(int type, int fade, const vec &from, const vec &to);
extern void particle_emit(int type, int *args, int basetime, int seed, const vec &p);
extern void particle_fireball(int type, const vec &o);
extern void addshotline(dynent *d, const vec &from, const vec &to);
extern bool addbullethole(dynent *d, const vec &from, const vec &to, float radius = 1, bool noisy = true, int type = 0); // shotty
extern bool addbullethole(dynent *d, const vec &from, const vec &to, float radius = 1, bool noisy = true);
extern bool addscorchmark(vec &o, float radius = 7);
extern void render_particles(int time, int typemask = ~0);
@@ -764,7 +764,7 @@ extern const char *mmshortname(const char *name);
// weapon
extern void shoot(playerent *d, vec &to);
extern void createrays(vec &from, vec &to);
extern void createrays(const vec &from, const vec &to);
extern void removebounceents(playerent *owner);
extern void movebounceents();
extern void clearbounceents();
@@ -1127,8 +1127,3 @@ struct servercommandline
}
};
// shotty: shotgun rays def
struct sgray {
int ds; // damage flag: outer, medium, center: SGSEGDMG_*
vec rv; // ray vector
};
-84
View File
@@ -90,90 +90,6 @@ VARP(hideconsole, 0, 0, 1);
VARP(hidespecthud, 0, 0, 1);
VAR(showmap, 0, 0, 1);
//shotty::
/*
VAR(showsgpat, 0, 0, 1);
void drawsgpat(int w, int h)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D);
glColor3ub(0, 0, 0);
float sz = min(VIRTW, VIRTH),
x1 = VIRTW/2 - sz/2,
x2 = VIRTW/2 + sz/2,
y1 = VIRTH/2 - sz/2,
y2 = VIRTH/2 + sz/2,
border = (512 - 64*2)/512.0f;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x1 + 0.5f*sz, y1 + 0.5f*sz);
int rgbcv = 0;
loopi(8+1)
{
// if((i%3)==0) { glColor3ub(rgbcv,rgbcv,rgbcv); rgbcv += 4; //rgbcv -= 255/(8+1); }
if(i%2) glColor3ub(64,64,64); else glColor3ub(32,32,32);
float c = 0.5f*(1 + border*cosf(i*2*M_PI/8.0f)), s = 0.5f*(1 + border*sinf(i*2*M_PI/8.0f));
glVertex2f(x1 + c*sz, y1 + s*sz);
}
glColor3ub(255,255,255);
glEnd();
glDisable(GL_BLEND);
rgbcv = 32;
glBegin(GL_TRIANGLE_STRIP);
loopi(8+1)
{
// if((i%3)==0) { glColor3ub(rgbcv,rgbcv,rgbcv); //,128); rgbcv += 8; //rgbcv -= 255/(8+1); }
if(i%2) glColor3ub(16,16,16); else glColor3ub(32,32,32);
float c = 0.5f*(1 + border*cosf(i*2*M_PI/8.0f)), s = 0.5f*(1 + border*sinf(i*2*M_PI/8.0f));
glVertex2f(x1 + c*sz, y1 + s*sz);
c = c < 0.4f ? 0 : (c > 0.6f ? 1 : 0.5f);
s = s < 0.4f ? 0 : (s > 0.6f ? 1 : 0.5f);
glVertex2f(x1 + c*sz, y1 + s*sz);
}
glColor3ub(255,255,255);
glEnd();
glEnable(GL_TEXTURE_2D);
static Texture *pattex = NULL;
if(!pattex) pattex = textureload("packages/misc/sgpat.png", 4);
loopk(3)
{
switch(k)
{
case 0: glColor3ub( 32, 250, 250); break; // center
case 1: glColor3ub( 250, 64, 64); break; // middle
case 2: glColor3ub( 250, 250, 64); break; // outer
default: glColor3ub( 255, 255, 255); break;
}
extern sgray pat[SGRAYS*3];
int j = k * SGRAYS;
loopi(SGRAYS)
{
if(pattex)
{
vec p = pat[j+i].rv;
int ppx = VIRTW/2 + p.x*(sz/2);
int ppy = VIRTH/2 + p.y*(sz/2);
drawicon(pattex, ppx, ppy, 16, 1, 1, 1);
}
}
}
glEnable(GL_BLEND);
/\*
// 2011may31: dmg/hits output comes upon each shot, let the pattern be shown "pure"
extern int lastsgs_hits;
extern int lastsgs_dmgt;
//draw_textf("H: %d DMG: %d", 8, 32, lastsgs_hits, lastsgs_dmgt);
defformatstring(t2show4hitdmg)("H: %d DMG: %d", lastsgs_hits, lastsgs_dmgt);
draw_text(t2show4hitdmg, VIRTW/2-text_width(t2show4hitdmg), VIRTH/2-3*FONTH/4);
*\/
}
*/
//::shotty
void drawscope(bool preload)
{
static Texture *scopetex = NULL;
+3 -11
View File
@@ -184,7 +184,7 @@ void cleanupexplosion()
}
}
#define MAXPARTYPES 22
#define MAXPARTYPES 20
struct particle { vec o, d; int fade, type; int millis; particle *next; };
particle *parlist[MAXPARTYPES], *parempty = NULL;
@@ -271,9 +271,6 @@ static struct parttype { int type; float r, g, b; int gr, tex; float sz; } partt
{ PT_PART, 1.0f, 0.5f, 0.2f, 20, 0, 0.08f }, // orange: edit mode ent type : "carrot"
{ PT_PART, 0.5f, 0.5f, 0.5f, 20, 0, 0.08f }, // grey: edit mode ent type : ladder, (pl)clip
{ PT_PART, 0.0f, 1.0f, 1.0f, 20, 0, 0.08f }, // turquoise: edit mode ent type : CTF-flag
// 2011jun18 : shotty decals
{ PT_BULLETHOLE, 0.2f, 0.2f, 1.0f, 0, 3, 0.1f }, // hole decal M
{ PT_BULLETHOLE, 0.2f, 1.0f, 0.2f, 0, 3, 0.1f }, // hole decal C
};
VAR(particlesize, 20, 100, 500);
@@ -623,9 +620,7 @@ VARP(bullethole, 0, 1, 1);
VARP(bulletholettl, 0, 10000, 30000);
VARP(bulletbouncesoundrad, 0, 15, 1000);
// 2011jun18: shotty decals
//bool addbullethole(dynent *d, const vec &from, const vec &to, float radius, bool noisy)
bool addbullethole(dynent *d, const vec &from, const vec &to, float radius, bool noisy, int type)
bool addbullethole(dynent *d, const vec &from, const vec &to, float radius, bool noisy)
{
if(!bulletholettl || !bullethole) return false;
vec surface, ray(to);
@@ -636,10 +631,7 @@ bool addbullethole(dynent *d, const vec &from, const vec &to, float radius, bool
vec o(from);
o.add(ray.mul(dist));
o.add(vec(surface).normalize().mul(0.01f));
// 2011jun18: shotty decals
int tf = type > 0 ? ( type > 1 ? 21 : 20 ) : 7;
newparticle(o, surface, bulletholettl, tf);
//newparticle(o, surface, bulletholettl, 7);
newparticle(o, surface, bulletholettl, 7);
if(noisy && bulletbouncesound && bulletbouncesoundrad && d!=player1 && o.dist(camera1->o) <= bulletbouncesoundrad)
{
audiomgr.playsound(o.z < waterlevel ? S_BULLETWATERHIT : S_BULLETHIT, &o, SP_LOW);
-1
View File
@@ -70,7 +70,6 @@ void processevent(client *c, shotevent &e)
bool gib = false;
if(e.gun == GUN_SHOTGUN)
{
h.info = isbigendian() ? endianswap(h.info) : h.info;
int bonusdist = h.info&0xFF;
int numhits_c = (h.info & 0x0000FF00) >> 8, numhits_m = (h.info & 0x00FF0000) >> 16, numhits_o = (h.info & 0xFF000000) >> 24;
tothits_c += numhits_c; tothits_m += numhits_m; tothits_o += numhits_o;
+32 -58
View File
@@ -8,8 +8,12 @@ VARP(autoreload, 0, 1, 1);
VARP(akimboautoswitch, 0, 1, 1);
VARP(akimboendaction, 0, 3, 3); // 0: switch to knife, 1: stay with pistol (if has ammo), 2: switch to grenade (if possible), 3: switch to primary (if has ammo) - all fallback to previous one w/o ammo for target
struct sgray {
int ds; // damage flag: 0:outer, 1:medium, 2:center
vec rv; // ray vector
};
sgray sgr[SGRAYS*3];
sgray pat[SGRAYS*3]; // DEBUG 2011may27
int burstshotssettings[NUMGUNS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
@@ -157,13 +161,8 @@ void tryreload(playerent *p)
COMMANDF(reload, "", () { tryreload(player1); });
int lastsgs_hits = 0;
int lastsgs_dmgt = 0;
void createrays(vec &from, vec &to) // create random spread of rays for the shotgun
void createrays(const vec &from, const vec &to) // create random spread of rays for the shotgun
{
// 2011jan17:ft: once this basic approach has been agreed upon this function should be optimized
// 2011may27:ft: indeed
vec dir = vec(from).sub(to);
float f = dir.magnitude() / 10.0f;
dir.normalize();
@@ -173,34 +172,29 @@ void createrays(vec &from, vec &to) // create random spread of rays for the shot
spoke.mul(f);
loopk(3)
{
float base;
int wrange;
switch(k)
{
case 0: base = SGCObase / 100.0f; wrange = SGCOrange; break;
case 1: base = SGCMbase / 100.0f; wrange = SGCMrange; break;
case 2:
default: base = SGCCbase / 100.0f; wrange = SGCCrange; break;
}
float rnddir = rndscale(2*M_PI);
loopi(SGRAYS)
{
int j = k * SGRAYS;
sgr[j+i].ds = k; //2011jun18 - damage-independent-section-indicator .. not: k==0 ? SGSEGDMG_O : (k==1? SGSEGDMG_M: SGSEGDMG_C);
int j = k * SGRAYS + i;
sgr[j].ds = k;
vec p(spoke);
float base = 0.0f;
int wrange = 50;
switch(sgr[j+i].ds)
{
case 0:/* SGSEGDMG_O:*/ base = SGCObase/100.0f; wrange = SGCOrange; break;
case 1:/* SGSEGDMG_M:*/ base = SGCMbase/100.0f; wrange = SGCMrange; break;
case 2:/* SGSEGDMG_C:*/
default: base = SGCCbase/100.0f; wrange = SGCCrange; break;
}
int rndmul = rnd(wrange);
float veclen = base + rndmul/100.0f;
p.mul( veclen );
p.mul(veclen);
p.rotate( 2*M_PI/SGRAYS * i + rnddir , dir );
p.rotate(2 * M_PI / SGRAYS * i + rnddir, dir);
vec rray = vec(to);
float nvl = veclen / ( ( SGCObase / 100.0f ) + ( SGCOrange / 100.0f ) );
vec pbv = vec( nvl, 0, 0);
pbv.rotate( 2*M_PI/SGRAYS * i + rnddir, vec( 0, 0, 1) );
pat[j+i].ds = int(veclen*100);
pat[j+i].rv = pbv;
rray.add(p);
sgr[j+i].rv = rray;
sgr[j].rv = rray;
}
}
}
@@ -627,9 +621,9 @@ void raydamage(vec &from, vec &to, playerent *d)
numhits_o = numhits_m = numhits_c = 0;
switch(sgr[h].ds)
{
case 0:/* SGSEGDMG_O:*/ numhits_o++; break;
case 1:/* SGSEGDMG_M:*/ numhits_m++; break;
case 2:/* SGSEGDMG_C:*/ numhits_c++; break;
case 0: numhits_o++; break;
case 1: numhits_m++; break;
case 2: numhits_c++; break;
default: break;
}
for(int j = i+1; j < 3*SGRAYS; j++) if(hits[j] == o)
@@ -637,52 +631,32 @@ void raydamage(vec &from, vec &to, playerent *d)
hits[j] = NULL;
switch(sgr[j].ds)
{
case 0:/* SGSEGDMG_O:*/ numhits_o++; break;
case 1:/* SGSEGDMG_M:*/ numhits_m++; break;
case 2:/* SGSEGDMG_C:*/ numhits_c++; break;
case 0: numhits_o++; break;
case 1: numhits_m++; break;
case 2: numhits_c++; break;
default: break;
}
}
int numhits = numhits_o + numhits_m + numhits_c;
int dmgreal = 0;
float dmg4r = 0.0f;
bool withBONUS = false;//'';
bool withBONUS = false;
if(SGDMGBONUS)
{
float d2o = SGDMGDISTB;
if(o) d2o = vec(from).sub(o->o).magnitude();
if(d2o <= (SGDMGDISTB/10.0f) && numhits)
{
/*
float soc = ( SGCCdmg/10.0f * SGDMGTOTAL/100.0f ) + ( SGCMdmg/10.0f * SGDMGTOTAL/100.0f ) + ( SGCOdmg/10.0f * SGDMGTOTAL/100.0f );
float d2t = SGDMGTOTAL - soc;
*/
dmg4r += SGDMGBONUS;//d2t; //was: "d2t" == if percentage-points are dangling and we have hits, we have a base-damage value
dmg4r += SGDMGBONUS;
withBONUS = true;
//printf("established SOC: %.2f | d2t: %.2f\n", soc, d2t);
//if(numhits) dmgreal += int(d2t);
}
}
dmg4r += /*(int)*/( ( SGCOdmg/10.0f * SGDMGTOTAL/100.0f ) * numhits_o/21.0f );
dmg4r += /*(int)*/( ( SGCMdmg/10.0f * SGDMGTOTAL/100.0f ) * numhits_m/21.0f );
dmg4r += /*(int)*/( ( SGCCdmg/10.0f * SGDMGTOTAL/100.0f ) * numhits_c/21.0f );
// int dmgreal = (SGSEGDMG_O * numhits_o + SGSEGDMG_M * numhits_m + SGSEGDMG_C * numhits_c)/3;
/*
float d2o = SGBONUSDIST;
if(o) d2o = vec(from).sub(o->o).magnitude();
if(d2o <= (SGBONUSDIST/10.0f) && numhits)
{
dmgreal += (SGMAXDMGABS-SGMAXDMGLOC);
dmgreal = min(dmgreal, SGMAXDMGABS);
}
*/
dmg4r += (SGCOdmg / 10.0f * SGDMGTOTAL / 100.0f) * numhits_o / 21.0f;
dmg4r += (SGCMdmg / 10.0f * SGDMGTOTAL / 100.0f) * numhits_m / 21.0f;
dmg4r += (SGCCdmg / 10.0f * SGDMGTOTAL / 100.0f) * numhits_c / 21.0f;
dmgreal = (int) ceil(dmg4r);
lastsgs_hits = numhits;
lastsgs_dmgt = dmgreal;
// conoutf("%d [%.3f%s] DMG with %d hits", lastsgs_dmgt, dmg4r, withBONUS ? "\fs\f3+\fr" : "", lastsgs_hits);
int info = (withBONUS ? SGDMGBONUS : 0) | (numhits_c << 8) | (numhits_m << 16) | (numhits_o << 24);
if(numhits) hitpush( dmgreal, o, d, from, to, d->weaponsel->type, lastsgs_hits == SGRAYS*3, isbigendian() ? endianswap(info) : info);
// if(numhits) hitpush( dmgreal, o, d, from, to, d->weaponsel->type, dmgreal == SGMAXDMGABS, dmgreal);
if(numhits) hitpush(dmgreal, o, d, from, to, d->weaponsel->type, numhits == SGRAYS * 3, info);
if(d==player1) hitted = true;
hitscount+=numhits;