Commit 7415ded9 authored by TimePath's avatar TimePath

Replace usages of mod() with the operator %

parent ef699c7a
......@@ -3118,7 +3118,7 @@ void HUD_Mod_NexBall(vector pos, vector mySize)
//Manage the progress bar if any
if (nb_pb_starttime > 0)
{
dt = mod(time - nb_pb_starttime, nb_pb_period);
dt = (time - nb_pb_starttime) % nb_pb_period;
// one period of positive triangle
p = 2 * dt / nb_pb_period;
if (p > 1)
......@@ -3762,7 +3762,7 @@ void HUD_InfoMessages(void)
}
string blinkcolor;
if(mod(time, 1) >= 0.5)
if(time % 1 >= 0.5)
blinkcolor = "^1";
else
blinkcolor = "^3";
......@@ -4563,7 +4563,7 @@ void HUD_Main (void)
}
else if(hud_dock_color == "pants") {
f = stof(getplayerkeyvalue(current_player - 1, "colors"));
color = colormapPaletteColor(mod(f, 16), 1);
color = colormapPaletteColor(f % 16, 1);
}
else
color = stov(hud_dock_color);
......
......@@ -189,7 +189,7 @@ if((teamplay) && panel_bg_color_team) {\
if(panel_bg_color_str == "shirt") {\
panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player - 1, "colors")) / 16), 0);\
} else if(panel_bg_color_str == "pants") {\
panel_bg_color = colormapPaletteColor(mod(stof(getplayerkeyvalue(current_player - 1, "colors")), 16), 1);\
panel_bg_color = colormapPaletteColor(stof(getplayerkeyvalue(current_player - 1, "colors")) % 16, 1);\
} else {\
panel_bg_color = stov(panel_bg_color_str);\
}\
......
......@@ -810,13 +810,13 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
}
if (!tab_backward)
{
level = mod(level + level_height, vid_conheight);
level = (level + level_height) % vid_conheight;
start_pos_x = 0;
candidate_pos_x = vid_conwidth;
}
else
{
level = mod(level - level_height, vid_conheight);
level = (level - level_height) % vid_conheight;
start_pos_x = vid_conwidth;
candidate_pos_x = 0;
}
......
......@@ -234,7 +234,7 @@ void MapVote_DrawAbstain(vector pos, float isize, float tsize, float count, floa
vector MapVote_GridVec(vector gridspec, float i, float m)
{
float r;
r = mod(i, m);
r = i % m;
return
'1 0 0' * (gridspec_x * r)
+
......
......@@ -555,7 +555,7 @@ string HUD_GetField(entity pl, float field)
hud_field_icon1 = "gfx/scoreboard/playercolor_shirt";
hud_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
hud_field_icon2 = "gfx/scoreboard/playercolor_pants";
hud_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);
hud_field_icon2_rgb = colormapPaletteColor(f % 16, 1);
}
}
return GetPlayerName(pl.sv_entnum);
......@@ -695,7 +695,7 @@ void HUD_PrintScoreboardItem(vector pos, vector item_size, entity pl, float is_s
// alternated rows highlighting
if(is_self)
drawfill(h_pos, h_size, rgb, scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);
else if((scoreboard_highlight) && (!mod(pl_number,2)))
else if((scoreboard_highlight) && (!(pl_number % 2)))
drawfill(h_pos, h_size, rgb, scoreboard_highlight_alpha, DRAWFLAG_NORMAL);
tmp_x = item_size_x;
......@@ -874,7 +874,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
column_dim_x = hud_size[i] + hud_fontsize_x;
if (scoreboard_highlight)
{
if (mod(i,2))
if (i % 2)
drawfill(pos - '0 1 0' - hud_fontsize_x / 2 * '1 0 0', column_dim, '0 0 0', scoreboard_alpha_bg * 0.2, DRAWFLAG_NORMAL);
}
drawstring(pos, hud_title[i], hud_fontsize, rgb * 1.5, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
......@@ -893,7 +893,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
if (scoreboard_highlight)
{
if (!mod(i,2))
if (!(i % 2))
{
if (i == hud_num_fields-1)
column_dim_x = hud_size[i] + hud_fontsize_x / 2 + 1;
......@@ -994,7 +994,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
// column highlighting
for(i = 0; i < weapon_cnt/rows; ++i)
{
if(!mod(i, 2))
if(!(i % 2))
drawfill(pos + '1 0 0' * weapon_width * rows * i, '0 1 0' * height * rows + '1 0 0' * weapon_width * rows, '0 0 0', scoreboard_alpha_bg * 0.2, DRAWFLAG_NORMAL);
}
......@@ -1185,7 +1185,7 @@ vector HUD_DrawScoreboardRankings(vector pos, entity pl, vector rgb, vector bg_
p = count_ordinal(i+1);
if(grecordholder[i] == GetPlayerName(player_localnum))
drawfill(pos, '1 0 0' * sbwidth + '0 1.25 0' * hud_fontsize_y, hl_rgb, scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);
else if(!mod(i, 2) && scoreboard_highlight)
else if(!(i % 2) && scoreboard_highlight)
drawfill(pos, '1 0 0' * sbwidth + '0 1.25 0' * hud_fontsize_y, hl_rgb, scoreboard_highlight_alpha, DRAWFLAG_NORMAL);
drawstring(pos, p, '1 1 0' * hud_fontsize_y, '1 1 1', scoreboard_alpha_fg, DRAWFLAG_NORMAL);
drawstring(pos + '3 0 0' * hud_fontsize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * hud_fontsize_y, '1 1 1', scoreboard_alpha_fg, DRAWFLAG_NORMAL);
......
......@@ -30,7 +30,7 @@ void tubasound(entity e, float restart)
f2 = 0;
p2 = 1;
m = mod(e.note, Tuba_PitchStep);
m = e.note % Tuba_PitchStep;
if(m)
{
if(e.note - m < TUBA_MIN)
......@@ -190,7 +190,7 @@ void Tuba_Precache()
}
for(n = TUBA_MIN; n <= TUBA_MAX; ++n)
{
if(!Tuba_PitchStep || (mod(n, Tuba_PitchStep) == 0))
if(!Tuba_PitchStep || ((n % Tuba_PitchStep) == 0))
{
for(i = 0; i < TUBA_INSTRUMENTS; ++i)
precache_sound(TUBA_STARTNOTE(i, n));
......
......@@ -701,7 +701,7 @@ void Ent_WaypointSprite()
if(f & 0x80)
{
self.(teamradar_times[self.teamradar_time_index]) = time;
self.teamradar_time_index = mod(self.teamradar_time_index + 1, MAX_TEAMRADAR_TIMES);
self.teamradar_time_index = (self.teamradar_time_index + 1) % MAX_TEAMRADAR_TIMES;
}
self.teamradar_color_x = ReadByte() / 255.0;
self.teamradar_color_y = ReadByte() / 255.0;
......
......@@ -153,7 +153,7 @@ void GenericCommand_qc_curl(float request, float argc)
{
curl_uri_get_exec[curl_uri_get_pos] = do_exec;
curl_uri_get_cvar[curl_uri_get_pos] = do_cvar;
curl_uri_get_pos = mod(curl_uri_get_pos + 1, URI_GET_CURL_END - URI_GET_CURL + 1);
curl_uri_get_pos = (curl_uri_get_pos + 1) % (URI_GET_CURL_END - URI_GET_CURL + 1);
}
else
print(_("error creating curl handle\n"));
......
......@@ -60,10 +60,10 @@ string count_ordinal(float interval)
// Basically, it just allows you to represent a number or count in different ways
// depending on the number... like, with count_ordinal you can provide integers
// and retrieve 1st, 2nd, 3rd, nth ordinal numbers in a clean and simple way.
if(floor((mod(interval, 100))/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
if(floor((interval % 100)/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
{
// otherwise, check normally for 1st,2nd,3rd insertions
switch(mod(interval, 10))
switch(interval % 10)
{
case 1: return sprintf(_("%dst"), interval);
case 2: return sprintf(_("%dnd"), interval);
......
......@@ -159,7 +159,7 @@ void url_single_fopen(string url, float mode, url_ready_func rdy, entity pass)
url_fromid[i] = e;
// make sure this slot won't be reused quickly even on map change
cvar_set("_urllib_nextslot", ftos(mod(i + 1, NUM_URL_ID)));
cvar_set("_urllib_nextslot", ftos((i + 1) % NUM_URL_ID));
break;
}
}
......@@ -262,7 +262,7 @@ void url_fclose(entity e)
url_fromid[i] = e;
// make sure this slot won't be reused quickly even on map change
cvar_set("_urllib_nextslot", ftos(mod(i + 1, NUM_URL_ID)));
cvar_set("_urllib_nextslot", ftos((i + 1) % NUM_URL_ID));
}
else
{
......
......@@ -346,14 +346,14 @@ void db_close(float db)
string db_get(float db, string pKey)
{
float h;
h = mod(crc16(FALSE, pKey), DB_BUCKETS);
h = crc16(FALSE, pKey) % DB_BUCKETS;
return uri_unescape(infoget(bufstr_get(db, h), pKey));
}
void db_put(float db, string pKey, string pValue)
{
float h;
h = mod(crc16(FALSE, pKey), DB_BUCKETS);
h = crc16(FALSE, pKey) % DB_BUCKETS;
bufstr_set(db, h, infoadd(bufstr_get(db, h), pKey, uri_escape(pValue)));
}
......@@ -2261,10 +2261,10 @@ const string XENCODE_22 = "0123456789abcdefABCDEF";
string xencode(float f)
{
float a, b, c, d;
d = mod(f, 22); f = floor(f / 22);
c = mod(f, 22); f = floor(f / 22);
b = mod(f, 22); f = floor(f / 22);
a = mod(f, 2); // f = floor(f / 2);
d = f % 22; f = floor(f / 22);
c = f % 22; f = floor(f / 22);
b = f % 22; f = floor(f / 22);
a = f % 2; // f = floor(f / 2);
return strcat(
"^",
substring(XENCODE_2, a, 1),
......
......@@ -98,11 +98,6 @@ void db_put(float db, string key, string value);
float buf_load(string filename);
void buf_save(float buf, string filename);
// modulo function
#ifndef MENUQC
float mod(float a, float b) { return a - (floor(a / b) * b); }
#endif
#define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.4)
string format_time(float seconds);
string mmsss(float t);
......
......@@ -298,7 +298,7 @@ void W_Fireball_Attack2(void)
vector f_diff;
float c;
c = mod(self.bulletcounter, 4);
c = self.bulletcounter % 4;
switch(c)
{
case 0:
......
......@@ -323,7 +323,7 @@ void W_Seeker_Fire_Flac(void)
W_DecreaseAmmo(WEP_CVAR(seeker, flac_ammo));
c = mod(self.bulletcounter, 4);
c = self.bulletcounter % 4;
switch(c)
{
case 0:
......@@ -430,7 +430,7 @@ void W_Seeker_Vollycontroller_Think(void) // TODO: Merge this with W_Seeker_Atta
oldenemy = self.enemy;
self.enemy = oldself.enemy;
c = mod(self.cnt, 4);
c = self.cnt % 4;
switch(c)
{
case 0:
......
......@@ -71,7 +71,7 @@ float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorep
nolength = FALSE;
for(i = 0; i < n; ++i)
{
vector v = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
vector v = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
float ai = stof(argv(n - i - 1));
float np = floor(ai);
if(ai == np)
......@@ -108,13 +108,13 @@ float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorep
for(i = 0; i < n; ++i)
{
vector vi = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
vector vi = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
float ai = stof(argv(n - i - 1));
ti -= 1 / (ai - floor(ai));
float tj = ti;
for(j = i+1; j < n; ++j)
{
vector vj = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - j + MAX_TUBANOTES, MAX_TUBANOTES)]);
vector vj = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - j + MAX_TUBANOTES) % MAX_TUBANOTES]);
float aj = stof(argv(n - j - 1));
tj -= (aj - floor(aj));
......@@ -154,7 +154,7 @@ void W_Tuba_NoteOff(void)
// note: self.cnt
if(self.owner.tuba_note == self)
{
self.owner.tuba_lastnotes_last = mod(self.owner.tuba_lastnotes_last + 1, MAX_TUBANOTES);
self.owner.tuba_lastnotes_last = (self.owner.tuba_lastnotes_last + 1) % MAX_TUBANOTES;
self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
self.owner.tuba_note = world;
self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
......
......@@ -222,7 +222,7 @@ float W_FixWeaponOrder_BuildImpulseList_cmp(float i, float j, entity pass)
float d;
e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
d = mod(e1.impulse + 9, 10) - mod(e2.impulse + 9, 10);
d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
if(d != 0)
return -d; // high impulse first!
return
......
......@@ -1075,7 +1075,7 @@ void DragBox_Think()
}
else
{
setmodel(self.killindicator, strcat("models/sprites/", ftos(mod(self.cnt, 10)), ".spr32"));
setmodel(self.killindicator, strcat("models/sprites/", ftos(self.cnt % 10), ".spr32"));
setmodel(self.killindicator.killindicator, strcat("models/sprites/", ftos(floor(self.cnt / 10)), ".spr32"));
}
......
......@@ -124,7 +124,7 @@ void ImpulseCommands (void)
if(self.deadflag == DEAD_NO)
{
// custom order weapon cycling
i = mod(imp, 10);
i = imp % 10;
m = (imp - (210 + i)); // <0 for prev, =0 for best, >0 for next
W_CycleWeapon(self.(cvar_cl_weaponpriorities[i]), m);
}
......
......@@ -293,7 +293,7 @@ string getmaplist()
{
if(MapInfo_CheckMap(argv(i)))
{
if(mod(i, 2)) { col = "^2"; }
if(i % 2) { col = "^2"; }
else { col = "^3"; }
maplist = sprintf("%s%s%s ", maplist, col, argv(i));
}
......@@ -321,12 +321,12 @@ string getlsmaps()
)
{
newmaps = TRUE;
if(mod(i, 2)) { col = "^4*"; }
if(i % 2) { col = "^4*"; }
else { col = "^5*"; }
}
else
{
if(mod(i, 2)) { col = "^2"; }
if(i % 2) { col = "^2"; }
else { col = "^3"; }
}
......@@ -345,7 +345,7 @@ string getmonsterlist()
for(i = MON_FIRST; i <= MON_LAST; ++i)
{
if(mod(i, 2)) { col = "^2"; }
if(i % 2) { col = "^2"; }
else { col = "^3"; }
monsterlist = sprintf("%s%s%s ", monsterlist, col, (get_monsterinfo(i)).netname);
}
......
......@@ -1771,7 +1771,7 @@ void target_voicescript_next(entity pl)
if(pl.voicescript_index < vs.cnt)
i = pl.voicescript_index * 2;
else if(n > vs.cnt * 2)
i = mod(pl.voicescript_index - vs.cnt, (n - vs.cnt * 2 - 1) / 2) * 2 + vs.cnt * 2 + 1;
i = ((pl.voicescript_index - vs.cnt) % ((n - vs.cnt * 2 - 1) / 2)) * 2 + vs.cnt * 2 + 1;
else
i = -1;
......
......@@ -41,7 +41,7 @@ void PingPLReport_Think()
WriteByte(MSG_BROADCAST, 0);
WriteByte(MSG_BROADCAST, 0);
}
self.cnt = mod(self.cnt + 1, maxclients);
self.cnt = (self.cnt + 1) % maxclients;
}
void PingPLReport_Spawn()
{
......@@ -1036,7 +1036,7 @@ float() MaplistMethod_Iterate = // usual method
for(i = 1; i < Map_Count; ++i)
{
float mapindex;
mapindex = mod(i + Map_Current, Map_Count);
mapindex = (i + Map_Current) % Map_Count;
if(Map_Check(mapindex, pass))
return mapindex;
}
......@@ -1064,7 +1064,7 @@ float() MaplistMethod_Random = // random map selection
for(i = 0; i <= imax; ++i)
{
float mapindex;
mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
mapindex = (Map_Current + floor(random() * (Map_Count - 1) + 1)) % Map_Count; // any OTHER map
if(Map_Check(mapindex, 1))
return mapindex;
}
......
......@@ -138,7 +138,7 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data)
else
n = tokenizebyseparator(data, "\n");
if(mod(n, 4) != 0)
if((n % 4) != 0)
{
print("error: received invalid item count: ", ftos(n), "\n");
return;
......
......@@ -668,7 +668,7 @@ void kh_Key_Think() // runs all the time
if(self.owner)
{
#ifndef KH_PLAYER_USE_ATTACHMENT
makevectors('0 1 0' * (self.cnt + mod(time, 360) * KH_KEY_XYSPEED));
makevectors('0 1 0' * (self.cnt + (time % 360) * KH_KEY_XYSPEED));
setorigin(self, v_forward * KH_KEY_XYDIST + '0 0 1' * self.origin_z);
#endif
}
......
......@@ -741,7 +741,7 @@ void W_Nexball_Attack(float t)
mi = autocvar_g_nexball_basketball_meter_minpower;
ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
//One triangle wave period with 1 as max
mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
mul = 2 * (t % g_nexball_meter_period) / g_nexball_meter_period;
if(mul > 1)
mul = 2 - mul;
mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
......
......@@ -1178,7 +1178,7 @@ float race_GetFractionalLapCount(entity e)
// race_timed_checkpoint == 0: then nextcp==0 means 0.9999x
float c, nc;
nc = race_highest_checkpoint + 1;
c = (mod(nextcpindex - race_timed_checkpoint + nc + nc - 1, nc) + 1) - bestfraction;
c = ((nextcpindex - race_timed_checkpoint + nc + nc - 1) % nc) + 1 - bestfraction;
return l + c / nc;
}
......@@ -188,7 +188,7 @@ void trigger_push_touch()
found = TRUE;
if(!found)
{
other.(jumppadsused[mod(other.jumppadcount, NUM_JUMPPADSUSED)]) = self;
other.(jumppadsused[other.jumppadcount % NUM_JUMPPADSUSED]) = self;
other.jumppadcount = other.jumppadcount + 1;
}
......
......@@ -494,7 +494,7 @@ float spiderbot_frame()
self = player;
mod(spider.misc_bulletcounter, 2) ? gun = spider.gun1 : gun = spider.gun2;
(spider.misc_bulletcounter % 2) ? gun = spider.gun1 : gun = spider.gun2;
v = gettaginfo(gun, gettagindex(gun, "barrels"));
v_forward = normalize(v_forward);
v += v_forward * 50;
......
......@@ -94,7 +94,7 @@ void accuracy_add(entity e, float w, float fired, float hit)
if(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])))
return;
w = pow(2, mod(w, 24));
w = pow(2, w % 24);
a.SendFlags |= w;
FOR_EACH_CLIENT(a)
if(IS_SPEC(a))
......
......@@ -182,7 +182,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
if(complain)
{
self.weaponcomplainindex += 1;
c = mod(self.weaponcomplainindex, c) + 1;
c = (self.weaponcomplainindex % c) + 1;
rest = weaponorder;
while(rest != "")
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment