From 44abbf67d159b86693d31a458f6562aab7a7af17 Mon Sep 17 00:00:00 2001 From: Ronald Reagan Date: Mon, 29 Oct 2012 03:01:32 +0000 Subject: [PATCH] New shotty sources git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6919 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/protocol.h | 3 +- source/src/protos.h | 8 ++- source/src/renderhud.cpp | 83 ++++++++++++++++++++++++ source/src/renderparticles.cpp | 16 ++++- source/src/weapon.cpp | 114 +++++++++++++++++++++++++-------- 5 files changed, 192 insertions(+), 32 deletions(-) diff --git a/source/src/protocol.h b/source/src/protocol.h index 722ddc49..179cc2e5 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -40,7 +40,8 @@ enum SV_SWITCHNAME, SV_SWITCHSKIN, SV_SWITCHTEAM, SV_CLIENT, SV_EXTENSION, - SV_MAPIDENT, SV_HUDEXTRAS, SV_POINTS, SV_NUM + SV_MAPIDENT, SV_HUDEXTRAS, SV_POINTS, + SV_NUM }; #ifdef _DEBUG diff --git a/source/src/protos.h b/source/src/protos.h index 683928d3..3fab02c6 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -632,7 +632,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); +extern bool addbullethole(dynent *d, const vec &from, const vec &to, float radius = 1, bool noisy = true, int type = 0); // shotty extern bool addscorchmark(vec &o, float radius = 7); extern void render_particles(int time, int typemask = ~0); @@ -1056,3 +1056,9 @@ struct servercommandline return true; } }; + +// shotty: shotgun rays def +struct sgray { + int ds; // damage flag: outer, medium, center: SGSEGDMG_* + vec rv; // ray vector +}; diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index fa9769e4..35547eb5 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -88,6 +88,88 @@ 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; @@ -777,6 +859,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat players.inrange(player1->followplayercn) && players[player1->followplayercn]); if(/*!menu &&*/ (!hideradar || showmap)) drawradar(p, w, h); + //if(showsgpat) drawsgpat(w,h); // shotty if(!editmode) { glMatrixMode(GL_MODELVIEW); diff --git a/source/src/renderparticles.cpp b/source/src/renderparticles.cpp index 78c91e52..3863bccd 100644 --- a/source/src/renderparticles.cpp +++ b/source/src/renderparticles.cpp @@ -184,7 +184,7 @@ void cleanupexplosion() } } -#define MAXPARTYPES 20 +#define MAXPARTYPES 22 struct particle { vec o, d; int fade, type; int millis; particle *next; }; particle *parlist[MAXPARTYPES], *parempty = NULL; @@ -258,6 +258,7 @@ static struct parttype { int type; float r, g, b; int gr, tex; float sz; } partt { PT_FIREBALL, 1.0f, 0.5f, 0.5f, 0, 2, 7.0f }, // explosion fireball { PT_SHOTLINE, 1.0f, 1.0f, 0.7f, 0, -1, 0.0f }, // yellow: shotline { PT_BULLETHOLE, 1.0f, 1.0f, 1.0f, 0, 3, 0.3f }, // hole decal + { PT_STAIN, 0.5f, 0.0f, 0.0f, 0, 4, 0.6f }, // red: blood stain { PT_DECAL, 1.0f, 1.0f, 1.0f, 0, 5, 1.5f }, // scorch decal { PT_HUDFLASH, 1.0f, 1.0f, 1.0f, 0, 6, 0.7f }, // hudgun muzzle flash @@ -270,6 +271,9 @@ 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); @@ -605,7 +609,9 @@ VARP(bullethole, 0, 1, 1); VARP(bulletholettl, 0, 10000, 30000); VARP(bulletbouncesoundrad, 0, 15, 1000); -bool addbullethole(dynent *d, const vec &from, const vec &to, float radius, bool noisy) +// 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) { if(!bulletholettl || !bullethole) return false; vec surface, ray(to); @@ -616,7 +622,10 @@ 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)); - newparticle(o, surface, bulletholettl, 7); + // 2011jun18: shotty decals + int tf = type > 0 ? ( type > 1 ? 21 : 20 ) : 7; + newparticle(o, surface, bulletholettl, tf); + //newparticle(o, surface, bulletholettl, 7); if(noisy && bulletbouncesound && bulletbouncesoundrad && d!=player1 && o.dist(camera1->o) <= bulletbouncesoundrad) { audiomgr.playsound(o.zo).magnitude(); - if(d2o <= (SGBONUSDIST/10.0f) && numhits) + int dmgreal = 0; + float dmg4r = 0.0f; + bool withBONUS = false;//''; + if(SGDMGBONUS) { - dmgreal += (SGMAXDMGABS-SGMAXDMGLOC); - dmgreal = min(dmgreal, SGMAXDMGABS); + 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 + withBONUS = true; + //printf("established SOC: %.2f | d2t: %.2f\n", soc, d2t); + //if(numhits) dmgreal += int(d2t); + } } - if(numhits) hitpush( dmgreal, o, d, from, to, d->weaponsel->type, dmgreal == SGMAXDMGABS, dmgreal); - + 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); + } + */ + dmgreal = (int) dmg4r; + lastsgs_hits = numhits; + lastsgs_dmgt = dmgreal; +// conoutf("%d [%.3f%s] DMG with %d hits", lastsgs_dmgt, dmg4r, withBONUS ? "\fs\f3+\fr" : "", lastsgs_hits); + if(numhits) hitpush( dmgreal, o, d, from, to, d->weaponsel->type, dmgreal == SGDMGTOTAL, dmgreal); +// if(numhits) hitpush( dmgreal, o, d, from, to, d->weaponsel->type, dmgreal == SGMAXDMGABS, dmgreal); + if(d==player1) hitted = true; hitscount+=numhits; } @@ -638,7 +695,7 @@ void raydamage(vec &from, vec &to, playerent *d) switch(d->weaponsel->type) { case GUN_KNIFE: gib = true; break; - case GUN_SNIPER: if(hitzone==2) { dam *= 3; gib = true; }; break; + case GUN_SNIPER: if(d==player1 && hitzone==2) { dam *= 3; gib = true; }; break; default: break; } bool info = gib; @@ -647,7 +704,7 @@ void raydamage(vec &from, vec &to, playerent *d) shorten(from, to, dist); hitscount++; } - + if(d==player1) { if(!rayscount) rayscount = 1; @@ -849,9 +906,11 @@ void weapon::renderhudmodel(int lastaction, int index) weaponmove wm; if(!intermission) wm.calcmove(unitv, lastaction, p); +// if(!intermission) wm.calcmove(unitv, p->lastaction, p); defformatstring(widn)("modmdlweap%d", type); defformatstring(path)("weapons/%s", identexists(widn)?getalias(widn):info.modelname); bool emit = (wm.anim&ANIM_INDEX)==ANIM_GUN_SHOOT && (lastmillis - lastaction) < flashtime(); +// bool emit = (wm.anim&ANIM_INDEX)==ANIM_GUN_SHOOT && (lastmillis - p->lastaction) < flashtime(); rendermodel(path, wm.anim|ANIM_DYNALLOC|(righthanded==index ? ANIM_MIRROR : 0)|(emit ? ANIM_PARTICLE : 0), 0, -1, wm.pos, p->yaw+90, p->pitch+wm.k_rot, 40.0f, wm.basetime, NULL, NULL, 1.28f); } @@ -1241,6 +1300,7 @@ bool shotgun::attack(vec &targ) void shotgun::attackfx(const vec &from, const vec &to, int millis) { loopi(SGRAYS) particle_splash(PART_SPARK, 5, 200, sgr[i].rv); + if(addbullethole(owner, from, to)) { loopk(3)