if(!isNew && n != this.sv_entnum)
{
//print("A CSQC entity changed its owner!\n");
- LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", num_for_edict(this), this.classname);
+ LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", etof(this), this.classname);
isNew = true;
Ent_Remove();
}
{
if (t != this.enttype || isnew)
{
- LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", num_for_edict(this), this.entnum, this.enttype, t);
+ LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", etof(this), this.entnum, this.enttype, t);
Ent_Remove();
clearentity(this);
isnew = true;
{
if (!isnew)
{
- LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", num_for_edict(this), this.entnum, t);
+ LOG_INFOF("A CSQC entity appeared out of nowhere! (edict: %d, server: %d, type: %d)\n", etof(this), this.entnum, t);
isnew = true;
}
}
int channel = MSG_ONE;
msg_entity = to;
WriteHeader(channel, net_debug);
- WriteShort(channel, num_for_edict(this));
+ WriteShort(channel, etof(this));
WriteByte(channel, is_pure(this));
WriteCoord(channel, this.origin.x);
WriteCoord(channel, this.origin.y);
pos.z = 0;
pos.y += ofs * size;
drawcolorcodedstring2(pos,
- sprintf("%d: '%s'@%s:%d", (e.debug ? e.sv_entnum : num_for_edict(e)),
+ sprintf("%d: '%s'@%s:%d", (e.debug ? e.sv_entnum : etof(e)),
e.classname, e.sourceLocFile, e.sourceLocLine),
size * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
++ofs;
// if this is a copied dead body, send the num of its player instead
// TODO: remove this field, read from model txt files
if(self.classname == "body")
- e.team = num_for_edict(self.enemy);
+ e.team = etof(self.enemy);
else
- e.team = num_for_edict(self);
+ e.team = etof(self);
setorigin(e, org);
e.velocity = dir;
void minigame_autoclean_entity(entity e)
{
- LOG_DEBUG("CL Auto-cleaned: ",ftos(num_for_edict(e)), " (",e.classname,")\n");
+ LOG_DEBUG("CL Auto-cleaned: ",ftos(etof(e)), " (",e.classname,")\n");
remove(e);
}
if ( sf & MINIG_SF_CREATE )
{
- LOG_DEBUG("CL Reading entity: ",ftos(num_for_edict(self)),
+ LOG_DEBUG("CL Reading entity: ",ftos(etof(self)),
" classname:",self.classname," enttype:",ftos(self.enttype) );
LOG_DEBUG(" sf:",ftos(sf)," netname:",self.netname,"\n\n");
}
}
minigame_session.minigame_event(minigame_session,"part",player);
GameLogEcho(strcat(":minigame:part:",minigame_session.netname,":",
- ftos(num_for_edict(player)),":",player.netname));
+ ftos(etof(player)),":",player.netname));
minigame_session.minigame_players = p.list_next;
remove ( p );
player_clear_minigame(player);
{
minigame_session.minigame_event(minigame_session,"part",player);
GameLogEcho(strcat(":minigame:part:",minigame_session.netname,":",
- ftos(num_for_edict(player)),":",player.netname));
+ ftos(etof(player)),":",player.netname));
p.list_next = e.list_next;
remove(e);
player_clear_minigame(player);
if ( sf & MINIG_SF_CREATE )
{
WriteString(MSG_ENTITY,self.owner.netname);
- WriteLong(MSG_ENTITY,num_for_edict(self.minigame_players));
+ WriteLong(MSG_ENTITY,etof(self.minigame_players));
}
if ( sf & MINIG_SF_UPDATE )
WriteByte(MSG_ENTITY,self.team);
}
else { remove(player_pointer); }
GameLogEcho(strcat(":minigame:join",(mgteam?"":"fail"),":",minigame_session.netname,":",
- ftos(num_for_edict(player)),":",player.netname));
+ ftos(etof(player)),":",player.netname));
return mgteam;
}
if ( e )
{
entity minig = new(minigame);
- minig.netname = strzone(strcat(e.netname,"_",ftos(num_for_edict(minig))));
+ minig.netname = strzone(strcat(e.netname,"_",ftos(etof(minig))));
minig.descriptor = e;
minig.minigame_event = e.minigame_event;
minig.minigame_event(minig,"start");
while( (e = findentity(e, owner, minigame_session)) )
if ( e.minigame_autoclean )
{
- LOG_TRACE("SV Auto-cleaned: ",ftos(num_for_edict(e)), " (",e.classname,")\n");
+ LOG_TRACE("SV Auto-cleaned: ",ftos(etof(e)), " (",e.classname,")\n");
remove(e);
}
inviter.active_minigame.netname, inviter.netname );
GameLogEcho(strcat(":minigame:invite:",inviter.active_minigame.netname,":",
- ftos(num_for_edict(player)),":",player.netname));
+ ftos(etof(player)),":",player.netname));
return "";
}
if(!_Movetype_TestEntityPosition(this, '0 0 1' * i)) goto success;
}
LOG_DEBUG("Can't unstick an entity (edict: %d, classname: %s, origin: %s)\n",
- num_for_edict(this), this.classname, vtos(this.move_origin));
+ etof(this), this.classname, vtos(this.move_origin));
return false;
: success;
LOG_DEBUG("Sucessfully unstuck an entity (edict: %d, classname: %s, origin: %s)\n",
- num_for_edict(this), this.classname, vtos(this.move_origin));
+ etof(this), this.classname, vtos(this.move_origin));
_Movetype_LinkEdict(this, true);
return true;
}
void stopsoundto(int _dest, entity e, int chan)
{
if (!sound_allowed(_dest, e)) return;
- int entno = num_for_edict(e);
+ int entno = etof(e);
if (entno >= 8192 || chan < 0 || chan > 7)
{
int idx = precache_sound_index(SND(Null));
void target_music_sendto(float to, float is)
{SELFPARAM();
WriteHeader(to, TE_CSQC_TARGET_MUSIC);
- WriteShort(to, num_for_edict(self));
+ WriteShort(to, etof(self));
WriteByte(to, self.volume * 255.0 * is);
WriteByte(to, self.fade_time * 16.0);
WriteByte(to, self.fade_rate * 16.0);
if(valuefield == "")
{
if(value == "")
- value = ftos(num_for_edict(valueent));
+ value = ftos(etof(valueent));
}
else
{
WriteByte(MSG_ENTITY, sf);
if(sf & BRG_SETUP)
{
- WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
+ WriteByte(MSG_ENTITY, etof(self.realowner));
WriteByte(MSG_ENTITY, self.realowner.team);
WriteByte(MSG_ENTITY, self.cnt);
}
WriteShort(MSG_BROADCAST, WEP_CVAR(shockwave, blast_distance));
WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_max), 255));
WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_min), 255));
- WriteByte(MSG_BROADCAST, num_for_edict(self));
+ WriteByte(MSG_BROADCAST, etof(self));
}
void W_Shockwave_Attack()
WriteCoord(MSG_BROADCAST, v.y);
WriteCoord(MSG_BROADCAST, v.z);
WriteByte(MSG_BROADCAST, hit);
- WriteByte(MSG_BROADCAST, num_for_edict(player));
+ WriteByte(MSG_BROADCAST, etof(player));
WriteByte(MSG_BROADCAST, player.team);
}
#elif defined(CSQC)
// already defined
#endif
-#undef etof
// avoid bounds checks
-#define etof(e) stof(sprintf("%i", e))
+#undef etof
+#if 1
+ #define etof(e) ITOF(reinterpret_cast(int, e))
+#else
+ #define etof(e) stof(sprintf("%i", e))
+#endif
#define GET(name) name##get
#define GETTER(type, name) type GET(name)() { return name; }
#define reinterpret_cast(T, it) _unsafe_cast_##T(0, it)
#define X(T) T _unsafe_cast_##T(int dummy, ...) { return ...(0, T); }
+X(bool)
+X(int)
X(float)
X(entity)
X(string)
X(rawfunc)
#undef X
-#define strid(s) etof(reinterpret_cast(entity, s))
+#define strid(s) ITOF(reinterpret_cast(int, s))
+
+.int _unsafe_fld1, _unsafe_fld2;
+int INTEGER_ONE;
+
+#define FTOI(f) ((f) * INTEGER_ONE)
+#define ITOF(i) ((i) / INTEGER_ONE)
+
+STATIC_INIT(INTEGER_ONE)
+{
+ INTEGER_ONE = reinterpret_cast(int, _unsafe_fld2) - reinterpret_cast(int, _unsafe_fld1);
+}
#endif
#define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE)
#define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET)
-#define FOR_EACH_CLIENTSLOT(v) for (v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); )
+#define FOR_EACH_CLIENTSLOT(v) for (v = world; (v = nextent(v)) && (etof(v) <= maxclients); )
#define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if (IS_CLIENT(v))
#define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if (IS_REAL_CLIENT(v))
#define FOREACH_CLIENT(cond, body) \
MACRO_BEGIN { \
int i = 0; \
- for (entity it = NULL; (it = nextent(it)) && (num_for_edict(it) <= maxclients); ++i) \
+ for (entity it = NULL; (it = nextent(it)) && (etof(it) <= maxclients); ++i) \
{ \
if (!IS_CLIENT(it)) continue; \
if (cond) { LAMBDA(body) } \
{
if(vlen(oldself.origin - start) < vlen(e.origin - start))
++effectnum;
- else if(vlen(oldself.origin - start) == vlen(e.origin - start) && num_for_edict(oldself) < num_for_edict(e))
+ else if(vlen(oldself.origin - start) == vlen(e.origin - start) && etof(oldself) < etof(e))
++effectnum;
}
fputs(f, strcat("\"race_place\" \"", ftos(effectnum), "\"\n"));
{
GameLogEcho(sprintf(":connect:%d:%d:%s",
self.playerid,
- num_for_edict(self),
+ etof(self),
((IS_REAL_CLIENT(self)) ? self.netaddress : "bot")
));
}
PlayerStats_GameReport_AddPlayer(self);
if(autocvar_sv_eventlog)
- GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot"), ":", self.netname));
+ GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(etof(self)), ":", ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot"), ":", self.netname));
LogTeamchange(self.playerid, self.team, 1);
float oldspectatee_status;
oldspectatee_status = self.spectatee_status;
if(IS_SPEC(self))
- self.spectatee_status = num_for_edict(self.enemy);
+ self.spectatee_status = etof(self.enemy);
else if(IS_OBSERVER(self))
- self.spectatee_status = num_for_edict(self);
+ self.spectatee_status = etof(self);
else
self.spectatee_status = 0;
if(self.spectatee_status != oldspectatee_status)
entity selection = GetFilteredEntity(input);
float output;
- output = num_for_edict(selection);
+ output = etof(selection);
return output;
}
}
print_to(caller, sprintf(strreplace(" ", separator, " #%-3d %-20.20s %-5d %-3d %-9s %-16s %s "),
- num_for_edict(tmp_player),
+ etof(tmp_player),
tmp_player.netname,
tmp_player.ping,
tmp_player.ping_packetloss,
FOR_EACH_CLIENT(client)
{
- argc = tokenize_console(strcat("defer_clear ", ftos(num_for_edict(client))));
+ argc = tokenize_console(strcat("defer_clear ", ftos(etof(client))));
GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc);
++i;
}
}
else
{
- shuffleteams_players[i] = num_for_edict(tmp_player);
+ shuffleteams_players[i] = etof(tmp_player);
break;
}
}
if (first_command == "kickban") command_arguments = strcat(ftos(autocvar_g_ban_default_bantime), " ", ftos(autocvar_g_ban_default_masksize), " ~");
else command_arguments = reason;
- vote_parsed_command = strcat(first_command, " # ", ftos(num_for_edict(victim)), " ", command_arguments);
+ vote_parsed_command = strcat(first_command, " # ", ftos(etof(victim)), " ", command_arguments);
vote_parsed_display = strcat("^1", vote_command, " (^7", victim.netname, "^1): ", reason);
}
else { print_to(caller, strcat("vcall: ", GetClientErrorString(accepted, argv(startpos + 1)), ".\n")); return false; }
WriteByte(MSG_ENTITY, sf);
if(sf & 1)
{
- WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
+ WriteByte(MSG_ENTITY, etof(self.realowner));
}
if(sf & 2)
{
if(trace_dphitcontents == 0)
{
//dprint("A hit happened with zero hit contents... DEBUG THIS, this should never happen for projectiles! Projectile will self-destruct.\n");
- LOG_TRACEF("A hit from a projectile happened with no hit contents! DEBUG THIS, this should never happen for projectiles! Profectile will self-destruct. (edict: %d, classname: %s, origin: %s)\n", num_for_edict(self), self.classname, vtos(self.origin));
+ LOG_TRACEF("A hit from a projectile happened with no hit contents! DEBUG THIS, this should never happen for projectiles! Profectile will self-destruct. (edict: %d, classname: %s, origin: %s)\n", etof(self), self.classname, vtos(self.origin));
checkclient();
}
if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
float i, p, longflags;
WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES);
- WriteByte(MSG_ENTITY, num_for_edict(self.owner));
+ WriteByte(MSG_ENTITY, etof(self.owner));
longflags = 0;
for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
}
if (result.x == 0 && strict)
- result.x = num_for_edict(t1.owner) - num_for_edict(t2.owner);
+ result.x = etof(t1.owner) - etof(t2.owner);
return result.x;
}
if(autocvar_g_spawn_alloweffects)
{
- WriteByte(MSG_ENTITY, num_for_edict(self.owner));
+ WriteByte(MSG_ENTITY, etof(self.owner));
WriteShort(MSG_ENTITY, self.owner.origin.x);
WriteShort(MSG_ENTITY, self.owner.origin.y);
WriteShort(MSG_ENTITY, self.owner.origin.z);