From b113d0e05b676394dc771bd9a963a030045bee7b Mon Sep 17 00:00:00 2001 From: driAn Date: Thu, 27 Oct 2005 23:32:52 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@77 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clientgame.cpp | 21 +++++ source/src/clients2c.cpp | 6 +- source/src/cube.h | 13 +++- source/src/entities.cpp | 4 +- source/src/physics.cpp | 150 +++++++++++++++++++++++++++++++++--- source/src/protos.h | 8 +- source/src/renderextras.cpp | 9 +++ source/src/rendergl.cpp | 9 ++- source/src/serverutil.cpp | 2 +- source/src/weapon.cpp | 126 +++++++++++++++++++++++++++--- 10 files changed, 315 insertions(+), 33 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 2fd8b8e2..30ba5697 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -13,6 +13,8 @@ bool intermission = false; dynent *player1 = newdynent(); // our client dvector players; // other clients +vector physents; + VAR(sensitivity, 0, 10, 1000); VAR(sensitivityscale, 1, 1, 100); VAR(invmouse, 0, 0, 1); @@ -48,6 +50,7 @@ void spawnstate(dynent *d) // reset player state not persistent acc //d->armourtype = A_BLUE; //d->quadmillis = 0; d->gunselect = GUN_PISTOL; + d->mag[6]=10; d->gunwait = 0; d->attacking = false; d->lastaction = 0; @@ -305,6 +308,23 @@ void otherplayers() }; }; +extern void explode_nade(physent *i); + +void mphysents() +{ + loopv(physents) if(physents[i]) + { + physent *p = physents[i]; + if(p->throwed) movephysent(p); + if(lastmillis - p->millis >= 5000) + { + explode_nade(physents[i]); + physents.remove(i); + i--; + }; + }; +}; + int sleepwait = 0; string sleepcmd; void sleep(char *msec, char *cmd) { sleepwait = atoi(msec)+lastmillis; strcpy_s(sleepcmd, cmd); }; @@ -327,6 +347,7 @@ void updateworld(int millis) // main game update loop if(getclientnum()>=0) shoot(player1, worldpos); // only shoot when connected to server gets2c(); // do this first, so we have most accurate information when our player moves }; + mphysents(); otherplayers(); if(!demoplayback) { diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index d462553d..1fde141a 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -181,8 +181,10 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th e.x = getint(p)/DMF; e.y = getint(p)/DMF; e.z = getint(p)/DMF; - if(gun==GUN_SHOTGUN) createrays(s, e); - shootv(gun, s, e, d); + if(gun==GUN_SHOTGUN) createrays(s, e); + int nadesec = getint(p); + printf("nadesec: %i\n", nadesec); + shootv(gun, s, e, d, nadesec); break; }; diff --git a/source/src/cube.h b/source/src/cube.h index c3e8d977..3c55d5d9 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -166,12 +166,20 @@ struct dynent // players & monsters int primary; //primary gun int nextprimary; md3state animstate[3]; +}; + +struct physent : dynent // inheritance: tons of unused stuff, but makes life easier +{ + vec rot; + int millis; + bool throwed; + dynent *owner; }; #define SAVEGAMEVERSION 6 // bump if dynent/netprotocol changes or any other savegame/demo data bumped from 5 //enum { A_BLUE, A_GREEN, A_YELLOW }; // armour types... take 20/40/60 % off -enum { M_NONE = 0, M_SEARCH, M_HOME, M_ATTACKING, M_PAIN, M_SLEEP, M_AIMING }; // monster states +enum { M_NONE = 0, M_SEARCH, M_HOME, M_ATTACKING, M_PAIN, M_SLEEP, M_AIMING, M_NADE /* bloody hack*/ }; // monster states #define MAXCLIENTS 256 // in a multiplayer game, can be arbitrarily changed #define MAXTRANS 5000 // max amount of data to swallow in 1 go @@ -232,7 +240,8 @@ extern header hdr; // current map header extern int sfactor, ssize; // ssize = 2^sfactor extern int cubicsize, mipsize; // cubicsize = ssize^2 extern dynent *player1; // special client ent that receives input and acts as camera -extern dvector players; // all the other clients (in multiplayer) +extern dvector players; // all the other clients (in multiplayer) +extern vectorphysents; extern bool editmode; extern vector ents; // map entities extern vec worldpos; // current target of the crosshair in the world diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 268c720c..1207f368 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -246,9 +246,9 @@ void radd(dynent *d) void item(int num) { - if (num>0 && num<6) player1->nextprimary = num; + if (num>0 && num<7) player1->nextprimary = num; - if (num==6) conoutf("sorry, no nades yet"); + //if (num==6) conoutf("sorry, no nades yet"); if (num==7) { player1->hasarmour=!player1->hasarmour; /*toggle armour*/ }; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 703dbb13..e3ecf662 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -116,7 +116,7 @@ bool collide(dynent *d, bool spawn, float drop, float rise) if(!o || o==d) continue; if(!plcollide(d, o, headspace)) return false; }; - if(d!=player1) if(!plcollide(d, player1, headspace)) return false; + if(d!=player1 && d->mtype!=M_NADE) if(!plcollide(d, player1, headspace)) return false; headspace -= 0.01f; mmcollide(d, hi, lo); // collide with map models @@ -232,22 +232,22 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime) { if(pl->onfloor || water) { - if (pl->onfloor || !pl->vel.z) - { + if (pl->onfloor || !pl->vel.z) + { int damage = (int)pl->startheight - (int)pl->o.z; - if (damage > 8 && local) //try adding "&& local" if falling not fixed - { - selfdamage(damage,-1,pl); - demodamage(damage, player1->o); - playsound(S_FALL1+rnd(2), &pl->o); + if (damage > 8 && local) //try adding "&& local" if falling not fixed + { + selfdamage(damage,-1,pl); + demodamage(damage, player1->o); + playsound(S_FALL1+rnd(2), &pl->o); }; pl->startheight=pl->o.z; }; if(pl->jumpnext) { - pl->jumpnext = false; - pl->vel.z = 1.7f; // physics impulse upwards + pl->jumpnext = false; + pl->vel.z = 1.7f; // physics impulse upwards if(water) { pl->vel.x /= 8; pl->vel.y /= 8; }; // dampen velocity change even harder, gives correct water feel if(local) playsoundc(S_JUMP); else if(pl->monsterstate) playsound(S_JUMP, &pl->o); @@ -329,10 +329,138 @@ void moveplayer(dynent *pl, int moveres, bool local, int curtime) if(!pl->inwater && water) { playsound(S_SPLASH2, &pl->o); pl->vel.z = 0; } else if(pl->inwater && !water) playsound(S_SPLASH1, &pl->o); pl->inwater = water; -}; +}; void moveplayer(dynent *pl, int moveres, bool local) { loopi(physicsrepeat) moveplayer(pl, moveres, local, i ? curtime/physicsrepeat : curtime-curtime/physicsrepeat*(physicsrepeat-1)); }; + +void movephysent(physent *pl) +{ + int moveres = 2; + bool local=true; + loopj(physicsrepeat) + { + const bool water = hdr.waterlevel>pl->o.z-0.5f; + const bool floating = (editmode && local); + vec d; // vector of direction we ideally want to move in + + d = pl->vel; + + + const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed; + const float friction = water ? 20.0f : (pl->onfloor || floating ? 6.0f : 30.0f); + + const float fpsfric = friction/curtime*20.0f; + + vmul(pl->vel, fpsfric-1); // slowly apply friction and direction to velocity, gives a smooth movement + vadd(pl->vel, d); + vdiv(pl->vel, fpsfric); + d = pl->vel; + vmul(d, speed); // d is now frametime based velocity vector + + +/* if(floating || water) + { + d.x *= (float)cos(rad(pl->pitch)); + d.y *= (float)cos(rad(pl->pitch)); + d.z = (float)(pl->move*sin(rad(pl->pitch))); + };*/ + + /*if(pl->onfloor || water) + { + if(pl->jumpnext) + { + pl->jumpnext = false; + pl->vel.z = 1.7f; // physics impulse upwards + if(water) { pl->vel.x /= 8; pl->vel.y /= 8; }; // dampen velocity change even harder, gives correct water feel + //if(local) playsoundc(S_JUMP); + } + else if(pl->timeinair>800) // if we land after long time must have been a high jump, make thud sound + { + //if(local) playsoundc(S_LAND); + //else if(pl->monsterstate) playsound(S_LAND, &pl->o); + }; + pl->timeinair = 0; + } + else + { + pl->timeinair += curtime; + };*/ + + if(pl->onfloor) + { + pl->timeinair = 0; + vmul(pl->vel, 0.8f); + } + else + { + pl->timeinair += curtime; + pl->pitch = (lastmillis-pl->millis) % 360; + pl->yaw = pl->pitch; + }; + + + //const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed; + + const float gravity = 20; + const float f = 1.0f/moveres; + float dropf = pl->timeinair/15.0f; // incorrect, but works fine + if(water) { dropf = 5; pl->timeinair = 0; }; // float slowly down in water + const float drop = dropf*curtime/gravity/100/moveres; // at high fps, gravity kicks in too fast + const float rise = speed/moveres/1.2f; // extra smoothness when lifting up stairs +// if(pl->mtype = M_NADE)printf("%i\n", pl->onfloor); +/* d.x -= d.x/50.0f*curtime; + d.y -= d.y/50.0f*curtime;*/ + + + loopi(moveres) // discrete steps collision detection & sliding + { + // try move forward + pl->o.x += f*d.x; + pl->o.y += f*d.y; + pl->o.z += f*d.z; + if(collide(pl, false, drop, rise)) continue; + // player stuck, try slide along y axis + pl->blocked = true; + pl->o.x -= f*d.x; + if(collide(pl, false, drop, rise)) { pl->vel.x = -d.x; vmul(pl->vel, 0.8f); d.x = 0; continue; }; + pl->o.x += f*d.x; + // still stuck, try x axis + pl->o.y -= f*d.y; + if(collide(pl, false, drop, rise)) { pl->vel.y = -d.y; vmul(pl->vel, 0.8f); d.y = 0; continue; }; + pl->o.y += f*d.y; + // try just dropping down + pl->moving = false; + pl->o.x -= f*d.x; + pl->o.y -= f*d.y; + if(collide(pl, false, drop, rise)) { d.y = d.x = 0; vmul(pl->vel, 0.8f); continue; }; + pl->o.z -= f*d.z; + break; + }; + + // detect wether player is outside map, used for skipping zbuffer clear mostly + + + + if(pl->o.x < 0 || pl->o.x >= ssize || pl->o.y <0 || pl->o.y > ssize) + { + pl->outsidemap = true; + } + else + { + sqr *s = S((int)pl->o.x, (int)pl->o.y); + pl->outsidemap = SOLID(s) + || pl->o.z < s->floor - (s->type==FHF ? s->vdelta/4 : 0) + || pl->o.z > s->ceil + (s->type==CHF ? s->vdelta/4 : 0); + }; + + // play sounds on water transitions + + if(!pl->inwater && water) { playsound(S_SPLASH2, &pl->o); pl->vel.z = 0; } + else if(pl->inwater && !water) playsound(S_SPLASH1, &pl->o); + pl->inwater = water; + }; +}; diff --git a/source/src/protos.h b/source/src/protos.h index d5d8abbb..60d5c8f3 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -162,7 +162,8 @@ extern void blendbox(int x1, int y1, int x2, int y2, bool border); extern void damageblend(int n); extern void addshotline(dynent *d, vec &from, vec &to); extern void rendershotlines(); -extern void shotlinereset(); +extern void shotlinereset(); +extern void renderphysents(); // renderparticles extern void setorient(vec &r, vec &u); @@ -188,7 +189,8 @@ extern void moveplayer(dynent *pl, int moveres, bool local); extern bool collide(dynent *d, bool spawn, float drop, float rise); extern void entinmap(dynent *d); extern void setentphysics(int mml, int mmr); -extern void physicsframe(); +extern void physicsframe(); +extern void movephysent(physent *pl); // sound extern void playsound(int n, vec *loc = 0); @@ -226,7 +228,7 @@ extern ENetPacket *recvmap(int n); // weapon //extern void selectgun(int a = -1, int b = -1, int c =-1); extern void shoot(dynent *d, vec &to); -extern void shootv(int gun, vec &from, vec &to, dynent *d = 0, bool local = false); +extern void shootv(int gun, vec &from, vec &to, dynent *d = 0, bool local = false, int nadesec = -1); extern void createrays(vec &from, vec &to); extern void moveprojectiles(float time); extern void projreset(); diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index c6a56129..69af7559 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -478,5 +478,14 @@ void rendershotlines() glPopMatrix(); }; +}; + +void renderphysents() +{ + loopv(physents) + { + physent *d = physents[i]; + if(d && d->throwed) rendermodel("vwep/grenade", 0, 1, 0, 1.5f, d->o.x, d->o.z, d->o.y, d->yaw, d->pitch, false, 2.0f, 100, 0, 0); + }; }; diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 99cd342b..fb674810 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -378,7 +378,11 @@ void gl_drawframe(int w, int h, float changelod, float curfps) renderentities(); renderspheres(curtime); - renderents(); + renderents(); + + renderphysents(); + + rendershotlines(); glDisable(GL_CULL_FACE); @@ -388,8 +392,7 @@ void gl_drawframe(int w, int h, float changelod, float curfps) int nquads = renderwater(hf); overbright(2); - render_particles(curtime); - rendershotlines(); + render_particles(curtime); overbright(1); glDisable(GL_FOG); diff --git a/source/src/serverutil.cpp b/source/src/serverutil.cpp index 34adb170..13a0252b 100644 --- a/source/src/serverutil.cpp +++ b/source/src/serverutil.cpp @@ -39,7 +39,7 @@ const char *modestr(int n) { return (n>=0 && n<6) ? modenames[n] : "unknown"; }; char msgsizesl[] = // size inclusive message token, 0 for variable or not-checked sizes { SV_INITS2C, 4, SV_INITC2S, 0, SV_POS, 12, SV_TEXT, 0, SV_SOUND, 2, SV_CDIS, 2, - SV_DIED, 2, SV_DAMAGE, 4, SV_SHOT, 8, SV_FRAGS, 2, + SV_DIED, 2, SV_DAMAGE, 4, SV_SHOT, 9, SV_FRAGS, 2, SV_TIMEUP, 2, SV_EDITENT, 10, SV_MAPRELOAD, 2, SV_ITEMACC, 2, SV_MAPCHANGE, 0, SV_ITEMSPAWN, 2, SV_ITEMPICKUP, 3, SV_DENIED, 2, SV_PING, 2, SV_PONG, 2, SV_CLIENTPING, 2, SV_GAMEMODE, 2, diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index bb9311e5..99ce00a8 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -30,7 +30,7 @@ guninfo guns[NUMGUNS] = { S_ASSULT, S_RASSULT, 2000, 130, 20, 0, 0, 20, 40, 20, assult_rot, assult_back, "assult" }, //recoil was 44 - { S_GRENADE, S_NULL, 0, 2000, 40, 30, 6, 1, 1, 1, 3, 1, "grenade" }, + { S_GRENADE, S_NULL, 0, 2000, 180, 30, 6, 1, 1, 1, 3, 1, "grenade" }, }; void updatekickback() { @@ -239,8 +239,8 @@ void hit(int target, int damage, dynent *d, dynent *at) demodamage(damage, d->o); }; -const float RL_RADIUS = 5; -const float RL_DAMRAD = 7; // hack +const float RL_RADIUS = 10; +const float RL_DAMRAD = 10; // hack void radialeffect(dynent *o, vec &v, int cn, int qdam, dynent *at) { @@ -328,8 +328,97 @@ void moveprojectiles(float time) p->o = v; }; }; + +extern float rad(float x); + +bool nade_activated = false; +physent *curnade; + +void thrownade(dynent *d, vec &to, bool prepare) +{ + physent *p; + if(prepare) p = (physent *)gp()->alloc(sizeof(physent)); + else if(curnade) p = curnade; + else return; + + p->owner = d; + if(!prepare) + { + p->yaw = 270; + p->pitch = 0; + p->roll = 0; + p->maxspeed = 16; //16 max speed, 14 max with armour + p->outsidemap = false; + p->inwater = false; + p->radius = 0.2f; + p->eyeheight = 0.3; + p->aboveeye = 0.0f; + p->frags = 0; + p->plag = 0; + p->ping = 0; + p->lastupdate = lastmillis; + p->enemy = NULL; + p->monsterstate = 0; + p->name[0] = p->team[0] = 0; + p->blocked = false; + p->lifesequence = 0; + p->state = CS_ALIVE; + p->shots = 0; + p->reloading = false; + p->nextprimary = 1; + p->hasarmour = false; + + p->k_left = false; + p->k_right = false; + p->k_up = false; + p->k_down = false; + p->jumpnext = false; + p->strafe = 0; + p->move = 0; + + p->timeinair = 0; + p->throwed = true; + p->onfloor = false; + + p->o = d->o; + + p->vel.x = sin(rad(d->yaw)); + p->vel.y = -cos(rad(d->yaw)); + p->vel.z = 0; + + float speed = (d->pitch+90)/180; + p->vel.x *= speed; + p->vel.y *= speed; + + p->vel.z = (d->pitch+90)/180; + vmul(p->vel, 2.2f); + + vadd(p->o, p->vel); vadd(p->o, p->vel); //vadd(p->o, p->vel); vadd(p->o, p->vel); + } + else + { + p->millis = lastmillis; + physents.add(p); + }; + + curnade = p; + nade_activated = prepare; +}; + +extern void explode_nade(physent *i) +{ + /*struct projectile { vec o, to; float speed; dynent *owner; int gun; bool inuse, local; }; + + projectile p; + p.o = + + splash(projectile *p, vec &v, vec &vold, int notthisplayer, int notthismonster, int qdam);*/ + + if(!i) return; + newprojectile(i->o, i->o, 1, true, i->owner, GUN_GRENADE); +}; -void shootv(int gun, vec &from, vec &to, dynent *d, bool local) // create visual effect from a shot +void shootv(int gun, vec &from, vec &to, dynent *d, bool local, int nadesec) // create visual effect from a shot { playsound(guns[gun].sound, d==player1 ? NULL : &d->o); int pspeed = 25; @@ -354,8 +443,13 @@ void shootv(int gun, vec &from, vec &to, dynent *d, bool local) // create vi case GUN_GRENADE: pspeed = guns[gun].projspeed; - newprojectile(from, to, (float)pspeed, local, d, gun); - conoutf("NADE"); + //newprojectile(from, to, (float)pspeed, local, d, gun); + thrownade(d, to, d==player1 ? d->attacking : false); + if(curnade) + { + curnade->millis = lastmillis - nadesec; + + }; break; case GUN_SNIPER: @@ -462,13 +556,27 @@ void spreadandrecoil(vec & from, vec & to, dynent * d) }; void shoot(dynent *d, vec &targ) -{ +{ + if(d==player1 && d->gunselect==GUN_GRENADE) // throw nade at mouse release + { + if(d->attacking && !nade_activated) + { + thrownade(d, targ, true); + return; + } + else if(d->attacking && nade_activated) return; + else if(!d->attacking && nade_activated) d->attacking = true; + } int attacktime = lastmillis-d->lastaction; if(d->reloading && (attacktimegunwait)) return; else if(attacktimegunwait) return; d->gunwait = 0; d->reloading = false; - if(!d->attacking) { d->shots = 0; return; }; + if(!d->attacking) + { + d->shots = 0; + return; + }; if(!(d->gunselect==GUN_SUBGUN || d->gunselect==GUN_ASSULT)) d->attacking = false; //makes sub/assult autos else { @@ -497,7 +605,7 @@ void shoot(dynent *d, vec &targ) //if(d->quadmillis && attacktime>200) playsoundc(S_ITEMPUP); shootv(d->gunselect, from, to, d, true); - 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)); + addmsg(1, 9, 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), (int) (d==player1 && d->gunselect==GUN_GRENADE ? lastmillis-curnade->millis : 0) ); d->gunwait = guns[d->gunselect].attackdelay; if(guns[d->gunselect].projspeed) return;