diff --git a/code/base_game/q_shared.h b/code/base_game/q_shared.h index 9d79505..9308dd1 100644 --- a/code/base_game/q_shared.h +++ b/code/base_game/q_shared.h @@ -594,9 +594,8 @@ void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out ); void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out ); int32_t Q_log2(int32_t val); -#undef random -inline auto random() { return ((rand () & 0x7fff) / ((float)0x7fff)); } -#define crandom() (2.0 * (random() - 0.5)) +#define qrandom() ((rand () & 0x7fff) / ((float)0x7fff)) +#define crandom() (2.0 * (qrandom() - 0.5)) float flrandom(float min, float max); int32_t irandom(int32_t min, int32_t max); diff --git a/code/common/Random.cpp b/code/common/Random.cpp index f246051..6689a9f 100644 --- a/code/common/Random.cpp +++ b/code/common/Random.cpp @@ -1,18 +1,18 @@ #include "Random.h" #include -TEST_CASE("random_int", "[common::random]") { +TEST_CASE("random_int", "[common::getRandom]") { for (auto x = 0; x < 1000; x++) { - auto i = common::random(); - auto a = common::random(); + auto i = common::getRandom(); + auto a = common::getRandom(); REQUIRE(i != a); } } -TEST_CASE("random_int_limit", "[common::random]") { +TEST_CASE("random_int_limit", "[common::getRandom]") { for (auto j = 0; j < 10; j++) { - auto min = common::random(); - auto max = common::random(); + auto min = common::getRandom(); + auto max = common::getRandom(); if (min > max) { std::swap(min, max); } @@ -25,25 +25,25 @@ TEST_CASE("random_int_limit", "[common::random]") { } for (auto x = 0; x < 100; x++) { - auto a = common::random(min, max); + auto a = common::getRandom(min, max); REQUIRE(a >= min); REQUIRE(a <= max); } } } -TEST_CASE("random_real", "[common::random]") { +TEST_CASE("random_real", "[common::getRandom]") { for (auto x = 0; x < 1000; x++) { - auto a = common::random(); - auto b = common::random(); + auto a = common::getRandom(); + auto b = common::getRandom(); REQUIRE(a != b); } } -TEST_CASE("random_real_limit", "[common::random]") { +TEST_CASE("random_real_limit", "[common::getRandom]") { for (auto j = 0; j < 10; j++) { - auto min = common::random(); - auto max = common::random(); + auto min = common::getRandom(); + auto max = common::getRandom(); if (min > max) { std::swap(min, max); } @@ -56,7 +56,7 @@ TEST_CASE("random_real_limit", "[common::random]") { } for (auto x = 0; x < 100; x++) { - auto a = common::random(min, max); + auto a = common::getRandom(min, max); REQUIRE(a >= min); REQUIRE(a <= max); } diff --git a/code/common/Random.h b/code/common/Random.h index f8fdc28..961df5d 100644 --- a/code/common/Random.h +++ b/code/common/Random.h @@ -5,7 +5,7 @@ namespace common { template >> -T random(T min = std::numeric_limits::min(), +T getRandom(T min = std::numeric_limits::min(), T max = std::numeric_limits::max()) { static auto seeder = std::random_device(); static auto engine = std::mt19937_64(seeder()); @@ -15,7 +15,7 @@ T random(T min = std::numeric_limits::min(), template && Dummy>> -T random(T min = std::numeric_limits::min(), +T getRandom(T min = std::numeric_limits::min(), T max = std::numeric_limits::max()) { static auto seeder = std::random_device(); static auto engine = std::mt19937_64(seeder()); diff --git a/code/common/Vector.cpp b/code/common/Vector.cpp index 31d5461..b004119 100644 --- a/code/common/Vector.cpp +++ b/code/common/Vector.cpp @@ -51,12 +51,12 @@ TEST_CASE("vector_dotproduct", "[common::Vector]") { REQUIRE(common::dotProduct({1, 5, 3}, {3, 2, 1}) == Approx(16.0f)); for (auto i = 0; i < 100; i++) { - auto v1 = common::Vector{common::random(-100000, 100000), - common::random(-100000, 100000), - common::random(-100000, 100000)}; - auto v2 = common::Vector{common::random(-100000, 100000), - common::random(-100000, 100000), - common::random(-100000, 100000)}; + auto v1 = common::Vector{common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000)}; + auto v2 = common::Vector{common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000)}; REQUIRE(common::dotProduct(v1, v2) == Approx(v1.x_ * v2.x_ + v1.y_ * v2.y_ + v1.z_ * v2.z_)); @@ -73,12 +73,12 @@ TEST_CASE("vector_substract", "[common::Vector}") { REQUIRE((common::Vector{2, 5, 4} - common::Vector{1, -2, 4}).z_ == 0.0f); for (auto i = 0; i < 100; i++) { - auto v1 = common::Vector{common::random(-100000, 100000), - common::random(-100000, 100000), - common::random(-100000, 100000)}; - auto v2 = common::Vector{common::random(-100000, 100000), - common::random(-100000, 100000), - common::random(-100000, 100000)}; + auto v1 = common::Vector{common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000)}; + auto v2 = common::Vector{common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000)}; auto res = v1 - v2; REQUIRE(res.x_ == v1.x_ - v2.x_); @@ -97,12 +97,12 @@ TEST_CASE("vector_add", "[common::Vector]") { REQUIRE((common::Vector{2, 5, 4} + common::Vector{1, -2, 4}).z_ == 8.0f); for (auto i = 0; i < 100; i++) { - auto v1 = common::Vector{common::random(-100000, 100000), - common::random(-100000, 100000), - common::random(-100000, 100000)}; - auto v2 = common::Vector{common::random(-100000, 100000), - common::random(-100000, 100000), - common::random(-100000, 100000)}; + auto v1 = common::Vector{common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000)}; + auto v2 = common::Vector{common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000), + common::getRandom(-100000, 100000)}; auto res = v1 + v2; REQUIRE(res.x_ == v1.x_ + v2.x_); diff --git a/code/game/ai_chat.cpp b/code/game/ai_chat.cpp index 302032b..2caab44 100644 --- a/code/game/ai_chat.cpp +++ b/code/game/ai_chat.cpp @@ -37,6 +37,7 @@ #include "match.h" //string matching types and vars // #include "g_syscalls.h" +#include "g_syscalls.h" /* @@ -280,7 +281,7 @@ static char* BotRandomOpponentName(bot_state_t* bs) { numopponents++; } - count = random() * numopponents; + count = qrandom() * numopponents; for (i = 0; i < numopponents; i++) { count--; @@ -357,7 +358,7 @@ BotRandomWeaponName ================== */ static const char* BotRandomWeaponName(void) { - int32_t rnd = random() * 8.9; + int32_t rnd = qrandom() * 8.9; switch (rnd) { case 0: return "Phaser"; @@ -500,7 +501,7 @@ int32_t BotChat_EnterGame(bot_state_t* bs) { } if (bot_fastchat.integer == 0) { - if (random() > rnd) { + if (qrandom() > rnd) { return qfalse; } } @@ -547,7 +548,7 @@ int32_t BotChat_ExitGame(bot_state_t* bs) { } if (bot_fastchat.integer == 0) { - if (random() > rnd) { + if (qrandom() > rnd) { return qfalse; } } @@ -596,7 +597,7 @@ int32_t BotChat_StartLevel(bot_state_t* bs) { } if (bot_fastchat.integer == 0) { - if (random() > rnd) { + if (qrandom() > rnd) { return qfalse; } } @@ -640,7 +641,7 @@ int32_t BotChat_EndLevel(bot_state_t* bs) { } if (bot_fastchat.integer == 0) { - if (random() > rnd) { + if (qrandom() > rnd) { return qfalse; } } @@ -699,7 +700,7 @@ int32_t BotChat_Death(bot_state_t* bs) { //if fast chatting is off if (bot_fastchat.integer == 0) { - if (random() > rnd) { + if (qrandom() > rnd) { return qfalse; } } @@ -747,7 +748,7 @@ int32_t BotChat_Death(bot_state_t* bs) { else if (bs->botdeathtype == MOD_TELEFRAG) { AI_main_BotAIInitialChat(bs, "death_telefrag", name, NULL); } else { - if (random() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_INSULT, 0, 1)) { + if (qrandom() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_INSULT, 0, 1)) { AI_main_BotAIInitialChat(bs, "death_insult", name, // 0 BotWeaponNameForMeansOfDeath(bs->botdeathtype), // 1 @@ -785,7 +786,7 @@ int32_t BotChat_Kill(bot_state_t* bs) { //if fast chat is off if (bot_fastchat.integer == 0) { - if (random() > rnd) { + if (qrandom() > rnd) { return qfalse; } } @@ -818,7 +819,7 @@ int32_t BotChat_Kill(bot_state_t* bs) { return qfalse; } else if (bs->enemydeathtype == MOD_TELEFRAG) { AI_main_BotAIInitialChat(bs, "kill_telefrag", name, NULL); - } else if (random() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_INSULT, 0, 1)) { //choose between insult and praise + } else if (qrandom() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_INSULT, 0, 1)) { //choose between insult and praise AI_main_BotAIInitialChat(bs, "kill_insult", name, NULL); } else { AI_main_BotAIInitialChat(bs, "kill_praise", name, NULL); @@ -857,7 +858,7 @@ int32_t BotChat_EnemySuicide(bot_state_t* bs) { //if fast chat is off if (bot_fastchat.integer == 0) { - if (random() > rnd) { + if (qrandom() > rnd) { return qfalse; } } @@ -924,7 +925,7 @@ int32_t BotChat_HitTalking(bot_state_t* bs) { //if fast chat is off if (bot_fastchat.integer == 0) { - if (random() > rnd * 0.5) { + if (qrandom() > rnd * 0.5) { return qfalse; } } @@ -985,7 +986,7 @@ int32_t BotChat_HitNoDeath(bot_state_t* bs) { //if fast chat is off if (bot_fastchat.integer == 0) { - if (random() > rnd * 0.5) { + if (qrandom() > rnd * 0.5) { return qfalse; } } @@ -1043,7 +1044,7 @@ int32_t BotChat_HitNoKill(bot_state_t* bs) { //if fast chat is off if (bot_fastchat.integer == 0) { - if (random() > rnd * 0.5) { + if (qrandom() > rnd * 0.5) { return qfalse; } } @@ -1102,16 +1103,16 @@ int32_t BotChat_Random(bot_state_t* bs) { return qfalse; } - if (random() > bs->thinktime * 0.1) { + if (qrandom() > bs->thinktime * 0.1) { return qfalse; } if (bot_fastchat.integer == 0) { - if (random() > rnd) { + if (qrandom() > rnd) { return qfalse; } - if (random() > 0.25) { + if (qrandom() > 0.25) { return qfalse; } } @@ -1130,7 +1131,7 @@ int32_t BotChat_Random(bot_state_t* bs) { EasyClientName(bs->lastkilledplayer, name, sizeof(name)); } - if (random() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_MISC, 0, 1)) { + if (qrandom() < trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_MISC, 0, 1)) { AI_main_BotAIInitialChat(bs, "random_misc", BotRandomOpponentName(bs), // 0 name, // 1 diff --git a/code/game/ai_cmd.cpp b/code/game/ai_cmd.cpp index 2557141..1aaefb4 100644 --- a/code/game/ai_cmd.cpp +++ b/code/game/ai_cmd.cpp @@ -422,7 +422,7 @@ static int32_t BotAddressedToBot(bot_state_t* bs, bot_match_t* match) { return qfalse; } else { //make sure not everyone reacts to this message - if (random() > (float) 1.0 / (NumPlayersOnSameTeam(bs) - 1)) { + if (qrandom() > (float) 1.0 / (NumPlayersOnSameTeam(bs) - 1)) { return qfalse; } } @@ -571,7 +571,7 @@ static void BotMatch_HelpAccompany(bot_state_t* bs, bot_match_t* match) { bs->teammatevisible_time = trap_AAS_Time(); //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //get the team goal time bs->teamgoal_time = BotGetTime(match); @@ -615,7 +615,7 @@ void BotMatch_DefendKeyArea(bot_state_t *bs, bot_match_t *match) { return; } //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //set the ltg type bs->ltgtype = LTG_DEFENDKEYAREA; //get the team goal time @@ -649,7 +649,7 @@ void BotMatch_GetItem(bot_state_t *bs, bot_match_t *match) { return; } //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //set the ltg type bs->ltgtype = LTG_GETITEM; //set the team goal time @@ -725,7 +725,7 @@ void BotMatch_Camp(bot_state_t *bs, bot_match_t *match) { return; } //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //set the ltg type bs->ltgtype = LTG_CAMPORDER; //get the team goal time @@ -754,7 +754,7 @@ void BotMatch_Patrol(bot_state_t *bs, bot_match_t *match) { //get the patrol waypoints if (!BotGetPatrolWaypoints(bs, match)) return; //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //set the ltg type bs->ltgtype = LTG_PATROL; //get the team goal time @@ -778,7 +778,7 @@ void BotMatch_GetFlag(bot_state_t *bs, bot_match_t *match) { //if not addressed to this bot if (!BotAddressedToBot(bs, match)) return; //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //set the ltg type bs->ltgtype = LTG_GETFLAG; //set the team goal time @@ -799,7 +799,7 @@ void BotMatch_RushBase(bot_state_t *bs, bot_match_t *match) { //if not addressed to this bot if (!BotAddressedToBot(bs, match)) return; //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //set the ltg type bs->ltgtype = LTG_RUSHBASE; //set the team goal time @@ -865,7 +865,7 @@ void BotMatch_ReturnFlag(bot_state_t *bs, bot_match_t *match) { //if not addressed to this bot if (!BotAddressedToBot(bs, match)) return; //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //set the ltg type bs->ltgtype = LTG_RETURNFLAG; //set the team goal time @@ -1347,7 +1347,7 @@ void BotMatch_LeadTheWay(bot_state_t *bs, bot_match_t *match) { bs->lead_teammate = client; bs->lead_time = trap_AAS_Time() + TEAM_LEAD_TIME; bs->leadvisible_time = 0; - bs->leadmessage_time = -(trap_AAS_Time() + 2 * random()); + bs->leadmessage_time = -(trap_AAS_Time() + 2 * qrandom()); } /* @@ -1373,7 +1373,7 @@ void BotMatch_Kill(bot_state_t *bs, bot_match_t *match) { } bs->teamgoal.entitynum = client; //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //set the ltg type bs->ltgtype = LTG_KILL; //set the team goal time diff --git a/code/game/ai_dmnet.cpp b/code/game/ai_dmnet.cpp index 53a3ae9..4a290e1 100644 --- a/code/game/ai_dmnet.cpp +++ b/code/game/ai_dmnet.cpp @@ -438,7 +438,7 @@ static int32_t AI_dmnet_BotGetLongTermGoal(bot_state_t* bs, int32_t tfl, int32_t //don't crouch if crouched less than 5 seconds ago if (bs->attackcrouch_time < trap_AAS_Time() - 5) { croucher = 1; - if (random() < bs->thinktime * croucher) { + if (qrandom() < bs->thinktime * croucher) { bs->attackcrouch_time = trap_AAS_Time() + 5 + croucher * 15; } } @@ -458,7 +458,7 @@ static int32_t AI_dmnet_BotGetLongTermGoal(bot_state_t* bs, int32_t tfl, int32_t bs->arrive_time = trap_AAS_Time(); } else if (bs->attackcrouch_time > trap_AAS_Time()) { //if the bot wants to crouch trap_EA_Crouch(bs->client); - } else if (random() < bs->thinktime * 0.3) { //else do some model taunts + } else if (qrandom() < bs->thinktime * 0.3) { //else do some model taunts //do a gesture :) trap_EA_Gesture(bs->client); } @@ -469,7 +469,7 @@ static int32_t AI_dmnet_BotGetLongTermGoal(bot_state_t* bs, int32_t tfl, int32_t VectorSubtract(entinfo.origin, bs->origin, dir); vectoangles(dir, bs->ideal_viewangles); bs->ideal_viewangles[2] *= 0.5; - } else if (random() < bs->thinktime * 0.8) { //else look strategically around for enemies + } else if (qrandom() < bs->thinktime * 0.8) { //else look strategically around for enemies BotRoamGoal(bs, target); VectorSubtract(target, bs->origin, dir); vectoangles(dir, bs->ideal_viewangles); @@ -550,7 +550,7 @@ static int32_t AI_dmnet_BotGetLongTermGoal(bot_state_t* bs, int32_t tfl, int32_t VectorSubtract(goal->origin, bs->origin, dir); if (VectorLength(dir) < 70) { trap_BotResetAvoidReach(bs->ms); - bs->defendaway_time = trap_AAS_Time() + 2 + 5 * random(); + bs->defendaway_time = trap_AAS_Time() + 2 + 5 * qrandom(); bs->defendaway_range = 250; } return qtrue; @@ -650,7 +650,7 @@ static int32_t AI_dmnet_BotGetLongTermGoal(bot_state_t* bs, int32_t tfl, int32_t } //look strategically around for enemies - if (random() < bs->thinktime * 0.8) { + if (qrandom() < bs->thinktime * 0.8) { BotRoamGoal(bs, target); VectorSubtract(target, bs->origin, dir); vectoangles(dir, bs->ideal_viewangles); @@ -661,7 +661,7 @@ static int32_t AI_dmnet_BotGetLongTermGoal(bot_state_t* bs, int32_t tfl, int32_t //don't crouch if crouched less than 5 seconds ago if (bs->attackcrouch_time < trap_AAS_Time() - 5) { croucher = 1; - if (random() < bs->thinktime * croucher) { + if (qrandom() < bs->thinktime * croucher) { bs->attackcrouch_time = trap_AAS_Time() + 5 + croucher * 15; } } @@ -821,7 +821,7 @@ static int32_t AI_dmnet_BotGetLongTermGoal(bot_state_t* bs, int32_t tfl, int32_t //base flag is gone, now just walk near the base a bit if (BotCTFCarryingFlag(bs) != 0) { trap_BotResetAvoidReach(bs->ms); - bs->rushbaseaway_time = trap_AAS_Time() + 5 + 10 * random(); + bs->rushbaseaway_time = trap_AAS_Time() + 5 + 10 * qrandom(); //FIXME: add chat to tell the others to get back the flag //FIXME: Make them camp? Get health? Preserve themselves? } else { @@ -1142,7 +1142,7 @@ static void AI_dmnet_AIEnter_Respawn(bot_state_t* bs) { bs->respawn_time = trap_AAS_Time() + BotChatTime(bs); bs->respawnchat_time = trap_AAS_Time(); } else { - bs->respawn_time = trap_AAS_Time() + 1 + random(); + bs->respawn_time = trap_AAS_Time() + 1 + qrandom(); bs->respawnchat_time = 0; } @@ -1234,7 +1234,7 @@ static int32_t AI_dmnet_AINode_Seek_ActivateEntity(bot_state_t* bs) { if ((moveresult.flags & (MOVERESULT_MOVEMENTVIEWSET | MOVERESULT_MOVEMENTVIEW | MOVERESULT_SWIMVIEW)) != 0) { VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); } else if (moveresult.flags & MOVERESULT_WAITING) { //if waiting for something - if (random() < bs->thinktime * 0.8) { + if (qrandom() < bs->thinktime * 0.8) { BotRoamGoal(bs, target); VectorSubtract(target, bs->origin, dir); vectoangles(dir, bs->ideal_viewangles); @@ -1392,7 +1392,7 @@ int32_t AI_dmnat_AINode_Seek_NBG(bot_state_t* bs) { if ((moveresult.flags & (MOVERESULT_MOVEMENTVIEWSET|MOVERESULT_MOVEMENTVIEW|MOVERESULT_SWIMVIEW)) != 0) { VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); } else if ((moveresult.flags & MOVERESULT_WAITING) != 0) { //if waiting for something - if (random() < bs->thinktime * 0.8) { + if (qrandom() < bs->thinktime * 0.8) { BotRoamGoal(bs, target); VectorSubtract(target, bs->origin, dir); vectoangles(dir, bs->ideal_viewangles); @@ -1493,7 +1493,7 @@ int32_t AI_dmnet_AINode_Seek_LTG(bot_state_t* bs) { bs->enemy = -1; if (bs->killedenemy_time > trap_AAS_Time() - 2) { - if (random() < bs->thinktime * 1) { + if (qrandom() < bs->thinktime * 1) { trap_EA_Gesture(bs->client); } } @@ -1580,7 +1580,7 @@ int32_t AI_dmnet_AINode_Seek_LTG(bot_state_t* bs) { if ((moveresult.flags & (MOVERESULT_MOVEMENTVIEWSET | MOVERESULT_MOVEMENTVIEW | MOVERESULT_SWIMVIEW)) != 0) { VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); } else if ((moveresult.flags & MOVERESULT_WAITING) != 0) { //if waiting for something - if (random() < bs->thinktime * 0.8) { + if (qrandom() < bs->thinktime * 0.8) { BotRoamGoal(bs, target); VectorSubtract(target, bs->origin, dir); vectoangles(dir, bs->ideal_viewangles); @@ -1592,7 +1592,7 @@ int32_t AI_dmnet_AINode_Seek_LTG(bot_state_t* bs) { vectoangles(dir, bs->ideal_viewangles); } else if (VectorLength(moveresult.movedir)) { //FIXME: look at cluster portals? vectoangles(moveresult.movedir, bs->ideal_viewangles); - } else if (random() < bs->thinktime * 0.8) { + } else if (qrandom() < bs->thinktime * 0.8) { BotRoamGoal(bs, target); VectorSubtract(target, bs->origin, dir); vectoangles(dir, bs->ideal_viewangles); @@ -1729,7 +1729,7 @@ static int32_t AI_dmnet_AINode_Battle_Fight(bot_state_t* bs) { //if the enemy is invisible and not shooting the bot looses track easily if (EntityIsInvisible(&entinfo) && !EntityIsShooting(&entinfo)) { - if (random() < 0.2) { + if (qrandom() < 0.2) { AI_dmnet_AIEnter_Seek_LTG(bs); return qfalse; } diff --git a/code/game/ai_dmq3.cpp b/code/game/ai_dmq3.cpp index 78a887f..0c22d3b 100644 --- a/code/game/ai_dmq3.cpp +++ b/code/game/ai_dmq3.cpp @@ -255,7 +255,7 @@ void BotCTFSeekGoals(bot_state_t *bs) { //last time the team mate was visible bs->teammatevisible_time = trap_AAS_Time(); //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //get the team goal time bs->teamgoal_time = trap_AAS_Time() + TEAM_ACCOMPANY_TIME; bs->ltgtype = LTG_TEAMACCOMPANY; @@ -315,9 +315,9 @@ void BotCTFSeekGoals(bot_state_t *bs) { //if the bot has anough aggression to decide what to do if (BotAggression(bs) < 50) return; //set the time to send a message to the team mates - bs->teammessage_time = trap_AAS_Time() + 2 * random(); + bs->teammessage_time = trap_AAS_Time() + 2 * qrandom(); //get the flag or defend the base - rnd = random(); + rnd = qrandom(); if (rnd < 0.33 && ctf_redflag.areanum && ctf_blueflag.areanum) { bs->ltgtype = LTG_GETFLAG; //set the time the bot will stop getting the flag @@ -1068,7 +1068,7 @@ void BotGoCamp(bot_state_t *bs, bot_goal_t *goal) { //get the team goal time camper = 0; if (camper > 0.99) bs->teamgoal_time = 99999; - else bs->teamgoal_time = 120 + 180 * camper + random() * 15; + else bs->teamgoal_time = 120 + 180 * camper + qrandom() * 15; //set the last time the bot started camping bs->camp_time = trap_AAS_Time(); //the teammate that requested the camping @@ -1136,19 +1136,19 @@ void BotRoamGoal(bot_state_t *bs, vec3_t goal) { for (i = 0; i < 10; i++) { //start at the bot origin VectorCopy(bs->origin, bestorg); - rnd = random(); + rnd = qrandom(); if (rnd > 0.25) { //add a random value to the x-coordinate - if (random() < 0.5) bestorg[0] -= 800 * random() + 100; - else bestorg[0] += 800 * random() + 100; + if (qrandom() < 0.5) bestorg[0] -= 800 * qrandom() + 100; + else bestorg[0] += 800 * qrandom() + 100; } if (rnd < 0.75) { //add a random value to the y-coordinate - if (random() < 0.5) bestorg[1] -= 800 * random() + 100; - else bestorg[1] += 800 * random() + 100; + if (qrandom() < 0.5) bestorg[1] -= 800 * qrandom() + 100; + else bestorg[1] += 800 * qrandom() + 100; } //add a random value to the z-coordinate (NOTE: 48 = maxjump?) - bestorg[2] += 2 * 48 * crandom(); + bestorg[2] += 2 * 48 * cqrandom(); //trace a line from the origin to the roam target AI_main_BotAITrace(&trace, bs->origin, NULL, NULL, bestorg, bs->entitynum, MASK_SOLID); //direction and length towards the roam target @@ -1224,11 +1224,11 @@ bot_moveresult_t BotAttackMove(bot_state_t *bs, int tfl) { movetype = MOVE_WALK; // if (bs->attackcrouch_time < trap_AAS_Time() - 1) { - if (random() < jumper) { + if (qrandom() < jumper) { movetype = MOVE_JUMP; } //wait at least one second before crouching again - else if (bs->attackcrouch_time < trap_AAS_Time() - 1 && random() < croucher) { + else if (bs->attackcrouch_time < trap_AAS_Time() - 1 && qrandom() < croucher) { bs->attackcrouch_time = trap_AAS_Time() + croucher * 5; } } @@ -1260,11 +1260,11 @@ bot_moveresult_t BotAttackMove(bot_state_t *bs, int tfl) { bs->attackstrafe_time += bs->thinktime; //get the strafe change time strafechange_time = 0.4 + (1 - attack_skill) * 0.2; - if (attack_skill > 0.7) strafechange_time += crandom() * 0.2; + if (attack_skill > 0.7) strafechange_time += cqrandom() * 0.2; //if the strafe direction should be changed if (bs->attackstrafe_time > strafechange_time) { //some magic number :) - if (random() > 0.935) { + if (qrandom() > 0.935) { //flip the strafe direction bs->flags ^= BFL_STRAFERIGHT; bs->attackstrafe_time = 0; @@ -1281,7 +1281,7 @@ bot_moveresult_t BotAttackMove(bot_state_t *bs, int tfl) { //reverse the vector depending on the strafe direction if (bs->flags & BFL_STRAFERIGHT) VectorNegate(sideward, sideward); //randomly go back a little - if (random() > 0.9) { + if (qrandom() > 0.9) { VectorAdd(sideward, backward, sideward); } else { @@ -1681,7 +1681,7 @@ void BotAimAtEnemy(bot_state_t *bs) { AI_main_BotEntityInfo(bs->enemy, &entinfo); //if the enemy is invisible then shoot crappy most of the time if (EntityIsInvisible(&entinfo)) { - if (random() > 0.1) aim_accuracy *= 0.4; + if (qrandom() > 0.1) aim_accuracy *= 0.4; } // VectorSubtract(entinfo.origin, entinfo.lastvisorigin, enemyvelocity); @@ -1808,9 +1808,9 @@ void BotAimAtEnemy(bot_state_t *bs) { } } } - bestorigin[0] += 20 * crandom() * (1 - aim_accuracy); - bestorigin[1] += 20 * crandom() * (1 - aim_accuracy); - bestorigin[2] += 10 * crandom() * (1 - aim_accuracy); + bestorigin[0] += 20 * cqrandom() * (1 - aim_accuracy); + bestorigin[1] += 20 * cqrandom() * (1 - aim_accuracy); + bestorigin[2] += 10 * cqrandom() * (1 - aim_accuracy); } else { // @@ -1865,14 +1865,14 @@ void BotAimAtEnemy(bot_state_t *bs) { int i; VectorNormalize(dir); - for (i = 0; i < 3; i++) dir[i] += 0.3 * crandom() * (1 - aim_accuracy); + for (i = 0; i < 3; i++) dir[i] += 0.3 * cqrandom() * (1 - aim_accuracy); } //set the ideal view angles vectoangles(dir, bs->ideal_viewangles); //take the weapon spread into account for lower skilled bots - bs->ideal_viewangles[PITCH] += 6 * wi.vspread * crandom() * (1 - aim_accuracy); + bs->ideal_viewangles[PITCH] += 6 * wi.vspread * cqrandom() * (1 - aim_accuracy); bs->ideal_viewangles[PITCH] = AngleMod(bs->ideal_viewangles[PITCH]); - bs->ideal_viewangles[YAW] += 6 * wi.hspread * crandom() * (1 - aim_accuracy); + bs->ideal_viewangles[YAW] += 6 * wi.hspread * cqrandom() * (1 - aim_accuracy); bs->ideal_viewangles[YAW] = AngleMod(bs->ideal_viewangles[YAW]); //if the bots should be really challenging //if the bot is really accurate and has the enemy in view for some time @@ -1914,7 +1914,7 @@ void BotCheckAttack(bot_state_t *bs) { if (bs->firethrottlewait_time > trap_AAS_Time()) return; firethrottle = 1; if (bs->firethrottleshoot_time < trap_AAS_Time()) { - if (random() > firethrottle) { + if (qrandom() > firethrottle) { bs->firethrottlewait_time = trap_AAS_Time() + firethrottle; bs->firethrottleshoot_time = 0; } @@ -1967,7 +1967,7 @@ void BotCheckAttack(bot_state_t *bs) { float points = (wi.proj.damage - 0.5 * trace.fraction * 1000) * 0.5; if (points > 0) { // selfpreservation = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_SELFPRESERVATION, 0, 1); -// if (random() < selfpreservation) return; +// if (qrandom() < selfpreservation) return; return; } } @@ -2068,9 +2068,9 @@ void BotMapScripts(bot_state_t *bs) { bs->flags |= BFL_IDEALVIEWSET; VectorSubtract(buttonorg, bs->eye, dir); vectoangles(dir, bs->ideal_viewangles); - bs->ideal_viewangles[PITCH] += 8 * crandom() * (1 - aim_accuracy); + bs->ideal_viewangles[PITCH] += 8 * cqrandom() * (1 - aim_accuracy); bs->ideal_viewangles[PITCH] = AngleMod(bs->ideal_viewangles[PITCH]); - bs->ideal_viewangles[YAW] += 8 * crandom() * (1 - aim_accuracy); + bs->ideal_viewangles[YAW] += 8 * cqrandom() * (1 - aim_accuracy); bs->ideal_viewangles[YAW] = AngleMod(bs->ideal_viewangles[YAW]); // if (InFieldOfVision(bs->viewangles, 20, bs->ideal_viewangles)) @@ -2408,7 +2408,7 @@ void BotAIBlocked(bot_state_t *bs, bot_moveresult_t *moveresult, int activate) { hordir[2] = 0; //if no direction just take a random direction if (VectorNormalize(hordir) < 0.1) { - VectorSet(angles, 0, 360 * random(), 0); + VectorSet(angles, 0, 360 * qrandom(), 0); AngleVectors(angles, hordir, NULL, NULL); } // @@ -2469,7 +2469,7 @@ void BotCheckConsoleMessages(bot_state_t *bs) { //if the chat state is flooded with messages the bot will read them quickly if (trap_BotNumConsoleMessages(bs->cs) < 10) { //if it is a chat message the bot needs some time to read it - if (m.type == CMS_CHAT && m.time > trap_AAS_Time() - (1 + random())) break; + if (m.type == CMS_CHAT && m.time > trap_AAS_Time() - (1 + qrandom())) break; } // ptr = m.message; @@ -2532,7 +2532,7 @@ void BotCheckConsoleMessages(bot_state_t *bs) { //if at a valid chat position and not chatting already else if (bs->ainode != AI_dmnet_AINode_Stand && BotValidChatPosition(bs)) { chat_reply = 0; - if (random() < 1.5 / (AI_main_NumBots()+1) && random() < chat_reply) { + if (qrandom() < 1.5 / (AI_main_NumBots()+1) && qrandom() < chat_reply) { //if bot replies with a chat message if (trap_BotReplyChat(bs->cs, message, context, CONTEXT_REPLY, NULL, NULL, diff --git a/code/game/ai_team.cpp b/code/game/ai_team.cpp index d6f3d67..fb11a7a 100644 --- a/code/game/ai_team.cpp +++ b/code/game/ai_team.cpp @@ -576,10 +576,10 @@ void BotTeamAI(bot_state_t *bs) { // if (!bs->askteamleader_time && !bs->becometeamleader_time) { if (bs->entergame_time + 10 > trap_AAS_Time()) { - bs->askteamleader_time = trap_AAS_Time() + 5 + random() * 10; + bs->askteamleader_time = trap_AAS_Time() + 5 + qrandom() * 10; } else { - bs->becometeamleader_time = trap_AAS_Time() + 5 + random() * 10; + bs->becometeamleader_time = trap_AAS_Time() + 5 + qrandom() * 10; } } if (bs->askteamleader_time && bs->askteamleader_time < trap_AAS_Time()) { @@ -587,7 +587,7 @@ void BotTeamAI(bot_state_t *bs) { AI_main_BotAIInitialChat(bs, "whoisteamleader", NULL); trap_BotEnterChat(bs->cs, bs->client, CHAT_TEAM); bs->askteamleader_time = 0; - bs->becometeamleader_time = trap_AAS_Time() + 15 + random() * 10; + bs->becometeamleader_time = trap_AAS_Time() + 15 + qrandom() * 10; } if (bs->becometeamleader_time && bs->becometeamleader_time < trap_AAS_Time()) { AI_main_BotAIInitialChat(bs, "iamteamleader", NULL); @@ -640,7 +640,7 @@ void BotTeamAI(bot_state_t *bs) { if (bs->lastflagcapture_time < trap_AAS_Time() - 240) { bs->lastflagcapture_time = trap_AAS_Time(); //randomly change the CTF strategy - if (random() < 0.4) { + if (qrandom() < 0.4) { bs->ctfstrategy ^= CTFS_PASSIVE; bs->teamgiveorders_time = trap_AAS_Time(); } diff --git a/code/game/g_bot.cpp b/code/game/g_bot.cpp index b568c36..05f5297 100644 --- a/code/game/g_bot.cpp +++ b/code/game/g_bot.cpp @@ -256,7 +256,7 @@ void G_AddRandomBot(int32_t team) { num++; } } - num = random() * num; + num = qrandom() * num; for (n = 0; n < g_numBots; n++) { value = Info_ValueForKey(g_botInfos[n], "name"); // diff --git a/code/game/g_fx.cpp b/code/game/g_fx.cpp index 4334024..93bdc79 100644 --- a/code/game/g_fx.cpp +++ b/code/game/g_fx.cpp @@ -1546,7 +1546,7 @@ static const uint8_t ELEC_FIRE_STARTOFF = 1; static void electric_fire_think(gentity_t *ent) { G_AddEvent(ent, EV_FX_ELECFIRE, 0); - ent->nextthink = level.time + (750 + (random() * 300)); + ent->nextthink = level.time + (750 + (qrandom() * 300)); } //------------------------------------------ @@ -1638,7 +1638,7 @@ enum fx_forgeBoltSpawnflags_e { static void forge_bolt_think(gentity_t *ent) { G_AddEvent(ent, EV_FX_FORGE_BOLT, ent->spawnflags & FORGE_BOLT_DELAYED); - ent->nextthink = (int)(level.time + (ent->wait + crandom() * ent->wait * 0.25) * 1000); + ent->nextthink = (int)(level.time + (ent->wait + cqrandom() * ent->wait * 0.25) * 1000); // If a fool gets in the bolt path, zap 'em if (ent->damage != 0) @@ -2445,7 +2445,7 @@ static void borg_bolt_think(gentity_t *ent) { if ((ent->spawnflags & BORG_BOLT_FX_NO_PROXIMITY_FX) != 0) { G_AddEvent(ent, EV_FX_BORG_BOLT, 0); - ent->nextthink = level.time + 100 + random() * 25; + ent->nextthink = level.time + 100 + qrandom() * 25; } else { G_AddEvent(ent, EV_FX_BORG_BOLT, 1); diff --git a/code/game/lua_qmath.c b/code/game/lua_qmath.c index 5c01974..86f8f96 100644 --- a/code/game/lua_qmath.c +++ b/code/game/lua_qmath.c @@ -340,7 +340,7 @@ Get a random floating point number. */ static int Qmath_Random(lua_State * L) { - lua_pushnumber(L, random()); + lua_pushnumber(L, qrandom()); return 1; } @@ -351,7 +351,7 @@ Get a random floating point number (using crazy random function). */ static int Qmath_Crandom(lua_State * L) { - lua_pushnumber(L, crandom()); + lua_pushnumber(L, cqrandom()); return 1; } diff --git a/code/ui/ui_menu.cpp b/code/ui/ui_menu.cpp index a80b984..03e0a3b 100644 --- a/code/ui/ui_menu.cpp +++ b/code/ui/ui_menu.cpp @@ -2664,20 +2664,20 @@ static void Quit_MenuBlinkies(void) for (i = 0; i < 5; ++i) { - quitmenu_graphics[i + QMG_COL1_NUM1].target = (random() * (900000000)) + 99999999; - quitmenu_graphics[i + QMG_COL3_NUM1].target = (random() * (900000000)) + 99999999; - quitmenu_graphics[i + QMG_COL4_NUM1].target = (random() * (900000000)) + 99999999; + quitmenu_graphics[i + QMG_COL1_NUM1].target = (qrandom() * (900000000)) + 99999999; + quitmenu_graphics[i + QMG_COL3_NUM1].target = (qrandom() * (900000000)) + 99999999; + quitmenu_graphics[i + QMG_COL4_NUM1].target = (qrandom() * (900000000)) + 99999999; } for (i = 0; i < 5; ++i) { - quitmenu_graphics[i + QMG_COL2_NUM1].target = (random() * (900000)) + 99999; + quitmenu_graphics[i + QMG_COL2_NUM1].target = (qrandom() * (900000)) + 99999; } for (i = 0; i < 5; ++i) { - quitmenu_graphics[i + QMG_COL5_NUM1].target = (random() * (90)) + 9; - quitmenu_graphics[i + QMG_COL6_NUM1].target = (random() * (90)) + 9; + quitmenu_graphics[i + QMG_COL5_NUM1].target = (qrandom() * (90)) + 9; + quitmenu_graphics[i + QMG_COL6_NUM1].target = (qrandom() * (90)) + 9; } quitmenu_graphics[QMG_NUMBERS].target = 1;