diff --git a/config/menus_edit.cfg b/config/menus_edit.cfg index d6d89552..e22e29cc 100644 --- a/config/menus_edit.cfg +++ b/config/menus_edit.cfg @@ -261,17 +261,15 @@ menuinit [ menurenderoffset -20 0 if $editing [ push ecurmenu (escape (curmenu)) - push i 0 push info "" - looplist (textureslotusagelist) [cnt used] [ + looplisti (textureslotusagelist) [cnt used] [ info = (edittextureslot $i) if (|| $cnt (strlen $info)) [ if (! (strlen $info)) [ info = " \fs\f3\fr" ] menuitem (concatword "edit texture slot #" $i ": " $info " (" $cnt " uses, " $used " visible)") (concat __texslot = $i "; showmenu [Edit texture slot]") (concat chmenutexture $ecurmenu (at $info 1)) ] - += i 1 ] - pop i info ecurmenu + pop info ecurmenu ] [ menuitem "menu only available in edit mode" -1 ] @@ -645,8 +643,7 @@ newmenu "deleted entities" menuinit [ resetcurmenu if (unlistdeletedentity) [ - push i 0 - looplist (getdeletedentities) [type x y z a1 a2 a3 a4 a5 a6 a7] [ + looplisti (getdeletedentities) [type x y z a1 a2 a3 a4 a5 a6 a7] [ push desc (concat $type (concatword "[" $x "|" $y "|" $z "]") (concatword "(" $a1 ", " $a2 ", " $a3 ", " $a4 ", " $a5 ", " $a6 ", " $a7 ")")) if (strcmp $type mapmodel) [desc = (concat $desc (mapmodelslotname $a2))] if (&& $editing (strcmp $type sound)) [desc = (concat $desc (at (editmapsoundslot $a1) 0))] @@ -655,9 +652,7 @@ menuinit [ ][ menuitem (pop desc) -1 ] - += i 1 ] - pop i menuitem "\f3clear this list" "unlistdeletedentity all" ] [ menuitem "no deleted entities" -1 @@ -973,13 +968,11 @@ menuinit [ resetcurmenu __placeprobepointdummies menuitem "\f4(return to previous position)" (concat gotoposition (gotoposition)) (concat gotoposition (gotoposition)) - push i 0 push ents (enumentities dummy) - looplist (mapareacheck pp) [x y z area vol avgh] [ + looplisti (mapareacheck pp) [x y z area vol avgh] [ menuitem (concatword "#" $i " area: " $area " volume: " $vol " avg height: " $avgh " (" $x "|" $y ")") (concat gotoentity (at $ents $i)) (concat gotoentity (at $ents $i)) - += i 1 ] - pop i ents + pop ents ] push __a "resetcurmenu ; menuitem [\f4(return to previous position)] (concat gotoposition (gotoposition)) (concat gotoposition (gotoposition)) ;" diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 2b3e7486..370fe4d0 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -1051,7 +1051,7 @@ void preparectf(bool cleanonly=false) if(e.type==CTF_FLAG) { e.spawned = true; - if(e.attr2>=2) { conoutf("\f3invalid ctf-flag entity (%i)", i); e.attr2 = 0; } + if(e.attr2>=2) { conoutf("\f3invalid ctf-flag entity (%d)", i); e.attr2 = 0; } flaginfo &f = flaginfos[e.attr2]; f.flagent = &e; f.pos.x = (float) e.x; diff --git a/source/src/command.cpp b/source/src/command.cpp index 85335c15..17df3573 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -523,7 +523,7 @@ const char *floatstr(float v, bool neat) static int i = 0; if(i > MAXSTRLEN - 100) i = 0; char *t = s + i; - sprintf(t, !neat && (v) == int(v) ? "%.1f" : "%.7g", v); // was ftoa() + snprintf(t, 99, !neat && (v) == int(v) ? "%.1f" : "%.7g", v); // was ftoa() i += strlen(t) + 1; return t; } @@ -1216,27 +1216,38 @@ void explodelist(const char *s, vector &elems) } } -void looplist(char *list, char *varlist, char *body) +void looplist(char *list, char *varlist, char *body, bool withi) { vector vars; explodelist(varlist, vars); if(vars.length() < 1) return; + int varslen = vars.length(); + if(withi) vars.add(newstring("i")); vector ids; bool ok = true; loopv(vars) if(ids.add(newident(vars[i]))->type != ID_ALIAS) { conoutf("looplist error: \"%s\" is readonly", vars[i]); ok = false; } if(ok) { + int ii = 0; vector elems; explodelist(list, elems); loopv(ids) pushident(*ids[i], newstring("")); loop_level++; - for(int i = 0; i <= elems.length() - vars.length(); i += vars.length()) + for(int i = 0; i <= elems.length() - varslen; i += varslen) { - loopvj(vars) + loopj(vars.length()) { if(ids[j]->action != ids[j]->executing) delete[] ids[j]->action; - ids[j]->action = elems[i + j]; - elems[i + j] = NULL; + if(j < varslen) + { + ids[j]->action = elems[i + j]; + elems[i + j] = NULL; + } + else + { + defformatstring(sii)("%d", ii++); + ids[j]->action = newstring(sii); + } } execute(body); loop_skip = false; @@ -1249,7 +1260,8 @@ void looplist(char *list, char *varlist, char *body) } loopv(vars) delete[] vars[i]; } -COMMAND(looplist, "sss"); +COMMANDF(looplist, "sss", (char *list, char *varlist, char *body) { looplist(list, varlist, body, false); }); +COMMANDF(looplisti, "sss", (char *list, char *varlist, char *body) { looplist(list, varlist, body, true); }); char *indexlist(const char *s, int pos) { diff --git a/source/src/console.cpp b/source/src/console.cpp index 078d996c..5cd13f60 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -199,7 +199,7 @@ void findkeycode(const char* s) { if(strcmp(s, keyms[i].name) == 0) { - defformatstring(out)("%i", keyms[i].code); + defformatstring(out)("%d", keyms[i].code); result(out); return; } @@ -239,7 +239,7 @@ void keybind(const char *key, int type) { keym *km = findbind(key); if(!km) { conoutf("unknown key \"%s\"", key); return; } - if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%i\"", type); return; } + if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%d\"", type); return; } result(km->actions[type]); } @@ -253,7 +253,7 @@ bool bindc(int code, const char *action, int type) void searchbinds(const char *action, int type) { if(!action || !action[0]) return; - if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%i\"", type); return; } + if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%d\"", type); return; } vector names; loopv(keyms) { diff --git a/source/src/docs.cpp b/source/src/docs.cpp index cc342b37..d09a33c2 100644 --- a/source/src/docs.cpp +++ b/source/src/docs.cpp @@ -335,7 +335,7 @@ void docwriteref(int allidents, const char *ref, const char *schemalocation, con switch(id->type) { case ID_VAR: - f->printf("\t\t\t\t\t\n", id->minval>id->maxval ? "" : "token=\"N\"", id->minval, id->maxval, *id->storage.i, id->minval>id->maxval ? "readOnly=\"true\"" : ""); + f->printf("\t\t\t\t\t\n", id->minval>id->maxval ? "" : "token=\"N\"", id->minval, id->maxval, *id->storage.i, id->minval>id->maxval ? "readOnly=\"true\"" : ""); break; case ID_FVAR: f->printf("\t\t\t\t\t\n", id->minvalf>id->maxvalf ? "" : "token=\"N\"", diff --git a/source/src/server.cpp b/source/src/server.cpp index cd67bd26..cda38acf 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -3346,7 +3346,7 @@ void process(ENetPacket *packet, int sender, int chan) { disconnect_client(sender, DISC_CN); #ifndef STANDALONE - conoutf("ERROR: invalid client (msg %i)", type); + conoutf("ERROR: invalid client (msg %d)", type); #endif return; } @@ -3374,7 +3374,7 @@ void process(ENetPacket *packet, int sender, int chan) { disconnect_client(sender, DISC_CN); #ifndef STANDALONE - conoutf("ERROR: invalid client (msg %i)", type); + conoutf("ERROR: invalid client (msg %d)", type); #endif return; } diff --git a/source/src/serverfiles.h b/source/src/serverfiles.h index 7a39ab1a..53ae799d 100644 --- a/source/src/serverfiles.h +++ b/source/src/serverfiles.h @@ -1425,12 +1425,12 @@ struct killmessagesfile : serverconfigfile if(gun < 0 || gun >= NUMGUNS) { - logline(ACLOG_INFO, " error in line %i, invalid gun : %i", line, gun); + logline(ACLOG_INFO, " error in line %d, invalid gun : %d", line, gun); errors++; } if(strlen(message)>MAXKILLMSGLEN) { - logline(ACLOG_INFO, " error in line %i, too long message : string length is %i, max. allowed is %i", line, int(strlen(message)), MAXKILLMSGLEN); + logline(ACLOG_INFO, " error in line %d, too long message : string length is %d, max. allowed is %d", line, int(strlen(message)), MAXKILLMSGLEN); errors++; } if(!errors) @@ -1438,12 +1438,12 @@ struct killmessagesfile : serverconfigfile if(fragmsg) { copystring(killmessages[0][gun], message, MAXKILLMSGLEN); - logline(ACLOG_VERBOSE, " added msg '%s' for frags with weapon %i ", message, gun); + logline(ACLOG_VERBOSE, " added msg '%s' for frags with weapon %d ", message, gun); } else { copystring(killmessages[1][gun], message, MAXKILLMSGLEN); - logline(ACLOG_VERBOSE, " added msg '%s' for gibs with weapon %i ", message, gun); + logline(ACLOG_VERBOSE, " added msg '%s' for gibs with weapon %d ", message, gun); } } s = NULL; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index cc0b9379..e52c3b51 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -831,13 +831,13 @@ VARP(oldfashionedgunstats, 0, 0, 1); void weapon::renderstats() { char gunstats[64]; - if(oldfashionedgunstats) sprintf(gunstats, "%i/%i", mag, ammo); else sprintf(gunstats, "%i", mag); + if(oldfashionedgunstats) snprintf(gunstats, 64, "%d/%d", mag, ammo); else snprintf(gunstats, 64, "%d", mag); draw_text(gunstats, HUDPOS_WEAPON + HUDPOS_NUMBERSPACING, 823); if(!oldfashionedgunstats) { int offset = text_width(gunstats); glScalef(0.5f, 0.5f, 1.0f); - sprintf(gunstats, "%i", ammo); + snprintf(gunstats, 64, "%d", ammo); draw_text(gunstats, (HUDPOS_WEAPON + HUDPOS_NUMBERSPACING + offset)*2, 826*2); glLoadIdentity(); } @@ -1179,7 +1179,7 @@ void grenades::dropnade() void grenades::renderstats() { char gunstats[64]; - sprintf(gunstats, "%i", mag); + sprintf(gunstats, "%d", mag); draw_text(gunstats, oldfashionedgunstats ? HUDPOS_GRENADE + HUDPOS_NUMBERSPACING + 25 : HUDPOS_GRENADE + HUDPOS_NUMBERSPACING, 823); }