From d315890fd59eaa40e003b1b6277ea6f49bd9c4e1 Mon Sep 17 00:00:00 2001 From: driAn Date: Sat, 10 May 2008 18:43:23 +0000 Subject: [PATCH] rewrote some nade code, "prompt" context, typos fixed git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1915 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clientgame.cpp | 2 +- source/src/console.cpp | 2 + source/src/entity.h | 14 +++-- source/src/protos.h | 1 + source/src/renderhud.cpp | 2 +- source/src/rendermodel.cpp | 2 +- source/src/weapon.cpp | 107 +++++++++++++++++++++---------------- source/src/weapon.h | 2 +- 8 files changed, 77 insertions(+), 55 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 6b90bfd7..19f581ff 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -828,9 +828,9 @@ playerent *findfollowplayer(int shiftdirection) playerent *f = players.inrange(player1->followplayercn) ? players[player1->followplayercn] : NULL; if(f) return f; } - vector available; loopv(players) if(players[i]) available.add(players[i]); + if(!available.length()) return NULL; player1->followplayercn = (player1->followplayercn+shiftdirection) % available.length(); return players[player1->followplayercn]; } diff --git a/source/src/console.cpp b/source/src/console.cpp index a7582477..7a8d3dc3 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -271,6 +271,7 @@ struct hline void run() { + pushscontext(IEXC_PROMPT); if(action) { alias("cmdbuf", buf); @@ -278,6 +279,7 @@ struct hline } else if(buf[0]=='/') execute(buf+1); else toserver(buf); + popscontext(); } }; vector history; diff --git a/source/src/entity.h b/source/src/entity.h index 29fa6ec2..18659e77 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -445,15 +445,15 @@ struct flaginfo flaginfo() : flag(0), actor(0), state(CTFF_INBASE), ack(false) {} }; -enum { NADE_ACTIVATED = 1, NADE_THROWED, GIB}; +enum { BT_NONE, BT_NADE, BT_GIB }; struct bounceent : physent // nades, gibs { - int millis, timetolife, bouncestate; // see enum above + int millis, timetolive, bouncetype; // see enum above float rotspeed; playerent *owner; - bounceent() : bouncestate(0), rotspeed(1.0f), owner(NULL) + bounceent() : bouncetype(BT_NONE), rotspeed(1.0f), owner(NULL) { type = ENT_BOUNCE; maxspeed = 40; @@ -464,8 +464,9 @@ struct bounceent : physent // nades, gibs virtual ~bounceent() {} - bool isalive(int lastmillis) { return lastmillis - millis < timetolife; } + bool isalive(int lastmillis) { return lastmillis - millis < timetolive; } virtual void destroy() {} + virtual bool applyphysics() { return true; } }; struct hitmsg @@ -476,11 +477,14 @@ struct hitmsg struct grenadeent : bounceent { + bool local; + int nadestate; grenadeent (playerent *owner, int millis = 0); void activate(vec &from, vec &to); - void _throw(); + void _throw(const vec &from, const vec &vel); void explode(); void splash(); virtual void destroy(); + virtual bool applyphysics(); }; diff --git a/source/src/protos.h b/source/src/protos.h index d1b2d3b3..76bbb0eb 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -449,6 +449,7 @@ 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); +extern bool collide(physent *d, bool spawn, float drop, float rise); // sound extern void playsound(int n, physent *p = NULL, entity *ent = NULL, const vec *v = NULL, int priority = SP_NORMAL); diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 0217f895..a4cdf728 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -270,7 +270,7 @@ void hudoutf(const char *s, ...) s_sprintfdv(sf, s); string sp; filtertext(sp, sf); - puts(sp); + //puts(sp); s = sf; hudmsgs.addline(s); conoutf(s); diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index 5bb7f2c6..0f201950 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -453,7 +453,7 @@ void renderclient(playerent *d, const char *mdlname, const char *vwepname, int t if(d->state==CS_DEAD) { if(d==player1 && d->allowmove()) return; - loopv(bounceents) if(bounceents[i]->bouncestate==GIB && bounceents[i]->owner==d) return; + loopv(bounceents) if(bounceents[i]->bouncetype==BT_GIB && bounceents[i]->owner==d) return; d->pitch = 0.1f; int r = 6; anim = ANIM_DEATH; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index d3225961..77b3f111 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -253,7 +253,7 @@ void movebounceents() loopv(bounceents) if(bounceents[i]) { bounceent *p = bounceents[i]; - if(p->bouncestate == NADE_THROWED || p->bouncestate == GIB) moveplayer(p, 2, false); + if((p->bouncetype==BT_NADE || p->bouncetype==BT_GIB) && p->applyphysics()) moveplayer(p, 2, false); if(!p->isalive(lastmillis)) { p->destroy(); @@ -279,20 +279,20 @@ void renderbounceents() string model; vec o(p->o); - switch(p->bouncestate) + switch(p->bouncetype) { - case NADE_THROWED: + case BT_NADE: s_strcpy(model, "weapons/grenade/static"); break; - case GIB: + case BT_GIB: default: { - uint n = (((4*(uint)(size_t)p)+(uint)p->timetolife)%3)+1; + uint n = (((4*(uint)(size_t)p)+(uint)p->timetolive)%3)+1; s_sprintf(model)("misc/gib0%u", n); int t = lastmillis-p->millis; - if(t>p->timetolife-2000) + if(t>p->timetolive-2000) { - t -= p->timetolife-2000; + t -= p->timetolive-2000; o.z -= t*t/4000000000.0f*t; } break; @@ -318,8 +318,8 @@ void addgib(playerent *d) bounceent *p = bounceents.add(new bounceent()); p->owner = d; p->millis = lastmillis; - p->timetolife = gibttl+rnd(10)*100; - p->bouncestate = GIB; + p->timetolive = gibttl+rnd(10)*100; + p->bouncetype = BT_GIB; p->o = d->o; p->o.z -= d->aboveeye; @@ -542,24 +542,29 @@ void weapon::equipplayer(playerent *pl) // grenadeent +enum { NS_NONE, NS_ACTIVATED = 0, NS_THROWED, NS_EXPLODED }; + grenadeent::grenadeent (playerent *owner, int millis) { ASSERT(owner); + nadestate = NS_NONE; + local = owner==player1; bounceent::owner = owner; bounceent::millis = lastmillis; - timetolife = 2000-millis; - bouncestate = NADE_ACTIVATED; + timetolive = 2000-millis; + bouncetype = BT_NADE; maxspeed = 27.0f; rotspeed = 6.0f; } void grenadeent::explode() { + if(nadestate!=NS_ACTIVATED && nadestate!=NS_THROWED ) return; + nadestate = NS_EXPLODED; static vec n(0,0,0); - if(bouncestate != NADE_THROWED) owner->weapons[GUN_GRENADE]->attack(n); hits.setsizenodelete(0); splash(); - if(owner == player1) + if(local) addmsg(SV_EXPLODE, "ri3iv", lastmillis, GUN_GRENADE, millis, // fixme hits.length(), hits.length()*sizeof(hitmsg)/sizeof(int), hits.getbuf()); playsound(S_FEXPLODE, &o); @@ -584,23 +589,40 @@ void grenadeent::splash() void grenadeent::activate(vec &from, vec &to) { - addmsg(SV_SHOOT, "ri2i6i", millis, owner->weaponsel->type, - (int)(from.x*DMF), (int)(from.y*DMF), (int)(from.z*DMF), - (int)(to.x*DMF), (int)(to.y*DMF), (int)(to.z*DMF), - 0); - playsound(S_GRENADEPULL, SP_HIGH); + if(nadestate!=NS_NONE) return; + nadestate = NS_ACTIVATED; + + if(local) + { + addmsg(SV_SHOOT, "ri2i6i", millis, owner->weaponsel->type, + (int)(from.x*DMF), (int)(from.y*DMF), (int)(from.z*DMF), + (int)(to.x*DMF), (int)(to.y*DMF), (int)(to.z*DMF), + 0); + playsound(S_GRENADEPULL, SP_HIGH); + } } -void grenadeent::_throw() +void grenadeent::_throw(const vec &from, const vec &vel) { - addmsg(SV_THROWNADE, "ri7", int(o.x*DMF), int(o.y*DMF), int(o.z*DMF), int(vel.x*DMF), int(vel.y*DMF), int(vel.z*DMF), lastmillis-millis); - playsound(S_GRENADETHROW, SP_HIGH); + if(nadestate!=NS_ACTIVATED) return; + nadestate = NS_THROWED; + + this->o = from; + this->vel = vel; + nadestate = NS_THROWED; + loopi(10) moveplayer(this, 10, true, 10); + + if(local) + { + addmsg(SV_THROWNADE, "ri7", int(o.x*DMF), int(o.y*DMF), int(o.z*DMF), int(vel.x*DMF), int(vel.y*DMF), int(vel.z*DMF), lastmillis-millis); + playsound(S_GRENADETHROW, SP_HIGH); + if(!collide(this, false, 0.0f, 0.0f)) destroy(); + } + else playsound(S_GRENADETHROW, owner); } -void grenadeent::destroy() -{ - if(bouncestate==NADE_ACTIVATED || bouncestate==NADE_THROWED) explode(); -} +void grenadeent::destroy() { explode(); } +bool grenadeent::applyphysics() { return nadestate==NS_THROWED; } // grenades @@ -655,7 +677,7 @@ void grenades::attackfx(vec &from, vec &to, int millis) // other player's grenad { inhandnade = new grenadeent(owner, millis); bounceents.add(inhandnade); - thrownade(from, to, inhandnade); + thrownade(from, to); } } @@ -675,7 +697,7 @@ void grenades::activatenade(vec &from, vec &to) if(!mag) return; throwmillis = 0; inhandnade = new grenadeent(owner); - bounceents.add(inhandnade); + bounceents.add(inhandnade); updatelastaction(owner); mag--; gunwait = info.attackdelay; @@ -696,33 +718,26 @@ void grenades::thrownade() from.mul(1.85f); from.add(owner->o); - thrownade(from, vel, inhandnade); - owner->attacking = false; + thrownade(from, vel); } -void grenades::thrownade(const vec &from, const vec &vel, grenadeent *p) +void grenades::thrownade(const vec &from, const vec &vel) { - if(!p) return; - p->vel = vel; - p->o = from; - p->bouncestate = NADE_THROWED; - loopi(10) moveplayer(p, 10, true, 10); - inhandnade = NULL; + if(!inhandnade) return; + inhandnade->_throw(from, vel); - if(owner==player1) - { - throwmillis = lastmillis; - updatelastaction(player1); - state = GST_THROWING; - p->_throw(); - } - else playsound(S_GRENADETHROW, owner); + throwmillis = lastmillis; + updatelastaction(player1); + state = GST_THROWING; + + inhandnade = NULL; + owner->attacking = false; } void grenades::dropnade() { vec n(0,0,0); - thrownade(owner->o, n, inhandnade); + thrownade(owner->o, n); } void grenades::renderstats() @@ -739,7 +754,7 @@ void grenades::onselecting() { reset(); playsound(S_GUNCHANGE); } void grenades::onownerdies() { reset(); - if(owner==player1 && inhandnade) inhandnade->explode(); + if(owner==player1 && inhandnade) dropnade(); } diff --git a/source/src/weapon.h b/source/src/weapon.h index a7fce2a2..3e63fa1a 100644 --- a/source/src/weapon.h +++ b/source/src/weapon.h @@ -61,7 +61,7 @@ struct grenades : weapon int modelanim(); void activatenade(vec &from, vec &to); void thrownade(); - void thrownade(const vec &from, const vec &vel, grenadeent *p); + void thrownade(const vec &from, const vec &vel); void dropnade(); void renderstats(); bool selectable();