diff --git a/source/src/entities.cpp b/source/src/entities.cpp index cfccbe36..338d70e4 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -3,6 +3,8 @@ #include "pch.h" #include "cube.h" +const int physent::crouchtime = 200; + vector ents; const char *entnames[] = @@ -16,7 +18,6 @@ const char *entnames[] = const char *entmdlnames[] = { -//FIXME : fix the "pickups" infront "pickups/pistolclips", "pickups/ammobox", "pickups/nades", "pickups/health", "pickups/kevlar", "pickups/akimbo", }; @@ -161,7 +162,7 @@ void checkitems(playerent *d) if(e.type==CTF_FLAG) { vec v(e.x, e.y, e.z); - if(d->o.dist(v)<5.0f) trypickup(i, d); + if(objcollide(d, v, 2.5f, 4.0f)) trypickup(i, d); } else { diff --git a/source/src/entity.h b/source/src/entity.h index ad794547..9c34ea6b 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -100,6 +100,7 @@ struct physent int lastcrouch; char move, strafe; uchar state, type; + static const int crouchtime; physent() : o(0, 0, 0), yaw(270), pitch(0), roll(0), pitchvel(0), crouching(false), lastcrouch(0), state(CS_ALIVE) @@ -118,9 +119,9 @@ struct physent virtual float dyneyeheight() { - extern int lastmillis, crouchtime; + extern int lastmillis; const float croucheyeheight = eyeheight*3.0f/4.0f; - const float t = (lastmillis-lastcrouch)/(float)crouchtime; + const float t = (lastmillis-lastcrouch)/(float)physent::crouchtime; if(lastcrouch && t < 1.0f && t >= 0.0f) // crouch move in progress { diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 6163f4d1..13424604 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -108,16 +108,26 @@ void mmcollide(physent *d, float &hi, float &lo) // collide with a map const float r = mmi.rad+d->radius; if(fabs(e.x-d->o.x)o.y)floor+mmi.zoff+e.attr3); - float dz = d->o.z+(-eyeheight+d->aboveeye)/2.0f; + const float mmz = (float)(S(e.x, e.y)->floor+mmi.zoff+e.attr3); + const float dz = d->o.z+(-eyeheight+d->aboveeye)/2.0f; if(dzlo) lo = mmz+mmi.h; } } } -// TESTME -VARP(crouchtime, 1, 200, 20000); +bool objcollide(physent *d, vec &objpos, float objrad, float objheight) // collide with custom/typeless objects +{ + const float r = d->radius+objrad; + if(fabs(objpos.x-d->o.x)o.y)eyeheight+d->aboveeye, objheight); + const float dz = d->o.z+(-d->eyeheight+d->aboveeye)/2.0f; + const float objz = objpos.z+objheight/2.0f; + return dz-objz <= maxdist || dz-objz >= -maxdist; + } + return false; +} // all collision happens here // spawn is a dirty side effect used in spawning @@ -217,7 +227,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) d->vel.z = 0; // cancel out jumping velocity } - d->onfloor = d->o.z-eyeheight-lo < (lastmillis-d->lastcrouch<=crouchtime ? 0.1f : 0.01f); + d->onfloor = d->o.z-eyeheight-lo < (lastmillis-d->lastcrouch<=physent::crouchtime ? 0.1f : 0.01f); } return true; } @@ -515,8 +525,8 @@ void updatecrouch(playerent *p, bool on) if(p->crouching == on) return; p->crouching = on; const int progress = lastmillis-p->lastcrouch; - if(progress > crouchtime) p->lastcrouch = lastmillis; // new crouch - else p->lastcrouch = lastmillis-(crouchtime-progress); // only change direction, fix progress time + if(progress > physent::crouchtime) p->lastcrouch = lastmillis; // new crouch + else p->lastcrouch = lastmillis-(physent::crouchtime-progress); // only change direction, fix progress time } void crouch(bool on) diff --git a/source/src/protos.h b/source/src/protos.h index 5560abe4..4fefb369 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -430,6 +430,7 @@ extern void mousemove(int dx, int dy); extern void fixcamerarange(physent *cam = camera1); extern float floor(short x, short y); extern void updatecrouch(playerent *p, bool on); +extern bool objcollide(physent *d, vec &objpos, float objrad, float objheight); // sound extern void playsound(int n, physent *p = NULL, entity *ent = NULL, const vec *v = NULL, int priority = SP_NORMAL);