summaryrefslogtreecommitdiff
path: root/src/fpsgame/entities.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fpsgame/entities.cpp')
-rw-r--r--src/fpsgame/entities.cpp211
1 files changed, 58 insertions, 153 deletions
diff --git a/src/fpsgame/entities.cpp b/src/fpsgame/entities.cpp
index 93e3dc9..9336c4e 100644
--- a/src/fpsgame/entities.cpp
+++ b/src/fpsgame/entities.cpp
@@ -2,38 +2,27 @@
int pwitemspicked[7] = { 0 };
-namespace entities
-{
+namespace entities {
using namespace game;
-
int extraentinfosize() { return 0; } // size in bytes of what the 2 methods below read/write... so it can be skipped by other games
#ifndef STANDALONE
vector<extentity *> ents;
-
vector<extentity *> &getents() { return ents; }
-
bool mayattach(extentity &e) { return false; }
bool attachent(extentity &e, extentity &a) { return false; }
-
- const char *itemname(int i)
- {
+ const char *itemname(int i) {
int t = ents[i]->type;
if(t<I_SHELLS || t>I_QUAD) return NULL;
return itemstats[t-I_SHELLS].name;
}
-
- int itemicon(int i)
- {
+ int itemicon(int i) {
int t = ents[i]->type;
if(t<I_SHELLS || t>I_QUAD) return -1;
return itemstats[t-I_SHELLS].icon;
}
-
- const char *entmdlname(int type)
- {
- static const char * const entmdlnames[] =
- {
+ const char *entmdlname(int type) {
+ static const char * const entmdlnames[] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"ammo/shells", "ammo/bullets", "ammo/rockets", "ammo/rrounds", "ammo/grenades", "ammo/cartridges",
"health", "boost", "tinyhealth", "tinyarmour", "armor/green", "armor/yellow", "quad", "teleporter",
@@ -47,23 +36,16 @@ namespace entities
};
return entmdlnames[type];
}
-
- const char *entmodel(const entity &e)
- {
- if(e.type == TELEPORT)
- {
+ const char *entmodel(const entity &e) {
+ if(e.type == TELEPORT) {
if(e.attr2 > 0) return mapmodelname(e.attr2);
if(e.attr2 < 0) return NULL;
}
return e.type < MAXENTTYPES ? entmdlname(e.type) : NULL;
}
-
- void preloadentities()
- {
- loopi(MAXENTTYPES)
- {
- switch(i)
- {
+ void preloadentities() {
+ loopi(MAXENTTYPES) {
+ switch(i) {
case I_SHELLS:
[[fallthrough]];
case I_BULLETS:
@@ -97,30 +79,23 @@ namespace entities
if(!mdl) continue;
preloadmodel(mdl);
}
- loopv(ents)
- {
+ loopv(ents) {
extentity &e = *ents[i];
- switch(e.type)
- {
+ switch(e.type) {
case TELEPORT:
if(e.attr2 > 0) preloadmodel(mapmodelname(e.attr2));
[[fallthrough]];
-
case JUMPPAD:
if(e.attr4 > 0) preloadmapsound(e.attr4);
break;
}
}
}
-
- void renderentities()
- {
- loopv(ents)
- {
+ void renderentities() {
+ loopv(ents) {
extentity &e = *ents[i];
int revs = 10;
- switch(e.type)
- {
+ switch(e.type) {
case TELEPORT:
if(e.attr2 < 0) continue;
break;
@@ -128,33 +103,25 @@ namespace entities
if(!e.spawned() || e.type < I_SHELLS || e.type > I_QUAD) continue;
}
const char *mdlname = entmodel(e);
- if(mdlname)
- {
+ if(mdlname) {
vec p = e.o;
p.z += 1+sinf(lastmillis/100.0+e.o.x+e.o.y)/20;
rendermodel(&e.light, mdlname, ANIM_MAPMODEL|ANIM_LOOP, p, lastmillis/(float)revs, 0, MDL_SHADOW | MDL_CULL_VFC | MDL_CULL_DIST | MDL_CULL_OCCLUDED);
}
}
}
-
- void addammo(int type, int &v, bool local)
- {
+ void addammo(int type, int &v, bool local) {
itemstat &is = itemstats[type-I_SHELLS];
v += is.add;
if(v>is.max) v = is.max;
if(local) msgsound(is.sound);
}
-
- void repammo(fpsent *d, int type, bool local)
- {
+ void repammo(fpsent *d, int type, bool local) {
addammo(type, d->ammo[type-I_SHELLS+GUN_SG], local);
}
-
// these two functions are called when the server acknowledges that you really
// picked up the item (in multiplayer someone may grab it before you).
-
- void pickupeffects(int n, fpsent *d)
- {
+ void pickupeffects(int n, fpsent *d) {
if(!ents.inrange(n)) return;
extentity *e = ents[n];
int type = e->type;
@@ -164,8 +131,7 @@ namespace entities
if(!d) return;
itemstat &is = itemstats[type-I_SHELLS];
fpsent *h = followingplayer(player1);
- if(d!=h || isthirdperson())
- {
+ if(d!=h || isthirdperson()) {
//particle_text(d->abovehead(), is.name, PART_TEXT, 2000, 0xFFC864, 4.0f, -8);
particle_icon(d->abovehead(), is.icon%4, is.icon/4, PART_HUD_ICON_GREY, 2000, 0xFFFFFF, 2.0f, -8);
}
@@ -180,29 +146,22 @@ namespace entities
case I_BOOST: pwitemspicked[5]++; break;
case I_QUAD: pwitemspicked[6]++; break;
}
- if(d==h) switch(type)
- {
+ if(d==h) switch(type) {
case I_BOOST:
conoutf(CON_GAMEINFO, "\f2you got the health boost!");
playsound(S_V_BOOST, NULL, NULL, 0, 0, 0, -1, 0, 3000);
break;
-
case I_QUAD:
conoutf(CON_GAMEINFO, "\f2you got the quad!");
playsound(S_V_QUAD, NULL, NULL, 0, 0, 0, -1, 0, 3000);
break;
}
}
-
// these functions are called when the client touches the item
-
- void teleporteffects(fpsent *d, int tp, int td, bool local)
- {
- if(ents.inrange(tp) && ents[tp]->type == TELEPORT)
- {
+ void teleporteffects(fpsent *d, int tp, int td, bool local) {
+ if(ents.inrange(tp) && ents[tp]->type == TELEPORT) {
extentity &e = *ents[tp];
- if(e.attr4 >= 0)
- {
+ if(e.attr4 >= 0) {
int snd = S_TELEPORT, flags = 0;
if(e.attr4 > 0) { snd = e.attr4; flags = SND_MAP; }
fpsent *h = followingplayer(player1);
@@ -210,8 +169,7 @@ namespace entities
if(d!=h && ents.inrange(td) && ents[td]->type == TELEDEST) playsound(snd, &ents[td]->o, NULL, flags);
}
}
- if(local && d->clientnum >= 0)
- {
+ if(local && d->clientnum >= 0) {
sendposition(d);
packetbuf p(32, ENET_PACKET_FLAG_RELIABLE);
putint(p, N_TELEPORT);
@@ -222,21 +180,16 @@ namespace entities
flushclient();
}
}
-
- void jumppadeffects(fpsent *d, int jp, bool local)
- {
- if(ents.inrange(jp) && ents[jp]->type == JUMPPAD)
- {
+ void jumppadeffects(fpsent *d, int jp, bool local) {
+ if(ents.inrange(jp) && ents[jp]->type == JUMPPAD) {
extentity &e = *ents[jp];
- if(e.attr4 >= 0)
- {
+ if(e.attr4 >= 0) {
int snd = S_JUMPPAD, flags = 0;
if(e.attr4 > 0) { snd = e.attr4; flags = SND_MAP; }
playsound(snd, d == followingplayer(player1) ? NULL : &e.o, NULL, flags);
}
}
- if(local && d->clientnum >= 0)
- {
+ if(local && d->clientnum >= 0) {
sendposition(d);
packetbuf p(16, ENET_PACKET_FLAG_RELIABLE);
putint(p, N_JUMPPAD);
@@ -246,22 +199,17 @@ namespace entities
flushclient();
}
}
-
- void teleport(int n, fpsent *d) // also used by monsters
- {
+ void teleport(int n, fpsent *d) { // also used by monsters {
int e = -1, tag = ents[n]->attr1, beenhere = -1;
- for(;;)
- {
+ for(;;) {
e = findentity(TELEDEST, e+1);
if(e==beenhere || e<0) { conoutf(CON_WARN, "no teleport destination for tag %d", tag); return; }
if(beenhere<0) beenhere = e;
- if(ents[e]->attr2==tag)
- {
+ if(ents[e]->attr2==tag) {
teleporteffects(d, n, e, true);
d->o = ents[e]->o;
d->yaw = ents[e]->attr1;
- if(ents[e]->attr3 > 0)
- {
+ if(ents[e]->attr3 > 0) {
vec dir;
vecfromyawpitch(d->yaw, 0, 1, 0, dir);
float speed = d->vel.magnitude2();
@@ -276,25 +224,18 @@ namespace entities
}
}
}
-
- void trypickup(int n, fpsent *d)
- {
+ void trypickup(int n, fpsent *d) {
extentity *e = ents[n];
- switch(e->type)
- {
+ switch(e->type) {
default:
- if(d->canpickup(e->type))
- {
+ if(d->canpickup(e->type)) {
addmsg(N_ITEMPICKUP, "rci", d, n);
e->setnopickup(); // even if someone else gets it first
}
break;
-
- case TELEPORT:
- {
+ case TELEPORT: {
if(d->lastpickup==e->type && lastmillis-d->lastpickupmillis<500) break;
- if(e->attr3 > 0)
- {
+ if(e->attr3 > 0) {
defformatstring(hookname, "can_teleport_%d", e->attr3);
if(!execidentbool(hookname, true)) break;
}
@@ -303,9 +244,7 @@ namespace entities
teleport(n, d);
break;
}
-
- case JUMPPAD:
- {
+ case JUMPPAD: {
if(d->lastpickup==e->type && lastmillis-d->lastpickupmillis<300) break;
d->lastpickup = e->type;
d->lastpickupmillis = lastmillis;
@@ -320,13 +259,10 @@ namespace entities
}
}
}
-
- void checkitems(fpsent *d)
- {
+ void checkitems(fpsent *d) {
if(d->state!=CS_ALIVE) return;
vec o = d->feetpos();
- loopv(ents)
- {
+ loopv(ents) {
extentity &e = *ents[i];
if(e.type==NOTUSED) continue;
if((!e.spawned() || e.nopickup()) && e.type!=TELEPORT && e.type!=JUMPPAD) continue;
@@ -334,97 +270,68 @@ namespace entities
if(dist<(e.type==TELEPORT ? 16 : 12)) trypickup(i, d);
}
}
-
- void checkquad(int time, fpsent *d)
- {
- if(d->quadmillis && (d->quadmillis -= time)<=0)
- {
+ void checkquad(int time, fpsent *d) {
+ if(d->quadmillis && (d->quadmillis -= time)<=0) {
d->quadmillis = 0;
fpsent *h = followingplayer(player1);
playsound(S_PUPOUT, d==h ? NULL : &d->o);
if(d==h) conoutf(CON_GAMEINFO, "\f2quad damage is over");
}
}
-
- void putitems(packetbuf &p) // puts items in network stream and also spawns them locally
- {
+ void putitems(packetbuf &p) { // puts items in network stream and also spawns them locally {
putint(p, N_ITEMLIST);
- loopv(ents) if(ents[i]->type>=I_SHELLS && ents[i]->type<=I_QUAD && (!m_noammo || ents[i]->type<I_SHELLS || ents[i]->type>I_CARTRIDGES))
- {
+ loopv(ents) if(ents[i]->type>=I_SHELLS && ents[i]->type<=I_QUAD && (!m_noammo || ents[i]->type<I_SHELLS || ents[i]->type>I_CARTRIDGES)) {
putint(p, i);
putint(p, ents[i]->type);
}
putint(p, -1);
}
-
void resetspawns() { loopv(ents) { extentity *e = ents[i]; e->clearspawned(); e->clearnopickup(); } }
-
- void spawnitems(bool force)
- {
+ void spawnitems(bool force) {
if(m_noitems) return;
- loopv(ents)
- {
+ loopv(ents) {
extentity *e = ents[i];
- if(e->type>=I_SHELLS && e->type<=I_QUAD && (!m_noammo || e->type<I_SHELLS || e->type>I_CARTRIDGES))
- {
+ if(e->type>=I_SHELLS && e->type<=I_QUAD && (!m_noammo || e->type<I_SHELLS || e->type>I_CARTRIDGES)) {
e->setspawned(force || !server::delayspawn(e->type));
e->clearnopickup();
}
}
}
-
void setspawn(int i, bool on) { if(ents.inrange(i)) { extentity *e = ents[i]; e->setspawned(on); e->clearnopickup(); } }
-
extentity *newentity() { return new extentity(); }
void deleteentity(extentity *e) { delete e; }
-
- void clearents()
- {
+ void clearents() {
while(ents.length()) deleteentity(ents.pop());
}
-
- void fixentity(extentity &e)
- {
+ void fixentity(extentity &e) {
if(e.type == TELEDEST) e.attr3 = e.attr2;
}
-
- void entradius(extentity &e, bool color)
- {
- switch(e.type)
- {
- case TELEDEST:
- {
+ void entradius(extentity &e, bool color) {
+ switch(e.type) {
+ case TELEDEST: {
vec dir;
vecfromyawpitch(e.attr1, 0, 1, 0, dir);
renderentarrow(e, dir, 4);
break;
}
case TELEPORT:
- loopv(ents) if(ents[i]->type == TELEDEST && e.attr1==ents[i]->attr2)
- {
+ loopv(ents) if(ents[i]->type == TELEDEST && e.attr1==ents[i]->attr2) {
renderentarrow(e, vec(ents[i]->o).sub(e.o).normalize(), e.o.dist(ents[i]->o));
break;
}
break;
-
case JUMPPAD:
renderentarrow(e, vec((int)(char)e.attr3*10.0f, (int)(char)e.attr2*10.0f, e.attr1*12.5f).normalize(), 4);
break;
-
default: break;
}
}
-
- bool printent(extentity &e, char *buf, int len)
- {
+ bool printent(extentity &e, char *buf, int len) {
return false;
}
-
const char *entnameinfo(entity &e) { return ""; }
- const char *entname(int i)
- {
- static const char * const entnames[] =
- {
+ const char *entname(int i) {
+ static const char * const entnames[] = {
"none?", "light", "mapmodel", "playerstart", "none?", "particles", "sound", "spotlight",
"shells", "bullets", "rockets", "riflerounds", "grenades", "cartridges",
"health", "healthboost", "tinyhealth", "tinyarmour", "greenarmour", "yellowarmour", "quaddamage",
@@ -434,9 +341,7 @@ namespace entities
};
return i>=0 && size_t(i)<sizeof(entnames)/sizeof(entnames[0]) ? entnames[i] : "";
}
-
- void editent(int i, bool local)
- {
+ void editent(int i, bool local) {
extentity &e = *ents[i];
if(local) addmsg(N_EDITENT, "rii3ii5", i, (int)(e.o.x*DMF), (int)(e.o.y*DMF), (int)(e.o.z*DMF), e.type, e.attr1, e.attr2, e.attr3, e.attr4, e.attr5);
}