fix weirdness in random numbers and ray creation
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6005 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+27
-19
@@ -109,7 +109,6 @@ MASTER_OBJS= \
|
||||
crypto-standalone.o \
|
||||
stream-standalone.o \
|
||||
command-standalone.o \
|
||||
crypto_tools-standalone.o \
|
||||
master-standalone.o
|
||||
|
||||
ifeq ($(PLATFORM),SunOS)
|
||||
@@ -196,7 +195,10 @@ depend:
|
||||
makedepend -a -o-standalone.o -Y -I. $(subst -standalone.o,.cpp,$(filter-out $(SERVER_OBJS), $(MASTER_OBJS)))
|
||||
|
||||
# DO NOT DELETE
|
||||
crypto.o: cube.h protos.h
|
||||
|
||||
crypto.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
crypto.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
crypto.o: protos.h
|
||||
audiomanager.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
audiomanager.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
audiomanager.o: protos.h
|
||||
@@ -230,7 +232,7 @@ i18n.o: entity.h world.h i18n.h command.h vote.h console.h protos.h
|
||||
log.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h weapon.h
|
||||
log.o: entity.h world.h i18n.h command.h vote.h console.h protos.h
|
||||
main.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h weapon.h
|
||||
main.o: entity.h world.h i18n.h command.h vote.h console.h protos.h
|
||||
main.o: entity.h world.h i18n.h command.h vote.h console.h protos.h jpegenc.h
|
||||
menus.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h weapon.h
|
||||
menus.o: entity.h world.h i18n.h command.h vote.h console.h protos.h
|
||||
oggstream.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
@@ -272,16 +274,16 @@ rndmap.o: protos.h
|
||||
scoreboard.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
scoreboard.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
scoreboard.o: protos.h
|
||||
server.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
server.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
server.o: protos.h server.h servercontroller.h serverfiles.h serverevents.h
|
||||
server.o: serveractions.h serverchecks.h
|
||||
serverbrowser.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
serverbrowser.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
serverbrowser.o: protos.h
|
||||
serverms.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
serverms.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
serverms.o: protos.h
|
||||
server.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
server.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
server.o: protos.h server.h servercontroller.h serverfiles.h serverchecks.h
|
||||
server.o: serverevents.h serveractions.h
|
||||
serverbrowser.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
serverbrowser.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
serverbrowser.o: protos.h
|
||||
shadow.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
shadow.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
shadow.o: protos.h
|
||||
@@ -307,7 +309,9 @@ weapon.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
weapon.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
weapon.o: protos.h bot/bot.h bot/bot_util.h bot/bot_waypoint.h bot/ac_bot.h
|
||||
weapon.o: hudgun.h
|
||||
wizard.o: platform.h
|
||||
wizard.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
wizard.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
wizard.o: protos.h
|
||||
world.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h weapon.h
|
||||
world.o: entity.h world.h i18n.h command.h vote.h console.h protos.h
|
||||
world.o: bot/bot.h bot/bot_util.h bot/bot_waypoint.h bot/ac_bot.h
|
||||
@@ -356,32 +360,36 @@ bot/ac_bot_ai.o: bot/ac_bot.h
|
||||
cube.h.gch: platform.h tools.h geom.h model.h protocol.h sound.h weapon.h
|
||||
cube.h.gch: entity.h world.h i18n.h command.h vote.h console.h protos.h
|
||||
|
||||
crypto-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
crypto-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
crypto-standalone.o: vote.h console.h protos.h
|
||||
log-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h sound.h
|
||||
log-standalone.o: weapon.h entity.h world.h i18n.h command.h vote.h console.h
|
||||
log-standalone.o: protos.h
|
||||
protocol-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
protocol-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
protocol-standalone.o: vote.h console.h protos.h
|
||||
server-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
server-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
server-standalone.o: vote.h console.h protos.h server.h servercontroller.h
|
||||
server-standalone.o: serverfiles.h serverevents.h serveractions.h serverchecks.h
|
||||
serverms-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
serverms-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
serverms-standalone.o: vote.h console.h protos.h
|
||||
crypto-standalone.o: cube.h protos.h
|
||||
crypto_tools-standalone.o: crypto_tools.h
|
||||
server-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
server-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
server-standalone.o: vote.h console.h protos.h server.h servercontroller.h
|
||||
server-standalone.o: serverfiles.h serverchecks.h serverevents.h
|
||||
server-standalone.o: serveractions.h
|
||||
stream-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
stream-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
stream-standalone.o: vote.h console.h protos.h
|
||||
tools-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
tools-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h vote.h
|
||||
tools-standalone.o: console.h protos.h
|
||||
wizard-standalone.o: platform.h
|
||||
wizard-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
wizard-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
wizard-standalone.o: vote.h console.h protos.h
|
||||
|
||||
command-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
command-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
command-standalone.o: vote.h console.h protos.h
|
||||
master-standalone.o: cube.h platform.h tools.h geom.h model.h protocol.h
|
||||
master-standalone.o: sound.h weapon.h entity.h world.h i18n.h command.h
|
||||
master-standalone.o: vote.h console.h protos.h crypto_tools.h
|
||||
master-standalone.o: vote.h console.h protos.h
|
||||
|
||||
@@ -656,7 +656,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p)
|
||||
playerent *s = getclient(scn);
|
||||
if(!s || !weapon::valid(gun)) break;
|
||||
loopk(3) from[k] = s->o.v[k];
|
||||
if(gun==GUN_SHOTGUN) createrays(from, to, true); // force - new:2010nov19
|
||||
if(gun==GUN_SHOTGUN) createrays(from, to);
|
||||
s->lastaction = lastmillis;
|
||||
s->mag[gun]--;
|
||||
if(s->weapons[gun])
|
||||
|
||||
@@ -828,3 +828,50 @@ bool checkchallenge(const char *answerstr, void *correct)
|
||||
return answer == *(gfint *)correct;
|
||||
}
|
||||
|
||||
////////////////////////// crypto rand ////////////////////////////////////////
|
||||
|
||||
#define N (624)
|
||||
#define M (397)
|
||||
#define K (0x9908B0DFU)
|
||||
#define hiBit(u) ((u) & 0x80000000U)
|
||||
#define loBit(u) ((u) & 0x00000001U)
|
||||
#define loBits(u) ((u) & 0x7FFFFFFFU)
|
||||
#define mixBits(u, v) (hiBit(u)|loBits(v))
|
||||
|
||||
static uint state[N+1];
|
||||
static uint *next;
|
||||
static int left = -1;
|
||||
|
||||
void seedMT(uint seed)
|
||||
{
|
||||
register uint x = (seed | 1U) & 0xFFFFFFFFU, *s = state;
|
||||
register int j;
|
||||
for(left=0, *s++=x, j=N; --j; *s++ = (x*=69069U) & 0xFFFFFFFFU);
|
||||
}
|
||||
|
||||
uint reloadMT(void)
|
||||
{
|
||||
register uint *p0=state, *p2=state+2, *pM=state+M, s0, s1;
|
||||
register int j;
|
||||
if(left < -1) seedMT(time(NULL));
|
||||
left=N-1, next=state+1;
|
||||
for(s0=state[0], s1=state[1], j=N-M+1; --j; s0=s1, s1=*p2++) *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
|
||||
for(pM=state, j=M; --j; s0=s1, s1=*p2++) *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
|
||||
s1=state[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
|
||||
s1 ^= (s1 >> 11);
|
||||
s1 ^= (s1 << 7) & 0x9D2C5680U;
|
||||
s1 ^= (s1 << 15) & 0xEFC60000U;
|
||||
return(s1 ^ (s1 >> 18));
|
||||
}
|
||||
|
||||
uint randomMT(void)
|
||||
{
|
||||
uint y;
|
||||
if(--left < 0) return(reloadMT());
|
||||
y = *next++;
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9D2C5680U;
|
||||
y ^= (y << 15) & 0xEFC60000U;
|
||||
return(y ^ (y >> 18));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
#include <time.h>
|
||||
#include "crypto_tools.h"
|
||||
#include "cube.h"
|
||||
|
||||
////////////////////////// crypto rand ////////////////////////////////////////
|
||||
|
||||
#define N (624)
|
||||
#define M (397)
|
||||
#define K (0x9908B0DFU)
|
||||
#define hiBit(u) ((u) & 0x80000000U)
|
||||
#define loBit(u) ((u) & 0x00000001U)
|
||||
#define loBits(u) ((u) & 0x7FFFFFFFU)
|
||||
#define mixBits(u, v) (hiBit(u)|loBits(v))
|
||||
|
||||
static uint state[N+1];
|
||||
static uint *next;
|
||||
static int left = -1;
|
||||
|
||||
void seedMT(uint seed)
|
||||
{
|
||||
register uint x = (seed | 1U) & 0xFFFFFFFFU, *s = state;
|
||||
register int j;
|
||||
for(left=0, *s++=x, j=N; --j; *s++ = (x*=69069U) & 0xFFFFFFFFU);
|
||||
}
|
||||
|
||||
uint reloadMT(void)
|
||||
{
|
||||
register uint *p0=state, *p2=state+2, *pM=state+M, s0, s1;
|
||||
register int j;
|
||||
if(left < -1) seedMT(time(NULL));
|
||||
left=N-1, next=state+1;
|
||||
for(s0=state[0], s1=state[1], j=N-M+1; --j; s0=s1, s1=*p2++) *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
|
||||
for(pM=state, j=M; --j; s0=s1, s1=*p2++) *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
|
||||
s1=state[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
|
||||
s1 ^= (s1 >> 11);
|
||||
s1 ^= (s1 << 7) & 0x9D2C5680U;
|
||||
s1 ^= (s1 << 15) & 0xEFC60000U;
|
||||
return(s1 ^ (s1 >> 18));
|
||||
}
|
||||
|
||||
uint randomMT(void)
|
||||
{
|
||||
uint y;
|
||||
if(--left < 0) return(reloadMT());
|
||||
y = *next++;
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9D2C5680U;
|
||||
y ^= (y << 15) & 0xEFC60000U;
|
||||
return(y ^ (y >> 18));
|
||||
}
|
||||
|
||||
@@ -1009,7 +1009,6 @@ const char *rndmapname()
|
||||
"ac_shine", "ac_snow", "ac_sunset", "ac_toxic", "ac_urban",
|
||||
"ac_werk",
|
||||
};
|
||||
srand(time(NULL));
|
||||
int l = sizeof(mapnames)/sizeof(mapnames[0]);
|
||||
int n = rnd(l);
|
||||
return mapnames[n];
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "cube.h"
|
||||
#include "crypto_tools.h"
|
||||
#include <signal.h>
|
||||
#include <enet/time.h>
|
||||
|
||||
|
||||
+1
-1
@@ -664,7 +664,7 @@ extern void updateclientname(playerent *d);
|
||||
|
||||
// weapon
|
||||
extern void shoot(playerent *d, vec &to);
|
||||
extern void createrays(vec &from, vec &to, bool force); // force - new:2010nov19
|
||||
extern void createrays(vec &from, vec &to);
|
||||
extern void removebounceents(playerent *owner);
|
||||
extern void movebounceents();
|
||||
extern void clearbounceents();
|
||||
|
||||
@@ -55,7 +55,6 @@ float perlinnoise_2D(float x, float y, int seedstep, float pers)
|
||||
|
||||
void perlinarea(block &b, int scale, int seed, int psize)
|
||||
{
|
||||
srand(seed);
|
||||
seed = rnd(10000);
|
||||
if(!scale) scale = 10;
|
||||
for(int y = b.y; y<=b.y+b.ys; y++) for(int x = b.x; x<=b.x+b.xs; x++)
|
||||
|
||||
@@ -1015,7 +1015,7 @@ void distributeteam(int team)
|
||||
if(team == 100 || team == clients[i]->team)
|
||||
{
|
||||
tdistrib.add(i);
|
||||
clients[i]->at3_score = rand();
|
||||
clients[i]->at3_score = rnd(0x1000000);
|
||||
}
|
||||
}
|
||||
tdistrib.sort(cmpscore); // random player order
|
||||
@@ -1023,7 +1023,7 @@ void distributeteam(int team)
|
||||
loopi(numsp)
|
||||
{
|
||||
ti.index = i;
|
||||
ti.value = rand();
|
||||
ti.value = rnd(0x1000000);
|
||||
sdistrib.add(ti);
|
||||
}
|
||||
sdistrib.sort(cmptwoint); // random spawn order
|
||||
@@ -3674,7 +3674,7 @@ void serverslice(uint timeout) // main server update, called from cube main lo
|
||||
c.peer->data = (void *)(size_t)c.clientnum;
|
||||
c.connectmillis = servmillis;
|
||||
c.state.state = CS_SPECTATE;
|
||||
c.salt = rand()*((servmillis%1000)+1);
|
||||
c.salt = rnd(0x1000000)*((servmillis%1000)+1);
|
||||
char hn[1024];
|
||||
copystring(c.hostname, (enet_address_get_host_ip(&c.peer->address, hn, sizeof(hn))==0) ? hn : "unknown");
|
||||
logline(ACLOG_INFO,"[%s] client connected", c.hostname);
|
||||
@@ -3912,7 +3912,6 @@ void initserver(bool dedicated, int argc, char **argv)
|
||||
if ( strlen(scl.servdesc_full) ) global_name = scl.servdesc_full;
|
||||
else global_name = server_name;
|
||||
|
||||
srand(time(NULL));
|
||||
smapname[0] = '\0';
|
||||
|
||||
string identity;
|
||||
|
||||
+4
-2
@@ -58,8 +58,8 @@ static inline T min(T a, T b)
|
||||
static inline float round(float x) { return floor(x + 0.5f); }
|
||||
|
||||
#define clamp(a,b,c) (max(b, min(a, c)))
|
||||
#define rnd(max) (rand()%(max))
|
||||
#define rnd_2x(max) (rand()%(max)+rand()%(max))
|
||||
#define rnd(x) ((int)(randomMT()&0xFFFFFF)%(x))
|
||||
#define rndscale(x) (float((randomMT()&0xFFFFFF)*double(x)/double(0xFFFFFF)))
|
||||
#define detrnd(s, x) ((int)(((((uint)(s))*1103515245+12345)>>16)%(x)))
|
||||
|
||||
#define loop(v,m) for(int v = 0; v<int(m); v++)
|
||||
@@ -913,6 +913,8 @@ extern enet_uint32 adler(unsigned char *data, size_t len);
|
||||
extern void endianswap(void *, int, int);
|
||||
extern bool isbigendian();
|
||||
extern void strtoupper(char *t, const char *s = NULL);
|
||||
extern void seedMT(uint seed);
|
||||
extern uint randomMT(void);
|
||||
|
||||
struct iprange { enet_uint32 lr, ur; };
|
||||
extern const char *atoip(const char *s, enet_uint32 *ip);
|
||||
|
||||
+15
-15
@@ -143,20 +143,17 @@ void tryreload(playerent *p)
|
||||
void selfreload() { tryreload(player1); }
|
||||
COMMANDN(reload, selfreload, ARG_NONE);
|
||||
|
||||
void createrays(vec &from, vec &to, bool force = false) // create random spread of rays for the shotgun
|
||||
void createrays(vec &from, vec &to) // create random spread of rays for the shotgun
|
||||
{
|
||||
if( force || player1->attacking )
|
||||
float f = to.dist(from)*SGSPREAD/1000;
|
||||
if(1==0)conoutf("shotgun distance: %.2f", f); // DEBUG 2010nov19
|
||||
loopi(SGRAYS)
|
||||
{
|
||||
float f = to.dist(from)*SGSPREAD/1000;
|
||||
if(1==0)conoutf("shotgun distance: %.2f", f); // DEBUG 2010nov19
|
||||
loopi(SGRAYS)
|
||||
{
|
||||
#define RNDD (rnd_2x(51)-50)*f // With this (rnd_2x in place of rnd) the spread does not change, but there will be more shots in the middle area
|
||||
vec r(RNDD, RNDD, RNDD);
|
||||
sg[i] = to;
|
||||
sg[i].add(r);
|
||||
#undef RNDD
|
||||
}
|
||||
#define RNDD (rndscale(100)-50)*f
|
||||
vec r(RNDD, RNDD, RNDD);
|
||||
sg[i] = to;
|
||||
sg[i].add(r);
|
||||
#undef RNDD
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1127,12 +1124,15 @@ void gun::checkautoreload() { if(autoreload && owner==player1 && !mag) reload();
|
||||
|
||||
shotgun::shotgun(playerent *owner) : gun(owner, GUN_SHOTGUN) {}
|
||||
|
||||
void shotgun::attackphysics(vec &from, vec &to)
|
||||
{
|
||||
createrays(from, to);
|
||||
gun::attackphysics(from, to);
|
||||
}
|
||||
|
||||
bool shotgun::attack(vec &targ)
|
||||
{
|
||||
if(1==0)conoutf("shotgun:attack(%.2f, %.2f, %.2f)", targ.x, targ.y, targ.z); // 2010nov19
|
||||
vec from = owner->o;
|
||||
from.z -= weaponbeloweye;
|
||||
createrays(from, targ, false); // force: false^=check-PLAYER-attacking-FLAG new:2010nov19 // TODO make check here not in createrays
|
||||
return gun::attack(targ);
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ struct rifle : gun
|
||||
struct shotgun : gun
|
||||
{
|
||||
shotgun(playerent *owner);
|
||||
void attackphysics(vec &from, vec &to);
|
||||
bool attack(vec &targ);
|
||||
void attackfx(const vec &from, const vec &to, int millis);
|
||||
bool selectable();
|
||||
|
||||
Reference in New Issue
Block a user