diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index ed1440a2..7d335786 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -323,7 +323,7 @@ void updateworld(int curtime, int lastmillis) // 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 } - mbounceents(); + movebounceents(); otherplayers(); if(!demoplayback) { @@ -350,23 +350,6 @@ void updateworld(int curtime, int lastmillis) // main game update loop } } -void entinmap(physent *d) // brute force but effective way to find a free spawn spot in the map -{ - loopi(100) // try max 100 times - { - float dx = (rnd(21)-10)/10.0f*i; // increasing distance - float dy = (rnd(21)-10)/10.0f*i; - d->o.x += dx; - d->o.y += dy; - if(collide(d, true, 0, 0)) return; - d->o.x -= dx; - d->o.y -= dy; - } - conoutf("can't find entity spawn spot! (%d, %d)", d->o.x, d->o.y); - // leave ent at original pos, possibly stuck -} - - #define SECURESPAWNDIST 15 int spawncycle = -1; int fixspawn = 2; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index f46d537c..8cb96870 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -365,76 +365,6 @@ void moveplayer(physent *p, int moveres, bool local) loopi(physicsrepeat) moveplayer(p, moveres, local, min(curtime, minframetime)); } -vector bounceents; - -bounceent *newbounceent() -{ - bounceent *p = new bounceent; - bounceents.add(p); - return p; -} - -extern void explode_nade(bounceent *i); - -void mbounceents() -{ - loopv(bounceents) if(bounceents[i]) - { - bounceent *p = bounceents[i]; - if(p->bouncestate == NADE_THROWED || p->bouncestate == GIB) //moveplayer(p, 2, false); - loopi(physicsrepeat) moveplayer(p, 2, false, min(curtime, minframetime)); - - if(lastmillis - p->millis >= p->timetolife) - { - if(p->bouncestate==NADE_ACTIVATED || p->bouncestate==NADE_THROWED) explode_nade(bounceents[i]); - delete p; - bounceents.remove(i); - i--; - } - } -} - -void clearbounceents() -{ - loopv(bounceents) if(bounceents[i]) { delete bounceents[i]; bounceents.remove(i); } -} - -VARP(gibnum, 0, 6, 1000); -VARP(gibttl, 0, 5000, 15000); -VARP(gibspeed, 1, 30, 100); - -void addgib(playerent *d) -{ - if(!d) return; - playsound(S_GIB, &d->o); - - loopi(gibnum) - { - bounceent *p = newbounceent(); - p->owner = d; - p->millis = lastmillis; - p->timetolife = gibttl+rnd(10)*100; - p->bouncestate = GIB; - - p->o = d->o; - p->o.z -= d->aboveeye; - - p->yaw = (float)rnd(360); - p->pitch = (float)rnd(360); - - p->maxspeed = 30.0f; - p->rotspeed = 3.0f; - - const float angle = (float)rnd(360); - const float speed = (float)gibspeed; - - p->vel.x = sinf(RAD*angle)*rnd(1000)/1000.0f; - p->vel.y = cosf(RAD*angle)*rnd(1000)/1000.0f; - p->vel.z = rnd(1000)/1000.0f; - p->vel.mul(speed/100.0f); - } -} - // movement input code #define dir(name,v,d,s,os) void name(bool isdown) { player1->s = isdown; player1->v = isdown ? d : (player1->os ? -(d) : 0); player1->lastmove = lastmillis; } @@ -496,3 +426,19 @@ void mousemove(int dx, int dy) } } +void entinmap(physent *d) // brute force but effective way to find a free spawn spot in the map +{ + loopi(100) // try max 100 times + { + float dx = (rnd(21)-10)/10.0f*i; // increasing distance + float dy = (rnd(21)-10)/10.0f*i; + d->o.x += dx; + d->o.y += dy; + if(collide(d, true, 0, 0)) return; + d->o.x -= dx; + d->o.y -= dy; + } + conoutf("can't find entity spawn spot! (%d, %d)", d->o.x, d->o.y); + // leave ent at original pos, possibly stuck +} + diff --git a/source/src/protos.h b/source/src/protos.h index 8e126b6a..8b6c3479 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -227,12 +227,7 @@ extern void moveplayer(physent *pl, int moveres, bool local); extern void moveplayer(physent *pl, int moveres, bool local, int curtime); extern bool collide(physent *d, bool spawn, float drop, float rise); extern void entinmap(physent *d); -extern void setentphysics(int mml, int mmr); extern void physicsframe(); -extern bounceent *newbounceent(); -extern void mbounceents(); -extern void clearbounceents(); -extern void addgib(playerent *d); extern void mousemove(int dx, int dy); extern void fixcamerarange(physent *cam = camera1); @@ -290,6 +285,10 @@ extern void shoot(playerent *d, vec &to); extern void shootv(int gun, vec &from, vec &to, playerent *d = 0, bool local = false, int nademillis=0); extern void createrays(vec &from, vec &to); extern void moveprojectiles(float time); +extern bounceent *newbounceent(); +extern void movebounceents(); +extern void clearbounceents(); +extern void addgib(playerent *d); extern void projreset(); extern playerent *playerincrosshair(); extern int reloadtime(int gun); diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 7b68bee3..7251a27e 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -347,6 +347,76 @@ void moveprojectiles(float time) } } +vector bounceents; + +bounceent *newbounceent() +{ + bounceent *p = new bounceent; + bounceents.add(p); + return p; +} + +void explode_nade(bounceent *i); + +void movebounceents() +{ + loopv(bounceents) if(bounceents[i]) + { + bounceent *p = bounceents[i]; + if(p->bouncestate == NADE_THROWED || p->bouncestate == GIB) moveplayer(p, 2, false); + moveplayer(p, 2, false); + + if(lastmillis - p->millis >= p->timetolife) + { + if(p->bouncestate==NADE_ACTIVATED || p->bouncestate==NADE_THROWED) explode_nade(bounceents[i]); + delete p; + bounceents.remove(i); + i--; + } + } +} + +void clearbounceents() +{ + loopv(bounceents) if(bounceents[i]) { delete bounceents[i]; bounceents.remove(i); } +} + +VARP(gibnum, 0, 6, 1000); +VARP(gibttl, 0, 5000, 15000); +VARP(gibspeed, 1, 30, 100); + +void addgib(playerent *d) +{ + if(!d) return; + playsound(S_GIB, &d->o); + + loopi(gibnum) + { + bounceent *p = newbounceent(); + p->owner = d; + p->millis = lastmillis; + p->timetolife = gibttl+rnd(10)*100; + p->bouncestate = GIB; + + p->o = d->o; + p->o.z -= d->aboveeye; + + p->yaw = (float)rnd(360); + p->pitch = (float)rnd(360); + + p->maxspeed = 30.0f; + p->rotspeed = 3.0f; + + const float angle = (float)rnd(360); + const float speed = (float)gibspeed; + + p->vel.x = sinf(RAD*angle)*rnd(1000)/1000.0f; + p->vel.y = cosf(RAD*angle)*rnd(1000)/1000.0f; + p->vel.z = rnd(1000)/1000.0f; + p->vel.mul(speed/100.0f); + } +} + void throw_nade(playerent *d, const vec &vel, bounceent *p) { if(!p || !d) return;