fixes/cleanup
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6842 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+18
-17
@@ -1,25 +1,26 @@
|
||||
if (! (checkalias mapstartalways)) [ mapstartalways = "" ]
|
||||
if (! (strstr $mapstartalways autoSaveCheck)) [ add2alias mapstartalways [ if $autosavemap autoSaveCheck; numAutoSaves = 0 ] ]
|
||||
checkinit mapstartalways [ if $autosavemap autoSaveCheck; numAutoSaves = 0 ]
|
||||
checkinit onNewMap [ if $autosavemap autoSaveCheck; numAutoSaves = 0 ]
|
||||
|
||||
if (! (checkalias onNewMap)) [ onNewMap = "" ]
|
||||
if (! (strstr $onNewMap autoSaveCheck)) [ add2alias onNewMap [ if $autosavemap autoSaveCheck; numAutoSaves = 0 ] ]
|
||||
checkinit autosavemap 0 // Autosavemap system disabled by default
|
||||
checkinit timeBetAutoSaves 300000 // Once every 5 minutes.
|
||||
checkinit numAutoSaveBackups 12 // Make a map .bak every 12 autosaves by default
|
||||
|
||||
if (! (checkalias autosavemap)) [ autosavemap = 0 ]
|
||||
if (! (checkalias timeBetAutoSaves)) [ timeBetAutoSaves = 300000 ] // Once every 5 minutes.
|
||||
if (! (checkalias numAutoSaveBackups)) [ numAutoSaveBackups = 12 ]
|
||||
const autoSaveCheck [ sleep $timeBetAutoSaves [ doAutoSave ] 1 ]
|
||||
|
||||
const autoSaveCheck [ sleep $timeBetAutoSaves [ doAutoSave ] ]
|
||||
const execAutoSave [
|
||||
+= numAutoSaves 1
|
||||
oldmapbackups = $mapbackupsonsave
|
||||
if (|| (!= $numAutoSaveBackups $numAutoSaves) (= $numAutoSaveBackups 0)) [ mapbackupsonsave 0 ] [ numAutoSaves = 0 ] // Temporarily turn off map backups to avoid clutter.
|
||||
savemap (curmap 1)
|
||||
mapbackupsonsave $oldmapbackups
|
||||
echo (blue)The map was automatically saved. (white)Next auto-save in (divf $timeBetAutoSaves 60000) minutes.
|
||||
]
|
||||
|
||||
const doAutoSave [
|
||||
if (&& (! (strstr $defaultmaps (curmap 1))) (! (strcmp (curmap 1) ""))) [
|
||||
if (|| $editing (= $gamemode (coop -1))) [
|
||||
if $autosavemap [
|
||||
+= numAutoSaves 1
|
||||
oldmapbackups = $mapbackupsonsave
|
||||
if (|| (!= $numAutoSaveBackups $numAutoSaves) (= $numAutoSaveBackups 0)) [ mapbackupsonsave 0 ] [ numAutoSaves = 0 ] // Temporarily turn off map backups to avoid clutter.
|
||||
savemap (curmap 1)
|
||||
mapbackupsonsave $oldmapbackups
|
||||
echo (blue)The map was automatically saved. (white)Next auto-save in (divf $timeBetAutoSaves 60000) minutes.
|
||||
if $autosavemap [
|
||||
if (&& (! (strstr $defaultmaps (curmap 1))) (strlen (curmap 1))) [
|
||||
if $editing execAutoSave [
|
||||
if (= $gamemode (coop -1)) execAutoSave
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
@@ -604,18 +604,6 @@ docexample [echo (testchar . 6)] [Output: 1 // It is a punctuation character];
|
||||
|
||||
docexample [echo (testchar " " 7)] [Output: 1 // It is a whitespace character];
|
||||
|
||||
docident [testlist] [Tests a list argument for various things.];
|
||||
|
||||
docargument [L] [the list to test] [] [0];
|
||||
|
||||
docargument [N] [type of test to run] [min 0/max 2/default 0] [0];
|
||||
|
||||
docexample [echo (testlist "1 2.45 8")] [Output: 1 // It is a valid list of numbers (supports ints and floats)];
|
||||
|
||||
docexample [echo (testlist "a B C defg hi jk" 1)] [Output: 1 // It is a valid list of alpha-characters a-z or A-Z only];
|
||||
|
||||
docexample [echo (testlist "a B C defg hi jk" 2)] [Output: 1 // It is a valid list of alpha-characters a-z or A-Z or whitespace only];
|
||||
|
||||
docident [tolower] [Converts a string to all lowercase characters.];
|
||||
|
||||
docargument [S] [a string] [] [0];
|
||||
|
||||
@@ -429,6 +429,6 @@ menuitem "2 [ OK ]" [ newent sound $ambientsoundmenu $soundrad $soundsize
|
||||
|
||||
newmenu "Editing settings"
|
||||
menuitemslider "Fly speeds multiplier: " 1 5 "$flyspeed" 1 "" [ flyspeed $arg1 ]
|
||||
menuitemcheckbox "Enable auto save map: " "$autosavemap" [ autosavemap = $arg1 ]
|
||||
menuitemcheckbox "Enable auto save map: " "result $autosavemap" [ autosavemap = $arg1 ]
|
||||
menuitemslider "Time between auto saves (in milliseconds): " 30000 600000 "$timeBetAutoSaves" 30000 [] [ timeBetAutoSaves = $arg1 ]
|
||||
menuitemtextinput "Make a map backup (.BAK) every (# auto saves):" "$numAutoSaveBackups" [ if (testlist $arg1) [ numAutoSaveBackups = $arg1 ] ] [] 4
|
||||
menuitemtextinput "Make a map backup (.BAK) every (# auto saves):" "result $numAutoSaveBackups" [ numAutoSaveBackups = $arg1 ] [] 4
|
||||
+8
-10
@@ -250,7 +250,7 @@ const add2alias [
|
||||
const addOnLoadOnce [ add2alias mapstartonce $arg1 ]
|
||||
const addOnLoadAlways [ add2alias mapstartalways $arg1 ]
|
||||
const addOnQuit [ add2alias onQuit $arg1 ]
|
||||
const checkinit [ if (> $numargs 0) [ if (! (checkalias $arg1)) [ $arg1 = "" ]; if (> $numargs 1) [ add2alias $arg1 $arg2 ] ] ]
|
||||
const checkinit [ if (> $numargs 0) [ if (! (checkalias $arg1)) [ $arg1 = "" ]; if (&& (> $numargs 1) (! (strstr (getalias $arg1) $arg2))) [ add2alias $arg1 $arg2 ] ] ]
|
||||
const aliasinit [ loop ail (listlen $arg1) [ if (< $numargs 2) [ checkinit (at $arg1 $ail) ] [ checkinit (at $arg1 $ail) $arg2 ] ] ]
|
||||
const add2list [ if (strcmp "" (getalias $arg1)) [ $arg1 = $arg2 ] [ $arg1 = (concat (getalias $arg1) $arg2) ] ]
|
||||
const add2bind [ if (! (strstr (keybind $arg1) $arg2)) [ bind $arg1 (format "%1; %2" (keybind $arg1) $arg2) ] ]
|
||||
@@ -260,7 +260,7 @@ const rndmap [ result (at $defaultmaps (rnd (listlen $defaultmaps))) ]
|
||||
const rrnd [ + (rnd (- $arg2 $arg1)) $arg1 ]
|
||||
|
||||
// listaverage - Returns the average of a list of numbers. (Supports ints & floats - e.g. echo (listaverage "2 5 5") // Output: 4.0)
|
||||
const listaverage [ if (&& (listlen $arg1) (testlist $arg1)) [ tmp_sum = 0; loop gsl (listlen $arg1) [ +=f tmp_sum (at $arg1 $gsl) ]; result (divf $tmp_sum (listlen $arg1)) ] ]
|
||||
const listaverage [ if (listlen $arg1) [ tmp_sum = 0; loop gsl (listlen $arg1) [ +=f tmp_sum (at $arg1 $gsl) ]; result (divf $tmp_sum (listlen $arg1)) ] ]
|
||||
|
||||
// copyent & pasteent - Quickly copy/paste the current closest entity. Initialize the two aliases below as "NULL" for error catching.
|
||||
// If /config/saved.cfg is readable/writable, errors are only possible up until the very first use of /copyent.
|
||||
@@ -278,14 +278,12 @@ const copyent [
|
||||
|
||||
const pasteent [
|
||||
if $editing [
|
||||
if (&& (! (strcmp $cp_entbuf NULL)) (! (strcmp $cp_entstr NULL))) [
|
||||
if (strcmp (at $cp_entbuf 0) mapmodel) [
|
||||
newent (at $cp_entbuf 0) (at $cp_entbuf 2) (at $cp_entbuf 3) (at $cp_entbuf 4)
|
||||
] [
|
||||
newent (at $cp_entbuf 0) (at $cp_entbuf 1) (at $cp_entbuf 2) (at $cp_entbuf 3) (at $cp_entbuf 4)
|
||||
]
|
||||
echo (blue)Note: (white)The previously copied entity: $cp_entstr - has been pasted.
|
||||
] [ echo (red)Error: (white)pasteent requires an (blue)initial (white)copyent to function. ]
|
||||
if (strcmp (at $cp_entbuf 0) mapmodel) [
|
||||
newent (at $cp_entbuf 0) (at $cp_entbuf 2) (at $cp_entbuf 3) (at $cp_entbuf 4)
|
||||
] [
|
||||
newent (at $cp_entbuf 0) (at $cp_entbuf 1) (at $cp_entbuf 2) (at $cp_entbuf 3) (at $cp_entbuf 4)
|
||||
]
|
||||
echo (blue)Note: (white)The previously copied entity: $cp_entstr - has been pasted.
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
@@ -1273,43 +1273,6 @@ void testchar(char *s, char *type)
|
||||
intret(0);
|
||||
}
|
||||
|
||||
// test a cubescript list for various conditions, default being - ensure that every element of the list
|
||||
// is a number (supports ints and floats)
|
||||
void testlist(char *list, char *type = "0")
|
||||
{
|
||||
if(listlen(list)) {
|
||||
int t = atoi(type);
|
||||
|
||||
for(int ctr = 0; ctr < listlen(list); ctr++) { // loop through every element of the list
|
||||
int periodCtr = 0; // counter for how many times a period (.) shows up in each element
|
||||
char *curelement = indexlist(list, ctr); // the current element to examine
|
||||
|
||||
for(unsigned int len = 0; len < strlen(curelement); len++) { // loop through the length (in chars) of the current element
|
||||
char curchar = curelement[len]; // the current char of the current element to examine
|
||||
|
||||
switch(t) {
|
||||
case 1: // test for a list of alpha characters (a-z || A-Z are valid)
|
||||
if(!isalpha(curchar)) { intret(0); delete[] curelement; return; }
|
||||
break;
|
||||
case 2: // test for a list of alhpa characters (a-z || A-Z || whitespace are valid)
|
||||
if(!isalpha(curchar) && !isspace(curchar)) { intret(0); delete[] curelement; return; }
|
||||
break;
|
||||
//case 3: break;
|
||||
default: // test for a list of valid numbers
|
||||
bool notvalid = (isalpha(curchar) || isspace(curchar) || (ispunct(curchar) && curchar != '.')); // determines if the char is valid or not
|
||||
|
||||
if(curchar == '.') periodCtr++; // increment the periods counter
|
||||
if(notvalid || periodCtr > 1) { intret(0); delete[] curelement; return; } // if the char is not valid or we have found more than 1 period in this element, it is an invalid list
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete[] curelement;
|
||||
}
|
||||
|
||||
intret(1);
|
||||
}
|
||||
}
|
||||
|
||||
void strreplace (const char *source, const char *search, const char *replace)
|
||||
{
|
||||
vector<char> buf;
|
||||
@@ -1355,7 +1318,6 @@ COMMAND(addpunct, ARG_2STR);
|
||||
COMMANDN(tolower, toLower, ARG_1STR);
|
||||
COMMANDN(toupper, toUpper, ARG_1STR);
|
||||
COMMAND(testchar, ARG_2STR);
|
||||
COMMAND(testlist, ARG_2STR);
|
||||
COMMAND(strreplace, ARG_3STR);
|
||||
|
||||
int add(int a, int b) { return a+b; } COMMANDN(+, add, ARG_2EXP);
|
||||
|
||||
Reference in New Issue
Block a user