From eb81f05ec9e44d8a1ccf9ec06169750f9bc44d34 Mon Sep 17 00:00:00 2001 From: driAn Date: Sun, 11 Nov 2007 14:20:52 +0000 Subject: [PATCH] crouching git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1419 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/bot/ac_bot_ai.cpp | 6 +++--- source/src/bot/bot_ai.cpp | 4 ++-- source/src/bot/bot_waypoint.cpp | 14 +++++++------- source/src/bot/botmanager.cpp | 9 +++++---- source/src/client.cpp | 2 +- source/src/clientgame.cpp | 3 +-- source/src/clients2c.cpp | 4 +++- source/src/editing.cpp | 1 + source/src/entities.cpp | 6 +++--- source/src/entity.h | 5 +++-- source/src/md2.h | 2 +- source/src/physics.cpp | 29 ++++++++++++++++++----------- source/src/rendermodel.cpp | 11 +++++------ source/src/weapon.cpp | 6 +++--- 14 files changed, 56 insertions(+), 46 deletions(-) diff --git a/source/src/bot/ac_bot_ai.cpp b/source/src/bot/ac_bot_ai.cpp index 8a509dda..a3bdfc77 100644 --- a/source/src/bot/ac_bot_ai.cpp +++ b/source/src/bot/ac_bot_ai.cpp @@ -120,7 +120,7 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight) { sScore = 0; entity &e = ents[i]; - vec o(e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight); + vec o(e.x, e.y, S(e.x, e.y)->floor+player1->dyneyeheight()); if (!ents[i].spawned) continue; if (OUTBORD(e.x, e.y)) continue; @@ -234,7 +234,7 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight) m_vGoal.x = pNewTargetEnt->x; m_vGoal.y = pNewTargetEnt->y; - m_vGoal.z = S(pNewTargetEnt->x, pNewTargetEnt->y)->floor+player1->eyeheight; + m_vGoal.z = S(pNewTargetEnt->x, pNewTargetEnt->y)->floor+player1->dyneyeheight(); } return pNewTargetEnt; @@ -245,7 +245,7 @@ bool CACBot::HeadToTargetEnt() if (m_pTargetEnt) { vec o(m_pTargetEnt->x, m_pTargetEnt->y, - S(m_pTargetEnt->x, m_pTargetEnt->y)->floor+m_pMyEnt->eyeheight); + S(m_pTargetEnt->x, m_pTargetEnt->y)->floor+m_pMyEnt->dyneyeheight()); if (m_pTargetEnt->spawned && (!UnderWater(m_pMyEnt->o) || !UnderWater(o))) diff --git a/source/src/bot/bot_ai.cpp b/source/src/bot/bot_ai.cpp index 49ea98d5..c71079a1 100644 --- a/source/src/bot/bot_ai.cpp +++ b/source/src/bot/bot_ai.cpp @@ -981,7 +981,7 @@ void CBot::DoCombatNav() { // Bot has already found an entity, still valid? vec v(m_pTargetEnt->x, m_pTargetEnt->y, - S(m_pTargetEnt->x, m_pTargetEnt->y)->floor+m_pMyEnt->eyeheight); + S(m_pTargetEnt->x, m_pTargetEnt->y)->floor+m_pMyEnt->dyneyeheight()); if ((GetDistance(v) > 25.0f) || !IsVisible(m_pTargetEnt)) m_pTargetEnt = NULL; } @@ -1002,7 +1002,7 @@ void CBot::DoCombatNav() { condebug("Combat ent"); vec v(m_pTargetEnt->x, m_pTargetEnt->y, - S(m_pTargetEnt->x, m_pTargetEnt->y)->floor+m_pMyEnt->eyeheight); + S(m_pTargetEnt->x, m_pTargetEnt->y)->floor+m_pMyEnt->dyneyeheight()); debugbeam(m_pMyEnt->o, v); diff --git a/source/src/bot/bot_waypoint.cpp b/source/src/bot/bot_waypoint.cpp index 33b4a73d..9512b868 100644 --- a/source/src/bot/bot_waypoint.cpp +++ b/source/src/bot/bot_waypoint.cpp @@ -1705,7 +1705,7 @@ void CCubeWaypointClass::StartFlood() if (e.type == TELEPORT) { - vec telepos = { e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight }, teledestpos = g_vecZero; + vec telepos = { e.x, e.y, S(e.x, e.y)->floor+player1->dyneyeheight() }, teledestpos = g_vecZero; // Find the teleport destination int n = -1, tag = e.attr1, beenhere = -1; @@ -1718,7 +1718,7 @@ void CCubeWaypointClass::StartFlood() { teledestpos.x = ents[n].x; teledestpos.y = ents[n].y; - teledestpos.z = S(ents[n].x, ents[n].y)->floor+player1->eyeheight; + teledestpos.z = S(ents[n].x, ents[n].y)->floor+player1->dyneyeheight(); break; } } @@ -1757,7 +1757,7 @@ void CCubeWaypointClass::StartFlood() } else if (e.type == CARROT) { - vec pos = { e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight }; + vec pos = { e.x, e.y, S(e.x, e.y)->floor+player1->dyneyeheight() }; int flags = (W_FL_FLOOD | W_FL_TRIGGER); if (S(e.x, e.y)->tag) flags |= W_FL_INTAG; @@ -1825,7 +1825,7 @@ void CCubeWaypointClass::CreateWPsAtTeleporters() if (e.type != TELEPORT) continue; if (OUTBORD(e.x, e.y)) continue; - vec telepos = { e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight }, teledestpos = g_vecZero; + vec telepos = { e.x, e.y, S(e.x, e.y)->floor+player1->dyneyeheight() }, teledestpos = g_vecZero; // Find the teleport destination int n = -1, tag = e.attr1, beenhere = -1; @@ -1838,7 +1838,7 @@ void CCubeWaypointClass::CreateWPsAtTeleporters() { teledestpos.x = ents[n].x; teledestpos.y = ents[n].y; - teledestpos.z = S(ents[n].x, ents[n].y)->floor+player1->eyeheight; + teledestpos.z = S(ents[n].x, ents[n].y)->floor+player1->dyneyeheight(); break; } } @@ -1870,7 +1870,7 @@ void CCubeWaypointClass::CreateWPsAtTriggers() if (e.type != CARROT) continue; if (OUTBORD(e.x, e.y)) continue; - vec pos = { e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight }; + vec pos = { e.x, e.y, S(e.x, e.y)->floor+player1->dyneyeheight() }; node_s *wp = AddWaypoint(pos, false); @@ -2391,7 +2391,7 @@ bool CBot::HeadToWaypoint() { // Check if bot has to jump vec from = m_pMyEnt->o; - from.z -= (m_pMyEnt->eyeheight - 1.25f); + from.z -= (m_pMyEnt->dyneyeheight() - 1.25f); float flEndDist; if (!IsVisible(from, FORWARD, 3.0f, false, &flEndDist) && (GetDistance(from, m_pCurrentWaypoint->pNode->v_origin) > flEndDist)) diff --git a/source/src/bot/botmanager.cpp b/source/src/bot/botmanager.cpp index 131130fd..1de2a744 100644 --- a/source/src/bot/botmanager.cpp +++ b/source/src/bot/botmanager.cpp @@ -859,7 +859,7 @@ void CBotManager::PickNextTrigger() #endif if (OUTBORD(e.x, e.y)) continue; - vec o(e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight); + vec o(e.x, e.y, S(e.x, e.y)->floor+player1->dyneyeheight()); node_s *pWptNearEnt = NULL; @@ -971,6 +971,7 @@ void addbot(char *arg1, char *arg2, char *arg3) if(!botmode()) return; conoutf("Creating bot...\n"); botent *b = BotManager.CreateBot(arg1, arg2, arg3); + if (b) conoutf("connected: %s", b->name); else @@ -1179,7 +1180,7 @@ void drawbeamtocarrots() loopv(ents) { entity &e = ents[i]; - vec o = { e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight }; + vec o = { e.x, e.y, S(e.x, e.y)->floor+player1->dyneyeheight() }; if ((e.type != CARROT) || !e.spawned) continue; particle_trail(1, 500, player1->o, o); } @@ -1192,7 +1193,7 @@ void drawbeamtoteleporters() loopv(ents) { entity &e = ents[i]; - vec o = { e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight }; + vec o = { e.x, e.y, S(e.x, e.y)->floor+player1->dyneyeheight() }; if (e.type != TELEPORT) continue; particle_trail(1, 500, player1->o, o); } @@ -1245,7 +1246,7 @@ void testvisible(int iDir) } vec from = player1->o; - from.z -= (player1->eyeheight - 1.25f); + from.z -= (player1->dyneyeheight() - 1.25f); end = from; makevec(&angles, player1->pitch, player1->yaw, player1->roll); angles.x=0; diff --git a/source/src/client.cpp b/source/src/client.cpp index 31884f75..23d89386 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -279,7 +279,7 @@ void c2sinfo(playerent *d) // send update to the server putint(q, (int)(d->vel.y*DVELF)); putint(q, (int)(d->vel.z*DVELF)); // pack rest in 1 int: strafe:2, move:2, onfloor:1, onladder: 1 - putuint(q, (d->strafe&3) | ((d->move&3)<<2) | (((int)d->onfloor)<<4) | (((int)d->onladder)<<5) | ((d->lifesequence&1)<<6)); + putuint(q, (d->strafe&3) | ((d->move&3)<<2) | (((int)d->onfloor)<<4) | (((int)d->onladder)<<5) | ((d->lifesequence&1)<<6) | (((int)d->crouching)<<7)); enet_packet_resize(packet, q.length()); sendpackettoserv(0, packet); diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index c9a2c6e6..ccf77c39 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -147,7 +147,6 @@ void spawnstate(playerent *d) // reset player state not persistent { d->respawn(); d->spawnstate(gamemode); - //d->lastaction = lastmillis; if(d==player1) { if(player1->skin!=player1->nextskin) setskin(player1, player1->nextskin); @@ -375,7 +374,7 @@ void showteamkill() { player1->lastteamkill = lastmillis; } void dodamage(int damage, playerent *pl, playerent *actor, bool gib, bool local) { - if(pl->state != CS_ALIVE || pl->state == CS_EDITING || intermission) return; + if(pl->state != CS_ALIVE || intermission) return; pl->lastpain = lastmillis; if(local) damage = pl->dodamage(damage); diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 6663b651..f9fcc9f6 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -29,7 +29,7 @@ void updatepos(playerent *d) const float dx = player1->o.x-d->o.x; const float dy = player1->o.y-d->o.y; const float dz = player1->o.z-d->o.z; - const float rz = player1->aboveeye+d->eyeheight; + const float rz = player1->aboveeye+d->dyneyeheight(); const float fx = (float)fabs(dx), fy = (float)fabs(dy), fz = (float)fabs(dz); if(fxstate!=CS_DEAD) { @@ -84,6 +84,8 @@ void parsepositions(ucharbuf &p) d->onfloor = f&1; f >>= 1; d->onladder = f&1; + f >>= 2; + d->crouching = f&1; updatepos(d); updatelagtime(d); if(d->state==CS_LAGGED || d->state==CS_SPAWNING) d->state = CS_ALIVE; diff --git a/source/src/editing.cpp b/source/src/editing.cpp index c21973b5..1afc87b7 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -50,6 +50,7 @@ void toggleedit() keyrepeat(editmode); selset = false; editing = editmode ? 1 : 0; + player1->state = editing ? CS_EDITING : CS_ALIVE; addmsg(SV_EDITMODE, "ri", editing); } diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 0eb165a2..3641745d 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -117,7 +117,7 @@ void trypickup(int n, playerent *d) break; case LADDER: - d->onladder = true; + if(!d->crouching) d->onladder = true; break; case CTF_FLAG: @@ -216,14 +216,14 @@ void checkitems(playerent *d) if(OUTBORD(e.x, e.y)) continue; vec v(e.x, e.y, d->o.z); float dist1 = d->o.dist(v); - float dist2 = d->o.z - (S(e.x, e.y)->floor+d->eyeheight); + float dist2 = d->o.z - (S(e.x, e.y)->floor+d->dyneyeheight()); if(dist1<1.5f && dist2floor+d->eyeheight); + vec v(e.x, e.y, S(e.x, e.y)->floor+d->dyneyeheight()); if(d->o.dist(v)<2.5f) trypickup(i, d); } } diff --git a/source/src/entity.h b/source/src/entity.h index e2b96da2..96bdcd45 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -93,8 +93,9 @@ struct physent float maxspeed; // cubes per second, 24 for player int timeinair; // used for fake gravity float radius, eyeheight, aboveeye; // bounding box size + float dyneyeheight() { return crouching ? eyeheight*3.0f/4.0f : eyeheight; } bool inwater; - bool onfloor, onladder, jumpnext; + bool onfloor, onladder, jumpnext, crouching; char move, strafe; uchar state, type; @@ -110,7 +111,7 @@ struct physent vel.x = vel.y = vel.z = 0; move = strafe = 0; timeinair = 0; - onfloor = onladder = inwater = jumpnext = false; + onfloor = onladder = inwater = jumpnext = crouching = false; } }; diff --git a/source/src/md2.h b/source/src/md2.h index c4190c18..be3b8cd9 100644 --- a/source/src/md2.h +++ b/source/src/md2.h @@ -157,7 +157,7 @@ struct md2 : vertmodel // I R A P P P J L F S T W P CI CW CA CP CD D D D LD LD LD F static int frame[] = { 0, 40, 46, 54, 58, 62, 66, 69, 72, 84, 95, 112,123,135,154,160,169,173,178,184,190,183,189,197, 0 }; static int range[] = { 40, 6, 8, 4, 4, 4, 3, 3, 12, 11, 17, 11, 12, 19, 6, 9, 4, 5, 6, 6, 8, 1, 1, 1, 7 }; - static int animfr[] = { 0, 1, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 24 }; + static int animfr[] = { 0, 1, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 24 }; if((size_t)anim >= sizeof(animfr)/sizeof(animfr[0])) { diff --git a/source/src/physics.cpp b/source/src/physics.cpp index dd930d74..16765381 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -66,11 +66,11 @@ bool plcollide(physent *d, physent *o, float &headspace, float &hi, float &lo) const float r = o->radius+d->radius, dx = o->o.x-d->o.x, dy = o->o.y-d->o.y; if(d->type==ENT_PLAYER && o->type==ENT_PLAYER ? dx*dx + dy*dy < r*r : fabs(dx)o.z-d->eyeheighto.z-o->eyeheight) { if(o->o.z-o->eyeheighto.z-o->eyeheight-1; } + if(d->o.z-d->dyneyeheight()o.z-o->dyneyeheight()) { if(o->o.z-o->dyneyeheight()o.z-o->dyneyeheight()-1; } else if(o->o.z+o->aboveeye>lo) lo = o->o.z+o->aboveeye+1; - if(fabs(o->o.z-d->o.z)aboveeye+d->eyeheight) { hitplayer = o; return false; } - headspace = d->o.z-o->o.z-o->aboveeye-d->eyeheight; + if(fabs(o->o.z-d->o.z)aboveeye+d->dyneyeheight()) { hitplayer = o; return false; } + headspace = d->o.z-o->o.z-o->aboveeye-d->dyneyeheight(); if(headspace<0) headspace = 10; } return true; @@ -106,7 +106,7 @@ void mmcollide(physent *d, float &hi, float &lo) // collide with a map if(fabs(e.x-d->o.x)o.y)floor+mmi.zoff+e.attr3); - if(d->o.z-d->eyeheighto.z-d->dyneyeheight()lo) lo = mmz+mmi.h; } } @@ -162,7 +162,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) if(floor>lo) lo = floor; } - if(hi-lo < d->eyeheight+d->aboveeye) return false; + if(hi-lo < d->dyneyeheight()+d->aboveeye) return false; // Modified by Rick: plcollide now takes hi and lo in account aswell, that way we can jump/walk on players @@ -181,17 +181,17 @@ bool collide(physent *d, bool spawn, float drop, float rise) if(spawn) { - d->o.z = lo+d->eyeheight; // just drop to floor (sideeffect) + d->o.z = lo+d->dyneyeheight(); // just drop to floor (sideeffect) d->onfloor = true; } else { - const float spacetop = d->o.z-d->eyeheight-lo; + const float spacetop = d->o.z-d->dyneyeheight()-lo; if(spacetop<0) { if(spacetop>-0.01) { - d->o.z = lo+d->eyeheight; // stick on step + d->o.z = lo+d->dyneyeheight(); // stick on step } else if(spacetop>-1.26f && d->type!=ENT_BOUNCE) d->o.z += rise; // rise thru stair else return false; @@ -209,7 +209,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) d->vel.z = 0; // cancel out jumping velocity } - d->onfloor = d->o.z-d->eyeheight-lo<0.01f; + d->onfloor = d->o.z-d->dyneyeheight()-lo<0.01f; } return true; } @@ -231,7 +231,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) const bool water = hdr.waterlevel>pl->o.z-0.5f; const bool floating = (editmode && local) || pl->state==CS_EDITING; - const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed; + const float speed = curtime/(water ? 2000.0f : 1000.0f)*(pl->crouching ? pl->maxspeed/2.0f : pl->maxspeed); const float friction = water ? 20.0f : (pl->onfloor || floating ? 6.0f : (pl->onladder ? 1.5f : 30.0f)); const float fpsfric = friction/curtime*20.0f; @@ -455,7 +455,7 @@ void moveplayer(physent *p, int moveres, bool local) dir(backward, move, -1, k_down, k_up); dir(forward, move, 1, k_up, k_down); dir(left, strafe, 1, k_left, k_right); -dir(right, strafe, -1, k_right, k_left); +dir(right, strafe, -1, k_right, k_left); void attack(bool on) { @@ -475,12 +475,19 @@ void jumpn(bool on) else player1->jumpnext = on; } +void crouch(bool on) +{ + if(intermission || player1->onladder) return; + player1->crouching = on; +} + COMMAND(backward, ARG_DOWN); COMMAND(forward, ARG_DOWN); COMMAND(left, ARG_DOWN); COMMAND(right, ARG_DOWN); COMMANDN(jump, jumpn, ARG_DOWN); COMMAND(attack, ARG_DOWN); +COMMAND(crouch, ARG_DOWN); void fixcamerarange(physent *cam) { diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index 840f9b5e..4c2a0fe9 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -333,7 +333,7 @@ void renderclient(playerent *d, char *mdlname, char *vwepname, int tex) int anim = ANIM_IDLE|ANIM_LOOP; float speed = 0.0; vec o(d->o); - o.z -= d->eyeheight; + o.z -= d->dyneyeheight(); int basetime = -((int)(size_t)d&0xFFF); if(d->state==CS_DEAD) { @@ -358,12 +358,11 @@ void renderclient(playerent *d, char *mdlname, char *vwepname, int tex) } else if(d->state==CS_EDITING) { anim = ANIM_JUMP|ANIM_END; } else if(d->state==CS_LAGGED) { anim = ANIM_SALUTE|ANIM_LOOP; } - else if(lastmillis-d->lastpain<300) { anim = ANIM_PAIN; speed = 300.0f/4; varseed += d->lastpain; basetime = d->lastpain; } + else if(lastmillis-d->lastpain<300) { anim = d->crouching ? ANIM_CROUCH_PAIN : ANIM_PAIN; speed = 300.0f/4; varseed += d->lastpain; basetime = d->lastpain; } else if(!d->onfloor && d->timeinair>50) { anim = ANIM_JUMP|ANIM_END; } - else if(d->gunselect==d->lastattackgun && lastmillis-d->lastaction<300) - { anim = ANIM_ATTACK; speed = 300.0f/8; basetime = d->lastaction; } - else if(!d->move && !d->strafe) { anim = ANIM_IDLE|ANIM_LOOP; } - else { anim = ANIM_RUN|ANIM_LOOP; speed = 1860/d->maxspeed; } + else if(d->gunselect==d->lastattackgun && lastmillis-d->lastaction<300) { anim = d->crouching ? ANIM_CROUCH_ATTACK : ANIM_ATTACK; speed = 300.0f/8; basetime = d->lastaction; } + else if(!d->move && !d->strafe) { anim = (d->crouching ? ANIM_CROUCH_IDLE : ANIM_IDLE)|ANIM_LOOP; } + else { anim = (d->crouching ? ANIM_CROUCH_WALK : ANIM_RUN)|ANIM_LOOP; speed = 1860/d->maxspeed; } rendermodel(mdlname, anim, tex, 1.5f, o, d->yaw+90, d->pitch/4, speed, basetime, d, vwepname); } diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index ab7399ed..c3a56d8b 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -176,8 +176,8 @@ static inline bool intersect(const vec &o, const vec &rad, const vec &from, cons bool intersect(dynent *d, const vec &from, const vec &to, vec *end) { vec o(d->o); - o.z += (d->aboveeye - d->eyeheight)/2; - return intersect(o, vec(d->radius, d->radius, (d->aboveeye + d->eyeheight)/2), from, to, end); + o.z += (d->aboveeye - d->dyneyeheight())/2; + return intersect(o, vec(d->radius, d->radius, (d->aboveeye + d->dyneyeheight())/2), from, to, end); } bool intersect(entity *e, const vec &from, const vec &to, vec *end) @@ -290,7 +290,7 @@ void hitpush(int damage, playerent *d, playerent *at, vec &from, vec &to, int gu float expdist(playerent *o, vec &dir, const vec &v) { vec middle = o->o; - middle.z += (o->aboveeye-o->eyeheight)/2; + middle.z += (o->aboveeye-o->dyneyeheight())/2; float dist = middle.dist(v, dir); dir.div(dist); if(dist<0) dist = 0;