diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index ab9c8821..fb899ba8 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -564,13 +564,13 @@ void spawnplayer(playerent *d) void respawnself() { - if(m_mp(gamemode)) addmsg(SV_TRYSPAWN, "r"); + if( m_mp(gamemode) ) addmsg(SV_TRYSPAWN, "r"); else { showscores(false); setscope(false); - lasthit = 0; - spawnplayer(player1); + lasthit = 0; + spawnplayer(player1); player1->lifesequence++; player1->weaponswitch(player1->primweap); player1->weaponchanging -= weapon::weaponchangetime/2; diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 0e4f25a5..f34845fe 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -242,6 +242,8 @@ void showhudextras(char hudextras, char value){ } } +int lastspawn = 0; + void parsemessages(int cn, playerent *d, ucharbuf &p) { static char text[MAXTRANS]; @@ -474,7 +476,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) case SV_SPAWNSTATE: { - if (!good_map()) { // if the client is not in a good map, he will never spawn // this will disrupt hacked servers + if ( !good_map() ) { loopi(6+2*NUMGUNS) getint(p); break; } @@ -492,6 +494,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) loopi(NUMGUNS) player1->ammo[i] = getint(p); loopi(NUMGUNS) player1->mag[i] = getint(p); player1->state = CS_ALIVE; + lastspawn = lastmillis; findplayerstart(player1, false, arenaspawn); arenaintermission = 0; if(m_arena && !localwrongmap) diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 845901bc..b95d7e99 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -179,17 +179,19 @@ void pickupeffects(int n, playerent *d) // these functions are called when the client touches the item +extern int lastspawn; + void trypickup(int n, playerent *d) { entity &e = ents[n]; switch(e.type) { default: - if(d->canpickup(e.type)) + if( d->canpickup(e.type) && lastmillis > e.lastmillis + 1000 && lastmillis > lastspawn + 1000 ) { if(d->type==ENT_PLAYER) addmsg(SV_ITEMPICKUP, "ri", n); else if(d->type==ENT_BOT && serverpickup(n, -1)) pickupeffects(n, d); - e.spawned = false; + e.lastmillis = lastmillis; } break; @@ -289,6 +291,7 @@ void spawnallitems() // spawns items locally { ents[i].spawned = true; ents[i].twice = false; + ents[i].lastmillis = lastmillis; } } @@ -305,6 +308,7 @@ void setspawn(int i, bool on) { if(ents.inrange(i)) { ents[i].twice = (ents[i].type == I_GRENADE && ents[i].spawned && on ? true : false); ents[i].spawned = on; + ents[i].lastmillis = lastmillis; // to control trypickup spam } } diff --git a/source/src/entity.h b/source/src/entity.h index d553fc97..e6888641 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -32,6 +32,7 @@ struct persistent_entity // map entity struct entity : persistent_entity { bool spawned, twice; //the dynamic states of a map entity + int lastmillis; entity(short x, short y, short z, uchar type, short attr1, uchar attr2, uchar attr3, uchar attr4) : persistent_entity(x, y, z, type, attr1, attr2, attr3, attr4), spawned(false), twice(false) {} entity() {} bool fitsmode(int gamemode) { return !m_noitems && isitem(type) && !(m_noitemsnade && type!=I_GRENADE) && !(m_pistol && type==I_AMMO); } @@ -253,9 +254,8 @@ public: case I_AMMO: return ammo[primary]isspectating() && player1->spectatemode==SM_FOLLOW1ST) return; - float dx = odx, dy = ody; - float cursens = sensitivity; - if ( mfilter > 0.0 && totalmillis < curtime * 2 + mousemillis ) { - float mousefilter=mfilter/curtime*14; - dx = fdx = ( fdx * mousefilter + dx )/( mousefilter + 1 ); - dy = fdy = ( fdy * mousefilter + dy )/( mousefilter + 1 ); + + float dx = odx, dy = ody; + int dt = totalmillis - mousemillis; + if ( mfilter > 0.0 && dt ) { + float k = curtime * mfilter; + fdx = dx = ( dt*dx + fdx*k )/( dt + k ); + fdy = dy = ( dt*dy + fdy*k )/( dt + k ); } - mousemillis=totalmillis; + if (odx || ody) mousemillis = totalmillis; if(mouseaccel && curtime && (dx || dy)) cursens += mouseaccel * sqrtf(dx*dx + dy*dy)/curtime; cursens /= 33.0f*sensitivityscale; camera1->yaw += dx*cursens; diff --git a/source/src/server.cpp b/source/src/server.cpp index 365f1913..0dfed24d 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -45,7 +45,7 @@ int smode = 0, nextgamemode; static int interm = 0, minremain = 0, gamemillis = 0, gamelimit = 0, lmsitemtype = 0; mapstats smapstats; vector sents; -char *maplayout = NULL; +char *maplayout = NULL, *testlayout = NULL; int maplayout_factor; servermapbuffer mapbuffer; @@ -992,7 +992,7 @@ bool items_blocked = false; // FIXME bool free_items(int n) // FIXME { client *c = clients[n]; - int waitspawn = min(c->ping,200) + c->state.lastspawn; + int waitspawn = min(c->ping,200) + c->state.lastrespawn; return !items_blocked && (arenaroundstartmillis + waitspawn < gamemillis) ; } @@ -1272,7 +1272,7 @@ bool serverpickup(int i, int sender) // server side item pickup, acknowl sendf(-1, 1, "ri3", SV_ITEMACC, i, sender); cl->state.pickup(sents[i].type); if (e.twice) { - sendf(-1, 1, "ri3", SV_ITEMACC, i, sender); + sendf(-1, 1, "ri3", SV_ITEMACC, i, sender); // FIXME cl->state.pickup(sents[i].type); } } @@ -1294,7 +1294,7 @@ void checkitemspawns(int diff) sendf(-1, 1, "ri2", SV_ITEMSPAWN, i); if (m_lss && sents[i].type == I_GRENADE && rnd(101) > 66 ) { sents[i].twice = true; - sendf(-1, 1, "ri2", SV_ITEMSPAWN, i); + sendf(-1, 1, "ri2", SV_ITEMSPAWN, i); // FIXME } } } @@ -2495,7 +2495,7 @@ void process(ENetPacket *packet, int sender, int chan) { updateclientteam(sender, TEAM_ANYACTIVE, FTR_PLAYERWISH); } - if(!m_arena && canspawn(cl) < SP_OK_NUM) sendspawn(cl); + if( !m_arena && canspawn(cl) < SP_OK_NUM && gamemillis > cl->state.lastspawn + 1000 ) sendspawn(cl); break; case SV_SPAWN: @@ -2503,6 +2503,7 @@ void process(ENetPacket *packet, int sender, int chan) int ls = getint(p), gunselect = getint(p); if((cl->state.state!=CS_ALIVE && cl->state.state!=CS_DEAD) || ls!=cl->state.lifesequence || cl->state.lastspawn<0 || gunselect<0 || gunselect>=NUMGUNS) break; cl->state.lastspawn = -1; + cl->state.lastrespawn = gamemillis; cl->state.state = CS_ALIVE; cl->state.gunselect = gunselect; QUEUE_BUF( diff --git a/source/src/server.h b/source/src/server.h index 0a90d46e..d567ee5d 100644 --- a/source/src/server.h +++ b/source/src/server.h @@ -118,7 +118,7 @@ struct clientstate : playerstate { vec o; int state; - int lastdeath, lastspawn, lifesequence; + int lastdeath, lastspawn, lastrespawn, lifesequence; int lastshot; projectilestate<8> grenades; int akimbomillis; @@ -156,6 +156,7 @@ struct clientstate : playerstate o = vec(-1e10f, -1e10f, -1e10f); lastdeath = 0; lastspawn = -1; + lastrespawn = 0; lastshot = 0; akimbomillis = 0; scoped = false; diff --git a/source/src/serveractions.h b/source/src/serveractions.h index ee39ebbe..8e8e3205 100644 --- a/source/src/serveractions.h +++ b/source/src/serveractions.h @@ -40,7 +40,7 @@ bool mapisok(mapstats *ms) } else FlagFlag = MINFF * 1000; // the map has no flags - return Mheight < MAXMHEIGHT && (Mopen = checkarea(maplayout_factor, maplayout)) < MAXMAREA && FlagFlag > MINFF; + return Mheight < MAXMHEIGHT && (Mopen = checkarea(maplayout_factor, testlayout)) < MAXMAREA && FlagFlag > MINFF; } struct mapaction : serveraction @@ -69,7 +69,7 @@ struct mapaction : serveraction { bool notify = valid_client(caller); int maploc = MAP_NOTFOUND; - mapstats *ms = map[0] ? getservermapstats(map, true, &maploc) : NULL; // this is very redundant, since startgame gets the layout + mapstats *ms = map[0] ? getservermapstats(map, false, &maploc) : NULL; // this is very redundant, since startgame gets the layout mapok = mode == GMODE_COOPEDIT || ( ms != NULL && mapisok(ms) ); if(!mapok) { diff --git a/source/src/tools.cpp b/source/src/tools.cpp index a26e398a..5138fbad 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -24,7 +24,7 @@ const char *numtime() return numt; } -extern char *maplayout; +extern char *maplayout, *testlayout; extern int maplayout_factor, Mvolume, Marea; extern float Mheight; @@ -70,64 +70,70 @@ mapstats *loadmapstats(const char *filename, bool getlayout) enttypes[i] = e.type; entposs[i * 3] = e.x; entposs[i * 3 + 1] = e.y; entposs[i * 3 + 2] = e.z; } + DELETEA(testlayout); + if(s.hdr.sfactor <= LARGEST_FACTOR && s.hdr.sfactor >= SMALLEST_FACTOR) + { + maplayout_factor = s.hdr.sfactor; + int layoutsize = 1 << (maplayout_factor * 2); + bool fail = false; + testlayout = new char[layoutsize + 256]; + memset(testlayout, 0, layoutsize * sizeof(char)); + char *t = NULL; + char floor = 0, ceil, diff = 0; + Mvolume = Marea = 0; + loopk(layoutsize) + { + char *c = testlayout + k; + int type = f->getchar(); + switch(type) + { + case 255: + { + int n = f->getchar(); + if(!t || n < 0) { fail = true; break; } + memset(c, *t, n); + k += n - 1; + break; + } + case 254: // only in MAPVERSION<=2 + if(!t) { fail = true; break; } + *c = *t; + f->getchar(); f->getchar(); + break; + default: + if(type<0 || type>=MAXTYPE) { fail = true; break; } + floor = f->getchar(); + ceil = f->getchar(); + if(floor >= ceil && ceil > -128) floor = ceil - 1; // for pre 12_13 + diff = ceil - floor; + if(type == FHF) floor = -128; + f->getchar(); f->getchar(); + if(s.hdr.version>=2) f->getchar(); + if(s.hdr.version>=5) f->getchar(); + + case SOLID: + *c = type == SOLID ? 127 : floor; + f->getchar(); f->getchar(); + if(s.hdr.version<=2) { f->getchar(); f->getchar(); } + break; + } + if ( type != SOLID && diff > 6 ) { + Marea++; + Mvolume+=diff; + } + if(fail) break; + t = c; + } + if(fail) { DELETEA(testlayout); } + else Mheight = Marea ? (float)Mvolume/Marea : 0; + } if(getlayout) { DELETEA(maplayout); - if(s.hdr.sfactor <= LARGEST_FACTOR && s.hdr.sfactor >= SMALLEST_FACTOR) - { - maplayout_factor = s.hdr.sfactor; + if (testlayout) { int layoutsize = 1 << (maplayout_factor * 2); - bool fail = false; maplayout = new char[layoutsize + 256]; - memset(maplayout, 0, layoutsize * sizeof(char)); - char *t = NULL; - char floor = 0, ceil, diff = 0; - Mvolume = Marea = 0; - loopk(layoutsize) - { - char *c = maplayout + k; - int type = f->getchar(); - switch(type) - { - case 255: - { - int n = f->getchar(); - if(!t || n < 0) { fail = true; break; } - memset(c, *t, n); - k += n - 1; - break; - } - case 254: // only in MAPVERSION<=2 - if(!t) { fail = true; break; } - *c = *t; - f->getchar(); f->getchar(); - break; - default: - if(type<0 || type>=MAXTYPE) { fail = true; break; } - floor = f->getchar(); - ceil = f->getchar(); - if(floor >= ceil && ceil > -128) floor = ceil - 1; // for pre 12_13 - diff = ceil - floor; - if(type == FHF) floor = -128; - f->getchar(); f->getchar(); - if(s.hdr.version>=2) f->getchar(); - if(s.hdr.version>=5) f->getchar(); - - case SOLID: - *c = type == SOLID ? 127 : floor; - f->getchar(); f->getchar(); - if(s.hdr.version<=2) { f->getchar(); f->getchar(); } - break; - } - if ( type != SOLID && diff > 6 ) { - Marea++; - Mvolume+=diff; - } - if(fail) break; - t = c; - } - if(fail) { DELETEA(maplayout); } - else Mheight = Marea ? (float)Mvolume/Marea : 0; + memcpy(maplayout, testlayout, layoutsize * sizeof(char)); } } delete f; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 2f37bd1d..8ddc3563 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -96,6 +96,8 @@ void shiftweapon(int s) else if(player1->isspectating()) updatefollowplayer(s); } +bool quicknade = false; + void quicknadethrow(bool on) { if(player1->state != CS_ALIVE) return; @@ -110,8 +112,7 @@ void quicknadethrow(bool on) else { attack(false); - if(player1->weaponsel->type == GUN_GRENADE) player1->quicknade = true; -// if(player1->weaponsel->type == GUN_GRENADE) selectweapon(player1->prevweaponsel); + if(player1->weaponsel->type == GUN_GRENADE) quicknade = true; } } @@ -847,7 +848,7 @@ bool grenades::attack(vec &targ) break; case GST_INHAND: - if(waitdone || ( owner->quicknade && quickwait ) ) + if(waitdone || ( quicknade && quickwait ) ) { if(!owner->attacking || this!=owner->weaponsel) thrownade(); // throw else if(!inhandnade->isalive(lastmillis)) dropnade(); // drop & have fun @@ -911,8 +912,8 @@ void grenades::activatenade(const vec &to) void grenades::thrownade() { - if (owner->quicknade && owner->weaponsel->type == GUN_GRENADE) selectweapon(owner->prevweaponsel); - owner->quicknade = false; + if (quicknade && owner->weaponsel->type == GUN_GRENADE) selectweapon(owner->prevweaponsel); + quicknade = false; if(!inhandnade) return; const float speed = cosf(RAD*owner->pitch); vec vel(sinf(RAD*owner->yaw)*speed, -cosf(RAD*owner->yaw)*speed, sinf(RAD*owner->pitch));