*** empty log message ***

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@77 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
driAn
2005-10-27 23:32:52 +00:00
parent 123b2f08c0
commit b113d0e05b
10 changed files with 315 additions and 33 deletions
+21
View File
@@ -13,6 +13,8 @@ bool intermission = false;
dynent *player1 = newdynent(); // our client
dvector players; // other clients
vector <physent *>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)
{
+3 -1
View File
@@ -182,7 +182,9 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th
e.y = getint(p)/DMF;
e.z = getint(p)/DMF;
if(gun==GUN_SHOTGUN) createrays(s, e);
shootv(gun, s, e, d);
int nadesec = getint(p);
printf("nadesec: %i\n", nadesec);
shootv(gun, s, e, d, nadesec);
break;
};
+10 -1
View File
@@ -168,10 +168,18 @@ struct dynent // players & monsters
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
@@ -233,6 +241,7 @@ 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 vector<physent *>physents;
extern bool editmode;
extern vector<entity> ents; // map entities
extern vec worldpos; // current target of the crosshair in the world
+2 -2
View File
@@ -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*/ };
+136 -8
View File
@@ -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,14 +232,14 @@ 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;
};
@@ -336,3 +336,131 @@ 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;
};
};
+3 -1
View File
@@ -163,6 +163,7 @@ extern void damageblend(int n);
extern void addshotline(dynent *d, vec &from, vec &to);
extern void rendershotlines();
extern void shotlinereset();
extern void renderphysents();
// renderparticles
extern void setorient(vec &r, vec &u);
@@ -189,6 +190,7 @@ 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 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();
+9
View File
@@ -480,3 +480,12 @@ void rendershotlines()
};
};
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);
};
};
+4 -1
View File
@@ -380,6 +380,10 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
renderspheres(curtime);
renderents();
renderphysents();
rendershotlines();
glDisable(GL_CULL_FACE);
drawhudgun(w, h, aspect, farplane);
@@ -389,7 +393,6 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
overbright(2);
render_particles(curtime);
rendershotlines();
overbright(1);
glDisable(GL_FOG);
+1 -1
View File
@@ -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,
+116 -8
View File
@@ -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)
{
@@ -329,7 +329,96 @@ void moveprojectiles(float time)
};
};
void shootv(int gun, vec &from, vec &to, dynent *d, bool local) // create visual effect from a shot
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, 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:
@@ -463,12 +557,26 @@ 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 && (attacktime<d->gunwait)) return;
else if(attacktime<d->gunwait) 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;