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
This commit is contained in:
@@ -828,9 +828,9 @@ playerent *findfollowplayer(int shiftdirection)
|
||||
playerent *f = players.inrange(player1->followplayercn) ? players[player1->followplayercn] : NULL;
|
||||
if(f) return f;
|
||||
}
|
||||
|
||||
vector<playerent *> 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];
|
||||
}
|
||||
|
||||
@@ -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<hline *> history;
|
||||
|
||||
+9
-5
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+61
-46
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user