Fix RAND_MAX overflow errors

In `psrand.h` it attempts to undefine RAND_MAX and then redefine it.
This may work on some compilers but G++/Clang. To resolve this error
RAND_MAX was renamed to D3_RAND_MAX but **only** in files that
included `psrand.h`. The code behavior should restored to that of the
official release.
This commit is contained in:
GravisZro 2024-05-22 19:38:56 -04:00
parent a1a8056afc
commit fb74b66bdf
20 changed files with 139 additions and 136 deletions

View File

@ -517,7 +517,7 @@ void GoalInitWanderAround(object *obj, goal *goal_ptr) {
goal_ptr->g_info.pos = pos;
goal_ptr->g_info.roomnum = roomnum;
goal_ptr->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)RAND_MAX;
goal_ptr->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)D3_RAND_MAX;
goal_ptr->flags |= GF_HAS_PATH;
}
@ -828,7 +828,7 @@ void GoalDoFrame(object *obj) {
GoalClearGoal(obj, cur_goal, kill_reason);
} else {
// Update time regardless of if we made the path (so dont don't do this every frame
cur_goal->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)RAND_MAX;
cur_goal->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)D3_RAND_MAX;
}
}
}
@ -850,7 +850,7 @@ void GoalPathComplete(object *obj) {
if (AIPathAllocPath(obj, ai_info, cur_goal, &obj->roomnum, &obj->pos, &goal_obj->roomnum, &goal_obj->pos, 0.0f, 0,
obj->handle, ignore_obj)) {
cur_goal->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)RAND_MAX;
cur_goal->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)D3_RAND_MAX;
}
} else {
GoalClearGoal(obj, cur_goal, AIN_GOAL_COMPLETE);
@ -1008,7 +1008,7 @@ int GoalAddGoal(object *obj, unsigned int goal_type, void *arg_struct, int level
if (AIPathAllocPath(obj, ai_info, &ai_info->goals[goal_index], &obj->roomnum, &obj->pos, &goal_obj->roomnum,
&goal_obj->pos, 0.0f, 0, obj->handle, ignore_obj)) {
goal_ptr->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)RAND_MAX;
goal_ptr->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)D3_RAND_MAX;
} else {
goal_ptr->next_path_time = Gametime;
}
@ -1029,7 +1029,7 @@ int GoalAddGoal(object *obj, unsigned int goal_type, void *arg_struct, int level
if (AIPathAllocPath(obj, ai_info, &ai_info->goals[goal_index], &obj->roomnum, &obj->pos, &goal_obj->roomnum,
&goal_obj->pos, 0.0f, 0, obj->handle, ignore_obj)) {
goal_ptr->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)RAND_MAX;
goal_ptr->next_path_time = Gametime + MIN_NEXT_PATH_INTERVAL + ps_rand() / (float)D3_RAND_MAX;
} else {
goal_ptr->next_path_time = Gametime;
}

View File

