diff --git a/config/defaults.cfg b/config/defaults.cfg index 8b78691c..a7d02331 100644 --- a/config/defaults.cfg +++ b/config/defaults.cfg @@ -36,8 +36,7 @@ bind G [ if $editing [ solid 0 ] [ quicknadethrow ] ] lighterror 4 //set higher (for example 8) if you experience slowdown alias altaction [ - concatword altaction_ (curweapon) - s + (concatword altaction_ (curweapon)) ] alias quicknadethrow [ @@ -49,7 +48,7 @@ alias quicknadethrow [ onrelease [ sleep 1 [ weapon $prevweapon ] ] ] -loop 7 [ concatword altaction_ $i; alias $s quicknadethrow ] // quick nade throw is default +loop i 7 [ alias (concatword altaction_ $i) quicknadethrow ] // quick nade throw is default alias altaction_4 [ zoom 1; onrelease [ zoom 0 ] ] // sniper alias altaction_6 [ ] // grenade (none) @@ -110,8 +109,7 @@ alias universaldelta [ if $editing [ alias s "edit" ] [ if (alive) [ alias s "game" ] [ alias s "spect" ] ] - concatword delta _ $s _ $modifier - s + (concatword delta _ $s _ $modifier) ] bind MOUSE4 "universaldelta 1" diff --git a/config/docs.cfg b/config/docs.cfg index d073843d..22fccb62 100644 --- a/config/docs.cfg +++ b/config/docs.cfg @@ -55,10 +55,11 @@ docargument [false] [the body to execute if the condition is true] [] [0]; docexample [if (> $x 10) [ echo x is bigger than 10 ] [ else x too small ]] []; docident [loop] [Loops the specified body.]; +docargument [I] [the alias of the current loop index] [] [0]; docargument [N] [the amount of loops] [] [0]; docargument [body] [the body to execute on each iteration] [] [0]; -docremark [This command sets the alias "i" from 0 to N-1 for every iteration.]; -docexample [loop 10 [ echo $i ]] []; +docremark [This command sets the alias I from 0 to N-1 for every iteration.]; +docexample [loop i 10 [ echo $i ]] []; docident [mod] [Performs a modulo operation.]; docargument [A] [the dividend] [] [0]; diff --git a/config/menus.cfg b/config/menus.cfg index f0252aaa..8ba0816a 100755 --- a/config/menus.cfg +++ b/config/menus.cfg @@ -19,17 +19,13 @@ menuitem "Quit" "quit" alias genmapitems [ alias n (listlen $arg1) - loop $n [ - at $arg1 $i - alias mapname $s - concat map $s - menuitem $s + loop i $n [ + alias mapname (at $arg1 $i) + menuitem (concat map $mapname) alias next (+ $i 1) if (= $next $n) [ alias next 0 ] [] - at $arg1 $next - alias nextmap $s - concatword nextmap_ $mapname - alias $s $nextmap + alias nextmap (at $arg1 $next) + alias (concatword nextmap_ $mapname) $nextmap ] ] @@ -84,12 +80,9 @@ menuitem "Rabid Viper Special Forces" "team RVSF" "chmenumdl team playermodels/ alias gencrosshairs [ - alias n (listlen $arg1) - loop $n [ - at $arg1 $i - alias label $s - concat loadcrosshair $s - menuitem $label $s + loop i (listlen $arg1) [ + alias label (at $arg1 i) + menuitem $label (concat loadcrosshair $label) ] ] @@ -171,24 +164,20 @@ menuitem "bad" "alias tmp_botskill bad; showmenu_enemies" alias genenemyitems [ - alias n (listlen $arg1) - loop $n [ - at $arg1 $i - alias numplayers $s + loop i (listlen $arg1) [ + alias numplayers (at $arg1 $i) if (= $arg2 0) [ // DM alias numplayers (- $numplayers 1) // don't count yourself as enemy if (= $numplayers 1) [ - concat $numplayers enemy + alias menutext (concat $numplayers enemy) ] [ - concat $numplayers enemies + alias menutext (concat $numplayers enemies) ] ] [ // TDM alias teamsize (div $numplayers 2) - concatword $teamsize on $teamsize + alias menutext (concatword $teamsize on $teamsize) ] - alias menutext $s - concat "alias tmp_numbots" $numplayers "; showmenu botmaps" - menuitem $menutext $s + menuitem $menutext (concat "alias tmp_numbots" $numplayers "); showmenu botmaps" ] ] @@ -202,14 +191,10 @@ genenemyitems "2 4 6 8 16 32" 1 newmenu botmaps alias genbotmaps [ - alias n (listlen $arg1) - loop $n [ - at $arg1 $i - alias mapname $s - concat map $mapname - alias menutext $s - concat "alias tmp_botmap" $mapname "; startbotmap" - menuitem $menutext $s + loop i (listlen $arg1) [ + alias mapname (at $arg1 $i) + alias menutext (concat map $mapname) + menuitem $menutext (concat "alias tmp_botmap" $mapname "; startbotmap") ] ] diff --git a/config/prefabs.cfg b/config/prefabs.cfg index a02fa01d..75360ef0 100755 --- a/config/prefabs.cfg +++ b/config/prefabs.cfg @@ -3,9 +3,8 @@ // archvertex // vertices not defined have a 0 delta alias av [ - loop $arg1 [ - at $arg2 $i - archvertex (+ $arg1 1) (+ $i 1) $s + loop i $arg1 [ + archvertex (+ $arg1 1) (+ $i 1) (at $arg2 $i) ] ] av 1 "2" @@ -24,4 +23,4 @@ av 13 "8 13 16 18 19 19 19 19 19 18 16 13 8" // these last few can be improve av 14 "8 13 16 18 19 19 19 19 19 19 18 16 13 8" av 15 "8 13 16 18 19 19 19 19 19 19 19 18 16 13 8" -// add wider arches here! :) \ No newline at end of file +// add wider arches here! :) diff --git a/config/sounds.cfg b/config/sounds.cfg index b89ee61b..9d162c98 100755 --- a/config/sounds.cfg +++ b/config/sounds.cfg @@ -49,11 +49,10 @@ registersound "player/footsteps" 100 1 // S_FOOTSTEPS alias fade [ // 0=in, 1=out alias stepsize 5 alias numsteps (div $maxmusicvol $stepsize) - loop (+ $numsteps 1) [ + loop i (+ $numsteps 1) [ alias curvol (* $i $stepsize) if (= $arg1 1) [ alias curvol (- $maxmusicvol $curvol) ] - concat musicvol ($curvol) - sleep (* $i 100) $s + sleep (* $i 100) (concat musicvol $curvol) ] ] diff --git a/source/src/command.cpp b/source/src/command.cpp index 620a8dc6..319f3edb 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -48,7 +48,7 @@ void popident(ident &id) delete stack; } -void pusha(const char *name, char *action) +ident *newident(const char *name) { ident *id = idents->access(name); if(!id) @@ -56,7 +56,12 @@ void pusha(const char *name, char *action) ident init(ID_ALIAS, newstring(name), newstring(""), persistidents, IEXC_CORE); id = idents->access(init.name, &init); } - pushident(*id, action); + return id; +} + +void pusha(const char *name, char *action) +{ + pushident(*newident(name), action); } void push(const char *name, const char *action) @@ -331,13 +336,7 @@ char *executeret(const char *p) // all evaluation hap if(i > argids.length()) { s_sprintfd(argname)("arg%d", i); - ident *id = idents->access(argname); - if(!id) - { - ident init(ID_ALIAS, newstring(argname), newstring(""), persistidents, IEXC_CORE); - id = idents->access(init.name, &init); - } - argids.add(id); + argids.add(newident(argname)); } pushident(*argids[i-1], w[i]); // set any arguments as (global) arg values so functions can access them } @@ -415,7 +414,20 @@ void exec(const char *cfgfile) void intset(const char *name, int v) { string b; itoa(b, v); alias(name, b); } void ifthen(char *cond, char *thenp, char *elsep) { execute(cond[0]!='0' ? thenp : elsep); } -void loopa(char *times, char *body) { int t = atoi(times); loopi(t) { intset("i", i); execute(body); } } +void loopa(char *var, char *times, char *body) +{ + int t = ATOI(times); + if(t<=0) return; + ident *id = newident(var); + if(id->type!=ID_ALIAS) return; + loopi(t) + { + if(i) itoa(id->action, i); + else pushident(*id, newstring("0", 16)); + execute(body); + } + popident(*id); +} void whilea(char *cond, char *body) { while(execute(cond)) execute(body); } // can't get any simpler than this :) void concat(char *s) { result(s); } @@ -450,12 +462,12 @@ char *indexlist(const char *s, int pos) return newstring(e, s-e); } -void listlen(char *s) +int listlen(char *s) { int n = 0; whitespaceskip; for(; *s; n++) elementskip, whitespaceskip; - intret(n); + return n; } void at(char *s, char *pos) @@ -463,12 +475,13 @@ void at(char *s, char *pos) commandret = indexlist(s, ATOI(pos)); } -COMMANDN(loop, loopa, ARG_2STR); +COMMANDN(loop, loopa, ARG_3STR); COMMANDN(while, whilea, ARG_2STR); COMMANDN(if, ifthen, ARG_3STR); COMMAND(exec, ARG_1STR); COMMAND(concat, ARG_VARI); COMMAND(concatword, ARG_VARIW); +COMMAND(result, ARG_1STR); COMMAND(at, ARG_2STR); COMMAND(listlen, ARG_1EST); diff --git a/source/src/tools.h b/source/src/tools.h index e030f513..b1e217f1 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -477,7 +477,7 @@ template struct hashtable } }; -#define itoa(s, i) { s_sprintf(s)("%d", i); } +#define itoa(s, i) sprintf(s, "%d", i) #define enumeratekt(ht,k,e,t,f,b) loopi((ht).size) for(hashtable::chain *enumc = (ht).table[i]; enumc; enumc = enumc->next) { hashtable::const_key &e = enumc->key; t &f = enumc->data; b; } #define enumerate(ht,t,e,b) loopi((ht).size) for((ht).enumc = (ht).table[i]; (ht).enumc; (ht).enumc = (ht).enumc->next) { t &e = (ht).enumc->data; b; }