@ -1926,7 +1926,7 @@ bool compute_dodge_dir(vector *movement_dir, object *obj, object *dodge_obj) {
}
obj->ai_info->dodge_till_time =
Gametime + ((float)ps_rand() / (float)RAND_MAX) * (3.0f * obj->ai_info->life_preservation) + 1.0f;
Gametime + ((float)ps_rand() / (float)D3_RAND_MAX) * (3.0f * obj->ai_info->life_preservation) + 1.0f;
*movement_dir += dodge_vec;
@ -2402,7 +2402,7 @@ bool AiMelee(object *obj) {
gi_fire attack_info;
int attack_num;
if (!(ai_info->flags & AIF_MELEE1) || ((ai_info->flags & AIF_MELEE2) && (ps_rand() > (RAND_MAX >> 1)))) {
if (!(ai_info->flags & AIF_MELEE1) || ((ai_info->flags & AIF_MELEE2) && (ps_rand() > (D3_RAND_MAX >> 1)))) {
attack_num = 1;
} else {
attack_num = 0;
@ -2450,7 +2450,7 @@ void do_melee_attack(object *obj) {
object *objptr = ObjGet(ai_info->target_handle);
if (objptr) {
if (ps_rand() > RAND_MAX / 2) {
if (ps_rand() > D3_RAND_MAX / 2) {
Sound_system.Play3dSound(SOUND_MELEE_HIT_0, SND_PRIORITY_HIGHEST, objptr);
if (Game_mode & GM_MULTI)
MultiPlay3dSound(SOUND_MELEE_HIT_0, OBJNUM(objptr), SND_PRIORITY_HIGHEST);
@ -3060,7 +3060,7 @@ bool AINotify(object *obj, ubyte notify_type, void *info) {
if (!(ai_info->flags & AIF_DISABLED)) {
if (ai_info->flags & AIF_DODGE) {
if (ai_info->awareness > AWARE_BARELY) {
if (ps_rand() < ai_info->dodge_percent * RAND_MAX) {
if (ps_rand() < ai_info->dodge_percent * D3_RAND_MAX) {
vector fov_vec;
if (ai_info->vec_to_target_actual * (*AIDetermineFovVec(&Objects[AI_RenderedList[i]], &fov_vec)) >=
@ -3099,7 +3099,7 @@ bool AINotify(object *obj, ubyte notify_type, void *info) {
if (ai_info->notify_flags & (0x00000001 << notify_type)) {
if (!(ai_info->flags & AIF_DISABLED)) {
if (ai_info->flags & AIF_DODGE) {
if (ps_rand() < ai_info->dodge_percent * RAND_MAX) {
if (ps_rand() < ai_info->dodge_percent * D3_RAND_MAX) {
vector to_weapon = other_obj->pos - Objects[i].pos;
vm_NormalizeVector(&to_weapon);
@ -3206,7 +3206,7 @@ bool AINotify(object *obj, ubyte notify_type, void *info) {
bool f_enemy = AIObjEnemy(obj, new_enemy);
float rand_val = ps_rand() / (float)RAND_MAX;
float rand_val = ps_rand() / (float)D3_RAND_MAX;
if (new_enemy && (new_enemy != obj)) {
// 20% per hit of switching to hitting player
@ -3222,7 +3222,7 @@ bool AINotify(object *obj, ubyte notify_type, void *info) {
ai_info->flags |= AIF_DETERMINE_TARGET;
obj->ai_info->next_target_update_time =
Gametime + MIN_TARGET_UPDATE_INTERVAL +
((float)ps_rand() / (float)RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
((float)ps_rand() / (float)D3_RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
AISetTarget(obj, new_enemy->handle);
}
}
@ -3240,7 +3240,7 @@ bool AINotify(object *obj, ubyte notify_type, void *info) {
ai_info->flags |= AIF_DETERMINE_TARGET;
ai_info->next_target_update_time =
Gametime + MIN_TARGET_UPDATE_INTERVAL +
((float)ps_rand() / (float)RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
((float)ps_rand() / (float)D3_RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
AISetTarget(obj, other_obj->handle);
}
}
@ -3527,7 +3527,7 @@ int AIFindRandomRoom(object *obj, ai_frame *ai_info, goal *goal_ptr, int avoid_r
if (max_depth >= 0 && min_depth >= 0) {
f_use_depth = true;
cur_depth = min_depth + (float)ps_rand() / (float)RAND_MAX * (max_depth - min_depth);
cur_depth = min_depth + (float)ps_rand() / (float)D3_RAND_MAX * (max_depth - min_depth);
}
do {
@ -3688,7 +3688,7 @@ bool AIInit(object *obj, ubyte ai_class, ubyte ai_type, ubyte ai_movement) {
bool f_no_scale = (IS_GENERIC(obj->type) && (Object_info[obj->id].flags & OIF_NO_DIFF_SCALE_MOVE)) ||
((ai_info->flags & AIF_TEAM_MASK) == AIF_TEAM_REBEL);
ai_info->mem_time_till_next_update = 3.0f + (float)ps_rand() / (float)RAND_MAX * 2.0f;
ai_info->mem_time_till_next_update = 3.0f + (float)ps_rand() / (float)D3_RAND_MAX * 2.0f;
memset(ai_info->memory, 0, sizeof(ai_mem) * AI_MEM_DEPTH);
for (i = 0; i < AI_MEM_DEPTH; i++) {
ai_info->memory[0].shields = obj->shields;
@ -3751,7 +3751,7 @@ bool AIInit(object *obj, ubyte ai_class, ubyte ai_type, ubyte ai_movement) {
p_info->anim_flags = AIAF_LOOPING;
// Setup the initial animation state info
float rand_offset = ps_rand() / ((float)RAND_MAX);
float rand_offset = ps_rand() / ((float)D3_RAND_MAX);
p_info->anim_start_frame = Object_info[obj->id].anim[ai_movement].elem[anim].from;
p_info->anim_end_frame = Object_info[obj->id].anim[ai_movement].elem[anim].to;
p_info->anim_time = Object_info[obj->id].anim[ai_movement].elem[anim].spc;
@ -3783,7 +3783,7 @@ bool AIInit(object *obj, ubyte ai_class, ubyte ai_type, ubyte ai_movement) {
ai_info->next_melee_time = Gametime;
ai_info->next_flinch_time = Gametime;
AISetTarget(obj, OBJECT_HANDLE_NONE);
ai_info->next_check_see_target_time = Gametime + (float)ps_rand() / (float)RAND_MAX;
ai_info->next_check_see_target_time = Gametime + (float)ps_rand() / (float)D3_RAND_MAX;
ai_info->last_see_target_time = Gametime - CHECK_VIS_INFREQUENTLY_TIME * 2.0f;
ai_info->last_hear_target_time = Gametime - CHECK_VIS_INFREQUENTLY_TIME * 2.0f;
ai_info->last_render_time = -1.0f;
@ -3791,11 +3791,11 @@ bool AIInit(object *obj, ubyte ai_class, ubyte ai_type, ubyte ai_movement) {
if (ai_info->flags & AIF_FLUCTUATE_SPEED_PROPERTIES) {
ai_info->max_velocity *=
1.0f + (((float)ps_rand() - RAND_MAX * 0.5f) / (RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT;
1.0f + (((float)ps_rand() - D3_RAND_MAX * 0.5f) / (D3_RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT;
ai_info->max_delta_velocity *=
1.0f + (((float)ps_rand() - RAND_MAX * 0.5f) / (RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT;
1.0f + (((float)ps_rand() - D3_RAND_MAX * 0.5f) / (D3_RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT;
ai_info->max_turn_rate *=
1.0f + (((float)ps_rand() - RAND_MAX * 0.5f) / (RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT;
1.0f + (((float)ps_rand() - D3_RAND_MAX * 0.5f) / (D3_RAND_MAX * 0.5f)) * MAX_FLUCTUATION_PERCENT;
}
ai_info->notify_flags |= AI_NOTIFIES_ALWAYS_ON;
@ -4061,11 +4061,11 @@ void AICheckTargetVis(object *obj) {
if ((ai_info->status_reg & AISR_SEES_GOAL) ||
Gametime - ai_info->last_see_target_time < CHECK_VIS_INFREQUENTLY_TIME)
ai_info->next_check_see_target_time =
Gametime + .9 * MIN_VIS_CHECK_INTERVAL + .2 * MIN_VIS_CHECK_INTERVAL * ((float)ps_rand() / (float)RAND_MAX);
Gametime + .9 * MIN_VIS_CHECK_INTERVAL + .2 * MIN_VIS_CHECK_INTERVAL * ((float)ps_rand() / (float)D3_RAND_MAX);
else
ai_info->next_check_see_target_time =
Gametime + .9 * CHECK_VIS_INFREQUENTLY_INTERVAL +
.2 * CHECK_VIS_INFREQUENTLY_INTERVAL * ((float)ps_rand() / (float)RAND_MAX);
.2 * CHECK_VIS_INFREQUENTLY_INTERVAL * ((float)ps_rand() / (float)D3_RAND_MAX);
}
}
@ -5532,7 +5532,7 @@ void ai_fire(object *obj) {
}
} else {
ai_info->status_reg &= ~AISR_RANGED_ATTACK;
obj->dynamic_wb[i].last_fire_time = Gametime + 1.0f + ps_rand() / (float)RAND_MAX;
obj->dynamic_wb[i].last_fire_time = Gametime + 1.0f + ps_rand() / (float)D3_RAND_MAX;
}
}
}
@ -5559,7 +5559,7 @@ static inline void do_awareness_based_anim_stuff(object *obj) {
// Once a second we have a chance of doing a quirk
if (new_time_int != last_time_int) {
if (ps_rand() < RAND_MAX * PERCENT_QUIRK_PER_SEC) {
if (ps_rand() < D3_RAND_MAX * PERCENT_QUIRK_PER_SEC) {
next_anim = AS_QUIRK;
GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL);
}
@ -5579,7 +5579,7 @@ static inline void do_awareness_based_anim_stuff(object *obj) {
// Once a second we have a chance of doing a quirk
if (new_time_int != last_time_int) {
if (ps_rand() < RAND_MAX * PERCENT_TAUNT_PER_SEC) {
if (ps_rand() < D3_RAND_MAX * PERCENT_TAUNT_PER_SEC) {
next_anim = AS_TAUNT;
GoalAddGoal(obj, AIG_SET_ANIM, (void *)&next_anim, ACTIVATION_BLEND_LEVEL);
}
@ -5929,11 +5929,11 @@ void AIDetermineTarget(object *obj) {
if (ai_info->awareness >= AWARE_BARELY)
ai_info->next_target_update_time =
Gametime + MIN_TARGET_UPDATE_INTERVAL +
((float)ps_rand() / (float)RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
((float)ps_rand() / (float)D3_RAND_MAX) * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
else
ai_info->next_target_update_time =
Gametime + 2.0f * MIN_TARGET_UPDATE_INTERVAL +
((float)ps_rand() / (float)RAND_MAX) * 2.0f * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
((float)ps_rand() / (float)D3_RAND_MAX) * 2.0f * (MAX_TARGET_UPDATE_INTERVAL - MIN_TARGET_UPDATE_INTERVAL);
// Chrishack -- if agression is over a value, NO switching targets!!!!!!!!! Need to implement
// Chrishack -- if frustration is over a value, act as hostile -- temp stuff AIF_TEAM_HOSTILE
@ -5964,8 +5964,8 @@ void AIDetermineTarget(object *obj) {
bool f_forgive_friend = false;
if ((t) && (t->control_type == CT_AI) && ((t->ai_info->flags & AIF_TEAM_MASK) == AIF_TEAM_PTMC)) {
// Do the divide because we don't want RAND_MAX to go too high
if (ps_rand() / AI_FORGIVE_AGRESSION_MULTIPLIER > ai_info->agression * RAND_MAX) {
// Do the divide because we don't want D3_RAND_MAX to go too high
if (ps_rand() / AI_FORGIVE_AGRESSION_MULTIPLIER > ai_info->agression * D3_RAND_MAX) {
f_forgive_friend = true;
}
}
@ -6013,7 +6013,7 @@ void AIDoFreud(object *obj) {
if (ai_info->goals[3].used == 0 && ai_info->awareness > AWARE_BARELY) {
if (IS_GENERIC(obj->type) && mem[0].shields / Object_info[obj->id].hit_points < ai_info->life_preservation &&
mem[0].num_enemy_shots_dodged > 0 && mem[0].num_friends < 2 &&
(float)ps_rand() / (float)RAND_MAX < ai_info->life_preservation) {
(float)ps_rand() / (float)D3_RAND_MAX < ai_info->life_preservation) {
float time = 10.0f * ai_info->life_preservation + 5.0f;
GoalAddGoal(obj, AIG_WANDER_AROUND, NULL, 3, 2.0f, GF_SPEED_FLEE | GF_ORIENT_VELOCITY | GF_NONFLUSHABLE);
@ -6027,7 +6027,7 @@ void AIDoFreud(object *obj) {
if (IS_GENERIC(obj->type) &&
(mem[fear_depth].shields - mem[0].shields) / mem[fear_depth].shields >
0.25f * (1.0f - ai_info->life_preservation) &&
(float)ps_rand() / (float)RAND_MAX < ai_info->life_preservation) {
(float)ps_rand() / (float)D3_RAND_MAX < ai_info->life_preservation) {
float time = 10.0f * ai_info->life_preservation + 5.0f;
GoalAddGoal(obj, AIG_WANDER_AROUND, NULL, 3, 2.0f, GF_SPEED_FLEE | GF_ORIENT_VELOCITY | GF_NONFLUSHABLE);
@ -6059,7 +6059,7 @@ void AIDoMemFrame(object *obj) {
int i;
// Compute next analyze time
ai_info->mem_time_till_next_update = 3.0f + (float)ps_rand() / (float)RAND_MAX * 2.0f;
ai_info->mem_time_till_next_update = 3.0f + (float)ps_rand() / (float)D3_RAND_MAX * 2.0f;
// Do the amount of friends/enemies left and the current shields before running Freud
short near_objs[100];

View File

@ -725,7 +725,7 @@ int ObjInitPlayer(object *objp) {
int ObjInitGeneric(object *objp, bool reinit) {
object_info *obj_info;
int ret = 1;
float r_val = (float)ps_rand() / (float)RAND_MAX;
float r_val = (float)ps_rand() / (float)D3_RAND_MAX;
if ((objp->id < 0) || (objp->id >= MAX_OBJECT_IDS)) {
Int3();
return 0;

View File

@ -2782,9 +2782,9 @@ void PlayerSpewGuidebot(object *parent, int type, int id) {
obj->mtype.phys_info.flags = (PF_GRAVITY | PF_BOUNCE | PF_FIXED_ROT_VELOCITY);
obj->mtype.phys_info.coeff_restitution = .25f;
obj->mtype.phys_info.rotvel.x = (float)((120000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
obj->mtype.phys_info.rotvel.y = (float)((120000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
obj->mtype.phys_info.rotvel.z = (float)((120000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
obj->mtype.phys_info.rotvel.x = (float)((120000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
obj->mtype.phys_info.rotvel.y = (float)((120000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
obj->mtype.phys_info.rotvel.z = (float)((120000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
obj->mtype.phys_info.num_bounces = 5;
@ -2805,9 +2805,9 @@ void PlayerSpewObject(object *objp, int timed, int room, vector *pos, matrix *or
ObjSetPos(objp, pos, room, orient, true);
// Set random velocity for powerups
objp->mtype.phys_info.velocity.x = ((ps_rand() / (float)RAND_MAX) - .5f) * 40.0; // +20 to -20
objp->mtype.phys_info.velocity.z = ((ps_rand() / (float)RAND_MAX) - .5f) * 40.0; // +20 to -20
objp->mtype.phys_info.velocity.y = ((ps_rand() / (float)RAND_MAX) - .5f) * 40.0; // +20 to -20
objp->mtype.phys_info.velocity.x = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 40.0; // +20 to -20
objp->mtype.phys_info.velocity.z = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 40.0; // +20 to -20
objp->mtype.phys_info.velocity.y = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 40.0; // +20 to -20
// Send object to other players
if (Game_mode & GM_MULTI) {
@ -3170,7 +3170,7 @@ void PlayerShipBreakup(object *obj, float magnitude) {
}
// this is an INDEX into the VALID subobjects in the polymodel. (skip 1st subobj)
idx = (ps_rand() * n_remaining_models / RAND_MAX) + 1;
idx = (ps_rand() * n_remaining_models / D3_RAND_MAX) + 1;
subobjnum = -1;
for (i = 1, j = 1; i < n_models; i++) {
@ -3216,12 +3216,12 @@ void PlayerShipSpewPartSub(object *obj, bsp_info *submodel, float magnitude) {
i++;
}
rand_vec.x = (float)(RAND_MAX / 2 - ps_rand());
rand_vec.x = (float)(D3_RAND_MAX / 2 - ps_rand());
if (obj->movement_type != MT_PHYSICS)
rand_vec.y = (float)((float)ps_rand() / 2.0); // A habit of moving upward
else
rand_vec.y = (float)((float)RAND_MAX / 1.5f - (float)ps_rand()); // A habit of moving upward
rand_vec.z = (float)(RAND_MAX / 2 - ps_rand());
rand_vec.y = (float)((float)D3_RAND_MAX / 1.5f - (float)ps_rand()); // A habit of moving upward
rand_vec.z = (float)(D3_RAND_MAX / 2 - ps_rand());
vm_NormalizeVectorFast(&rand_vec);
object *subobj = CreateSubobjectDebrisDirected(obj, subobjnum, &rand_vec, magnitude);

View File

@ -3212,7 +3212,7 @@ void TelcomEndScreen(void) {
TCWorking_screen = -1;
}
float myrand(float max) { return (max * (((float)ps_rand()) / ((float)RAND_MAX))); }
float myrand(float max) { return (max * (((float)ps_rand()) / ((float)D3_RAND_MAX))); }
/////////////////////////////////////////////////////////////////////////////
// These are the functions used for serialization, yes they are out of place,

View File

@ -1576,7 +1576,7 @@ object *HomingAquireTarget(object *obj) {
}
}
} else {
if (ps_rand() < RAND_MAX / 4) { // 1/4 chance of picking chaff
if (ps_rand() < D3_RAND_MAX / 4) { // 1/4 chance of picking chaff
best_index = i;
break;
}

View File

@ -146,7 +146,7 @@ bool AIFindAltPath(object *obj, int i, int j, float *dist) {
if (BOA_cost_array[cur_node->roomnum][counter] >= 0.0f)
new_cost = cur_node->cost +
(1.0f + 0.1f * ((float)ps_rand() - (float)RAND_MAX / 2.0f) / ((float)RAND_MAX / 2.0f)) *
(1.0f + 0.1f * ((float)ps_rand() - (float)D3_RAND_MAX / 2.0f) / ((float)D3_RAND_MAX / 2.0f)) *
(BOA_cost_array[cur_node->roomnum][counter] + BOA_cost_array[BOA_INDEX(next_room)][next_portal]);
else
continue;

View File

@ -89,8 +89,8 @@ asp Ambient_sound_patterns[MAX_AMBIENT_SOUND_PATTERNS];
int Num_ambient_sound_patterns = 0;
// Computes a floating-point pseudo-random number.
// Returns value in the range 0..1, with the precision 1/RAND_MAX
static float randf() { return ((float)ps_rand()) / ((float)RAND_MAX); }
// Returns value in the range 0..1, with the precision 1/D3_RAND_MAX
static float randf() { return ((float)ps_rand()) / ((float)D3_RAND_MAX); }
// Process an Ambient Sound Pattern
static void ProcessASP(asp *asp) {
@ -105,7 +105,7 @@ static void ProcessASP(asp *asp) {
if (asp->delay < 0.0) {
// Figure out which sound to play
int roll = (ps_rand() * 100) / (RAND_MAX + 1); // roll = 0..99
int roll = (ps_rand() * 100) / (D3_RAND_MAX + 1); // roll = 0..99
int s;
for (s = 0; s < asp->num_sounds; s++)

View File

@ -1059,7 +1059,7 @@ void KillObject(object *objp, object *killer, float damage) {
if (IS_GENERIC(objp->type)) {
// Get random probability
int r = (ps_rand() * 100 / (RAND_MAX + 1)) + 1; // in range 1 to 100
int r = (ps_rand() * 100 / (D3_RAND_MAX + 1)) + 1; // in range 1 to 100
// Loop through death types looking for chosen one
for (int i = 0; i < MAX_DEATH_TYPES; i++) {
@ -1072,7 +1072,7 @@ void KillObject(object *objp, object *killer, float damage) {
delay_min = Object_info[objp->id].death_types[i].delay_min;
delay_max = Object_info[objp->id].death_types[i].delay_max;
delay_time = delay_min + (delay_max - delay_min) * ps_rand() / RAND_MAX;
delay_time = delay_min + (delay_max - delay_min) * ps_rand() / D3_RAND_MAX;
mprintf((0, "Using %d\n", i));
break;
@ -1108,15 +1108,15 @@ void SetFallingPhysics(object *objp) {
if (proj < 0.0f)
objp->mtype.phys_info.velocity -= proj * objp->orient.uvec;
objp->mtype.phys_info.velocity += objp->orient.uvec * (3.0f + ((float)ps_rand() / RAND_MAX) * 5.0);
objp->mtype.phys_info.velocity += objp->orient.uvec * (3.0f + ((float)ps_rand() / D3_RAND_MAX) * 5.0);
objp->movement_type = MT_PHYSICS;
} else { // not a walker
// If not spinning much, give the object a good spin
if (vm_GetMagnitude(&objp->mtype.phys_info.rotvel) < 4000.0f) {
objp->mtype.phys_info.rotvel.x = (float)((60000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
objp->mtype.phys_info.rotvel.y = (float)((60000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
objp->mtype.phys_info.rotvel.z = (float)((60000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
objp->mtype.phys_info.rotvel.x = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
objp->mtype.phys_info.rotvel.y = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
objp->mtype.phys_info.rotvel.z = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
}
}
}
@ -1134,9 +1134,9 @@ void SetFlyingPhysics(object *objp, bool tumbles) {
if (tumbles) {
// Make y spin a little bit more that x or z
objp->mtype.phys_info.rotvel.x = (float)((40000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
objp->mtype.phys_info.rotvel.y = (float)((60000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
objp->mtype.phys_info.rotvel.z = (float)((40000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
objp->mtype.phys_info.rotvel.x = (float)((40000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
objp->mtype.phys_info.rotvel.y = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
objp->mtype.phys_info.rotvel.z = (float)((40000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
}
if (objp->orient.uvec.y == 1.0f) {
@ -1386,7 +1386,7 @@ bool ApplyDamageToGeneric(object *hit_obj, object *killer, int damage_type, floa
// if (!((Game_mode & GM_MULTI) && (Netgame.local_role == LR_CLIENT)))
// {
// // Attached objects have a 50% chance of falling off their parent when they die
// if(ps_rand() >= (RAND_MAX >> 1))
// if(ps_rand() >= (D3_RAND_MAX >> 1))
// {
// UnattachFromParent(hit_obj);
// }

View File

@ -376,8 +376,8 @@
*
* 131 8/17/98 1:32a Chris
* Fixed a type cast bug the resulted in rand_vec.y always equaling .4
* and then zero after normalization (as the others ranged from RAND_MAX/2
* to -RAND_MAX/2)
* and then zero after normalization (as the others ranged from D3_RAND_MAX/2
* to -D3_RAND_MAX/2)
*
* 130 8/17/98 1:15a Chris
* By default, obj_debris don't make a sound when they die
@ -939,9 +939,9 @@ object *CreateSubobjectDebrisDirected(object *parent, int subobj_num, vector *di
obj->mtype.phys_info.flags = (PF_GRAVITY | PF_BOUNCE | PF_FIXED_ROT_VELOCITY);
obj->mtype.phys_info.coeff_restitution = .2f;
obj->mtype.phys_info.rotvel.x = (float)((60000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
obj->mtype.phys_info.rotvel.y = (float)((60000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
obj->mtype.phys_info.rotvel.z = (float)((60000.0f * (float)(RAND_MAX / 2 - ps_rand())) / (float)(RAND_MAX / 2));
obj->mtype.phys_info.rotvel.x = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
obj->mtype.phys_info.rotvel.y = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
obj->mtype.phys_info.rotvel.z = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
if (death_flags & DF_DEBRIS_REMAINS) {
obj->mtype.phys_info.num_bounces = 8;
obj->mtype.phys_info.flags |= PF_STICK;
@ -963,12 +963,12 @@ object *CreateSubobjectDebrisDirected(object *parent, int subobj_num, vector *di
object *CreateSubobjectDebris(object *parent, int subobj_num, float explosion_mag, int death_flags) {
vector rand_vec;
// Set physics data for this object
rand_vec.x = (float)(RAND_MAX / 2 - ps_rand());
rand_vec.y = (float)(RAND_MAX / 2 - ps_rand()) + .2f * RAND_MAX; // a habit of moving upwards
rand_vec.z = (float)(RAND_MAX / 2 - ps_rand());
rand_vec.x = (float)(D3_RAND_MAX / 2 - ps_rand());
rand_vec.y = (float)(D3_RAND_MAX / 2 - ps_rand()) + .2f * D3_RAND_MAX; // a habit of moving upwards
rand_vec.z = (float)(D3_RAND_MAX / 2 - ps_rand());
vm_NormalizeVectorFast(&rand_vec);
explosion_mag *= 1.0f + ((float)(RAND_MAX / 2 - ps_rand()) / (float)(RAND_MAX / 2) * 0.05); // +5/-5 percent
explosion_mag *= 1.0f + ((float)(D3_RAND_MAX / 2 - ps_rand()) / (float)(D3_RAND_MAX / 2) * 0.05); // +5/-5 percent
return CreateSubobjectDebrisDirected(parent, subobj_num, &rand_vec, explosion_mag, death_flags);
}
// Create extra fireballs for an exploding object
@ -1153,7 +1153,7 @@ void DoDeathSpew(object *parent) {
continue; // spew type set to none
type = Object_info[id].type;
int max_spewed = Object_info[parent->id].dspew_number[i];
int rand_val = (int)((float)RAND_MAX * Object_info[parent->id].dspew_percent[i]);
int rand_val = (int)((float)D3_RAND_MAX * Object_info[parent->id].dspew_percent[i]);
// Skip it if the player has that weapon battery enabled
// If multiplayer, it will spew type 2 if no type 1 is spewed
if (i == 0 && (f_dspew & DSF_ONLY_IF_PLAYER_HAS_OBJ_1)) {
@ -1192,9 +1192,9 @@ void DoDeathSpew(object *parent) {
object *obj = &Objects[objnum];
// Set random velocity for powerups
obj->mtype.phys_info.velocity.x = ((ps_rand() / (float)RAND_MAX) - .5f) * 35.0;
obj->mtype.phys_info.velocity.z = ((ps_rand() / (float)RAND_MAX) - .5f) * 35.0;
obj->mtype.phys_info.velocity.y = ((ps_rand() / (float)RAND_MAX) - .5f) * 35.0;
obj->mtype.phys_info.velocity.x = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 35.0;
obj->mtype.phys_info.velocity.z = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 35.0;
obj->mtype.phys_info.velocity.y = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 35.0;
InitObjectScripts(obj);
// Send object to other players
if (Game_mode & GM_MULTI) {
@ -1315,7 +1315,7 @@ void PlayObjectExplosionSound(object *objp) {
if (objp->type == OBJ_BUILDING)
sound = SOUND_BUILDING_EXPLODE;
else
sound = (ps_rand() > RAND_MAX / 2) ? SOUND_ROBOT_EXPLODE_1 : SOUND_ROBOT_EXPLODE_2;
sound = (ps_rand() > D3_RAND_MAX / 2) ? SOUND_ROBOT_EXPLODE_1 : SOUND_ROBOT_EXPLODE_2;
}
}
if (sound != -1)
@ -2379,7 +2379,7 @@ void DoExplosionEvent(int eventnum, void *data) {
sound_pos.orient = &id_mat;
sound_pos.velocity = &zero_vec;
if (ps_rand() > RAND_MAX / 2)
if (ps_rand() > D3_RAND_MAX / 2)
Sound_system.Play3dSound(SOUND_ROBOT_EXPLODE_1, SND_PRIORITY_HIGH, &sound_pos);
else
Sound_system.Play3dSound(SOUND_ROBOT_EXPLODE_2, SND_PRIORITY_HIGH, &sound_pos);

View File

@ -1186,7 +1186,7 @@ bool matcen::SetStatus(int status, bool f_enable) // Not all flags are settable
void matcen::CheckActivateStatus() {
m_next_active_check_time = Gametime + MATCEN_ACTIVE_CHECK_RATE +
(MATCEN_ACTIVE_CHECK_VARIENCE * (((float)ps_rand()) / ((float)RAND_MAX) - .5f));
(MATCEN_ACTIVE_CHECK_VARIENCE * (((float)ps_rand()) / ((float)D3_RAND_MAX) - .5f));
m_last_active_check_result = (m_status & MSTAT_ACTIVE) != 0;
// Determine if active

View File

@ -1986,7 +1986,7 @@ vector osipf_AIGetRoomPathPoint(int roomnum) {
vector pos;
ComputeTerrainSegmentCenter(&pos, cell);
pos.y += 15.0f + ((float)ps_rand() / (float)RAND_MAX) * 20; // between 15 and 35
pos.y += 15.0f + ((float)ps_rand() / (float)D3_RAND_MAX) * 20; // between 15 and 35
return pos;
}
@ -3640,7 +3640,7 @@ void osipf_ObjKill(int handle, int killer_handle, float damage, int flags, float
if (flags == -1) // no flags, so use default death
KillObject(obj, killer, damage);
else {
float delay_time = min_time + (max_time - min_time) * ps_rand() / RAND_MAX;
float delay_time = min_time + (max_time - min_time) * ps_rand() / D3_RAND_MAX;
KillObject(obj, killer, damage, flags, delay_time);
}
}

View File

@ -63,7 +63,7 @@
#define TABMASK (TABSIZE - 1)
#define PERM(x) perm[(x) & TABMASK]
#define INDEX(ix, iy) PERM((ix) + PERM((iy)))
#define RANDNBR ((prand()) / (float)RAND_MAX)
#define RANDNBR ((prand()) / (float)D3_RAND_MAX)
#define LERP(t, x0, x1) ((x0) + (t) * ((x1) - (x0)))
#define SMOOTHSTEP(x) ((x))
unsigned char perm[TABSIZE];

View File

@ -2271,7 +2271,7 @@ void DrawVirusLightning(object *obj) {
if (!(obj->effect_info->type_flags & EF_VIRUS_INFECTED))
return;
float shield_norm = (float)(ps_rand() % RAND_MAX) / (float)RAND_MAX;
float shield_norm = (float)(ps_rand() % D3_RAND_MAX) / (float)D3_RAND_MAX;
shield_norm = 1 - shield_norm;
ASSERT(shield_norm >= 0 && shield_norm <= 1);

View File

@ -262,7 +262,7 @@ void WBFireBattery(object *obj, otype_wb_info *static_wb, int poly_wb_index, int
}
if (static_wb->flags & WBF_RANDOM_FIRE_ORDER) {
p_dwb->cur_firing_mask = ((float)ps_rand() / (float)RAND_MAX) * static_wb->num_masks;
p_dwb->cur_firing_mask = ((float)ps_rand() / (float)D3_RAND_MAX) * static_wb->num_masks;
} else {
p_dwb->cur_firing_mask++;
}

View File

@ -321,17 +321,17 @@ void SpewEmitAll(void) {
// do random computations
if ((spew->random & SPEW_RAND_SIZE) != 0) {
size = spew->size + (((RAND_MAX >> 1) - ps_rand()) / (float)RAND_MAX) * spew->size * 0.5f;
size = spew->size + (((D3_RAND_MAX >> 1) - ps_rand()) / (float)D3_RAND_MAX) * spew->size * 0.5f;
} else
size = spew->size;
if ((spew->random & SPEW_RAND_SPEED) != 0) {
speed = spew->speed + (((RAND_MAX >> 1) - ps_rand()) / (float)RAND_MAX) * spew->speed * 0.5f;
speed = spew->speed + (((D3_RAND_MAX >> 1) - ps_rand()) / (float)D3_RAND_MAX) * spew->speed * 0.5f;
} else
speed = spew->speed;
if ((spew->random & SPEW_RAND_LIFETIME) != 0) {
lifetime = spew->lifetime + (((RAND_MAX >> 1) - ps_rand()) / (float)RAND_MAX) * spew->lifetime * 0.5f;
lifetime = spew->lifetime + (((D3_RAND_MAX >> 1) - ps_rand()) / (float)D3_RAND_MAX) * spew->lifetime * 0.5f;
} else
lifetime = spew->lifetime;

View File

@ -33,12 +33,15 @@
*
* $NoKeywords: $
*/
#ifndef PS_RAND_H
#define PS_RAND_H
#include <cstdint>
#undef RAND_MAX
#define RAND_MAX 0x7fff
#define D3_RAND_MAX 0x7fff
void ps_srand(unsigned int seed);
void ps_srand(uint32_t seed);
int ps_rand(void);
int32_t ps_rand(void);
#endif

View File

@ -40,6 +40,6 @@ static int32_t ps_holdrand = 1L;
// These are adapted from the C runtime lib. Pretty simple.
void ps_srand(unsigned int seed) { ps_holdrand = (int32_t)seed; }
void ps_srand(uint32_t seed) { ps_holdrand = static_cast<int32_t>(seed); }
int ps_rand(void) { return (((ps_holdrand = ps_holdrand * 214013L + 2531011L) >> 16) & 0x7fff); }
int32_t ps_rand(void) { return (((ps_holdrand = ps_holdrand * 214013L + 2531011L) >> 16) & 0x7fff); }

View File

@ -2435,27 +2435,27 @@ void AlienOrganism::CalcEnergyBeamPositions(int me) {
// If we're in a beam mode, get the appropriate beam directions
if (memory->mode == ALIEN_LANDED_DEPOSITING) {
beam1_dir = -0.40f * orient.uvec - orient.fvec;
// beam1_dir += orient.rvec*(0.5f-((float)rand()/(float)RAND_MAX)*1.0f);
// beam1_dir += orient.rvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f);
vm_VectorNormalize(&beam1_dir);
beam2_dir = -0.40f * orient.uvec + orient.fvec - orient.rvec;
// beam2_dir += orient.fvec*(0.5f-((float)rand()/(float)RAND_MAX)*1.0f);
// beam2_dir += orient.fvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f);
vm_VectorNormalize(&beam2_dir);
beam3_dir = -0.40f * orient.uvec + orient.fvec + orient.rvec;
// beam3_dir += orient.fvec*(0.5f-((float)rand()/(float)RAND_MAX)*1.0f);
// beam3_dir += orient.fvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f);
vm_VectorNormalize(&beam3_dir);
} else if (memory->mode == ALIEN_LANDED_WITHDRAWING) {
beam1_dir = -0.3f * orient.uvec + orient.fvec;
// beam1_dir += orient.rvec*(0.5f-((float)rand()/(float)RAND_MAX)*1.0f);
// beam1_dir += orient.rvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f);
vm_VectorNormalize(&beam1_dir);
beam2_dir = -0.3f * orient.uvec - orient.fvec - orient.rvec;
// beam2_dir -= orient.fvec*(0.5f-((float)rand()/(float)RAND_MAX)*1.0f);
// beam2_dir -= orient.fvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f);
vm_VectorNormalize(&beam2_dir);
beam3_dir = -0.3f * orient.uvec - orient.fvec + orient.rvec;
// beam3_dir -= orient.fvec*(0.5f-((float)rand()/(float)RAND_MAX)*1.0f);
// beam3_dir -= orient.fvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f);
vm_VectorNormalize(&beam3_dir);
} else if (memory->mode == ALIEN_LANDED_HEALING) {
beam2_dir = -0.4f * orient.uvec + orient.rvec * 2.0f;
@ -2495,7 +2495,7 @@ void AlienOrganism::UpdateEnergyBeams(int me) {
// See if it's time to create the next energy effect
if (memory->next_update_beam_time <= Game_GetTime()) {
float next_duration = ALIEN_BEAM_UPDATE_TIME /*+ ((float)rand()/(float)RAND_MAX)*0.2f*/;
float next_duration = ALIEN_BEAM_UPDATE_TIME /*+ ((float)rand()/(float)D3_RAND_MAX)*0.2f*/;
memory->next_update_beam_time = Game_GetTime() + next_duration;
if (memory->mode == ALIEN_LANDED_DEPOSITING) {
@ -2565,7 +2565,7 @@ void AlienOrganism::UpdateEnergyEffect(int me) {
// See if it's time to create the next energy effect
if (memory->next_update_energy_time <= Game_GetTime()) {
float slow_down = 0.5f * (ALIEN_MAX_ENERGY_CHARGES - memory->energy_charges) / ALIEN_MAX_ENERGY_CHARGES;
memory->next_update_energy_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 0.1f + 0.05f + slow_down;
memory->next_update_energy_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 0.1f + 0.05f + slow_down;
Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
@ -2785,7 +2785,7 @@ void AlienOrganism::SetMode(int me, char mode) {
// Set the next activity time
if (mode == ALIEN_LANDED_RESTING) {
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 2.0f;
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 2.0f;
memory->ok_to_deposit = true;
} else {
memory->next_activity_time = Game_GetTime() + ALIEN_LANDED_ACTION_TIME;
@ -2846,7 +2846,7 @@ void AlienOrganism::SetMode(int me, char mode) {
memory->next_activity_time = 0.0f;
// Set the max time to wander between 20 and 40 seconds
memory->max_wander_time = ((float)rand() / (float)RAND_MAX) * 20.0f + 40.0f;
memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 20.0f + 40.0f;
} break;
case ALIEN_SCAVENGING: {
@ -2897,10 +2897,10 @@ void AlienOrganism::SetMode(int me, char mode) {
SetMaxSpeed(me, memory->base_speed * ALIEN_SCAV_SPEED_MOD);
// Set the next activity check to happen within .4 to .8 seconds
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f;
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 3.0f;
// Set the max time to wander between 20 and 40 seconds
memory->max_wander_time = ((float)rand() / (float)RAND_MAX) * 10.0f + 10.0f;
memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 10.0f + 10.0f;
} break;
case ALIEN_ATTACKING_MELEE: {
@ -2949,7 +2949,7 @@ void AlienOrganism::SetMode(int me, char mode) {
}
// Clear the next activity time
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 0.5f + 0.7f;
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 0.5f + 0.7f;
// Clear the next wander time
memory->max_wander_time = 0.0f;
@ -3046,7 +3046,7 @@ void AlienOrganism::SetMode(int me, char mode) {
Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &curr_shields);
percent_damaged = (memory->base_shields - curr_shields) / memory->base_shields;
memory->max_wander_time = ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f + (percent_damaged * 6.0f);
memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 3.0f + (percent_damaged * 6.0f);
} break;
default:
@ -3075,7 +3075,7 @@ void AlienOrganism::DoTakeoff(int me, float takeoff_speed, float speed_variance)
vector vel;
Obj_Value(me, VF_GET, OBJV_V_VELOCITY, &vel);
vel += (memory->home_uvec * (takeoff_speed + ((float)rand() / (float)RAND_MAX) * speed_variance));
vel += (memory->home_uvec * (takeoff_speed + ((float)rand() / (float)D3_RAND_MAX) * speed_variance));
Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel);
// Play the takeoff anim and tell it to go to alert next
@ -3128,7 +3128,7 @@ void AlienOrganism::DoInit(int me) {
memory->num_teammates = 0;
// .1 to 1.1 seconds into the level, do the first squad matching
memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 2.0f + 0.1f;
memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 2.0f + 0.1f;
// Update the energy effect as soon as charge exists
memory->next_update_energy_time = Game_GetTime();
@ -3141,8 +3141,8 @@ void AlienOrganism::DoInit(int me) {
memory->next_special_damage_time = Game_GetTime();
// Set the next generic check time
memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 1.0f + 0.5f;
memory->next_vis_check_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 2.0f + 1.0f;
memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f + 0.5f;
memory->next_vis_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 2.0f + 1.0f;
// Init other times
memory->next_activity_time = Game_GetTime();
@ -3230,8 +3230,8 @@ bool AlienOrganism::FindHome(int me) {
while (!home_found && num_attempts < MAX_HOME_FINDING_ATTEMPTS) {
// Determine ray angle
home_dir = start_orient.fvec;
home_dir += start_orient.uvec * (HOME_LOOK_OFFSET - ((float)rand() / (float)RAND_MAX) * 2.0f * HOME_LOOK_OFFSET);
home_dir += start_orient.rvec * (HOME_LOOK_OFFSET - ((float)rand() / (float)RAND_MAX) * 2.0f * HOME_LOOK_OFFSET);
home_dir += start_orient.uvec * (HOME_LOOK_OFFSET - ((float)rand() / (float)D3_RAND_MAX) * 2.0f * HOME_LOOK_OFFSET);
home_dir += start_orient.rvec * (HOME_LOOK_OFFSET - ((float)rand() / (float)D3_RAND_MAX) * 2.0f * HOME_LOOK_OFFSET);
// Cast home-finding ray
target_pos = start_pos + (home_dir * MAX_HOME_FINDING_DIST);
@ -3422,13 +3422,13 @@ void AlienOrganism::DoFrame(int me) {
// Periodically update the squad information (remove dead teammates and/or recruit new ones)
if (memory->next_update_squad_time <= Game_GetTime()) {
memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f;
memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 3.0f;
UpdateSquad(me);
}
// Periodically update the squad visibility information
if (memory->next_vis_check_time <= Game_GetTime()) {
memory->next_vis_check_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 1.0f + 1.0f;
memory->next_vis_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f + 1.0f;
// If we're leading, update the squad's visibility flags
if (memory->squad_flags & ALIEN_LEADER) {
@ -3446,7 +3446,7 @@ void AlienOrganism::DoFrame(int me) {
// Handle generic checks (pertains to more than 1 mode)
if (memory->next_generic_check_time <= Game_GetTime()) {
memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 1.4f + 0.6f;
memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.4f + 0.6f;
// If we're not already landed, or heading home to heal, see if we should
if (!IsLandedMode(memory->mode) && memory->mode != ALIEN_LANDING_AT_HOME &&
@ -3486,7 +3486,7 @@ void AlienOrganism::DoFrame(int me) {
// See if it should consider doing something spontaneously
if (Game_GetTime() >= memory->next_activity_time) {
// Set the next time to think about doing something (4-6 seconds)
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 1.0f + 0.5f;
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f + 0.5f;
// If alien has a target, decide whether it should go hunt it down
if (last_perceive_time < 3.0f) {
@ -3739,7 +3739,7 @@ void AlienOrganism::DoFrame(int me) {
// See if it is time to go home
if (memory->mode_time >= memory->max_wander_time) {
// Set the next max wander time
memory->max_wander_time = ((float)rand() / (float)RAND_MAX) * 10.0f + 10.0f;
memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 10.0f + 10.0f;
// If not a squadie, decide to go home
if (!(memory->squad_flags & ALIEN_SQUADIE)) {
@ -3764,7 +3764,7 @@ void AlienOrganism::DoFrame(int me) {
// See if it is time to go home
if (memory->mode_time >= memory->max_wander_time) {
// Set the next max wander time
memory->max_wander_time = ((float)rand() / (float)RAND_MAX) * 10.0f + 10.0f;
memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 10.0f + 10.0f;
// If not a squadie, decide to go home
if (!(memory->squad_flags & ALIEN_SQUADIE)) {
@ -3852,7 +3852,7 @@ void AlienOrganism::DoFrame(int me) {
// See if we should decide whether to do any charge related activities
if (Game_GetTime() >= memory->next_activity_time) {
// Set the next time to do something
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 0.6f + 0.8f;
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 0.6f + 0.8f;
// If we have some charges, see if we should do something with it
if (memory->energy_charges > 0.0f) {
@ -4014,7 +4014,7 @@ void AlienOrganism::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) {
damage_data->damage *= 0.9f;
if (Game_GetTime() >= memory->next_special_damage_time) {
memory->next_special_damage_time = Game_GetTime() + 0.8f + ((float)rand() / (float)RAND_MAX) * 0.5f;
memory->next_special_damage_time = Game_GetTime() + 0.8f + ((float)rand() / (float)D3_RAND_MAX) * 0.5f;
// Create a frag burst effect
vector pos;
@ -4032,7 +4032,7 @@ void AlienOrganism::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) {
Game_GetTime() >= memory->next_special_damage_time) {
// Check if we're currently doing energy transfer or healing
if (IsEnergyRelatedLandedMode(memory->mode)) {
memory->next_special_damage_time = Game_GetTime() + 0.1f + ((float)rand() / (float)RAND_MAX) * 0.2f;
memory->next_special_damage_time = Game_GetTime() + 0.1f + ((float)rand() / (float)D3_RAND_MAX) * 0.2f;
// Do double damage
damage_data->damage *= 3.0f;
@ -4042,7 +4042,7 @@ void AlienOrganism::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) {
vector pos;
Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
Game_CreateRandomSparks(30 + int(((float)rand() / (float)RAND_MAX) * 10.0f), &pos, room);
Game_CreateRandomSparks(30 + int(((float)rand() / (float)D3_RAND_MAX) * 10.0f), &pos, room);
return;
}
@ -4404,8 +4404,8 @@ void HeavyTrooper::DoInit(int me) {
// Init to no charge
memory->charge = 0.0f;
memory->max_charge = HT_MAX_CHARGE + ((float)rand() / (float)RAND_MAX) * HT_MAX_CHARGE_VARIANCE;
memory->curlup_dist = HT_CURLUP_DIST + ((float)rand() / (float)RAND_MAX) * HT_CURLUP_DIST_VARIANCE;
memory->max_charge = HT_MAX_CHARGE + ((float)rand() / (float)D3_RAND_MAX) * HT_MAX_CHARGE_VARIANCE;
memory->curlup_dist = HT_CURLUP_DIST + ((float)rand() / (float)D3_RAND_MAX) * HT_CURLUP_DIST_VARIANCE;
// Check for a grenade shot as soon as possible
memory->next_grenade_check_time = Game_GetTime();
@ -4499,7 +4499,7 @@ void HeavyTrooper::DoFrame(int me) {
// Decide if we should switch into grenade mode
if (Game_GetTime() >= memory->next_grenade_check_time) {
memory->next_grenade_check_time =
Game_GetTime() + HT_GRENADE_CHECK_INTERVAL + ((float)rand() / (float)RAND_MAX) * HT_GRENADE_CHECK_VARIANCE;
Game_GetTime() + HT_GRENADE_CHECK_INTERVAL + ((float)rand() / (float)D3_RAND_MAX) * HT_GRENADE_CHECK_VARIANCE;
// Make sure enough time has gone by since we last fired
if ((Game_GetTime() - memory->last_grenade_time) >= HT_GRENADE_RELOAD_TIME) {
@ -4936,7 +4936,7 @@ void Lifter::ReleaseTarget(int me) {
// Set the next pull check time for a nice delay
memory->next_pull_check_time =
Game_GetTime() + LIFTER_NEXT_PULL_DELAY + (((float)rand() / (float)RAND_MAX) * LIFTER_NEXT_PULL_VARIANCE);
Game_GetTime() + LIFTER_NEXT_PULL_DELAY + (((float)rand() / (float)D3_RAND_MAX) * LIFTER_NEXT_PULL_VARIANCE);
mprintf(0, "Target released.\n");
}
@ -5925,7 +5925,7 @@ void AlienBoss::SetMode(int me, char mode) {
}
// Set the next activity check to happen within .4 to .8 seconds
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 3.0f + 3.0f;
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 3.0f;
} break;
case AB_ATTACKING: {
@ -5957,7 +5957,7 @@ void AlienBoss::SetMode(int me, char mode) {
SetMaxSpeed(me, memory->base_speed * AB_ATTACK_SPEED_MOD);
// Set the next activity time
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 1.0f;
memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f;
// Clear the next wander time
memory->max_wander_time = 0.0f;
@ -6047,7 +6047,7 @@ void AlienBoss::SetMode(int me, char mode) {
// Set the max time to flee (base time somewhat off of damage)
float time_percent = (float(memory->fire_flee_chance) / 100.0f);
memory->max_wander_time = ((float)rand() / (float)RAND_MAX) * 2.0f + AB_MAX_FLEE_TIME * time_percent;
memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 2.0f + AB_MAX_FLEE_TIME * time_percent;
// Decrease the flee chance for next time
memory->fire_flee_chance -= AB_FLEE_CHANCE_DECREMENT;
@ -6156,7 +6156,7 @@ void AlienBoss::DoTakeoff(int me, float takeoff_speed, float speed_variance) {
int flags;
Obj_Value(me, VF_GET, OBJV_V_VELOCITY, &vel);
vel += (memory->home_uvec * (takeoff_speed + ((float)rand() / (float)RAND_MAX) * speed_variance));
vel += (memory->home_uvec * (takeoff_speed + ((float)rand() / (float)D3_RAND_MAX) * speed_variance));
Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel);
// Play the takeoff anim and tell it to go to alert next
@ -6223,7 +6223,7 @@ void AlienBoss::DoInit(int me) {
memory->next_melee_attack_time = Game_GetTime();
// Set the next generic check time
memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)RAND_MAX) * 1.0f + 0.5f;
memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f + 0.5f;
// Init other times
memory->next_activity_time = Game_GetTime();
@ -6609,7 +6609,7 @@ void AlienBoss::DoFrame(int me) {
aSoundPlayObject(boss_see_id, me, 1.0f);
memory->next_special_attack_time =
Game_GetTime() + AB_SPECIAL_ATTACK_DELAY + ((float)rand() / (float)RAND_MAX) * AB_SPECIAL_ATTACK_VARIANCE;
Game_GetTime() + AB_SPECIAL_ATTACK_DELAY + ((float)rand() / (float)D3_RAND_MAX) * AB_SPECIAL_ATTACK_VARIANCE;
SetMode(me, AB_PREPARE_SPECIAL_ATTACK);
break;
@ -6657,7 +6657,7 @@ void AlienBoss::DoFrame(int me) {
// Wait until the melee attack time has expired
if (memory->mode_time > AB_MAX_MELEE_TIME) {
memory->next_melee_attack_time =
Game_GetTime() + AB_MELEE_ATTACK_DELAY + ((float)rand() / (float)RAND_MAX) * AB_MELEE_ATTACK_VARIANCE;
Game_GetTime() + AB_MELEE_ATTACK_DELAY + ((float)rand() / (float)D3_RAND_MAX) * AB_MELEE_ATTACK_VARIANCE;
SetMode(me, AB_ATTACKING);
break;
@ -6881,7 +6881,7 @@ void AlienBoss::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) {
memory->damage += (damage_data->damage * 0.7f);
if (Game_GetTime() >= memory->next_special_damage_time) {
memory->next_special_damage_time = Game_GetTime() + 0.8f + ((float)rand() / (float)RAND_MAX) * 0.5f;
memory->next_special_damage_time = Game_GetTime() + 0.8f + ((float)rand() / (float)D3_RAND_MAX) * 0.5f;
// Create a frag burst effect
vector pos;
@ -6899,7 +6899,7 @@ void AlienBoss::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) {
Game_GetTime() >= memory->next_special_damage_time) {
// Check if we're currently susceptible to energy damage
if (false) {
memory->next_special_damage_time = Game_GetTime() + 0.1f + ((float)rand() / (float)RAND_MAX) * 0.2f;
memory->next_special_damage_time = Game_GetTime() + 0.1f + ((float)rand() / (float)D3_RAND_MAX) * 0.2f;
// Do double damage
memory->damage += (damage_data->damage * 1.5f);
@ -6909,7 +6909,7 @@ void AlienBoss::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) {
vector pos;
Obj_Value(me, VF_GET, OBJV_V_POS, &pos);
Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room);
Game_CreateRandomSparks(30 + int(((float)rand() / (float)RAND_MAX) * 10.0f), &pos, room);
Game_CreateRandomSparks(30 + int(((float)rand() / (float)D3_RAND_MAX) * 10.0f), &pos, room);
return;
} else {

View File

@ -858,9 +858,9 @@ float vm_GetCentroidFast(vector *centroid, vector *src, int nv) {
// creates a completely random, non-normalized vector with a range of values from -1023 to +1024 values)
void vm_MakeRandomVector(vector *vec) {
vec->x = ps_rand() - RAND_MAX / 2;
vec->y = ps_rand() - RAND_MAX / 2;
vec->z = ps_rand() - RAND_MAX / 2;
vec->x = ps_rand() - D3_RAND_MAX / 2;
vec->y = ps_rand() - D3_RAND_MAX / 2;
vec->z = ps_rand() - D3_RAND_MAX / 2;
}
// Given a set of points, computes the minimum bounding sphere of those points